Commit 84fe446d authored by Maire Nicolas's avatar Maire Nicolas

Encore beaucoup de cleanup dans ClippingShader.

parent 8b720013
......@@ -171,19 +171,19 @@ void StageShader::slot_doubleSpinBox_ColorAttenuationFactor(double c)
void StageShader::slot_doubleSpinBox_GridDisplaySize(double c)
{
m_shader->setPlaneDisplaySize((float)c);
m_shader->setClipPlanesDisplaySize((float)c);
updateGL();
}
void StageShader::slot_spinBox_GridResolutionX(int i)
{
m_shader->setPlaneDisplayXRes((size_t)i);
m_shader->setClipPlanesDisplayXRes((size_t)i);
updateGL();
}
void StageShader::slot_spinBox_GridResolutionY(int i)
{
m_shader->setPlaneDisplayYRes((size_t)i);
m_shader->setClipPlanesDisplayYRes((size_t)i);
updateGL();
}
......@@ -193,16 +193,16 @@ void StageShader::slot_doubleSpinBox_GridColor(double c)
float g = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_GridColorG->value();
float b = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_GridColorB->value();
m_shader->setPlaneDisplayColor(Geom::Vec3f(r, g, b));
m_shader->setClipPlanesDisplayColor(Geom::Vec3f(r, g, b));
updateGL();
}
void StageShader::slot_horizontalSlider_GridType(int i)
{
if (i == 0)
m_shader->setPlaneDisplayType(Utils::ClippingShader::STRAIGHT_GRID);
m_shader->setClipPlanesDisplayType(Utils::ClippingShader::STRAIGHT_GRID);
else if (i == 1)
m_shader->setPlaneDisplayType(Utils::ClippingShader::RADIAL_GRID);
m_shader->setClipPlanesDisplayType(Utils::ClippingShader::RADIAL_GRID);
updateGL();
}
......@@ -286,16 +286,16 @@ void StageShader::initGUI()
dock.fragmentEdit->setPlainText(QString(m_shader->getFragmentShaderSrc()));
dock.doubleSpinBox_ColorAttenuationFactor->setValue(m_shader->getClipColorAttenuationFactor());
dock.doubleSpinBox_GridDisplaySize->setValue(m_shader->getPlaneDisplaySize());
dock.spinBox_GridResolutionX->setValue(m_shader->getPlaneDisplayXRes());
dock.spinBox_GridResolutionY->setValue(m_shader->getPlaneDisplayYRes());
Geom::Vec3f col = m_shader->getPlaneDisplayColor();
dock.doubleSpinBox_GridDisplaySize->setValue(m_shader->getClipPlanesDisplaySize());
dock.spinBox_GridResolutionX->setValue(m_shader->getClipPlanesDisplayXRes());
dock.spinBox_GridResolutionY->setValue(m_shader->getClipPlanesDisplayYRes());
Geom::Vec3f col = m_shader->getClipPlanesDisplayColor();
dock.doubleSpinBox_GridColorR->setValue(col[0]);
dock.doubleSpinBox_GridColorG->setValue(col[1]);
dock.doubleSpinBox_GridColorB->setValue(col[2]);
if (m_shader->getPlaneDisplayType() == Utils::ClippingShader::STRAIGHT_GRID)
if (m_shader->getClipPlanesDisplayType() == Utils::ClippingShader::STRAIGHT_GRID)
dock.horizontalSlider_GridType->setValue(0);
else if (m_shader->getPlaneDisplayType() == Utils::ClippingShader::RADIAL_GRID)
else if (m_shader->getClipPlanesDisplayType() == Utils::ClippingShader::RADIAL_GRID)
dock.horizontalSlider_GridType->setValue(1);
}
......@@ -356,7 +356,7 @@ void StageShader::importMesh(std::string& filename)
updateGLMatrices() ;
m_shader->setPlaneDisplaySize((m_bb.maxSize())*1.2f);
m_shader->setClipPlanesDisplaySize((m_bb.maxSize())*1.2f);
}
/*******************************************************************************
......@@ -382,9 +382,9 @@ void StageShader::cb_initGL()
registerShader(m_shader);
m_shader->setPlaneDisplayColor(Geom::Vec3f (1.0, 0.0, 0.0));
m_shader->setPlaneDisplayXRes(10);
m_shader->setPlaneDisplayYRes(5);
m_shader->setClipPlanesDisplayColor(Geom::Vec3f (1.0, 0.0, 0.0));
m_shader->setClipPlanesDisplayXRes(10);
m_shader->setClipPlanesDisplayYRes(5);
}
void StageShader::updateVBOprimitives(int upType)
......
......@@ -65,10 +65,13 @@ public :
*
***********************************************/
public:
private:
/// enum used to choose which type of clip plane grid to display
enum clipPlaneDisplayGridType { STRAIGHT_GRID, RADIAL_GRID };
/// original vertex shader source code (without clipping)
std::string originalVertShaderSrc;
/// original fragment shader source code (without clipping)
std::string originalFragShaderSrc;
/***********************************************
......@@ -77,6 +80,8 @@ public:
*
***********************************************/
public:
/**
* set the clip planes count
* - inserts plane clipping instructions into vertex and fragment shader source code
......@@ -97,7 +102,7 @@ public:
* @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify
*/
void setClipPlaneParamsAll(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);
/**
* set first vector for one clip plane
......@@ -105,7 +110,7 @@ public:
* @param vec1 first basis vector
* @param planeIndex index of the plane to modify
*/
void setClipPlaneParamsFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
void setClipPlaneParamsFirstVec(Geom::Vec3f vec1, int planeIndex);
/**
* set second vector for one clip plane
......@@ -113,7 +118,7 @@ public:
* @param vec2 second basis vector
* @param planeIndex index of the plane to modify
*/
void setClipPlaneParamsSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
void setClipPlaneParamsSecondVec(Geom::Vec3f vec2, int planeIndex);
/**
* set origin for one clip plane
......@@ -121,28 +126,66 @@ public:
* @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify
*/
void setClipPlaneParamsOrigin(Geom::Vec3f origin, int planeIndex = 0);
void setClipPlaneParamsOrigin(Geom::Vec3f origin, int planeIndex);
/**
* get first vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClipPlaneParamsFirstVec(int planeIndex = 0);
Geom::Vec3f getClipPlaneParamsFirstVec(int planeIndex);
/**
* get second vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClipPlaneParamsSecondVec(int planeIndex = 0);
Geom::Vec3f getClipPlaneParamsSecondVec(int planeIndex);
/**
* get origin for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClipPlaneParamsOrigin(int planeIndex = 0);
Geom::Vec3f getClipPlaneParamsOrigin(int planeIndex);
private:
/**
* update clip plane equation array
* @param planeIndex index of the plane
*/
void updateClipPlaneArray(int planeIndex);
/// clip planes structure
struct clipPlane
{
Geom::Vec3f firstVec, secondVec, origin;
};
/// clip planes array
std::vector<clipPlane> m_clipPlanes;
/**
* clip planes equations array (size = 4*(planes count))
* - ** only used for sending planes data to shader **
*/
std::vector<float> m_clipPlanesEquations;
/// clip planes equations vector uniform id
GLint m_unif_clipPlanesEquations;
/***********************************************
*
* Plane Clipping Display
*
***********************************************/
public:
/// enum used to choose which type of clip plane grid to display
enum clipPlaneDisplayGridType { STRAIGHT_GRID, RADIAL_GRID };
/// display all clipping planes
void displayClipPlanes();
......@@ -151,46 +194,75 @@ public:
* set the planes display color
* @param color the new color
*/
void setPlaneDisplayColor(Geom::Vec3f color) { m_clipPlanesDisplayColor = color; updateAllClippingPlanesVBOs(); }
void setClipPlanesDisplayColor(Geom::Vec3f color) { m_clipPlanesDisplayColor = color; updateClipPlanesVBOs(); }
/// get the planes display color
Geom::Vec3f getPlaneDisplayColor() { return m_clipPlanesDisplayColor; }
Geom::Vec3f getClipPlanesDisplayColor() { return m_clipPlanesDisplayColor; }
/**
* set the planes display grids type
* @param gridType the new grid type
*/
void setPlaneDisplayType(clipPlaneDisplayGridType gridType) { m_clipPlanesDisplayType = gridType; updateAllClippingPlanesVBOs(); }
void setClipPlanesDisplayType(clipPlaneDisplayGridType gridType) { m_clipPlanesDisplayType = gridType; updateClipPlanesVBOs(); }
/// get the planes display grids type
clipPlaneDisplayGridType getPlaneDisplayType() { return m_clipPlanesDisplayType; }
clipPlaneDisplayGridType getClipPlanesDisplayType() { return m_clipPlanesDisplayType; }
/**
* set the planes display grid x resolution
* @param res the new resolution
*/
void setPlaneDisplayXRes(size_t res) { m_clipPlanesDisplayXRes = res; updateAllClippingPlanesVBOs(); }
void setClipPlanesDisplayXRes(size_t res) { m_clipPlanesDisplayXRes = res; updateClipPlanesVBOs(); }
/// get the planes display grid x resolution
size_t getPlaneDisplayXRes() { return m_clipPlanesDisplayXRes; }
size_t getClipPlanesDisplayXRes() { return m_clipPlanesDisplayXRes; }
/**
* set the planes display grid y resolution
* @param res the new resolution
*/
void setPlaneDisplayYRes(size_t res) { m_clipPlanesDisplayYRes = res; updateAllClippingPlanesVBOs(); }
void setClipPlanesDisplayYRes(size_t res) { m_clipPlanesDisplayYRes = res; updateClipPlanesVBOs(); }
/// get the planes display grid y resolution
size_t getPlaneDisplayYRes() { return m_clipPlanesDisplayYRes; }
size_t getClipPlanesDisplayYRes() { return m_clipPlanesDisplayYRes; }
/**
* set the planes display size
* @param size the new size
*/
void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size; updateAllClippingPlanesVBOs(); }
void setClipPlanesDisplaySize(float size) { m_clipPlanesDisplaySize = size; updateClipPlanesVBOs(); }
/// get the planes display size
float getPlaneDisplaySize() { return m_clipPlanesDisplaySize; }
float getClipPlanesDisplaySize() { return m_clipPlanesDisplaySize; }
private:
/**
* update VBO for one plane
* @param planeIndex index of the plane
*/
void updateClipPlaneVBO(int planeIndex);
/// update VBOs for all planes
void updateClipPlanesVBOs();
/// clip planes drawers array
std::vector<Drawer*> m_clipPlanesDrawers;
/// clip planes display color
Geom::Vec3f m_clipPlanesDisplayColor;
/// clip planes display grid type
clipPlaneDisplayGridType m_clipPlanesDisplayType;
/// clip planes x grid display resolution
size_t m_clipPlanesDisplayXRes;
/// clip planes y grid display resolution
size_t m_clipPlanesDisplayYRes;
/// clip planes display size
float m_clipPlanesDisplaySize;
/***********************************************
......@@ -199,6 +271,8 @@ public:
*
***********************************************/
public:
/**
* set the color attenuation factor for clipping
* @param colorAttenuationFactor color attenuation factor
......@@ -208,6 +282,14 @@ public:
/// get the color attenuation factor for clipping
float getClipColorAttenuationFactor();
private:
/// color attenuation factor
float m_clipColorAttenuationFactor;
/// color attenuation factor uniform id
GLint m_unif_clipColorAttenuationFactor;
/***********************************************
*
......@@ -215,86 +297,18 @@ public:
*
***********************************************/
public:
/// update uniforms (get their locations and send their values again) for clipping
void updateClippingUniforms();
/***********************************************
*
* Private Section
*
***********************************************/
private:
/// clip planes structure
struct clipPlane
{
Geom::Vec3f firstVec, secondVec, origin;
};
/// sends the clip planes arrays to shader
void sendClippingPlanesUniform();
/// sends the clip planes equations array to shader
void sendClipPlanesEquationsUniform();
/// sends the color attenuation factor to shader
void sendColorAttenuationFactorUniform();
/**
* update clip planes parameters arrays
* @param planeIndex index of the plane
*/
void updateClippingPlaneArray(int planeIndex);
/**
* update VBO for one plane
* @param planeIndex index of the plane
*/
void updateClippingPlaneVBO(int planeIndex);
/// update VBOs for all planes
void updateAllClippingPlanesVBOs();
/// original vertex shader source code (without clipping)
std::string originalVertShaderSrc;
/// original fragment shader source code (without clipping)
std::string originalFragShaderSrc;
/// clip planes array
std::vector<clipPlane> m_clipPlanes;
/**
* clip planes equations array (size = 4*(planes count))
* - ** only used for sending planes data to shader **
*/
std::vector<float> m_clipPlanesEquations;
/// clip planes equations vector uniform id
GLint m_unif_clipPlanesEquations;
/// color attenuation factor
float m_colorAttenuationFactor;
/// color attenuation factor uniform id
GLint m_unif_colorAttenuationFactor;
/// clip planes drawers array
std::vector<Drawer*> m_clipPlanesDrawers;
/// clip planes display color
Geom::Vec3f m_clipPlanesDisplayColor;
/// clip planes display grid type
clipPlaneDisplayGridType m_clipPlanesDisplayType;
/// clip planes x grid display resolution
size_t m_clipPlanesDisplayXRes;
/// clip planes y grid display resolution
size_t m_clipPlanesDisplayYRes;
/// clip planes display size
float m_clipPlanesDisplaySize;
void sendClipColorAttenuationFactorUniform();
};
......
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