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:
@@ -314,9 +314,9 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Turn antialiasing on/off */
|
/* TODO: Turn antialiasing on/off */
|
||||||
glDisable(GL_LINE_SMOOTH);
|
// glDisable(GL_LINE_SMOOTH);
|
||||||
glDisable(GL_POLYGON_SMOOTH);
|
// glDisable(GL_POLYGON_SMOOTH);
|
||||||
glEnable(GL_MULTISAMPLE);
|
// glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
/* Pick paint if available or default*/
|
/* Pick paint if available or default*/
|
||||||
fill = (context->fillPaint ? context->fillPaint : &context->defaultPaint);
|
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
|
/* TODO: Is there any way to do this safely along
|
||||||
with the paint generation pass?? */
|
with the paint generation pass?? */
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_MULTISAMPLE);
|
// glDisable(GL_MULTISAMPLE);
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||||
shDrawBoundBox(context, p, VG_FILL_PATH);
|
shDrawBoundBox(context, p, VG_FILL_PATH);
|
||||||
|
|
||||||
/* Reset state */
|
/* Reset state */
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
glDisable(GL_BLEND);
|
// glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Turn antialiasing on/off */
|
/* TODO: Turn antialiasing on/off */
|
||||||
glDisable(GL_LINE_SMOOTH);
|
// glDisable(GL_LINE_SMOOTH);
|
||||||
glDisable(GL_POLYGON_SMOOTH);
|
// glDisable(GL_POLYGON_SMOOTH);
|
||||||
glEnable(GL_MULTISAMPLE);
|
// glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
if ((paintModes & VG_STROKE_PATH) &&
|
if ((paintModes & VG_STROKE_PATH) &&
|
||||||
context->strokeLineWidth > 0.0f) {
|
context->strokeLineWidth > 0.0f) {
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (1) {/*context->strokeLineWidth > 1.0f) {*/
|
if (1) {/*context->strokeLineWidth > 1.0f) {*/
|
||||||
|
#endif
|
||||||
if (shIsStrokeCacheValid( context, p ) == VG_FALSE)
|
if (shIsStrokeCacheValid( context, p ) == VG_FALSE)
|
||||||
{
|
{
|
||||||
/* Generate stroke triangles in user space */
|
/* Generate stroke triangles in user space */
|
||||||
@@ -411,15 +412,15 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
|
|||||||
|
|
||||||
/* Clear stencil for sure */
|
/* Clear stencil for sure */
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_MULTISAMPLE);
|
// glDisable(GL_MULTISAMPLE);
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||||
shDrawBoundBox(context, p, VG_STROKE_PATH);
|
shDrawBoundBox(context, p, VG_STROKE_PATH);
|
||||||
|
|
||||||
/* Reset state */
|
/* Reset state */
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
glDisable(GL_BLEND);
|
// glDisable(GL_BLEND);
|
||||||
|
#if 0
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
/* Simulate thin stroke by alpha */
|
/* Simulate thin stroke by alpha */
|
||||||
@@ -438,6 +439,7 @@ VG_API_CALL void vgDrawPath(VGPath path, VGbitfield paintModes)
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -217,9 +217,8 @@ namespace canvas
|
|||||||
state->setClientActiveTextureUnit(0);
|
state->setClientActiveTextureUnit(0);
|
||||||
state->disableAllVertexArrays();
|
state->disableAllVertexArrays();
|
||||||
|
|
||||||
glPushAttrib(~0u); // Don't use GL_ALL_ATTRIB_BITS as on my machine it
|
bool was_blend_enabled = state->getLastAppliedMode(GL_BLEND);
|
||||||
// eg. doesn't include GL_MULTISAMPLE_BIT
|
bool was_stencil_enabled = state->getLastAppliedMode(GL_STENCIL_TEST);
|
||||||
glPushClientAttrib(~0u);
|
|
||||||
|
|
||||||
// Initialize/Update the paint
|
// Initialize/Update the paint
|
||||||
if( _attributes_dirty & STROKE_COLOR )
|
if( _attributes_dirty & STROKE_COLOR )
|
||||||
@@ -269,8 +268,8 @@ namespace canvas
|
|||||||
if( err != VG_NO_ERROR )
|
if( err != VG_NO_ERROR )
|
||||||
SG_LOG(SG_GL, SG_ALERT, "vgError: " << err);
|
SG_LOG(SG_GL, SG_ALERT, "vgError: " << err);
|
||||||
|
|
||||||
glPopAttrib();
|
if( was_blend_enabled ) glEnable(GL_BLEND);
|
||||||
glPopClientAttrib();
|
if( was_stencil_enabled ) glEnable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::BoundingBox getTransformedBounds(const osg::Matrix& mat) const
|
osg::BoundingBox getTransformedBounds(const osg::Matrix& mat) const
|
||||||
|
|||||||
Reference in New Issue
Block a user