Commit ded869be authored by Maire Nicolas's avatar Maire Nicolas

Cleanup dans shaderMutator.

parent 3b0e0cdd
...@@ -56,6 +56,7 @@ public: ...@@ -56,6 +56,7 @@ public:
* checks if a variable is declared in the shader source * checks if a variable is declared in the shader source
* @param srcType shader source to use * @param srcType shader source to use
* @param variableName variable to search for * @param variableName variable to search for
* @return true if the variable was declared
*/ */
bool containsVariableDeclaration(shaderSrcType srcType, const std::string& variableName); bool containsVariableDeclaration(shaderSrcType srcType, const std::string& variableName);
...@@ -64,37 +65,42 @@ public: ...@@ -64,37 +65,42 @@ public:
* - only if the current version is lower * - only if the current version is lower
* @param srcType shader source to use * @param srcType shader source to use
* @param version version to set (110, 120, 150...) * @param version version to set (110, 120, 150...)
* @return true if the version was set or changed
*/ */
void setMinShadingLanguageVersion(shaderSrcType srcType, int version); bool setMinShadingLanguageVersion(shaderSrcType srcType, int version);
/** /**
* changes int constant value in the shader source * changes int constant value in the shader source
* @param srcType shader source to use * @param srcType shader source to use
* @param newVal new constant value * @param newVal new constant value
* @return true on success
*/ */
void changeIntConstantValue(shaderSrcType srcType, const std::string& constantName, int newVal); bool changeIntConstantValue(shaderSrcType srcType, const std::string& constantName, int newVal);
/** /**
* inserts code before main function in the shader source * inserts code before main function in the shader source
* @param srcType shader source to use * @param srcType shader source to use
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
* @return true on success
*/ */
void insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode); bool insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode);
/** /**
* inserts code at the beginning of main function in the shader source * inserts code at the beginning of main function in the shader source
* @param srcType shader source to use * @param srcType shader source to use
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
* @return true on success
*/ */
void insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode); bool insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode);
/** /**
* inserts code at the end of main function in the shader source * inserts code at the end of main function in the shader source
* @warning takes the number of opening and closing braces of main function into account * @warning takes the number of opening and closing braces of main function into account
* @param srcType shader source to use * @param srcType shader source to use
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
* @return true on success
*/ */
void insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode); bool insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode);
/// returns the modified vertex shader source code /// returns the modified vertex shader source code
std::string getModifiedVertexShaderSrc() { return m_vShaderMutation; } std::string getModifiedVertexShaderSrc() { return m_vShaderMutation; }
...@@ -123,13 +129,15 @@ private: ...@@ -123,13 +129,15 @@ private:
* checks if the given position is commented * checks if the given position is commented
* @param pos position in the source (like in a string) * @param pos position in the source (like in a string)
* @param src source to analyze * @param src source to analyze
* @return true if the given position is commented
*/ */
bool srcIsCommented(size_t pos, const std::string& src); bool srcIsCommented(size_t pos, const std::string& src);
/** /**
* checks if the given position is commented with a one-line comment * checks if the given position is one-line commented
* @param pos position in the source (like in a string) * @param pos position in the source (like in a string)
* @param src source to analyze * @param src source to analyze
* @return true if the given position is one-line commented
*/ */
bool srcIsOneLineCommented(size_t pos, const std::string& src); bool srcIsOneLineCommented(size_t pos, const std::string& src);
...@@ -137,6 +145,7 @@ private: ...@@ -137,6 +145,7 @@ private:
* checks if a variable is declared * checks if a variable is declared
* @param variableName variable to search for * @param variableName variable to search for
* @param src source to analyze * @param src source to analyze
* @return true if the variable was declared
*/ */
bool srcContainsVariableDeclaration(const std::string& variableName, std::string& src); bool srcContainsVariableDeclaration(const std::string& variableName, std::string& src);
...@@ -144,6 +153,7 @@ private: ...@@ -144,6 +153,7 @@ private:
* sets or changes shading language version if the current version is lower * sets or changes shading language version if the current version is lower
* @param version version to set (110, 120, 150...) * @param version version to set (110, 120, 150...)
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
* @return true if the version was set or changed
*/ */
bool srcSetMinShadingLanguageVersion(int version, std::string& modifiedSrc); bool srcSetMinShadingLanguageVersion(int version, std::string& modifiedSrc);
...@@ -152,6 +162,7 @@ private: ...@@ -152,6 +162,7 @@ private:
* @param newVal new constant value * @param newVal new constant value
* @param constantName constant name as it is declared * @param constantName constant name as it is declared
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
* @return true on success
*/ */
bool srcChangeIntConstantValue(int newVal, const std::string& constantName, std::string& modifiedSrc); bool srcChangeIntConstantValue(int newVal, const std::string& constantName, std::string& modifiedSrc);
...@@ -159,6 +170,7 @@ private: ...@@ -159,6 +170,7 @@ private:
* inserts code before main function * inserts code before main function
* @param insertedCode source code to insert * @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
* @return true on success
*/ */
bool srcInsertCodeBeforeMainFunction(const std::string& insertedCode, std::string& modifiedSrc); bool srcInsertCodeBeforeMainFunction(const std::string& insertedCode, std::string& modifiedSrc);
...@@ -166,6 +178,7 @@ private: ...@@ -166,6 +178,7 @@ private:
* inserts code at the beginning of main function * inserts code at the beginning of main function
* @param insertedCode source code to insert * @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
* @return true on success
*/ */
bool srcInsertCodeAtMainFunctionBeginning(const std::string& insertedCode, std::string& modifiedSrc); bool srcInsertCodeAtMainFunctionBeginning(const std::string& insertedCode, std::string& modifiedSrc);
...@@ -173,6 +186,7 @@ private: ...@@ -173,6 +186,7 @@ private:
* inserts code at the end of main function * inserts code at the end of main function
* @param insertedCode source code to insert * @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
* @return true on success
*/ */
bool srcInsertCodeAtMainFunctionEnd(const std::string& insertedCode, std::string& modifiedSrc); bool srcInsertCodeAtMainFunctionEnd(const std::string& insertedCode, std::string& modifiedSrc);
......
...@@ -71,25 +71,29 @@ bool ShaderMutator::containsVariableDeclaration(shaderSrcType srcType, const std ...@@ -71,25 +71,29 @@ bool ShaderMutator::containsVariableDeclaration(shaderSrcType srcType, const std
return result; return result;
} }
void ShaderMutator::setMinShadingLanguageVersion(shaderSrcType srcType, int version) bool ShaderMutator::setMinShadingLanguageVersion(shaderSrcType srcType, int version)
{ {
bool result = false;
switch (srcType) switch (srcType)
{ {
case VERTEX_SHADER : case VERTEX_SHADER :
srcSetMinShadingLanguageVersion(version, m_vShaderMutation); result = srcSetMinShadingLanguageVersion(version, m_vShaderMutation);
break; break;
case FRAGMENT_SHADER : case FRAGMENT_SHADER :
srcSetMinShadingLanguageVersion(version, m_fShaderMutation); result = srcSetMinShadingLanguageVersion(version, m_fShaderMutation);
break; break;
case GEOMETRY_SHADER : case GEOMETRY_SHADER :
srcSetMinShadingLanguageVersion(version, m_gShaderMutation); result = srcSetMinShadingLanguageVersion(version, m_gShaderMutation);
break; break;
} }
return result;
} }
void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::string& constantName, int newVal) bool ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::string& constantName, int newVal)
{ {
switch (srcType) switch (srcType)
{ {
...@@ -104,7 +108,7 @@ void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::str ...@@ -104,7 +108,7 @@ void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::str
<< ". Constant declaration not found" << ". Constant declaration not found"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -119,7 +123,7 @@ void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::str ...@@ -119,7 +123,7 @@ void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::str
<< ". Constant declaration not found" << ". Constant declaration not found"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -134,13 +138,15 @@ void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::str ...@@ -134,13 +138,15 @@ void ShaderMutator::changeIntConstantValue(shaderSrcType srcType, const std::str
<< ". Constant declaration not found" << ". Constant declaration not found"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
} }
return true;
} }
void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode) bool ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode)
{ {
switch (srcType) switch (srcType)
{ {
...@@ -155,7 +161,7 @@ void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const st ...@@ -155,7 +161,7 @@ void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const st
<< ". You should check if the shader has a main function declaration" << ". You should check if the shader has a main function declaration"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -170,7 +176,7 @@ void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const st ...@@ -170,7 +176,7 @@ void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const st
<< ". You should check if the shader has a main function declaration" << ". You should check if the shader has a main function declaration"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -185,13 +191,15 @@ void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const st ...@@ -185,13 +191,15 @@ void ShaderMutator::insertCodeBeforeMainFunction(shaderSrcType srcType, const st
<< ". You should check if the shader has a main function declaration" << ". You should check if the shader has a main function declaration"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
} }
return true;
} }
void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode) bool ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode)
{ {
switch (srcType) switch (srcType)
{ {
...@@ -206,7 +214,7 @@ void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, con ...@@ -206,7 +214,7 @@ void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, con
<< ". You should check if the shader has a main function declaration" << ". You should check if the shader has a main function declaration"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -221,7 +229,7 @@ void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, con ...@@ -221,7 +229,7 @@ void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, con
<< ". You should check if the shader has a main function declaration" << ". You should check if the shader has a main function declaration"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -236,13 +244,15 @@ void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, con ...@@ -236,13 +244,15 @@ void ShaderMutator::insertCodeAtMainFunctionBeginning(shaderSrcType srcType, con
<< ". You should check if the shader has a main function declaration" << ". You should check if the shader has a main function declaration"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
} }
return true;
} }
void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode) bool ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode)
{ {
switch (srcType) switch (srcType)
{ {
...@@ -258,7 +268,7 @@ void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std ...@@ -258,7 +268,7 @@ void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std
<< "and as many '{' as '}' in main" << "and as many '{' as '}' in main"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -274,7 +284,7 @@ void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std ...@@ -274,7 +284,7 @@ void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std
<< "and as many '{' as '}' in main" << "and as many '{' as '}' in main"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
...@@ -290,10 +300,12 @@ void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std ...@@ -290,10 +300,12 @@ void ShaderMutator::insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std
<< "and as many '{' as '}' in main" << "and as many '{' as '}' in main"
<< CGoGNendl; << CGoGNendl;
return; return false;
} }
break; break;
} }
return true;
} }
......
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