Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Thomas Pitiot
CGoGN
Commits
bf53f017
Commit
bf53f017
authored
Jul 25, 2011
by
Maire Nicolas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Un peu de cleanup dans clippingShader.
parent
b458a5ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
78 deletions
+82
-78
include/Utils/clippingShader.h
include/Utils/clippingShader.h
+63
-60
src/Utils/clippingShader.cpp
src/Utils/clippingShader.cpp
+19
-18
No files found.
include/Utils/clippingShader.h
View file @
bf53f017
...
...
@@ -65,65 +65,65 @@ public :
public:
/**
* set the clip planes count
* @param planesCount
the
clip planes count to use
* set
s
the clip planes count
* @param planesCount clip planes count to use
* @warning insertClippingCode must be called first
*/
void
setClipPlanesCount
(
int
planesCount
);
/// get the clip planes count
/// get
s
the clip planes count
int
getClipPlanesCount
();
/**
* set all parameters for one clip plane
* set
s
all parameters for one clip plane
* @warning planeIndex starts at 0
* @param vec1 first basis vector
* @param vec2 second basis vector
* @param origin
point of the plane that will be used as origin to display it
* @param planeIndex index of the plane
to modify
* @param origin
origin
* @param planeIndex index of the plane
*/
void
setClipPlaneParamsAll
(
Geom
::
Vec3f
vec1
,
Geom
::
Vec3f
vec2
,
Geom
::
Vec3f
origin
,
int
planeIndex
);
/**
* set first vector for one clip plane
* set
s
first vector for one clip plane
* @warning planeIndex starts at 0
* @param vec1 first basis vector
* @param planeIndex index of the plane
to modify
* @param planeIndex index of the plane
*/
void
setClipPlaneParamsFirstVec
(
Geom
::
Vec3f
vec1
,
int
planeIndex
);
/**
* set second vector for one clip plane
* set
s
second vector for one clip plane
* @warning planeIndex starts at 0
* @param vec2 second basis vector
* @param planeIndex index of the plane
to modify
* @param planeIndex index of the plane
*/
void
setClipPlaneParamsSecondVec
(
Geom
::
Vec3f
vec2
,
int
planeIndex
);
/**
* set origin for one clip plane
* set
s
origin for one clip plane
* @warning planeIndex starts at 0
* @param origin
point of the plane that will be used as origin to display it
* @param planeIndex index of the plane
to modify
* @param origin
origin
* @param planeIndex index of the plane
*/
void
setClipPlaneParamsOrigin
(
Geom
::
Vec3f
origin
,
int
planeIndex
);
/**
* get first vector for one clip plane
* get
s
first vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane
*/
Geom
::
Vec3f
getClipPlaneParamsFirstVec
(
int
planeIndex
);
/**
* get second vector for one clip plane
* get
s
second vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane
*/
Geom
::
Vec3f
getClipPlaneParamsSecondVec
(
int
planeIndex
);
/**
* get origin for one clip plane
* get
s
origin for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane
*/
...
...
@@ -132,10 +132,10 @@ public:
private:
/**
* update clip plane equation array
* update
s
clip plane equation
uniforms
array
* @param planeIndex index of the plane
*/
void
updateClipPlaneArray
(
int
planeIndex
);
void
updateClipPlane
Uniforms
Array
(
int
planeIndex
);
/// clip planes structure
struct
clipPlane
...
...
@@ -146,13 +146,10 @@ private:
/// clip planes array
std
::
vector
<
clipPlane
>
m_clipPlanes
;
/**
* clip planes equations array (size = 4*(planes count))
* - ** only used for sending planes data to shader **
*/
/// clip planes equations uniforms array
std
::
vector
<
float
>
m_clipPlanesEquations
;
/// clip planes equations
array
uniform id
/// clip planes equations uniform
s array
id
GLint
m_unif_clipPlanesEquations
;
...
...
@@ -165,49 +162,49 @@ private:
public:
/**
* set the clip spheres count
* @param spheresCount
the
clip spheres count to use
* set
s
the clip spheres count
* @param spheresCount clip spheres count to use
* @warning insertClippingCode must be called first
*/
void
setClipSpheresCount
(
int
spheresCount
);
/// get the clip spheres count
/// get
s
the clip spheres count
int
getClipSpheresCount
();
/**
* set all parameters for one clip sphere
* set
s
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
* @param sphereIndex index of the sphere
*/
void
setClipSphereParamsAll
(
Geom
::
Vec3f
center
,
float
radius
,
int
sphereIndex
);
/**
* set center for one clip sphere
* set
s
center for one clip sphere
* @warning sphereIndex starts at 0
* @param center center
* @param sphereIndex index of the sphere
to modify
* @param sphereIndex index of the sphere
*/
void
setClipSphereParamsCenter
(
Geom
::
Vec3f
center
,
int
sphereIndex
);
/**
* set radius for one clip sphere
* set
s
radius for one clip sphere
* @warning sphereIndex starts at 0
* @param radius radius
* @param sphereIndex index of the sphere
to modify
* @param sphereIndex index of the sphere
*/
void
setClipSphereParamsRadius
(
float
radius
,
int
sphereIndex
);
/**
* get center for one clip sphere
* get
s
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
* get
s
radius for one clip sphere
* @warning sphereIndex starts at 0
* @param sphereIndex index of the sphere
*/
...
...
@@ -216,10 +213,10 @@ public:
private:
/**
* update clip sphere center and radius array
* update
s
clip sphere center and radius
uniforms
array
* @param sphereIndex index of the sphere
*/
void
updateClipSphereArray
(
int
sphereIndex
);
void
updateClipSphere
Uniforms
Array
(
int
sphereIndex
);
/// clip spheres structure
struct
clipSphere
...
...
@@ -231,13 +228,10 @@ private:
/// 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 **
*/
/// clip spheres centers and radiuses uniforms array
std
::
vector
<
float
>
m_clipSpheresCentersAndRadiuses
;
/// clip spheres
equations vector
uniform id
/// clip spheres
centers and radiuses
uniform
s array
id
GLint
m_unif_clipSpheresCentersAndRadiuses
;
...
...
@@ -249,36 +243,37 @@ private:
public:
/// enum used to choose
which
clipping mode
to use
/// enum used to choose clipping mode
enum
clippingMode
{
CLIPPING_MODE_AND
,
CLIPPING_MODE_OR
};
/**
* insert clipping instructions into shader source code
* insert
s
clipping instructions into shader source code
* @warning this function is designed for shaders which *do not* use a geometry shader
* @return true if shader was processed successfully
*/
bool
insertClippingCode
();
/**
* set the color attenuation factor
for clipping
* set
s
the color attenuation factor
* @param colorAttenuationFactor color attenuation factor
*/
void
setClipColorAttenuationFactor
(
float
colorAttenuationFactor
);
/// get the color attenuation factor
for clipping
/// get
s
the color attenuation factor
float
getClipColorAttenuationFactor
();
/*
* set the clipping mode
* set
s
the clipping mode
* @param clipMode clipping mode
*/
void
setClipMode
(
clippingMode
clipMode
);
/// get the clipping mode
/// get
s
the clipping mode
clippingMode
getClipMode
();
private:
/// to control clipping code has been inserted before clipping objects
have been added
///
used
to control clipping code has been inserted before
adding
clipping objects
bool
m_hasClippingCodeBeenInserted
;
/// color attenuation factor
...
...
@@ -299,18 +294,18 @@ private:
public:
/// update uniforms (get their locations and send their values again)
for clipping
/// update
s
uniforms (get their locations and send their values again)
void
updateClippingUniforms
();
private:
/// sends the clip planes equations array to shader
/// sends the clip planes equations
uniforms
array to shader
void
sendClipPlanesEquationsUniform
();
/// sends the clip spheres centers and radiuses array to shader
/// sends the clip spheres centers and radiuses
uniforms
array to shader
void
sendClipSpheresCentersAndRadiusesUniform
();
/// sends the color attenuation factor to shader
/// sends the color attenuation factor
uniform
to shader
void
sendClipColorAttenuationFactorUniform
();
...
...
@@ -323,64 +318,72 @@ private:
private:
/**
* Output a "parameter not positive" error if the condition is satisfied
* Output
s
a "parameter not positive" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
* @param paramName name of the parameter
* @return true if the error has been raised
*/
bool
errorRaiseParameterIsNotPositive
(
bool
condition
,
const
std
::
string
&
location
,
const
std
::
string
&
paramName
);
/**
* Output a "shader source is empty" error if the condition is satisfied
* Output
s
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
* @return true if the error has been raised
*/
bool
errorRaiseShaderSourceIsEmpty
(
bool
condition
,
const
std
::
string
&
location
,
ShaderMutator
::
shaderSrcType
shaderType
);
/**
* Output a "shader uses a geometry shader" error if the condition is satisfied
* Output
s
a "shader uses a geometry shader" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
* @return true if the error has been raised
*/
bool
errorRaiseShaderUsesGeometryShader
(
bool
condition
,
const
std
::
string
&
location
);
/**
* Output a ".. not found in shader" error if the condition is satisfied
* Output
s
a ".. not found in shader" 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
* @param varName name of the variable that may not be found
* @return true if the error has been raised
*/
bool
errorRaiseVariableNotFoundInShader
(
bool
condition
,
const
std
::
string
&
location
,
ShaderMutator
::
shaderSrcType
shaderType
,
const
std
::
string
&
varName
);
/**
* Output a "parameter is out of range" error if the condition is satisfied
* Output
s
a "parameter is out of range" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
* @param paramName name of the parameter
* @return true if the error has been raised
*/
bool
errorRaiseParameterIsOutOfRange
(
bool
condition
,
const
std
::
string
&
location
,
const
std
::
string
&
paramName
);
/**
* Output a "uniform .. not found in shader" error if the condition is satisfied
* Output
s
a "uniform .. not found in shader" error if the condition is satisfied
* @param condition condition to satisfy
* @param location name of the function where the error raising is done
* @param uniformName name of the uniform that may not be found
* @return true if the error has been raised
*/
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
* Output
s
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
* @return true if the error has been raised
*/
bool
errorRaiseClippingCodeAlreadyInserted
(
bool
condition
,
const
std
::
string
&
location
);
/**
* Output a "clipping code has not been inserted yet" error if the condition is satisfied
* Output
s
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
* @return true if the error has been raised
*/
bool
errorRaiseClippingCodeNotInserted
(
bool
condition
,
const
std
::
string
&
location
);
...
...
src/Utils/clippingShader.cpp
View file @
bf53f017
...
...
@@ -38,17 +38,18 @@ namespace Utils
***********************************************/
ClippingShader
::
ClippingShader
()
ClippingShader
::
ClippingShader
()
:
// Initialize clipping shapes variables
m_unif_clipPlanesEquations
(
0
),
m_unif_clipSpheresCentersAndRadiuses
(
0
),
// Initialize default global clipping variables
m_hasClippingCodeBeenInserted
(
false
),
m_clipColorAttenuationFactor
(
1.0
),
m_unif_clipColorAttenuationFactor
(
0
),
m_clipMode
(
CLIPPING_MODE_AND
)
{
// Initialize uniforms ids
m_unif_clipPlanesEquations
=
0
;
m_unif_clipSpheresCentersAndRadiuses
=
0
;
m_unif_clipColorAttenuationFactor
=
0
;
// Initialize default global clipping variables
m_hasClippingCodeBeenInserted
=
false
;
m_clipColorAttenuationFactor
=
1.0
;
m_clipMode
=
CLIPPING_MODE_AND
;
}
...
...
@@ -136,7 +137,7 @@ void ClippingShader::setClipPlaneParamsAll(Geom::Vec3f vec1, Geom::Vec3f vec2, G
m_clipPlanes
[
planeIndex
].
origin
=
origin
;
// Update the plane arrays
updateClipPlaneArray
(
planeIndex
);
updateClipPlane
Uniforms
Array
(
planeIndex
);
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform
();
...
...
@@ -159,7 +160,7 @@ void ClippingShader::setClipPlaneParamsFirstVec(Geom::Vec3f vec1, int planeIndex
m_clipPlanes
[
planeIndex
].
firstVec
=
vec1Normalized
;
// Update the plane arrays
updateClipPlaneArray
(
planeIndex
);
updateClipPlane
Uniforms
Array
(
planeIndex
);
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform
();
...
...
@@ -182,7 +183,7 @@ void ClippingShader::setClipPlaneParamsSecondVec(Geom::Vec3f vec2, int planeInde
m_clipPlanes
[
planeIndex
].
secondVec
=
vec2Normalized
;
// Update the plane arrays
updateClipPlaneArray
(
planeIndex
);
updateClipPlane
Uniforms
Array
(
planeIndex
);
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform
();
...
...
@@ -201,7 +202,7 @@ void ClippingShader::setClipPlaneParamsOrigin(Geom::Vec3f origin, int planeIndex
m_clipPlanes
[
planeIndex
].
origin
=
origin
;
// Update the plane arrays
updateClipPlaneArray
(
planeIndex
);
updateClipPlane
Uniforms
Array
(
planeIndex
);
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform
();
...
...
@@ -238,7 +239,7 @@ Geom::Vec3f ClippingShader::getClipPlaneParamsOrigin(int planeIndex)
return
m_clipPlanes
[
planeIndex
].
origin
;
}
void
ClippingShader
::
updateClipPlaneArray
(
int
planeIndex
)
void
ClippingShader
::
updateClipPlane
Uniforms
Array
(
int
planeIndex
)
{
// Check if the given index is out of range
if
(
errorRaiseParameterIsOutOfRange
(((
planeIndex
<
0
)
||
(
planeIndex
>
(
getClipPlanesCount
()
-
1
))),
"ClippingShader::updateClipPlaneArray"
,
"planeIndex"
))
...
...
@@ -330,7 +331,7 @@ void ClippingShader::setClipSphereParamsAll(Geom::Vec3f center, float radius, in
m_clipSpheres
[
sphereIndex
].
radius
=
radius
;
// Update the sphere array
updateClipSphereArray
(
sphereIndex
);
updateClipSphere
Uniforms
Array
(
sphereIndex
);
// Send again the whole spheres centers and radiuses array to shader
sendClipSpheresCentersAndRadiusesUniform
();
...
...
@@ -349,7 +350,7 @@ void ClippingShader::setClipSphereParamsCenter(Geom::Vec3f center, int sphereInd
m_clipSpheres
[
sphereIndex
].
center
=
center
;
// Update the sphere array
updateClipSphereArray
(
sphereIndex
);
updateClipSphere
Uniforms
Array
(
sphereIndex
);
// Send again the whole spheres centers and radiuses array to shader
sendClipSpheresCentersAndRadiusesUniform
();
...
...
@@ -368,7 +369,7 @@ void ClippingShader::setClipSphereParamsRadius(float radius, int sphereIndex)
m_clipSpheres
[
sphereIndex
].
radius
=
radius
;
// Update the sphere array
updateClipSphereArray
(
sphereIndex
);
updateClipSphere
Uniforms
Array
(
sphereIndex
);
// Send again the whole spheres centers and radiuses array to shader
sendClipSpheresCentersAndRadiusesUniform
();
...
...
@@ -395,7 +396,7 @@ float ClippingShader::getClipSphereParamsRadius(int sphereIndex)
return
m_clipSpheres
[
sphereIndex
].
radius
;
}
void
ClippingShader
::
updateClipSphereArray
(
int
sphereIndex
)
void
ClippingShader
::
updateClipSphere
Uniforms
Array
(
int
sphereIndex
)
{
// Check if the given index is out of range
if
(
errorRaiseParameterIsOutOfRange
(((
sphereIndex
<
0
)
||
(
sphereIndex
>
(
getClipSpheresCount
()
-
1
))),
"ClippingShader::updateClipSphereArray"
,
"sphereIndex"
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment