Commit 0300d533 authored by Maire Nicolas's avatar Maire Nicolas

Cleanup dans clippingShader.cpp.

parent 31366e50
...@@ -179,19 +179,20 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal, ...@@ -179,19 +179,20 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal,
Geom::Vec3f normalNormalized = normal; Geom::Vec3f normalNormalized = normal;
normalNormalized.normalize(); normalNormalized.normalize();
if ((normalNormalized != m_clipPlanes[planeIndex].normal) // Check if it is worth updating values !
|| (origin != m_clipPlanes[planeIndex].origin)) if ((normalNormalized == m_clipPlanes[planeIndex].normal)
{ && (origin == m_clipPlanes[planeIndex].origin))
// Copy the given clipping plane parameters return;
m_clipPlanes[planeIndex].normal = normalNormalized;
m_clipPlanes[planeIndex].origin = origin;
// Update the plane arrays // Copy the given clipping plane parameters
updateClipPlaneUniformsArray(id); m_clipPlanes[planeIndex].normal = normalNormalized;
m_clipPlanes[planeIndex].origin = origin;
// Send again the whole planes equations array to shader // Update the plane arrays
sendClipPlanesEquationsUniform(); updateClipPlaneUniformsArray(id);
}
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform();
} }
void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal) void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal)
...@@ -209,17 +210,18 @@ void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f norma ...@@ -209,17 +210,18 @@ void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f norma
Geom::Vec3f normalNormalized = normal; Geom::Vec3f normalNormalized = normal;
normalNormalized.normalize(); normalNormalized.normalize();
if (normalNormalized != m_clipPlanes[planeIndex].normal) // Check if it is worth updating values !
{ if (normalNormalized == m_clipPlanes[planeIndex].normal)
// Copy the given clipping plane parameter return;
m_clipPlanes[planeIndex].normal = normalNormalized;
// Update the plane arrays // Copy the given clipping plane parameter
updateClipPlaneUniformsArray(id); m_clipPlanes[planeIndex].normal = normalNormalized;
// Send again the whole planes equations array to shader // Update the plane arrays
sendClipPlanesEquationsUniform(); updateClipPlaneUniformsArray(id);
}
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform();
} }
void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin) void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin)
...@@ -233,17 +235,18 @@ void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origi ...@@ -233,17 +235,18 @@ void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origi
// Get the corresponding plane index // Get the corresponding plane index
int planeIndex = m_clipPlanesIds[id].index; int planeIndex = m_clipPlanesIds[id].index;
if (origin != m_clipPlanes[planeIndex].origin) // Check if it is worth updating values !
{ if (origin == m_clipPlanes[planeIndex].origin)
// Copy the given clipping plane parameter return;
m_clipPlanes[planeIndex].origin = origin;
// Update the plane arrays // Copy the given clipping plane parameter
updateClipPlaneUniformsArray(id); m_clipPlanes[planeIndex].origin = origin;
// Send again the whole planes equations array to shader // Update the plane arrays
sendClipPlanesEquationsUniform(); updateClipPlaneUniformsArray(id);
}
// Send again the whole planes equations array to shader
sendClipPlanesEquationsUniform();
} }
Geom::Vec3f ClippingShader::getClipPlaneParamsNormal(unsigned int id) Geom::Vec3f ClippingShader::getClipPlaneParamsNormal(unsigned int id)
...@@ -434,19 +437,20 @@ void ClippingShader::setClipSphereParamsAll(unsigned int id, Geom::Vec3f center, ...@@ -434,19 +437,20 @@ void ClippingShader::setClipSphereParamsAll(unsigned int id, Geom::Vec3f center,
// Get the corresponding sphere index // Get the corresponding sphere index
int sphereIndex = m_clipSpheresIds[id].index; int sphereIndex = m_clipSpheresIds[id].index;
if ((center != m_clipSpheres[sphereIndex].center) // Check if it is worth updating values !
|| (radius != m_clipSpheres[sphereIndex].radius)) if ((center == m_clipSpheres[sphereIndex].center)
{ && (radius == m_clipSpheres[sphereIndex].radius))
// Copy the given clipping sphere parameters return;
m_clipSpheres[sphereIndex].center = center;
m_clipSpheres[sphereIndex].radius = radius;
// Update the sphere array // Copy the given clipping sphere parameters
updateClipSphereUniformsArray(id); m_clipSpheres[sphereIndex].center = center;
m_clipSpheres[sphereIndex].radius = radius;
// Send again the whole spheres centers and radiuses array to shader // Update the sphere array
sendClipSpheresCentersAndRadiusesUniform(); updateClipSphereUniformsArray(id);
}
// Send again the whole spheres centers and radiuses array to shader
sendClipSpheresCentersAndRadiusesUniform();
} }
void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f center) void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f center)
...@@ -460,17 +464,18 @@ void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f cent ...@@ -460,17 +464,18 @@ void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f cent
// Get the corresponding sphere index // Get the corresponding sphere index
int sphereIndex = m_clipSpheresIds[id].index; int sphereIndex = m_clipSpheresIds[id].index;
if (center != m_clipSpheres[sphereIndex].center) // Check if it is worth updating values !
{ if (center == m_clipSpheres[sphereIndex].center)
// Copy the given clipping sphere parameter return;
m_clipSpheres[sphereIndex].center = center;
// Update the sphere array // Copy the given clipping sphere parameter
updateClipSphereUniformsArray(id); m_clipSpheres[sphereIndex].center = center;
// Send again the whole spheres centers and radiuses array to shader // Update the sphere array
sendClipSpheresCentersAndRadiusesUniform(); updateClipSphereUniformsArray(id);
}
// Send again the whole spheres centers and radiuses array to shader
sendClipSpheresCentersAndRadiusesUniform();
} }
void ClippingShader::setClipSphereParamsRadius(unsigned int id, float radius) void ClippingShader::setClipSphereParamsRadius(unsigned int id, float radius)
...@@ -484,17 +489,18 @@ void ClippingShader::setClipSphereParamsRadius(unsigned int id, float radius) ...@@ -484,17 +489,18 @@ void ClippingShader::setClipSphereParamsRadius(unsigned int id, float radius)
// Get the corresponding sphere index // Get the corresponding sphere index
int sphereIndex = m_clipSpheresIds[id].index; int sphereIndex = m_clipSpheresIds[id].index;
if (radius != m_clipSpheres[sphereIndex].radius) // Check if it is worth updating values !
{ if (radius == m_clipSpheres[sphereIndex].radius)
// Copy the given clipping sphere parameter return;
m_clipSpheres[sphereIndex].radius = radius;
// Update the sphere array // Copy the given clipping sphere parameter
updateClipSphereUniformsArray(id); m_clipSpheres[sphereIndex].radius = radius;
// Send again the whole spheres centers and radiuses array to shader // Update the sphere array
sendClipSpheresCentersAndRadiusesUniform(); updateClipSphereUniformsArray(id);
}
// Send again the whole spheres centers and radiuses array to shader
sendClipSpheresCentersAndRadiusesUniform();
} }
Geom::Vec3f ClippingShader::getClipSphereParamsCenter(unsigned int id) Geom::Vec3f ClippingShader::getClipSphereParamsCenter(unsigned int id)
...@@ -810,14 +816,15 @@ bool ClippingShader::insertClippingCode() ...@@ -810,14 +816,15 @@ bool ClippingShader::insertClippingCode()
void ClippingShader::setClipColorAttenuationFactor(float colorAttenuationFactor) void ClippingShader::setClipColorAttenuationFactor(float colorAttenuationFactor)
{ {
if (colorAttenuationFactor != m_clipColorAttenuationFactor) // Check if it is worth updating values !
{ if (colorAttenuationFactor == m_clipColorAttenuationFactor)
// Copy the given value return;
m_clipColorAttenuationFactor = colorAttenuationFactor;
// Send again the uniform to shader // Copy the given value
sendClipColorAttenuationFactorUniform(); m_clipColorAttenuationFactor = colorAttenuationFactor;
}
// Send again the uniform to shader
sendClipColorAttenuationFactorUniform();
} }
float ClippingShader::getClipColorAttenuationFactor() float ClippingShader::getClipColorAttenuationFactor()
...@@ -827,48 +834,49 @@ float ClippingShader::getClipColorAttenuationFactor() ...@@ -827,48 +834,49 @@ float ClippingShader::getClipColorAttenuationFactor()
void ClippingShader::setClipColorAttenuationMode(colorAttenuationMode colAttMode) void ClippingShader::setClipColorAttenuationMode(colorAttenuationMode colAttMode)
{ {
if (colAttMode != m_colorAttenuationMode) // Check if it is worth updating values !
{ if (colAttMode == m_colorAttenuationMode)
// Check if the clipping code has been inserted into shader return;
if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipColorAttenuationMode"))
return;
// Shader name string
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
// Copy the given value // Check if the clipping code has been inserted into shader
m_colorAttenuationMode = colAttMode; if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipColorAttenuationMode"))
return;
// Use a shader mutator // Shader name string
ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
// Change color attenuation mode constant // Copy the given value
int newConstantValue; m_colorAttenuationMode = colAttMode;
switch (colAttMode)
{
case COLOR_ATTENUATION_MODE_LINEAR :
newConstantValue = 0;
break;
case COLOR_ATTENUATION_MODE_QUADRATIC : // Use a shader mutator
newConstantValue = 1; ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());
break;
default : // Change color attenuation mode constant
newConstantValue = 0; int newConstantValue;
break; switch (colAttMode)
} {
if (errorRaiseShaderMutatorFailure( case COLOR_ATTENUATION_MODE_LINEAR :
(!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_COLOR_ATTENUATION_MODE", newConstantValue)), newConstantValue = 0;
"ClippingShader::setClipColorAttenuationMode")) break;
return;
// Reload modified shader case COLOR_ATTENUATION_MODE_QUADRATIC :
reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); newConstantValue = 1;
break;
// Recompile shaders (automatically calls updateClippingUniforms) default :
recompile(); newConstantValue = 0;
break;
} }
if (errorRaiseShaderMutatorFailure(
(!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_COLOR_ATTENUATION_MODE", newConstantValue)),
"ClippingShader::setClipColorAttenuationMode"))
return;
// Reload modified shader
reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());
// Recompile shaders (automatically calls updateClippingUniforms)
recompile();
} }
ClippingShader::colorAttenuationMode ClippingShader::getClipColorAttenuationMode() ClippingShader::colorAttenuationMode ClippingShader::getClipColorAttenuationMode()
...@@ -878,48 +886,49 @@ ClippingShader::colorAttenuationMode ClippingShader::getClipColorAttenuationMode ...@@ -878,48 +886,49 @@ ClippingShader::colorAttenuationMode ClippingShader::getClipColorAttenuationMode
void ClippingShader::setClipMode(clippingMode clipMode) void ClippingShader::setClipMode(clippingMode clipMode)
{ {
if (clipMode != m_clipMode) // Check if it is worth updating values !
{ if (clipMode == m_clipMode)
// Check if the clipping code has been inserted into shader return;
if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipMode"))
return;
// Shader name string
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
// Copy the given value // Check if the clipping code has been inserted into shader
m_clipMode = clipMode; if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipMode"))
return;
// Use a shader mutator // Shader name string
ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
// Change clipping mode constant // Copy the given value
int newConstantValue; m_clipMode = clipMode;
switch (clipMode)
{
case CLIPPING_MODE_AND :
newConstantValue = 0;
break;
case CLIPPING_MODE_OR : // Use a shader mutator
newConstantValue = 1; ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());
break;
default : // Change clipping mode constant
newConstantValue = 0; int newConstantValue;
break; switch (clipMode)
} {
if (errorRaiseShaderMutatorFailure( case CLIPPING_MODE_AND :
(!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_MODE", newConstantValue)), newConstantValue = 0;
"ClippingShader::setClipMode")) break;
return;
// Reload modified shader case CLIPPING_MODE_OR :
reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); newConstantValue = 1;
break;
// Recompile shaders (automatically calls updateClippingUniforms) default :
recompile(); newConstantValue = 0;
break;
} }
if (errorRaiseShaderMutatorFailure(
(!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_MODE", newConstantValue)),
"ClippingShader::setClipMode"))
return;
// Reload modified shader
reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());
// Recompile shaders (automatically calls updateClippingUniforms)
recompile();
} }
ClippingShader::clippingMode ClippingShader::getClipMode() ClippingShader::clippingMode ClippingShader::getClipMode()
......
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