[Kstars-devel] branches/kstars/hdevalence/kstars/kstars

Henry de Valence hdevalence at gmail.com
Fri Jul 23 09:16:04 CEST 2010


SVN commit 1153435 by hdevalence:

Implement Odd-Even fill for convex polygons as described in Ch.14 of the Red 
Book. To test it, uncomment the "#define MAKE_KSTARS_SLOW" line.

We disable the colour buffer, then draw triangle fans that invert the stencil 
buffer. At the end any pixel in even-ly-many triangles is eliminated and any in
odd-ly-many triangles is kept. Then we draw a big polygon using this stencil.

While this temporarily solves the non-concavity issue, it does so at the price 
of killing the framerate: when the Milky Way is enabled, the rendering is twice
as slow -- previously, enabling it had no noticable effect on speed.
This is because of all of the extra triangles it has to draw.

Ideally we would change the data to have only concave polygons, but I'm not 
sure of the format, or whether we will ever want to have other convex data.

CCMAIL:kstars-devel at kde.org



 M  +29 -1     skyglpainter.cpp  


--- branches/kstars/hdevalence/kstars/kstars/skyglpainter.cpp #1153434:1153435
@@ -226,12 +226,40 @@
         isVisibleLast = isVisible;
     }
 
+    //#define MAKE_KSTARS_SLOW TRUE
     if ( polygon.size() ) {
         glDisable(GL_TEXTURE_2D);
+        #ifdef MAKE_KSTARS_SLOW
+        //Set up the stencil buffer and disable the color buffer
+        glClear(GL_STENCIL_BUFFER_BIT);
+        glColorMask(0,0,0,0);
+        glEnable(GL_STENCIL_TEST);
+        glStencilFunc(GL_ALWAYS, 0, 0);
+        glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
+        //Now draw a triangle fan. Because of the GL_INVERT,
+        //this will fill the stencil buffer with odd-even fill.
         glEnableClientState(GL_VERTEX_ARRAY);
         glVertexPointer(2,GL_FLOAT,0, polygon.data() );
+        glDrawArrays(GL_TRIANGLE_FAN, 0, polygon.size());
+        glDisableClientState(GL_VERTEX_ARRAY);
+
+        //Now draw the stencil:
+        glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
+        glColorMask(1,1,1,1);
+        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+        glBegin(GL_QUADS);
+        glVertex2f(0,0);
+        glVertex2f(0,m_sm->height());
+        glVertex2f(m_sm->width(),m_sm->height());
+        glVertex2f(m_sm->width(),0);
+        glEnd();
+        glDisable(GL_STENCIL_TEST);
+        #else
+        glEnableClientState(GL_VERTEX_ARRAY);
+        glVertexPointer(2,GL_FLOAT,0, polygon.data() );
         glDrawArrays(GL_POLYGON, 0, polygon.size() );
         glDisableClientState(GL_VERTEX_ARRAY);
+        #endif
     }
 }
 
@@ -319,7 +347,7 @@
     glLineStipple(1,0xCCCC);
     glEnable(GL_BLEND);
     glBlendFunc(GL_ONE, GL_ONE);
-    
+    glClearStencil(0);
 }
 
 void SkyGLPainter::setBrush(const QBrush& brush)


More information about the Kstars-devel mailing list