]> git.mxchange.org Git - simgear.git/commitdiff
Canvas::Path: reduce number of OpenGL state changes.
authorThomas Geymayer <tomgey@gmail.com>
Tue, 1 Apr 2014 10:03:53 +0000 (12:03 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Tue, 1 Apr 2014 10:03:53 +0000 (12:03 +0200)
 - 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
simgear/canvas/elements/CanvasPath.cxx

index 005c9c690207ae7990e566c9b28a868f42d147f0..4eb2fd27c6fd1b74a6c12990a5a2bddddac0cf59 100644 (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
   }
   
   
index 07d06babef88c9fb48ef71800c026c9820f90f99..a2026369f89e7a7957c47fe45abc1345076ba961 100644 (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