Decorate all GLSL user-defined names with an underscore to avoid name clashes

TRAC #11314 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@143 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 5ac52159
...@@ -41,6 +41,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -41,6 +41,7 @@ class OutputHLSL : public TIntermTraverser
static TString typeString(const TType &type); static TString typeString(const TType &type);
static TString arrayString(const TType &type); static TString arrayString(const TType &type);
static TString initializer(const TType &type); static TString initializer(const TType &type);
static TString decorate(const TString &string); // Prepend an underscore to avoid naming clashes
TParseContext &mContext; TParseContext &mContext;
......
...@@ -1261,7 +1261,7 @@ void Context::applyState() ...@@ -1261,7 +1261,7 @@ void Context::applyState()
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
GLint frontCCW = programObject->getUniformLocation("__frontCCW"); GLint frontCCW = programObject->getUniformLocation("gl_frontCCW");
GLint ccw = (frontFace == GL_CCW); GLint ccw = (frontFace == GL_CCW);
programObject->setUniform1iv(frontCCW, 1, &ccw); programObject->setUniform1iv(frontCCW, 1, &ccw);
......
...@@ -195,7 +195,7 @@ GLint Program::getUniformLocation(const char *name) ...@@ -195,7 +195,7 @@ GLint Program::getUniformLocation(const char *name)
{ {
for (unsigned int location = 0; location < mUniforms.size(); location++) for (unsigned int location = 0; location < mUniforms.size(); location++)
{ {
if (mUniforms[location]->name == name) if (mUniforms[location]->name == decorate(name))
{ {
return location; return location;
} }
...@@ -1250,6 +1250,19 @@ Uniform *Program::createUniform(const D3DXCONSTANT_DESC &constantDescription, st ...@@ -1250,6 +1250,19 @@ Uniform *Program::createUniform(const D3DXCONSTANT_DESC &constantDescription, st
return 0; return 0;
} }
// This methods needs to match OutputHLSL::decorate
std::string Program::decorate(const std::string &string)
{
if (string.substr(0, 3) != "gl_")
{
return "_" + string;
}
else
{
return string;
}
}
bool Program::applyUniform1bv(GLint location, GLsizei count, const GLboolean *v) bool Program::applyUniform1bv(GLint location, GLsizei count, const GLboolean *v)
{ {
BOOL *vector = new BOOL[count]; BOOL *vector = new BOOL[count];
......
...@@ -112,6 +112,7 @@ class Program ...@@ -112,6 +112,7 @@ class Program
bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = ""); bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = "");
bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
static std::string decorate(const std::string &string); // Prepend an underscore
bool applyUniform1bv(GLint location, GLsizei count, const GLboolean *v); bool applyUniform1bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform2bv(GLint location, GLsizei count, const GLboolean *v); bool applyUniform2bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform3bv(GLint location, GLsizei count, const GLboolean *v); bool applyUniform3bv(GLint location, GLsizei count, const GLboolean *v);
......
...@@ -348,7 +348,7 @@ void VertexShader::parseAttributes() ...@@ -348,7 +348,7 @@ void VertexShader::parseAttributes()
char attributeName[100]; char attributeName[100];
int semanticIndex; int semanticIndex;
int matches = sscanf(input, "%s : TEXCOORD%d;", attributeName, &semanticIndex); int matches = sscanf(input, "_%s : TEXCOORD%d;", attributeName, &semanticIndex);
if (matches == 2) if (matches == 2)
{ {
......
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