Commit b72c15a4 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

add option to pass gl_ClipDistance[] through geometry shader

parent 8b1648d7
...@@ -1615,6 +1615,20 @@ void ShaderProgGenerator::buildGeometryShader() ...@@ -1615,6 +1615,20 @@ void ShaderProgGenerator::buildGeometryShader()
mainCode.push_back("gl_Position = gl_in[inIdx].gl_Position;"); mainCode.push_back("gl_Position = gl_in[inIdx].gl_Position;");
mainCode.push_back("gl_PrimitiveID = gl_PrimitiveIDIn;"); mainCode.push_back("gl_PrimitiveID = gl_PrimitiveIDIn;");
// built-in gl_ClipDistance[]
static int maxClipDistances = -1;
if (maxClipDistances < 0)
{
glGetIntegerv(GL_MAX_CLIP_DISTANCES, &maxClipDistances);
maxClipDistances = std::min(maxClipDistances, 32); // clamp to 32 bits
}
for (int i = 0; i < maxClipDistances; ++i)
{
if (desc_.clipDistanceMask & (1 << i))
mainCode.push_back(QString("gl_ClipDistance[%1] = gl_in[inIdx].gl_ClipDistance[%1];").arg(i));
}
// custom IO // custom IO
for (int i = 0; i < geometry_->getNumInputs(); ++i) for (int i = 0; i < geometry_->getNumInputs(); ++i)
{ {
...@@ -2720,7 +2734,7 @@ QString ShaderGenDesc::toString() const ...@@ -2720,7 +2734,7 @@ QString ShaderGenDesc::toString() const
resStrm << "version: " << version; resStrm << "version: " << version;
resStrm << "shaderDesc.numLights: " << numLights; resStrm << "\nshaderDesc.numLights: " << numLights;
if (numLights) if (numLights)
{ {
......
...@@ -102,6 +102,7 @@ public: ...@@ -102,6 +102,7 @@ public:
fragmentTemplateFile(""), fragmentTemplateFile(""),
normalizeTexColors(true), normalizeTexColors(true),
colorMaterialMode(GL_AMBIENT_AND_DIFFUSE), colorMaterialMode(GL_AMBIENT_AND_DIFFUSE),
clipDistanceMask(0),
textureTypes_(), textureTypes_(),
texGenDim(0), texGenDim(0),
texGenMode(GL_EYE_LINEAR), texGenMode(GL_EYE_LINEAR),
...@@ -178,6 +179,11 @@ public: ...@@ -178,6 +179,11 @@ public:
// default: GL_AMBIENT_AND_DIFFUSE // default: GL_AMBIENT_AND_DIFFUSE
GLenum colorMaterialMode; GLenum colorMaterialMode;
// Bitmask of enabled hardware clip planes.
// Bit i represents the i'th clip plane starting at the least significant bit.
// This is needed to pass the gl_ClipDistance[] array through the geometry shader stage.
uint clipDistanceMask;
struct TextureType struct TextureType
{ {
GLenum type; GLenum type;
...@@ -279,6 +285,13 @@ public: ...@@ -279,6 +285,13 @@ public:
return false; return false;
} }
if (!geometryTemplateFile.isEmpty())
{
// clip distance mask only affects the geometry shader
if (clipDistanceMask != _rhs.clipDistanceMask)
return false;
}
if (fragmentTemplateFile != _rhs.fragmentTemplateFile) if (fragmentTemplateFile != _rhs.fragmentTemplateFile)
return false; return false;
......
...@@ -248,6 +248,8 @@ void ClippingNode::ClippingObjectModifier::apply(RenderObject* _obj) ...@@ -248,6 +248,8 @@ void ClippingNode::ClippingObjectModifier::apply(RenderObject* _obj)
// set shader modifier // set shader modifier
_obj->shaderDesc.shaderMods.push_back(shaderModID); _obj->shaderDesc.shaderMods.push_back(shaderModID);
// enable clip distance pass through in geometry shader
_obj->shaderDesc.clipDistanceMask = _obj->clipDistanceMask;
} }
//============================================================================= //=============================================================================
......
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