* commit 'dedcb46019fae19d5f81f6924025e5ba54a1ec20': 2.0 translator: workaround for nVidia "bug"
This commit is contained in:
@@ -3,18 +3,23 @@
|
|||||||
|
|
||||||
ShaderParser::ShaderParser():ObjectData(SHADER_DATA),
|
ShaderParser::ShaderParser():ObjectData(SHADER_DATA),
|
||||||
m_type(0),
|
m_type(0),
|
||||||
m_src(NULL),
|
m_parsedLines(NULL) {};
|
||||||
m_parsedLines(NULL){};
|
|
||||||
|
|
||||||
ShaderParser::ShaderParser(GLenum type):ObjectData(SHADER_DATA),
|
ShaderParser::ShaderParser(GLenum type):ObjectData(SHADER_DATA),
|
||||||
m_type(type),
|
m_type(type),
|
||||||
m_parsedLines(NULL){};
|
m_parsedLines(NULL) {};
|
||||||
|
|
||||||
void ShaderParser::setSrc(const Version& ver,GLsizei count,const GLchar** strings,const GLint* length){
|
void ShaderParser::setSrc(const Version& ver,GLsizei count,const GLchar** strings,const GLint* length){
|
||||||
for(int i = 0;i<count;i++){
|
for(int i = 0;i<count;i++){
|
||||||
m_src.append(strings[i]);
|
m_src.append(strings[i]);
|
||||||
}
|
}
|
||||||
clearParsedSrc();
|
clearParsedSrc();
|
||||||
|
|
||||||
|
if(getenv("NV_WAR"))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Workaround for nVidia's liberal shader compilation - adding #version token to shader\n");
|
||||||
|
parseGLSLversion();
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
version 1.30.10 is the first version of GLSL Language containing precision qualifiers
|
version 1.30.10 is the first version of GLSL Language containing precision qualifiers
|
||||||
if the glsl version is less than 1.30.10 than we will use a shader parser which omits
|
if the glsl version is less than 1.30.10 than we will use a shader parser which omits
|
||||||
@@ -31,12 +36,29 @@ void ShaderParser::setSrc(const Version& ver,GLsizei count,const GLchar** string
|
|||||||
//XXX: Until proved otherwise, glsl doesn't know/use those precision macros, so we omit then
|
//XXX: Until proved otherwise, glsl doesn't know/use those precision macros, so we omit then
|
||||||
parseOmitPrecision();
|
parseOmitPrecision();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
parseOriginalSrc();
|
||||||
}
|
}
|
||||||
|
const GLchar** ShaderParser::parsedLines() {
|
||||||
|
m_parsedLines = (GLchar*)m_parsedSrc.c_str();
|
||||||
|
return const_cast<const GLchar**> (&m_parsedLines);
|
||||||
|
};
|
||||||
|
|
||||||
const char* ShaderParser::getOriginalSrc(){
|
const char* ShaderParser::getOriginalSrc(){
|
||||||
return m_src.c_str();
|
return m_src.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderParser::parseOriginalSrc() {
|
||||||
|
m_parsedSrc+=m_src;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderParser::parseGLSLversion() {
|
||||||
|
//if no version definition is found
|
||||||
|
if (m_src.find("#version ", 0) == std::string::npos) {
|
||||||
|
m_parsedSrc += "#version 100\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderParser::parseOmitPrecision(){
|
void ShaderParser::parseOmitPrecision(){
|
||||||
|
|
||||||
//defines we need to add in order to Omit precisions qualifiers
|
//defines we need to add in order to Omit precisions qualifiers
|
||||||
@@ -47,16 +69,7 @@ void ShaderParser::parseOmitPrecision(){
|
|||||||
"#define highp \n"
|
"#define highp \n"
|
||||||
"#define precision \n"
|
"#define precision \n"
|
||||||
};
|
};
|
||||||
|
m_parsedSrc+=defines;
|
||||||
//the lengths of defines we need to add in order to Omit precisions qualifiers
|
|
||||||
static GLuint definesLength = strlen(defines);
|
|
||||||
|
|
||||||
const GLchar* origSrc = m_src.c_str();
|
|
||||||
unsigned int origLength = strlen(origSrc);
|
|
||||||
|
|
||||||
m_parsedLines = new GLchar[origLength + definesLength + 1];
|
|
||||||
strncpy(m_parsedLines,defines,definesLength);
|
|
||||||
strcpy(m_parsedLines+definesLength,origSrc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderParser::parseExtendDefaultPrecision(){
|
void ShaderParser::parseExtendDefaultPrecision(){
|
||||||
@@ -68,21 +81,11 @@ void ShaderParser::parseExtendDefaultPrecision(){
|
|||||||
"precision lowp samplerCube;\n"
|
"precision lowp samplerCube;\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
//the length of the precision lines which we need to add to the shader
|
m_parsedSrc+=extend;
|
||||||
static GLint extendLength = strlen(extend);
|
|
||||||
|
|
||||||
const GLchar* origSrc = m_src.c_str();
|
|
||||||
unsigned int origLength = strlen(origSrc);
|
|
||||||
|
|
||||||
m_parsedLines = new GLchar[origLength + extendLength + 1];
|
|
||||||
strncpy(m_parsedLines,extend,extendLength);
|
|
||||||
strcpy(m_parsedLines+extendLength,origSrc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderParser::clearParsedSrc(){
|
void ShaderParser::clearParsedSrc(){
|
||||||
if(m_parsedLines){
|
m_parsedSrc.clear();
|
||||||
delete[] m_parsedLines;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum ShaderParser::getType() {
|
GLenum ShaderParser::getType() {
|
||||||
|
|||||||
@@ -12,17 +12,20 @@ public:
|
|||||||
ShaderParser(GLenum type);
|
ShaderParser(GLenum type);
|
||||||
void setSrc(const Version& ver,GLsizei count,const GLchar** strings,const GLint* length);
|
void setSrc(const Version& ver,GLsizei count,const GLchar** strings,const GLint* length);
|
||||||
const char* getOriginalSrc();
|
const char* getOriginalSrc();
|
||||||
const GLchar** parsedLines(){return const_cast<const GLchar**>(&m_parsedLines);};
|
const GLchar** parsedLines();
|
||||||
GLenum getType();
|
GLenum getType();
|
||||||
~ShaderParser();
|
~ShaderParser();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void parseOriginalSrc();
|
||||||
|
void parseGLSLversion();
|
||||||
void parseOmitPrecision();
|
void parseOmitPrecision();
|
||||||
void parseExtendDefaultPrecision();
|
void parseExtendDefaultPrecision();
|
||||||
void clearParsedSrc();
|
void clearParsedSrc();
|
||||||
|
|
||||||
GLenum m_type;
|
GLenum m_type;
|
||||||
std::string m_src;
|
std::string m_src;
|
||||||
|
std::string m_parsedSrc;
|
||||||
GLchar* m_parsedLines;
|
GLchar* m_parsedLines;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user