Step one in migrating to use glArray calls in Blender
authorTon Roosendaal <ton@blender.org>
Mon, 20 Nov 2006 21:25:02 +0000 (21:25 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 20 Nov 2006 21:25:02 +0000 (21:25 +0000)
- Curve/Nurbs/Font/MBall now all draw arrays.
- had to flip abgr to rgba in shaded drawing
- Mesh drawing can't be easily done; the indices for faces are not in
  in one chunk. Also need a way to gether trias/quads, per material.

Speedup results are mixed. Something between 2-4 times. Especially for
text it seems to help.

source/blender/blenkernel/BKE_displist.h
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/mball.c
source/blender/render/intern/source/convertblender.c
source/blender/src/drawobject.c
source/blender/src/drawview.c
source/blender/src/vpaint.c

index 4bcd5d8955c6ab1c3ce5e598a021beb62dac44cb..04f3aadbe3c1f85e9c9fcbf5d663b8bdc839602a 100644 (file)
@@ -85,28 +85,18 @@ struct Material;
 struct Bone;
 struct Mesh;
 
-/*
- * All the different DispList.type's use the
- * data in the displist structure in fairly
- * different ways which can be rather confusing, 
- * the best thing to do would be to make a structure
- * for each displaylist type that has the fields
- * needed w/ proper names, and then make the actual
- * DispList structure a typed union.
- *   - zr
- */
-
-/* needs splitting! */
+
+/* used for curves, nurbs, mball, importing */
 typedef struct DispList {
     struct DispList *next, *prev;
     short type, flag;
     int parts, nr;
-    short col, rt;              /* rt wordt gebruikt door initrenderNurbs */
+    short col, rt;              /* rt used by initrenderNurbs */
        float *verts, *nors;
        int *index;
        unsigned int *col1, *col2;
        int charidx;
-       int pad;
+       int totindex;                           /* indexed array drawing surfaces */
 
        unsigned int *bevelSplitFlag;
 } DispList;
index 78ee6bb40e2912775721816b66cb540b325540ee..19898ebb03c45f633336a09564c8e9d0b602f4c7 100644 (file)
@@ -343,26 +343,26 @@ static void cdDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned cha
                        glBegin(glmode = new_glmode);
                }
                        
-               glColor3ub(cp1[3], cp1[2], cp1[1]);
+               glColor3ub(cp1[0], cp1[1], cp1[2]);
                glVertex3fv(mvert[mface->v1].co);
-               glColor3ub(cp1[7], cp1[6], cp1[5]);
+               glColor3ub(cp1[4], cp1[5], cp1[6]);
                glVertex3fv(mvert[mface->v2].co);
-               glColor3ub(cp1[11], cp1[10], cp1[9]);
+               glColor3ub(cp1[8], cp1[9], cp1[10]);
                glVertex3fv(mvert[mface->v3].co);
                if(mface->v4) {
-                       glColor3ub(cp1[15], cp1[14], cp1[13]);
+                       glColor3ub(cp1[12], cp1[13], cp1[14]);
                        glVertex3fv(mvert[mface->v4].co);
                }
                        
                if(useTwoSided) {
-                       glColor3ub(cp2[11], cp2[10], cp2[9]);
+                       glColor3ub(cp2[8], cp2[9], cp2[10]);
                        glVertex3fv(mvert[mface->v3].co );
-                       glColor3ub(cp2[7], cp2[6], cp2[5]);
+                       glColor3ub(cp2[4], cp2[5], cp2[6]);
                        glVertex3fv(mvert[mface->v2].co );
-                       glColor3ub(cp2[3], cp2[2], cp2[1]);
+                       glColor3ub(cp2[0], cp2[1], cp2[2]);
                        glVertex3fv(mvert[mface->v1].co );
                        if(mface->v4) {
-                               glColor3ub(cp2[15], cp2[14], cp2[13]);
+                               glColor3ub(cp2[12], cp2[13], cp2[14]);
                                glVertex3fv(mvert[mface->v4].co );
                        }
                }
index e8ac82fc5969c9a74a9f0da8c6e742a3516153ce..763a4cdc0a09f24c849ef8245d4ca08e06c51374 100644 (file)
@@ -196,14 +196,14 @@ void addnormalsDispList(Object *ob, ListBase *lb)
        
        while(dl) {
                if(dl->type==DL_INDEX3) {
-                       if(dl->nors==0) {
+                       if(dl->nors==NULL) {
                                dl->nors= MEM_callocN(sizeof(float)*3, "dlnors");
                                if(dl->verts[2]<0.0) dl->nors[2]= -1.0;
                                else dl->nors[2]= 1.0;
                        }
                }
                else if(dl->type==DL_SURF) {
-                       if(dl->nors==0) {
+                       if(dl->nors==NULL) {
                                dl->nors= MEM_callocN(sizeof(float)*3*dl->nr*dl->parts, "dlnors");
                                
                                vdata= dl->verts;
@@ -276,7 +276,7 @@ void count_displist(ListBase *lb, int *totvert, int *totface)
 }
 
 
-/* ***************************** shade displist ******************** */
+/* ***************************** shade displist. note colors now are in rgb(a) order ******************** */
 
 /* create default shade input... save cpu cycles with ugly global */
 static ShadeInput shi;
@@ -369,11 +369,11 @@ static void fastshade(float *co, float *nor, float *orco, float *uv, Material *m
        VECADD(shr.combined, shr.diff, shr.spec);
        
        a= 256.0f*(shr.combined[0]);
-       col1[3]= CLAMPIS(a, 0, 255);
+       col1[0]= CLAMPIS(a, 0, 255);
        a= 256.0f*(shr.combined[1]);
-       col1[2]= CLAMPIS(a, 0, 255);
-       a= 256.0f*(shr.combined[2]);
        col1[1]= CLAMPIS(a, 0, 255);
+       a= 256.0f*(shr.combined[2]);
+       col1[2]= CLAMPIS(a, 0, 255);
        
        if(col2) {
                shi.vn[0]= -shi.vn[0];
@@ -386,11 +386,11 @@ static void fastshade(float *co, float *nor, float *orco, float *uv, Material *m
                VECADD(shr.combined, shr.diff, shr.spec);
                
                a= 256.0f*(shr.combined[0]);
-               col2[3]= CLAMPIS(a, 0, 255);
+               col2[0]= CLAMPIS(a, 0, 255);
                a= 256.0f*(shr.combined[1]);
-               col2[2]= CLAMPIS(a, 0, 255);
-               a= 256.0f*(shr.combined[2]);
                col2[1]= CLAMPIS(a, 0, 255);
+               a= 256.0f*(shr.combined[2]);
+               col2[2]= CLAMPIS(a, 0, 255);
        }
 }
 
@@ -558,8 +558,17 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
 
 void shadeMeshMCol(Object *ob, Mesh *me)
 {
+       int a;
+       char *cp;
+       
        Render *re= fastshade_get_render();
        mesh_create_shadedColors(re, ob, 1, (unsigned int **)&me->mcol, NULL);
+       
+       /* swap bytes */
+       for(cp= (char *)me->mcol, a= 4*me->totface; a>0; a--, cp+=4) {
+               SWAP(char, cp[0], cp[3]);
+               SWAP(char, cp[1], cp[2]);
+       }
 }
 
 /* has base pointer, to check for layer */
@@ -1226,6 +1235,35 @@ void curve_calc_modifiers_post(Object *ob, ListBase *nurb, ListBase *dispbase, i
        }
 }
 
+static void displist_surf_indices(DispList *dl)
+{
+       int a, b, p1, p2, p3, p4;
+       int *index;
+       
+       dl->totindex= 0;
+       
+       index=dl->index= MEM_mallocN( 4*sizeof(int)*(dl->parts+1)*(dl->nr+1), "index array nurbs");
+       
+       for(a=0; a<dl->parts; a++) {
+               
+               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
+               
+               for(; b<dl->nr; b++, index+=4) {        
+                       index[0]= p1;
+                       index[1]= p2;
+                       index[2]= p4;
+                       index[3]= p3;
+                       
+                       dl->totindex++;
+                       
+                       p2= p1; p1++;
+                       p4= p3; p3++;
+
+               }
+       }
+       
+}
+
 void makeDispListSurf(Object *ob, ListBase *dispbase, int forRender)
 {
        ListBase *nubase;
@@ -1288,6 +1326,9 @@ void makeDispListSurf(Object *ob, ListBase *dispbase, int forRender)
                                if(nu->flagu & CU_CYCLIC) dl->flag|= DL_CYCL_V;
 
                                makeNurbfaces(nu, data, 0);
+                               
+                               /* gl array drawing: using indices */
+                               displist_surf_indices(dl);
                        }
                }
        }
@@ -1440,6 +1481,9 @@ void makeDispListCurveTypes(Object *ob, int forOrco)
                                                                }
                                                        }
                                                }
+                                               
+                                               /* gl array drawing: using indices */
+                                               displist_surf_indices(dl);
                                        }
                                }
 
index 65a7a3f4f209c555832d695279bae8528c0d470c..3c4b1526c8b2c9e4260a61532ce52e895b36e50b 100644 (file)
@@ -571,7 +571,7 @@ float metaball(float x, float y, float z)
 
 /* ******************************************** */
 
-int *indices=0;
+int *indices=NULL;
 int totindex, curindex;
 
 
@@ -593,25 +593,15 @@ void accum_mballfaces(int i1, int i2, int i3, int i4)
        
        cur= indices+4*curindex;
 
-       /* prevent zero codes for faces indices */
-       if(i3==0) {
-               if(i4) {
-                       i3= i4;
-                       i4= i1;
-                       i1= i2;
-                       i2= 0;
-               }
-               else {
-                       i3= i2;
-                       i2= i1;
-                       i1= 0;
-               }
-       }
+       /* diplists now support array drawing, we treat trias as fake quad */
        
        cur[0]= i1;
        cur[1]= i2;
        cur[2]= i3;
-       cur[3]= i4;
+       if(i4==0)
+               cur[3]= i3;
+       else 
+               cur[3]= i4;
        
        curindex++;
 
index 07232618fc59d913babdc798f4c9cf47d2029211..89d4698f93bf1c884b06e3d9c08cbc7568c27aaa 100644 (file)
@@ -1599,7 +1599,7 @@ static void init_render_mball(Render *re, Object *ob)
                vlr->lay= ob->lay;
 
                /* mball -too bad- always has triangles, because quads can be non-planar */
-               if(index[3]) {
+               if(index[3] && index[3]!=index[2]) {
                        vlr1= RE_findOrAddVlak(re, re->totvlak++);
                        *vlr1= *vlr;
                        vlr1->v2= vlr1->v3;
index a00e2cea3d52417d505db8b47e38e4f6ca5d25dc..3fe86f34e58222766246c93ab1dfd8a764f29ccc 100644 (file)
@@ -90,6 +90,7 @@
 #include "BKE_mesh.h"
 #include "BKE_material.h"
 #include "BKE_mball.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_anim.h"                  //for the where_on_path function
 #ifdef WITH_VERSE
@@ -2122,12 +2123,7 @@ static void draw_mesh_fancy(Base *base, DerivedMesh *baseDM, DerivedMesh *dm, in
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
                }
 
-               /* I need advise on this from Daniel... without this code it does it nicer */
-//             if (G.f & (G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT)) {
-//                     baseDM->drawEdges(baseDM, dt==OB_WIRE);
-//             } else {
-                       dm->drawEdges(dm, (dt==OB_WIRE || totface==0));
-//             }
+               dm->drawEdges(dm, (dt==OB_WIRE || totface==0));
 
                if (dt!=OB_WIRE) {
                        glDepthMask(1);
@@ -2198,10 +2194,13 @@ static int index3_nors_incr= 1;
 static int drawDispListwire(ListBase *dlbase)
 {
        DispList *dl;
-       int parts, nr, ofs, *index;
+       int parts, nr;
        float *data;
 
        if(dlbase==NULL) return 1;
+       
+       glDisableClientState(GL_NORMAL_ARRAY);
+       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 
 
        for(dl= dlbase->first; dl; dl= dl->next) {
                if(dl->parts==0 || dl->nr==0)
@@ -2211,47 +2210,38 @@ static int drawDispListwire(ListBase *dlbase)
        
                switch(dl->type) {
                case DL_SEGM:
-                       parts= dl->parts;
-                       while(parts--) {
-                               nr= dl->nr;
-                               glBegin(GL_LINE_STRIP);
-                               while(nr--) {
-                                       glVertex3fv(data);
-                                       data+=3;
-                               }
-                               glEnd();
-                       }
+                       
+                       glVertexPointer(3, GL_FLOAT, 0, data);
+                       
+                       for(parts=0; parts<dl->parts; parts++)
+                               glDrawArrays(GL_LINE_STRIP, parts*dl->nr, dl->nr);
+                               
                        break;
                case DL_POLY:
-                       parts= dl->parts;
-                       while(parts--) {
-                               nr= dl->nr;
-                               glBegin(GL_LINE_LOOP);
-                               while(nr--) {
-                                       glVertex3fv(data);
-                                       data+=3;
-                               }
-                               glEnd();
-                       }
+                       
+                       glVertexPointer(3, GL_FLOAT, 0, data);
+                       
+                       for(parts=0; parts<dl->parts; parts++)
+                               glDrawArrays(GL_LINE_LOOP, parts*dl->nr, dl->nr);
+                       
                        break;
                case DL_SURF:
-                       parts= dl->parts;
-                       while(parts--) {
-                               nr= dl->nr;
-                               if(dl->flag & DL_CYCL_U) glBegin(GL_LINE_LOOP);
-                               else glBegin(GL_LINE_STRIP);
-
-                               while(nr--) {
-                                       glVertex3fv(data);
-                                       data+=3;
-                               }
-                               glEnd();
+                       
+                       glVertexPointer(3, GL_FLOAT, 0, data);
+                       
+                       for(parts=0; parts<dl->parts; parts++) {
+                               if(dl->flag & DL_CYCL_U) 
+                                       glDrawArrays(GL_LINE_LOOP, parts*dl->nr, dl->nr);
+                               else
+                                       glDrawArrays(GL_LINE_STRIP, parts*dl->nr, dl->nr);
                        }
-                       ofs= 3*dl->nr;
-                       nr= dl->nr;
-                       while(nr--) {
+                       
+                       for(nr=0; nr<dl->nr; nr++) {
+                               int ofs= 3*dl->nr;
+                               
                                data= (  dl->verts )+3*nr;
                                parts= dl->parts;
+
                                if(dl->flag & DL_CYCL_V) glBegin(GL_LINE_LOOP);
                                else glBegin(GL_LINE_STRIP);
                                
@@ -2260,54 +2250,43 @@ static int drawDispListwire(ListBase *dlbase)
                                        data+=ofs;
                                }
                                glEnd();
+                               
+                               /* (ton) this code crashes for me when resolv is 86 or higher... no clue */
+//                             glVertexPointer(3, GL_FLOAT, sizeof(float)*3*dl->nr, data + 3*nr);
+//                             if(dl->flag & DL_CYCL_V) 
+//                                     glDrawArrays(GL_LINE_LOOP, 0, dl->parts);
+//                             else
+//                                     glDrawArrays(GL_LINE_STRIP, 0, dl->parts);
                        }
                        break;
                        
                case DL_INDEX3:
                        if(draw_index_wire) {
-                               parts= dl->parts;
-                               data= dl->verts;
-                               index= dl->index;
-                               while(parts--) {
-
-                                       glBegin(GL_LINE_LOOP);
-                                               glVertex3fv(data+3*index[0]);
-                                               glVertex3fv(data+3*index[1]);
-                                               glVertex3fv(data+3*index[2]);
-                                       glEnd();
-                                       index+= 3;
-                               }
+                               glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                               glDrawElements(GL_TRIANGLES, 3*dl->parts, GL_UNSIGNED_INT, dl->index);
                        }
                        break;
                        
                case DL_INDEX4:
                        if(draw_index_wire) {
-                               parts= dl->parts;
-                               data= dl->verts;
-                               index= dl->index;
-                               while(parts--) {
-
-                                       glBegin(GL_LINE_LOOP);
-                                               glVertex3fv(data+3*index[0]);
-                                               glVertex3fv(data+3*index[1]);
-                                               glVertex3fv(data+3*index[2]);
-                                               if(index[3]) glVertex3fv(data+3*index[3]);
-                                       glEnd();
-                                       index+= 4;
-                               }
+                               glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                               glDrawElements(GL_QUADS, 4*dl->parts, GL_UNSIGNED_INT, dl->index);
                        }
                        break;
                }
        }
+       
+       glEnableClientState(GL_NORMAL_ARRAY);
+       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
+       
        return 0;
 }
 
 static void drawDispListsolid(ListBase *lb, Object *ob)
 {
        DispList *dl;
-       int nr, parts, ofs, p1, p2, p3, p4, a, b, *index;
-       float *data, *v1, *v2, *v3, *v4, curcol[4];
-       float *ndata, *n1, *n2, *n3, *n4;
+       float *data, curcol[4];
+       float *ndata;
        
        if(lb==NULL) return;
        
@@ -2333,16 +2312,10 @@ static void drawDispListsolid(ListBase *lb, Object *ob)
                        if(ob->type==OB_SURF) {
                                glDisable(GL_LIGHTING);
                                glColor3fv(curcol);
-                               parts= dl->parts;
-                               while(parts--) {
-                                       nr= dl->nr;
-                                       glBegin(GL_LINE_STRIP);
-                                       while(nr--) {
-                                               glVertex3fv(data);
-                                               data+=3;
-                                       }
-                                       glEnd();
-                               }
+                               
+                               glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                               glDrawArrays(GL_LINE_STRIP, 0, dl->parts);
+
                                glEnable(GL_LIGHTING);
                        }
                        break;
@@ -2350,123 +2323,56 @@ static void drawDispListsolid(ListBase *lb, Object *ob)
                        if(ob->type==OB_SURF) {
                                BIF_ThemeColor(TH_WIRE);
                                glDisable(GL_LIGHTING);
-                               parts= dl->parts;
-                               while(parts--) {
-                                       nr= dl->nr;
-                                       glBegin(GL_LINE_LOOP);
-                                       while(nr--) {
-                                               glVertex3fv(data);
-                                               data+=3;
-                                       }
-                                       glEnd();
-                               }
+                               
+                               glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                               glDrawArrays(GL_LINE_LOOP, 0, dl->parts);
+                               
                                glEnable(GL_LIGHTING);
                                break;
                        }
                case DL_SURF:
-
-                       set_gl_material(dl->col+1);
                        
-                       if(dl->rt & CU_SMOOTH) glShadeModel(GL_SMOOTH);
-                       else glShadeModel(GL_FLAT);
-
-                       for(a=0; a<dl->parts; a++) {
-                               
-                               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
-                               
-                               v1= data+ 3*p1; 
-                               v2= data+ 3*p2;
-                               v3= data+ 3*p3; 
-                               v4= data+ 3*p4;
-                               n1= ndata+ 3*p1; 
-                               n2= ndata+ 3*p2;
-                               n3= ndata+ 3*p3; 
-                               n4= ndata+ 3*p4;
-                               
-                               glBegin(GL_QUAD_STRIP);
-                               
-                               glNormal3fv(n2); glVertex3fv(v2);
-                               glNormal3fv(n4); glVertex3fv(v4);
-
-                               for(; b<dl->nr; b++) {
-                                       
-                                       glNormal3fv(n1); glVertex3fv(v1);
-                                       glNormal3fv(n3); glVertex3fv(v3);
-
-                                       v2= v1; v1+= 3;
-                                       v4= v3; v3+= 3;
-                                       n2= n1; n1+= 3;
-                                       n4= n3; n3+= 3;
-                               }
+                       if(dl->index) {
+                               set_gl_material(dl->col+1);
                                
+                               if(dl->rt & CU_SMOOTH) glShadeModel(GL_SMOOTH);
+                               else glShadeModel(GL_FLAT);
                                
-                               glEnd();
-                       }
+                               glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                               glNormalPointer(GL_FLOAT, 0, dl->nors);
+                               glDrawElements(GL_QUADS, 4*dl->totindex, GL_UNSIGNED_INT, dl->index);
+                       }                       
                        break;
 
                case DL_INDEX3:
                
-                       parts= dl->parts;
-                       data= dl->verts;
-                       ndata= dl->nors;
-                       index= dl->index;
-
                        set_gl_material(dl->col+1);
-                                                       
+                       
+                       glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                       
                        /* voor polys only one normal needed */
                        if(index3_nors_incr==0) {
-                               while(parts--) {
-
-                                       glBegin(GL_TRIANGLES);
-                                               glNormal3fv(ndata);
-                                               glVertex3fv(data+3*index[0]);
-                                               glVertex3fv(data+3*index[1]);
-                                               glVertex3fv(data+3*index[2]);
-                                       glEnd();
-                                       index+= 3;
-                               }
+                               glDisableClientState(GL_NORMAL_ARRAY);
+                               glNormal3fv(ndata);
                        }
-                       else {
-                               while(parts--) {
+                       else
+                               glNormalPointer(GL_FLOAT, 0, dl->nors);
+                       
+                       glDrawElements(GL_TRIANGLES, 3*dl->parts, GL_UNSIGNED_INT, dl->index);
+                       
+                       if(index3_nors_incr==0)
+                               glEnableClientState(GL_NORMAL_ARRAY);
 
-                                       glBegin(GL_TRIANGLES);
-                                               ofs= 3*index[0];
-                                               glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                               ofs= 3*index[1];
-                                               glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                               ofs= 3*index[2];
-                                               glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                       glEnd();
-                                       index+= 3;
-                               }
-                       }
                        break;
 
                case DL_INDEX4:
 
-                       parts= dl->parts;
-                       data= dl->verts;
-                       ndata= dl->nors;
-                       index= dl->index;
-
                        set_gl_material(dl->col+1);
-               
-                       while(parts--) {
-
-                               glBegin(index[3]?GL_QUADS:GL_TRIANGLES);
-                                       ofs= 3*index[0];
-                                       glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                       ofs= 3*index[1];
-                                       glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                       ofs= 3*index[2];
-                                       glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                       if(index[3]) {
-                                               ofs= 3*index[3];
-                                               glNormal3fv(ndata+ofs); glVertex3fv(data+ofs);
-                                       }
-                               glEnd();
-                               index+= 4;
-                       }
+                       
+                       glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                       glNormalPointer(GL_FLOAT, 0, dl->nors);
+                       glDrawElements(GL_QUADS, 4*dl->parts, GL_UNSIGNED_INT, dl->index);
+                       
                        break;
                }
                dl= dl->next;
@@ -2480,124 +2386,52 @@ static void drawDispListsolid(ListBase *lb, Object *ob)
 static void drawDispListshaded(ListBase *lb, Object *ob)
 {
        DispList *dl, *dlob;
-       int parts, p1, p2, p3, p4, a, b, *index;
-       float *data, *v1, *v2, *v3, *v4;
-       unsigned int *cdata, *c1, *c2, *c3, *c4;
-       char *cp;
+       unsigned int *cdata;
 
-       if(lb==0) return;
+       if(lb==NULL) return;
 
        glShadeModel(GL_SMOOTH);
-
+       glDisableClientState(GL_NORMAL_ARRAY);
+       glEnableClientState(GL_COLOR_ARRAY);
+       
        dl= lb->first;
        dlob= ob->disp.first;
        while(dl && dlob) {
                
                cdata= dlob->col1;
-               data= dl->verts;
-               if(cdata==0) break;
+               if(cdata==NULL) break;
                
                switch(dl->type) {
                case DL_SURF:
-
-                       for(a=0; a<dl->parts; a++) {
-
-                               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
-
-                               v1= data+ 3*p1; 
-                               v2= data+ 3*p2;
-                               v3= data+ 3*p3; 
-                               v4= data+ 3*p4;
-                               c1= cdata+ p1; 
-                               c2= cdata+ p2;
-                               c3= cdata+ p3; 
-                               c4= cdata+ p4;
-
-                               for(; b<dl->nr; b++) {
-
-                                       glBegin(GL_QUADS);
-                                               cp= (char *)c1;
-                                               glColor3ub(cp[3], cp[2], cp[1]);
-                                               glVertex3fv(v1);
-                                               cp= (char *)c2;
-                                               glColor3ub(cp[3], cp[2], cp[1]);
-                                               glVertex3fv(v2);
-                                               cp= (char *)c4;
-                                               glColor3ub(cp[3], cp[2], cp[1]);
-                                               glVertex3fv(v4);
-                                               cp= (char *)c3;
-                                               glColor3ub(cp[3], cp[2], cp[1]);
-                                               glVertex3fv(v3);
-                                       glEnd();
-
-                                       v2= v1; v1+= 3;
-                                       v4= v3; v3+= 3;
-                                       c2= c1; c1++;
-                                       c4= c3; c3++;
-                               }
-                       }
+                       if(dl->index) {
+                               glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                               glColorPointer(4, GL_UNSIGNED_BYTE, 0, cdata);
+                               glDrawElements(GL_QUADS, 4*dl->totindex, GL_UNSIGNED_INT, dl->index);
+                       }                       
                        break;
 
                case DL_INDEX3:
                        
-                       parts= dl->parts;
-                       index= dl->index;
-                       
-                       while(parts--) {
-
-                               glBegin(GL_TRIANGLES);
-                                       cp= (char *)(cdata+index[0]);
-                                       glColor3ub(cp[3], cp[2], cp[1]);                                        
-                                       glVertex3fv(data+3*index[0]);
-
-                                       cp= (char *)(cdata+index[1]);
-                                       glColor3ub(cp[3], cp[2], cp[1]);                                        
-                                       glVertex3fv(data+3*index[1]);
-
-                                       cp= (char *)(cdata+index[2]);
-                                       glColor3ub(cp[3], cp[2], cp[1]);                                        
-                                       glVertex3fv(data+3*index[2]);
-                               glEnd();
-                               index+= 3;
-                       }
+                       glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                       glColorPointer(4, GL_UNSIGNED_BYTE, 0, cdata);
+                       glDrawElements(GL_TRIANGLES, 3*dl->parts, GL_UNSIGNED_INT, dl->index);
                        break;
 
                case DL_INDEX4:
-               
-                       parts= dl->parts;
-                       index= dl->index;
-                       while(parts--) {
-
-                               glBegin(index[3]?GL_QUADS:GL_TRIANGLES);
-                                       cp= (char *)(cdata+index[0]);
-                                       glColor3ub(cp[3], cp[2], cp[1]);                                        
-                                       glVertex3fv(data+3*index[0]);
-
-                                       cp= (char *)(cdata+index[1]);
-                                       glColor3ub(cp[3], cp[2], cp[1]);                                        
-                                       glVertex3fv(data+3*index[1]);
-
-                                       cp= (char *)(cdata+index[2]);
-                                       glColor3ub(cp[3], cp[2], cp[1]);                                        
-                                       glVertex3fv(data+3*index[2]);
-                                       
-                                       if(index[3]) {
-                                       
-                                               cp= (char *)(cdata+index[3]);
-                                               glColor3ub(cp[3], cp[2], cp[1]);        
-                                               glVertex3fv(data+3*index[3]);
-                                       }
-                               glEnd();
-                               index+= 4;
-                       }
-                       break;
                        
+                       glVertexPointer(3, GL_FLOAT, 0, dl->verts);
+                       glColorPointer(4, GL_UNSIGNED_BYTE, 0, cdata);
+                       glDrawElements(GL_QUADS, 4*dl->parts, GL_UNSIGNED_INT, dl->index);
+                       break;
                }
+               
                dl= dl->next;
                dlob= dlob->next;
        }
        
        glShadeModel(GL_FLAT);
+       glEnableClientState(GL_NORMAL_ARRAY);
+       glDisableClientState(GL_COLOR_ARRAY);
 }
 
 /* returns 1 when nothing was drawn */
@@ -2744,7 +2578,9 @@ static void draw_particle_system(Base *base, PartEff *paf)
        ctime= bsystem_time(ob, 0, (float)(G.scene->r.cfra), ptime);
 
        glPointSize(1.0);
-       if(paf->stype!=PAF_VECT) glBegin(GL_POINTS);
+       
+       if(paf->stype==PAF_VECT) glBegin(GL_LINES);
+       else glBegin(GL_POINTS);
 
        totpart= (paf->disp*paf->totpart)/100;
        for(a=0; a<totpart; a++, pa+=paf->totkey) {
@@ -2756,23 +2592,18 @@ static void draw_particle_system(Base *base, PartEff *paf)
                                        where_is_particle(paf, pa, ctime, vec);
                                        where_is_particle(paf, pa, ctime+1.0, vec1);
                
-
-                                       glBegin(GL_LINE_STRIP);
-                                               glVertex3fv(vec);
-                                               glVertex3fv(vec1);
-                                       glEnd();
-                                       
+                                       glVertex3fv(vec);
+                                       glVertex3fv(vec1);
                                }
                                else {
                                        where_is_particle(paf, pa, ctime, vec);
                                        
                                        glVertex3fv(vec);
-                                               
                                }
                        }
                }
        }
-       if(paf->stype!=PAF_VECT) glEnd();
+       glEnd();
        
        myloadmatrix(G.vd->viewmat);
        mymultmatrix(ob->obmat);        // bring back local matrix for dtx
@@ -2863,6 +2694,9 @@ static void tekenhandlesN(Nurb *nu, short sel)
        int a;
 
        if(nu->hide) return;
+       
+       glBegin(GL_LINES); 
+       
        if( (nu->type & 7)==1) {
                if(sel) col= nurbcol+4;
                else col= nurbcol;
@@ -2873,41 +2707,34 @@ static void tekenhandlesN(Nurb *nu, short sel)
                        if(bezt->hide==0) {
                                if( (bezt->f2 & 1)==sel) {
                                        fp= bezt->vec[0];
+                                       
                                        cpack(col[bezt->h1]);
-
-                                       glBegin(GL_LINE_STRIP); 
                                        glVertex3fv(fp);
                                        glVertex3fv(fp+3); 
-                                       glEnd();
-                                       cpack(col[bezt->h2]);
 
-                                       glBegin(GL_LINE_STRIP); 
+                                       cpack(col[bezt->h2]);
                                        glVertex3fv(fp+3); 
                                        glVertex3fv(fp+6); 
-                                       glEnd();
                                }
                                else if( (bezt->f1 & 1)==sel) {
                                        fp= bezt->vec[0];
+                                       
                                        cpack(col[bezt->h1]);
-
-                                       glBegin(GL_LINE_STRIP); 
                                        glVertex3fv(fp); 
                                        glVertex3fv(fp+3); 
-                                       glEnd();
                                }
                                else if( (bezt->f3 & 1)==sel) {
                                        fp= bezt->vec[1];
+                                       
                                        cpack(col[bezt->h2]);
-
-                                       glBegin(GL_LINE_STRIP); 
                                        glVertex3fv(fp); 
                                        glVertex3fv(fp+3); 
-                                       glEnd();
                                }
                        }
                        bezt++;
                }
        }
+       glEnd();
 }
 
 static void tekenvertsN(Nurb *nu, short sel)
@@ -2970,15 +2797,13 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                bp= nu->bp;
                                for(b=0; b<nu->pntsv; b++) {
                                        if(nu->flagu & 1) glBegin(GL_LINE_LOOP);
-
                                        else glBegin(GL_LINE_STRIP);
 
                                        for(a=0; a<nu->pntsu; a++, bp++) {
                                                glVertex3fv(bp->vec);
                                        }
 
-                                       if(nu->flagu & 1) glEnd();
-                                       else glEnd();
+                                       glEnd();
                                }
                                break;
                        case CU_NURBS:
@@ -3715,7 +3540,9 @@ static void drawSolidSelect(Base *base)
        if(ELEM3(ob->type, OB_FONT,OB_CURVE, OB_SURF)) {
                Curve *cu = ob->data;
                if (displist_has_faces(&cu->disp) && boundbox_clip(ob->obmat, cu->bb)) {
+                       draw_index_wire= 0;
                        drawDispListwire(&cu->disp);
+                       draw_index_wire= 1;
                }
        } else if (ob->type==OB_MBALL) {
                if((base->flag & OB_FROMDUPLI)==0) 
index 45392c6cc716b98626b1048892f1c410e332651d..84b48904d261c36c81cc3bb9a108c6274e6f164b 100644 (file)
@@ -277,6 +277,10 @@ void init_gl_stuff(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);
+       
        glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
        glPixelTransferi(GL_RED_SCALE, 1);
        glPixelTransferi(GL_RED_BIAS, 0);
index 0d6b6a0e376e187dd52a362ed95fc0860220b29d..cd3553abfd1266e46364dbb7b82f4832a594a94e 100644 (file)
@@ -245,7 +245,7 @@ void make_vertexcol(int shade)      /* single ob */
        if(shade)
                shadeMeshMCol(ob, me);
        else
-               memset(me->mcol, 255, sizeof(MCol)*me->totface);
+               memset(me->mcol, 0, 4*sizeof(MCol)*me->totface);
 
        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);