Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit ccbaf38f authored by Maire Nicolas's avatar Maire Nicolas
Browse files

Gestion correcte du passage de zéro plans de clipping à n plans et vice versa

parent 1915119d
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
/** /**
* get the clipping planes count used for plane clipping * get the clipping planes count used for plane clipping
*/ */
int getClippingPlanesCount() { return (int)m_clipPlanesEquations.size(); } int getClippingPlanesCount() { return (int)m_clipPlanesEquations.size() / 4; }
/** /**
* update uniforms (get their locations and resend their values) for clipping * update uniforms (get their locations and resend their values) for clipping
...@@ -130,6 +130,16 @@ private: ...@@ -130,6 +130,16 @@ private:
*/ */
void sendColorAttenuationFactorUniform(); void sendColorAttenuationFactorUniform();
/**
* stored original vertex shader source code (without clipping)
*/
std::string originalVertShaderSrc;
/**
* stored original fragment shader source code (without clipping)
*/
std::string originalFragShaderSrc;
/** /**
* clip planes equations (a, b, c, d)*planes count * clip planes equations (a, b, c, d)*planes count
*/ */
......
...@@ -49,19 +49,19 @@ public: ...@@ -49,19 +49,19 @@ public:
ShaderMutator(const std::string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc); ShaderMutator(const std::string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc);
/** /**
* check if a variable is declared in the vertex shader source or not * check if a variable is declared in the vertex shader source
* @param variableName the variable to search for * @param variableName the variable to search for
*/ */
bool VS_containsVariableDeclaration(const std::string& variableName); bool VS_containsVariableDeclaration(const std::string& variableName);
/** /**
* check if a variable is declared in the fragment shader source or not * check if a variable is declared in the fragment shader source
* @param variableName the variable to search for * @param variableName the variable to search for
*/ */
bool FS_containsVariableDeclaration(const std::string& variableName); bool FS_containsVariableDeclaration(const std::string& variableName);
/** /**
* check if a variable is declared in the geometry shader source or not * check if a variable is declared in the geometry shader source
* @param variableName the variable to search for * @param variableName the variable to search for
*/ */
bool GS_containsVariableDeclaration(const std::string& variableName); bool GS_containsVariableDeclaration(const std::string& variableName);
......
...@@ -148,15 +148,20 @@ float ClippingShader::getClippingColorAttenuationFactor() ...@@ -148,15 +148,20 @@ float ClippingShader::getClippingColorAttenuationFactor()
void ClippingShader::setPlaneClipping(int planesCount) void ClippingShader::setPlaneClipping(int planesCount)
{ {
// Verify that the given clipping planes count is valid
if (planesCount < 0)
{
CGoGNerr
<< "ERROR - "
<< "ClippingShader::setPlanesClipping"
<< " - Given clipping planes count given is not positive !"
<< CGoGNendl;
return;
}
// Shader name // Shader name
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
// String for clipping planes count
std::string planesCountStr;
std::stringstream ss;
ss << planesCount;
planesCountStr = ss.str();
// Verify that the shader has been well created // Verify that the shader has been well created
if (!isCreated()) if (!isCreated())
{ {
...@@ -183,16 +188,11 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -183,16 +188,11 @@ void ClippingShader::setPlaneClipping(int planesCount)
return; return;
} }
// Verify that the given clipping planes count is valid // String for clipping planes count
if (planesCount < 0) std::string planesCountStr;
{ std::stringstream ss;
CGoGNerr ss << planesCount;
<< "ERROR - " planesCountStr = ss.str();
<< "ClippingShader::setPlanesClipping"
<< " - Given clipping planes count given is not positive !"
<< CGoGNendl;
return;
}
// Strings that will be inserted into the source code // Strings that will be inserted into the source code
...@@ -260,8 +260,19 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -260,8 +260,19 @@ void ClippingShader::setPlaneClipping(int planesCount)
" gl_FragColor.rgb /= (1.0 + clip_MinDistanceToPlanes*clip_ColorAttenuationFactor);\n"; " gl_FragColor.rgb /= (1.0 + clip_MinDistanceToPlanes*clip_ColorAttenuationFactor);\n";
// If the previous plane count was zero, the previous shader source codes were the original ones. Store them
if (getClippingPlanesCount() == 0)
{
originalVertShaderSrc = getVertexShaderSrc();
originalFragShaderSrc = getFragmentShaderSrc();
}
// If the given plane count is > 0, modify the original shader sources
if (planesCount > 0)
{
// Use a shader mutator // Use a shader mutator
ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc(), ""); ShaderMutator SM(shaderName, originalVertShaderSrc, originalFragShaderSrc, "");
// First check if the vertex shader contains the VertexPosition attribute // First check if the vertex shader contains the VertexPosition attribute
if (!SM.VS_containsVariableDeclaration("VertexPosition")) if (!SM.VS_containsVariableDeclaration("VertexPosition"))
...@@ -292,6 +303,15 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -292,6 +303,15 @@ void ClippingShader::setPlaneClipping(int planesCount)
reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str()); reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());
}
// Else no clipping is wanted anymore, so get back the original shader sources
else
{
// Reload both original shaders
reloadVertexShaderFromMemory(originalVertShaderSrc.c_str());
reloadFragmentShaderFromMemory(originalFragShaderSrc.c_str());
}
// Resize the planes equations uniform to the right size // Resize the planes equations uniform to the right size
m_clipPlanesEquations.resize(4*(size_t)planesCount, 0.0); m_clipPlanesEquations.resize(4*(size_t)planesCount, 0.0);
...@@ -301,6 +321,10 @@ void ClippingShader::setPlaneClipping(int planesCount) ...@@ -301,6 +321,10 @@ void ClippingShader::setPlaneClipping(int planesCount)
void ClippingShader::updateClippingUniforms() void ClippingShader::updateClippingUniforms()
{ {
// These uniforms only exist if the clipping planes count is > 0
if (getClippingPlanesCount() <= 0)
return;
// Shader name // Shader name
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
......
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