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 ...@@ -27,6 +27,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
mHlsl = NULL; mHlsl = NULL;
mInfoLog = NULL; mInfoLog = NULL;
uncompile();
// Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler) // Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler)
if (!mFragmentCompiler) if (!mFragmentCompiler)
{ {
...@@ -294,36 +296,53 @@ void Shader::parseVaryings() ...@@ -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) 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; int compileOptions = SH_OBJECT_CODE;
std::string sourcePath; std::string sourcePath;
if (perfActive()) if (perfActive())
{ {
sourcePath = getTempPath(); sourcePath = getTempPath();
writeFile(sourcePath.c_str(), mSource, strlen(mSource)); writeFile(sourcePath.c_str(), source, strlen(source));
compileOptions |= SH_LINE_DIRECTIVES; compileOptions |= SH_LINE_DIRECTIVES;
} }
int result; int result;
if (sourcePath.empty()) if (sourcePath.empty())
{ {
result = ShCompile(compiler, &mSource, 1, compileOptions); result = ShCompile(compiler, &source, 1, compileOptions);
} }
else else
{ {
const char* sourceStrings[2] = const char* sourceStrings[2] =
{ {
sourcePath.c_str(), sourcePath.c_str(),
mSource source
}; };
result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH); result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH);
...@@ -478,8 +497,18 @@ GLenum VertexShader::getType() ...@@ -478,8 +497,18 @@ GLenum VertexShader::getType()
return GL_VERTEX_SHADER; return GL_VERTEX_SHADER;
} }
void VertexShader::uncompile()
{
Shader::uncompile();
// set by ParseAttributes
mAttributes.clear();
};
void VertexShader::compile() void VertexShader::compile()
{ {
uncompile();
compileToHLSL(mVertexCompiler); compileToHLSL(mVertexCompiler);
parseAttributes(); parseAttributes();
parseVaryings(); parseVaryings();
...@@ -545,6 +574,8 @@ GLenum FragmentShader::getType() ...@@ -545,6 +574,8 @@ GLenum FragmentShader::getType()
void FragmentShader::compile() void FragmentShader::compile()
{ {
uncompile();
compileToHLSL(mFragmentCompiler); compileToHLSL(mFragmentCompiler);
parseVaryings(); parseVaryings();
mVaryings.sort(compareVarying); mVaryings.sort(compareVarying);
......
...@@ -62,6 +62,7 @@ class Shader ...@@ -62,6 +62,7 @@ class Shader
void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer); void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer);
virtual void compile() = 0; virtual void compile() = 0;
virtual void uncompile();
bool isCompiled(); bool isCompiled();
const char *getHLSL(); const char *getHLSL();
...@@ -134,6 +135,7 @@ class VertexShader : public Shader ...@@ -134,6 +135,7 @@ class VertexShader : public Shader
virtual GLenum getType(); virtual GLenum getType();
virtual void compile(); virtual void compile();
virtual void uncompile();
int getSemanticIndex(const std::string &attributeName); int getSemanticIndex(const std::string &attributeName);
private: 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