From 8c45796dc8bb468ff78f490ab646e007d32e0189 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Tue, 1 Apr 2014 12:03:53 +0200 Subject: [PATCH] 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. --- simgear/canvas/ShivaVG/src/shPipeline.c | 28 +++++++++++++------------ simgear/canvas/elements/CanvasPath.cxx | 9 ++++---- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/simgear/canvas/ShivaVG/src/shPipeline.c b/simgear/canvas/ShivaVG/src/shPipeline.c index 005c9c69..4eb2fd27 100644 --- a/simgear/canvas/ShivaVG/src/shPipeline.c +++ b/simgear/canvas/ShivaVG/src/shPipeline.c @@ -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 } diff --git a/simgear/canvas/elements/CanvasPath.cxx b/simgear/canvas/elements/CanvasPath.cxx index 07d06bab..a2026369 100644 --- a/simgear/canvas/elements/CanvasPath.cxx +++ b/simgear/canvas/elements/CanvasPath.cxx @@ -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 -- 2.39.5