Skip to content
Permalink
Browse files

GFX3D: The polygon clipping stage now occurs before any polygon sorti…

…ng, allowing for the sorting of smaller lists. This can be a significant performance improvement for some 3D scenes with high polygon counts.

- 3D renderers no longer perform polygon clipping themselves, instead relying on GFX3D to do it. By default, the clipping mode is ClipperMode_DetermineClipOnly, but 3D renderers can change this by overriding the virtual method Render3D::GetPreferredPolygonClippingMode() and returning their preferred clipping mode.
  • Loading branch information...
rogerman committed Jan 24, 2019
1 parent b8e85e0 commit e06d11f6df8c2e35d570412c45f5a63e5e7c031d
@@ -4239,6 +4239,10 @@ Render3DError OpenGLRenderer_1_2::BeginRender(const GFX3D &engine)
return OGLERROR_BEGINGL_FAILED;
}

this->_clippedPolyCount = engine.clippedPolyCount;
this->_clippedPolyOpaqueCount = engine.clippedPolyOpaqueCount;
this->_clippedPolyList = engine.clippedPolyList;

if (this->isVBOSupported)
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, OGLRef.vboGeometryVtxID);
@@ -4256,8 +4260,6 @@ Render3DError OpenGLRenderer_1_2::BeginRender(const GFX3D &engine)
}

// Generate the clipped polygon list.
this->_PerformClipping<ClipperMode_DetermineClipOnly>(engine.vertList, engine.polylist, &engine.indexlist);

this->_renderNeedsDepthEqualsTest = false;
for (size_t i = 0, vertIndexCount = 0; i < this->_clippedPolyCount; i++)
{
@@ -5531,15 +5533,17 @@ Render3DError OpenGLRenderer_2_0::BeginRender(const GFX3D &engine)
return OGLERROR_BEGINGL_FAILED;
}

this->_clippedPolyCount = engine.clippedPolyCount;
this->_clippedPolyOpaqueCount = engine.clippedPolyOpaqueCount;
this->_clippedPolyList = engine.clippedPolyList;

glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboGeometryVtxID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboGeometryIndexID);

// Only copy as much vertex data as we need to, since this can be a potentially large upload size.
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VERT) * engine.vertListCount, engine.vertList);

// Generate the clipped polygon list.
this->_PerformClipping<ClipperMode_DetermineClipOnly>(engine.vertList, engine.polylist, &engine.indexlist);

this->_renderNeedsDepthEqualsTest = false;
for (size_t i = 0, vertIndexCount = 0; i < this->_clippedPolyCount; i++)
{
@@ -2153,6 +2153,10 @@ Render3DError OpenGLRenderer_3_2::BeginRender(const GFX3D &engine)
return OGLERROR_BEGINGL_FAILED;
}

this->_clippedPolyCount = engine.clippedPolyCount;
this->_clippedPolyOpaqueCount = engine.clippedPolyOpaqueCount;
this->_clippedPolyList = engine.clippedPolyList;

glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboGeometryVtxID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboGeometryIndexID);

@@ -2213,8 +2217,6 @@ Render3DError OpenGLRenderer_3_2::BeginRender(const GFX3D &engine)
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(this->_pendingRenderStates), &this->_pendingRenderStates);

// Generate the clipped polygon list.
this->_PerformClipping<ClipperMode_DetermineClipOnly>(engine.vertList, engine.polylist, &engine.indexlist);

if ( (OGLRef.uboPolyStatesID != 0) && (this->_clippedPolyCount > MAX_CLIPPED_POLY_COUNT_FOR_UBO) )
{
// In practice, there shouldn't be any game scene with a clipped polygon count that
Oops, something went wrong.

0 comments on commit e06d11f

Please sign in to comment.
You can’t perform that action at this time.