Canvas::Path: reduce number of OpenGL state changes.

- Do not enable any multisampling as for FBOs it is not
   supported anyhow.
 - Just restore GL_BLEND and GL_STENCIL_TEST manually
   => Getting rid of the huge load of glPushAttrib/glPopAttrib
      gets us a huge performance boost, especially for drivers
      with slow state stack implementations.
This commit is contained in:
Thomas Geymayer
2014-04-01 12:03:53 +02:00
parent a160e176da
commit 8c45796dc8
2 changed files with 19 additions and 18 deletions

View File

@@ -314,9 +314,9 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
}
/* TODO: Turn antialiasing on/off */
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
glEnable(GL_MULTISAMPLE);
// glDisable(GL_LINE_SMOOTH);
// glDisable(GL_POLYGON_SMOOTH);
// glEnable(GL_MULTISAMPLE);
/* Pick paint if available or default*/
fill = (context->fillPaint ? context->fillPaint : &context->defaultPaint);
@@ -364,26 +364,27 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
/* TODO: Is there any way to do this safely along
with the paint generation pass?? */
glDisable(GL_BLEND);
glDisable(GL_MULTISAMPLE);
// glDisable(GL_MULTISAMPLE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
shDrawBoundBox(context, p, VG_FILL_PATH);
/* Reset state */
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
// glDisable(GL_BLEND);
}
/* TODO: Turn antialiasing on/off */
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
glEnable(GL_MULTISAMPLE);
// glDisable(GL_LINE_SMOOTH);
// glDisable(GL_POLYGON_SMOOTH);
// glEnable(GL_MULTISAMPLE);
if ((paintModes & VG_STROKE_PATH) &&
context->strokeLineWidth > 0.0f) {
if (1) {/*context->strokeLineWidth > 1.0f) {*/
#if 0
if (1) {/*context->strokeLineWidth > 1.0f) {*/
#endif
if (shIsStrokeCacheValid( context, p ) == VG_FALSE)
{
/* Generate stroke triangles in user space */
@@ -411,15 +412,15 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
/* Clear stencil for sure */
glDisable(GL_BLEND);
glDisable(GL_MULTISAMPLE);
// glDisable(GL_MULTISAMPLE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
shDrawBoundBox(context, p, VG_STROKE_PATH);
/* Reset state */
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
// glDisable(GL_BLEND);
#if 0
}else{
/* Simulate thin stroke by alpha */
@@ -438,6 +439,7 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
#endif
}

View File

@@ -217,9 +217,8 @@ namespace canvas
state->setClientActiveTextureUnit(0);
state->disableAllVertexArrays();
glPushAttrib(~0u); // Don't use GL_ALL_ATTRIB_BITS as on my machine it
// eg. doesn't include GL_MULTISAMPLE_BIT
glPushClientAttrib(~0u);
bool was_blend_enabled = state->getLastAppliedMode(GL_BLEND);
bool was_stencil_enabled = state->getLastAppliedMode(GL_STENCIL_TEST);
// Initialize/Update the paint
if( _attributes_dirty & STROKE_COLOR )
@@ -269,8 +268,8 @@ namespace canvas
if( err != VG_NO_ERROR )
SG_LOG(SG_GL, SG_ALERT, "vgError: " << err);
glPopAttrib();
glPopClientAttrib();
if( was_blend_enabled ) glEnable(GL_BLEND);
if( was_stencil_enabled ) glEnable(GL_STENCIL_TEST);
}
osg::BoundingBox getTransformedBounds(const osg::Matrix& mat) const