Commit 8b720013 authored by Maire Nicolas's avatar Maire Nicolas

Un peu plus de cleanup dans clippingShader et shaderMutator.

parent f34546ec
...@@ -77,7 +77,7 @@ void StageShader::slot_pushButton_addPlane() ...@@ -77,7 +77,7 @@ void StageShader::slot_pushButton_addPlane()
{ {
m_shader->setClipPlanesCount(dock.comboBox_PlaneIndex->count() + 1); m_shader->setClipPlanesCount(dock.comboBox_PlaneIndex->count() + 1);
m_shader->setClipPlaneOrigin(m_bb.center(), dock.comboBox_PlaneIndex->count() + 1 - 1); m_shader->setClipPlaneParamsOrigin(m_bb.center(), dock.comboBox_PlaneIndex->count() + 1 - 1);
std::string indexStr; std::string indexStr;
std::stringstream ss; std::stringstream ss;
...@@ -110,17 +110,17 @@ void StageShader::slot_comboBox_PlaneIndexChanged(int newIndex) ...@@ -110,17 +110,17 @@ void StageShader::slot_comboBox_PlaneIndexChanged(int newIndex)
{ {
if (newIndex >= 0) if (newIndex >= 0)
{ {
Geom::Vec3f currPlaneVec1 = m_shader->getClipPlaneFirstVec(newIndex); Geom::Vec3f currPlaneVec1 = m_shader->getClipPlaneParamsFirstVec(newIndex);
dock.doubleSpinBox_PlaneVec1x->setValue(currPlaneVec1[0]); dock.doubleSpinBox_PlaneVec1x->setValue(currPlaneVec1[0]);
dock.doubleSpinBox_PlaneVec1y->setValue(currPlaneVec1[1]); dock.doubleSpinBox_PlaneVec1y->setValue(currPlaneVec1[1]);
dock.doubleSpinBox_PlaneVec1z->setValue(currPlaneVec1[2]); dock.doubleSpinBox_PlaneVec1z->setValue(currPlaneVec1[2]);
Geom::Vec3f currPlaneVec2 = m_shader->getClipPlaneSecondVec(newIndex); Geom::Vec3f currPlaneVec2 = m_shader->getClipPlaneParamsSecondVec(newIndex);
dock.doubleSpinBox_PlaneVec2x->setValue(currPlaneVec2[0]); dock.doubleSpinBox_PlaneVec2x->setValue(currPlaneVec2[0]);
dock.doubleSpinBox_PlaneVec2y->setValue(currPlaneVec2[1]); dock.doubleSpinBox_PlaneVec2y->setValue(currPlaneVec2[1]);
dock.doubleSpinBox_PlaneVec2z->setValue(currPlaneVec2[2]); dock.doubleSpinBox_PlaneVec2z->setValue(currPlaneVec2[2]);
Geom::Vec3f currPlaneOrigin = m_shader->getClipPlaneOrigin(newIndex); Geom::Vec3f currPlaneOrigin = m_shader->getClipPlaneParamsOrigin(newIndex);
dock.doubleSpinBox_PlaneOriginx->setValue(currPlaneOrigin[0]); dock.doubleSpinBox_PlaneOriginx->setValue(currPlaneOrigin[0]);
dock.doubleSpinBox_PlaneOriginy->setValue(currPlaneOrigin[1]); dock.doubleSpinBox_PlaneOriginy->setValue(currPlaneOrigin[1]);
dock.doubleSpinBox_PlaneOriginz->setValue(currPlaneOrigin[2]); dock.doubleSpinBox_PlaneOriginz->setValue(currPlaneOrigin[2]);
...@@ -134,7 +134,7 @@ void StageShader::slot_doubleSpinBox_PlaneVec1(double c) ...@@ -134,7 +134,7 @@ void StageShader::slot_doubleSpinBox_PlaneVec1(double c)
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1x->value(); float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1x->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1y->value(); float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1y->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1z->value(); float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1z->value();
m_shader->setClipPlaneFirstVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex()); m_shader->setClipPlaneParamsFirstVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL(); updateGL();
} }
} }
...@@ -146,7 +146,7 @@ void StageShader::slot_doubleSpinBox_PlaneVec2(double c) ...@@ -146,7 +146,7 @@ void StageShader::slot_doubleSpinBox_PlaneVec2(double c)
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2x->value(); float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2x->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2y->value(); float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2y->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2z->value(); float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2z->value();
m_shader->setClipPlaneSecondVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex()); m_shader->setClipPlaneParamsSecondVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL(); updateGL();
} }
} }
...@@ -158,7 +158,7 @@ void StageShader::slot_doubleSpinBox_PlaneOrigin(double c) ...@@ -158,7 +158,7 @@ void StageShader::slot_doubleSpinBox_PlaneOrigin(double c)
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginx->value(); float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginx->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginy->value(); float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginy->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginz->value(); float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginz->value();
m_shader->setClipPlaneOrigin(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex()); m_shader->setClipPlaneParamsOrigin(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL(); updateGL();
} }
} }
......
...@@ -43,22 +43,51 @@ namespace Utils ...@@ -43,22 +43,51 @@ namespace Utils
class ClippingShader : public GLSLShader class ClippingShader : public GLSLShader
{ {
/***********************************************
*
* Constructor / Destructor
*
***********************************************/
public :
/// constructor
ClippingShader();
/// destructor
~ClippingShader();
/***********************************************
*
* Miscellaneous Stuff
*
***********************************************/
public: public:
/** /// enum used to choose which type of clip plane grid to display
* enum used to choose which type of clip plane grid to display
*/
enum clipPlaneDisplayGridType { STRAIGHT_GRID, RADIAL_GRID }; enum clipPlaneDisplayGridType { STRAIGHT_GRID, RADIAL_GRID };
/**
* constructor /***********************************************
*/ *
ClippingShader(); * Plane Clipping
*
***********************************************/
/** /**
* destructor * set the clip planes count
* - inserts plane clipping instructions into vertex and fragment shader source code
* - does not modify the geometry shader source code
* @param planesCount the clip planes count to use
* @warning this function is designed for shaders which *do not* use a geometry shader
*/ */
~ClippingShader(); void setClipPlanesCount(int planesCount);
/// get the clip planes count
int getClipPlanesCount();
/** /**
* set all parameters for one clip plane * set all parameters for one clip plane
...@@ -68,7 +97,7 @@ public: ...@@ -68,7 +97,7 @@ public:
* @param origin point of the plane that will be used as origin to display it * @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
void setClipPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0); void setClipPlaneParamsAll(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);
/** /**
* set first vector for one clip plane * set first vector for one clip plane
...@@ -76,7 +105,7 @@ public: ...@@ -76,7 +105,7 @@ public:
* @param vec1 first basis vector * @param vec1 first basis vector
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
void setClipPlaneFirstVec(Geom::Vec3f vec1, int planeIndex = 0); void setClipPlaneParamsFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
/** /**
* set second vector for one clip plane * set second vector for one clip plane
...@@ -84,7 +113,7 @@ public: ...@@ -84,7 +113,7 @@ public:
* @param vec2 second basis vector * @param vec2 second basis vector
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
void setClipPlaneSecondVec(Geom::Vec3f vec2, int planeIndex = 0); void setClipPlaneParamsSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
/** /**
* set origin for one clip plane * set origin for one clip plane
...@@ -92,46 +121,30 @@ public: ...@@ -92,46 +121,30 @@ public:
* @param origin point of the plane that will be used as origin to display it * @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
void setClipPlaneOrigin(Geom::Vec3f origin, int planeIndex = 0); void setClipPlaneParamsOrigin(Geom::Vec3f origin, int planeIndex = 0);
/** /**
* get first vector for one clip plane * get first vector for one clip plane
* @warning planeIndex starts at 0 * @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
Geom::Vec3f getClipPlaneFirstVec(int planeIndex = 0); Geom::Vec3f getClipPlaneParamsFirstVec(int planeIndex = 0);
/** /**
* get second vector for one clip plane * get second vector for one clip plane
* @warning planeIndex starts at 0 * @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
Geom::Vec3f getClipPlaneSecondVec(int planeIndex = 0); Geom::Vec3f getClipPlaneParamsSecondVec(int planeIndex = 0);
/** /**
* get origin for one clip plane * get origin for one clip plane
* @warning planeIndex starts at 0 * @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify * @param planeIndex index of the plane to modify
*/ */
Geom::Vec3f getClipPlaneOrigin(int planeIndex = 0); Geom::Vec3f getClipPlaneParamsOrigin(int planeIndex = 0);
/** /// display all clipping planes
* set the clip planes count
* - inserts plane clipping instructions into vertex and fragment shader source code
* but does not modify the geometry shader source code
* @param planesCount the clip planes count to use
* @warning this function is designed for shaders which *do not* use a geometry shader
*/
void setClipPlanesCount(int planesCount);
/**
* get the clip planes count
*/
int getClipPlanesCount() { return (int)m_clipPlanes.size(); }
/**
* display all clipping planes
*/
void displayClipPlanes(); void displayClipPlanes();
/** /**
...@@ -140,9 +153,7 @@ public: ...@@ -140,9 +153,7 @@ public:
*/ */
void setPlaneDisplayColor(Geom::Vec3f color) { m_clipPlanesDisplayColor = color; updateAllClippingPlanesVBOs(); } void setPlaneDisplayColor(Geom::Vec3f color) { m_clipPlanesDisplayColor = color; updateAllClippingPlanesVBOs(); }
/** /// get the planes display color
* get the planes display color
*/
Geom::Vec3f getPlaneDisplayColor() { return m_clipPlanesDisplayColor; } Geom::Vec3f getPlaneDisplayColor() { return m_clipPlanesDisplayColor; }
/** /**
...@@ -151,9 +162,7 @@ public: ...@@ -151,9 +162,7 @@ public:
*/ */
void setPlaneDisplayType(clipPlaneDisplayGridType gridType) { m_clipPlanesDisplayType = gridType; updateAllClippingPlanesVBOs(); } void setPlaneDisplayType(clipPlaneDisplayGridType gridType) { m_clipPlanesDisplayType = gridType; updateAllClippingPlanesVBOs(); }
/** /// get the planes display grids type
* get the planes display grids type
*/
clipPlaneDisplayGridType getPlaneDisplayType() { return m_clipPlanesDisplayType; } clipPlaneDisplayGridType getPlaneDisplayType() { return m_clipPlanesDisplayType; }
/** /**
...@@ -162,9 +171,7 @@ public: ...@@ -162,9 +171,7 @@ public:
*/ */
void setPlaneDisplayXRes(size_t res) { m_clipPlanesDisplayXRes = res; updateAllClippingPlanesVBOs(); } void setPlaneDisplayXRes(size_t res) { m_clipPlanesDisplayXRes = res; updateAllClippingPlanesVBOs(); }
/** /// get the planes display grid x resolution
* get the planes display grid x resolution
*/
size_t getPlaneDisplayXRes() { return m_clipPlanesDisplayXRes; } size_t getPlaneDisplayXRes() { return m_clipPlanesDisplayXRes; }
/** /**
...@@ -173,57 +180,63 @@ public: ...@@ -173,57 +180,63 @@ public:
*/ */
void setPlaneDisplayYRes(size_t res) { m_clipPlanesDisplayYRes = res; updateAllClippingPlanesVBOs(); } void setPlaneDisplayYRes(size_t res) { m_clipPlanesDisplayYRes = res; updateAllClippingPlanesVBOs(); }
/** /// get the planes display grid y resolution
* get the planes display grid y resolution
*/
size_t getPlaneDisplayYRes() { return m_clipPlanesDisplayYRes; } size_t getPlaneDisplayYRes() { return m_clipPlanesDisplayYRes; }
/** /**
* set the planes display size * set the planes display size
* @param size the new size * @param size the new size
*/ */
void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size;/*sendClippingPlanesUniform();*/updateAllClippingPlanesVBOs(); } void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size; updateAllClippingPlanesVBOs(); }
/** /// get the planes display size
* get the planes display size
*/
float getPlaneDisplaySize() { return m_clipPlanesDisplaySize; } float getPlaneDisplaySize() { return m_clipPlanesDisplaySize; }
/***********************************************
*
* Global Clipping Stuff
*
***********************************************/
/** /**
* set the color attenuation factor for clipping * set the color attenuation factor for clipping
* @param colorAttenuationFactor color attenuation factor * @param colorAttenuationFactor color attenuation factor
*/ */
void setClipColorAttenuationFactor(float colorAttenuationFactor); void setClipColorAttenuationFactor(float colorAttenuationFactor);
/** /// get the color attenuation factor for clipping
* get the color attenuation factor for clipping float getClipColorAttenuationFactor();
*/
float getClipColorAttenuationFactor() { return m_colorAttenuationFactor; }
/**
* update uniforms (get their locations and send their values again) for clipping /***********************************************
*/ *
* Clipping Uniforms Handling
*
***********************************************/
/// update uniforms (get their locations and send their values again) for clipping
void updateClippingUniforms(); void updateClippingUniforms();
/***********************************************
*
* Private Section
*
***********************************************/
private: private:
/** /// clip planes structure
* clip planes structure
*/
struct clipPlane struct clipPlane
{ {
Geom::Vec3f firstVec, secondVec, origin; Geom::Vec3f firstVec, secondVec, origin;
}; };
/** /// sends the clip planes arrays to shader
* sends the clip planes arrays to shader
*/
void sendClippingPlanesUniform(); void sendClippingPlanesUniform();
/** /// sends the color attenuation factor to shader
* sends the color attenuation factor to shader
*/
void sendColorAttenuationFactorUniform(); void sendColorAttenuationFactorUniform();
/** /**
...@@ -238,24 +251,16 @@ private: ...@@ -238,24 +251,16 @@ private:
*/ */
void updateClippingPlaneVBO(int planeIndex); void updateClippingPlaneVBO(int planeIndex);
/** /// update VBOs for all planes
* update VBOs for all planes
*/
void updateAllClippingPlanesVBOs(); void updateAllClippingPlanesVBOs();
/** /// original vertex shader source code (without clipping)
* original vertex shader source code (without clipping)
*/
std::string originalVertShaderSrc; std::string originalVertShaderSrc;
/** /// original fragment shader source code (without clipping)
* original fragment shader source code (without clipping)
*/
std::string originalFragShaderSrc; std::string originalFragShaderSrc;
/** /// clip planes array
* clip planes array
*/
std::vector<clipPlane> m_clipPlanes; std::vector<clipPlane> m_clipPlanes;
/** /**
...@@ -264,49 +269,31 @@ private: ...@@ -264,49 +269,31 @@ private:
*/ */
std::vector<float> m_clipPlanesEquations; std::vector<float> m_clipPlanesEquations;
/** /// clip planes equations vector uniform id
* clip planes equations vector uniform id
*/
GLint m_unif_clipPlanesEquations; GLint m_unif_clipPlanesEquations;
/** /// color attenuation factor
* color attenuation factor
*/
float m_colorAttenuationFactor; float m_colorAttenuationFactor;
/** /// color attenuation factor uniform id
* color attenuation factor uniform id
*/
GLint m_unif_colorAttenuationFactor; GLint m_unif_colorAttenuationFactor;
/** /// clip planes drawers array
* clip planes drawers array
*/
std::vector<Drawer*> m_clipPlanesDrawers; std::vector<Drawer*> m_clipPlanesDrawers;
/** /// clip planes display color
* clip planes display color
*/
Geom::Vec3f m_clipPlanesDisplayColor; Geom::Vec3f m_clipPlanesDisplayColor;
/** /// clip planes display grid type
* clip planes display grid type
*/
clipPlaneDisplayGridType m_clipPlanesDisplayType; clipPlaneDisplayGridType m_clipPlanesDisplayType;
/** /// clip planes x grid display resolution
* clip planes x grid display resolution
*/
size_t m_clipPlanesDisplayXRes; size_t m_clipPlanesDisplayXRes;
/** /// clip planes y grid display resolution
* clip planes y grid display resolution
*/
size_t m_clipPlanesDisplayYRes; size_t m_clipPlanesDisplayYRes;
/** /// clip planes display size
* clip planes display size
*/
float m_clipPlanesDisplaySize; float m_clipPlanesDisplaySize;
}; };
......
...@@ -41,9 +41,7 @@ class ShaderMutator ...@@ -41,9 +41,7 @@ class ShaderMutator
public: public:
/** /// enum used to choose which shader src type to modify
* enum used to choose which shader src type to modify
*/
enum shaderSrcType { VERTEX_SHADER, FRAGMENT_SHADER, GEOMETRY_SHADER }; enum shaderSrcType { VERTEX_SHADER, FRAGMENT_SHADER, GEOMETRY_SHADER };
/** /**
...@@ -98,41 +96,27 @@ public: ...@@ -98,41 +96,27 @@ public:
*/ */
void insertCodeAtMainFunctionEnd(shaderSrcType srcType, 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
*/
std::string getModifiedVertexShaderSrc() { return m_vShaderMutation; } std::string getModifiedVertexShaderSrc() { return m_vShaderMutation; }
/** /// returns the modified fragment shader source code
* returns the modified fragment shader source code
*/
std::string getModifiedFragmentShaderSrc() { return m_fShaderMutation; } std::string getModifiedFragmentShaderSrc() { return m_fShaderMutation; }
/** /// returns the modified geometry shader source code
* returns the modified geometry shader source code
*/
std::string getModifiedGeometryShaderSrc() { return m_gShaderMutation; } std::string getModifiedGeometryShaderSrc() { return m_gShaderMutation; }
private: private:
/** /// processed shader name stored for log purpose
* processed shader name stored for log purpose
*/
std::string m_shaderName; std::string m_shaderName;
/** /// modified version of the original vertex shader source code
* modified version of the original vertex shader source code
*/
std::string m_vShaderMutation; std::string m_vShaderMutation;
/** /// modified version of the original fragment shader source code
* modified version of the original fragment shader source code
*/
std::string m_fShaderMutation; std::string m_fShaderMutation;
/** /// modified version of the original geometry shader source code
* modified version of the original geometry shader source code
*/
std::string m_gShaderMutation; std::string m_gShaderMutation;
/** /**
......
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