Add ability to recompile shader source

Trac# 19900 Issue=291 - add an 'uncompile' function to clear all results from any previous compile attempts - allow compiling to be done multiple times on the same shader - allow a shader to be compiled with no source specified (to produce an appropriate error). Signed-off-by: Shannon Woods Signed-off-by: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@991 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent cde6a610
......@@ -27,6 +27,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
mHlsl = NULL;
mInfoLog = NULL;
uncompile();
// Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler)
if (!mFragmentCompiler)
{
......@@ -294,36 +296,53 @@ void Shader::parseVaryings()
}
}
// initialize/clean up previous state
void Shader::uncompile()
{
// set by compileToHLSL
delete[] mHlsl;
mHlsl = NULL;
delete[] mInfoLog;
mInfoLog = NULL;
// set by parseVaryings
mVaryings.clear();
mUsesFragCoord = false;
mUsesFrontFacing = false;
mUsesPointSize = false;
mUsesPointCoord = false;
}
void Shader::compileToHLSL(void *compiler)
{
if (isCompiled() || !mSource)
// ensure we don't pass a NULL source to the compiler
char *source = "\0";
if (mSource)
{
return;
source = mSource;
}
delete[] mInfoLog;
mInfoLog = NULL;
int compileOptions = SH_OBJECT_CODE;
std::string sourcePath;
if (perfActive())
{
sourcePath = getTempPath();
writeFile(sourcePath.c_str(), mSource, strlen(mSource));
writeFile(sourcePath.c_str(), source, strlen(source));
compileOptions |= SH_LINE_DIRECTIVES;
}
int result;
if (sourcePath.empty())
{
result = ShCompile(compiler, &mSource, 1, compileOptions);
result = ShCompile(compiler, &source, 1, compileOptions);
}
else
{
const char* sourceStrings[2] =
{
sourcePath.c_str(),
mSource
source
};
result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH);
......@@ -478,8 +497,18 @@ GLenum VertexShader::getType()
return GL_VERTEX_SHADER;
}
void VertexShader::uncompile()
{
Shader::uncompile();
// set by ParseAttributes
mAttributes.clear();
};
void VertexShader::compile()
{
uncompile();
compileToHLSL(mVertexCompiler);
parseAttributes();
parseVaryings();
......@@ -545,6 +574,8 @@ GLenum FragmentShader::getType()
void FragmentShader::compile()
{
uncompile();
compileToHLSL(mFragmentCompiler);
parseVaryings();
mVaryings.sort(compareVarying);
......
......@@ -62,6 +62,7 @@ class Shader
void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer);
virtual void compile() = 0;
virtual void uncompile();
bool isCompiled();
const char *getHLSL();
......@@ -134,6 +135,7 @@ class VertexShader : public Shader
virtual GLenum getType();
virtual void compile();
virtual void uncompile();
int getSemanticIndex(const std::string &attributeName);
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment