Commit 69e6238c authored by Maire Nicolas's avatar Maire Nicolas

Inclusion du code du shader dans clippingShader. Implémentation de toutes les...

Inclusion du code du shader dans clippingShader. Implémentation de toutes les fonctions relatives au clipping par sphères.
parent 003f4f5a
......@@ -197,16 +197,6 @@ void StageShader::slot_doubleSpinBox_GridColor(double c)
updateGL();
}
void StageShader::slot_horizontalSlider_GridType(int i)
{
if (i == 0)
m_shader->setClipPlanesDisplayType(Utils::ClippingShader::STRAIGHT_GRID);
else if (i == 1)
m_shader->setClipPlanesDisplayType(Utils::ClippingShader::RADIAL_GRID);
updateGL();
}
void StageShader::button_compile()
{
QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText();
......@@ -278,7 +268,6 @@ void StageShader::initGUI()
setCallBack(dock.doubleSpinBox_GridColorR, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_GridColor(double)));
setCallBack(dock.doubleSpinBox_GridColorG, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_GridColor(double)));
setCallBack(dock.doubleSpinBox_GridColorB, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_GridColor(double)));
setCallBack(dock.horizontalSlider_GridType, SIGNAL(valueChanged(int)), SLOT(slot_horizontalSlider_GridType(int)));
setCallBack(dock.compileButton, SIGNAL(clicked()), SLOT(button_compile()) );
......@@ -293,10 +282,6 @@ void StageShader::initGUI()
dock.doubleSpinBox_GridColorR->setValue(col[0]);
dock.doubleSpinBox_GridColorG->setValue(col[1]);
dock.doubleSpinBox_GridColorB->setValue(col[2]);
if (m_shader->getClipPlanesDisplayType() == Utils::ClippingShader::STRAIGHT_GRID)
dock.horizontalSlider_GridType->setValue(0);
else if (m_shader->getClipPlanesDisplayType() == Utils::ClippingShader::RADIAL_GRID)
dock.horizontalSlider_GridType->setValue(1);
}
void StageShader::cb_Open()
......@@ -385,6 +370,8 @@ void StageShader::cb_initGL()
m_shader->setClipPlanesDisplayColor(Geom::Vec3f (1.0, 0.0, 0.0));
m_shader->setClipPlanesDisplayXRes(10);
m_shader->setClipPlanesDisplayYRes(5);
m_shader->insertClippingCode();
}
void StageShader::updateVBOprimitives(int upType)
......
......@@ -138,7 +138,6 @@ public slots:
void slot_spinBox_GridResolutionX(int i);
void slot_spinBox_GridResolutionY(int i);
void slot_doubleSpinBox_GridColor(double c);
void slot_horizontalSlider_GridType(int i);
void button_compile();
};
......
......@@ -34,7 +34,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget_3">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_Object">
<attribute name="title">
......@@ -308,23 +308,6 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_GridType">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSlider" name="horizontalSlider_GridType">
<property name="maximum">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
......
......@@ -33,6 +33,7 @@
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
namespace CGoGN
{
......@@ -59,21 +60,6 @@ public :
~ClippingShader();
/***********************************************
*
* Original Shader Sources
*
***********************************************/
private:
/// original vertex shader source code (without clipping)
std::string originalVertShaderSrc;
/// original fragment shader source code (without clipping)
std::string originalFragShaderSrc;
/***********************************************
*
* Plane Clipping
......@@ -84,10 +70,8 @@ public:
/**
* 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
* @warning insertClippingCode must be called first
*/
void setClipPlanesCount(int planesCount);
......@@ -131,21 +115,21 @@ public:
/**
* get first vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
* @param planeIndex index of the plane
*/
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
* @param planeIndex index of the plane
*/
Geom::Vec3f getClipPlaneParamsSecondVec(int planeIndex);
/**
* get origin for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
* @param planeIndex index of the plane
*/
Geom::Vec3f getClipPlaneParamsOrigin(int planeIndex);
......@@ -184,9 +168,6 @@ private:
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();
......@@ -199,15 +180,6 @@ public:
/// get the planes display color
Geom::Vec3f getClipPlanesDisplayColor();
/**
* set the planes display grids type
* @param gridType the new grid type
*/
void setClipPlanesDisplayType(clipPlaneDisplayGridType gridType);
/// get the planes display grids type
clipPlaneDisplayGridType getClipPlanesDisplayType();
/**
* set the planes display grid x resolution
* @param res the new resolution
......@@ -252,9 +224,6 @@ private:
/// 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;
......@@ -265,6 +234,153 @@ private:
float m_clipPlanesDisplaySize;
/***********************************************
*
* Sphere Clipping
*
***********************************************/
public:
/**
* set the clip spheres count
* @param spheresCount the clip spheres count to use
* @warning insertClippingCode must be called first
*/
void setClipSpheresCount(int spheresCount);
/// get the clip spheres count
int getClipSpheresCount();
/**
* set all parameters for one clip sphere
* @warning sphereIndex starts at 0
* @param center center
* @param radius radius
* @param sphereIndex index of the sphere to modify
*/
void setClipSphereParamsAll(Geom::Vec3f center, float radius, int sphereIndex);
/**
* set center for one clip sphere
* @warning sphereIndex starts at 0
* @param center center
* @param sphereIndex index of the sphere to modify
*/
void setClipSphereParamsCenter(Geom::Vec3f center, int sphereIndex);
/**
* set radius for one clip sphere
* @warning sphereIndex starts at 0
* @param radius radius
* @param sphereIndex index of the sphere to modify
*/
void setClipSphereParamsRadius(float radius, int sphereIndex);
/**
* get center for one clip sphere
* @warning sphereIndex starts at 0
* @param sphereIndex index of the sphere
*/
Geom::Vec3f getClipSphereParamsCenter(int sphereIndex);
/**
* get radius for one clip sphere
* @warning sphereIndex starts at 0
* @param sphereIndex index of the sphere
*/
float getClipSphereParamsRadius(int sphereIndex);
private:
/**
* update clip sphere center and radius array
* @param sphereIndex index of the sphere
*/
void updateClipSphereArray(int sphereIndex);
/// clip spheres structure
struct clipSphere
{
Geom::Vec3f center;
float radius;
};
/// clip spheres array
std::vector<clipSphere> m_clipSpheres;
/**
* clip spheres centers and radiuses array (size = 4*(spheres count))
* - ** only used for sending sphere data to shader **
*/
std::vector<float> m_clipSpheresCentersAndRadiuses;
/// clip spheres equations vector uniform id
GLint m_unif_clipSpheresCentersAndRadiuses;
/***********************************************
*
* Sphere Clipping Display
*
***********************************************/
public:
/// display all clipping spheres
void displayClipSpheres();
/**
* set the spheres display color
* @param color the new color
*/
void setClipSpheresDisplayColor(Geom::Vec3f color);
/// get the spheres display color
Geom::Vec3f getClipSpheresDisplayColor();
/**
* set the spheres display grid x resolution
* @param res the new resolution
*/
void setClipSpheresDisplayXRes(size_t res);
/// get the spheres display grid x resolution
size_t getClipSpheresDisplayXRes();
/**
* set the spheres display grid y resolution
* @param res the new resolution
*/
void setClipSpheresDisplayYRes(size_t res);
/// get the spheres display grid y resolution
size_t getClipSpheresDisplayYRes();
private:
/**
* update VBO for one sphere
* @param sphereIndex index of the sphere
*/
void updateClipSphereVBO(int sphereIndex);
/// update VBOs for all spheres
void updateClipSpheresVBOs();
/// clip spheres drawers array
std::vector<Drawer*> m_clipSpheresDrawers;
/// clip spheres display color
Geom::Vec3f m_clipSpheresDisplayColor;
/// clip spheres x grid display resolution
size_t m_clipSpheresDisplayXRes;
/// clip spheres y grid display resolution
size_t m_clipSpheresDisplayYRes;
/***********************************************
*
* Global Clipping Stuff
......@@ -273,6 +389,12 @@ private:
public:
/**
* insert clipping instructions into shader source code
* @warning this function is designed for shaders which *do not* use a geometry shader
*/
bool insertClippingCode();
/**
* set the color attenuation factor for clipping
* @param colorAttenuationFactor color attenuation factor
......@@ -284,6 +406,9 @@ public:
private:
/// to control clipping code has been inserted before clipping objects have been added
bool m_hasClippingCodeBeenInserted;
/// color attenuation factor
float m_clipColorAttenuationFactor;
......@@ -307,6 +432,9 @@ private:
/// sends the clip planes equations array to shader
void sendClipPlanesEquationsUniform();
/// sends the clip spheres centers and radiuses array to shader
void sendClipSpheresCentersAndRadiusesUniform();
/// sends the color attenuation factor to shader
void sendClipColorAttenuationFactorUniform();
......@@ -328,11 +456,12 @@ private:
bool errorRaiseParameterIsNotPositive(bool condition, const std::string& location, const std::string& paramName);
/**
* Output a "shader has not been well created" error if the condition is satisfied
* Output a "shader source is empty" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
* @param shaderType type of the shader
*/
bool errorRaiseShaderHasNotBeenWellCreated(bool condition, const std::string& location);
bool errorRaiseShaderSourceIsEmpty(bool condition, const std::string& location, ShaderMutator::shaderSrcType shaderType);
/**
* Output a "shader uses a geometry shader" error if the condition is satisfied
......@@ -366,6 +495,20 @@ private:
*/
bool errorRaiseUniformNotFoundInShader(bool condition, const std::string& location, const std::string& uniformName);
/**
* Output a "clipping code was already inserted" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
*/
bool errorRaiseClippingCodeAlreadyInserted(bool condition, const std::string& location);
/**
* Output a "clipping code has not been inserted yet" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
*/
bool errorRaiseClippingCodeNotInserted(bool condition, const std::string& location);
};
......
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