2.5
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 01bdc1ba941c86fab5036e4c806e1e9f4c397ddf..bcb2b8b8e359e389375c629328f833aef7088dd4 100644 (file)
@@ -133,10 +133,8 @@ void EM_init_index_arrays(int x, int y, int z) {} // XXX
 void EM_free_index_arrays(void) {}             // XXX
 #define EM_FGON        0
 EditFace *EM_get_actFace(int x) {return NULL;} // XXX
-int draw_armature(Base *base, int x, int y) {return 0;}        // XXX
-int em_solidoffs;      // XXX
-int em_wireoffs;
-int em_vertoffs;
+
+extern unsigned int em_vertoffs, em_solidoffs, em_wireoffs;
 
 /* check for glsl drawing */
 
@@ -1261,6 +1259,7 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
                data->func(data->userData, eed, s[0][0], s[0][1], s[1][0], s[1][1], index);
        }
 }
+
 void mesh_foreachScreenEdge(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts)
 {
        struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
@@ -1293,6 +1292,7 @@ static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *ce
                data->func(data->userData, efa, s[0], s[1], index);
        }
 }
+
 void mesh_foreachScreenFace(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData)
 {
        struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; float pmat[4][4], vmat[4][4]; } data;
@@ -1804,7 +1804,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
        if(v3d->zbuf && (v3d->flag & V3D_ZBUF_SELECT)==0)
                glDisable(GL_DEPTH_TEST);
 
-       if(v3d->zbuf) bglPolygonOffset(5.0);
+       if(v3d->zbuf) bglPolygonOffset(v3d->dist, 5.0);
        
        if(G.f & G_DRAW_EDGELEN) {
                UI_GetThemeColor3fv(TH_TEXT, col);
@@ -1939,7 +1939,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
        
        if(v3d->zbuf) {
                glEnable(GL_DEPTH_TEST);
-               bglPolygonOffset(0.0);
+               bglPolygonOffset(v3d->dist, 0.0);
        }
 }
 
@@ -2014,7 +2014,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
                // write to show selected edge wires better
                UI_ThemeColor(TH_WIRE);
 
-               bglPolygonOffset(1.0);
+               bglPolygonOffset(v3d->dist, 1.0);
                glDepthMask(0);
        } 
        else {
@@ -2117,7 +2117,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
 
        if(dt>OB_WIRE) {
                glDepthMask(1);
-               bglPolygonOffset(0.0);
+               bglPolygonOffset(v3d->dist, 0.0);
                GPU_disable_material();
        }
 
@@ -2349,7 +2349,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                                * otherwise this wire is to overlay solid mode faces so do some depth buffer tricks.
                                */
                if (dt!=OB_WIRE && draw_wire==2) {
-                       bglPolygonOffset(1.0);
+                       bglPolygonOffset(v3d->dist, 1.0);
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
                }
                
@@ -2357,7 +2357,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                
                if (dt!=OB_WIRE && draw_wire==2) {
                        glDepthMask(1);
-                       bglPolygonOffset(0.0);
+                       bglPolygonOffset(v3d->dist, 0.0);
                }
        }
 
@@ -2388,7 +2388,7 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
                if(dt>OB_WIRE) {
                        // no transp in editmode, the fancy draw over goes bad then
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       GPU_set_object_materials(scene, ob, glsl, NULL);
+                       GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
                }
 
                draw_em_fancy(scene, v3d, ob, G.editMesh, cageDM, finalDM, dt);
@@ -2407,7 +2407,7 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
                        check_alpha = check_material_alpha(base, ob, glsl);
 
                        if(dt==OB_SOLID || glsl) {
-                               GPU_set_object_materials(scene, ob, glsl,
+                               GPU_set_object_materials(v3d, scene, ob, glsl,
                                        (check_alpha)? &do_alpha_pass: NULL);
                        }
 
@@ -2722,7 +2722,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        }
                        else {
                                if(draw_glsl_material(scene, ob, v3d, dt)) {
-                                       GPU_set_object_materials(scene, ob, 1, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 1, NULL);
                                        drawDispListsolid(lb, ob, 1);
                                }
                                else if(dt == OB_SHADED) {
@@ -2730,7 +2730,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                        drawDispListshaded(lb, ob);
                                }
                                else {
-                                       GPU_set_object_materials(scene, ob, 0, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 0, NULL);
                                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                        drawDispListsolid(lb, ob, 0);
                                }
@@ -2760,7 +2760,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        if(dl->nors==NULL) addnormalsDispList(ob, lb);
                        
                        if(draw_glsl_material(scene, ob, v3d, dt)) {
-                               GPU_set_object_materials(scene, ob, 1, NULL);
+                               GPU_set_object_materials(v3d, scene, ob, 1, NULL);
                                drawDispListsolid(lb, ob, 1);
                        }
                        else if(dt==OB_SHADED) {
@@ -2768,7 +2768,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                drawDispListshaded(lb, ob);
                        }
                        else {
-                               GPU_set_object_materials(scene, ob, 0, NULL);
+                               GPU_set_object_materials(v3d, scene, ob, 0, NULL);
                                glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                        
                                drawDispListsolid(lb, ob, 0);
@@ -2788,7 +2788,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        if(solid) {
                                
                                if(draw_glsl_material(scene, ob, v3d, dt)) {
-                                       GPU_set_object_materials(scene, ob, 1, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 1, NULL);
                                        drawDispListsolid(lb, ob, 1);
                                }
                                else if(dt == OB_SHADED) {
@@ -2797,7 +2797,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                        drawDispListshaded(lb, ob);
                                }
                                else {
-                                       GPU_set_object_materials(scene, ob, 0, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 0, NULL);
                                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                
                                        drawDispListsolid(lb, ob, 0);
@@ -3964,18 +3964,35 @@ static void drawnurb(Scene *scene, View3D *v3d, Base *base, Nurb *nurb, int dt)
 /* draw a sphere for use as an empty drawtype */
 static void draw_empty_sphere (float size)
 {
-       float cent=0;
-       GLUquadricObj *qobj = gluNewQuadric(); 
-       gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
+       static GLuint displist=0;
+       
+       if (displist == 0) {
+               GLUquadricObj   *qobj;
                
-       glPushMatrix();
-       glTranslatef(cent, cent, cent);
-       glScalef(size, size, size);
-       gluSphere(qobj, 1.0, 8, 5);
+               displist= glGenLists(1);
+               glNewList(displist, GL_COMPILE_AND_EXECUTE);
                
-       glPopMatrix();
+               glPushMatrix();
+               
+               qobj    = gluNewQuadric(); 
+               gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
+               gluDisk(qobj, 0.0,  1, 16, 1);
+               
+               glRotatef(90, 0, 1, 0);
+               gluDisk(qobj, 0.0,  1, 16, 1);
+               
+               glRotatef(90, 1, 0, 0);
+               gluDisk(qobj, 0.0,  1, 16, 1);
+               
+               gluDeleteQuadric(qobj);  
+               
+               glPopMatrix();
+               glEndList();
+       }
        
-       gluDeleteQuadric(qobj); 
+       glScalef(size, size, size);
+               glCallList(displist);
+       glScalef(1/size, 1/size, 1/size);
 }
 
 /* draw a cone for use as an empty drawtype */
@@ -4542,7 +4559,7 @@ static void drawtexspace(Object *ob)
 }
 
 /* draws wire outline */
-static void drawSolidSelect(View3D *v3d, Base *base) 
+static void drawSolidSelect(Scene *scene, View3D *v3d, Base *base) 
 {
        Object *ob= base->object;
        
@@ -4562,7 +4579,7 @@ static void drawSolidSelect(View3D *v3d, Base *base)
        }
        else if(ob->type==OB_ARMATURE) {
                if(!(ob->flag & OB_POSEMODE))
-                       draw_armature(base, OB_WIRE, 0);
+                       draw_armature(scene, v3d, base, OB_WIRE, 0);
        }
 
        glLineWidth(1.0);
@@ -4593,7 +4610,7 @@ static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob)
                }
        }
        
-       bglPolygonOffset(1.0);
+       bglPolygonOffset(v3d->dist, 1.0);
        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
        
        if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
@@ -4610,7 +4627,7 @@ static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob)
        }
 
        glDepthMask(1);
-       bglPolygonOffset(0.0);
+       bglPolygonOffset(v3d->dist, 0.0);
 }
 
 /* should be called in view space */
@@ -4888,7 +4905,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        if((v3d->flag & V3D_SELECT_OUTLINE) && ob->type!=OB_MESH) {
                if(dt>OB_WIRE && dt<OB_TEXTURE && ob!=G.obedit && (flag && DRAW_SCENESET)==0) {
                        if (!(ob->dtx&OB_DRAWWIRE) && (ob->flag&SELECT) && !(flag&DRAW_PICKING)) {
-                               drawSolidSelect(v3d, base);
+                               drawSolidSelect(scene, v3d, base);
                        }
                }
        }
@@ -5033,7 +5050,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        break;
                case OB_ARMATURE:
                        if(dt>OB_WIRE) GPU_enable_material(0, NULL); // we use default material
-                       empty_object= draw_armature(base, dt, flag);
+                       empty_object= draw_armature(scene, v3d, base, dt, flag);
                        if(dt>OB_WIRE) GPU_disable_material();
                        break;
                default:
@@ -5376,7 +5393,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
 
                        em_solidoffs= bbs_mesh_solid_EM(scene, v3d, dm, scene->selectmode & SCE_SELECT_FACE);
                        
-                       bglPolygonOffset(1.0);
+                       bglPolygonOffset(v3d->dist, 1.0);
                        
                        // we draw edges always, for loop (select) tools
                        em_wireoffs= bbs_mesh_wire(dm, em_solidoffs);
@@ -5386,7 +5403,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
                                em_vertoffs= bbs_mesh_verts(dm, em_wireoffs);
                        else em_vertoffs= em_wireoffs;
                        
-                       bglPolygonOffset(0.0);
+                       bglPolygonOffset(v3d->dist, 0.0);
 
                        dm->release(dm);
 
@@ -5430,7 +5447,7 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, Object *ob, int
 
                if(dm) {
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       GPU_set_object_materials(scene, ob, glsl, NULL);
+                       GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
                }
                else {
                        glEnable(GL_COLOR_MATERIAL);