Commit fde3961a authored by Maire Nicolas's avatar Maire Nicolas

Rajout d'une méthode dans ShaderMutator pour changer la valeur d'une constante...

Rajout d'une méthode dans ShaderMutator pour changer la valeur d'une constante de type int + gros cleanup.
parent 0c7e7d06
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
...@@ -269,22 +269,6 @@ ...@@ -269,22 +269,6 @@
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>check_drawFaces</sender>
<signal>toggled(bool)</signal>
<receiver>combo_faceLighting</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>65</x>
<y>98</y>
</hint>
<hint type="destinationlabel">
<x>65</x>
<y>127</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>check_drawNormals</sender> <sender>check_drawNormals</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
......
...@@ -27,9 +27,6 @@ ...@@ -27,9 +27,6 @@
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "glm/glm.hpp"
#include "Geometry/matrix.h"
#include "Utils/trackball.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
#include "Utils/shaderMutator.h" #include "Utils/shaderMutator.h"
#include "Utils/drawer.h" #include "Utils/drawer.h"
......
...@@ -40,6 +40,12 @@ class ShaderMutator ...@@ -40,6 +40,12 @@ class ShaderMutator
{ {
public: public:
/**
* enums used to choose which shader src to modify
*/
enum shaderSrcType { VERTEX_SHADER, FRAGMENT_SHADER, GEOMETRY_SHADER };
/** /**
* constructor * constructor
* @param vertShaderSrc the vertex shader source to store * @param vertShaderSrc the vertex shader source to store
...@@ -49,85 +55,48 @@ public: ...@@ -49,85 +55,48 @@ public:
ShaderMutator(const std::string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc); ShaderMutator(const std::string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc);
/** /**
* check if a variable is declared in the vertex shader source * check if a variable is declared in the shader source
* @param srcType the shader source to use (vertex, fragment or geometry)
* @param variableName the variable to search for * @param variableName the variable to search for
*/ */
bool VS_containsVariableDeclaration(const std::string& variableName); bool containsVariableDeclaration(shaderSrcType srcType, const std::string& variableName);
/**
* check if a variable is declared in the fragment shader source
* @param variableName the variable to search for
*/
bool FS_containsVariableDeclaration(const std::string& variableName);
/** /**
* check if a variable is declared in the geometry shader source * set or change shading language version in the shader source
* @param variableName the variable to search for * - only if the current version is lower
*/ * @param srcType the shader source to use (vertex, fragment or geometry)
bool GS_containsVariableDeclaration(const std::string& variableName);
/**
* set or change shading language version if the current version is lower
* @param version the version to set (110, 120, 150...) * @param version the version to set (110, 120, 150...)
*/ */
void VS_FS_GS_setMinShadingLanguageVersion(int version); void setMinShadingLanguageVersion(shaderSrcType srcType, int version);
/** /**
* insert code before main function into shader vertex source code * change int constant value in the shader source
* @param insertedCode source code to insert into shader * @param srcType the shader source to use (vertex, fragment or geometry)
*/ * @param newVal the new value
void VS_insertCodeBeforeMainFunction(const std::string& insertedCode);
/**
* insert code before main function into shader fragment source code
* @param insertedCode source code to insert into shader
*/
void FS_insertCodeBeforeMainFunction(const std::string& insertedCode);
/**
* insert code before main function into shader geometry source code
* @param insertedCode source code to insert into shader
*/ */
void GS_insertCodeBeforeMainFunction(const std::string& insertedCode); void changeIntConstantValue(shaderSrcType srcType, int newVal);
/**
* insert code at the beginning of main function into shader vertex source code
* @param insertedCode source code to insert into shader
*/
void VS_insertCodeAtMainFunctionBeginning(const std::string& insertedCode);
/**
* insert code at the beginning of main function into shader fragment source code
* @param insertedCode source code to insert into shader
*/
void FS_insertCodeAtMainFunctionBeginning(const std::string& insertedCode);
/**
* insert code at the beginning of main function into shader geometry source code
* @param insertedCode source code to insert into shader
*/
void GS_insertCodeAtMainFunctionBeginning(const std::string& insertedCode);
/** /**
* insert code at the beginning of main function into shader vertex source code * insert code before main function into shader source
* @warning takes the number of opening and closing braces of main function into account * @param srcType the shader source to use (vertex, fragment or geometry)
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
*/ */
void VS_insertCodeAtMainFunctionEnd(const std::string& insertedCode); void insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode);
/** /**
* insert code at the beginning of main function into shader fragment source code * insert code at the beginning of main function into shader source
* @warning takes the number of opening and closing braces of main function into account * @param srcType the shader source to use (vertex, fragment or geometry)
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
*/ */
void FS_insertCodeAtMainFunctionEnd(const std::string& insertedCode); void insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode);
/** /**
* insert code at the beginning of main function into shader geometry source code * insert code at the end of main function into 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 the shader source to use (vertex, fragment or geometry)
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
*/ */
void GS_insertCodeAtMainFunctionEnd(const std::string& insertedCode); void insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode);
/** /**
* returns the modified vertex shader source code * returns the modified vertex shader source code
...@@ -167,52 +136,59 @@ private: ...@@ -167,52 +136,59 @@ private:
std::string m_gShaderMutation; std::string m_gShaderMutation;
/** /**
* verify if the given position in the string is commented or not * check if the given position in the source is commented
* @param pos the position * @param pos the position
* @param str the string to analyze * @param src the source to analyze
*/ */
bool isCommented(size_t pos, const std::string& str); bool srcIsCommented(size_t pos, const std::string& src);
/** /**
* verify if the given position in the string is commented with a one-line comment or not * check if the given position in the source is commented with a one-line comment
* @param pos the position * @param pos the position
* @param str the string to analyze * @param src the source to analyze
*/ */
bool isOneLineCommented(size_t pos, const std::string& str); bool srcIsOneLineCommented(size_t pos, const std::string& src);
/** /**
* check if a variable is declared in a source code or not * check if a variable is declared in a source code
* @param variable the variable to search for * @param variable the variable to search for
*/ */
bool containsVariableDeclaration(const std::string& variableName, std::string& src); bool srcContainsVariableDeclaration(const std::string& variableName, std::string& src);
/** /**
* set or change shading language version if the current version is lower * set or change shading language version if the current version is lower
* @param version the version to set (110, 120, 150...) * @param version the version to set (110, 120, 150...)
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
*/ */
bool setMinShadingLanguageVersion(int version, std::string& modifiedSrc); bool srcSetMinShadingLanguageVersion(int version, std::string& modifiedSrc);
/**
* change int constant value
* @param newVal the new value
* @param modifiedSrc shader source code to modify
*/
bool srcChangeIntConstantValue(int newVal, std::string& modifiedSrc);
/** /**
* insert code before main function into source code * insert code before main function into source code
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
*/ */
bool insertCodeBeforeMainFunction(const std::string& insertedCode, std::string& modifiedSrc); bool srcInsertCodeBeforeMainFunction(const std::string& insertedCode, std::string& modifiedSrc);
/** /**
* insert code at the beginning of main function into source code * insert code at the beginning of main function into source code
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
*/ */
bool insertCodeAtMainFunctionBeginning(const std::string& insertedCode, std::string& modifiedSrc); bool srcInsertCodeAtMainFunctionBeginning(const std::string& insertedCode, std::string& modifiedSrc);
/** /**
* insert code at the end of main function into source code * insert code at the end of main function into source code
* @param insertedCode source code to insert into shader * @param insertedCode source code to insert into shader
* @param modifiedSrc shader source code to modify * @param modifiedSrc shader source code to modify
*/ */
bool insertCodeAtMainFunctionEnd(const std::string& insertedCode, std::string& modifiedSrc); bool srcInsertCodeAtMainFunctionEnd(const std::string& insertedCode, std::string& modifiedSrc);
}; };
......
...@@ -261,7 +261,8 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -261,7 +261,8 @@ void ClippingShader::setPlaneClipping(int planesCount)
" gl_FragColor.rgb /= (1.0 + clip_MinDistanceToPlanes*clip_ColorAttenuationFactor);\n"; " gl_FragColor.rgb /= (1.0 + clip_MinDistanceToPlanes*clip_ColorAttenuationFactor);\n";
// If the previous plane count was zero, the previous shader source codes were the original ones. Store them // If the previous planes count was zero, the previous shader source codes were the original ones. Store them
// (the planes count is initially zero when the object is constructed)
if (getClippingPlanesCount() == 0) if (getClippingPlanesCount() == 0)
{ {
originalVertShaderSrc = getVertexShaderSrc(); originalVertShaderSrc = getVertexShaderSrc();
...@@ -276,7 +277,7 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -276,7 +277,7 @@ void ClippingShader::setPlaneClipping(int planesCount)
ShaderMutator SM(shaderName, originalVertShaderSrc, originalFragShaderSrc, ""); ShaderMutator SM(shaderName, originalVertShaderSrc, originalFragShaderSrc, "");
// First check if the vertex shader contains the VertexPosition attribute // First check if the vertex shader contains the VertexPosition attribute
if (!SM.VS_containsVariableDeclaration("VertexPosition")) if (!SM.containsVariableDeclaration(ShaderMutator::VERTEX_SHADER, "VertexPosition"))
{ {
CGoGNerr CGoGNerr
<< "ERROR - " << "ERROR - "
...@@ -289,16 +290,15 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -289,16 +290,15 @@ void ClippingShader::setPlaneClipping(int planesCount)
} }
// Modify vertex shader source code // Modify vertex shader source code
SM.VS_insertCodeBeforeMainFunction(VS_head_insertion); SM.insertCodeBeforeMainFunction(ShaderMutator::VERTEX_SHADER, VS_head_insertion);
SM.VS_insertCodeAtMainFunctionBeginning(VS_mainBegin_insertion); SM.insertCodeAtMainFunctionBeginning(ShaderMutator::VERTEX_SHADER, VS_mainBegin_insertion);
// Following code insertions need at least shading language 120 (GLSL arrays)
SM.VS_FS_GS_setMinShadingLanguageVersion(120);
// Modify fragment shader source code // Modify fragment shader source code
SM.FS_insertCodeBeforeMainFunction(FS_head_insertion); SM.setMinShadingLanguageVersion(ShaderMutator::FRAGMENT_SHADER, 120); // Following code insertions need at least shading language 120 (GLSL arrays)
SM.FS_insertCodeAtMainFunctionEnd(FS_mainEnd_insertion); SM.insertCodeBeforeMainFunction(ShaderMutator::FRAGMENT_SHADER, FS_head_insertion);
SM.FS_insertCodeAtMainFunctionBeginning(FS_mainBegin_insertion); SM.insertCodeAtMainFunctionEnd(ShaderMutator::FRAGMENT_SHADER, FS_mainEnd_insertion);
SM.insertCodeAtMainFunctionBeginning(ShaderMutator::FRAGMENT_SHADER, FS_mainBegin_insertion);
// Reload both shaders // Reload both shaders
reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str()); reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
...@@ -356,11 +356,6 @@ void ClippingShader::updateClippingUniforms() ...@@ -356,11 +356,6 @@ void ClippingShader::updateClippingUniforms()
sendColorAttenuationFactorUniform(); sendColorAttenuationFactorUniform();
} }
void ClippingShader::displayClippingPlane()
{
m_planeDrawer->callList();
}
void ClippingShader::sendClippingPlanesUniform() void ClippingShader::sendClippingPlanesUniform()
{ {
bind(); bind();
...@@ -373,6 +368,11 @@ void ClippingShader::sendColorAttenuationFactorUniform() ...@@ -373,6 +368,11 @@ void ClippingShader::sendColorAttenuationFactorUniform()
glUniform1f(m_unif_colorAttenuationFactor, m_colorAttenuationFactor); glUniform1f(m_unif_colorAttenuationFactor, m_colorAttenuationFactor);
} }
void ClippingShader::displayClippingPlane()
{
m_planeDrawer->callList();
}
} // namespace Utils } // namespace Utils
} // namespace CGoGN } // namespace CGoGN
......
...@@ -326,8 +326,6 @@ void GLWidget::keyPressEvent(QKeyEvent* event) ...@@ -326,8 +326,6 @@ void GLWidget::keyPressEvent(QKeyEvent* event)
m_state_modifier = event->modifiers(); m_state_modifier = event->modifiers();
std::cout << "Press : " << m_state_modifier << std::endl;
int k = event->key(); int k = event->key();
if ( (k >= 65) && (k <= 91) && !(event->modifiers() & Qt::ShiftModifier) ) if ( (k >= 65) && (k <= 91) && !(event->modifiers() & Qt::ShiftModifier) )
k += 32; k += 32;
...@@ -343,8 +341,6 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event) ...@@ -343,8 +341,6 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event)
m_state_modifier = event->modifiers(); m_state_modifier = event->modifiers();
int k = event->key(); int k = event->key();
std::cout << "Up : " << m_state_modifier << std::endl;
// align on axis // align on axis
if ((k == 'Z') && (event->modifiers() & Qt::ShiftModifier)) if ((k == 'Z') && (event->modifiers() & Qt::ShiftModifier))
{ {
......
This diff is collapsed.
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