~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/space_view3d/drawobject.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 *  \ingroup spview3d
28
28
 */
29
29
 
30
 
 
31
 
#include <string.h>
32
 
#include <math.h>
33
 
 
34
30
#include "MEM_guardedalloc.h"
35
31
 
36
32
#include "DNA_camera_types.h"
37
33
#include "DNA_curve_types.h"
38
 
#include "DNA_constraint_types.h" // for drawing constraint
 
34
#include "DNA_constraint_types.h"  /* for drawing constraint */
39
35
#include "DNA_lamp_types.h"
40
36
#include "DNA_lattice_types.h"
41
37
#include "DNA_material_types.h"
42
38
#include "DNA_mesh_types.h"
43
 
#include "DNA_meshdata_types.h"
44
39
#include "DNA_meta_types.h"
45
40
#include "DNA_scene_types.h"
46
41
#include "DNA_smoke_types.h"
47
 
#include "DNA_speaker_types.h"
48
42
#include "DNA_world_types.h"
49
 
#include "DNA_armature_types.h"
 
43
#include "DNA_object_types.h"
50
44
 
51
 
#include "BLI_utildefines.h"
52
45
#include "BLI_blenlib.h"
53
46
#include "BLI_math.h"
54
 
#include "BLI_edgehash.h"
55
 
#include "BLI_rand.h"
56
 
#include "BLI_utildefines.h"
57
47
 
58
 
#include "BKE_anim.h"  //for the where_on_path function
 
48
#include "BKE_anim.h"  /* for the where_on_path function */
59
49
#include "BKE_armature.h"
60
50
#include "BKE_camera.h"
61
 
#include "BKE_constraint.h" // for the get_constraint_target function
 
51
#include "BKE_constraint.h"  /* for the get_constraint_target function */
62
52
#include "BKE_curve.h"
63
53
#include "BKE_DerivedMesh.h"
64
54
#include "BKE_deform.h"
78
68
#include "BKE_pointcache.h"
79
69
#include "BKE_scene.h"
80
70
#include "BKE_unit.h"
81
 
#include "BKE_movieclip.h"
82
71
#include "BKE_tracking.h"
83
72
 
84
73
#include "BKE_tessmesh.h"
85
74
 
86
 
#include "smoke_API.h"
87
 
 
88
75
#include "IMB_imbuf.h"
89
76
#include "IMB_imbuf_types.h"
90
77
 
99
86
#include "ED_screen.h"
100
87
#include "ED_sculpt.h"
101
88
#include "ED_types.h"
102
 
#include "ED_curve.h" /* for curve_editnurbs */
103
89
 
104
90
#include "UI_resources.h"
 
91
#include "UI_interface_icons.h"
105
92
 
106
93
#include "WM_api.h"
107
 
#include "wm_subwindow.h"
108
94
#include "BLF_api.h"
109
95
 
110
 
#include "view3d_intern.h"  // own include
 
96
#include "view3d_intern.h"  /* bad level include */
111
97
 
112
98
typedef enum eWireDrawMode {
113
99
        OBDRAW_WIRE_OFF = 0,
115
101
        OBDRAW_WIRE_ON_DEPTH = 2
116
102
} eWireDrawMode;
117
103
 
118
 
/* user data structures for derived mesh callbacks */
119
 
typedef struct foreachScreenVert_userData {
120
 
        void (*func)(void *userData, BMVert *eve, int x, int y, int index);
121
 
        void *userData;
122
 
        ViewContext vc;
123
 
        eV3DClipTest clipVerts;
124
 
} foreachScreenVert_userData;
125
 
 
126
 
typedef struct foreachScreenEdge_userData {
127
 
        void (*func)(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index);
128
 
        void *userData;
129
 
        ViewContext vc;
130
 
        rcti win_rect; /* copy of: vc.ar->winx/winy, use for faster tests, minx/y will always be 0 */
131
 
        eV3DClipTest clipVerts;
132
 
} foreachScreenEdge_userData;
133
 
 
134
 
typedef struct foreachScreenFace_userData {
135
 
        void (*func)(void *userData, BMFace *efa, int x, int y, int index);
136
 
        void *userData;
137
 
        ViewContext vc;
138
 
} foreachScreenFace_userData;
139
 
 
140
104
typedef struct drawDMVerts_userData {
141
 
        BMEditMesh *em; /* BMESH BRANCH ONLY */
 
105
        BMEditMesh *em;
142
106
 
143
107
        int sel;
144
108
        BMVert *eve_act;
 
109
 
 
110
        /* cached theme values */
 
111
        unsigned char th_editmesh_active[4];
 
112
        unsigned char th_vertex_select[4];
 
113
        unsigned char th_vertex[4];
 
114
        unsigned char th_skin_root[4];
 
115
        float th_vertex_size;
 
116
 
 
117
        /* for skin node drawing */
 
118
        int has_vskin;
 
119
        float imat[4][4];
145
120
} drawDMVerts_userData;
146
121
 
147
122
typedef struct drawDMEdgesSel_userData {
148
 
        BMEditMesh *em; /* BMESH BRANCH ONLY */
 
123
        BMEditMesh *em;
149
124
 
150
125
        unsigned char *baseCol, *selCol, *actCol;
151
126
        BMEdge *eed_act;
154
129
typedef struct drawDMFacesSel_userData {
155
130
        unsigned char *cols[3];
156
131
 
157
 
        DerivedMesh *dm; /* BMESH BRANCH ONLY */
158
 
        BMEditMesh *em;  /* BMESH BRANCH ONLY */
 
132
        DerivedMesh *dm;
 
133
        BMEditMesh *em;
159
134
 
160
135
        BMFace *efa_act;
161
 
        int *orig_index;
 
136
        int *orig_index_mf_to_mpoly;
 
137
        int *orig_index_mp_to_orig;
162
138
} drawDMFacesSel_userData;
163
139
 
164
140
typedef struct drawDMNormal_userData {
181
157
static void draw_empty_sphere(float size);
182
158
static void draw_empty_cone(float size);
183
159
 
 
160
static void ob_wire_color_blend_theme_id(const unsigned char ob_wire_col[4], const int theme_id, float fac)
 
161
{
 
162
        float col_wire[3], col_bg[3], col[3];
 
163
 
 
164
        rgb_uchar_to_float(col_wire, ob_wire_col);
 
165
 
 
166
        UI_GetThemeColor3fv(theme_id, col_bg);
 
167
        interp_v3_v3v3(col, col_bg, col_wire, fac);
 
168
        glColor3fv(col);
 
169
}
 
170
 
184
171
/* this condition has been made more complex since editmode can draw textures */
185
 
static int check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
 
172
static bool check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
186
173
{
187
174
        /* texture and material draw modes */
188
 
        if (ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID)
189
 
                return TRUE;
 
175
        if (ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID) {
 
176
                return true;
 
177
        }
190
178
 
191
179
        /* textured solid */
192
 
        if (v3d->drawtype == OB_SOLID && (v3d->flag2 & V3D_SOLID_TEX) && !scene_use_new_shading_nodes(scene))
193
 
                return TRUE;
194
 
        
195
 
        return FALSE;
 
180
        if ((v3d->drawtype == OB_SOLID) &&
 
181
            (v3d->flag2 & V3D_SOLID_TEX) &&
 
182
            (BKE_scene_use_new_shading_nodes(scene) == false))
 
183
        {
 
184
                return true;
 
185
        }
 
186
        
 
187
        if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) {
 
188
                return true;
 
189
        }
 
190
        
 
191
        return false;
196
192
}
197
193
 
198
194
static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
216
212
        return 1;
217
213
}
218
214
 
219
 
/* ************* only use while object drawing **************
220
 
 * or after running ED_view3d_init_mats_rv3d
221
 
 * */
222
 
static void view3d_project_short_clip(ARegion *ar, const float vec[3], short adr[2], int is_local)
223
 
{
224
 
        RegionView3D *rv3d = ar->regiondata;
225
 
        float fx, fy, vec4[4];
226
 
        
227
 
        adr[0] = IS_CLIPPED;
228
 
        
229
 
        /* clipplanes in eye space */
230
 
        if (rv3d->rflag & RV3D_CLIPPING) {
231
 
                if (ED_view3d_clipping_test(rv3d, vec, is_local))
232
 
                        return;
233
 
        }
234
 
        
235
 
        copy_v3_v3(vec4, vec);
236
 
        vec4[3] = 1.0;
237
 
        
238
 
        mul_m4_v4(rv3d->persmatob, vec4);
239
 
        
240
 
        /* clipplanes in window space */
241
 
        if (vec4[3] > (float)BL_NEAR_CLIP) {    /* is the NEAR clipping cutoff for picking */
242
 
                fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
243
 
                
244
 
                if (fx > 0 && fx < ar->winx) {
245
 
                        
246
 
                        fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
247
 
                        
248
 
                        if (fy > 0.0f && fy < (float)ar->winy) {
249
 
                                adr[0] = (short)floorf(fx);
250
 
                                adr[1] = (short)floorf(fy);
251
 
                        }
252
 
                }
253
 
        }
254
 
}
255
 
 
256
 
/* BMESH NOTE: this function is unused in bmesh only */
257
 
 
258
 
/* only use while object drawing */
259
 
static void UNUSED_FUNCTION(view3d_project_short_noclip) (ARegion * ar, const float vec[3], short adr[2])
260
 
{
261
 
        RegionView3D *rv3d = ar->regiondata;
262
 
        float fx, fy, vec4[4];
263
 
        
264
 
        adr[0] = IS_CLIPPED;
265
 
        
266
 
        copy_v3_v3(vec4, vec);
267
 
        vec4[3] = 1.0;
268
 
        
269
 
        mul_m4_v4(rv3d->persmatob, vec4);
270
 
        
271
 
        if (vec4[3] > (float)BL_NEAR_CLIP) {    /* is the NEAR clipping cutoff for picking */
272
 
                fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
273
 
                
274
 
                if (fx > -32700 && fx < 32700) {
275
 
                        
276
 
                        fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
277
 
                        
278
 
                        if (fy > -32700.0f && fy < 32700.0f) {
279
 
                                adr[0] = (short)floorf(fx);
280
 
                                adr[1] = (short)floorf(fy);
281
 
                        }
282
 
                }
283
 
        }
284
 
}
285
 
 
286
 
/* same as view3d_project_short_clip but use persmat instead of persmatob for projection */
287
 
static void view3d_project_short_clip_persmat(ARegion *ar, const float vec[3], short adr[2], int is_local)
288
 
{
289
 
        RegionView3D *rv3d = ar->regiondata;
290
 
        float fx, fy, vec4[4];
291
 
 
292
 
        adr[0] = IS_CLIPPED;
293
 
 
294
 
        /* clipplanes in eye space */
295
 
        if (rv3d->rflag & RV3D_CLIPPING) {
296
 
                if (ED_view3d_clipping_test(rv3d, vec, is_local))
297
 
                        return;
298
 
        }
299
 
 
300
 
        copy_v3_v3(vec4, vec);
301
 
        vec4[3] = 1.0;
302
 
 
303
 
        mul_m4_v4(rv3d->persmat, vec4);
304
 
 
305
 
        /* clipplanes in window space */
306
 
        if (vec4[3] > (float)BL_NEAR_CLIP) {    /* is the NEAR clipping cutoff for picking */
307
 
                fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
308
 
 
309
 
                if (fx > 0 && fx < ar->winx) {
310
 
 
311
 
                        fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
312
 
 
313
 
                        if (fy > 0.0f && fy < (float)ar->winy) {
314
 
                                adr[0] = (short)floorf(fx);
315
 
                                adr[1] = (short)floorf(fy);
316
 
                        }
317
 
                }
318
 
        }
319
 
}
320
215
/* ************************ */
321
216
 
322
217
/* check for glsl drawing */
323
218
 
324
 
int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt)
 
219
int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, const char dt)
325
220
{
326
221
        if (!GPU_glsl_support())
327
222
                return 0;
331
226
                return 0;
332
227
        if (ob == OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
333
228
                return 0;
334
 
        if (scene_use_new_shading_nodes(scene))
 
229
        
 
230
        if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP)
 
231
                return 1;
 
232
        
 
233
        if (BKE_scene_use_new_shading_nodes(scene))
335
234
                return 0;
336
235
        
337
236
        return (scene->gm.matmode == GAME_MAT_GLSL) && (dt > OB_SOLID);
344
243
 
345
244
        if (G.f & G_PICKSEL)
346
245
                return 0;
347
 
        
 
246
 
 
247
        if (base->object->mode & OB_MODE_ALL_PAINT)
 
248
                return 0;
 
249
 
348
250
        return (base->object->dtx & OB_DRAWTRANSP);
349
251
}
350
252
 
351
253
/***/
352
 
static unsigned int colortab[24] =
353
 
{0x0,       0xFF88FF, 0xFFBBFF,
354
 
 0x403000,  0xFFFF88, 0xFFFFBB,
355
 
 0x104040,  0x66CCCC, 0x77CCCC,
356
 
 0x104010,  0x55BB55, 0x66FF66,
357
 
 0xFFFFFF};
 
254
static unsigned int colortab[24] = {
 
255
        0x0,      0xFF88FF, 0xFFBBFF,
 
256
        0x403000, 0xFFFF88, 0xFFFFBB,
 
257
        0x104040, 0x66CCCC, 0x77CCCC,
 
258
        0x104010, 0x55BB55, 0x66FF66,
 
259
        0xFFFFFF
 
260
};
358
261
 
359
262
 
360
263
static float cube[8][3] = {
641
544
 
642
545
 
643
546
/* Function to draw an Image on a empty Object */
644
 
static void draw_empty_image(Object *ob)
 
547
static void draw_empty_image(Object *ob, const short dflag, const unsigned char ob_wire_col[4])
645
548
{
646
549
        Image *ima = (Image *)ob->data;
647
 
        ImBuf *ibuf = ima ? BKE_image_get_ibuf(ima, NULL) : NULL;
 
550
        ImBuf *ibuf = ima ? BKE_image_acquire_ibuf(ima, NULL, NULL) : NULL;
648
551
 
649
552
        float scale, ofs_x, ofs_y, sca_x, sca_y;
650
553
        int ima_x, ima_y;
694
597
        glTranslatef(0.0f,  0.0f,  0.0f);
695
598
 
696
599
        /* Calculate Image scale */
697
 
        scale = (ob->empty_drawsize / (float)MAX2(ima_x * sca_x, ima_y * sca_y));
 
600
        scale = (ob->empty_drawsize / max_ff((float)ima_x * sca_x, (float)ima_y * sca_y));
698
601
 
699
602
        /* Set the object scale */
700
603
        glScalef(scale * sca_x, scale * sca_y, 1.0f);
714
617
                glDisable(GL_BLEND);
715
618
        }
716
619
 
717
 
        UI_ThemeColor((ob->flag & SELECT) ? TH_SELECT : TH_WIRE);
 
620
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
621
                glColor3ubv(ob_wire_col);
718
622
 
719
 
        /* Calculate the outline vertex positions */
720
 
        glBegin(GL_LINE_LOOP);
721
 
        glVertex2f(ofs_x, ofs_y);
722
 
        glVertex2f(ofs_x + ima_x, ofs_y);
723
 
        glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
724
 
        glVertex2f(ofs_x, ofs_y + ima_y);
725
 
        glEnd();
 
623
                /* Calculate the outline vertex positions */
 
624
                glBegin(GL_LINE_LOOP);
 
625
                glVertex2f(ofs_x, ofs_y);
 
626
                glVertex2f(ofs_x + ima_x, ofs_y);
 
627
                glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
 
628
                glVertex2f(ofs_x, ofs_y + ima_y);
 
629
                glEnd();
 
630
        }
726
631
 
727
632
        /* Reset GL settings */
728
633
        glMatrixMode(GL_MODELVIEW);
729
634
        glPopMatrix();
 
635
 
 
636
        BKE_image_release_ibuf(ima, ibuf, NULL);
730
637
}
731
638
 
732
 
static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3], float rad, float tmat[][4])
 
639
static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3], float rad, float tmat[4][4])
733
640
{
734
641
        float vx[3], vy[3];
735
642
        float *viter = (float *)verts;
745
652
        }
746
653
}
747
654
 
748
 
void drawcircball(int mode, const float cent[3], float rad, float tmat[][4])
 
655
void drawcircball(int mode, const float cent[3], float rad, float tmat[4][4])
749
656
{
750
657
        float verts[CIRCLE_RESOL][3];
751
658
 
837
744
 
838
745
        BLI_addtail(strings, vos);
839
746
        copy_v3_v3(vos->vec, co);
840
 
        vos->col.pack = *((int *)col);
 
747
        copy_v4_v4_char((char *)vos->col.ub, (const char *)col);
841
748
        vos->xoffs = xoffs;
842
749
        vos->flag = flag;
843
750
        vos->str_len = alloc_len - 1;
846
753
        memcpy(++vos, str, alloc_len);
847
754
}
848
755
 
849
 
void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, float mat[][4])
 
756
void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, float mat[4][4])
850
757
{
851
758
        RegionView3D *rv3d = ar->regiondata;
852
759
        ListBase *strings = &CachedText[CachedTextLevel - 1];
858
765
                if (mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE))
859
766
                        mul_m4_v3(mat, vos->vec);
860
767
 
861
 
                if (vos->flag & V3D_CACHE_TEXT_GLOBALSPACE)
862
 
                        view3d_project_short_clip_persmat(ar, vos->vec, vos->sco, (vos->flag & V3D_CACHE_TEXT_LOCALCLIP) != 0);
863
 
                else
864
 
                        view3d_project_short_clip(ar, vos->vec, vos->sco, (vos->flag & V3D_CACHE_TEXT_LOCALCLIP) != 0);
865
 
 
866
 
                if (vos->sco[0] != IS_CLIPPED)
 
768
                if (ED_view3d_project_short_ex(ar,
 
769
                                               (vos->flag & V3D_CACHE_TEXT_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob,
 
770
                                               (vos->flag & V3D_CACHE_TEXT_LOCALCLIP) != 0,
 
771
                                               vos->vec, vos->sco,
 
772
                                               V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
 
773
                {
867
774
                        tot++;
 
775
                }
 
776
                else {
 
777
                        vos->sco[0] = IS_CLIPPED;
 
778
                }
868
779
        }
869
780
 
870
781
        if (tot) {
929
840
                if (depth_write) {
930
841
                        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
931
842
                }
932
 
                else glDepthMask(1);
 
843
                else {
 
844
                        glDepthMask(1);
 
845
                }
933
846
                
934
847
                glMatrixMode(GL_PROJECTION);
935
848
                glPopMatrix();
971
884
        glEnd();
972
885
}
973
886
 
974
 
/* draws a cube on given the scaling of the cube, assuming that 
 
887
/* draws a cube on given the scaling of the cube, assuming that
975
888
 * all required matrices have been set (used for drawing empties)
976
889
 */
977
890
static void drawcube_size(float size)
1030
943
}
1031
944
#endif
1032
945
 
1033
 
static void drawshadbuflimits(Lamp *la, float mat[][4])
 
946
static void drawshadbuflimits(Lamp *la, float mat[4][4])
1034
947
{
1035
948
        float sta[3], end[3], lavec[3];
1036
949
 
1177
1090
        glCullFace(GL_BACK);
1178
1091
}
1179
1092
 
1180
 
static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 
1093
static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
1094
                     const char dt, const short dflag, const unsigned char ob_wire_col[4])
1181
1095
{
1182
1096
        Object *ob = base->object;
1183
1097
        const float pixsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
1184
1098
        Lamp *la = ob->data;
1185
1099
        float vec[3], lvec[3], vvec[3], circrad, x, y, z;
1186
1100
        float lampsize;
1187
 
        float imat[4][4], curcol[4];
 
1101
        float imat[4][4];
 
1102
 
 
1103
        unsigned char curcol[4];
1188
1104
        unsigned char col[4];
1189
1105
        /* cone can't be drawn for duplicated lamps, because duplilist would be freed to */
1190
1106
        /* the moment of view3d_draw_transp() call */
1198
1114
 
1199
1115
        if (drawcone && !v3d->transp) {
1200
1116
                /* in this case we need to draw delayed */
1201
 
                add_view3d_after(&v3d->afterdraw_transp, base, flag);
 
1117
                ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
1202
1118
                return;
1203
1119
        }
1204
1120
        
1216
1132
 
1217
1133
        /* lamp center */
1218
1134
        copy_v3_v3(vec, ob->obmat[3]);
1219
 
        
1220
 
        /* for AA effects */
1221
 
        glGetFloatv(GL_CURRENT_COLOR, curcol);
1222
 
        curcol[3] = 0.6;
1223
 
        glColor4fv(curcol);
1224
 
        
 
1135
 
 
1136
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1137
                /* for AA effects */
 
1138
                curcol[0] = ob_wire_col[0];
 
1139
                curcol[1] = ob_wire_col[1];
 
1140
                curcol[2] = ob_wire_col[2];
 
1141
                curcol[3] = 154;
 
1142
                glColor4ubv(curcol);
 
1143
        }
 
1144
 
1225
1145
        if (lampsize > 0.0f) {
1226
1146
 
1227
 
                if (ob->id.us > 1) {
1228
 
                        if (ob == OBACT || (ob->flag & SELECT)) glColor4ub(0x88, 0xFF, 0xFF, 155);
1229
 
                        else glColor4ub(0x77, 0xCC, 0xCC, 155);
 
1147
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1148
                        if (ob->id.us > 1) {
 
1149
                                if (ob == OBACT || (ob->flag & SELECT)) glColor4ub(0x88, 0xFF, 0xFF, 155);
 
1150
                                else glColor4ub(0x77, 0xCC, 0xCC, 155);
 
1151
                        }
1230
1152
                }
1231
1153
                
1232
1154
                /* Inner Circle */
1236
1158
                drawcircball(GL_POLYGON, vec, lampsize, imat);
1237
1159
                
1238
1160
                /* restore */
1239
 
                if (ob->id.us > 1)
1240
 
                        glColor4fv(curcol);
 
1161
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1162
                        if (ob->id.us > 1)
 
1163
                                glColor4ubv(curcol);
 
1164
                }
1241
1165
 
1242
1166
                /* Outer circle */
1243
1167
                circrad = 3.0f * lampsize;
1344
1268
                        glVertex3fv(tvec);
1345
1269
                        glEnd();
1346
1270
                }
1347
 
                else circ(0.0, 0.0, fabsf(z));
1348
 
                
 
1271
                else {
 
1272
                        circ(0.0, 0.0, fabsf(z));
 
1273
                }
 
1274
 
1349
1275
                /* draw the circle/square representing spotbl */
1350
1276
                if (la->type == LA_SPOT) {
1351
1277
                        float spotblcirc = fabs(z) * (1 - pow(la->spotblend, 2));
1374
1300
                        glVertex3fv(vvec_clip);
1375
1301
                        glEnd();
1376
1302
                }
 
1303
                /* Else, draw spot direction (using distance as end limit, same as for Area lamp). */
 
1304
                else {
 
1305
                        glBegin(GL_LINE_STRIP);
 
1306
                        glVertex3f(0.0, 0.0, -circrad);
 
1307
                        glVertex3f(0.0, 0.0, -la->dist);
 
1308
                        glEnd();
 
1309
                }
1377
1310
        }
1378
1311
        else if (ELEM(la->type, LA_HEMI, LA_SUN)) {
1379
1312
                
1469
1402
        
1470
1403
        glDisable(GL_BLEND);
1471
1404
        
1472
 
        /* restore for drawing extra stuff */
1473
 
        glColor3fv(curcol);
1474
 
 
 
1405
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1406
                /* restore for drawing extra stuff */
 
1407
                glColor3ubv(ob_wire_col);
 
1408
        }
1475
1409
}
1476
1410
 
1477
1411
static void draw_limit_line(float sta, float end, unsigned int col)
1488
1422
        glVertex3f(0.0, 0.0, -end);
1489
1423
        glEnd();
1490
1424
        glPointSize(1.0);
1491
 
}               
 
1425
}
1492
1426
 
1493
1427
 
1494
1428
/* yafray: draw camera focus point (cross, similar to aqsis code in tuhopuu) */
1504
1438
}
1505
1439
 
1506
1440
#ifdef VIEW3D_CAMERA_BORDER_HACK
1507
 
float view3d_camera_border_hack_col[4];
 
1441
unsigned char view3d_camera_border_hack_col[3];
1508
1442
short view3d_camera_border_hack_test = FALSE;
1509
1443
#endif
1510
1444
 
1534
1468
}
1535
1469
 
1536
1470
static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D *v3d,
1537
 
                                                MovieClip *clip, MovieTrackingObject *tracking_object, int flag,
 
1471
                                                MovieClip *clip, MovieTrackingObject *tracking_object,
 
1472
                                                const short dflag, const unsigned char ob_wire_col[4],
1538
1473
                                                int *global_track_index, int draw_selected)
1539
1474
{
1540
1475
        MovieTracking *tracking = &clip->tracking;
1541
1476
        MovieTrackingTrack *track;
1542
1477
        float mat[4][4], imat[4][4];
1543
 
        unsigned char col[4], scol[4];
 
1478
        unsigned char col_unsel[4], col_sel[4];
1544
1479
        int tracknr = *global_track_index;
1545
 
        ListBase *tracksbase = BKE_tracking_object_tracks(tracking, tracking_object);
1546
 
 
1547
 
        UI_GetThemeColor4ubv(TH_TEXT, col);
1548
 
        UI_GetThemeColor4ubv(TH_SELECT, scol);
1549
 
 
1550
 
        BKE_get_tracking_mat(scene, base->object, mat);
 
1480
        ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
 
1481
 
 
1482
        UI_GetThemeColor4ubv(TH_TEXT, col_unsel);
 
1483
        UI_GetThemeColor4ubv(TH_SELECT, col_sel);
 
1484
 
 
1485
        BKE_tracking_get_camera_object_matrix(scene, base->object, mat);
1551
1486
 
1552
1487
        glPushMatrix();
1553
1488
 
1563
1498
        else {
1564
1499
                float obmat[4][4];
1565
1500
 
1566
 
                BKE_tracking_get_interpolated_camera(tracking, tracking_object, scene->r.cfra, obmat);
 
1501
                BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object, scene->r.cfra, obmat);
1567
1502
 
1568
1503
                invert_m4_m4(imat, obmat);
1569
1504
                glMultMatrixf(imat);
1578
1513
                if ((track->flag & TRACK_HAS_BUNDLE) == 0)
1579
1514
                        continue;
1580
1515
 
1581
 
                if (flag & DRAW_PICKING)
 
1516
                if (dflag & DRAW_PICKING)
1582
1517
                        glLoadName(base->selcol + (tracknr << 16));
1583
1518
 
1584
1519
                glPushMatrix();
1588
1523
                if (v3d->drawtype == OB_WIRE) {
1589
1524
                        glDisable(GL_LIGHTING);
1590
1525
 
1591
 
                        if (selected) {
1592
 
                                if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
1593
 
                                else UI_ThemeColor(TH_SELECT);
1594
 
                        }
1595
 
                        else {
1596
 
                                if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
1597
 
                                else UI_ThemeColor(TH_WIRE);
 
1526
                        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1527
                                if (selected && (track->flag & TRACK_CUSTOMCOLOR) == 0) {
 
1528
                                        glColor3ubv(ob_wire_col);
 
1529
                                }
 
1530
                                else {
 
1531
                                        glColor3fv(track->color);
 
1532
                                }
1598
1533
                        }
1599
1534
 
1600
1535
                        drawaxes(0.05f, v3d->bundle_drawtype);
1605
1540
                        if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) {
1606
1541
                                /* selection outline */
1607
1542
                                if (selected) {
1608
 
                                        if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
1609
 
                                        else UI_ThemeColor(TH_SELECT);
 
1543
                                        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1544
                                                glColor3ubv(ob_wire_col);
 
1545
                                        }
1610
1546
 
1611
1547
                                        glLineWidth(2.f);
1612
1548
                                        glDisable(GL_LIGHTING);
1619
1555
                                        glLineWidth(1.f);
1620
1556
                                }
1621
1557
 
1622
 
                                if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
1623
 
                                else UI_ThemeColor(TH_BUNDLE_SOLID);
 
1558
                                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1559
                                        if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 
1560
                                        else UI_ThemeColor(TH_BUNDLE_SOLID);
 
1561
                                }
1624
1562
 
1625
1563
                                draw_bundle_sphere();
1626
1564
                        }
1627
1565
                        else {
1628
1566
                                glDisable(GL_LIGHTING);
1629
1567
 
1630
 
                                if (selected) {
1631
 
                                        if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
1632
 
                                        else UI_ThemeColor(TH_SELECT);
1633
 
                                }
1634
 
                                else {
1635
 
                                        if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
1636
 
                                        else UI_ThemeColor(TH_WIRE);
 
1568
                                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1569
                                        if (selected) {
 
1570
                                                glColor3ubv(ob_wire_col);
 
1571
                                        }
 
1572
                                        else {
 
1573
                                                if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 
1574
                                                else UI_ThemeColor(TH_WIRE);
 
1575
                                        }
1637
1576
                                }
1638
1577
 
1639
1578
                                drawaxes(0.05f, v3d->bundle_drawtype);
1644
1583
 
1645
1584
                glPopMatrix();
1646
1585
 
1647
 
                if ((flag & DRAW_PICKING) == 0 && (v3d->flag2 & V3D_SHOW_BUNDLENAME)) {
 
1586
                if ((dflag & DRAW_PICKING) == 0 && (v3d->flag2 & V3D_SHOW_BUNDLENAME)) {
1648
1587
                        float pos[3];
1649
 
                        unsigned char tcol[4];
1650
 
 
1651
 
                        if (selected) memcpy(tcol, scol, sizeof(tcol));
1652
 
                        else memcpy(tcol, col, sizeof(tcol));
1653
1588
 
1654
1589
                        mul_v3_m4v3(pos, mat, track->bundle_pos);
1655
 
                        view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
 
1590
                        view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, selected ? col_sel : col_unsel);
1656
1591
                }
1657
1592
 
1658
1593
                tracknr++;
1659
1594
        }
1660
1595
 
1661
 
        if ((flag & DRAW_PICKING) == 0) {
 
1596
        if ((dflag & DRAW_PICKING) == 0) {
1662
1597
                if ((v3d->flag2 & V3D_SHOW_CAMERAPATH) && (tracking_object->flag & TRACKING_OBJECT_CAMERA)) {
1663
1598
                        MovieTrackingReconstruction *reconstruction;
1664
 
                        reconstruction = BKE_tracking_object_reconstruction(tracking, tracking_object);
 
1599
                        reconstruction = BKE_tracking_object_get_reconstruction(tracking, tracking_object);
1665
1600
 
1666
1601
                        if (reconstruction->camnr) {
1667
1602
                                MovieReconstructedCamera *camera = reconstruction->cameras;
1689
1624
}
1690
1625
 
1691
1626
static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip,
1692
 
                                         int flag, int draw_selected)
 
1627
                                         const short dflag, const unsigned char ob_wire_col[4],
 
1628
                                         int draw_selected)
1693
1629
{
1694
1630
        MovieTracking *tracking = &clip->tracking;
1695
1631
        MovieTrackingObject *tracking_object;
1696
 
        float curcol[4];
1697
1632
        int global_track_index = 1;
1698
1633
 
1699
1634
        if ((v3d->flag2 & V3D_SHOW_RECONSTRUCTION) == 0)
1702
1637
        if (v3d->flag2 & V3D_RENDER_OVERRIDE)
1703
1638
                return;
1704
1639
 
1705
 
        glGetFloatv(GL_CURRENT_COLOR, curcol);
1706
 
 
1707
1640
        glEnable(GL_LIGHTING);
1708
1641
        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
1709
1642
        glEnable(GL_COLOR_MATERIAL);
1712
1645
        tracking_object = tracking->objects.first;
1713
1646
        while (tracking_object) {
1714
1647
                draw_viewport_object_reconstruction(scene, base, v3d, clip, tracking_object,
1715
 
                                                    flag, &global_track_index, draw_selected);
 
1648
                                                    dflag, ob_wire_col, &global_track_index, draw_selected);
1716
1649
 
1717
1650
                tracking_object = tracking_object->next;
1718
1651
        }
1722
1655
        glDisable(GL_COLOR_MATERIAL);
1723
1656
        glDisable(GL_LIGHTING);
1724
1657
 
1725
 
        glColor4fv(curcol);
 
1658
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1659
                glColor3ubv(ob_wire_col);
 
1660
        }
1726
1661
 
1727
 
        if (flag & DRAW_PICKING)
 
1662
        if (dflag & DRAW_PICKING)
1728
1663
                glLoadName(base->selcol);
1729
1664
}
1730
1665
 
1731
1666
/* flag similar to draw_object() */
1732
 
static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int flag)
 
1667
static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
1668
                       const short dflag, const unsigned char ob_wire_col[4])
1733
1669
{
1734
1670
        /* a standing up pyramid with (0,0,0) as top */
1735
1671
        Camera *cam;
1739
1675
        int i;
1740
1676
        float drawsize;
1741
1677
        const short is_view = (rv3d->persp == RV3D_CAMOB && ob == v3d->camera);
1742
 
        MovieClip *clip = object_get_movieclip(scene, base->object, 0);
 
1678
        MovieClip *clip = BKE_object_movieclip_get(scene, base->object, 0);
1743
1679
 
1744
1680
        /* draw data for movie clip set as active for scene */
1745
1681
        if (clip) {
1746
 
                draw_viewport_reconstruction(scene, base, v3d, clip, flag, FALSE);
1747
 
                draw_viewport_reconstruction(scene, base, v3d, clip, flag, TRUE);
 
1682
                draw_viewport_reconstruction(scene, base, v3d, clip, dflag, ob_wire_col, FALSE);
 
1683
                draw_viewport_reconstruction(scene, base, v3d, clip, dflag, ob_wire_col, TRUE);
1748
1684
        }
1749
1685
 
1750
1686
#ifdef VIEW3D_CAMERA_BORDER_HACK
1751
1687
        if (is_view && !(G.f & G_PICKSEL)) {
1752
 
                glGetFloatv(GL_CURRENT_COLOR, view3d_camera_border_hack_col);
 
1688
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
1689
                        view3d_camera_border_hack_col[0] = ob_wire_col[0];
 
1690
                        view3d_camera_border_hack_col[1] = ob_wire_col[1];
 
1691
                        view3d_camera_border_hack_col[2] = ob_wire_col[2];
 
1692
                }
 
1693
                else {
 
1694
                        float col[4];
 
1695
                        glGetFloatv(GL_CURRENT_COLOR, col);
 
1696
                        rgb_float_to_uchar(view3d_camera_border_hack_col, col);
 
1697
                }
1753
1698
                view3d_camera_border_hack_test = TRUE;
1754
1699
                return;
1755
1700
        }
1761
1706
        scale[1] = 1.0f / len_v3(ob->obmat[1]);
1762
1707
        scale[2] = 1.0f / len_v3(ob->obmat[2]);
1763
1708
 
1764
 
        camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale,
1765
 
                             asp, shift, &drawsize, vec);
 
1709
        BKE_camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale,
 
1710
                                 asp, shift, &drawsize, vec);
1766
1711
 
1767
1712
        glDisable(GL_LIGHTING);
1768
1713
        glDisable(GL_CULL_FACE);
1817
1762
                glEnd();
1818
1763
        }
1819
1764
 
1820
 
        if (flag == 0) {
 
1765
        if (dflag == 0) {
1821
1766
                if (cam->flag & (CAM_SHOWLIMITS + CAM_SHOWMIST)) {
1822
1767
                        float nobmat[4][4];
1823
1768
                        World *wrld;
1833
1778
                        if (cam->flag & CAM_SHOWLIMITS) {
1834
1779
                                draw_limit_line(cam->clipsta, cam->clipend, 0x77FFFF);
1835
1780
                                /* qdn: was yafray only, now also enabled for Blender to be used with defocus composite node */
1836
 
                                draw_focus_cross(object_camera_dof_distance(ob), cam->drawsize);
 
1781
                                draw_focus_cross(BKE_camera_object_dof_distance(ob), cam->drawsize);
1837
1782
                        }
1838
1783
 
1839
1784
                        wrld = scene->world;
1918
1863
        bglEnd();
1919
1864
}
1920
1865
 
1921
 
void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPoint *bp, int x, int y), void *userData)
1922
 
{
1923
 
        Object *obedit = vc->obedit;
1924
 
        Lattice *lt = obedit->data;
1925
 
        BPoint *bp = lt->editlatt->latt->def;
1926
 
        DispList *dl = find_displist(&obedit->disp, DL_VERTS);
1927
 
        float *co = dl ? dl->verts : NULL;
1928
 
        int i, N = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
1929
 
        short s[2] = {IS_CLIPPED, 0};
1930
 
 
1931
 
        ED_view3d_clipping_local(vc->rv3d, obedit->obmat); /* for local clipping lookups */
1932
 
 
1933
 
        for (i = 0; i < N; i++, bp++, co += 3) {
1934
 
                if (bp->hide == 0) {
1935
 
                        view3d_project_short_clip(vc->ar, dl ? co : bp->vec, s, TRUE);
1936
 
                        if (s[0] != IS_CLIPPED)
1937
 
                                func(userData, bp, s[0], s[1]);
1938
 
                }
1939
 
        }
1940
 
}
1941
 
 
1942
1866
static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, int use_wcol)
1943
1867
{
1944
1868
        int index = ((w * lt->pntsv + v) * lt->pntsu) + u;
1966
1890
        Lattice *lt = ob->data;
1967
1891
        DispList *dl;
1968
1892
        int u, v, w;
1969
 
        int use_wcol = 0, is_edit = (lt->editlatt != NULL);
 
1893
        int use_wcol = FALSE, is_edit = (lt->editlatt != NULL);
1970
1894
 
1971
1895
        /* now we default make displist, this will modifiers work for non animated case */
1972
1896
        if (ob->disp.first == NULL)
1973
 
                lattice_calc_modifiers(scene, ob);
1974
 
        dl = find_displist(&ob->disp, DL_VERTS);
 
1897
                BKE_lattice_modifiers_calc(scene, ob);
 
1898
        dl = BKE_displist_find(&ob->disp, DL_VERTS);
1975
1899
        
1976
1900
        if (is_edit) {
1977
1901
                lt = lt->editlatt->latt;
2025
1949
 
2026
1950
/* ***************** ******************** */
2027
1951
 
2028
 
/* Note! - foreach funcs should be called while drawing or directly after
2029
 
 * if not, ED_view3d_init_mats_rv3d() can be used for selection tools
2030
 
 * but would not give correct results with dupli's for eg. which don't
2031
 
 * use the object matrix in the usual way */
2032
 
static void mesh_foreachScreenVert__mapFunc(void *userData, int index, const float co[3],
2033
 
                                            const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
2034
 
{
2035
 
        foreachScreenVert_userData *data = userData;
2036
 
        BMVert *eve = EDBM_vert_at_index(data->vc.em, index);
2037
 
 
2038
 
        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
2039
 
                short s[2] = {IS_CLIPPED, 0};
2040
 
 
2041
 
                if (data->clipVerts != V3D_CLIP_TEST_OFF) {
2042
 
                        view3d_project_short_clip(data->vc.ar, co, s, TRUE);
2043
 
                }
2044
 
                else {
2045
 
                        float co2[2];
2046
 
                        mul_v3_m4v3(co2, data->vc.obedit->obmat, co);
2047
 
                        project_short_noclip(data->vc.ar, co2, s);
2048
 
                }
2049
 
 
2050
 
                if (s[0] != IS_CLIPPED)
2051
 
                        data->func(data->userData, eve, s[0], s[1], index);
2052
 
        }
2053
 
}
2054
 
 
2055
 
void mesh_foreachScreenVert(
2056
 
    ViewContext *vc,
2057
 
    void (*func)(void *userData, BMVert *eve, int x, int y, int index),
2058
 
    void *userData, eV3DClipTest clipVerts)
2059
 
{
2060
 
        foreachScreenVert_userData data;
2061
 
        DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
2062
 
        
2063
 
        data.vc = *vc;
2064
 
        data.func = func;
2065
 
        data.userData = userData;
2066
 
        data.clipVerts = clipVerts;
2067
 
 
2068
 
        if (clipVerts != V3D_CLIP_TEST_OFF)
2069
 
                ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat);  /* for local clipping lookups */
2070
 
 
2071
 
        EDBM_index_arrays_init(vc->em, 1, 0, 0);
2072
 
        dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
2073
 
        EDBM_index_arrays_free(vc->em);
2074
 
 
2075
 
        dm->release(dm);
2076
 
}
2077
 
 
2078
1952
/*  draw callback */
2079
1953
static void drawSelectedVertices__mapFunc(void *userData, int index, const float co[3],
2080
1954
                                          const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
2084
1958
        if (!(mv->flag & ME_HIDE)) {
2085
1959
                const char sel = mv->flag & SELECT;
2086
1960
 
2087
 
                // TODO define selected color
 
1961
                /* TODO define selected color */
2088
1962
                if (sel) {
2089
1963
                        glColor3f(1.0f, 1.0f, 0.0f);
2090
1964
                }
2103
1977
        glEnd();
2104
1978
}
2105
1979
 
2106
 
static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, const float v0co[3], const float v1co[3])
2107
 
{
2108
 
        foreachScreenEdge_userData *data = userData;
2109
 
        BMEdge *eed = EDBM_edge_at_index(data->vc.em, index);
2110
 
 
2111
 
        if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
2112
 
                short s[2][2];
2113
 
 
2114
 
                if (data->clipVerts == V3D_CLIP_TEST_RV3D_CLIPPING) {
2115
 
                        view3d_project_short_clip(data->vc.ar, v0co, s[0], TRUE);
2116
 
                        view3d_project_short_clip(data->vc.ar, v1co, s[1], TRUE);
2117
 
                }
2118
 
                else {
2119
 
                        float v1_co[3], v2_co[3];
2120
 
 
2121
 
                        mul_v3_m4v3(v1_co, data->vc.obedit->obmat, v0co);
2122
 
                        mul_v3_m4v3(v2_co, data->vc.obedit->obmat, v1co);
2123
 
 
2124
 
                        project_short_noclip(data->vc.ar, v1_co, s[0]);
2125
 
                        project_short_noclip(data->vc.ar, v2_co, s[1]);
2126
 
 
2127
 
                        if (data->clipVerts == V3D_CLIP_TEST_REGION) {
2128
 
                                /* make an int copy */
2129
 
                                int s_int[2][2] = {{s[0][0], s[0][1]},
2130
 
                                                   {s[1][0], s[1][1]}};
2131
 
                                if (!BLI_segment_in_rcti(&data->win_rect, s_int[0], s_int[1])) {
2132
 
                                        return;
2133
 
                                }
2134
 
                        }
2135
 
                }
2136
 
 
2137
 
                data->func(data->userData, eed, s[0][0], s[0][1], s[1][0], s[1][1], index);
2138
 
        }
2139
 
}
2140
 
 
2141
 
void mesh_foreachScreenEdge(
2142
 
    ViewContext *vc,
2143
 
    void (*func)(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index),
2144
 
    void *userData, eV3DClipTest clipVerts)
2145
 
{
2146
 
        foreachScreenEdge_userData data;
2147
 
        DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
2148
 
 
2149
 
        data.vc = *vc;
2150
 
 
2151
 
        data.win_rect.xmin = 0;
2152
 
        data.win_rect.ymin = 0;
2153
 
        data.win_rect.xmax = vc->ar->winx;
2154
 
        data.win_rect.ymax = vc->ar->winy;
2155
 
 
2156
 
        data.func = func;
2157
 
        data.userData = userData;
2158
 
        data.clipVerts = clipVerts;
2159
 
 
2160
 
        if (clipVerts != V3D_CLIP_TEST_OFF)
2161
 
                ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat);  /* for local clipping lookups */
2162
 
 
2163
 
        EDBM_index_arrays_init(vc->em, 0, 1, 0);
2164
 
        dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
2165
 
        EDBM_index_arrays_free(vc->em);
2166
 
 
2167
 
        dm->release(dm);
2168
 
}
2169
 
 
2170
 
static void mesh_foreachScreenFace__mapFunc(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
2171
 
{
2172
 
        foreachScreenFace_userData *data = userData;
2173
 
        BMFace *efa = EDBM_face_at_index(data->vc.em, index);
2174
 
 
2175
 
        if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
2176
 
                float cent2[3];
2177
 
                short s[2];
2178
 
 
2179
 
                mul_v3_m4v3(cent2, data->vc.obedit->obmat, cent);
2180
 
                project_short(data->vc.ar, cent2, s);
2181
 
 
2182
 
                if (s[0] != IS_CLIPPED) {
2183
 
                        data->func(data->userData, efa, s[0], s[1], index);
2184
 
                }
2185
 
        }
2186
 
}
2187
 
 
2188
 
void mesh_foreachScreenFace(
2189
 
    ViewContext *vc,
2190
 
    void (*func)(void *userData, BMFace *efa, int x, int y, int index),
2191
 
    void *userData)
2192
 
{
2193
 
        foreachScreenFace_userData data;
2194
 
        DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
2195
 
 
2196
 
        data.vc = *vc;
2197
 
        data.func = func;
2198
 
        data.userData = userData;
2199
 
 
2200
 
        //if (clipVerts)
2201
 
        ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
2202
 
 
2203
 
        EDBM_index_arrays_init(vc->em, 0, 0, 1);
2204
 
        dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
2205
 
        EDBM_index_arrays_free(vc->em);
2206
 
 
2207
 
        dm->release(dm);
2208
 
}
2209
 
 
2210
 
void nurbs_foreachScreenVert(
2211
 
    ViewContext *vc,
2212
 
    void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y),
2213
 
    void *userData)
2214
 
{
2215
 
        Curve *cu = vc->obedit->data;
2216
 
        short s[2] = {IS_CLIPPED, 0};
2217
 
        Nurb *nu;
2218
 
        int i;
2219
 
        ListBase *nurbs = curve_editnurbs(cu);
2220
 
 
2221
 
        ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
2222
 
 
2223
 
        for (nu = nurbs->first; nu; nu = nu->next) {
2224
 
                if (nu->type == CU_BEZIER) {
2225
 
                        for (i = 0; i < nu->pntsu; i++) {
2226
 
                                BezTriple *bezt = &nu->bezt[i];
2227
 
 
2228
 
                                if (bezt->hide == 0) {
2229
 
                                        
2230
 
                                        if (cu->drawflag & CU_HIDE_HANDLES) {
2231
 
                                                view3d_project_short_clip(vc->ar, bezt->vec[1], s, TRUE);
2232
 
                                                if (s[0] != IS_CLIPPED)
2233
 
                                                        func(userData, nu, NULL, bezt, 1, s[0], s[1]);
2234
 
                                        }
2235
 
                                        else {
2236
 
                                                view3d_project_short_clip(vc->ar, bezt->vec[0], s, TRUE);
2237
 
                                                if (s[0] != IS_CLIPPED)
2238
 
                                                        func(userData, nu, NULL, bezt, 0, s[0], s[1]);
2239
 
                                                view3d_project_short_clip(vc->ar, bezt->vec[1], s, TRUE);
2240
 
                                                if (s[0] != IS_CLIPPED)
2241
 
                                                        func(userData, nu, NULL, bezt, 1, s[0], s[1]);
2242
 
                                                view3d_project_short_clip(vc->ar, bezt->vec[2], s, TRUE);
2243
 
                                                if (s[0] != IS_CLIPPED)
2244
 
                                                        func(userData, nu, NULL, bezt, 2, s[0], s[1]);
2245
 
                                        }
2246
 
                                }
2247
 
                        }
2248
 
                }
2249
 
                else {
2250
 
                        for (i = 0; i < nu->pntsu * nu->pntsv; i++) {
2251
 
                                BPoint *bp = &nu->bp[i];
2252
 
 
2253
 
                                if (bp->hide == 0) {
2254
 
                                        view3d_project_short_clip(vc->ar, bp->vec, s, TRUE);
2255
 
                                        if (s[0] != IS_CLIPPED)
2256
 
                                                func(userData, nu, bp, NULL, -1, s[0], s[1]);
2257
 
                                }
2258
 
                        }
2259
 
                }
2260
 
        }
2261
 
}
2262
 
 
2263
1980
/* ************** DRAW MESH ****************** */
2264
1981
 
2265
 
/* First section is all the "simple" draw routines, 
 
1982
/* First section is all the "simple" draw routines,
2266
1983
 * ones that just pass some sort of primitive to GL,
2267
1984
 * with perhaps various options to control lighting,
2268
1985
 * color, etc.
2399
2116
        BMVert *eve = EDBM_vert_at_index(data->em, index);
2400
2117
 
2401
2118
        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT) == data->sel) {
 
2119
                /* skin nodes: draw a red circle around the root
 
2120
                 * node(s) */
 
2121
                if (data->has_vskin) {
 
2122
                        const MVertSkin *vs = CustomData_bmesh_get(&data->em->bm->vdata,
 
2123
                                                                   eve->head.data,
 
2124
                                                                   CD_MVERT_SKIN);
 
2125
                        if (vs->flag & MVERT_SKIN_ROOT) {
 
2126
                                float radius = (vs->radius[0] + vs->radius[1]) * 0.5f;
 
2127
                                bglEnd();
 
2128
                        
 
2129
                                glColor4ubv(data->th_skin_root);
 
2130
                                drawcircball(GL_LINES, co, radius, data->imat);
 
2131
 
 
2132
                                glColor4ubv(data->sel ? data->th_vertex_select : data->th_vertex);
 
2133
                                bglBegin(GL_POINTS);
 
2134
                        }
 
2135
                }
 
2136
 
2402
2137
                /* draw active larger - need to stop/start point drawing for this :/ */
2403
2138
                if (eve == data->eve_act) {
2404
 
                        float size = UI_GetThemeValuef(TH_VERTEX_SIZE);
2405
 
                        UI_ThemeColor4(TH_EDITMESH_ACTIVE);
 
2139
                        glColor4ubv(data->th_editmesh_active);
2406
2140
                        
2407
2141
                        bglEnd();
2408
2142
                        
2409
 
                        glPointSize(size);
 
2143
                        glPointSize(data->th_vertex_size);
2410
2144
                        bglBegin(GL_POINTS);
2411
2145
                        bglVertex3fv(co);
2412
2146
                        bglEnd();
2413
 
                        
2414
 
                        UI_ThemeColor4(data->sel ? TH_VERTEX_SELECT : TH_VERTEX);
2415
 
                        glPointSize(size);
 
2147
 
 
2148
                        glColor4ubv(data->sel ? data->th_vertex_select : data->th_vertex);
 
2149
                        glPointSize(data->th_vertex_size);
2416
2150
                        bglBegin(GL_POINTS);
2417
2151
                }
2418
2152
                else {
2421
2155
        }
2422
2156
}
2423
2157
 
2424
 
static void draw_dm_verts(BMEditMesh *em, DerivedMesh *dm, int sel, BMVert *eve_act)
 
2158
static void draw_dm_verts(BMEditMesh *em, DerivedMesh *dm, int sel, BMVert *eve_act,
 
2159
                          RegionView3D *rv3d)
2425
2160
{
2426
2161
        drawDMVerts_userData data;
2427
2162
        data.sel = sel;
2428
2163
        data.eve_act = eve_act;
2429
2164
        data.em = em;
2430
2165
 
 
2166
        /* Cache theme values */
 
2167
        UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, data.th_editmesh_active);
 
2168
        UI_GetThemeColor4ubv(TH_VERTEX_SELECT, data.th_vertex_select);
 
2169
        UI_GetThemeColor4ubv(TH_VERTEX, data.th_vertex);
 
2170
        UI_GetThemeColor4ubv(TH_SKIN_ROOT, data.th_skin_root);
 
2171
        data.th_vertex_size = UI_GetThemeValuef(TH_VERTEX_SIZE);
 
2172
 
 
2173
        /* For skin root drawing */
 
2174
        data.has_vskin = CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN);
 
2175
        /* view-aligned matrix */
 
2176
        mult_m4_m4m4(data.imat, rv3d->viewmat, em->ob->obmat);
 
2177
        invert_m4(data.imat);
 
2178
 
2431
2179
        bglBegin(GL_POINTS);
2432
2180
        dm->foreachMappedVert(dm, draw_dm_verts__mapFunc, &data);
2433
2181
        bglEnd();
2466
2214
                return DM_DRAW_OPTION_SKIP;
2467
2215
        }
2468
2216
}
2469
 
static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol, 
 
2217
static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
2470
2218
                              unsigned char *selCol, unsigned char *actCol, BMEdge *eed_act)
2471
2219
{
2472
2220
        drawDMEdgesSel_userData data;
2488
2236
                return DM_DRAW_OPTION_NORMAL;
2489
2237
}
2490
2238
 
2491
 
static void draw_dm_edges(BMEditMesh *em, DerivedMesh *dm) 
 
2239
static void draw_dm_edges(BMEditMesh *em, DerivedMesh *dm)
2492
2240
{
2493
2241
        dm->drawMappedEdges(dm, draw_dm_edges__setDrawOptions, em);
2494
2242
}
2590
2338
 
2591
2339
        unsigned char *col, *next_col;
2592
2340
 
2593
 
        if (!data->orig_index)
 
2341
        if (!data->orig_index_mf_to_mpoly)
2594
2342
                return 0;
2595
2343
 
2596
 
        efa = EDBM_face_at_index(data->em, data->orig_index[index]);
2597
 
        next_efa = EDBM_face_at_index(data->em, data->orig_index[next_index]);
 
2344
        efa = EDBM_face_at_index(data->em, DM_origindex_mface_mpoly(data->orig_index_mf_to_mpoly, data->orig_index_mp_to_orig, index));
 
2345
        next_efa = EDBM_face_at_index(data->em, DM_origindex_mface_mpoly(data->orig_index_mf_to_mpoly, data->orig_index_mp_to_orig, next_index));
2598
2346
 
2599
2347
        if (efa == next_efa)
2600
2348
                return 1;
2612
2360
}
2613
2361
 
2614
2362
/* also draws the active face */
2615
 
static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol, 
 
2363
static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
2616
2364
                              unsigned char *selCol, unsigned char *actCol, BMFace *efa_act)
2617
2365
{
2618
2366
        drawDMFacesSel_userData data;
2622
2370
        data.cols[1] = selCol;
2623
2371
        data.cols[2] = actCol;
2624
2372
        data.efa_act = efa_act;
2625
 
        data.orig_index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
 
2373
        /* double lookup */
 
2374
        data.orig_index_mf_to_mpoly = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
 
2375
        data.orig_index_mp_to_orig  = DM_get_poly_data_layer(dm, CD_ORIGINDEX);
 
2376
        if ((data.orig_index_mf_to_mpoly && data.orig_index_mp_to_orig) == FALSE) {
 
2377
                data.orig_index_mf_to_mpoly = data.orig_index_mp_to_orig = NULL;
 
2378
        }
2626
2379
 
2627
2380
        dm->drawMappedFaces(dm, draw_dm_faces_sel__setDrawOptions, GPU_enable_material, draw_dm_faces_sel__compareDrawOptions, &data, 0);
2628
2381
}
2709
2462
 
2710
2463
/* EditMesh drawing routines*/
2711
2464
 
2712
 
static void draw_em_fancy_verts(Scene *scene, View3D *v3d, Object *obedit, 
2713
 
                                BMEditMesh *em, DerivedMesh *cageDM, BMVert *eve_act)
 
2465
static void draw_em_fancy_verts(Scene *scene, View3D *v3d, Object *obedit,
 
2466
                                BMEditMesh *em, DerivedMesh *cageDM, BMVert *eve_act,
 
2467
                                RegionView3D *rv3d)
2714
2468
{
2715
2469
        ToolSettings *ts = scene->toolsettings;
2716
2470
        int sel;
2717
2471
 
2718
 
        if (v3d->zbuf) glDepthMask(0);      // disable write in zbuffer, zbuf select
 
2472
        if (v3d->zbuf) glDepthMask(0);  /* disable write in zbuffer, zbuf select */
2719
2473
 
2720
2474
        for (sel = 0; sel < 2; sel++) {
2721
2475
                unsigned char col[4], fcol[4];
2749
2503
                        if (ts->selectmode & SCE_SELECT_VERTEX) {
2750
2504
                                glPointSize(size);
2751
2505
                                glColor4ubv(col);
2752
 
                                draw_dm_verts(em, cageDM, sel, eve_act);
 
2506
                                draw_dm_verts(em, cageDM, sel, eve_act, rv3d);
2753
2507
                        }
2754
2508
                        
2755
2509
                        if (check_ob_drawface_dot(scene, v3d, obedit->dt)) {
2777
2531
        int pass;
2778
2532
        unsigned char wireCol[4], selCol[4], actCol[4];
2779
2533
 
2780
 
        /* since this function does transparant... */
 
2534
        /* since this function does transparent... */
2781
2535
        UI_GetThemeColor4ubv(TH_EDGE_SELECT, selCol);
2782
2536
        UI_GetThemeColor4ubv(TH_WIRE, wireCol);
2783
2537
        UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, actCol);
2788
2542
                wireCol[3] = 0;
2789
2543
 
2790
2544
        for (pass = 0; pass < 2; pass++) {
2791
 
                /* show wires in transparant when no zbuf clipping for select */
 
2545
                /* show wires in transparent when no zbuf clipping for select */
2792
2546
                if (pass == 0) {
2793
2547
                        if (v3d->zbuf && (v3d->flag & V3D_ZBUF_SELECT) == 0) {
2794
2548
                                glEnable(GL_BLEND);
2808
2562
                if (ts->selectmode == SCE_SELECT_FACE) {
2809
2563
                        draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act);
2810
2564
                }
2811
 
                else if ( (me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE) ) {
 
2565
                else if ((me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE)) {
2812
2566
                        if (cageDM->drawMappedEdgesInterp && (ts->selectmode & SCE_SELECT_VERTEX)) {
2813
2567
                                glShadeModel(GL_SMOOTH);
2814
2568
                                draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol);
2830
2584
                        glEnable(GL_DEPTH_TEST);
2831
2585
                }
2832
2586
        }
2833
 
}       
 
2587
}
2834
2588
 
2835
2589
static void draw_em_measure_stats(View3D *v3d, Object *ob, BMEditMesh *em, UnitSettings *unit)
2836
2590
{
2849
2603
        BMIter iter;
2850
2604
        int i;
2851
2605
 
2852
 
        /* make the precision of the pronted value proportionate to the gridsize */
 
2606
        /* make the precision of the display value proportionate to the gridsize */
2853
2607
 
2854
 
        if (grid < 0.01f) conv_float = "%.6g";
2855
 
        else if (grid < 0.1f) conv_float = "%.5g";
2856
 
        else if (grid < 1.0f) conv_float = "%.4g";
2857
 
        else if (grid < 10.0f) conv_float = "%.3g";
 
2608
        if (grid <= 0.01f) conv_float = "%.6g";
 
2609
        else if (grid <= 0.1f) conv_float = "%.5g";
 
2610
        else if (grid <= 1.0f) conv_float = "%.4g";
 
2611
        else if (grid <= 10.0f) conv_float = "%.3g";
2858
2612
        else conv_float = "%.2g";
2859
2613
        
2860
2614
        if (me->drawflag & ME_DRAWEXTRA_EDGELEN) {
2899
2653
                BMFace *f;
2900
2654
                int n;
2901
2655
 
2902
 
#define DRAW_EM_MEASURE_STATS_FACEAREA()                                      \
2903
 
        if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {                               \
2904
 
                mul_v3_fl(vmid, 1.0f / (float)n);                                     \
2905
 
                if (unit->system)                                                     \
2906
 
                        bUnit_AsString(numstr, sizeof(numstr),                            \
2907
 
                                   (double)(area * unit->scale_length),               \
2908
 
                                       3, unit->system, B_UNIT_LENGTH, do_split, FALSE);  \
2909
 
                else                                                                  \
2910
 
                        BLI_snprintf(numstr, sizeof(numstr), conv_float, area);           \
2911
 
                view3d_cached_text_draw_add(vmid, numstr, 0, txt_flag, col);          \
2912
 
        }
 
2656
#define DRAW_EM_MEASURE_STATS_FACEAREA()                                                 \
 
2657
        if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {                                          \
 
2658
                mul_v3_fl(vmid, 1.0f / (float)n);                                                \
 
2659
                if (unit->system) {                                                              \
 
2660
                        bUnit_AsString(numstr, sizeof(numstr),                                       \
 
2661
                                       (double)(area * unit->scale_length * unit->scale_length),     \
 
2662
                                       3, unit->system, B_UNIT_AREA, do_split, FALSE);               \
 
2663
                        view3d_cached_text_draw_add(vmid, numstr, 0,                                 \
 
2664
                                                    /* Metric system uses unicode "squared" sign! */ \
 
2665
                                                    txt_flag ^ V3D_CACHE_TEXT_ASCII, col);           \
 
2666
                }                                                                                \
 
2667
                else {                                                                           \
 
2668
                        BLI_snprintf(numstr, sizeof(numstr), conv_float, area);                      \
 
2669
                        view3d_cached_text_draw_add(vmid, numstr, 0, txt_flag, col);                 \
 
2670
                }                                                                                \
 
2671
        } (void)0
2913
2672
 
2914
2673
                UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
2915
2674
                
2930
2689
                        copy_v3_v3(v1, l[0]->v->co);
2931
2690
                        copy_v3_v3(v2, l[1]->v->co);
2932
2691
                        copy_v3_v3(v3, l[2]->v->co);
 
2692
                        add_v3_v3(vmid, v1);
 
2693
                        add_v3_v3(vmid, v2);
 
2694
                        add_v3_v3(vmid, v3);
 
2695
                        n += 3;
2933
2696
                        if (do_global) {
2934
2697
                                mul_mat3_m4_v3(ob->obmat, v1);
2935
2698
                                mul_mat3_m4_v3(ob->obmat, v2);
2936
2699
                                mul_mat3_m4_v3(ob->obmat, v3);
2937
2700
                        }
2938
2701
                        area += area_tri_v3(v1, v2, v3);
2939
 
                        add_v3_v3(vmid, v1);
2940
 
                        add_v3_v3(vmid, v2);
2941
 
                        add_v3_v3(vmid, v3);
2942
 
                        n += 3;
2943
2702
                }
2944
2703
 
2945
2704
                if (f) {
2950
2709
 
2951
2710
        if (me->drawflag & ME_DRAWEXTRA_FACEANG) {
2952
2711
                BMFace *efa;
 
2712
                int is_rad = unit->system_rotation == USER_UNIT_ROT_RADIANS;
2953
2713
 
2954
2714
                UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
2955
2715
 
2956
2716
 
2957
 
                for (efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL);
2958
 
                     efa; efa = BM_iter_step(&iter))
2959
 
                {
2960
 
                        BMIter liter;
2961
 
                        BMLoop *loop;
2962
 
 
2963
 
                        BM_face_calc_center_bounds(efa, vmid);
2964
 
 
2965
 
                        for (loop = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa);
2966
 
                             loop; loop = BM_iter_step(&liter))
2967
 
                        {
2968
 
                                float v1[3], v2[3], v3[3];
2969
 
 
2970
 
                                copy_v3_v3(v1, loop->prev->v->co);
2971
 
                                copy_v3_v3(v2, loop->v->co);
2972
 
                                copy_v3_v3(v3, loop->next->v->co);
2973
 
 
2974
 
                                if (do_global) {
2975
 
                                        mul_mat3_m4_v3(ob->obmat, v1);
2976
 
                                        mul_mat3_m4_v3(ob->obmat, v2);
2977
 
                                        mul_mat3_m4_v3(ob->obmat, v3);
2978
 
                                }
2979
 
 
2980
 
                                if ( (BM_elem_flag_test(efa, BM_ELEM_SELECT)) ||
2981
 
                                     (do_moving && BM_elem_flag_test(loop->v, BM_ELEM_SELECT)))
2982
 
                                {
2983
 
                                        BLI_snprintf(numstr, sizeof(numstr), "%.3g", RAD2DEGF(angle_v3v3v3(v1, v2, v3)));
2984
 
                                        interp_v3_v3v3(fvec, vmid, v2, 0.8f);
2985
 
                                        view3d_cached_text_draw_add(fvec, numstr, 0, txt_flag, col);
 
2717
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
 
2718
                        const int is_face_sel = BM_elem_flag_test(efa, BM_ELEM_SELECT);
 
2719
 
 
2720
                        if (is_face_sel || do_moving) {
 
2721
                                BMIter liter;
 
2722
                                BMLoop *loop;
 
2723
                                int is_first = TRUE;
 
2724
 
 
2725
                                BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) {
 
2726
                                        if (is_face_sel || (do_moving && BM_elem_flag_test(loop->v, BM_ELEM_SELECT))) {
 
2727
                                                float angle;
 
2728
 
 
2729
                                                /* lazy init center calc */
 
2730
                                                if (is_first) {
 
2731
                                                        BM_face_calc_center_bounds(efa, vmid);
 
2732
                                                        /* Avoid triple matrix multiply every vertex for 'global' */
 
2733
                                                        if (do_global) {
 
2734
                                                                copy_v3_v3(v1, loop->prev->v->co);
 
2735
                                                                copy_v3_v3(v2, loop->v->co);
 
2736
                                                                mul_mat3_m4_v3(ob->obmat, v1);
 
2737
                                                                mul_mat3_m4_v3(ob->obmat, v2);
 
2738
                                                        }
 
2739
                                                        is_first = FALSE;
 
2740
                                                }
 
2741
 
 
2742
                                                if (do_global) {
 
2743
                                                        copy_v3_v3(v3, loop->next->v->co);
 
2744
 
 
2745
                                                        mul_mat3_m4_v3(ob->obmat, v3);
 
2746
 
 
2747
                                                        angle = angle_v3v3v3(v1, v2, v3);
 
2748
                                                        copy_v3_v3(v1, v2);
 
2749
                                                        copy_v3_v3(v2, v3);
 
2750
                                                }
 
2751
                                                else {
 
2752
                                                        angle = angle_v3v3v3(loop->prev->v->co, loop->v->co, loop->next->v->co);
 
2753
                                                }
 
2754
 
 
2755
                                                BLI_snprintf(numstr, sizeof(numstr), "%.3f", is_rad ? angle : RAD2DEGF(angle));
 
2756
                                                interp_v3_v3v3(fvec, vmid, loop->v->co, 0.8f);
 
2757
                                                view3d_cached_text_draw_add(fvec, numstr, 0, txt_flag, col);
 
2758
                                        }
2986
2759
                                }
2987
2760
                        }
2988
2761
                }
3066
2839
}
3067
2840
 
3068
2841
static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
3069
 
                          Object *ob, BMEditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, int dt)
 
2842
                          Object *ob, BMEditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, const char dt)
3070
2843
 
3071
2844
{
3072
2845
        Mesh *me = ob->data;
3073
 
        BMFace *efa_act = BM_active_face_get(em->bm, FALSE); /* annoying but active faces is stored differently */
 
2846
        BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); /* annoying but active faces is stored differently */
3074
2847
        BMEdge *eed_act = NULL;
3075
2848
        BMVert *eve_act = NULL;
3076
2849
        
3081
2854
                if (ese->type == BM_FACE) {
3082
2855
                        efa_act = (BMFace *)ese->data;
3083
2856
                }
3084
 
                else 
 
2857
                else
3085
2858
#endif
3086
2859
                if (ese->htype == BM_EDGE) {
3087
2860
                        eed_act = (BMEdge *)ese->ele;
3091
2864
                }
3092
2865
        }
3093
2866
        
3094
 
        EDBM_index_arrays_init(em, 1, 1, 1);
 
2867
        EDBM_index_arrays_ensure(em, BM_VERT | BM_EDGE | BM_FACE);
3095
2868
 
3096
2869
        if (dt > OB_WIRE) {
3097
2870
                if (check_object_draw_texture(scene, v3d, dt)) {
3122
2895
                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
3123
2896
                }
3124
2897
 
3125
 
                // Setup for drawing wire over, disable zbuffer
3126
 
                // write to show selected edge wires better
 
2898
                /* Setup for drawing wire over, disable zbuffer
 
2899
                 * write to show selected edge wires better */
3127
2900
                UI_ThemeColor(TH_WIRE);
3128
2901
 
3129
2902
                bglPolygonOffset(rv3d->dist, 1.0);
3142
2915
                UI_GetThemeColor4ubv(TH_FACE, col1);
3143
2916
                UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
3144
2917
                UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
3145
 
                
 
2918
 
3146
2919
                glEnable(GL_BLEND);
3147
 
                glDepthMask(0);     // disable write in zbuffer, needed for nice transp
3148
 
                
 
2920
                glDepthMask(0);  /* disable write in zbuffer, needed for nice transp */
 
2921
 
3149
2922
                /* don't draw unselected faces, only selected, this is MUCH nicer when texturing */
3150
2923
                if (check_object_draw_texture(scene, v3d, dt))
3151
2924
                        col1[3] = 0;
3152
 
                
 
2925
 
3153
2926
                draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
3154
2927
 
3155
2928
                glDisable(GL_BLEND);
3156
 
                glDepthMask(1);     // restore write in zbuffer
 
2929
                glDepthMask(1);  /* restore write in zbuffer */
3157
2930
        }
3158
2931
        else if (efa_act) {
3159
2932
                /* even if draw faces is off it would be nice to draw the stipple face
3162
2935
                unsigned char col1[4], col2[4], col3[4];
3163
2936
                col1[3] = col2[3] = 0; /* don't draw */
3164
2937
                UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
3165
 
                
 
2938
 
3166
2939
                glEnable(GL_BLEND);
3167
 
                glDepthMask(0);     // disable write in zbuffer, needed for nice transp
3168
 
                
 
2940
                glDepthMask(0);  /* disable write in zbuffer, needed for nice transp */
 
2941
 
3169
2942
                draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
3170
2943
 
3171
2944
                glDisable(GL_BLEND);
3172
 
                glDepthMask(1);     // restore write in zbuffer
3173
 
                
 
2945
                glDepthMask(1);  /* restore write in zbuffer */
 
2946
 
3174
2947
        }
3175
2948
 
3176
2949
        /* here starts all fancy draw-extra over */
3211
2984
 
3212
2985
                draw_em_fancy_edges(em, scene, v3d, me, cageDM, 0, eed_act);
3213
2986
        }
3214
 
        if (em) {
3215
 
                draw_em_fancy_verts(scene, v3d, ob, em, cageDM, eve_act);
 
2987
 
 
2988
        {
 
2989
                draw_em_fancy_verts(scene, v3d, ob, em, cageDM, eve_act, rv3d);
3216
2990
 
3217
2991
                if (me->drawflag & ME_DRAWNORMALS) {
3218
2992
                        UI_ThemeColor(TH_NORMAL);
3223
2997
                        draw_dm_vert_normals(em, scene, ob, cageDM);
3224
2998
                }
3225
2999
 
3226
 
                if ( (me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_FACEAREA | ME_DRAWEXTRA_FACEANG)) &&
3227
 
                     !(v3d->flag2 & V3D_RENDER_OVERRIDE))
 
3000
                if ((me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_FACEAREA | ME_DRAWEXTRA_FACEANG)) &&
 
3001
                    !(v3d->flag2 & V3D_RENDER_OVERRIDE))
3228
3002
                {
3229
3003
                        draw_em_measure_stats(v3d, ob, em, &scene->unit);
3230
3004
                }
3231
3005
 
3232
3006
                if ((G.debug & G_DEBUG) && (me->drawflag & ME_DRAWEXTRA_INDICES) &&
3233
 
                    !(v3d->flag2 & V3D_RENDER_OVERRIDE)) {
 
3007
                    !(v3d->flag2 & V3D_RENDER_OVERRIDE))
 
3008
                {
3234
3009
                        draw_em_indices(em);
3235
3010
                }
3236
3011
        }
3240
3015
                bglPolygonOffset(rv3d->dist, 0.0);
3241
3016
                GPU_disable_material();
3242
3017
        }
3243
 
 
3244
 
        EDBM_index_arrays_free(em);
3245
3018
}
3246
3019
 
3247
3020
/* Mesh drawing routines */
3248
3021
 
3249
3022
static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
3250
3023
{
3251
 
        
3252
3024
        if ((v3d->transp == FALSE) &&  /* not when we draw the transparent pass */
3253
3025
            (ob->mode & OB_MODE_ALL_PAINT) == FALSE) /* not when painting (its distracting) - campbell */
3254
3026
        {
3255
3027
                glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f);
3256
3028
                glDepthMask(0);
3257
 
                
 
3029
 
3258
3030
                /* if transparent, we cannot draw the edges for solid select... edges have no material info.
3259
3031
                 * drawFacesSolid() doesn't draw the transparent faces */
3260
3032
                if (ob->dtx & OB_DRAWTRANSP) {
3272
3044
        }
3273
3045
}
3274
3046
 
3275
 
static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 
3047
static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
 
3048
                            const char dt, const unsigned char ob_wire_col[4], const short dflag)
3276
3049
{
3277
3050
        Object *ob = base->object;
3278
3051
        Mesh *me = ob->data;
3319
3092
        else if (dt == OB_WIRE || totface == 0) {
3320
3093
                draw_wire = OBDRAW_WIRE_ON; /* draw wire only, no depth buffer stuff  */
3321
3094
        }
3322
 
        else if ( ((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
3323
 
                  check_object_draw_texture(scene, v3d, dt))
 
3095
        else if (((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
 
3096
                 check_object_draw_texture(scene, v3d, dt))
3324
3097
        {
3325
 
                if ( (v3d->flag & V3D_SELECT_OUTLINE) &&
3326
 
                     ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
3327
 
                     (base->flag & SELECT) &&
3328
 
                     !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) &&
3329
 
                     (draw_wire == OBDRAW_WIRE_OFF))
 
3098
                if ((v3d->flag & V3D_SELECT_OUTLINE) &&
 
3099
                    ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
 
3100
                    (base->flag & SELECT) &&
 
3101
                    !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) &&
 
3102
                    (draw_wire == OBDRAW_WIRE_OFF))
3330
3103
                {
3331
3104
                        draw_mesh_object_outline(v3d, ob, dm);
3332
3105
                }
3335
3108
                        glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
3336
3109
 
3337
3110
                        dm->drawFacesGLSL(dm, GPU_enable_material);
3338
 
//                      if (get_ob_property(ob, "Text"))
 
3111
//                      if (BKE_bproperty_object_get(ob, "Text"))
3339
3112
// XXX                          draw_mesh_text(ob, 1);
3340
3113
                        GPU_disable_material();
3341
3114
 
3346
3119
                }
3347
3120
 
3348
3121
                if (!(draw_flags & DRAW_FACE_SELECT)) {
3349
 
                        if (base->flag & SELECT)
3350
 
                                UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
3351
 
                        else
3352
 
                                UI_ThemeColor(TH_WIRE);
3353
 
 
3354
 
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
 
3122
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
 
3123
                                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
3124
                                        glColor3ubv(ob_wire_col);
 
3125
                                }
3355
3126
                                dm->drawLooseEdges(dm);
 
3127
                        }
3356
3128
                }
3357
3129
        }
3358
3130
        else if (dt == OB_SOLID) {
3359
 
                if (is_obact && ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
3360
 
                        /* weight paint in solid mode, special case. focus on making the weights clear
3361
 
                         * rather than the shading, this is also forced in wire view */
3362
 
                        GPU_enable_material(0, NULL);
3363
 
                        dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, me->mpoly,
3364
 
                                            DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
3365
 
 
3366
 
                        bglPolygonOffset(rv3d->dist, 1.0);
3367
 
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
3368
 
 
3369
 
                        glEnable(GL_BLEND);
3370
 
                        glColor4ub(255, 255, 255, 96);
3371
 
                        glEnable(GL_LINE_STIPPLE);
3372
 
                        glLineStipple(1, 0xAAAA);
3373
 
 
3374
 
                        dm->drawEdges(dm, 1, 1);
3375
 
 
3376
 
                        bglPolygonOffset(rv3d->dist, 0.0);
3377
 
                        glDepthMask(1);
3378
 
                        glDisable(GL_LINE_STIPPLE);
3379
 
                        glDisable(GL_BLEND);
3380
 
 
3381
 
                        GPU_disable_material();
3382
 
                        
3383
 
                        /* since we already draw wire as wp guide, don't draw over the top */
3384
 
                        draw_wire = OBDRAW_WIRE_OFF;
3385
 
                }
3386
 
                else if (draw_flags & DRAW_MODIFIERS_PREVIEW) {
 
3131
                if (draw_flags & DRAW_MODIFIERS_PREVIEW) {
3387
3132
                        /* for object selection draws no shade */
3388
 
                        if (flag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
 
3133
                        if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
3389
3134
                                dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
3390
3135
                        }
3391
3136
                        else {
 
3137
                                const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f};
 
3138
 
3392
3139
                                /* draw outline */
3393
 
                                if ( (v3d->flag & V3D_SELECT_OUTLINE) &&
3394
 
                                     ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
3395
 
                                     (base->flag & SELECT) &&
3396
 
                                     (draw_wire == OBDRAW_WIRE_OFF) &&
3397
 
                                     (ob->sculpt == NULL))
 
3140
                                if ((v3d->flag & V3D_SELECT_OUTLINE) &&
 
3141
                                    ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
 
3142
                                    (base->flag & SELECT) &&
 
3143
                                    (draw_wire == OBDRAW_WIRE_OFF) &&
 
3144
                                    (ob->sculpt == NULL))
3398
3145
                                {
3399
3146
                                        draw_mesh_object_outline(v3d, ob, dm);
3400
3147
                                }
3406
3153
                                
3407
3154
                                /* set default spec */
3408
3155
                                glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
3409
 
                                glEnable(GL_COLOR_MATERIAL);    /* according manpages needed */
3410
 
                                glColor3ub(120, 120, 120);
3411
 
                                glDisable(GL_COLOR_MATERIAL);
 
3156
                                glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
3412
3157
                                /* diffuse */
3413
3158
                                glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
3414
3159
                                glEnable(GL_LIGHTING);
3424
3169
                else {
3425
3170
                        Paint *p;
3426
3171
 
3427
 
                        if ( (v3d->flag & V3D_SELECT_OUTLINE) &&
3428
 
                             ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
3429
 
                             (base->flag & SELECT) &&
3430
 
                             (draw_wire == OBDRAW_WIRE_OFF) &&
3431
 
                             (ob->sculpt == NULL))
 
3172
                        if ((v3d->flag & V3D_SELECT_OUTLINE) &&
 
3173
                            ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
 
3174
                            (base->flag & SELECT) &&
 
3175
                            (draw_wire == OBDRAW_WIRE_OFF) &&
 
3176
                            (ob->sculpt == NULL))
3432
3177
                        {
3433
3178
                                draw_mesh_object_outline(v3d, ob, dm);
3434
3179
                        }
3463
3208
 
3464
3209
                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
3465
3210
 
3466
 
                        if (base->flag & SELECT) {
3467
 
                                UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
3468
 
                        }
3469
 
                        else {
3470
 
                                UI_ThemeColor(TH_WIRE);
3471
 
                        }
3472
 
                        if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
 
3211
                        if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
 
3212
                                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
3213
                                        glColor3ubv(ob_wire_col);
 
3214
                                }
3473
3215
                                dm->drawLooseEdges(dm);
 
3216
                        }
3474
3217
                }
3475
3218
        }
3476
3219
        else if (dt == OB_PAINT) {
3477
 
                draw_mesh_paint(rv3d, ob, dm, draw_flags);
3478
 
        }
3479
 
        
3480
 
        /* set default draw color back for wire or for draw-extra later on */
3481
 
        if (dt != OB_WIRE) {
3482
 
                if (base->flag & SELECT) {
3483
 
                        if (is_obact && ob->flag & OB_FROMGROUP)
3484
 
                                UI_ThemeColor(TH_GROUP_ACTIVE);
3485
 
                        else if (ob->flag & OB_FROMGROUP)
3486
 
                                UI_ThemeColorShade(TH_GROUP_ACTIVE, -16);
3487
 
                        else if (flag != DRAW_CONSTCOLOR)
3488
 
                                UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
3489
 
                        else
3490
 
                                glColor3ub(80, 80, 80);
3491
 
                }
3492
 
                else {
3493
 
                        if (ob->flag & OB_FROMGROUP)
3494
 
                                UI_ThemeColor(TH_GROUP);
3495
 
                        else {
3496
 
                                if (ob->dtx & OB_DRAWWIRE && flag == DRAW_CONSTCOLOR)
3497
 
                                        glColor3ub(80, 80, 80);
3498
 
                                else
3499
 
                                        UI_ThemeColor(TH_WIRE);
3500
 
                        }
3501
 
                }
3502
 
        }
3503
 
        if (draw_wire != OBDRAW_WIRE_OFF) {
3504
 
 
 
3220
                draw_mesh_paint(v3d, rv3d, ob, dm, draw_flags);
 
3221
 
 
3222
                /* since we already draw wire as wp guide, don't draw over the top */
 
3223
                draw_wire = OBDRAW_WIRE_OFF;
 
3224
        }
 
3225
 
 
3226
        if ((draw_wire != OBDRAW_WIRE_OFF) &&  /* draw extra wire */
 
3227
            /* when overriding with render only, don't bother  */
 
3228
            (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0))
 
3229
        {
3505
3230
                /* When using wireframe object draw in particle edit mode
3506
3231
                 * the mesh gets in the way of seeing the particles, fade the wire color
3507
3232
                 * with the background. */
3508
 
                if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
3509
 
                        float col_wire[4], col_bg[4], col[3];
3510
3233
 
3511
 
                        UI_GetThemeColor3fv(TH_BACK, col_bg);
3512
 
                        glGetFloatv(GL_CURRENT_COLOR, col_wire);
3513
 
                        interp_v3_v3v3(col, col_bg, col_wire, 0.15);
3514
 
                        glColor3fv(col);
 
3234
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
3235
                        if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
 
3236
                                ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.15f);
 
3237
                        }
 
3238
                        else {
 
3239
                                glColor3ubv(ob_wire_col);
 
3240
                        }
3515
3241
                }
3516
3242
 
3517
3243
                /* If drawing wire and drawtype is not OB_WIRE then we are
3525
3251
                 */
3526
3252
                if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
3527
3253
                        bglPolygonOffset(rv3d->dist, 1.0);
3528
 
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
 
3254
                        glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
3529
3255
                }
3530
3256
                
3531
 
                if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0)
3532
 
                        dm->drawEdges(dm, (dt == OB_WIRE || totface == 0), me->drawflag & ME_ALLEDGES);
 
3257
                dm->drawEdges(dm, (dt == OB_WIRE || totface == 0), (ob->dtx & OB_DRAW_ALL_EDGES));
3533
3258
 
3534
3259
                if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
3535
3260
                        glDepthMask(1);
3538
3263
        }
3539
3264
        
3540
3265
        if (is_obact && paint_vertsel_test(ob)) {
3541
 
                
 
3266
                const int use_depth = (v3d->flag & V3D_ZBUF_SELECT);
3542
3267
                glColor3f(0.0f, 0.0f, 0.0f);
3543
3268
                glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
3544
 
                
 
3269
 
 
3270
                if (!use_depth) glDisable(GL_DEPTH_TEST);
 
3271
                else            bglPolygonOffset(rv3d->dist, 1.0);
3545
3272
                drawSelectedVertices(dm, ob->data);
 
3273
                if (!use_depth) glEnable(GL_DEPTH_TEST);
 
3274
                else            bglPolygonOffset(rv3d->dist, 0.0);
3546
3275
                
3547
3276
                glPointSize(1.0f);
3548
3277
        }
3550
3279
}
3551
3280
 
3552
3281
/* returns 1 if nothing was drawn, for detecting to draw an object center */
3553
 
static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 
3282
static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
 
3283
                            const char dt, const unsigned char ob_wire_col[4], const short dflag)
3554
3284
{
3555
3285
        Object *ob = base->object;
3556
3286
        Object *obedit = scene->obedit;
3557
3287
        Mesh *me = ob->data;
3558
3288
        BMEditMesh *em = me->edit_btmesh;
3559
 
        int do_alpha_after = 0, drawlinked = 0, retval = 0, glsl, check_alpha, i;
 
3289
        int do_alpha_after = FALSE, drawlinked = 0, retval = 0, glsl, check_alpha, i;
3560
3290
 
3561
3291
        /* If we are drawing shadows and any of the materials don't cast a shadow,
3562
3292
         * then don't draw the object */
3570
3300
        }
3571
3301
        
3572
3302
        if (obedit && ob != obedit && ob->data == obedit->data) {
3573
 
                if (ob_get_key(ob) || ob_get_key(obedit)) {}
 
3303
                if (BKE_key_from_object(ob) || BKE_key_from_object(obedit)) {}
3574
3304
                else if (ob->modifiers.first || obedit->modifiers.first) {}
3575
3305
                else drawlinked = 1;
3576
3306
        }
3577
 
        
 
3307
 
 
3308
        /* backface culling */
 
3309
        if (v3d->flag2 & V3D_BACKFACE_CULLING) {
 
3310
                glEnable(GL_CULL_FACE);
 
3311
                glCullFace(GL_BACK);
 
3312
        }
 
3313
 
3578
3314
        if (ob == obedit || drawlinked) {
3579
3315
                DerivedMesh *finalDM, *cageDM;
3580
3316
                
3598
3334
                        finalDM->release(finalDM);
3599
3335
        }
3600
3336
        else {
3601
 
                /* don't create boundbox here with mesh_get_bb(), the derived system will make it, puts deformed bb's OK */
3602
 
                if (me->totpoly <= 4 || ED_view3d_boundbox_clip(rv3d, ob->obmat, (ob->bb) ? ob->bb : me->bb)) {
 
3337
                /* ob->bb was set by derived mesh system, do NULL check just to be sure */
 
3338
                if (me->totpoly <= 4 || (!ob->bb || ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb))) {
3603
3339
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
3604
3340
                        check_alpha = check_alpha_pass(base);
3605
3341
 
3608
3344
                                                           (check_alpha) ? &do_alpha_after : NULL);
3609
3345
                        }
3610
3346
 
3611
 
                        draw_mesh_fancy(scene, ar, v3d, rv3d, base, dt, flag);
 
3347
                        draw_mesh_fancy(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
3612
3348
 
3613
3349
                        GPU_end_object_materials();
3614
3350
                        
3616
3352
                }
3617
3353
        }
3618
3354
        
3619
 
        /* GPU_begin_object_materials checked if this is needed */
3620
 
        if (do_alpha_after) {
3621
 
                if (ob->dtx & OB_DRAWXRAY) {
3622
 
                        add_view3d_after(&v3d->afterdraw_xraytransp, base, flag);
3623
 
                }
3624
 
                else {
3625
 
                        add_view3d_after(&v3d->afterdraw_transp, base, flag);
3626
 
                }
3627
 
        }
3628
 
        else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) {
3629
 
                /* special case xray+transp when alpha is 1.0, without this the object vanishes */
3630
 
                if (v3d->xray == 0 && v3d->transp == 0) {
3631
 
                        add_view3d_after(&v3d->afterdraw_xray, base, flag);
3632
 
                }
3633
 
        }
 
3355
        if ((dflag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0 && (v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
 
3356
                /* GPU_begin_object_materials checked if this is needed */
 
3357
                if (do_alpha_after) {
 
3358
                        if (ob->dtx & OB_DRAWXRAY) {
 
3359
                                ED_view3d_after_add(&v3d->afterdraw_xraytransp, base, dflag);
 
3360
                        }
 
3361
                        else {
 
3362
                                ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
 
3363
                        }
 
3364
                }
 
3365
                else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) {
 
3366
                        /* special case xray+transp when alpha is 1.0, without this the object vanishes */
 
3367
                        if (v3d->xray == 0 && v3d->transp == 0) {
 
3368
                                ED_view3d_after_add(&v3d->afterdraw_xray, base, dflag);
 
3369
                        }
 
3370
                }
 
3371
        }
 
3372
 
 
3373
        if (v3d->flag2 & V3D_BACKFACE_CULLING)
 
3374
                glDisable(GL_CULL_FACE);
3634
3375
        
3635
3376
        return retval;
3636
3377
}
3701
3442
                                        }
3702
3443
                                        glEnd();
3703
3444
 
3704
 
/* (ton) this code crashes for me when resolv is 86 or higher... no clue */
3705
 
//                              glVertexPointer(3, GL_FLOAT, sizeof(float)*3*dl->nr, data + 3*nr);
3706
 
//                              if (dl->flag & DL_CYCL_V)
3707
 
//                                      glDrawArrays(GL_LINE_LOOP, 0, dl->parts);
3708
 
//                              else
3709
 
//                                      glDrawArrays(GL_LINE_STRIP, 0, dl->parts);
 
3445
#if 0
 
3446
                                /* (ton) this code crashes for me when resolv is 86 or higher... no clue */
 
3447
                                glVertexPointer(3, GL_FLOAT, sizeof(float) * 3 * dl->nr, data + 3 * nr);
 
3448
                                if (dl->flag & DL_CYCL_V)
 
3449
                                        glDrawArrays(GL_LINE_LOOP, 0, dl->parts);
 
3450
                                else
 
3451
                                        glDrawArrays(GL_LINE_STRIP, 0, dl->parts);
 
3452
#endif
3710
3453
                                }
3711
3454
                                break;
3712
3455
 
3732
3475
        return 0;
3733
3476
}
3734
3477
 
3735
 
static void drawDispListsolid(ListBase *lb, Object *ob, int glsl)
 
3478
static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
 
3479
                              const unsigned char ob_wire_col[4], int use_glsl)
3736
3480
{
3737
3481
        DispList *dl;
3738
3482
        GPUVertexAttribs gattribs;
3739
 
        float *data, curcol[4];
 
3483
        float *data;
3740
3484
        float *ndata;
3741
3485
        
3742
3486
        if (lb == NULL) return;
3743
 
        
3744
 
        /* for drawing wire */
3745
 
        glGetFloatv(GL_CURRENT_COLOR, curcol);
3746
3487
 
3747
3488
        glEnable(GL_LIGHTING);
3748
3489
        glEnableClientState(GL_VERTEX_ARRAY);
3750
3491
        if (ob->transflag & OB_NEG_SCALE) glFrontFace(GL_CW);
3751
3492
        else glFrontFace(GL_CCW);
3752
3493
        
3753
 
        if (ob->type == OB_MBALL) {   // mball always smooth shaded
 
3494
        if (ob->type == OB_MBALL) {  /* mball always smooth shaded */
3754
3495
                glShadeModel(GL_SMOOTH);
3755
3496
        }
3756
3497
        
3765
3506
                                        int nr;
3766
3507
 
3767
3508
                                        glDisable(GL_LIGHTING);
3768
 
                                        glColor3fv(curcol);
 
3509
 
 
3510
                                        if ((dflag & DRAW_CONSTCOLOR) == 0)
 
3511
                                                glColor3ubv(ob_wire_col);
3769
3512
 
3770
3513
                                        // glVertexPointer(3, GL_FLOAT, 0, dl->verts);
3771
3514
                                        // glDrawArrays(GL_LINE_STRIP, 0, dl->nr);
3799
3542
                        case DL_SURF:
3800
3543
 
3801
3544
                                if (dl->index) {
3802
 
                                        GPU_enable_material(dl->col + 1, (glsl) ? &gattribs : NULL);
 
3545
                                        GPU_enable_material(dl->col + 1, (use_glsl) ? &gattribs : NULL);
3803
3546
 
3804
3547
                                        if (dl->rt & CU_SMOOTH) glShadeModel(GL_SMOOTH);
3805
3548
                                        else glShadeModel(GL_FLAT);
3813
3556
                                break;
3814
3557
 
3815
3558
                        case DL_INDEX3:
3816
 
                                GPU_enable_material(dl->col + 1, (glsl) ? &gattribs : NULL);
 
3559
                                GPU_enable_material(dl->col + 1, (use_glsl) ? &gattribs : NULL);
3817
3560
 
3818
3561
                                glVertexPointer(3, GL_FLOAT, 0, dl->verts);
3819
3562
 
3820
 
                                /* voor polys only one normal needed */
 
3563
                                /* for polys only one normal needed */
3821
3564
                                if (index3_nors_incr) {
3822
3565
                                        glEnableClientState(GL_NORMAL_ARRAY);
3823
3566
                                        glNormalPointer(GL_FLOAT, 0, dl->nors);
3833
3576
                                break;
3834
3577
 
3835
3578
                        case DL_INDEX4:
3836
 
                                GPU_enable_material(dl->col + 1, (glsl) ? &gattribs : NULL);
 
3579
                                GPU_enable_material(dl->col + 1, (use_glsl) ? &gattribs : NULL);
3837
3580
 
3838
3581
                                glEnableClientState(GL_NORMAL_ARRAY);
3839
3582
                                glVertexPointer(3, GL_FLOAT, 0, dl->verts);
3859
3602
}
3860
3603
 
3861
3604
/* return 1 when nothing was drawn */
3862
 
static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 
3605
static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt)
3863
3606
{
3864
3607
        Object *ob = base->object;
3865
3608
        DerivedMesh *dm = ob->derivedFinal;
3890
3633
        return 0;
3891
3634
}
3892
3635
 
3893
 
/* returns 1 when nothing was drawn */
3894
 
static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 
3636
/**
 
3637
 * Only called by #drawDispList
 
3638
 * \return 1 when nothing was drawn
 
3639
 */
 
3640
static int drawDispList_nobackface(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
3641
                                   const char dt, const short dflag, const unsigned char ob_wire_col[4])
3895
3642
{
3896
3643
        Object *ob = base->object;
3897
3644
        ListBase *lb = NULL;
3899
3646
        Curve *cu;
3900
3647
        const short render_only = (v3d->flag2 & V3D_RENDER_OVERRIDE);
3901
3648
        const short solid = (dt > OB_WIRE);
3902
 
        int retval = 0;
3903
3649
 
3904
3650
        if (drawCurveDerivedMesh(scene, v3d, rv3d, base, dt) == 0) {
3905
 
                return 0;
 
3651
                return FALSE;
3906
3652
        }
3907
3653
 
3908
3654
        switch (ob->type) {
3914
3660
 
3915
3661
                        if (solid) {
3916
3662
                                dl = lb->first;
3917
 
                                if (dl == NULL) return 1;
 
3663
                                if (dl == NULL) {
 
3664
                                        return TRUE;
 
3665
                                }
3918
3666
 
3919
 
                                if (dl->nors == NULL) addnormalsDispList(lb);
 
3667
                                if (dl->nors == NULL) BKE_displist_normals_add(lb);
3920
3668
                                index3_nors_incr = 0;
3921
3669
 
3922
 
                                if (displist_has_faces(lb) == 0) {
 
3670
                                if (BKE_displist_has_faces(lb) == 0) {
3923
3671
                                        if (!render_only) {
3924
3672
                                                draw_index_wire = 0;
3925
3673
                                                drawDispListwire(lb);
3929
3677
                                else {
3930
3678
                                        if (draw_glsl_material(scene, ob, v3d, dt)) {
3931
3679
                                                GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
3932
 
                                                drawDispListsolid(lb, ob, 1);
 
3680
                                                drawDispListsolid(lb, ob, dflag, ob_wire_col, TRUE);
3933
3681
                                                GPU_end_object_materials();
3934
3682
                                        }
3935
3683
                                        else {
3936
3684
                                                GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
3937
 
                                                drawDispListsolid(lb, ob, 0);
 
3685
                                                drawDispListsolid(lb, ob, dflag, ob_wire_col, FALSE);
3938
3686
                                                GPU_end_object_materials();
3939
3687
                                        }
3940
3688
                                        if (cu->editnurb && cu->bevobj == NULL && cu->taperobj == NULL && cu->ext1 == 0.0f && cu->ext2 == 0.0f) {
3947
3695
                                index3_nors_incr = 1;
3948
3696
                        }
3949
3697
                        else {
3950
 
                                if (!render_only || (render_only && displist_has_faces(lb))) {
 
3698
                                if (!render_only || (render_only && BKE_displist_has_faces(lb))) {
 
3699
                                        int retval;
3951
3700
                                        draw_index_wire = 0;
3952
3701
                                        retval = drawDispListwire(lb);
3953
3702
                                        draw_index_wire = 1;
 
3703
                                        return retval;
3954
3704
                                }
3955
3705
                        }
3956
3706
                        break;
3960
3710
 
3961
3711
                        if (solid) {
3962
3712
                                dl = lb->first;
3963
 
                                if (dl == NULL) return 1;
 
3713
                                if (dl == NULL) {
 
3714
                                        return TRUE;
 
3715
                                }
3964
3716
 
3965
 
                                if (dl->nors == NULL) addnormalsDispList(lb);
 
3717
                                if (dl->nors == NULL) BKE_displist_normals_add(lb);
3966
3718
 
3967
3719
                                if (draw_glsl_material(scene, ob, v3d, dt)) {
3968
3720
                                        GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
3969
 
                                        drawDispListsolid(lb, ob, 1);
 
3721
                                        drawDispListsolid(lb, ob, dflag, ob_wire_col, TRUE);
3970
3722
                                        GPU_end_object_materials();
3971
3723
                                }
3972
3724
                                else {
3973
3725
                                        GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
3974
 
                                        drawDispListsolid(lb, ob, 0);
 
3726
                                        drawDispListsolid(lb, ob, dflag, ob_wire_col, FALSE);
3975
3727
                                        GPU_end_object_materials();
3976
3728
                                }
3977
3729
                        }
3978
3730
                        else {
3979
 
                                retval = drawDispListwire(lb);
 
3731
                                return drawDispListwire(lb);
3980
3732
                        }
3981
3733
                        break;
3982
3734
                case OB_MBALL:
3983
3735
 
3984
 
                        if (is_basis_mball(ob)) {
 
3736
                        if (BKE_mball_is_basis(ob)) {
3985
3737
                                lb = &ob->disp;
3986
 
                                if (lb->first == NULL) makeDispListMBall(scene, ob);
3987
 
                                if (lb->first == NULL) return 1;
 
3738
                                if (lb->first == NULL) BKE_displist_make_mball(scene, ob);
 
3739
                                if (lb->first == NULL) {
 
3740
                                        return TRUE;
 
3741
                                }
3988
3742
 
3989
3743
                                if (solid) {
3990
3744
 
3991
3745
                                        if (draw_glsl_material(scene, ob, v3d, dt)) {
3992
3746
                                                GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
3993
 
                                                drawDispListsolid(lb, ob, 1);
 
3747
                                                drawDispListsolid(lb, ob, dflag, ob_wire_col, TRUE);
3994
3748
                                                GPU_end_object_materials();
3995
3749
                                        }
3996
3750
                                        else {
3997
3751
                                                GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
3998
 
                                                drawDispListsolid(lb, ob, 0);
 
3752
                                                drawDispListsolid(lb, ob, dflag, ob_wire_col, FALSE);
3999
3753
                                                GPU_end_object_materials();
4000
3754
                                        }
4001
3755
                                }
4002
3756
                                else {
4003
3757
                                        /* MetaBalls use DL_INDEX4 type of DispList */
4004
 
                                        retval = drawDispListwire(lb);
 
3758
                                        return drawDispListwire(lb);
4005
3759
                                }
4006
3760
                        }
4007
3761
                        break;
4008
3762
        }
4009
 
        
 
3763
 
 
3764
        return FALSE;
 
3765
}
 
3766
static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
3767
                        const char dt, const short dflag, const unsigned char ob_wire_col[4])
 
3768
{
 
3769
        int retval;
 
3770
 
 
3771
        /* backface culling */
 
3772
        if (v3d->flag2 & V3D_BACKFACE_CULLING) {
 
3773
                /* not all displists use same in/out normal direction convention */
 
3774
                glEnable(GL_CULL_FACE);
 
3775
                glCullFace((base->object->type == OB_MBALL) ? GL_BACK : GL_FRONT);
 
3776
        }
 
3777
 
 
3778
        retval = drawDispList_nobackface(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
 
3779
 
 
3780
        if (v3d->flag2 & V3D_BACKFACE_CULLING) {
 
3781
                glDisable(GL_CULL_FACE);
 
3782
        }
 
3783
 
4010
3784
        return retval;
4011
3785
}
4012
3786
 
4205
3979
        ParticleDrawData *pdd = psys->pdd;
4206
3980
        Material *ma;
4207
3981
        float vel[3], imat[4][4];
4208
 
        float timestep, pixsize_scale, pa_size, r_tilt, r_length;
 
3982
        float timestep, pixsize_scale = 1.0f, pa_size, r_tilt, r_length;
4209
3983
        float pa_time, pa_birthtime, pa_dietime, pa_health, intensity;
4210
3984
        float cfra;
4211
3985
        float ma_col[3] = {0.0f, 0.0f, 0.0f};
4273
4047
 
4274
4048
        timestep = psys_get_timestep(&sim);
4275
4049
 
4276
 
        if ( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) {
 
4050
        if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) {
4277
4051
                float mat[4][4];
4278
4052
                mult_m4_m4m4(mat, ob->obmat, psys->imat);
4279
4053
                glMultMatrixf(mat);
4284
4058
 
4285
4059
        totpart = psys->totpart;
4286
4060
 
4287
 
        cfra = BKE_curframe(scene);
 
4061
        cfra = BKE_scene_frame_get(scene);
4288
4062
 
4289
4063
        if (draw_as == PART_DRAW_PATH && psys->pathcache == NULL && psys->childcache == NULL)
4290
4064
                draw_as = PART_DRAW_DOT;
4710
4484
 
4711
4485
                if (cdata2)
4712
4486
                        MEM_freeN(cdata2);
4713
 
                /* cd2= */ /* UNUSED */ cdata2 = NULL;
 
4487
                /* cd2 = */ /* UNUSED */ cdata2 = NULL;
4714
4488
 
4715
4489
                glLineWidth(1.0f);
4716
4490
 
4819
4593
                pdd->ma_col = NULL;
4820
4594
        }
4821
4595
 
4822
 
        if ( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) {
 
4596
        if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) {
4823
4597
                glLoadMatrixf(rv3d->viewmat);
4824
4598
        }
4825
4599
}
4913
4687
                                if (!(point->flag & PEP_HIDE))
4914
4688
                                        totkeys += point->totkey;
4915
4689
 
4916
 
                        if (edit->points && !(edit->points->keys->flag & PEK_USE_WCO))
4917
 
                                pd = pdata = MEM_callocN(totkeys * 3 * sizeof(float), "particle edit point data");
4918
 
                        cd = cdata = MEM_callocN(totkeys * (timed ? 4 : 3) * sizeof(float), "particle edit color data");
 
4690
                        if (totkeys) {
 
4691
                                if (edit->points && !(edit->points->keys->flag & PEK_USE_WCO))
 
4692
                                        pd = pdata = MEM_callocN(totkeys * 3 * sizeof(float), "particle edit point data");
 
4693
                                cd = cdata = MEM_callocN(totkeys * (timed ? 4 : 3) * sizeof(float), "particle edit color data");
 
4694
                        }
4919
4695
 
4920
4696
                        for (i = 0, point = edit->points; i < totpoint; i++, point++) {
4921
4697
                                if (point->flag & PEP_HIDE)
5152
4928
        glEnd();
5153
4929
}
5154
4930
 
5155
 
/*place to add drawers */
 
4931
/* place to add drawers */
5156
4932
 
5157
 
static void tekenhandlesN(Nurb *nu, short sel, short hide_handles)
 
4933
static void drawhandlesN(Nurb *nu, short sel, short hide_handles)
5158
4934
{
5159
4935
        BezTriple *bezt;
5160
4936
        float *fp;
5179
4955
                a = nu->pntsu;
5180
4956
                while (a--) {
5181
4957
                        if (bezt->hide == 0) {
5182
 
                                if ( (bezt->f2 & SELECT) == sel) {
 
4958
                                if ((bezt->f2 & SELECT) == sel) {
5183
4959
                                        fp = bezt->vec[0];
5184
4960
 
5185
4961
                                        glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
5190
4966
                                        glVertex3fv(fp + 3);
5191
4967
                                        glVertex3fv(fp + 6);
5192
4968
                                }
5193
 
                                else if ( (bezt->f1 & SELECT) == sel) {
 
4969
                                else if ((bezt->f1 & SELECT) == sel) {
5194
4970
                                        fp = bezt->vec[0];
5195
4971
 
5196
4972
                                        glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
5197
4973
                                        glVertex3fv(fp);
5198
4974
                                        glVertex3fv(fp + 3);
5199
4975
                                }
5200
 
                                else if ( (bezt->f3 & SELECT) == sel) {
 
4976
                                else if ((bezt->f3 & SELECT) == sel) {
5201
4977
                                        fp = bezt->vec[1];
5202
4978
 
5203
4979
                                        glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
5214
4990
        glEnd();
5215
4991
}
5216
4992
 
5217
 
static void tekenhandlesN_active(Nurb *nu)
 
4993
static void drawhandlesN_active(Nurb *nu)
5218
4994
{
5219
4995
        BezTriple *bezt;
5220
4996
        float *fp;
5249
5025
        glLineWidth(1);
5250
5026
}
5251
5027
 
5252
 
static void tekenvertsN(Nurb *nu, short sel, short hide_handles, void *lastsel)
 
5028
static void drawvertsN(Nurb *nu, short sel, short hide_handles, void *lastsel)
5253
5029
{
5254
5030
        BezTriple *bezt;
5255
5031
        BPoint *bp;
5432
5208
                                                for (a = nu->pntsu - 1; a > 0; a--, bp++) {
5433
5209
                                                        if (bp->hide == 0 && bp1->hide == 0) {
5434
5210
                                                                if (sel) {
5435
 
                                                                        if ( (bp->f1 & SELECT) && (bp1->f1 & SELECT) ) {
 
5211
                                                                        if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) {
5436
5212
                                                                                UI_ThemeColor(TH_NURB_SEL_ULINE);
5437
5213
 
5438
5214
                                                                                glBegin(GL_LINE_STRIP);
5467
5243
                                                        for (a = nu->pntsv - 1; a > 0; a--, bp += ofs) {
5468
5244
                                                                if (bp->hide == 0 && bp1->hide == 0) {
5469
5245
                                                                        if (sel) {
5470
 
                                                                                if ( (bp->f1 & SELECT) && (bp1->f1 & SELECT) ) {
 
5246
                                                                                if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) {
5471
5247
                                                                                        UI_ThemeColor(TH_NURB_SEL_VLINE);
5472
5248
 
5473
5249
                                                                                        glBegin(GL_LINE_STRIP);
5499
5275
                        }
5500
5276
                }
5501
5277
 
5502
 
                ++index;
 
5278
                index++;
5503
5279
                nu = nu->next;
5504
5280
        }
5505
5281
}
5506
5282
 
5507
 
static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, Nurb *nurb, int dt)
 
5283
static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, Nurb *nurb,
 
5284
                     const char dt, const short dflag, const unsigned char ob_wire_col[4])
5508
5285
{
5509
5286
        ToolSettings *ts = scene->toolsettings;
5510
5287
        Object *ob = base->object;
5513
5290
        BevList *bl;
5514
5291
        short hide_handles = (cu->drawflag & CU_HIDE_HANDLES);
5515
5292
        int index;
 
5293
        unsigned char wire_col[3];
5516
5294
 
5517
5295
        /* DispList */
5518
 
        UI_ThemeColor(TH_WIRE);
5519
 
        drawDispList(scene, v3d, rv3d, base, dt);
 
5296
        UI_GetThemeColor3ubv(TH_WIRE, wire_col);
 
5297
        glColor3ubv(wire_col);
 
5298
 
 
5299
        drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
5520
5300
 
5521
5301
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
5522
5302
        
5525
5305
        for (nu = nurb; nu; nu = nu->next) {
5526
5306
                if (nu->type == CU_BEZIER) {
5527
5307
                        if (index == cu->actnu && !hide_handles)
5528
 
                                tekenhandlesN_active(nu);
5529
 
                        tekenhandlesN(nu, 0, hide_handles);
 
5308
                                drawhandlesN_active(nu);
 
5309
                        drawhandlesN(nu, 0, hide_handles);
5530
5310
                }
5531
 
                ++index;
 
5311
                index++;
5532
5312
        }
5533
5313
        draw_editnurb(ob, nurb, 0);
5534
5314
        draw_editnurb(ob, nurb, 1);
5535
5315
        /* selected handles */
5536
5316
        for (nu = nurb; nu; nu = nu->next) {
5537
5317
                if (nu->type == CU_BEZIER && (cu->drawflag & CU_HIDE_HANDLES) == 0)
5538
 
                        tekenhandlesN(nu, 1, hide_handles);
5539
 
                tekenvertsN(nu, 0, hide_handles, NULL);
 
5318
                        drawhandlesN(nu, 1, hide_handles);
 
5319
                drawvertsN(nu, 0, hide_handles, NULL);
5540
5320
        }
5541
5321
        
5542
5322
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
5553
5333
                        
5554
5334
                        while (nr-- > 0) { /* accounts for empty bevel lists */
5555
5335
                                const float fac = bevp->radius * ts->normalsize;
5556
 
                                float vec_a[3]; // Offset perpendicular to the curve
5557
 
                                float vec_b[3]; // Delta along the curve
 
5336
                                float vec_a[3]; /* Offset perpendicular to the curve */
 
5337
                                float vec_b[3]; /* Delta along the curve */
5558
5338
 
5559
5339
                                vec_a[0] = fac;
5560
5340
                                vec_a[1] = 0.0f;
5587
5367
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
5588
5368
        
5589
5369
        for (nu = nurb; nu; nu = nu->next) {
5590
 
                tekenvertsN(nu, 1, hide_handles, cu->lastsel);
 
5370
                drawvertsN(nu, 1, hide_handles, cu->lastsel);
5591
5371
        }
5592
5372
        
5593
5373
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
5649
5429
        gluDeleteQuadric(qobj);
5650
5430
}
5651
5431
 
5652
 
/* draw points on curve speed handles */
5653
 
#if 0 // XXX old animation system stuff
5654
 
static void curve_draw_speed(Scene *scene, Object *ob)
5655
 
{
5656
 
        Curve *cu = ob->data;
5657
 
        IpoCurve *icu;
5658
 
        BezTriple *bezt;
5659
 
        float loc[4], dir[3];
5660
 
        int a;
5661
 
        
5662
 
        if (cu->ipo == NULL)
5663
 
                return;
5664
 
        
5665
 
        icu = cu->ipo->curve.first;
5666
 
        if (icu == NULL || icu->totvert < 2)
5667
 
                return;
5668
 
        
5669
 
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE) );
5670
 
        bglBegin(GL_POINTS);
5671
 
 
5672
 
        for (a = 0, bezt = icu->bezt; a < icu->totvert; a++, bezt++) {
5673
 
                if (where_on_path(ob, bezt->vec[1][1], loc, dir)) {
5674
 
                        UI_ThemeColor((bezt->f2 & SELECT) && ob == OBACT ? TH_VERTEX_SELECT : TH_VERTEX);
5675
 
                        bglVertex3fv(loc);
5676
 
                }
5677
 
        }
5678
 
 
5679
 
        glPointSize(1.0);
5680
 
        bglEnd();
5681
 
}
5682
 
#endif // XXX old animation system stuff
5683
 
 
5684
 
 
5685
 
static void draw_textcurs(float textcurs[4][2])
 
5432
static void draw_textcurs(RegionView3D *rv3d, float textcurs[4][2])
5686
5433
{
5687
5434
        cpack(0);
5688
 
        
 
5435
        bglPolygonOffset(rv3d->dist, -1.0);
5689
5436
        set_inverted_drawing(1);
5690
5437
        glBegin(GL_QUADS);
5691
5438
        glVertex2fv(textcurs[0]);
5694
5441
        glVertex2fv(textcurs[3]);
5695
5442
        glEnd();
5696
5443
        set_inverted_drawing(0);
 
5444
        bglPolygonOffset(rv3d->dist, 0.0);
5697
5445
}
5698
5446
 
5699
 
static void drawspiral(const float cent[3], float rad, float tmat[][4], int start)
 
5447
static void drawspiral(const float cent[3], float rad, float tmat[4][4], int start)
5700
5448
{
5701
5449
        float vec[3], vx[3], vy[3];
5702
5450
        const float tot_inv = (1.0f / (float)CIRCLE_RESOL);
5762
5510
        glEnd();
5763
5511
}
5764
5512
 
5765
 
/* draws a circle on x-z plane given the scaling of the circle, assuming that 
 
5513
/* draws a circle on x-z plane given the scaling of the circle, assuming that
5766
5514
 * all required matrices have been set (used for drawing empties)
5767
5515
 */
5768
5516
static void drawcircle_size(float size)
5772
5520
 
5773
5521
        glBegin(GL_LINE_LOOP);
5774
5522
 
5775
 
        /* coordinates are: cos(degrees*11.25)=x, sin(degrees*11.25)=y, 0.0f=z */
 
5523
        /* coordinates are: cos(degrees * 11.25) = x, sin(degrees*11.25) = y, 0.0f = z */
5776
5524
        for (degrees = 0; degrees < CIRCLE_RESOL; degrees++) {
5777
5525
                x = cosval[degrees];
5778
5526
                y = sinval[degrees];
5784
5532
 
5785
5533
}
5786
5534
 
5787
 
/* needs fixing if non-identity matrice used */
5788
 
static void drawtube(const float vec[3], float radius, float height, float tmat[][4])
 
5535
/* needs fixing if non-identity matrix used */
 
5536
static void drawtube(const float vec[3], float radius, float height, float tmat[4][4])
5789
5537
{
5790
5538
        float cur[3];
5791
5539
        drawcircball(GL_LINE_LOOP, vec, radius, tmat);
5806
5554
        glVertex3f(cur[0], cur[1] - radius, cur[2]);
5807
5555
        glEnd();
5808
5556
}
5809
 
/* needs fixing if non-identity matrice used */
5810
 
static void drawcone(const float vec[3], float radius, float height, float tmat[][4])
 
5557
 
 
5558
/* needs fixing if non-identity matrix used */
 
5559
static void drawcone(const float vec[3], float radius, float height, float tmat[4][4])
5811
5560
{
5812
5561
        float cur[3];
5813
5562
 
5827
5576
        glVertex3f(cur[0], cur[1] - radius, cur[2]);
5828
5577
        glEnd();
5829
5578
}
5830
 
/* return 1 if nothing was drawn */
5831
 
static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 
5579
 
 
5580
/* return TRUE if nothing was drawn */
 
5581
static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
5582
                     const char dt, const short dflag, const unsigned char ob_wire_col[4])
5832
5583
{
5833
5584
        Object *ob = base->object;
5834
5585
        MetaBall *mb;
5839
5590
        mb = ob->data;
5840
5591
 
5841
5592
        if (mb->editelems) {
5842
 
                UI_ThemeColor(TH_WIRE);
5843
 
                if ((G.f & G_PICKSEL) == 0) drawDispList(scene, v3d, rv3d, base, dt);
 
5593
                if ((G.f & G_PICKSEL) == 0) {
 
5594
                        unsigned char wire_col[4];
 
5595
                        UI_GetThemeColor4ubv(TH_WIRE, wire_col);
 
5596
                        glColor3ubv(wire_col);
 
5597
 
 
5598
                        drawDispList(scene, v3d, rv3d, base, dt, dflag, wire_col);
 
5599
                }
5844
5600
                ml = mb->editelems->first;
5845
5601
        }
5846
5602
        else {
5847
 
                if ((base->flag & OB_FROMDUPLI) == 0)
5848
 
                        drawDispList(scene, v3d, rv3d, base, dt);
 
5603
                if ((base->flag & OB_FROMDUPLI) == 0) {
 
5604
                        drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
 
5605
                }
5849
5606
                ml = mb->elems.first;
5850
5607
        }
5851
5608
 
5852
 
        if (ml == NULL) return 1;
 
5609
        if (ml == NULL) {
 
5610
                return TRUE;
 
5611
        }
5853
5612
 
5854
 
        if (v3d->flag2 & V3D_RENDER_OVERRIDE) return 0;
5855
 
        
5856
 
        /* in case solid draw, reset wire colors */
5857
 
        if (ob->flag & SELECT) {
5858
 
                if (ob == OBACT) UI_ThemeColor(TH_ACTIVE);
5859
 
                else UI_ThemeColor(TH_SELECT);
 
5613
        if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
 
5614
                return FALSE;
5860
5615
        }
5861
 
        else UI_ThemeColor(TH_WIRE);
5862
5616
 
5863
5617
        invert_m4_m4(imat, rv3d->viewmatob);
5864
5618
        normalize_v3(imat[0]);
5865
5619
        normalize_v3(imat[1]);
 
5620
 
 
5621
        if (mb->editelems == NULL) {
 
5622
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5623
                        glColor3ubv(ob_wire_col);
 
5624
                }
 
5625
        }
5866
5626
        
5867
5627
        while (ml) {
5868
 
 
5869
5628
                /* draw radius */
5870
5629
                if (mb->editelems) {
5871
 
                        if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
5872
 
                        else cpack(0x3030A0);
 
5630
                        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5631
                                if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
 
5632
                                else cpack(0x3030A0);
 
5633
                        }
5873
5634
                        
5874
5635
                        if (G.f & G_PICKSEL) {
5875
5636
                                ml->selcol1 = code;
5880
5641
 
5881
5642
                /* draw stiffness */
5882
5643
                if (mb->editelems) {
5883
 
                        if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) cpack(0xA0F0A0);
5884
 
                        else cpack(0x30A030);
 
5644
                        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5645
                                if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) cpack(0xA0F0A0);
 
5646
                                else cpack(0x30A030);
 
5647
                        }
5885
5648
                        
5886
5649
                        if (G.f & G_PICKSEL) {
5887
5650
                                ml->selcol2 = code;
5892
5655
                
5893
5656
                ml = ml->next;
5894
5657
        }
5895
 
        return 0;
 
5658
        return FALSE;
5896
5659
}
5897
5660
 
5898
 
static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
 
5661
static void draw_forcefield(Object *ob, RegionView3D *rv3d,
 
5662
                            const short dflag, const unsigned char ob_wire_col[4])
5899
5663
{
5900
5664
        PartDeflect *pd = ob->pd;
5901
5665
        float imat[4][4], tmat[4][4];
5902
5666
        float vec[3] = {0.0, 0.0, 0.0};
5903
 
        int curcol;
5904
5667
        float size;
5905
 
 
5906
 
        /* XXX why? */
5907
 
        if (ob != scene->obedit && (ob->flag & SELECT)) {
5908
 
                if (ob == OBACT) curcol = TH_ACTIVE;
5909
 
                else curcol = TH_SELECT;
5910
 
        }
5911
 
        else curcol = TH_EMPTY;
5912
5668
        
5913
5669
        /* scale size of circle etc with the empty drawsize */
5914
5670
        if (ob->type == OB_EMPTY) size = ob->empty_drawsize;
5916
5672
        
5917
5673
        /* calculus here, is reused in PFIELD_FORCE */
5918
5674
        invert_m4_m4(imat, rv3d->viewmatob);
5919
 
//      normalize_v3(imat[0]);          // we don't do this because field doesnt scale either... apart from wind!
 
5675
//      normalize_v3(imat[0]);  /* we don't do this because field doesnt scale either... apart from wind! */
5920
5676
//      normalize_v3(imat[1]);
5921
5677
        
5922
5678
        if (pd->forcefield == PFIELD_WIND) {
5923
5679
                float force_val;
5924
 
                
5925
 
                unit_m4(tmat);
5926
 
                UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
5927
 
                
 
5680
 
 
5681
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5682
                        ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
 
5683
                }
 
5684
 
5928
5685
                //if (has_ipo_code(ob->ipo, OB_PD_FSTR))
5929
5686
                //      force_val = IPO_GetFloatValue(ob->ipo, OB_PD_FSTR, scene->r.cfra);
5930
5687
                //else
5931
5688
                {
5932
5689
                        force_val = pd->f_strength;
5933
5690
                }
 
5691
 
 
5692
                unit_m4(tmat);
5934
5693
                force_val *= 0.1f;
5935
5694
                drawcircball(GL_LINE_LOOP, vec, size, tmat);
5936
5695
                vec[2] = 0.5f * force_val;
5952
5711
                        ffall_val = pd->f_power;
5953
5712
                }
5954
5713
 
5955
 
                UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
 
5714
                if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
5956
5715
                drawcircball(GL_LINE_LOOP, vec, size, imat);
5957
 
                UI_ThemeColorBlend(curcol, TH_BACK, 0.9f - 0.4f / powf(1.5f, ffall_val));
 
5716
                if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.9f - 0.4f / powf(1.5f, ffall_val));
5958
5717
                drawcircball(GL_LINE_LOOP, vec, size * 1.5f, imat);
5959
 
                UI_ThemeColorBlend(curcol, TH_BACK, 0.9f - 0.4f / powf(2.0f, ffall_val));
 
5718
                if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.9f - 0.4f / powf(2.0f, ffall_val));
5960
5719
                drawcircball(GL_LINE_LOOP, vec, size * 2.0f, imat);
5961
5720
        }
5962
5721
        else if (pd->forcefield == PFIELD_VORTEX) {
5975
5734
                        force_val = pd->f_strength;
5976
5735
                }
5977
5736
 
5978
 
                UI_ThemeColorBlend(curcol, TH_BACK, 0.7f);
 
5737
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5738
                        ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.7f);
 
5739
                }
 
5740
 
5979
5741
                if (force_val < 0) {
5980
5742
                        drawspiral(vec, size, tmat, 1);
5981
5743
                        drawspiral(vec, size, tmat, 16);
5997
5759
                                mindist = pd->f_strength;
5998
5760
                        }
5999
5761
 
 
5762
                        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5763
                                ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
 
5764
                        }
 
5765
 
6000
5766
                        /*path end*/
6001
5767
                        setlinestyle(3);
6002
5768
                        where_on_path(ob, 1.0f, guidevec1, guidevec2, NULL, NULL, NULL);
6003
 
                        UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
6004
5769
                        drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
6005
5770
 
6006
5771
                        /*path beginning*/
6007
5772
                        setlinestyle(0);
6008
5773
                        where_on_path(ob, 0.0f, guidevec1, guidevec2, NULL, NULL, NULL);
6009
 
                        UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
6010
5774
                        drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
6011
5775
                        
6012
5776
                        copy_v3_v3(vec, guidevec1); /* max center */
6014
5778
        }
6015
5779
 
6016
5780
        setlinestyle(3);
6017
 
        UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
 
5781
 
 
5782
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
5783
                ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
 
5784
        }
6018
5785
 
6019
5786
        if (pd->falloff == PFIELD_FALL_SPHERE) {
6020
5787
                /* as last, guide curve alters it */
6091
5858
#if 0
6092
5859
static void get_local_bounds(Object *ob, float center[3], float size[3])
6093
5860
{
6094
 
        BoundBox *bb = object_get_boundbox(ob);
 
5861
        BoundBox *bb = BKE_object_boundbox_get(ob);
6095
5862
        
6096
5863
        if (bb == NULL) {
6097
5864
                zero_v3(center);
6098
5865
                copy_v3_v3(size, ob->size);
6099
5866
        }
6100
5867
        else {
6101
 
                size[0] = 0.5 * fabs(bb->vec[0][0] - bb->vec[4][0]);
6102
 
                size[1] = 0.5 * fabs(bb->vec[0][1] - bb->vec[2][1]);
6103
 
                size[2] = 0.5 * fabs(bb->vec[0][2] - bb->vec[1][2]);
 
5868
                size[0] = 0.5 * fabsf(bb->vec[0][0] - bb->vec[4][0]);
 
5869
                size[1] = 0.5 * fabsf(bb->vec[0][1] - bb->vec[2][1]);
 
5870
                size[2] = 0.5 * fabsf(bb->vec[0][2] - bb->vec[1][2]);
6104
5871
 
6105
5872
                center[0] = (bb->vec[0][0] + bb->vec[4][0]) / 2.0;
6106
5873
                center[1] = (bb->vec[0][1] + bb->vec[2][1]) / 2.0;
6152
5919
        BoundBox *bb = NULL;
6153
5920
        
6154
5921
        if (ob->type == OB_MESH) {
6155
 
                bb = mesh_get_bb(ob);
 
5922
                bb = BKE_mesh_boundbox_get(ob);
6156
5923
        }
6157
5924
        else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
6158
5925
                bb = ob->bb ? ob->bb : ( (Curve *)ob->data)->bb;
6159
5926
        }
6160
5927
        else if (ob->type == OB_MBALL) {
6161
 
                if (is_basis_mball(ob)) {
 
5928
                if (BKE_mball_is_basis(ob)) {
6162
5929
                        bb = ob->bb;
6163
5930
                        if (bb == NULL) {
6164
 
                                makeDispListMBall(scene, ob);
 
5931
                                BKE_displist_make_mball(scene, ob);
6165
5932
                                bb = ob->bb;
6166
5933
                        }
6167
5934
                }
6168
5935
        }
6169
5936
        else if (ob->type == OB_ARMATURE) {
6170
 
                bb = BKE_armature_get_bb(ob);
 
5937
                bb = BKE_armature_boundbox_get(ob);
6171
5938
        }
6172
5939
        else {
6173
5940
                drawcube();
6186
5953
        float vec[8][3], loc[3], size[3];
6187
5954
        
6188
5955
        if (ob->type == OB_MESH) {
6189
 
                mesh_get_texspace(ob->data, loc, NULL, size);
 
5956
                BKE_mesh_texspace_get(ob->data, loc, NULL, size);
6190
5957
        }
6191
5958
        else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
6192
5959
                Curve *cu = ob->data;
6217
5984
}
6218
5985
 
6219
5986
/* draws wire outline */
6220
 
static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 
5987
static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
 
5988
                             const unsigned char ob_wire_col[4])
6221
5989
{
6222
5990
        RegionView3D *rv3d = ar->regiondata;
6223
5991
        Object *ob = base->object;
6234
6002
                        hasfaces = dm->getNumTessFaces(dm);
6235
6003
                }
6236
6004
                else {
6237
 
                        hasfaces = displist_has_faces(&ob->disp);
 
6005
                        hasfaces = BKE_displist_has_faces(&ob->disp);
6238
6006
                }
6239
6007
 
6240
6008
                if (hasfaces && ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
6249
6017
                }
6250
6018
        }
6251
6019
        else if (ob->type == OB_MBALL) {
6252
 
                if (is_basis_mball(ob)) {
 
6020
                if (BKE_mball_is_basis(ob)) {
6253
6021
                        if ((base->flag & OB_FROMDUPLI) == 0)
6254
6022
                                drawDispListwire(&ob->disp);
6255
6023
                }
6256
6024
        }
6257
6025
        else if (ob->type == OB_ARMATURE) {
6258
6026
                if (!(ob->mode & OB_MODE_POSE && base == scene->basact))
6259
 
                        draw_armature(scene, v3d, ar, base, OB_WIRE, FALSE, TRUE);
 
6027
                        draw_armature(scene, v3d, ar, base, OB_WIRE, FALSE, ob_wire_col, TRUE);
6260
6028
        }
6261
6029
 
6262
6030
        glLineWidth(1.0);
6263
6031
        glDepthMask(1);
6264
6032
}
6265
6033
 
6266
 
static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob) 
 
6034
static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsigned char ob_wire_col[4])
6267
6035
{
6268
 
        if (ob != scene->obedit && (ob->flag & SELECT)) {
6269
 
                if (ob == OBACT) {
6270
 
                        if (ob->flag & OB_FROMGROUP) UI_ThemeColor(TH_GROUP_ACTIVE);
6271
 
                        else UI_ThemeColor(TH_ACTIVE);
 
6036
        if (ELEM4(ob->type, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL)) {
 
6037
 
 
6038
                if (scene->obedit == ob) {
 
6039
                        UI_ThemeColor(TH_WIRE);
6272
6040
                }
6273
 
                else if (ob->flag & OB_FROMGROUP)
6274
 
                        UI_ThemeColorShade(TH_GROUP_ACTIVE, -16);
6275
 
                else
6276
 
                        UI_ThemeColor(TH_SELECT);
6277
 
        }
6278
 
        else {
6279
 
                if (ob->flag & OB_FROMGROUP)
6280
 
                        UI_ThemeColor(TH_GROUP);
6281
6041
                else {
6282
 
                        if (ob->dtx & OB_DRAWWIRE) {
6283
 
                                glColor3ub(80, 80, 80);
6284
 
                        }
6285
 
                        else {
6286
 
                                UI_ThemeColor(TH_WIRE);
6287
 
                        }
6288
 
                }
6289
 
        }
6290
 
        
6291
 
        bglPolygonOffset(rv3d->dist, 1.0);
6292
 
        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
6293
 
        
6294
 
        if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
6295
 
                Curve *cu = ob->data;
6296
 
                if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
6297
 
                        if (ob->type == OB_CURVE)
6298
 
                                draw_index_wire = 0;
6299
 
 
6300
 
                        if (ob->derivedFinal) {
6301
 
                                drawCurveDMWired(ob);
6302
 
                        }
6303
 
                        else {
 
6042
                        glColor3ubv(ob_wire_col);
 
6043
                }
 
6044
 
 
6045
                bglPolygonOffset(rv3d->dist, 1.0);
 
6046
                glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
 
6047
 
 
6048
                if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
 
6049
                        Curve *cu = ob->data;
 
6050
                        if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
 
6051
                                if (ob->type == OB_CURVE)
 
6052
                                        draw_index_wire = 0;
 
6053
 
 
6054
                                if (ob->derivedFinal) {
 
6055
                                        drawCurveDMWired(ob);
 
6056
                                }
 
6057
                                else {
 
6058
                                        drawDispListwire(&ob->disp);
 
6059
                                }
 
6060
 
 
6061
                                if (ob->type == OB_CURVE)
 
6062
                                        draw_index_wire = 1;
 
6063
                        }
 
6064
                }
 
6065
                else if (ob->type == OB_MBALL) {
 
6066
                        if (BKE_mball_is_basis(ob)) {
6304
6067
                                drawDispListwire(&ob->disp);
6305
6068
                        }
6306
 
 
6307
 
                        if (ob->type == OB_CURVE)
6308
 
                                draw_index_wire = 1;
6309
 
                }
6310
 
        }
6311
 
        else if (ob->type == OB_MBALL) {
6312
 
                if (is_basis_mball(ob)) {
6313
 
                        drawDispListwire(&ob->disp);
6314
 
                }
6315
 
        }
6316
 
 
6317
 
        glDepthMask(1);
6318
 
        bglPolygonOffset(rv3d->dist, 0.0);
 
6069
                }
 
6070
 
 
6071
                glDepthMask(1);
 
6072
                bglPolygonOffset(rv3d->dist, 0.0);
 
6073
        }
6319
6074
}
6320
6075
 
6321
6076
/* should be called in view space */
6348
6103
        }
6349
6104
}
6350
6105
 
6351
 
static void drawRBpivot(bRigidBodyJointConstraint *data)
 
6106
static void draw_rigid_body_pivot(bRigidBodyJointConstraint *data, const short dflag, unsigned char ob_wire_col[4])
6352
6107
{
6353
6108
        const char *axis_str[3] = {"px", "py", "pz"};
6354
6109
        int axis;
6355
6110
        float mat[4][4];
6356
6111
 
6357
 
        /* color */
6358
 
        float curcol[4];
6359
 
        unsigned char tcol[4];
6360
 
 
6361
 
        glGetFloatv(GL_CURRENT_COLOR, curcol);
6362
 
        rgb_float_to_uchar(tcol, curcol);
6363
 
        tcol[3] = 255;
6364
 
 
6365
6112
        eul_to_mat4(mat, &data->axX);
6366
6113
        glLineWidth(4.0f);
6367
6114
        setlinestyle(2);
6371
6118
 
6372
6119
                copy_v3_v3(v, &data->pivX);
6373
6120
 
6374
 
                dir[axis] = 1.f;
 
6121
                dir[axis] = 1.0f;
6375
6122
                glBegin(GL_LINES);
6376
6123
                mul_m4_v3(mat, dir);
6377
6124
                add_v3_v3(v, dir);
6379
6126
                glVertex3fv(v);
6380
6127
                glEnd();
6381
6128
 
6382
 
                view3d_cached_text_draw_add(v, axis_str[axis], 0, V3D_CACHE_TEXT_ASCII, tcol);
 
6129
                /* when const color is set wirecolor is NULL - we could get the current color but
 
6130
                 * with selection and group instancing its not needed to draw the text */
 
6131
                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
6132
                        view3d_cached_text_draw_add(v, axis_str[axis], 0, V3D_CACHE_TEXT_ASCII, ob_wire_col);
 
6133
                }
6383
6134
        }
6384
6135
        glLineWidth(1.0f);
6385
6136
        setlinestyle(0);
6386
6137
}
6387
6138
 
6388
 
/* flag can be DRAW_PICKING     and/or DRAW_CONSTCOLOR, DRAW_SCENESET */
6389
 
void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 
6139
static void draw_object_wire_color(Scene *scene, Base *base, unsigned char r_ob_wire_col[4],
 
6140
                                   const int warning_recursive)
 
6141
{
 
6142
        Object *ob = base->object;
 
6143
        int colindex = 0;
 
6144
 
 
6145
        /* confusing logic here, there are 2 methods of setting the color
 
6146
         * 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
 
6147
         *
 
6148
         * note: no theme yet for 'colindex' */
 
6149
        int theme_id = TH_WIRE;
 
6150
        int theme_shade = 0;
 
6151
 
 
6152
        if ((scene->obedit == NULL) &&
 
6153
            (G.moving & G_TRANSFORM_OBJ) &&
 
6154
            (base->flag & (SELECT + BA_WAS_SEL)))
 
6155
        {
 
6156
                theme_id = TH_TRANSFORM;
 
6157
        }
 
6158
        else {
 
6159
                /* Sets the 'colindex' */
 
6160
                if (ob->id.lib) {
 
6161
                        colindex = (base->flag & (SELECT + BA_WAS_SEL)) ? 4 : 3;
 
6162
                }
 
6163
                else if (warning_recursive == 1) {
 
6164
                        if (base->flag & (SELECT + BA_WAS_SEL)) {
 
6165
                                colindex = (scene->basact == base) ? 8 : 7;
 
6166
                        }
 
6167
                        else {
 
6168
                                colindex = 6;
 
6169
                        }
 
6170
                }
 
6171
                /* Sets the 'theme_id' or fallback to wire */
 
6172
                else {
 
6173
                        if (ob->flag & OB_FROMGROUP) {
 
6174
                                if (base->flag & (SELECT + BA_WAS_SEL)) {
 
6175
                                        /* uses darker active color for non-active + selected*/
 
6176
                                        theme_id = TH_GROUP_ACTIVE;
 
6177
 
 
6178
                                        if (scene->basact != base) {
 
6179
                                                theme_shade = -16;
 
6180
                                        }
 
6181
                                }
 
6182
                                else {
 
6183
                                        theme_id = TH_GROUP;
 
6184
                                }
 
6185
                        }
 
6186
                        else {
 
6187
                                if (base->flag & (SELECT + BA_WAS_SEL)) {
 
6188
                                        theme_id = scene->basact == base ? TH_ACTIVE : TH_SELECT;
 
6189
                                }
 
6190
                                else {
 
6191
                                        if (ob->type == OB_LAMP) theme_id = TH_LAMP;
 
6192
                                        else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
 
6193
                                        else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
 
6194
                                        else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
 
6195
                                        /* fallback to TH_WIRE */
 
6196
                                }
 
6197
                        }
 
6198
                }
 
6199
        }
 
6200
 
 
6201
        /* finally set the color */
 
6202
        if (colindex == 0) {
 
6203
                if (theme_shade == 0) UI_GetThemeColor3ubv(theme_id, r_ob_wire_col);
 
6204
                else                  UI_GetThemeColorShade3ubv(theme_id, theme_shade, r_ob_wire_col);
 
6205
        }
 
6206
        else {
 
6207
                cpack_cpy_3ub(r_ob_wire_col, colortab[colindex]);
 
6208
        }
 
6209
 
 
6210
        /* no reason to use this but some functions take col[4] */
 
6211
        r_ob_wire_col[3] = 255;
 
6212
}
 
6213
 
 
6214
static void draw_object_matcap_check(Scene *scene, View3D *v3d, Object *ob)
 
6215
{
 
6216
        /* fixed rule, active object draws as matcap */
 
6217
        if (ob == OBACT) {
 
6218
                if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))
 
6219
                        return;
 
6220
                        
 
6221
                if (v3d->defmaterial == NULL) {
 
6222
                        extern Material defmaterial;
 
6223
                        
 
6224
                        v3d->defmaterial = MEM_mallocN(sizeof(Material), "matcap material");
 
6225
                        *(v3d->defmaterial) = defmaterial;
 
6226
                        v3d->defmaterial->gpumaterial.first = v3d->defmaterial->gpumaterial.last = NULL;
 
6227
                        v3d->defmaterial->preview = NULL;
 
6228
                }
 
6229
                /* first time users */
 
6230
                if (v3d->matcap_icon == 0)
 
6231
                        v3d->matcap_icon = ICON_MATCAP_01;
 
6232
                
 
6233
                if (v3d->defmaterial->preview == NULL)
 
6234
                        v3d->defmaterial->preview = UI_icon_to_preview(v3d->matcap_icon);
 
6235
                
 
6236
                /* signal to all material checks, gets cleared below */
 
6237
                v3d->flag2 |= V3D_SHOW_SOLID_MATCAP;
 
6238
        }
 
6239
 
 
6240
}
 
6241
 
 
6242
/**
 
6243
 * main object drawing function, draws in selection
 
6244
 * \param dflag (draw flag) can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET
 
6245
 */
 
6246
void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short dflag)
6390
6247
{
6391
6248
        static int warning_recursive = 0;
6392
6249
        ModifierData *md = NULL;
6395
6252
        RegionView3D *rv3d = ar->regiondata;
6396
6253
        float vec1[3], vec2[3];
6397
6254
        unsigned int col = 0;
6398
 
        int /*sel, drawtype,*/ colindex = 0;
 
6255
        unsigned char _ob_wire_col[4];      /* dont initialize this */
 
6256
        unsigned char *ob_wire_col = NULL;  /* dont initialize this, use NULL crashes as a way to find invalid use */
6399
6257
        int i, selstart, selend, empty_object = 0;
6400
 
        short dt, dtx, zbufoff = 0;
 
6258
        short dtx;
 
6259
        char  dt;
 
6260
        short zbufoff = 0;
6401
6261
        const short is_obact = (ob == OBACT);
6402
6262
 
6403
6263
        /* only once set now, will be removed too, should become a global standard */
6415
6275
        }
6416
6276
 
6417
6277
        /* XXX particles are not safe for simultaneous threaded render */
6418
 
        if (G.rendering && ob->particlesystem.first)
 
6278
        if (G.is_rendering && ob->particlesystem.first)
6419
6279
                return;
6420
6280
 
6421
6281
        /* xray delay? */
6422
 
        if ((flag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0) {
 
6282
        if ((dflag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0 && (v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
6423
6283
                /* don't do xray in particle mode, need the z-buffer */
6424
6284
                if (!(ob->mode & OB_MODE_PARTICLE_EDIT)) {
6425
6285
                        /* xray and transp are set when it is drawing the 2nd/3rd pass */
6426
6286
                        if (!v3d->xray && !v3d->transp && (ob->dtx & OB_DRAWXRAY) && !(ob->dtx & OB_DRAWTRANSP)) {
6427
 
                                add_view3d_after(&v3d->afterdraw_xray, base, flag);
 
6287
                                ED_view3d_after_add(&v3d->afterdraw_xray, base, dflag);
6428
6288
                                return;
6429
6289
                        }
6430
6290
                }
6433
6293
        /* no return after this point, otherwise leaks */
6434
6294
        view3d_cached_text_draw_begin();
6435
6295
        
6436
 
        /* patch? children objects with a timeoffs change the parents. How to solve! */
6437
 
        /* if ( ((int)ob->ctime) != F_(scene->r.cfra)) where_is_object(scene, ob); */
6438
 
        
6439
6296
        /* draw motion paths (in view space) */
6440
6297
        if (ob->mpath && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
6441
6298
                bAnimVizSettings *avs = &ob->avs;
6455
6312
        ED_view3d_init_mats_rv3d_gl(ob, rv3d);
6456
6313
 
6457
6314
        /* which wire color */
6458
 
        if ((flag & DRAW_CONSTCOLOR) == 0) {
6459
 
                /* confusing logic here, there are 2 methods of setting the color
6460
 
                 * 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
6461
 
                 *
6462
 
                 * note: no theme yet for 'colindex' */
6463
 
                int theme_id = TH_WIRE;
6464
 
                int theme_shade = 0;
6465
 
 
6466
 
                project_short(ar, ob->obmat[3], &base->sx);
6467
 
 
6468
 
                if ((scene->obedit == NULL) &&
6469
 
                    (G.moving & G_TRANSFORM_OBJ) &&
6470
 
                    (base->flag & (SELECT + BA_WAS_SEL)))
6471
 
                {
6472
 
                        theme_id = TH_TRANSFORM;
6473
 
                }
6474
 
                else {
6475
 
                        /* Sets the 'colindex' */
6476
 
                        if (ob->id.lib) {
6477
 
                                colindex = (base->flag & (SELECT + BA_WAS_SEL)) ? 4 : 3;
6478
 
                        }
6479
 
                        else if (warning_recursive == 1) {
6480
 
                                if (base->flag & (SELECT + BA_WAS_SEL)) {
6481
 
                                        colindex = (scene->basact == base) ? 8 : 7;
6482
 
                                }
6483
 
                                else {
6484
 
                                        colindex = 6;
6485
 
                                }
6486
 
                        }
6487
 
                        /* Sets the 'theme_id' or fallback to wire */
6488
 
                        else {
6489
 
                                if (ob->flag & OB_FROMGROUP) {
6490
 
                                        if (base->flag & (SELECT + BA_WAS_SEL)) {
6491
 
                                                /* uses darker active color for non-active + selected*/
6492
 
                                                theme_id = TH_GROUP_ACTIVE;
6493
 
                                                
6494
 
                                                if (scene->basact != base) {
6495
 
                                                        theme_shade = -16;
6496
 
                                                }
6497
 
                                        }
6498
 
                                        else {
6499
 
                                                theme_id = TH_GROUP;
6500
 
                                        }
6501
 
                                }
6502
 
                                else {
6503
 
                                        if (base->flag & (SELECT + BA_WAS_SEL)) {
6504
 
                                                theme_id = scene->basact == base ? TH_ACTIVE : TH_SELECT;
6505
 
                                        }
6506
 
                                        else {
6507
 
                                                if (ob->type == OB_LAMP) theme_id = TH_LAMP;
6508
 
                                                else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
6509
 
                                                else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
6510
 
                                                else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
6511
 
                                                /* fallback to TH_WIRE */
6512
 
                                        }
6513
 
                                }
6514
 
                        }
6515
 
                }
6516
 
 
6517
 
                /* finally set the color */
6518
 
                if (colindex == 0) {
6519
 
                        if (theme_shade == 0) UI_ThemeColor(theme_id);
6520
 
                        else UI_ThemeColorShade(theme_id, theme_shade);
6521
 
                }
6522
 
                else {
6523
 
                        col = colortab[colindex];
6524
 
                        cpack(col);
6525
 
                }
 
6315
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
6316
 
 
6317
                ED_view3d_project_base(ar, base);
 
6318
 
 
6319
                draw_object_wire_color(scene, base, _ob_wire_col, warning_recursive);
 
6320
                ob_wire_col = _ob_wire_col;
 
6321
 
 
6322
                glColor3ubv(ob_wire_col);
6526
6323
        }
6527
6324
 
6528
6325
        /* maximum drawtype */
6531
6328
        dt = MIN2(dt, ob->dt);
6532
6329
        if (v3d->zbuf == 0 && dt > OB_WIRE) dt = OB_WIRE;
6533
6330
        dtx = 0;
 
6331
        
 
6332
        /* matcap check */
 
6333
        if (dt == OB_SOLID && (v3d->flag2 & V3D_SOLID_MATCAP))
 
6334
                draw_object_matcap_check(scene, v3d, ob);
6534
6335
 
6535
 
        /* faceselect exception: also draw solid when dt==wire, except in editmode */
 
6336
        /* faceselect exception: also draw solid when (dt == wire), except in editmode */
6536
6337
        if (is_obact && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) {
6537
6338
                if (ob->type == OB_MESH) {
6538
6339
 
6575
6376
        /* bad exception, solve this! otherwise outline shows too late */
6576
6377
        if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
6577
6378
                /* still needed for curves hidden in other layers. depgraph doesnt handle that yet */
6578
 
                if (ob->disp.first == NULL) makeDispListCurveTypes(scene, ob, 0);
 
6379
                if (ob->disp.first == NULL) BKE_displist_make_curveTypes(scene, ob, 0);
6579
6380
        }
6580
6381
        
6581
6382
        /* draw outline for selected objects, mesh does itself */
6582
6383
        if ((v3d->flag & V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && ob->type != OB_MESH) {
6583
 
                if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (flag & DRAW_SCENESET) == 0) {
6584
 
                        if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(flag & DRAW_PICKING)) {
6585
 
                                
6586
 
                                drawObjectSelect(scene, v3d, ar, base);
 
6384
                if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (dflag & DRAW_SCENESET) == 0) {
 
6385
                        if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(dflag & (DRAW_PICKING | DRAW_CONSTCOLOR))) {
 
6386
                                drawObjectSelect(scene, v3d, ar, base, ob_wire_col);
6587
6387
                        }
6588
6388
                }
6589
6389
        }
6590
6390
 
6591
6391
        switch (ob->type) {
6592
6392
                case OB_MESH:
6593
 
                        empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, flag);
6594
 
                        if (flag != DRAW_CONSTCOLOR) dtx &= ~OB_DRAWWIRE;  // mesh draws wire itself
 
6393
                        empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
 
6394
                        if (dflag != DRAW_CONSTCOLOR) dtx &= ~OB_DRAWWIRE;  // mesh draws wire itself
6595
6395
 
6596
6396
                        break;
6597
6397
                case OB_FONT:
6598
6398
                        cu = ob->data;
6599
6399
                        if (cu->editfont) {
6600
 
                                draw_textcurs(cu->editfont->textcurs);
 
6400
                                draw_textcurs(rv3d, cu->editfont->textcurs);
6601
6401
 
6602
6402
                                if (cu->flag & CU_FAST) {
6603
6403
                                        cpack(0xFFFFFF);
6604
6404
                                        set_inverted_drawing(1);
6605
 
                                        drawDispList(scene, v3d, rv3d, base, OB_WIRE);
 
6405
                                        drawDispList(scene, v3d, rv3d, base, OB_WIRE, dflag, ob_wire_col);
6606
6406
                                        set_inverted_drawing(0);
6607
6407
                                }
6608
6408
                                else {
6609
 
                                        drawDispList(scene, v3d, rv3d, base, dt);
 
6409
                                        drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6610
6410
                                }
6611
6411
 
6612
6412
                                if (cu->linewidth != 0.0f) {
6648
6448
                                setlinestyle(0);
6649
6449
 
6650
6450
 
6651
 
                                if (BKE_font_getselection(ob, &selstart, &selend) && cu->selboxes) {
 
6451
                                if (BKE_vfont_select_get(ob, &selstart, &selend) && cu->selboxes) {
6652
6452
                                        float selboxw;
6653
6453
 
6654
6454
                                        cpack(0xffffff);
6681
6481
                                }
6682
6482
                        }
6683
6483
                        else if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
6684
 
                                empty_object = drawDispList(scene, v3d, rv3d, base, dt);
 
6484
                                empty_object = drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6685
6485
                        }
6686
6486
 
6687
6487
                        break;
6690
6490
                        cu = ob->data;
6691
6491
 
6692
6492
                        if (cu->editnurb) {
6693
 
                                ListBase *nurbs = curve_editnurbs(cu);
6694
 
                                drawnurb(scene, v3d, rv3d, base, nurbs->first, dt);
 
6493
                                ListBase *nurbs = BKE_curve_editNurbs_get(cu);
 
6494
                                drawnurb(scene, v3d, rv3d, base, nurbs->first, dt, dflag, ob_wire_col);
6695
6495
                        }
6696
6496
                        else if (dt == OB_BOUNDBOX) {
6697
6497
                                if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && (v3d->drawtype >= OB_WIRE)) == 0) {
6699
6499
                                }
6700
6500
                        }
6701
6501
                        else if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
6702
 
                                empty_object = drawDispList(scene, v3d, rv3d, base, dt);
 
6502
                                empty_object = drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6703
6503
 
6704
6504
//XXX old animsys                               if (cu->path)
6705
6505
//                                  curve_draw_speed(scene, ob);
6710
6510
                        MetaBall *mb = ob->data;
6711
6511
                        
6712
6512
                        if (mb->editelems)
6713
 
                                drawmball(scene, v3d, rv3d, base, dt);
 
6513
                                drawmball(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6714
6514
                        else if (dt == OB_BOUNDBOX) {
6715
6515
                                if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && (v3d->drawtype >= OB_WIRE)) == 0) {
6716
6516
                                        draw_bounding_volume(scene, ob, ob->boundtype);
6717
6517
                                }
6718
6518
                        }
6719
6519
                        else
6720
 
                                empty_object = drawmball(scene, v3d, rv3d, base, dt);
 
6520
                                empty_object = drawmball(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6721
6521
                        break;
6722
6522
                }
6723
6523
                case OB_EMPTY:
6724
6524
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
6725
6525
                                if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
6726
 
                                        draw_empty_image(ob);
 
6526
                                        draw_empty_image(ob, dflag, ob_wire_col);
6727
6527
                                }
6728
6528
                                else {
6729
6529
                                        drawaxes(ob->empty_drawsize, ob->empty_drawtype);
6732
6532
                        break;
6733
6533
                case OB_LAMP:
6734
6534
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
6735
 
                                drawlamp(scene, v3d, rv3d, base, dt, flag);
 
6535
                                drawlamp(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
6736
6536
                                if (dtx || (base->flag & SELECT)) glMultMatrixf(ob->obmat);
6737
6537
                        }
6738
6538
                        break;
6740
6540
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0 ||
6741
6541
                            (rv3d->persp == RV3D_CAMOB && v3d->camera == ob)) /* special exception for active camera */
6742
6542
                        {
6743
 
                                drawcamera(scene, v3d, rv3d, base, flag);
 
6543
                                drawcamera(scene, v3d, rv3d, base, dflag, ob_wire_col);
6744
6544
                                break;
6745
6545
                        }
6746
6546
                case OB_SPEAKER:
6747
6547
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
6748
 
                                drawspeaker(scene, v3d, rv3d, ob, flag);
 
6548
                                drawspeaker(scene, v3d, rv3d, ob, dflag);
6749
6549
                        break;
6750
6550
                case OB_LATTICE:
6751
6551
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
6763
6563
                                else {
6764
6564
                                        if (dt > OB_WIRE)
6765
6565
                                                GPU_enable_material(0, NULL);  /* we use default material */
6766
 
                                        empty_object = draw_armature(scene, v3d, ar, base, dt, flag, FALSE);
 
6566
                                        empty_object = draw_armature(scene, v3d, ar, base, dt, dflag, ob_wire_col, FALSE);
6767
6567
                                        if (dt > OB_WIRE)
6768
6568
                                                GPU_disable_material();
6769
6569
                                }
6777
6577
 
6778
6578
        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
6779
6579
 
6780
 
                if (ob->soft /*&& flag & OB_SBMOTION*/) {
 
6580
                if (ob->soft /*&& dflag & OB_SBMOTION*/) {
6781
6581
                        float mrt[3][3], msc[3][3], mtr[3][3];
6782
6582
                        SoftBody *sb = NULL;
6783
6583
                        float tipw = 0.5f, tiph = 0.5f, drawsize = 4.0f;
6795
6595
                }
6796
6596
 
6797
6597
                if (ob->pd && ob->pd->forcefield) {
6798
 
                        draw_forcefield(scene, ob, rv3d);
 
6598
                        draw_forcefield(ob, rv3d, dflag, ob_wire_col);
6799
6599
                }
6800
6600
        }
6801
6601
 
6802
6602
        /* code for new particle system */
6803
6603
        if ((warning_recursive == 0) &&
6804
6604
            (ob->particlesystem.first) &&
6805
 
            (flag & DRAW_PICKING) == 0 &&
6806
6605
            (ob != scene->obedit)
6807
6606
            )
6808
6607
        {
6835
6634
        }
6836
6635
 
6837
6636
        /* draw edit particles last so that they can draw over child particles */
6838
 
        if ( (warning_recursive == 0) &&
6839
 
             (flag & DRAW_PICKING) == 0 &&
6840
 
             (!scene->obedit))
 
6637
        if ((warning_recursive == 0) &&
 
6638
            (dflag & DRAW_PICKING) == 0 &&
 
6639
            (!scene->obedit))
6841
6640
        {
6842
6641
 
6843
6642
                if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) {
6889
6688
#endif
6890
6689
                }
6891
6690
 
6892
 
                // only draw domains
6893
 
                if (smd->domain && smd->domain->fluid) {
6894
 
                        if (CFRA < smd->domain->point_cache[0]->startframe) {
6895
 
                                /* don't show smoke before simulation starts, this could be made an option in the future */
6896
 
                        }
6897
 
                        else if (!smd->domain->wt || !(smd->domain->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
6898
 
// #if 0
6899
 
                                smd->domain->tex = NULL;
6900
 
                                GPU_create_smoke(smd, 0);
6901
 
                                draw_volume(ar, smd->domain->tex,
6902
 
                                            smd->domain->p0, smd->domain->p1,
6903
 
                                            smd->domain->res, smd->domain->dx,
6904
 
                                            smd->domain->tex_shadow);
6905
 
                                GPU_free_smoke(smd);
6906
 
// #endif
 
6691
                /* only draw domains */
 
6692
                if (smd->domain) {
 
6693
                        SmokeDomainSettings *sds = smd->domain;
 
6694
                        float p0[3], p1[3], viewnormal[3];
 
6695
                        BoundBox bb;
 
6696
 
 
6697
                        glLoadMatrixf(rv3d->viewmat);
 
6698
                        glMultMatrixf(ob->obmat);
 
6699
 
 
6700
                        /* draw adaptive domain bounds */
 
6701
                        if (sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN) {
 
6702
                                /* draw domain max bounds */
 
6703
                                VECSUBFAC(p0, sds->p0, sds->cell_size, sds->adapt_res);
 
6704
                                VECADDFAC(p1, sds->p1, sds->cell_size, sds->adapt_res);
 
6705
                                BKE_boundbox_init_from_minmax(&bb, p0, p1);
 
6706
                                draw_box(bb.vec);
 
6707
 
 
6708
                                /* draw base resolution bounds */
6907
6709
#if 0
6908
 
                                int x, y, z;
6909
 
                                float *density = smoke_get_density(smd->domain->fluid);
6910
 
 
6911
 
                                glLoadMatrixf(rv3d->viewmat);
6912
 
                                // glMultMatrixf(ob->obmat);
6913
 
 
6914
 
                                if (col || (ob->flag & SELECT)) cpack(0xFFFFFF);
6915
 
                                glDepthMask(GL_FALSE);
6916
 
                                glEnable(GL_BLEND);
6917
 
                                
6918
 
 
6919
 
                                // glPointSize(3.0);
6920
 
                                bglBegin(GL_POINTS);
6921
 
 
6922
 
                                for (x = 0; x < smd->domain->res[0]; x++) {
6923
 
                                        for (y = 0; y < smd->domain->res[1]; y++) {
6924
 
                                                for (z = 0; z < smd->domain->res[2]; z++) {
6925
 
                                                        float tmp[3];
6926
 
                                                        int index = smoke_get_index(x, smd->domain->res[0], y, smd->domain->res[1], z);
6927
 
 
6928
 
                                                        if (density[index] > FLT_EPSILON) {
6929
 
                                                                float color[3];
6930
 
                                                                copy_v3_v3(tmp, smd->domain->p0);
6931
 
                                                                tmp[0] += smd->domain->dx * x + smd->domain->dx * 0.5;
6932
 
                                                                tmp[1] += smd->domain->dx * y + smd->domain->dx * 0.5;
6933
 
                                                                tmp[2] += smd->domain->dx * z + smd->domain->dx * 0.5;
6934
 
                                                                color[0] = color[1] = color[2] = density[index];
6935
 
                                                                glColor3fv(color);
6936
 
                                                                bglVertex3fv(tmp);
6937
 
                                                        }
6938
 
                                                }
6939
 
                                        }
6940
 
                                }
6941
 
 
6942
 
                                bglEnd();
6943
 
                                glPointSize(1.0);
6944
 
 
6945
 
                                glMultMatrixf(ob->obmat);
6946
 
                                glDisable(GL_BLEND);
6947
 
                                glDepthMask(GL_TRUE);
6948
 
                                if (col) cpack(col);
 
6710
                                BKE_boundbox_init_from_minmax(&bb, sds->p0, sds->p1);
 
6711
                                draw_box(bb.vec);
6949
6712
#endif
6950
6713
                        }
6951
 
                        else if (smd->domain->wt && (smd->domain->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
6952
 
                                smd->domain->tex = NULL;
6953
 
                                GPU_create_smoke(smd, 1);
6954
 
                                draw_volume(ar, smd->domain->tex,
6955
 
                                            smd->domain->p0, smd->domain->p1,
6956
 
                                            smd->domain->res_wt, smd->domain->dx_wt,
6957
 
                                            smd->domain->tex_shadow);
6958
 
                                GPU_free_smoke(smd);
 
6714
 
 
6715
                        /* don't show smoke before simulation starts, this could be made an option in the future */
 
6716
                        if (smd->domain->fluid && CFRA >= smd->domain->point_cache[0]->startframe) {
 
6717
 
 
6718
                                // get view vector
 
6719
                                copy_v3_v3(viewnormal, rv3d->viewinv[2]);
 
6720
                                mul_mat3_m4_v3(ob->imat, viewnormal);
 
6721
                                normalize_v3(viewnormal);
 
6722
 
 
6723
                                /* set dynamic boundaries to draw the volume */
 
6724
                                p0[0] = sds->p0[0] + sds->cell_size[0] * sds->res_min[0] + sds->obj_shift_f[0];
 
6725
                                p0[1] = sds->p0[1] + sds->cell_size[1] * sds->res_min[1] + sds->obj_shift_f[1];
 
6726
                                p0[2] = sds->p0[2] + sds->cell_size[2] * sds->res_min[2] + sds->obj_shift_f[2];
 
6727
                                p1[0] = sds->p0[0] + sds->cell_size[0] * sds->res_max[0] + sds->obj_shift_f[0];
 
6728
                                p1[1] = sds->p0[1] + sds->cell_size[1] * sds->res_max[1] + sds->obj_shift_f[1];
 
6729
                                p1[2] = sds->p0[2] + sds->cell_size[2] * sds->res_max[2] + sds->obj_shift_f[2];
 
6730
 
 
6731
                                /* scale cube to global space to equalize volume slicing on all axises
 
6732
                                 *  (its scaled back before drawing) */
 
6733
                                mul_v3_v3(p0, ob->size);
 
6734
                                mul_v3_v3(p1, ob->size);
 
6735
 
 
6736
                                if (!sds->wt || !(sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
 
6737
                                        smd->domain->tex = NULL;
 
6738
                                        GPU_create_smoke(smd, 0);
 
6739
                                        draw_smoke_volume(sds, ob, sds->tex,
 
6740
                                                          p0, p1,
 
6741
                                                          sds->res, sds->dx, sds->scale * sds->maxres,
 
6742
                                                          viewnormal, sds->tex_shadow, sds->tex_flame);
 
6743
                                        GPU_free_smoke(smd);
 
6744
                                }
 
6745
                                else if (sds->wt && (sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
 
6746
                                        sds->tex = NULL;
 
6747
                                        GPU_create_smoke(smd, 1);
 
6748
                                        draw_smoke_volume(sds, ob, sds->tex,
 
6749
                                                          p0, p1,
 
6750
                                                          sds->res_wt, sds->dx, sds->scale * sds->maxres,
 
6751
                                                          viewnormal, sds->tex_shadow, sds->tex_flame);
 
6752
                                        GPU_free_smoke(smd);
 
6753
                                }
 
6754
 
 
6755
                                /* smoke debug render */
 
6756
#ifdef SMOKE_DEBUG_VELOCITY
 
6757
                                draw_smoke_velocity(smd->domain, ob);
 
6758
#endif
 
6759
#ifdef SMOKE_DEBUG_HEAT
 
6760
                                draw_smoke_heat(smd->domain, ob);
 
6761
#endif
6959
6762
                        }
6960
6763
                }
6961
6764
        }
6967
6770
                        if (con->type == CONSTRAINT_TYPE_RIGIDBODYJOINT) {
6968
6771
                                bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint *)con->data;
6969
6772
                                if (data->flag & CONSTRAINT_DRAW_PIVOT)
6970
 
                                        drawRBpivot(data);
 
6773
                                        draw_rigid_body_pivot(data, dflag, ob_wire_col);
6971
6774
                        }
6972
6775
                }
6973
6776
 
6974
6777
                if (ob->gameflag & OB_BOUNDS) {
6975
 
                        if (ob->boundtype != ob->collision_boundtype || (dtx & OB_BOUNDBOX) == 0) {
 
6778
                        if (ob->boundtype != ob->collision_boundtype || (dtx & OB_DRAWBOUNDOX) == 0) {
 
6779
 
6976
6780
                                setlinestyle(2);
6977
6781
                                draw_bounding_volume(scene, ob, ob->collision_boundtype);
6978
6782
                                setlinestyle(0);
6985
6789
                        if (dtx & OB_AXIS) {
6986
6790
                                drawaxes(1.0f, OB_ARROWS);
6987
6791
                        }
6988
 
                        if (dtx & OB_BOUNDBOX) {
 
6792
                        if (dtx & OB_DRAWBOUNDOX) {
6989
6793
                                draw_bounding_volume(scene, ob, ob->boundtype);
6990
6794
                        }
6991
6795
                        if (dtx & OB_TEXSPACE) {
6992
6796
                                drawtexspace(ob);
6993
6797
                        }
6994
6798
                        if (dtx & OB_DRAWNAME) {
6995
 
                                /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
 
6799
                                /* patch for several 3d cards (IBM mostly) that crash on GL_SELECT with text drawing */
6996
6800
                                /* but, we also don't draw names for sets or duplicators */
6997
 
                                if (flag == 0) {
6998
 
                                        float zero[3] = {0, 0, 0};
6999
 
                                        float curcol[4];
7000
 
                                        unsigned char tcol[4];
7001
 
                                        glGetFloatv(GL_CURRENT_COLOR, curcol);
7002
 
                                        rgb_float_to_uchar(tcol, curcol);
7003
 
                                        tcol[3] = 255;
7004
 
                                        view3d_cached_text_draw_add(zero, ob->id.name + 2, 10, 0, tcol);
 
6801
                                if (dflag == 0) {
 
6802
                                        const float zero[3] = {0, 0, 0};
 
6803
                                        view3d_cached_text_draw_add(zero, ob->id.name + 2, 10, 0, ob_wire_col);
7005
6804
                                }
7006
6805
                        }
7007
6806
                        /*if (dtx & OB_DRAWIMAGE) drawDispListwire(&ob->disp);*/
7008
6807
                        if ((dtx & OB_DRAWWIRE) && dt >= OB_SOLID) {
7009
 
                                drawWireExtra(scene, rv3d, ob);
 
6808
                                if ((dflag & DRAW_CONSTCOLOR) == 0) {
 
6809
                                        draw_wire_extra(scene, rv3d, ob, ob_wire_col);
 
6810
                                }
7010
6811
                        }
7011
6812
                }
7012
6813
        }
7013
6814
 
7014
6815
        if (dt <= OB_SOLID && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
7015
 
                if ((ob->gameflag & OB_DYNAMIC) ||
7016
 
                    ((ob->gameflag & OB_BOUNDS) && (ob->boundtype == OB_BOUND_SPHERE)))
 
6816
                if (((ob->gameflag & OB_DYNAMIC) &&
 
6817
                     !ELEM(ob->collision_boundtype, OB_BOUND_TRIANGLE_MESH, OB_BOUND_CONVEX_HULL)) ||
 
6818
 
 
6819
                    ((ob->gameflag & OB_BOUNDS) &&
 
6820
                     (ob->boundtype == OB_BOUND_SPHERE)))
7017
6821
                {
7018
6822
                        float imat[4][4], vec[3] = {0.0f, 0.0f, 0.0f};
7019
6823
 
7028
6832
        /* return warning, this is cached text draw */
7029
6833
        invert_m4_m4(ob->imat, ob->obmat);
7030
6834
        view3d_cached_text_draw_end(v3d, ar, 1, NULL);
7031
 
 
 
6835
        /* return warning, clear temp flag */
 
6836
        v3d->flag2 &= ~V3D_SHOW_SOLID_MATCAP;
 
6837
        
7032
6838
        glLoadMatrixf(rv3d->viewmat);
7033
6839
 
7034
6840
        if (zbufoff) {
7043
6849
        }
7044
6850
 
7045
6851
        /* object centers, need to be drawn in viewmat space for speed, but OK for picking select */
7046
 
        if (!is_obact || !(ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) {
 
6852
        if (!is_obact || !(ob->mode & OB_MODE_ALL_PAINT)) {
7047
6853
                int do_draw_center = -1; /* defines below are zero or positive... */
7048
6854
 
7049
6855
                if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
7057
6863
                        do_draw_center = DESELECT;
7058
6864
 
7059
6865
                if (do_draw_center != -1) {
7060
 
                        if (flag & DRAW_PICKING) {
 
6866
                        if (dflag & DRAW_PICKING) {
7061
6867
                                /* draw a single point for opengl selection */
7062
6868
                                glBegin(GL_POINTS);
7063
6869
                                glVertex3fv(ob->obmat[3]);
7064
6870
                                glEnd();
7065
6871
                        }
7066
 
                        else if ((flag & DRAW_CONSTCOLOR) == 0) {
 
6872
                        else if ((dflag & DRAW_CONSTCOLOR) == 0) {
7067
6873
                                /* we don't draw centers for duplicators and sets */
7068
6874
                                if (U.obcenter_dia > 0) {
7069
6875
                                        /* check > 0 otherwise grease pencil can draw into the circle select which is annoying. */
7074
6880
        }
7075
6881
 
7076
6882
        /* not for sets, duplicators or picking */
7077
 
        if (flag == 0 && (v3d->flag & V3D_HIDE_HELPLINES) == 0 && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
 
6883
        if (dflag == 0 && (v3d->flag & V3D_HIDE_HELPLINES) == 0 && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
7078
6884
                ListBase *list;
7079
6885
                
7080
6886
                /* draw hook center and offset line */
7102
6908
                        UI_make_axis_color(col1, col2, 'Z');
7103
6909
                        glColor3ubv(col2);
7104
6910
                        
7105
 
                        cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
 
6911
                        cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
7106
6912
                        
7107
6913
                        for (curcon = list->first; curcon; curcon = curcon->next) {
7108
 
                                bConstraintTypeInfo *cti = constraint_get_typeinfo(curcon);
 
6914
                                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(curcon);
7109
6915
                                ListBase targets = {NULL, NULL};
7110
6916
                                bConstraintTarget *ct;
7111
6917
                                
7136
6942
                                                setlinestyle(0);
7137
6943
                                        }
7138
6944
                                }
7139
 
                                else if ((curcon->flag & CONSTRAINT_EXPAND) && (cti) && (cti->get_constraint_targets)) {
 
6945
                                else if ((curcon->flag & CONSTRAINT_EXPAND) && (cti->get_constraint_targets)) {
7140
6946
                                        cti->get_constraint_targets(curcon, &targets);
7141
6947
                                        
7142
6948
                                        for (ct = targets.first; ct; ct = ct->next) {
7143
6949
                                                /* calculate target's matrix */
7144
6950
                                                if (cti->get_target_matrix)
7145
 
                                                        cti->get_target_matrix(curcon, cob, ct, BKE_curframe(scene));
 
6951
                                                        cti->get_target_matrix(curcon, cob, ct, BKE_scene_frame_get(scene));
7146
6952
                                                else
7147
6953
                                                        unit_m4(ct->matrix);
7148
6954
                                                
7159
6965
                                }
7160
6966
                        }
7161
6967
                        
7162
 
                        constraints_clear_evalob(cob);
 
6968
                        BKE_constraints_clear_evalob(cob);
7163
6969
                }
7164
6970
        }
7165
6971
 
7176
6982
        int offset = (intptr_t) data->offset;
7177
6983
 
7178
6984
        if (!(mv->flag & ME_HIDE)) {
7179
 
                WM_set_framebuffer_index_color(offset + index);
 
6985
                WM_framebuffer_index_set(offset + index);
7180
6986
                bglVertex3fv(co);
7181
6987
        }
7182
6988
}
7188
6994
        MVert *mvert = me->mvert;
7189
6995
        data.mvert = mvert;
7190
6996
        data.offset = (void *)(intptr_t) offset;
7191
 
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE) );
 
6997
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
7192
6998
        bglBegin(GL_POINTS);
7193
6999
        dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, &data);
7194
7000
        bglEnd();
7203
7009
        BMVert *eve = EDBM_vert_at_index(ptrs[1], index);
7204
7010
 
7205
7011
        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
7206
 
                WM_set_framebuffer_index_color(offset + index);
 
7012
                WM_framebuffer_index_set(offset + index);
7207
7013
                bglVertex3fv(co);
7208
7014
        }
7209
7015
}
7211
7017
{
7212
7018
        void *ptrs[2] = {(void *)(intptr_t) offset, em};
7213
7019
 
7214
 
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE) );
 
7020
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
7215
7021
        bglBegin(GL_POINTS);
7216
7022
        dm->foreachMappedVert(dm, bbs_mesh_verts__mapFunc, ptrs);
7217
7023
        bglEnd();
7218
7024
        glPointSize(1.0);
7219
 
}               
 
7025
}
7220
7026
 
7221
7027
static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index)
7222
7028
{
7225
7031
        BMEdge *eed = EDBM_edge_at_index(ptrs[1], index);
7226
7032
 
7227
7033
        if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
7228
 
                WM_set_framebuffer_index_color(offset + index);
 
7034
                WM_framebuffer_index_set(offset + index);
7229
7035
                return DM_DRAW_OPTION_NORMAL;
7230
7036
        }
7231
7037
        else {
7236
7042
{
7237
7043
        void *ptrs[2] = {(void *)(intptr_t) offset, em};
7238
7044
        dm->drawMappedEdges(dm, bbs_mesh_wire__setDrawOptions, ptrs);
7239
 
}               
 
7045
}
7240
7046
 
7241
7047
static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int index)
7242
7048
{
7244
7050
        
7245
7051
        if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
7246
7052
                if (((void **)userData)[1]) {
7247
 
                        WM_set_framebuffer_index_color(index + 1);
 
7053
                        WM_framebuffer_index_set(index + 1);
7248
7054
                }
7249
7055
                return DM_DRAW_OPTION_NORMAL;
7250
7056
        }
7258
7064
        BMFace *efa = EDBM_face_at_index(((void **)userData)[0], index);
7259
7065
 
7260
7066
        if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
7261
 
                WM_set_framebuffer_index_color(index + 1);
 
7067
                WM_framebuffer_index_set(index + 1);
7262
7068
 
7263
7069
                bglVertex3fv(cent);
7264
7070
        }
7291
7097
 
7292
7098
static DMDrawOption bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index)
7293
7099
{
7294
 
        WM_set_framebuffer_index_color(index + 1);
 
7100
        WM_framebuffer_index_set(index + 1);
7295
7101
        return DM_DRAW_OPTION_NORMAL;
7296
7102
}
7297
7103
 
7300
7106
        Mesh *me = userData;
7301
7107
 
7302
7108
        if (!(me->mpoly[index].flag & ME_HIDE)) {
7303
 
                WM_set_framebuffer_index_color(index + 1);
 
7109
                WM_framebuffer_index_set(index + 1);
7304
7110
                return DM_DRAW_OPTION_NORMAL;
7305
7111
        }
7306
7112
        else {
7308
7114
        }
7309
7115
}
7310
7116
 
7311
 
// must have called WM_set_framebuffer_index_color beforehand
 
7117
/* must have called WM_framebuffer_index_set beforehand */
7312
7118
static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index)
7313
7119
{
7314
7120
        Mesh *me = userData;
7320
7126
                return DM_DRAW_OPTION_SKIP;
7321
7127
        }
7322
7128
}
7323
 
static void bbs_mesh_solid(Scene *scene, Object *ob)
 
7129
 
 
7130
static void bbs_mesh_solid_verts(Scene *scene, Object *ob)
 
7131
{
 
7132
        Mesh *me = ob->data;
 
7133
        DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
 
7134
        glColor3ub(0, 0, 0);
 
7135
 
 
7136
        dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, GPU_enable_material, NULL, me, 0);
 
7137
 
 
7138
        bbs_obmode_mesh_verts(ob, dm, 1);
 
7139
        bm_vertoffs = me->totvert + 1;
 
7140
        dm->release(dm);
 
7141
}
 
7142
 
 
7143
static void bbs_mesh_solid_faces(Scene *scene, Object *ob)
7324
7144
{
7325
7145
        DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
7326
7146
        Mesh *me = (Mesh *)ob->data;
7327
7147
        
7328
7148
        glColor3ub(0, 0, 0);
7329
7149
 
7330
 
        if ((me->editflag & ME_EDIT_PAINT_MASK))
 
7150
        if ((me->editflag & ME_EDIT_PAINT_FACE_SEL))
7331
7151
                dm->drawMappedFaces(dm, bbs_mesh_solid_hide__setDrawOpts, GPU_enable_material, NULL, me, 0);
7332
7152
        else
7333
7153
                dm->drawMappedFaces(dm, bbs_mesh_solid__setDrawOpts, GPU_enable_material, NULL, me, 0);
7352
7172
 
7353
7173
                                DerivedMesh *dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH);
7354
7174
 
7355
 
                                EDBM_index_arrays_init(em, 1, 1, 1);
 
7175
                                EDBM_index_arrays_ensure(em, BM_VERT | BM_EDGE | BM_FACE);
7356
7176
 
7357
7177
                                bbs_mesh_solid_EM(em, scene, v3d, ob, dm, ts->selectmode & SCE_SELECT_FACE);
7358
7178
                                if (ts->selectmode & SCE_SELECT_FACE)
7362
7182
 
7363
7183
                                bglPolygonOffset(rv3d->dist, 1.0);
7364
7184
 
7365
 
                                // we draw edges always, for loop (select) tools
 
7185
                                /* we draw edges always, for loop (select) tools */
7366
7186
                                bbs_mesh_wire(em, dm, bm_solidoffs);
7367
7187
                                bm_wireoffs = bm_solidoffs + em->bm->totedge;
7368
7188
 
7369
 
                                // we draw verts if vert select mode or if in transform (for snap).
 
7189
                                /* we draw verts if vert select mode or if in transform (for snap). */
7370
7190
                                if ((ts->selectmode & SCE_SELECT_VERTEX) || (G.moving & G_TRANSFORM_EDIT)) {
7371
7191
                                        bbs_mesh_verts(em, dm, bm_wireoffs);
7372
7192
                                        bm_vertoffs = bm_wireoffs + em->bm->totvert;
7378
7198
                                bglPolygonOffset(rv3d->dist, 0.0);
7379
7199
 
7380
7200
                                dm->release(dm);
7381
 
 
7382
 
                                EDBM_index_arrays_free(em);
7383
7201
                        }
7384
7202
                        else {
7385
7203
                                Mesh *me = ob->data;
7386
 
                                if ((me->editflag & ME_EDIT_VERT_SEL) &&
 
7204
                                if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) &&
7387
7205
                                    /* currently vertex select only supports weight paint */
7388
7206
                                    (ob->mode & OB_MODE_WEIGHT_PAINT))
7389
7207
                                {
7390
 
                                        DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
7391
 
                                        glColor3ub(0, 0, 0);
7392
 
 
7393
 
                                        dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, GPU_enable_material, NULL, me, 0);
7394
 
 
7395
 
 
7396
 
                                        bbs_obmode_mesh_verts(ob, dm, 1);
7397
 
                                        bm_vertoffs = me->totvert + 1;
7398
 
                                        dm->release(dm);
 
7208
                                        bbs_mesh_solid_verts(scene, ob);
7399
7209
                                }
7400
7210
                                else {
7401
 
                                        bbs_mesh_solid(scene, ob);
 
7211
                                        bbs_mesh_solid_faces(scene, ob);
7402
7212
                                }
7403
7213
                        }
7404
7214
                        break;
7415
7225
/*               assumes all matrices/etc set OK */
7416
7226
 
7417
7227
/* helper function for drawing object instances - meshes */
7418
 
static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, 
7419
 
                                      Object *ob, int dt, int outline)
 
7228
static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d,
 
7229
                                      Object *ob, const short dt, int outline)
7420
7230
{
7421
7231
        Mesh *me = ob->data;
7422
7232
        DerivedMesh *dm = NULL, *edm = NULL;
7464
7274
        if (dm) dm->release(dm);
7465
7275
}
7466
7276
 
7467
 
void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int outline)
 
7277
void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, const char dt, int outline)
7468
7278
{
7469
7279
        if (ob == NULL)
7470
7280
                return;
7475
7285
                        break;
7476
7286
                case OB_EMPTY:
7477
7287
                        if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
7478
 
                                draw_empty_image(ob);
 
7288
                                /* CONSTCOLOR == no wire outline */
 
7289
                                draw_empty_image(ob, DRAW_CONSTCOLOR, NULL);
7479
7290
                        }
7480
7291
                        else {
7481
7292
                                drawaxes(ob->empty_drawsize, ob->empty_drawtype);