VBO:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 9 Dec 2009 14:37:26 +0000 (14:37 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 9 Dec 2009 14:37:26 +0000 (14:37 +0000)
* Fix #19785: curves not drawing with VBO enabled
* Fix #19553: duplicate Window crashes with VBO's

The convention in Blender was to have GL_VERTEX_ARRAY and GL_NORMAL_ARRAY
enabled by default, and other arrays disabled. The VBO drawing code did
not take this into account. I've made these now disabled by default, since
that makes the code clearer in other places too.

source/blender/editors/space_view3d/drawobject.c
source/blender/gpu/intern/gpu_buffers.c
source/blender/gpu/intern/gpu_draw.c

index fa8eee630aa727c53f0e8c082e8c4107afd2e93d..31c12285293916526e3c41d14dd51487ccd1fe61 100644 (file)
@@ -3010,7 +3010,7 @@ static int drawDispListwire(ListBase *dlbase)
 
        if(dlbase==NULL) return 1;
        
-       glDisableClientState(GL_NORMAL_ARRAY);
+       glEnableClientState(GL_VERTEX_ARRAY);
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 
 
        for(dl= dlbase->first; dl; dl= dl->next) {
@@ -3087,7 +3087,7 @@ static int drawDispListwire(ListBase *dlbase)
                }
        }
        
-       glEnableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_VERTEX_ARRAY);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
        
        return 0;
@@ -3106,6 +3106,7 @@ static void drawDispListsolid(ListBase *lb, Object *ob, int glsl)
        glGetFloatv(GL_CURRENT_COLOR, curcol);
 
        glEnable(GL_LIGHTING);
+       glEnableClientState(GL_VERTEX_ARRAY);
        
        if(ob->transflag & OB_NEG_SCALE) glFrontFace(GL_CW);
        else glFrontFace(GL_CCW);
@@ -3164,10 +3165,12 @@ static void drawDispListsolid(ListBase *lb, Object *ob, int glsl)
                                
                                if(dl->rt & CU_SMOOTH) glShadeModel(GL_SMOOTH);
                                else glShadeModel(GL_FLAT);
-                               
+
+                               glEnableClientState(GL_NORMAL_ARRAY);
                                glVertexPointer(3, GL_FLOAT, 0, dl->verts);
                                glNormalPointer(GL_FLOAT, 0, dl->nors);
                                glDrawElements(GL_QUADS, 4*dl->totindex, GL_UNSIGNED_INT, dl->index);
+                               glDisableClientState(GL_NORMAL_ARRAY);
                        }                       
                        break;
 
@@ -3177,32 +3180,35 @@ static void drawDispListsolid(ListBase *lb, Object *ob, int glsl)
                        glVertexPointer(3, GL_FLOAT, 0, dl->verts);
                        
                        /* voor polys only one normal needed */
-                       if(index3_nors_incr==0) {
-                               glDisableClientState(GL_NORMAL_ARRAY);
-                               glNormal3fv(ndata);
+                       if(index3_nors_incr) {
+                               glEnableClientState(GL_NORMAL_ARRAY);
+                               glNormalPointer(GL_FLOAT, 0, dl->nors);
                        }
                        else
-                               glNormalPointer(GL_FLOAT, 0, dl->nors);
+                               glNormal3fv(ndata);
                        
                        glDrawElements(GL_TRIANGLES, 3*dl->parts, GL_UNSIGNED_INT, dl->index);
                        
-                       if(index3_nors_incr==0)
-                               glEnableClientState(GL_NORMAL_ARRAY);
+                       if(index3_nors_incr)
+                               glDisableClientState(GL_NORMAL_ARRAY);
 
                        break;
 
                case DL_INDEX4:
                        GPU_enable_material(dl->col+1, (glsl)? &gattribs: NULL);
                        
+                       glEnableClientState(GL_NORMAL_ARRAY);
                        glVertexPointer(3, GL_FLOAT, 0, dl->verts);
                        glNormalPointer(GL_FLOAT, 0, dl->nors);
                        glDrawElements(GL_QUADS, 4*dl->parts, GL_UNSIGNED_INT, dl->index);
+                       glDisableClientState(GL_NORMAL_ARRAY);
 
                        break;
                }
                dl= dl->next;
        }
 
+       glDisableClientState(GL_VERTEX_ARRAY);
        glShadeModel(GL_FLAT);
        glDisable(GL_LIGHTING);
        glFrontFace(GL_CCW);
@@ -3216,7 +3222,7 @@ static void drawDispListshaded(ListBase *lb, Object *ob)
        if(lb==NULL) return;
 
        glShadeModel(GL_SMOOTH);
-       glDisableClientState(GL_NORMAL_ARRAY);
+       glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        
        dl= lb->first;
@@ -3255,7 +3261,7 @@ static void drawDispListshaded(ListBase *lb, Object *ob)
        }
        
        glShadeModel(GL_FLAT);
-       glEnableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
 }
 
@@ -3996,14 +4002,12 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 /* 6. */
 
        glGetIntegerv(GL_POLYGON_MODE, polygonmode);
-       glDisableClientState(GL_NORMAL_ARRAY);
+       glEnableClientState(GL_VERTEX_ARRAY);
 
        if(draw_as==PART_DRAW_PATH){
                ParticleCacheKey **cache, *path;
                float *cd2=0,*cdata2=0;
 
-               glEnableClientState(GL_VERTEX_ARRAY);
-
                /* setup gl flags */
                if(ob_dt > OB_WIRE) {
                        glEnableClientState(GL_NORMAL_ARRAY);
@@ -4131,7 +4135,6 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                glDisableClientState(GL_COLOR_ARRAY);
                cpack(0xC0C0C0);
                
-               glEnableClientState(GL_VERTEX_ARRAY);
                glVertexPointer(3, GL_FLOAT, 0, pdd->vedata);
                
                glDrawArrays(GL_LINES, 0, 2*totve);
@@ -4144,7 +4147,8 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
        
        glDisable(GL_LIGHTING);
        glDisableClientState(GL_COLOR_ARRAY);
-       glEnableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_VERTEX_ARRAY);
+       glDisableClientState(GL_NORMAL_ARRAY);
 
        if(states)
                MEM_freeN(states);
@@ -4209,7 +4213,6 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obj
        }
 
        glEnableClientState(GL_VERTEX_ARRAY);
-       glDisableClientState(GL_NORMAL_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
 
        glEnable(GL_COLOR_MATERIAL);
@@ -4319,7 +4322,8 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obj
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
        glDisableClientState(GL_COLOR_ARRAY);
-       glEnableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_VERTEX_ARRAY);
        glEnable(GL_DEPTH_TEST);
        glLineWidth(1.0f);
 
index a59c263055d74d0c7d781baa2cd04d0b3a59cc14..3c178b10561d90ec6cbb77993718e696f33a95a5 100644 (file)
@@ -388,15 +388,9 @@ GPUBuffer *GPU_buffer_setup( DerivedMesh *dm, GPUDrawObject *object, int size, G
 
        DEBUG_VBO("GPU_buffer_setup\n");
 
-       if( globalPool == 0 ) {
+       if( globalPool == 0 )
                globalPool = GPU_buffer_pool_new();
 
-               /* somehow GL_NORMAL_ARRAY is enabled on startup and causes edge drawing code to crash */
-               glDisableClientState( GL_VERTEX_ARRAY );
-               glDisableClientState( GL_NORMAL_ARRAY );
-               glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-               glDisableClientState( GL_COLOR_ARRAY );
-       }
        buffer = GPU_buffer_alloc(size,globalPool);
        if( buffer == 0 ) {
                dm->drawObject->legacy = 1;
index c2cf4dfa9fd7f92312413c50c5d1f244b4346c25..db6c7fa5ce063fc51ed87285598d5bf5dca0235d 100644 (file)
@@ -1276,9 +1276,11 @@ void GPU_state_init(void)
        glDisable(GL_TEXTURE_1D);
        glDisable(GL_TEXTURE_2D);
 
-       /* default on, disable/enable should be local per function */
-       glEnableClientState(GL_VERTEX_ARRAY);
-       glEnableClientState(GL_NORMAL_ARRAY);
+       /* default disabled, enable should be local per function */
+       glDisableClientState(GL_VERTEX_ARRAY);
+       glDisableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_COLOR_ARRAY);
+       glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        
        glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
        glPixelTransferi(GL_RED_SCALE, 1);