4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
33 #include "DNA_action_types.h"
34 #include "DNA_armature_types.h"
35 #include "DNA_camera_types.h"
36 #include "DNA_customdata_types.h"
37 #include "DNA_group_types.h"
38 #include "DNA_key_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_scene_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_userdef_types.h"
44 #include "DNA_view3d_types.h"
45 #include "DNA_world_types.h"
47 #include "MEM_guardedalloc.h"
49 #include "BLI_blenlib.h"
50 #include "BLI_arithb.h"
54 #include "BKE_context.h"
55 #include "BKE_customdata.h"
56 #include "BKE_image.h"
59 #include "BKE_object.h"
60 #include "BKE_global.h"
61 #include "BKE_scene.h"
62 #include "BKE_screen.h"
63 #include "BKE_utildefines.h"
65 #include "RE_pipeline.h" // make_stars
67 #include "IMB_imbuf_types.h"
68 #include "IMB_imbuf.h"
71 #include "BIF_glutil.h"
76 #include "ED_armature.h"
77 #include "ED_keyframing.h"
79 #include "ED_screen.h"
80 #include "ED_space_api.h"
84 #include "UI_interface.h"
85 #include "UI_interface_icons.h"
86 #include "UI_resources.h"
87 #include "UI_view2d.h"
90 #include "GPU_material.h"
92 #include "view3d_intern.h" // own include
96 static void star_stuff_init_func(void)
102 static void star_stuff_vertex_func(float* i)
106 static void star_stuff_term_func(void)
111 void circf(float x, float y, float rad)
113 GLUquadricObj *qobj = gluNewQuadric();
115 gluQuadricDrawStyle(qobj, GLU_FILL);
119 glTranslatef(x, y, 0.);
121 gluDisk( qobj, 0.0, rad, 32, 1);
125 gluDeleteQuadric(qobj);
128 void circ(float x, float y, float rad)
130 GLUquadricObj *qobj = gluNewQuadric();
132 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
136 glTranslatef(x, y, 0.);
138 gluDisk( qobj, 0.0, rad, 32, 1);
142 gluDeleteQuadric(qobj);
146 /* ********* custom clipping *********** */
148 static void view3d_draw_clipping(View3D *v3d)
150 BoundBox *bb= v3d->clipbb;
152 UI_ThemeColorShade(TH_BACK, -8);
156 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[3]);
157 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[1]);
158 glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[5]);
159 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[3]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[6]);
160 glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[2]);
161 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[3]);
166 void view3d_set_clipping(View3D *v3d)
172 QUATCOPY(plane, v3d->clip[a]);
173 glClipPlane(GL_CLIP_PLANE0+a, plane);
174 glEnable(GL_CLIP_PLANE0+a);
178 void view3d_clr_clipping(void)
183 glDisable(GL_CLIP_PLANE0+a);
187 int view3d_test_clipping(View3D *v3d, float *vec)
189 /* vec in world coordinates, returns 1 if clipped */
194 if(0.0f < v3d->clip[0][3] + INPR(view, v3d->clip[0]))
195 if(0.0f < v3d->clip[1][3] + INPR(view, v3d->clip[1]))
196 if(0.0f < v3d->clip[2][3] + INPR(view, v3d->clip[2]))
197 if(0.0f < v3d->clip[3][3] + INPR(view, v3d->clip[3]))
203 /* ********* end custom clipping *********** */
206 static void drawgrid_draw(ARegion *ar, float wx, float wy, float x, float y, float dx)
215 while(fx< ar->winx) {
216 fdrawline(fx, 0.0, fx, (float)ar->winy);
224 while(fy< ar->winy) {
225 fdrawline(0.0, fy, (float)ar->winx, fy);
231 // not intern, called in editobject for constraint axis too
232 void make_axis_color(char *col, char *col2, char axis)
235 col2[0]= col[0]>219?255:col[0]+36;
236 col2[1]= col[1]<26?0:col[1]-26;
237 col2[2]= col[2]<26?0:col[2]-26;
240 col2[0]= col[0]<46?0:col[0]-36;
241 col2[1]= col[1]>189?255:col[1]+66;
242 col2[2]= col[2]<46?0:col[2]-36;
245 col2[0]= col[0]<26?0:col[0]-26;
246 col2[1]= col[1]<26?0:col[1]-26;
247 col2[2]= col[2]>209?255:col[2]+46;
252 static void drawgrid(ARegion *ar, View3D *v3d)
254 /* extern short bgpicmode; */
255 float wx, wy, x, y, fw, fx, fy, dx;
257 char col[3], col2[3];
258 short sublines = v3d->gridsubdiv;
260 vec4[0]=vec4[1]=vec4[2]=0.0;
262 Mat4MulVec4fl(v3d->persmat, vec4);
267 wx= (ar->winx/2.0); /* because of rounding errors, grid at wrong location */
273 vec4[0]=vec4[1]=v3d->grid;
276 Mat4MulVec4fl(v3d->persmat, vec4);
281 dx= fabs(x-(wx)*fx/fw);
282 if(dx==0) dx= fabs(y-(wy)*fy/fw);
284 glDepthMask(0); // disable write in zbuffer
287 UI_ThemeColor(TH_GRID);
290 v3d->gridview*= sublines;
294 v3d->gridview*= sublines;
298 v3d->gridview*= sublines;
302 UI_ThemeColor(TH_GRID);
303 drawgrid_draw(ar, wx, wy, x, y, dx);
306 else { // start blending out
307 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
308 drawgrid_draw(ar, wx, wy, x, y, dx);
310 UI_ThemeColor(TH_GRID);
311 drawgrid_draw(ar, wx, wy, x, y, sublines*dx);
314 else { // start blending out (6 < dx < 60)
315 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
316 drawgrid_draw(ar, wx, wy, x, y, dx);
318 UI_ThemeColor(TH_GRID);
319 drawgrid_draw(ar, wx, wy, x, y, sublines*dx);
323 if(dx>60.0) { // start blending in
324 v3d->gridview/= sublines;
326 if(dx>60.0) { // start blending in
327 v3d->gridview/= sublines;
330 UI_ThemeColor(TH_GRID);
331 drawgrid_draw(ar, wx, wy, x, y, dx);
334 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
335 drawgrid_draw(ar, wx, wy, x, y, dx);
336 UI_ThemeColor(TH_GRID);
337 drawgrid_draw(ar, wx, wy, x, y, dx*sublines);
341 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
342 drawgrid_draw(ar, wx, wy, x, y, dx);
343 UI_ThemeColor(TH_GRID);
344 drawgrid_draw(ar, wx, wy, x, y, dx*sublines);
348 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
349 drawgrid_draw(ar, wx, wy, x, y, dx);
350 UI_ThemeColor(TH_GRID);
351 drawgrid_draw(ar, wx, wy, x, y, dx*sublines);
357 UI_GetThemeColor3ubv(TH_GRID, col);
362 if(v3d->view==3) make_axis_color(col, col2, 'y');
363 else make_axis_color(col, col2, 'x');
364 glColor3ubv((GLubyte *)col2);
366 fdrawline(0.0, y, (float)ar->winx, y);
368 if(v3d->view==7) make_axis_color(col, col2, 'y');
369 else make_axis_color(col, col2, 'z');
370 glColor3ubv((GLubyte *)col2);
372 fdrawline(x, 0.0, x, (float)ar->winy);
374 glDepthMask(1); // enable write in zbuffer
378 static void drawfloor(Scene *scene, View3D *v3d)
381 int a, gridlines, emphasise;
382 char col[3], col2[3];
387 if(v3d->gridlines<3) return;
389 if(v3d->zbuf && scene->obedit) glDepthMask(0); // for zbuffer-select
391 gridlines= v3d->gridlines/2;
392 grid= gridlines*v3d->grid;
394 UI_GetThemeColor3ubv(TH_GRID, col);
395 UI_GetThemeColor3ubv(TH_BACK, col2);
397 /* emphasise division lines lighter instead of darker, if background is darker than grid */
398 if ( ((col[0]+col[1]+col[2])/3+10) > (col2[0]+col2[1]+col2[2])/3 )
403 /* draw the Y axis and/or grid lines */
404 for(a= -gridlines;a<=gridlines;a++) {
406 /* check for the 'show Y axis' preference */
407 if (v3d->gridflag & V3D_SHOW_Y) {
408 make_axis_color(col, col2, 'y');
409 glColor3ubv((GLubyte *)col2);
412 } else if (v3d->gridflag & V3D_SHOW_FLOOR) {
413 UI_ThemeColorShade(TH_GRID, emphasise);
418 /* check for the 'show grid floor' preference */
419 if (v3d->gridflag & V3D_SHOW_FLOOR) {
421 UI_ThemeColorShade(TH_GRID, emphasise);
423 else UI_ThemeColorShade(TH_GRID, 10);
432 glBegin(GL_LINE_STRIP);
433 vert[0]= a*v3d->grid;
442 /* draw the X axis and/or grid lines */
443 for(a= -gridlines;a<=gridlines;a++) {
445 /* check for the 'show X axis' preference */
446 if (v3d->gridflag & V3D_SHOW_X) {
447 make_axis_color(col, col2, 'x');
448 glColor3ubv((GLubyte *)col2);
451 } else if (v3d->gridflag & V3D_SHOW_FLOOR) {
452 UI_ThemeColorShade(TH_GRID, emphasise);
457 /* check for the 'show grid floor' preference */
458 if (v3d->gridflag & V3D_SHOW_FLOOR) {
460 UI_ThemeColorShade(TH_GRID, emphasise);
462 else UI_ThemeColorShade(TH_GRID, 10);
471 glBegin(GL_LINE_STRIP);
472 vert[1]= a*v3d->grid;
481 /* draw the Z axis line */
482 /* check for the 'show Z axis' preference */
483 if (v3d->gridflag & V3D_SHOW_Z) {
484 make_axis_color(col, col2, 'z');
485 glColor3ubv((GLubyte *)col2);
487 glBegin(GL_LINE_STRIP);
497 if(v3d->zbuf && scene->obedit) glDepthMask(1);
501 static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
506 /* we dont want the clipping for cursor */
509 project_short(ar, v3d, give_cursor(scene, v3d), co);
518 circ((float)mx, (float)my, 10.0);
521 circ((float)mx, (float)my, 10.0);
525 sdrawline(mx-20, my, mx-5, my);
526 sdrawline(mx+5, my, mx+20, my);
527 sdrawline(mx, my-20, mx, my-5);
528 sdrawline(mx, my+5, mx, my+20);
532 /* Draw a live substitute of the view icon, which is always shown */
533 static void draw_view_axis(View3D *v3d)
535 const float k = U.rvisize; /* axis size */
536 const float toll = 0.5; /* used to see when view is quasi-orthogonal */
537 const float start = k + 1.0; /* axis center in screen coordinates, x=y */
538 float ydisp = 0.0; /* vertical displacement to allow obj info text */
540 /* rvibright ranges approx. from original axis icon color to gizmo color */
541 float bright = U.rvibright / 15.0f;
543 unsigned char col[3];
544 unsigned char gridcol[3];
551 /* thickness of lines is proportional to k */
552 /* (log(k)-1) gives a more suitable thickness, but fps decreased by about 3 fps */
554 //glLineWidth(log(k)-1); // a bit slow
556 UI_GetThemeColor3ubv(TH_GRID, (char *)gridcol);
561 QuatMulVecf(v3d->viewquat, vec);
563 make_axis_color((char *)gridcol, (char *)col, 'x');
564 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
565 s = s<0.5 ? s+0.5 : 1.0;
567 v = (v<1.0-(bright) ? v+bright : 1.0);
568 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
573 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
574 if (fabs(dx) > toll || fabs(dy) > toll) {
575 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
576 BMF_DrawString(G.fonts, "x");
582 QuatMulVecf(v3d->viewquat, vec);
584 make_axis_color((char *)gridcol, (char *)col, 'y');
585 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
586 s = s<0.5 ? s+0.5 : 1.0;
588 v = (v<1.0-(bright) ? v+bright : 1.0);
589 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
594 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
595 if (fabs(dx) > toll || fabs(dy) > toll) {
596 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
597 BMF_DrawString(G.fonts, "y");
603 QuatMulVecf(v3d->viewquat, vec);
605 make_axis_color((char *)gridcol, (char *)col, 'z');
606 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
607 s = s<0.5 ? s+0.5 : 1.0;
609 v = (v<1.0-(bright) ? v+bright : 1.0);
610 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
615 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
616 if (fabs(dx) > toll || fabs(dy) > toll) {
617 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
618 BMF_DrawString(G.fonts, "z");
621 /* restore line-width */
626 static void draw_view_icon(View3D *v3d)
630 if(v3d->view==7) icon= ICON_AXIS_TOP;
631 else if(v3d->view==1) icon= ICON_AXIS_FRONT;
632 else if(v3d->view==3) icon= ICON_AXIS_SIDE;
636 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
638 UI_icon_draw(5.0, 5.0, icon);
643 char *view3d_get_name(View3D *v3d)
649 if (v3d->persp == V3D_ORTHO)
650 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Ortho" : "Front Ortho";
652 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Persp" : "Front Persp";
655 if (v3d->persp == V3D_ORTHO)
656 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Ortho" : "Right Ortho";
658 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Persp" : "Right Persp";
661 if (v3d->persp == V3D_ORTHO)
662 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Ortho" : "Top Ortho";
664 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Persp" : "Top Persp";
667 if (v3d->persp==V3D_CAMOB) {
668 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
670 cam = v3d->camera->data;
671 name = (cam->type != CAM_ORTHO) ? "Camera Persp" : "Camera Ortho";
673 name = "Object as Camera";
676 name = (v3d->persp == V3D_ORTHO) ? "User Ortho" : "User Persp";
684 static void draw_viewport_name(ARegion *ar, View3D *v3d)
686 char *name = view3d_get_name(v3d);
687 char *printable = NULL;
689 if (v3d->localview) {
690 printable = malloc(strlen(name) + strlen(" (Local)_")); /* '_' gives space for '\0' */
691 strcpy(printable, name);
692 strcat(printable, " (Local)");
698 UI_ThemeColor(TH_TEXT_HI);
699 glRasterPos2i(10, ar->winy-20);
700 BMF_DrawString(G.fonts, printable);
703 if (v3d->localview) {
709 static char *get_cfra_marker_name(Scene *scene)
711 ListBase *markers= &scene->markers;
714 /* search through markers for match */
715 for (m1=markers->first, m2=markers->last; m1 && m2; m1=m1->next, m2=m2->prev) {
729 /* draw info beside axes in bottom left-corner:
730 * framenum, object name, bone name (if available), marker name (if available)
732 static void draw_selected_name(Scene *scene, Object *ob, View3D *v3d)
734 char info[256], *markern;
737 /* get name of marker on current frame (if available) */
738 markern= get_cfra_marker_name(scene);
740 /* check if there is an object */
742 /* name(s) to display depends on type of object */
743 if(ob->type==OB_ARMATURE) {
744 bArmature *arm= ob->data;
747 /* show name of active bone too (if possible) */
750 for (ebo=arm->edbo->first; ebo; ebo=ebo->next){
751 if ((ebo->flag & BONE_ACTIVE) && (ebo->layer & arm->layer)) {
757 else if(ob->pose && (ob->flag & OB_POSEMODE)) {
759 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
760 if((pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) {
767 sprintf(info, "(%d) %s %s <%s>", CFRA, ob->id.name+2, name, markern);
769 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, name);
771 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
773 else if(ELEM3(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
778 /* try to display active shapekey too */
780 key = ob_get_key(ob);
782 kb = BLI_findlink(&key->block, ob->shapenr-1);
784 sprintf(shapes, ": %s ", kb->name);
785 if(ob->shapeflag == OB_SHAPE_LOCK){
786 sprintf(shapes, "%s (Pinned)",shapes);
792 sprintf(info, "(%d) %s %s <%s>", CFRA, ob->id.name+2, shapes, markern);
794 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, shapes);
797 /* standard object */
799 sprintf(info, "(%d) %s <%s>", CFRA, ob->id.name+2, markern);
801 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
804 /* colour depends on whether there is a keyframe */
805 if (id_frame_has_keyframe((ID *)ob, /*frame_to_float(scene, CFRA)*/(float)(CFRA), v3d->keyflags))
806 UI_ThemeColor(TH_VERTEX_SELECT);
808 UI_ThemeColor(TH_TEXT_HI);
813 sprintf(info, "(%d) <%s>", CFRA, markern);
815 sprintf(info, "(%d)", CFRA);
817 /* colour is always white */
818 UI_ThemeColor(TH_TEXT_HI);
821 if (U.uiflag & USER_SHOW_ROTVIEWICON)
822 offset = 14 + (U.rvisize * 2);
824 glRasterPos2i(offset, 10);
825 BMF_DrawString(G.fonts, info);
828 static void view3d_get_viewborder_size(Scene *scene, ARegion *ar, float size_r[2])
830 float winmax= MAX2(ar->winx, ar->winy);
831 float aspect= (float) (scene->r.xsch*scene->r.xasp)/(scene->r.ysch*scene->r.yasp);
835 size_r[1]= winmax/aspect;
837 size_r[0]= winmax*aspect;
842 void calc_viewborder(Scene *scene, ARegion *ar, View3D *v3d, rctf *viewborder_r)
844 float zoomfac, size[2];
845 float dx= 0.0f, dy= 0.0f;
847 view3d_get_viewborder_size(scene, ar, size);
849 /* magic zoom calculation, no idea what
850 * it signifies, if you find out, tell me! -zr
852 /* simple, its magic dude!
853 * well, to be honest, this gives a natural feeling zooming
854 * with multiple keypad presses (ton)
857 zoomfac= (M_SQRT2 + v3d->camzoom/50.0);
858 zoomfac= (zoomfac*zoomfac)*0.25;
860 size[0]= size[0]*zoomfac;
861 size[1]= size[1]*zoomfac;
863 /* center in window */
864 viewborder_r->xmin= 0.5*ar->winx - 0.5*size[0];
865 viewborder_r->ymin= 0.5*ar->winy - 0.5*size[1];
866 viewborder_r->xmax= viewborder_r->xmin + size[0];
867 viewborder_r->ymax= viewborder_r->ymin + size[1];
869 dx= ar->winx*v3d->camdx*zoomfac*2.0f;
870 dy= ar->winy*v3d->camdy*zoomfac*2.0f;
873 viewborder_r->xmin-= dx;
874 viewborder_r->ymin-= dy;
875 viewborder_r->xmax-= dx;
876 viewborder_r->ymax-= dy;
878 if(v3d->camera && v3d->camera->type==OB_CAMERA) {
879 Camera *cam= v3d->camera->data;
880 float w = viewborder_r->xmax - viewborder_r->xmin;
881 float h = viewborder_r->ymax - viewborder_r->ymin;
882 float side = MAX2(w, h);
884 viewborder_r->xmin+= cam->shiftx*side;
885 viewborder_r->xmax+= cam->shiftx*side;
886 viewborder_r->ymin+= cam->shifty*side;
887 viewborder_r->ymax+= cam->shifty*side;
891 void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
894 int im_width= (scene->r.size*scene->r.xsch)/100;
896 view3d_get_viewborder_size(scene, ar, size);
898 v3d->camzoom= (sqrt(4.0*im_width/size[0]) - M_SQRT2)*50.0;
899 v3d->camzoom= CLAMPIS(v3d->camzoom, -30, 300);
903 static void drawviewborder_flymode(ARegion *ar)
905 /* draws 4 edge brackets that frame the safe area where the
906 mouse can move during fly mode without spinning the view */
907 float x1, x2, y1, y2;
909 x1= 0.45*(float)ar->winx;
910 y1= 0.45*(float)ar->winy;
911 x2= 0.55*(float)ar->winx;
912 y2= 0.55*(float)ar->winy;
948 static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
950 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad); // interface_panel.c
952 float x1, x2, y1, y2;
953 float x3, y3, x4, y4;
957 if(v3d->camera==NULL)
959 if(v3d->camera->type==OB_CAMERA)
960 ca = v3d->camera->data;
962 calc_viewborder(scene, ar, v3d, &viewborder);
968 /* passepartout, specified in camera edit buttons */
969 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001) {
970 if (ca->passepartalpha == 1.0) {
973 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
975 glColor4f(0, 0, 0, ca->passepartalpha);
978 glRectf(0.0, (float)ar->winy, x1, 0.0);
979 if (x2 < (float)ar->winx)
980 glRectf(x2, (float)ar->winy, (float)ar->winx, 0.0);
981 if (y2 < (float)ar->winy)
982 glRectf(x1, (float)ar->winy, x2, y2);
984 glRectf(x1, y1, x2, 0.0);
990 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
993 UI_ThemeColor(TH_BACK);
994 glRectf(x1, y1, x2, y2);
997 UI_ThemeColor(TH_WIRE);
998 glRectf(x1, y1, x2, y2);
1000 /* camera name - draw in highlighted text color */
1001 if (ca && (ca->flag & CAM_SHOWNAME)) {
1002 UI_ThemeColor(TH_TEXT_HI);
1003 glRasterPos2f(x1, y1-15);
1005 BMF_DrawString(G.font, v3d->camera->id.name+2);
1006 UI_ThemeColor(TH_WIRE);
1011 if(scene->r.mode & R_BORDER) {
1014 x3= x1+ scene->r.border.xmin*(x2-x1);
1015 y3= y1+ scene->r.border.ymin*(y2-y1);
1016 x4= x1+ scene->r.border.xmax*(x2-x1);
1017 y4= y1+ scene->r.border.ymax*(y2-y1);
1020 glRectf(x3, y3, x4, y4);
1024 if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
1035 UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
1038 gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
1042 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1046 /* *********************** backdraw for selection *************** */
1048 void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d)
1052 /*for 2.43 release, don't use glext and just define the constant.
1053 this to avoid possibly breaking platforms before release.*/
1054 #ifndef GL_MULTISAMPLE_ARB
1055 #define GL_MULTISAMPLE_ARB 0x809D
1058 #ifdef GL_MULTISAMPLE_ARB
1062 if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT || G.f & G_TEXTUREPAINT);
1063 else if(scene->obedit && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT));
1065 v3d->flag &= ~V3D_NEEDBACKBUFDRAW;
1069 if( !(v3d->flag & V3D_NEEDBACKBUFDRAW) ) return;
1073 // addafterqueue(ar->win, BACKBUFDRAW, 1);
1078 /* Disable FSAA for backbuffer selection.
1080 Only works if GL_MULTISAMPLE_ARB is defined by the header
1081 file, which is should be for every OS that supports FSAA.*/
1083 #ifdef GL_MULTISAMPLE_ARB
1084 m = glIsEnabled(GL_MULTISAMPLE_ARB);
1085 if (m) glDisable(GL_MULTISAMPLE_ARB);
1088 if(v3d->drawtype > OB_WIRE) v3d->zbuf= TRUE;
1090 glDisable(GL_DITHER);
1092 glClearColor(0.0, 0.0, 0.0, 0.0);
1094 glEnable(GL_DEPTH_TEST);
1095 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1098 glClear(GL_COLOR_BUFFER_BIT);
1099 glDisable(GL_DEPTH_TEST);
1102 if(v3d->flag & V3D_CLIPPING)
1103 view3d_set_clipping(v3d);
1105 G.f |= G_BACKBUFSEL;
1107 base= (scene->basact);
1108 if(base && (base->lay & v3d->lay)) {
1109 draw_object_backbufsel(scene, v3d, base->object);
1112 v3d->flag &= ~V3D_NEEDBACKBUFDRAW;
1114 G.f &= ~G_BACKBUFSEL;
1116 glDisable(GL_DEPTH_TEST);
1117 glEnable(GL_DITHER);
1119 if(v3d->flag & V3D_CLIPPING)
1120 view3d_clr_clipping();
1122 #ifdef GL_MULTISAMPLE_ARB
1123 if (m) glEnable(GL_MULTISAMPLE_ARB);
1126 /* it is important to end a view in a transform compatible with buttons */
1127 // persp(PERSP_WIN); // set ortho
1131 void view3d_validate_backbuf(ViewContext *vc)
1133 if(vc->v3d->flag & V3D_NEEDBACKBUFDRAW)
1134 backdrawview3d(vc->scene, vc->ar, vc->v3d);
1137 /* samples a single pixel (copied from vpaint) */
1138 unsigned int view3d_sample_backbuf(ViewContext *vc, int x, int y)
1142 if(x >= vc->ar->winx || y >= vc->ar->winy) return 0;
1143 x+= vc->ar->winrct.xmin;
1144 y+= vc->ar->winrct.ymin;
1146 view3d_validate_backbuf(vc);
1148 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
1149 glReadBuffer(GL_BACK);
1151 if(ENDIAN_ORDER==B_ENDIAN) SWITCH_INT(col);
1153 return WM_framebuffer_to_index(col);
1156 /* reads full rect, converts indices */
1157 ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax, short ymax)
1159 unsigned int *dr, *rd;
1160 struct ImBuf *ibuf, *ibuf1;
1162 short xminc, yminc, xmaxc, ymaxc, xs, ys;
1165 if(xmin<0) xminc= 0; else xminc= xmin;
1166 if(xmax >= vc->ar->winx) xmaxc= vc->ar->winx-1; else xmaxc= xmax;
1167 if(xminc > xmaxc) return NULL;
1169 if(ymin<0) yminc= 0; else yminc= ymin;
1170 if(ymax >= vc->ar->winy) ymaxc= vc->ar->winy-1; else ymaxc= ymax;
1171 if(yminc > ymaxc) return NULL;
1173 ibuf= IMB_allocImBuf((xmaxc-xminc+1), (ymaxc-yminc+1), 32, IB_rect,0);
1175 view3d_validate_backbuf(vc);
1177 glReadPixels(vc->ar->winrct.xmin+xminc, vc->ar->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1178 glReadBuffer(GL_BACK);
1180 if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
1182 a= (xmaxc-xminc+1)*(ymaxc-yminc+1);
1185 if(*dr) *dr= WM_framebuffer_to_index(*dr);
1189 /* put clipped result back, if needed */
1190 if(xminc==xmin && xmaxc==xmax && yminc==ymin && ymaxc==ymax)
1193 ibuf1= IMB_allocImBuf( (xmax-xmin+1),(ymax-ymin+1),32,IB_rect,0);
1197 for(ys= ymin; ys<=ymax; ys++) {
1198 for(xs= xmin; xs<=xmax; xs++, dr++) {
1199 if( xs>=xminc && xs<=xmaxc && ys>=yminc && ys<=ymaxc) {
1205 IMB_freeImBuf(ibuf);
1209 /* smart function to sample a rect spiralling outside, nice for backbuf selection */
1210 unsigned int view3d_sample_backbuf_rect(ViewContext *vc, short mval[2], int size,
1211 unsigned int min, unsigned int max, int *dist, short strict,
1212 void *handle, unsigned int (*indextest)(void *handle, unsigned int index))
1215 unsigned int *bufmin, *bufmax, *tbuf;
1217 int a, b, rc, nr, amount, dirvec[4][2];
1219 unsigned int index = 0;
1224 minx = mval[0]-(amount+1);
1225 miny = mval[1]-(amount+1);
1226 buf = view3d_read_backbuf(vc, minx, miny, minx+size-1, miny+size-1);
1231 dirvec[0][0]= 1; dirvec[0][1]= 0;
1232 dirvec[1][0]= 0; dirvec[1][1]= -size;
1233 dirvec[2][0]= -1; dirvec[2][1]= 0;
1234 dirvec[3][0]= 0; dirvec[3][1]= size;
1238 bufmax = buf->rect + size*size;
1239 tbuf+= amount*size+ amount;
1241 for(nr=1; nr<=size; nr++) {
1243 for(a=0; a<2; a++) {
1244 for(b=0; b<nr; b++, distance++) {
1245 if (*tbuf && *tbuf>=min && *tbuf<max) { //we got a hit
1247 indexok = indextest(handle, *tbuf - min+1);
1249 *dist= (short) sqrt( (float)distance );
1250 index = *tbuf - min+1;
1255 *dist= (short) sqrt( (float)distance ); // XXX, this distance is wrong -
1256 index = *tbuf - min+1; // messy yah, but indices start at 1
1261 tbuf+= (dirvec[rc][0]+dirvec[rc][1]);
1263 if(tbuf<bufmin || tbuf>=bufmax) {
1278 /* ************************************************************* */
1280 static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
1285 float vec[4], fac, asp, zoomx, zoomy;
1286 float x1, y1, x2, y2, cx, cy;
1289 if(bgpic==NULL) return;
1294 ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser);
1295 if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL) )
1297 if(ibuf->channels!=4)
1299 if(ibuf->rect==NULL)
1300 IMB_rect_from_float(ibuf);
1305 calc_viewborder(scene, ar, v3d, &vb);
1315 /* calc window coord */
1316 initgrabz(v3d, 0.0, 0.0, 0.0);
1317 window_to_3d(ar, v3d, vec, 1, 0);
1318 fac= MAX3( fabs(vec[0]), fabs(vec[1]), fabs(vec[1]) );
1321 asp= ( (float)ibuf->y)/(float)ibuf->x;
1323 vec[0] = vec[1] = vec[2] = 0.0;
1324 view3d_project_float(ar, vec, sco, v3d->persmat);
1328 x1= cx+ fac*(bgpic->xof-bgpic->size);
1329 y1= cy+ asp*fac*(bgpic->yof-bgpic->size);
1330 x2= cx+ fac*(bgpic->xof+bgpic->size);
1331 y2= cy+ asp*fac*(bgpic->yof+bgpic->size);
1334 /* complete clip? */
1338 if(x1 > ar->winx ) return;
1339 if(y1 > ar->winy ) return;
1341 zoomx= (x2-x1)/ibuf->x;
1342 zoomy= (y2-y1)/ibuf->y;
1344 /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */
1345 if(zoomx < 1.0f || zoomy < 1.0f) {
1346 float tzoom= MIN2(zoomx, zoomy);
1349 if(ibuf->mipmap[0]==NULL)
1350 IMB_makemipmap(ibuf, 0);
1352 while(tzoom < 1.0f && mip<8 && ibuf->mipmap[mip]) {
1359 ibuf= ibuf->mipmap[mip-1];
1362 if(v3d->zbuf) glDisable(GL_DEPTH_TEST);
1364 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1366 glMatrixMode(GL_PROJECTION);
1368 glMatrixMode(GL_MODELVIEW);
1371 glaDefine2DArea(&ar->winrct);
1375 glPixelZoom(zoomx, zoomy);
1376 glColor4f(1.0, 1.0, 1.0, 1.0-bgpic->blend);
1377 glaDrawPixelsTex(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
1379 glPixelZoom(1.0, 1.0);
1380 glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
1382 glMatrixMode(GL_PROJECTION);
1384 glMatrixMode(GL_MODELVIEW);
1387 glDisable(GL_BLEND);
1388 if(v3d->zbuf) glEnable(GL_DEPTH_TEST);
1391 /* ****************** View3d afterdraw *************** */
1393 typedef struct View3DAfter {
1394 struct View3DAfter *next, *prev;
1399 /* temp storage of Objects that need to be drawn as last */
1400 void add_view3d_after(View3D *v3d, Base *base, int type, int flag)
1402 View3DAfter *v3da= MEM_callocN(sizeof(View3DAfter), "View 3d after");
1404 BLI_addtail(&v3d->afterdraw, v3da);
1410 /* clears zbuffer and draws it over */
1411 static void view3d_draw_xray(Scene *scene, ARegion *ar, View3D *v3d, int clear)
1413 View3DAfter *v3da, *next;
1416 for(v3da= v3d->afterdraw.first; v3da; v3da= v3da->next)
1417 if(v3da->type==V3D_XRAY) doit= 1;
1420 if(clear && v3d->zbuf) glClear(GL_DEPTH_BUFFER_BIT);
1423 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
1425 if(v3da->type==V3D_XRAY) {
1426 draw_object(scene, ar, v3d, v3da->base, v3da->flag);
1427 BLI_remlink(&v3d->afterdraw, v3da);
1435 /* disables write in zbuffer and draws it over */
1436 static void view3d_draw_transp(Scene *scene, ARegion *ar, View3D *v3d)
1438 View3DAfter *v3da, *next;
1443 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
1445 if(v3da->type==V3D_TRANSP) {
1446 draw_object(scene, ar, v3d, v3da->base, v3da->flag);
1447 BLI_remlink(&v3d->afterdraw, v3da);
1457 /* *********************** */
1460 In most cases call draw_dupli_objects,
1461 draw_dupli_objects_color was added because when drawing set dupli's
1462 we need to force the color
1464 static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int color)
1471 short transflag, use_displist= -1; /* -1 is initialize */
1474 if (base->object->restrictflag & OB_RESTRICT_VIEW) return;
1476 tbase.flag= OB_FROMDUPLI|base->flag;
1477 lb= object_duplilist(scene, base->object);
1479 for(dob= lb->first; dob; dob= dob->next) {
1482 tbase.object= dob->ob;
1484 /* extra service: draw the duplicator in drawtype of parent */
1485 /* MIN2 for the drawtype to allow bounding box objects in groups for lods */
1486 dt= tbase.object->dt; tbase.object->dt= MIN2(tbase.object->dt, base->object->dt);
1487 dtx= tbase.object->dtx; tbase.object->dtx= base->object->dtx;
1489 /* negative scale flag has to propagate */
1490 transflag= tbase.object->transflag;
1491 if(base->object->transflag & OB_NEG_SCALE)
1492 tbase.object->transflag ^= OB_NEG_SCALE;
1494 UI_ThemeColorBlend(color, TH_BACK, 0.5);
1496 /* generate displist, test for new object */
1497 if(use_displist==1 && dob->prev && dob->prev->ob!=dob->ob) {
1499 glDeleteLists(displist, 1);
1501 /* generate displist */
1502 if(use_displist == -1) {
1504 /* lamp drawing messes with matrices, could be handled smarter... but this works */
1505 if(dob->ob->type==OB_LAMP || dob->type==OB_DUPLIGROUP)
1508 /* disable boundbox check for list creation */
1509 object_boundbox_flag(dob->ob, OB_BB_DISABLED, 1);
1510 /* need this for next part of code */
1511 bb= object_get_boundbox(dob->ob);
1513 Mat4One(dob->ob->obmat); /* obmat gets restored */
1515 displist= glGenLists(1);
1516 glNewList(displist, GL_COMPILE);
1517 draw_object(scene, ar, v3d, &tbase, DRAW_CONSTCOLOR);
1521 object_boundbox_flag(dob->ob, OB_BB_DISABLED, 0);
1525 wmMultMatrix(dob->mat);
1526 if(boundbox_clip(v3d, dob->mat, bb))
1527 glCallList(displist);
1528 wmLoadMatrix(v3d->viewmat);
1531 Mat4CpyMat4(dob->ob->obmat, dob->mat);
1532 draw_object(scene, ar, v3d, &tbase, DRAW_CONSTCOLOR);
1535 tbase.object->dt= dt;
1536 tbase.object->dtx= dtx;
1537 tbase.object->transflag= transflag;
1541 /* Transp afterdraw disabled, afterdraw only stores base pointers, and duplis can be same obj */
1543 free_object_duplilist(lb); /* does restore */
1546 glDeleteLists(displist, 1);
1549 static void draw_dupli_objects(Scene *scene, ARegion *ar, View3D *v3d, Base *base)
1551 /* define the color here so draw_dupli_objects_color can be called
1552 * from the set loop */
1554 int color= (base->flag & SELECT)?TH_SELECT:TH_WIRE;
1556 if(base->object->dup_group && base->object->dup_group->id.us<1)
1559 draw_dupli_objects_color(scene, ar, v3d, base, color);
1563 void view3d_update_depths(ARegion *ar, View3D *v3d)
1565 /* Create storage for, and, if necessary, copy depth buffer */
1566 if(!v3d->depths) v3d->depths= MEM_callocN(sizeof(ViewDepths),"ViewDepths");
1568 ViewDepths *d= v3d->depths;
1569 if(d->w != ar->winx ||
1575 MEM_freeN(d->depths);
1576 d->depths= MEM_mallocN(sizeof(float)*d->w*d->h,"View depths");
1581 glReadPixels(ar->winrct.xmin,ar->winrct.ymin,d->w,d->h,
1582 GL_DEPTH_COMPONENT,GL_FLOAT, d->depths);
1584 glGetDoublev(GL_DEPTH_RANGE,d->depth_range);
1591 /* Enable sculpting in wireframe mode by drawing sculpt object only to the depth buffer */
1592 static void draw_sculpt_depths(Scene *scene, ARegion *ar, View3D *v3d)
1596 int dt= MIN2(v3d->drawtype, ob->dt);
1597 if(v3d->zbuf==0 && dt>OB_WIRE)
1601 int orig_vdt = v3d->drawtype;
1602 int orig_zbuf = v3d->zbuf;
1603 int orig_odt = ob->dt;
1605 glGetBooleanv(GL_DEPTH_TEST, &depth_on);
1606 v3d->drawtype = ob->dt = OB_SOLID;
1609 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1610 glEnable(GL_DEPTH_TEST);
1611 draw_object(scene, ar, v3d, BASACT, 0);
1612 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1614 glDisable(GL_DEPTH_TEST);
1616 v3d->drawtype = orig_vdt;
1617 v3d->zbuf = orig_zbuf;
1622 void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *))
1628 /* temp set drawtype to solid */
1630 /* Setting these temporarily is not nice */
1633 glalphaclip = U.glalphaclip;
1635 U.glalphaclip = 0.5; /* not that nice but means we wont zoom into billboards */
1636 v3d->flag &= ~V3D_SELECT_OUTLINE;
1638 setwinmatrixview3d(v3d, ar->winx, ar->winy, NULL); /* 0= no pick rect */
1639 setviewmatrixview3d(scene, v3d); /* note: calls where_is_object for camera... */
1641 Mat4MulMat4(v3d->persmat, v3d->viewmat, v3d->winmat);
1642 Mat4Invert(v3d->persinv, v3d->persmat);
1643 Mat4Invert(v3d->viewinv, v3d->viewmat);
1645 glClear(GL_DEPTH_BUFFER_BIT);
1647 wmLoadMatrix(v3d->viewmat);
1648 // persp(PERSP_STORE); // store correct view for persp(PERSP_VIEW) calls
1650 if(v3d->flag & V3D_CLIPPING) {
1651 view3d_set_clipping(v3d);
1655 glEnable(GL_DEPTH_TEST);
1657 /* draw set first */
1659 for(SETLOOPER(scene->set, base)) {
1660 if(v3d->lay & base->lay) {
1661 if (func == NULL || func(base)) {
1662 draw_object(scene, ar, v3d, base, 0);
1663 if(base->object->transflag & OB_DUPLI) {
1664 draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
1671 for(base= scene->base.first; base; base= base->next) {
1672 if(v3d->lay & base->lay) {
1673 if (func == NULL || func(base)) {
1675 if(base->object->transflag & OB_DUPLI) {
1676 draw_dupli_objects(scene, ar, v3d, base);
1678 draw_object(scene, ar, v3d, base, 0);
1683 /* this isnt that nice, draw xray objects as if they are normal */
1684 if (v3d->afterdraw.first) {
1685 View3DAfter *v3da, *next;
1689 glDepthFunc(GL_ALWAYS); /* always write into the depth bufer, overwriting front z values */
1690 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
1692 if(v3da->type==V3D_XRAY) {
1693 draw_object(scene, ar, v3d, v3da->base, 0);
1696 /* dont remove this time */
1700 glDepthFunc(GL_LEQUAL); /* Now write the depth buffer normally */
1701 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
1703 if(v3da->type==V3D_XRAY) {
1704 v3d->xray= TRUE; v3d->transp= FALSE;
1705 } else if (v3da->type==V3D_TRANSP) {
1706 v3d->xray= FALSE; v3d->transp= TRUE;
1709 draw_object(scene, ar, v3d, v3da->base, 0); /* Draw Xray or Transp objects normally */
1710 BLI_remlink(&v3d->afterdraw, v3da);
1718 U.glalphaclip = glalphaclip;
1722 typedef struct View3DShadow {
1723 struct View3DShadow *next, *prev;
1727 static void gpu_render_lamp_update(Scene *scene, View3D *v3d, Object *ob, Object *par, float obmat[][4], ListBase *shadows)
1730 View3DShadow *shadow;
1732 lamp = GPU_lamp_from_blender(scene, ob, par);
1735 GPU_lamp_update(lamp, ob->lay, obmat);
1737 if((ob->lay & v3d->lay) && GPU_lamp_has_shadow_buffer(lamp)) {
1738 shadow= MEM_callocN(sizeof(View3DShadow), "View3DShadow");
1739 shadow->lamp = lamp;
1740 BLI_addtail(shadows, shadow);
1745 static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d)
1748 View3DShadow *shadow;
1753 shadows.first= shadows.last= NULL;
1755 /* update lamp transform and gather shadow lamps */
1756 for(SETLOOPER(scene, base)) {
1759 if(ob->type == OB_LAMP)
1760 gpu_render_lamp_update(scene, v3d, ob, NULL, ob->obmat, &shadows);
1762 if (ob->transflag & OB_DUPLI) {
1764 ListBase *lb = object_duplilist(scene, ob);
1766 for(dob=lb->first; dob; dob=dob->next)
1767 if(dob->ob->type==OB_LAMP)
1768 gpu_render_lamp_update(scene, v3d, dob->ob, ob, dob->mat, &shadows);
1770 free_object_duplilist(lb);
1774 /* render shadows after updating all lamps, nested object_duplilist
1775 * don't work correct since it's replacing object matrices */
1776 for(shadow=shadows.first; shadow; shadow=shadow->next) {
1777 /* this needs to be done better .. */
1778 float viewmat[4][4], winmat[4][4];
1779 int drawtype, lay, winsize, flag2;
1781 drawtype= v3d->drawtype;
1783 flag2= v3d->flag2 & V3D_SOLID_TEX;
1785 v3d->drawtype = OB_SOLID;
1786 v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
1787 v3d->flag2 &= ~V3D_SOLID_TEX;
1789 GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
1790 // XXX drawview3d_render(v3d, viewmat, winsize, winsize, winmat, 1);
1791 GPU_lamp_shadow_buffer_unbind(shadow->lamp);
1793 v3d->drawtype= drawtype;
1795 v3d->flag2 |= flag2;
1798 BLI_freelistN(&shadows);
1801 /* *********************** customdata **************** */
1803 /* goes over all modes and view3d settings */
1804 static CustomDataMask get_viewedit_datamask(bScreen *screen)
1806 CustomDataMask mask = CD_MASK_BAREMESH;
1809 /* check if we need tfaces & mcols due to face select or texture paint */
1810 if(FACESEL_PAINT_TEST || G.f & G_TEXTUREPAINT)
1811 mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
1813 /* check if we need tfaces & mcols due to view mode */
1814 for(sa = screen->areabase.first; sa; sa = sa->next) {
1815 if(sa->spacetype == SPACE_VIEW3D) {
1816 View3D *view = sa->spacedata.first;
1817 if(view->drawtype == OB_SHADED) {
1818 /* this includes normals for mesh_create_shadedColors */
1819 mask |= CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_NORMAL | CD_MASK_ORCO;
1821 if((view->drawtype == OB_TEXTURE) || ((view->drawtype == OB_SOLID) && (view->flag2 & V3D_SOLID_TEX))) {
1822 mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
1824 if((G.fileflags & G_FILE_GAME_MAT) &&
1825 (G.fileflags & G_FILE_GAME_MAT_GLSL)) {
1826 mask |= CD_MASK_ORCO;
1832 /* check if we need mcols due to vertex paint or weightpaint */
1833 if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT)
1834 mask |= CD_MASK_MCOL;
1836 if(G.f & G_SCULPTMODE)
1837 mask |= CD_MASK_MDISPS;
1842 void view3d_main_area_draw(const bContext *C, ARegion *ar)
1844 Scene *scene= CTX_data_scene(C);
1845 ScrArea *sa= CTX_wm_area(C);
1846 View3D *v3d= sa->spacedata.first; /* XXX get from region */
1850 int retopo= 0, sculptparticle= 0;
1851 Object *obact = OBACT;
1853 /* from now on all object derived meshes check this */
1854 v3d->customdata_mask= get_viewedit_datamask(CTX_wm_screen(C));
1856 /* update all objects, ipos, matrices, displists, etc. Flags set by depgraph or manual,
1857 no layer check here, gets correct flushed */
1858 /* sets first, we allow per definition current scene to have dependencies on sets */
1860 for(SETLOOPER(scene->set, base))
1861 object_handle_update(scene, base->object); // bke_object.h
1865 for(base= scene->base.first; base; base= base->next) {
1866 object_handle_update(scene, base->object); // bke_object.h
1867 v3d->lay_used |= base->lay;
1870 /* shadow buffers, before we setup matrices */
1871 if(draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
1872 gpu_update_lamps_shadows(scene, v3d);
1874 setwinmatrixview3d(v3d, ar->winx, ar->winy, NULL); /* 0= no pick rect */
1875 setviewmatrixview3d(scene, v3d); /* note: calls where_is_object for camera... */
1877 Mat4MulMat4(v3d->persmat, v3d->viewmat, v3d->winmat);
1878 Mat4Invert(v3d->persinv, v3d->persmat);
1879 Mat4Invert(v3d->viewinv, v3d->viewmat);
1881 /* calculate pixelsize factor once, is used for lamps and obcenters */
1883 float len1, len2, vec[3];
1885 VECCOPY(vec, v3d->persinv[0]);
1886 len1= Normalize(vec);
1887 VECCOPY(vec, v3d->persinv[1]);
1888 len2= Normalize(vec);
1890 v3d->pixsize= 2.0f*(len1>len2?len1:len2);
1892 /* correct for window size */
1893 if(ar->winx > ar->winy) v3d->pixsize/= (float)ar->winx;
1894 else v3d->pixsize/= (float)ar->winy;
1897 if(v3d->drawtype > OB_WIRE) {
1899 UI_GetThemeColor3fv(TH_BACK, col);
1900 glClearColor(col[0], col[1], col[2], 0.0);
1901 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
1907 UI_GetThemeColor3fv(TH_BACK, col);
1908 glClearColor(col[0], col[1], col[2], 0.0);
1909 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
1912 wmLoadMatrix(v3d->viewmat);
1914 if(v3d->flag & V3D_CLIPPING)
1915 view3d_draw_clipping(v3d);
1917 /* set zbuffer after we draw clipping region */
1918 if(v3d->drawtype > OB_WIRE) {
1920 glEnable(GL_DEPTH_TEST);
1923 // needs to be done always, gridview is adjusted in drawgrid() now
1924 v3d->gridview= v3d->grid;
1926 if(v3d->view==0 || v3d->persp!=0) {
1927 drawfloor(scene, v3d);
1930 if(scene->world->mode & WO_STARS) {
1931 RE_make_stars(NULL, scene, star_stuff_init_func, star_stuff_vertex_func,
1932 star_stuff_term_func);
1935 if(v3d->flag & V3D_DISPBGPIC) draw_bgpic(scene, ar, v3d);
1939 ED_region_pixelspace(ar);
1941 /* XXX make function? replaces persp(1) */
1942 glMatrixMode(GL_PROJECTION);
1943 wmLoadMatrix(v3d->winmat);
1944 glMatrixMode(GL_MODELVIEW);
1945 wmLoadMatrix(v3d->viewmat);
1947 if(v3d->flag & V3D_DISPBGPIC) {
1948 draw_bgpic(scene, ar, v3d);
1952 if(v3d->flag & V3D_CLIPPING)
1953 view3d_set_clipping(v3d);
1955 /* draw set first */
1957 for(SETLOOPER(scene->set, base)) {
1959 if(v3d->lay & base->lay) {
1961 UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
1962 draw_object(scene, ar, v3d, base, DRAW_CONSTCOLOR|DRAW_SCENESET);
1964 if(base->object->transflag & OB_DUPLI) {
1965 draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
1970 /* Transp and X-ray afterdraw stuff for sets is done later */
1973 /* then draw not selected and the duplis, but skip editmode object */
1974 for(base= scene->base.first; base; base= base->next) {
1975 if(v3d->lay & base->lay) {
1978 if(base->object->transflag & OB_DUPLI) {
1979 draw_dupli_objects(scene, ar, v3d, base);
1981 if((base->flag & SELECT)==0) {
1982 if(base->object!=scene->obedit)
1983 draw_object(scene, ar, v3d, base, 0);
1988 // retopo= retopo_mesh_check() || retopo_curve_check();
1989 sculptparticle= (G.f & (G_SCULPTMODE|G_PARTICLEEDIT)) && !scene->obedit;
1991 view3d_update_depths(ar, v3d);
1993 /* draw selected and editmode */
1994 for(base= scene->base.first; base; base= base->next) {
1995 if(v3d->lay & base->lay) {
1996 if (base->object==scene->obedit || ( base->flag & SELECT) )
1997 draw_object(scene, ar, v3d, base, 0);
2001 if(!retopo && sculptparticle && !(obact && (obact->dtx & OB_DRAWXRAY))) {
2002 if(G.f & G_SCULPTMODE)
2003 draw_sculpt_depths(scene, ar, v3d);
2004 view3d_update_depths(ar, v3d);
2007 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST);
2011 // if(scene->radio) RAD_drawall(v3d->drawtype>=OB_SOLID);
2013 /* Transp and X-ray afterdraw stuff */
2014 view3d_draw_transp(scene, ar, v3d);
2015 view3d_draw_xray(scene, ar, v3d, 1); // clears zbuffer if it is used!
2017 if(!retopo && sculptparticle && (obact && (OBACT->dtx & OB_DRAWXRAY))) {
2018 if(G.f & G_SCULPTMODE)
2019 draw_sculpt_depths(scene, ar, v3d);
2020 view3d_update_depths(ar, v3d);
2023 if(v3d->flag & V3D_CLIPPING)
2024 view3d_clr_clipping();
2026 // BIF_draw_manipulator(ar);
2030 glDisable(GL_DEPTH_TEST);
2033 /* draw grease-pencil stuff */
2034 // if (v3d->flag2 & V3D_DISPGP)
2035 // draw_gpencil_3dview(ar, 1);
2037 ED_region_pixelspace(ar);
2039 /* Draw Sculpt Mode brush XXX (removed) */
2041 // retopo_paint_view_update(v3d);
2042 // retopo_draw_paint_lines();
2044 /* Draw particle edit brush XXX (removed) */
2046 if(v3d->persp>1) drawviewborder(scene, ar, v3d);
2047 if(v3d->flag2 & V3D_FLYMODE) drawviewborder_flymode(ar);
2049 /* draw grease-pencil stuff */
2050 // if (v3d->flag2 & V3D_DISPGP)
2051 // draw_gpencil_3dview(ar, 0);
2053 drawcursor(scene, ar, v3d);
2055 if(U.uiflag & USER_SHOW_ROTVIEWICON)
2056 draw_view_axis(v3d);
2058 draw_view_icon(v3d);
2060 /* XXX removed viewport fps */
2061 if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
2062 draw_viewport_name(ar, v3d);
2066 if(U.uiflag & USER_DRAWVIEWINFO)
2067 draw_selected_name(scene, ob, v3d);
2069 /* XXX here was the blockhandlers for floating panels */
2071 if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT || G.f & G_TEXTUREPAINT) {
2072 v3d->flag |= V3D_NEEDBACKBUFDRAW;
2073 // XXX addafterqueue(ar->win, BACKBUFDRAW, 1);
2075 // test for backbuf select
2076 if(scene->obedit && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) {
2078 v3d->flag |= V3D_NEEDBACKBUFDRAW;
2079 // XXX if(afterqtest(ar->win, BACKBUFDRAW)==0) {
2080 // addafterqueue(ar->win, BACKBUFDRAW, 1);
2084 #ifndef DISABLE_PYTHON
2085 /* XXX here was scriptlink */