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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
29 /** \file blender/editors/space_view3d/view3d_draw.c
38 #include "DNA_armature_types.h"
39 #include "DNA_camera_types.h"
40 #include "DNA_customdata_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_group_types.h"
43 #include "DNA_key_types.h"
44 #include "DNA_lamp_types.h"
45 #include "DNA_scene_types.h"
46 #include "DNA_world_types.h"
48 #include "MEM_guardedalloc.h"
50 #include "BLI_blenlib.h"
53 #include "BLI_utildefines.h"
56 #include "BKE_context.h"
57 #include "BKE_customdata.h"
58 #include "BKE_image.h"
60 #include "BKE_object.h"
61 #include "BKE_global.h"
62 #include "BKE_paint.h"
63 #include "BKE_scene.h"
66 #include "RE_pipeline.h" // make_stars
68 #include "IMB_imbuf_types.h"
69 #include "IMB_imbuf.h"
72 #include "BIF_glutil.h"
77 #include "ED_armature.h"
78 #include "ED_keyframing.h"
79 #include "ED_gpencil.h"
80 #include "ED_screen.h"
81 #include "ED_space_api.h"
82 #include "ED_screen_types.h"
83 #include "ED_transform.h"
85 #include "UI_interface.h"
86 #include "UI_interface_icons.h"
87 #include "UI_resources.h"
90 #include "GPU_material.h"
91 #include "GPU_extensions.h"
93 #include "view3d_intern.h" // own include
97 static void star_stuff_init_func(void)
103 static void star_stuff_vertex_func(float* i)
107 static void star_stuff_term_func(void)
112 void circf(float x, float y, float rad)
114 GLUquadricObj *qobj = gluNewQuadric();
116 gluQuadricDrawStyle(qobj, GLU_FILL);
120 glTranslatef(x, y, 0.);
122 gluDisk( qobj, 0.0, rad, 32, 1);
126 gluDeleteQuadric(qobj);
129 void circ(float x, float y, float rad)
131 GLUquadricObj *qobj = gluNewQuadric();
133 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
137 glTranslatef(x, y, 0.);
139 gluDisk( qobj, 0.0, rad, 32, 1);
143 gluDeleteQuadric(qobj);
147 /* ********* custom clipping *********** */
149 static void view3d_draw_clipping(RegionView3D *rv3d)
151 BoundBox *bb= rv3d->clipbb;
154 UI_ThemeColorShade(TH_BACK, -8);
158 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[3]);
159 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[1]);
160 glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[5]);
161 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[3]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[6]);
162 glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[2]);
163 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[3]);
169 void view3d_set_clipping(RegionView3D *rv3d)
174 if(rv3d->viewlock) tot= 6;
176 for(a=0; a<tot; a++) {
177 QUATCOPY(plane, rv3d->clip[a]);
178 glClipPlane(GL_CLIP_PLANE0+a, plane);
179 glEnable(GL_CLIP_PLANE0+a);
183 void view3d_clr_clipping(void)
188 glDisable(GL_CLIP_PLANE0+a);
192 static int test_clipping(float *vec, float clip[][4])
195 copy_v3_v3(view, vec);
197 if(0.0f < clip[0][3] + INPR(view, clip[0]))
198 if(0.0f < clip[1][3] + INPR(view, clip[1]))
199 if(0.0f < clip[2][3] + INPR(view, clip[2]))
200 if(0.0f < clip[3][3] + INPR(view, clip[3]))
206 /* for 'local' ED_view3d_local_clipping must run first
207 * then all comparisons can be done in localspace */
208 int view3d_test_clipping(RegionView3D *rv3d, float *vec, int local)
210 return test_clipping(vec, local ? rv3d->clip_local : rv3d->clip);
213 /* ********* end custom clipping *********** */
216 static void drawgrid_draw(ARegion *ar, float wx, float wy, float x, float y, float dx)
224 v2[1]= (float)ar->winy;
226 v1[0] = v2[0] = x-dx*floor(x/dx);
230 while(v1[0] < ar->winx) {
233 v1[0] = v2[0] = v1[0] + dx;
237 v2[0]= (float)ar->winx;
239 v1[1]= v2[1]= y-dx*floor(y/dx);
241 while(v1[1] < ar->winy) {
244 v1[1] = v2[1] = v1[1] + dx;
250 #define GRID_MIN_PX 6.0f
252 static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit)
254 /* extern short bgpicmode; */
255 RegionView3D *rv3d= ar->regiondata;
256 float wx, wy, x, y, fw, fx, fy, dx;
258 unsigned char col[3], col2[3];
260 vec4[0]=vec4[1]=vec4[2]=0.0;
262 mul_m4_v4(rv3d->persmat, vec4);
267 wx= (ar->winx/2.0); /* because of rounding errors, grid at wrong location */
273 vec4[0]=vec4[1]= v3d->grid;
277 mul_m4_v4(rv3d->persmat, vec4);
282 dx= fabs(x-(wx)*fx/fw);
283 if(dx==0) dx= fabs(y-(wy)*fy/fw);
285 glDepthMask(0); // disable write in zbuffer
288 UI_ThemeColor(TH_GRID);
291 /* Use GRID_MIN_PX*2 for units because very very small grid
292 * items are less useful when dealing with units */
299 bUnit_GetSystem(&usys, &len, unit->system, B_UNIT_LENGTH);
304 scalar= bUnit_GetScaler(usys, i);
306 dx_scalar = dx * scalar / unit->scale_length;
307 if (dx_scalar < (GRID_MIN_PX*2))
310 /* Store the smallest drawn grid size units name so users know how big each grid cell is */
311 if(*grid_unit==NULL) {
312 *grid_unit= bUnit_GetNameDisplay(usys, i);
313 rv3d->gridview= (scalar * v3d->grid) / unit->scale_length;
315 blend_fac= 1-((GRID_MIN_PX*2)/dx_scalar);
317 /* tweak to have the fade a bit nicer */
318 blend_fac= (blend_fac * blend_fac) * 2.0f;
319 CLAMP(blend_fac, 0.3f, 1.0f);
322 UI_ThemeColorBlend(TH_BACK, TH_GRID, blend_fac);
324 drawgrid_draw(ar, wx, wy, x, y, dx_scalar);
329 short sublines = v3d->gridsubdiv;
332 rv3d->gridview*= sublines;
336 rv3d->gridview*= sublines;
340 rv3d->gridview*= sublines;
344 UI_ThemeColor(TH_GRID);
345 drawgrid_draw(ar, wx, wy, x, y, dx);
348 else { // start blending out
349 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/(GRID_MIN_PX*6));
350 drawgrid_draw(ar, wx, wy, x, y, dx);
352 UI_ThemeColor(TH_GRID);
353 drawgrid_draw(ar, wx, wy, x, y, sublines*dx);
356 else { // start blending out (GRID_MIN_PX < dx < (GRID_MIN_PX*10))
357 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/(GRID_MIN_PX*6));
358 drawgrid_draw(ar, wx, wy, x, y, dx);
360 UI_ThemeColor(TH_GRID);
361 drawgrid_draw(ar, wx, wy, x, y, sublines*dx);
365 if(dx>(GRID_MIN_PX*10)) { // start blending in
366 rv3d->gridview/= sublines;
368 if(dx>(GRID_MIN_PX*10)) { // start blending in
369 rv3d->gridview/= sublines;
371 if(dx>(GRID_MIN_PX*10)) {
372 UI_ThemeColor(TH_GRID);
373 drawgrid_draw(ar, wx, wy, x, y, dx);
376 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/(GRID_MIN_PX*6));
377 drawgrid_draw(ar, wx, wy, x, y, dx);
378 UI_ThemeColor(TH_GRID);
379 drawgrid_draw(ar, wx, wy, x, y, dx*sublines);
383 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/(GRID_MIN_PX*6));
384 drawgrid_draw(ar, wx, wy, x, y, dx);
385 UI_ThemeColor(TH_GRID);
386 drawgrid_draw(ar, wx, wy, x, y, dx*sublines);
390 UI_ThemeColorBlend(TH_BACK, TH_GRID, dx/(GRID_MIN_PX*6));
391 drawgrid_draw(ar, wx, wy, x, y, dx);
392 UI_ThemeColor(TH_GRID);
393 drawgrid_draw(ar, wx, wy, x, y, dx*sublines);
401 UI_GetThemeColor3ubv(TH_GRID, col);
406 /* horizontal line */
407 if( ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT))
408 UI_make_axis_color(col, col2, 'Y');
409 else UI_make_axis_color(col, col2, 'X');
412 fdrawline(0.0, y, (float)ar->winx, y);
415 if( ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM))
416 UI_make_axis_color(col, col2, 'Y');
417 else UI_make_axis_color(col, col2, 'Z');
420 fdrawline(x, 0.0, x, (float)ar->winy);
422 glDepthMask(1); // enable write in zbuffer
426 static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit)
428 float vert[3], grid, grid_scale;
429 int a, gridlines, emphasise;
430 unsigned char col[3], col2[3];
435 if(v3d->gridlines<3) return;
437 grid_scale= v3d->grid;
438 /* use 'grid_scale' instead of 'v3d->grid' from now on */
441 if(scene->unit.system) {
445 bUnit_GetSystem(&usys, &len, scene->unit.system, B_UNIT_LENGTH);
448 int i= bUnit_GetBaseUnit(usys);
449 *grid_unit= bUnit_GetNameDisplay(usys, i);
450 grid_scale = (grid_scale * bUnit_GetScaler(usys, i)) / scene->unit.scale_length;
454 if(v3d->zbuf && scene->obedit) glDepthMask(0); // for zbuffer-select
456 gridlines= v3d->gridlines/2;
457 grid= gridlines * grid_scale;
459 UI_GetThemeColor3ubv(TH_GRID, col);
460 UI_GetThemeColor3ubv(TH_BACK, col2);
462 /* emphasise division lines lighter instead of darker, if background is darker than grid */
463 if ( ((col[0]+col[1]+col[2])/3+10) > (col2[0]+col2[1]+col2[2])/3 )
468 /* draw the Y axis and/or grid lines */
469 for(a= -gridlines;a<=gridlines;a++) {
471 /* check for the 'show Y axis' preference */
472 if (v3d->gridflag & V3D_SHOW_Y) {
473 UI_make_axis_color(col, col2, 'Y');
477 } else if (v3d->gridflag & V3D_SHOW_FLOOR) {
478 UI_ThemeColorShade(TH_GRID, emphasise);
483 /* check for the 'show grid floor' preference */
484 if (v3d->gridflag & V3D_SHOW_FLOOR) {
486 UI_ThemeColorShade(TH_GRID, emphasise);
488 else UI_ThemeColorShade(TH_GRID, 10);
497 glBegin(GL_LINE_STRIP);
498 vert[0]= a * grid_scale;
507 /* draw the X axis and/or grid lines */
508 for(a= -gridlines;a<=gridlines;a++) {
510 /* check for the 'show X axis' preference */
511 if (v3d->gridflag & V3D_SHOW_X) {
512 UI_make_axis_color(col, col2, 'X');
516 } else if (v3d->gridflag & V3D_SHOW_FLOOR) {
517 UI_ThemeColorShade(TH_GRID, emphasise);
522 /* check for the 'show grid floor' preference */
523 if (v3d->gridflag & V3D_SHOW_FLOOR) {
525 UI_ThemeColorShade(TH_GRID, emphasise);
527 else UI_ThemeColorShade(TH_GRID, 10);
536 glBegin(GL_LINE_STRIP);
537 vert[1]= a * grid_scale;
546 /* draw the Z axis line */
547 /* check for the 'show Z axis' preference */
548 if (v3d->gridflag & V3D_SHOW_Z) {
549 UI_make_axis_color(col, col2, 'Z');
552 glBegin(GL_LINE_STRIP);
562 if(v3d->zbuf && scene->obedit) glDepthMask(1);
566 static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
571 /* we dont want the clipping for cursor */
574 project_short(ar, give_cursor(scene, v3d), co);
583 circ((float)mx, (float)my, 10.0);
586 circ((float)mx, (float)my, 10.0);
590 sdrawline(mx-20, my, mx-5, my);
591 sdrawline(mx+5, my, mx+20, my);
592 sdrawline(mx, my-20, mx, my-5);
593 sdrawline(mx, my+5, mx, my+20);
597 /* Draw a live substitute of the view icon, which is always shown
598 * colors copied from transform_manipulator.c, we should keep these matching. */
599 static void draw_view_axis(RegionView3D *rv3d)
601 const float k = U.rvisize; /* axis size */
602 const float toll = 0.5; /* used to see when view is quasi-orthogonal */
603 const float start = k + 1.0; /* axis center in screen coordinates, x=y */
604 float ydisp = 0.0; /* vertical displacement to allow obj info text */
605 int bright = 25*(float)U.rvibright + 5; /* axis alpha (rvibright has range 0-10) */
610 /* thickness of lines is proportional to k */
614 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
619 mul_qt_v3(rv3d->viewquat, vec);
623 glColor4ub(220, 0, 0, bright);
625 glVertex2f(start, start + ydisp);
626 glVertex2f(start + dx, start + dy + ydisp);
629 if (fabs(dx) > toll || fabs(dy) > toll) {
630 BLF_draw_default(start + dx + 2, start + dy + ydisp + 2, 0.0f, "x", 1);
633 /* BLF_draw_default disables blending */
639 mul_qt_v3(rv3d->viewquat, vec);
643 glColor4ub(0, 220, 0, bright);
645 glVertex2f(start, start + ydisp);
646 glVertex2f(start + dx, start + dy + ydisp);
649 if (fabs(dx) > toll || fabs(dy) > toll) {
650 BLF_draw_default(start + dx + 2, start + dy + ydisp + 2, 0.0f, "y", 1);
658 mul_qt_v3(rv3d->viewquat, vec);
662 glColor4ub(30, 30, 220, bright);
664 glVertex2f(start, start + ydisp);
665 glVertex2f(start + dx, start + dy + ydisp);
668 if (fabs(dx) > toll || fabs(dy) > toll) {
669 BLF_draw_default(start + dx + 2, start + dy + ydisp + 2, 0.0f, "z", 1);
672 /* restore line-width */
679 static void draw_view_icon(RegionView3D *rv3d)
683 if( ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM))
685 else if( ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK))
686 icon= ICON_AXIS_FRONT;
687 else if( ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT))
688 icon= ICON_AXIS_SIDE;
692 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
694 UI_icon_draw(5.0, 5.0, icon);
699 static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
701 const char *name = NULL;
703 switch (rv3d->view) {
704 case RV3D_VIEW_FRONT:
705 if (rv3d->persp == RV3D_ORTHO) name = "Front Ortho";
706 else name = "Front Persp";
709 if (rv3d->persp == RV3D_ORTHO) name = "Back Ortho";
710 else name = "Back Persp";
713 if (rv3d->persp == RV3D_ORTHO) name = "Top Ortho";
714 else name = "Top Persp";
716 case RV3D_VIEW_BOTTOM:
717 if (rv3d->persp == RV3D_ORTHO) name = "Bottom Ortho";
718 else name = "Bottom Persp";
720 case RV3D_VIEW_RIGHT:
721 if (rv3d->persp == RV3D_ORTHO) name = "Right Ortho";
722 else name = "Right Persp";
725 if (rv3d->persp == RV3D_ORTHO) name = "Left Ortho";
726 else name = "Left Persp";
730 if (rv3d->persp==RV3D_CAMOB) {
731 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
733 cam = v3d->camera->data;
734 name = (cam->type != CAM_ORTHO) ? "Camera Persp" : "Camera Ortho";
736 name = "Object as Camera";
739 name = (rv3d->persp == RV3D_ORTHO) ? "User Ortho" : "User Persp";
747 static void draw_viewport_name(ARegion *ar, View3D *v3d)
749 RegionView3D *rv3d= ar->regiondata;
750 const char *name= view3d_get_name(v3d, rv3d);
754 BLI_snprintf(tmpstr, sizeof(tmpstr), "%s (Local)", name);
759 UI_ThemeColor(TH_TEXT_HI);
760 BLF_draw_default(22, ar->winy-17, 0.0f, name, sizeof(tmpstr));
764 /* draw info beside axes in bottom left-corner:
765 * framenum, object name, bone name (if available), marker name (if available)
767 static void draw_selected_name(Scene *scene, Object *ob, View3D *v3d)
769 char info[256], *markern;
772 /* get name of marker on current frame (if available) */
773 markern= scene_find_marker_name(scene, CFRA);
775 /* check if there is an object */
777 /* name(s) to display depends on type of object */
778 if(ob->type==OB_ARMATURE) {
779 bArmature *arm= ob->data;
782 /* show name of active bone too (if possible) */
786 name= ((EditBone *)arm->act_edbone)->name;
789 else if(ob->mode & OB_MODE_POSE) {
792 if(arm->act_bone->layer & arm->layer)
793 name= arm->act_bone->name;
798 sprintf(info, "(%d) %s %s <%s>", CFRA, ob->id.name+2, name, markern);
800 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, name);
802 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
804 else if(ELEM3(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
809 /* try to display active shapekey too */
811 key = ob_get_key(ob);
813 kb = BLI_findlink(&key->block, ob->shapenr-1);
815 sprintf(shapes, ": %s ", kb->name);
816 if(ob->shapeflag == OB_SHAPE_LOCK){
817 strcat(shapes, " (Pinned)");
823 sprintf(info, "(%d) %s %s <%s>", CFRA, ob->id.name+2, shapes, markern);
825 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, shapes);
828 /* standard object */
830 sprintf(info, "(%d) %s <%s>", CFRA, ob->id.name+2, markern);
832 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
835 /* color depends on whether there is a keyframe */
836 if (id_frame_has_keyframe((ID *)ob, /*BKE_curframe(scene)*/(float)(CFRA), v3d->keyflags))
837 UI_ThemeColor(TH_VERTEX_SELECT);
839 UI_ThemeColor(TH_TEXT_HI);
844 sprintf(info, "(%d) <%s>", CFRA, markern);
846 sprintf(info, "(%d)", CFRA);
848 /* color is always white */
849 UI_ThemeColor(TH_TEXT_HI);
852 if (U.uiflag & USER_SHOW_ROTVIEWICON)
853 offset = 14 + (U.rvisize * 2);
855 BLF_draw_default(offset, 10, 0.0f, info, sizeof(info)-1);
858 void view3d_viewborder_size_get(Scene *scene, ARegion *ar, float size_r[2])
860 float winmax= MAX2(ar->winx, ar->winy);
861 float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
865 size_r[1]= winmax/aspect;
867 size_r[0]= winmax*aspect;
872 void view3d_calc_camera_border(Scene *scene, ARegion *ar, RegionView3D *rv3d, View3D *v3d, rctf *viewborder_r, short do_shift)
874 float zoomfac, size[2];
875 float dx= 0.0f, dy= 0.0f;
877 view3d_viewborder_size_get(scene, ar, size);
880 rv3d = ar->regiondata;
882 /* magic zoom calculation, no idea what
883 * it signifies, if you find out, tell me! -zr
885 /* simple, its magic dude!
886 * well, to be honest, this gives a natural feeling zooming
887 * with multiple keypad presses (ton)
890 zoomfac= (M_SQRT2 + rv3d->camzoom/50.0);
891 zoomfac= (zoomfac*zoomfac)*0.25;
893 size[0]= size[0]*zoomfac;
894 size[1]= size[1]*zoomfac;
896 /* center in window */
897 viewborder_r->xmin= 0.5*ar->winx - 0.5*size[0];
898 viewborder_r->ymin= 0.5*ar->winy - 0.5*size[1];
899 viewborder_r->xmax= viewborder_r->xmin + size[0];
900 viewborder_r->ymax= viewborder_r->ymin + size[1];
902 dx= ar->winx*rv3d->camdx*zoomfac*2.0f;
903 dy= ar->winy*rv3d->camdy*zoomfac*2.0f;
906 viewborder_r->xmin-= dx;
907 viewborder_r->ymin-= dy;
908 viewborder_r->xmax-= dx;
909 viewborder_r->ymax-= dy;
911 if(do_shift && v3d->camera && v3d->camera->type==OB_CAMERA) {
912 Camera *cam= v3d->camera->data;
913 float w = viewborder_r->xmax - viewborder_r->xmin;
914 float h = viewborder_r->ymax - viewborder_r->ymin;
915 float side = MAX2(w, h);
917 if(do_shift == -1) side *= -1;
918 viewborder_r->xmin+= cam->shiftx*side;
919 viewborder_r->xmax+= cam->shiftx*side;
920 viewborder_r->ymin+= cam->shifty*side;
921 viewborder_r->ymax+= cam->shifty*side;
925 static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
928 float x1, x2, y1, y2;
929 float x1i, x2i, y1i, y2i;
930 float x3, y3, x4, y4;
933 RegionView3D *rv3d= (RegionView3D *)ar->regiondata;
935 if(v3d->camera==NULL)
937 if(v3d->camera->type==OB_CAMERA)
938 ca = v3d->camera->data;
940 view3d_calc_camera_border(scene, ar, rv3d, v3d, &viewborder, FALSE);
947 /* apply offsets so the real 3D camera shows through */
948 x1i= (int)(x1 - 1.0f);
949 y1i= (int)(y1 - 1.0f);
950 x2i= (int)(x2 + 1.0f);
951 y2i= (int)(y2 + 1.0f);
953 /* passepartout, specified in camera edit buttons */
954 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001) {
955 if (ca->passepartalpha == 1.0) {
958 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
960 glColor4f(0, 0, 0, ca->passepartalpha);
963 glRectf(0.0, (float)ar->winy, x1i, 0.0);
964 if (x2i < (float)ar->winx)
965 glRectf(x2i, (float)ar->winy, (float)ar->winx, 0.0);
966 if (y2i < (float)ar->winy)
967 glRectf(x1i, (float)ar->winy, x2i, y2i);
969 glRectf(x1i, y1i, x2i, 0.0);
975 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
978 UI_ThemeColor(TH_BACK);
979 glRectf(x1i, y1i, x2i, y2i);
982 UI_ThemeColor(TH_WIRE);
983 glRectf(x1i, y1i, x2i, y2i);
986 if(scene->r.mode & R_BORDER) {
989 x3= x1+ scene->r.border.xmin*(x2-x1);
990 y3= y1+ scene->r.border.ymin*(y2-y1);
991 x4= x1+ scene->r.border.xmax*(x2-x1);
992 y4= y1+ scene->r.border.ymax*(y2-y1);
995 glRectf(x3, y3, x4, y4);
999 if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
1010 UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
1013 uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
1017 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1019 /* camera name - draw in highlighted text color */
1020 if (ca && (ca->flag & CAM_SHOWNAME)) {
1021 UI_ThemeColor(TH_TEXT_HI);
1022 BLF_draw_default(x1i, y1i-15, 0.0f, v3d->camera->id.name+2, sizeof(v3d->camera->id.name)-2);
1023 UI_ThemeColor(TH_WIRE);
1027 /* *********************** backdraw for selection *************** */
1029 static void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d)
1031 RegionView3D *rv3d= ar->regiondata;
1032 struct Base *base = scene->basact;
1035 if(base && (base->object->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT) ||
1036 paint_facesel_test(base->object)));
1037 else if((base && (base->object->mode & OB_MODE_TEXTURE_PAINT)) &&
1038 scene->toolsettings && (scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE));
1039 else if((base && (base->object->mode & OB_MODE_PARTICLE_EDIT)) && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT));
1040 else if(scene->obedit && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT));
1042 v3d->flag &= ~V3D_INVALID_BACKBUF;
1046 if( !(v3d->flag & V3D_INVALID_BACKBUF) ) return;
1050 // addafterqueue(ar->win, BACKBUFDRAW, 1);
1055 if(v3d->drawtype > OB_WIRE) v3d->zbuf= TRUE;
1057 glDisable(GL_DITHER);
1059 region_scissor_winrct(ar, &winrct);
1060 glScissor(winrct.xmin, winrct.ymin, winrct.xmax - winrct.xmin, winrct.ymax - winrct.ymin);
1062 glClearColor(0.0, 0.0, 0.0, 0.0);
1064 glEnable(GL_DEPTH_TEST);
1065 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1068 glClear(GL_COLOR_BUFFER_BIT);
1069 glDisable(GL_DEPTH_TEST);
1072 if(rv3d->rflag & RV3D_CLIPPING)
1073 view3d_set_clipping(rv3d);
1075 G.f |= G_BACKBUFSEL;
1077 if(base && (base->lay & v3d->lay)) {
1078 draw_object_backbufsel(scene, v3d, rv3d, base->object);
1081 v3d->flag &= ~V3D_INVALID_BACKBUF;
1082 ar->swap= 0; /* mark invalid backbuf for wm draw */
1084 G.f &= ~G_BACKBUFSEL;
1086 glDisable(GL_DEPTH_TEST);
1087 glEnable(GL_DITHER);
1089 if(rv3d->rflag & RV3D_CLIPPING)
1090 view3d_clr_clipping();
1092 /* it is important to end a view in a transform compatible with buttons */
1093 // persp(PERSP_WIN); // set ortho
1097 void view3d_validate_backbuf(ViewContext *vc)
1099 if(vc->v3d->flag & V3D_INVALID_BACKBUF)
1100 backdrawview3d(vc->scene, vc->ar, vc->v3d);
1103 /* samples a single pixel (copied from vpaint) */
1104 unsigned int view3d_sample_backbuf(ViewContext *vc, int x, int y)
1108 if(x >= vc->ar->winx || y >= vc->ar->winy) return 0;
1109 x+= vc->ar->winrct.xmin;
1110 y+= vc->ar->winrct.ymin;
1112 view3d_validate_backbuf(vc);
1114 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
1115 glReadBuffer(GL_BACK);
1117 if(ENDIAN_ORDER==B_ENDIAN) SWITCH_INT(col);
1119 return WM_framebuffer_to_index(col);
1122 /* reads full rect, converts indices */
1123 ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax, short ymax)
1125 unsigned int *dr, *rd;
1126 struct ImBuf *ibuf, *ibuf1;
1128 short xminc, yminc, xmaxc, ymaxc, xs, ys;
1131 if(xmin<0) xminc= 0; else xminc= xmin;
1132 if(xmax >= vc->ar->winx) xmaxc= vc->ar->winx-1; else xmaxc= xmax;
1133 if(xminc > xmaxc) return NULL;
1135 if(ymin<0) yminc= 0; else yminc= ymin;
1136 if(ymax >= vc->ar->winy) ymaxc= vc->ar->winy-1; else ymaxc= ymax;
1137 if(yminc > ymaxc) return NULL;
1139 ibuf= IMB_allocImBuf((xmaxc-xminc+1), (ymaxc-yminc+1), 32, IB_rect);
1141 view3d_validate_backbuf(vc);
1143 glReadPixels(vc->ar->winrct.xmin+xminc, vc->ar->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1144 glReadBuffer(GL_BACK);
1146 if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
1148 a= (xmaxc-xminc+1)*(ymaxc-yminc+1);
1151 if(*dr) *dr= WM_framebuffer_to_index(*dr);
1155 /* put clipped result back, if needed */
1156 if(xminc==xmin && xmaxc==xmax && yminc==ymin && ymaxc==ymax)
1159 ibuf1= IMB_allocImBuf( (xmax-xmin+1),(ymax-ymin+1),32,IB_rect);
1163 for(ys= ymin; ys<=ymax; ys++) {
1164 for(xs= xmin; xs<=xmax; xs++, dr++) {
1165 if( xs>=xminc && xs<=xmaxc && ys>=yminc && ys<=ymaxc) {
1171 IMB_freeImBuf(ibuf);
1175 /* smart function to sample a rect spiralling outside, nice for backbuf selection */
1176 unsigned int view3d_sample_backbuf_rect(ViewContext *vc, short mval[2], int size,
1177 unsigned int min, unsigned int max, int *dist, short strict,
1178 void *handle, unsigned int (*indextest)(void *handle, unsigned int index))
1181 unsigned int *bufmin, *bufmax, *tbuf;
1183 int a, b, rc, nr, amount, dirvec[4][2];
1185 unsigned int index = 0;
1190 minx = mval[0]-(amount+1);
1191 miny = mval[1]-(amount+1);
1192 buf = view3d_read_backbuf(vc, minx, miny, minx+size-1, miny+size-1);
1197 dirvec[0][0]= 1; dirvec[0][1]= 0;
1198 dirvec[1][0]= 0; dirvec[1][1]= -size;
1199 dirvec[2][0]= -1; dirvec[2][1]= 0;
1200 dirvec[3][0]= 0; dirvec[3][1]= size;
1204 bufmax = buf->rect + size*size;
1205 tbuf+= amount*size+ amount;
1207 for(nr=1; nr<=size; nr++) {
1209 for(a=0; a<2; a++) {
1210 for(b=0; b<nr; b++, distance++) {
1211 if (*tbuf && *tbuf>=min && *tbuf<max) { //we got a hit
1213 indexok = indextest(handle, *tbuf - min+1);
1215 *dist= (short) sqrt( (float)distance );
1216 index = *tbuf - min+1;
1221 *dist= (short) sqrt( (float)distance ); // XXX, this distance is wrong -
1222 index = *tbuf - min+1; // messy yah, but indices start at 1
1227 tbuf+= (dirvec[rc][0]+dirvec[rc][1]);
1229 if(tbuf<bufmin || tbuf>=bufmax) {
1244 /* ************************************************************* */
1246 static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
1248 RegionView3D *rv3d= ar->regiondata;
1252 float vec[4], fac, asp, zoomx, zoomy;
1253 float x1, y1, x2, y2, cx, cy;
1256 for ( bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next ) {
1258 if( (bgpic->view == 0) || /* zero for any */
1259 (bgpic->view & (1<<rv3d->view)) || /* check agaist flags */
1260 (rv3d->persp==RV3D_CAMOB && bgpic->view == (1<<RV3D_VIEW_CAMERA))
1265 BKE_image_user_calc_frame(&bgpic->iuser, CFRA, 0);
1266 ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser);
1267 if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL) )
1269 if(ibuf->channels!=4)
1271 if(ibuf->rect==NULL)
1272 IMB_rect_from_float(ibuf);
1274 if(rv3d->persp==RV3D_CAMOB) {
1277 view3d_calc_camera_border(scene, ar, rv3d, v3d, &vb, FALSE);
1287 /* calc window coord */
1288 initgrabz(rv3d, 0.0, 0.0, 0.0);
1289 window_to_3d_delta(ar, vec, 1, 0);
1290 fac= MAX3( fabs(vec[0]), fabs(vec[1]), fabs(vec[1]) );
1293 asp= ( (float)ibuf->y)/(float)ibuf->x;
1295 vec[0] = vec[1] = vec[2] = 0.0;
1296 view3d_project_float(ar, vec, sco, rv3d->persmat);
1300 x1= cx+ fac*(bgpic->xof-bgpic->size);
1301 y1= cy+ asp*fac*(bgpic->yof-bgpic->size);
1302 x2= cx+ fac*(bgpic->xof+bgpic->size);
1303 y2= cy+ asp*fac*(bgpic->yof+bgpic->size);
1306 /* complete clip? */
1308 if(x2 < 0 ) continue;
1309 if(y2 < 0 ) continue;
1310 if(x1 > ar->winx ) continue;
1311 if(y1 > ar->winy ) continue;
1313 zoomx= (x2-x1)/ibuf->x;
1314 zoomy= (y2-y1)/ibuf->y;
1316 /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */
1317 if(zoomx < 1.0f || zoomy < 1.0f) {
1318 float tzoom= MIN2(zoomx, zoomy);
1321 if(ibuf->mipmap[0]==NULL)
1322 IMB_makemipmap(ibuf, 0);
1324 while(tzoom < 1.0f && mip<8 && ibuf->mipmap[mip]) {
1331 ibuf= ibuf->mipmap[mip-1];
1334 if(v3d->zbuf) glDisable(GL_DEPTH_TEST);
1338 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1340 glMatrixMode(GL_PROJECTION);
1342 glMatrixMode(GL_MODELVIEW);
1344 ED_region_pixelspace(ar);
1346 glPixelZoom(zoomx, zoomy);
1347 glColor4f(1.0, 1.0, 1.0, 1.0-bgpic->blend);
1348 glaDrawPixelsTex(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
1350 glPixelZoom(1.0, 1.0);
1351 glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
1353 glMatrixMode(GL_PROJECTION);
1355 glMatrixMode(GL_MODELVIEW);
1358 glDisable(GL_BLEND);
1361 if(v3d->zbuf) glEnable(GL_DEPTH_TEST);
1366 /* ****************** View3d afterdraw *************** */
1368 typedef struct View3DAfter {
1369 struct View3DAfter *next, *prev;
1374 /* temp storage of Objects that need to be drawn as last */
1375 void add_view3d_after(ListBase *lb, Base *base, int flag)
1377 View3DAfter *v3da= MEM_callocN(sizeof(View3DAfter), "View 3d after");
1378 BLI_addtail(lb, v3da);
1383 /* disables write in zbuffer and draws it over */
1384 static void view3d_draw_transp(Scene *scene, ARegion *ar, View3D *v3d)
1386 View3DAfter *v3da, *next;
1391 for(v3da= v3d->afterdraw_transp.first; v3da; v3da= next) {
1393 draw_object(scene, ar, v3d, v3da->base, v3da->flag);
1394 BLI_remlink(&v3d->afterdraw_transp, v3da);
1403 /* clears zbuffer and draws it over */
1404 static void view3d_draw_xray(Scene *scene, ARegion *ar, View3D *v3d, int clear)
1406 View3DAfter *v3da, *next;
1408 if(clear && v3d->zbuf)
1409 glClear(GL_DEPTH_BUFFER_BIT);
1412 for(v3da= v3d->afterdraw_xray.first; v3da; v3da= next) {
1414 draw_object(scene, ar, v3d, v3da->base, v3da->flag);
1415 BLI_remlink(&v3d->afterdraw_xray, v3da);
1422 /* clears zbuffer and draws it over */
1423 static void view3d_draw_xraytransp(Scene *scene, ARegion *ar, View3D *v3d, int clear)
1425 View3DAfter *v3da, *next;
1427 if(clear && v3d->zbuf)
1428 glClear(GL_DEPTH_BUFFER_BIT);
1433 for(v3da= v3d->afterdraw_xraytransp.first; v3da; v3da= next) {
1435 draw_object(scene, ar, v3d, v3da->base, v3da->flag);
1436 BLI_remlink(&v3d->afterdraw_xraytransp, v3da);
1445 /* *********************** */
1448 In most cases call draw_dupli_objects,
1449 draw_dupli_objects_color was added because when drawing set dupli's
1450 we need to force the color
1454 int dupli_ob_sort(void *arg1, void *arg2)
1456 void *p1= ((DupliObject *)arg1)->ob;
1457 void *p2= ((DupliObject *)arg2)->ob;
1459 if (p1 < p2) val = -1;
1460 else if (p1 > p2) val = 1;
1466 static DupliObject *dupli_step(DupliObject *dob)
1468 while(dob && dob->no_draw)
1473 static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int color)
1475 RegionView3D *rv3d= ar->regiondata;
1477 DupliObject *dob_prev= NULL, *dob, *dob_next= NULL;
1479 BoundBox bb, *bb_tmp; /* use a copy because draw_object, calls clear_mesh_caches */
1481 short transflag, use_displist= -1; /* -1 is initialize */
1484 if (base->object->restrictflag & OB_RESTRICT_VIEW) return;
1486 tbase.flag= OB_FROMDUPLI|base->flag;
1487 lb= object_duplilist(scene, base->object);
1488 // BLI_sortlist(lb, dupli_ob_sort); // might be nice to have if we have a dupli list with mixed objects.
1490 dob=dupli_step(lb->first);
1491 if(dob) dob_next= dupli_step(dob->next);
1493 for( ; dob ; dob_prev= dob, dob= dob_next, dob_next= dob_next ? dupli_step(dob_next->next) : NULL) {
1494 tbase.object= dob->ob;
1496 /* extra service: draw the duplicator in drawtype of parent */
1497 /* MIN2 for the drawtype to allow bounding box objects in groups for lods */
1498 dt= tbase.object->dt; tbase.object->dt= MIN2(tbase.object->dt, base->object->dt);
1499 dtx= tbase.object->dtx; tbase.object->dtx= base->object->dtx;
1501 /* negative scale flag has to propagate */
1502 transflag= tbase.object->transflag;
1503 if(base->object->transflag & OB_NEG_SCALE)
1504 tbase.object->transflag ^= OB_NEG_SCALE;
1506 UI_ThemeColorBlend(color, TH_BACK, 0.5);
1508 /* generate displist, test for new object */
1509 if(dob_prev && dob_prev->ob != dob->ob) {
1511 glDeleteLists(displist, 1);
1516 /* generate displist */
1517 if(use_displist == -1) {
1519 /* note, since this was added, its checked dob->type==OB_DUPLIGROUP
1520 * however this is very slow, it was probably needed for the NLA
1521 * offset feature (used in group-duplicate.blend but no longer works in 2.5)
1522 * so for now it should be ok to - campbell */
1524 if( (dob_next==NULL || dob_next->ob != dob->ob) || /* if this is the last no need to make a displist */
1525 (dob->ob->type == OB_LAMP) || /* lamp drawing messes with matrices, could be handled smarter... but this works */
1526 (dob->type == OB_DUPLIGROUP && dob->animated) ||
1527 !(bb_tmp= object_get_boundbox(dob->ob))
1529 // printf("draw_dupli_objects_color: skipping displist for %s\n", dob->ob->id.name+2);
1533 // printf("draw_dupli_objects_color: using displist for %s\n", dob->ob->id.name+2);
1534 bb= *bb_tmp; /* must make a copy */
1536 /* disable boundbox check for list creation */
1537 object_boundbox_flag(dob->ob, OB_BB_DISABLED, 1);
1538 /* need this for next part of code */
1539 unit_m4(dob->ob->obmat); /* obmat gets restored */
1541 displist= glGenLists(1);
1542 glNewList(displist, GL_COMPILE);
1543 draw_object(scene, ar, v3d, &tbase, DRAW_CONSTCOLOR);
1547 object_boundbox_flag(dob->ob, OB_BB_DISABLED, 0);
1551 glMultMatrixf(dob->mat);
1552 if(boundbox_clip(rv3d, dob->mat, &bb))
1553 glCallList(displist);
1554 glLoadMatrixf(rv3d->viewmat);
1557 copy_m4_m4(dob->ob->obmat, dob->mat);
1558 draw_object(scene, ar, v3d, &tbase, DRAW_CONSTCOLOR);
1561 tbase.object->dt= dt;
1562 tbase.object->dtx= dtx;
1563 tbase.object->transflag= transflag;
1566 /* Transp afterdraw disabled, afterdraw only stores base pointers, and duplis can be same obj */
1568 free_object_duplilist(lb); /* does restore */
1571 glDeleteLists(displist, 1);
1574 static void draw_dupli_objects(Scene *scene, ARegion *ar, View3D *v3d, Base *base)
1576 /* define the color here so draw_dupli_objects_color can be called
1577 * from the set loop */
1579 int color= (base->flag & SELECT)?TH_SELECT:TH_WIRE;
1581 if(base->object->dup_group && base->object->dup_group->id.us<1)
1584 draw_dupli_objects_color(scene, ar, v3d, base, color);
1587 void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect)
1591 /* clamp rect by area */
1598 /* Constrain rect to depth bounds */
1599 BLI_isect_rcti(&r, rect, rect);
1601 /* assign values to compare with the ViewDepths */
1605 w= rect->xmax - rect->xmin;
1606 h= rect->ymax - rect->ymin;
1608 if(w <= 0 || h <= 0) {
1610 MEM_freeN(d->depths);
1615 else if( d->w != w ||
1627 MEM_freeN(d->depths);
1629 d->depths= MEM_mallocN(sizeof(float)*d->w*d->h,"View depths Subset");
1635 glReadPixels(ar->winrct.xmin+d->x,ar->winrct.ymin+d->y, d->w,d->h, GL_DEPTH_COMPONENT,GL_FLOAT, d->depths);
1636 glGetDoublev(GL_DEPTH_RANGE,d->depth_range);
1641 /* note, with nouveau drivers the glReadPixels() is very slow. [#24339] */
1642 void view3d_update_depths(ARegion *ar)
1644 RegionView3D *rv3d= ar->regiondata;
1646 /* Create storage for, and, if necessary, copy depth buffer */
1647 if(!rv3d->depths) rv3d->depths= MEM_callocN(sizeof(ViewDepths),"ViewDepths");
1649 ViewDepths *d= rv3d->depths;
1650 if(d->w != ar->winx ||
1656 MEM_freeN(d->depths);
1657 d->depths= MEM_mallocN(sizeof(float)*d->w*d->h,"View depths");
1662 glReadPixels(ar->winrct.xmin,ar->winrct.ymin,d->w,d->h,
1663 GL_DEPTH_COMPONENT,GL_FLOAT, d->depths);
1665 glGetDoublev(GL_DEPTH_RANGE,d->depth_range);
1672 /* utility function to find the closest Z value, use for autodepth */
1673 float view3d_depth_near(ViewDepths *d)
1675 /* convert to float for comparisons */
1676 const float near= (float)d->depth_range[0];
1677 const float far_real= (float)d->depth_range[1];
1678 float far= far_real;
1680 const float *depths= d->depths;
1681 float depth= FLT_MAX;
1682 int i= (int)d->w * (int)d->h; /* cast to avoid short overflow */
1684 /* far is both the starting 'far' value
1685 * and the closest value found. */
1688 if((depth < far) && (depth > near)) {
1693 return far == far_real ? FLT_MAX : far;
1696 void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d)
1698 short zbuf= v3d->zbuf;
1699 RegionView3D *rv3d= ar->regiondata;
1701 setwinmatrixview3d(ar, v3d, NULL); /* 0= no pick rect */
1702 setviewmatrixview3d(scene, v3d, rv3d); /* note: calls where_is_object for camera... */
1704 mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat);
1705 invert_m4_m4(rv3d->persinv, rv3d->persmat);
1706 invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
1708 glClear(GL_DEPTH_BUFFER_BIT);
1710 glLoadMatrixf(rv3d->viewmat);
1713 glEnable(GL_DEPTH_TEST);
1715 draw_gpencil_view3d_ext(scene, v3d, ar, 1);
1721 void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *))
1723 RegionView3D *rv3d= ar->regiondata;
1725 short zbuf= v3d->zbuf;
1726 short flag= v3d->flag;
1727 float glalphaclip= U.glalphaclip;
1728 int obcenter_dia= U.obcenter_dia;
1729 /* temp set drawtype to solid */
1731 /* Setting these temporarily is not nice */
1732 v3d->flag &= ~V3D_SELECT_OUTLINE;
1733 U.glalphaclip = 0.5; /* not that nice but means we wont zoom into billboards */
1736 setwinmatrixview3d(ar, v3d, NULL); /* 0= no pick rect */
1737 setviewmatrixview3d(scene, v3d, rv3d); /* note: calls where_is_object for camera... */
1739 mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat);
1740 invert_m4_m4(rv3d->persinv, rv3d->persmat);
1741 invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
1743 glClear(GL_DEPTH_BUFFER_BIT);
1745 glLoadMatrixf(rv3d->viewmat);
1746 // persp(PERSP_STORE); // store correct view for persp(PERSP_VIEW) calls
1748 if(rv3d->rflag & RV3D_CLIPPING) {
1749 view3d_set_clipping(rv3d);
1753 glEnable(GL_DEPTH_TEST);
1755 /* draw set first */
1758 for(SETLOOPER(scene->set, sce_iter, base)) {
1759 if(v3d->lay & base->lay) {
1760 if (func == NULL || func(base)) {
1761 draw_object(scene, ar, v3d, base, 0);
1762 if(base->object->transflag & OB_DUPLI) {
1763 draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
1770 for(base= scene->base.first; base; base= base->next) {
1771 if(v3d->lay & base->lay) {
1772 if (func == NULL || func(base)) {
1774 if(base->object->transflag & OB_DUPLI) {
1775 draw_dupli_objects(scene, ar, v3d, base);
1777 draw_object(scene, ar, v3d, base, 0);
1782 /* this isnt that nice, draw xray objects as if they are normal */
1783 if ( v3d->afterdraw_transp.first ||
1784 v3d->afterdraw_xray.first ||
1785 v3d->afterdraw_xraytransp.first
1787 View3DAfter *v3da, *next;
1792 /* transp materials can change the depth mask, see #21388 */
1793 glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig);
1796 if(v3d->afterdraw_xray.first || v3d->afterdraw_xraytransp.first) {
1797 glDepthFunc(GL_ALWAYS); /* always write into the depth bufer, overwriting front z values */
1798 for(v3da= v3d->afterdraw_xray.first; v3da; v3da= next) {
1800 draw_object(scene, ar, v3d, v3da->base, 0);
1802 glDepthFunc(GL_LEQUAL); /* Now write the depth buffer normally */
1805 /* draw 3 passes, transp/xray/xraytransp */
1808 for(v3da= v3d->afterdraw_transp.first; v3da; v3da= next) {
1810 draw_object(scene, ar, v3d, v3da->base, 0);
1811 BLI_remlink(&v3d->afterdraw_transp, v3da);
1817 for(v3da= v3d->afterdraw_xray.first; v3da; v3da= next) {
1819 draw_object(scene, ar, v3d, v3da->base, 0);
1820 BLI_remlink(&v3d->afterdraw_xray, v3da);
1826 for(v3da= v3d->afterdraw_xraytransp.first; v3da; v3da= next) {
1828 draw_object(scene, ar, v3d, v3da->base, 0);
1829 BLI_remlink(&v3d->afterdraw_xraytransp, v3da);
1837 glDepthMask(mask_orig);
1840 if(rv3d->rflag & RV3D_CLIPPING)
1841 view3d_clr_clipping();
1844 if(!v3d->zbuf) glDisable(GL_DEPTH_TEST);
1846 U.glalphaclip = glalphaclip;
1848 U.obcenter_dia= obcenter_dia;
1851 typedef struct View3DShadow {
1852 struct View3DShadow *next, *prev;
1856 static void gpu_render_lamp_update(Scene *scene, View3D *v3d, Object *ob, Object *par, float obmat[][4], ListBase *shadows)
1859 Lamp *la = (Lamp*)ob->data;
1860 View3DShadow *shadow;
1862 lamp = GPU_lamp_from_blender(scene, ob, par);
1865 GPU_lamp_update(lamp, ob->lay, (ob->restrictflag & OB_RESTRICT_RENDER), obmat);
1866 GPU_lamp_update_colors(lamp, la->r, la->g, la->b, la->energy);
1868 if((ob->lay & v3d->lay) && GPU_lamp_has_shadow_buffer(lamp)) {
1869 shadow= MEM_callocN(sizeof(View3DShadow), "View3DShadow");
1870 shadow->lamp = lamp;
1871 BLI_addtail(shadows, shadow);
1876 static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d)
1879 View3DShadow *shadow;
1884 shadows.first= shadows.last= NULL;
1886 /* update lamp transform and gather shadow lamps */
1887 for(SETLOOPER(scene, sce_iter, base)) {
1890 if(ob->type == OB_LAMP)
1891 gpu_render_lamp_update(scene, v3d, ob, NULL, ob->obmat, &shadows);
1893 if (ob->transflag & OB_DUPLI) {
1895 ListBase *lb = object_duplilist(scene, ob);
1897 for(dob=lb->first; dob; dob=dob->next)
1898 if(dob->ob->type==OB_LAMP)
1899 gpu_render_lamp_update(scene, v3d, dob->ob, ob, dob->mat, &shadows);
1901 free_object_duplilist(lb);
1905 /* render shadows after updating all lamps, nested object_duplilist
1906 * don't work correct since it's replacing object matrices */
1907 for(shadow=shadows.first; shadow; shadow=shadow->next) {
1908 /* this needs to be done better .. */
1909 float viewmat[4][4], winmat[4][4];
1910 int drawtype, lay, winsize, flag2=v3d->flag2;
1912 RegionView3D rv3d= {{{0}}};
1914 drawtype= v3d->drawtype;
1917 v3d->drawtype = OB_SOLID;
1918 v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
1919 v3d->flag2 &= ~V3D_SOLID_TEX;
1920 v3d->flag2 |= V3D_RENDER_OVERRIDE;
1922 GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
1924 ar.regiondata= &rv3d;
1925 ar.regiontype= RGN_TYPE_WINDOW;
1926 rv3d.persp= RV3D_CAMOB;
1927 copy_m4_m4(rv3d.winmat, winmat);
1928 copy_m4_m4(rv3d.viewmat, viewmat);
1929 invert_m4_m4(rv3d.viewinv, rv3d.viewmat);
1930 mul_m4_m4m4(rv3d.persmat, rv3d.viewmat, rv3d.winmat);
1931 invert_m4_m4(rv3d.persinv, rv3d.viewinv);
1933 ED_view3d_draw_offscreen(scene, v3d, &ar, winsize, winsize, viewmat, winmat);
1934 GPU_lamp_shadow_buffer_unbind(shadow->lamp);
1936 v3d->drawtype= drawtype;
1941 BLI_freelistN(&shadows);
1944 /* *********************** customdata **************** */
1946 /* goes over all modes and view3d settings */
1947 CustomDataMask ED_viewedit_datamask(bScreen *screen)
1949 Scene *scene= screen->scene;
1950 Object *ob= scene->basact ? scene->basact->object : NULL;
1951 CustomDataMask mask = CD_MASK_BAREMESH;
1954 /* check if we need tfaces & mcols due to face select or texture paint */
1955 if(paint_facesel_test(ob) || (ob && ob->mode & OB_MODE_TEXTURE_PAINT))
1956 mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
1958 /* check if we need tfaces & mcols due to view mode */
1959 for(sa = screen->areabase.first; sa; sa = sa->next) {
1960 if(sa->spacetype == SPACE_VIEW3D) {
1961 View3D *view = sa->spacedata.first;
1962 if(view->drawtype == OB_SHADED) {
1963 /* this includes normals for mesh_create_shadedColors */
1964 mask |= CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_NORMAL | CD_MASK_ORCO;
1966 if((view->drawtype == OB_TEXTURE) || ((view->drawtype == OB_SOLID) && (view->flag2 & V3D_SOLID_TEX))) {
1967 mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
1969 if(scene->gm.matmode == GAME_MAT_GLSL)
1970 mask |= CD_MASK_ORCO;
1975 /* check if we need mcols due to vertex paint or weightpaint */
1977 if(ob->mode & OB_MODE_VERTEX_PAINT)
1978 mask |= CD_MASK_MCOL;
1979 if(ob->mode & OB_MODE_WEIGHT_PAINT)
1980 mask |= CD_MASK_WEIGHT_MCOL;
1986 static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[][4], float winmat[][4])
1988 RegionView3D *rv3d= ar->regiondata;
1990 /* setup window matrices */
1992 copy_m4_m4(rv3d->winmat, winmat);
1994 setwinmatrixview3d(ar, v3d, NULL); /* NULL= no pickrect */
1996 /* setup view matrix */
1998 copy_m4_m4(rv3d->viewmat, viewmat);
2000 setviewmatrixview3d(scene, v3d, rv3d); /* note: calls where_is_object for camera... */
2002 /* update utilitity matrices */
2003 mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat);
2004 invert_m4_m4(rv3d->persinv, rv3d->persmat);
2005 invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
2007 /* calculate pixelsize factor once, is used for lamps and obcenters */
2009 /* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])'
2010 * because of float point precision problems at large values [#23908] */
2014 v1[0]= rv3d->persmat[0][0];
2015 v1[1]= rv3d->persmat[1][0];
2016 v1[2]= rv3d->persmat[2][0];
2018 v2[0]= rv3d->persmat[0][1];
2019 v2[1]= rv3d->persmat[1][1];
2020 v2[2]= rv3d->persmat[2][1];
2022 len1= 1.0f / len_v3(v1);
2023 len2= 1.0f / len_v3(v2);
2025 rv3d->pixsize = (2.0f * MAX2(len1, len2)) / (float)MAX2(ar->winx, ar->winy);
2028 /* set for opengl */
2029 glMatrixMode(GL_PROJECTION);
2030 glLoadMatrixf(rv3d->winmat);
2031 glMatrixMode(GL_MODELVIEW);
2032 glLoadMatrixf(rv3d->viewmat);
2035 void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy, float viewmat[][4], float winmat[][4])
2044 /* set temporary new size */
2053 ar->winrct.xmax= winx;
2054 ar->winrct.ymax= winy;
2058 G.f |= G_RENDER_OGL;
2060 /* free images which can have changed on frame-change
2061 * warning! can be slow so only free animated images - campbell */
2062 GPU_free_images_anim();
2064 /* shadow buffers, before we setup matrices */
2065 if(draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
2066 gpu_update_lamps_shadows(scene, v3d);
2068 /* set background color, fallback on the view background color */
2070 if(scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
2071 linearrgb_to_srgb_v3_v3(backcol, &scene->world->horr);
2073 copy_v3_v3(backcol, &scene->world->horr);
2074 glClearColor(backcol[0], backcol[1], backcol[2], 0.0);
2077 UI_ThemeClearColor(TH_BACK);
2080 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
2082 /* setup view matrices */
2083 view3d_main_area_setup_view(scene, v3d, ar, viewmat, winmat);
2086 if(v3d->drawtype > OB_WIRE) {
2088 glEnable(GL_DEPTH_TEST);
2093 /* draw set first */
2096 for(SETLOOPER(scene->set, sce_iter, base)) {
2097 if(v3d->lay & base->lay) {
2098 UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
2099 draw_object(scene, ar, v3d, base, DRAW_CONSTCOLOR|DRAW_SCENESET);
2101 if(base->object->transflag & OB_DUPLI)
2102 draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
2107 /* then draw not selected and the duplis, but skip editmode object */
2108 for(base= scene->base.first; base; base= base->next) {
2109 if(v3d->lay & base->lay) {
2111 if(base->object->transflag & OB_DUPLI)
2112 draw_dupli_objects(scene, ar, v3d, base);
2114 draw_object(scene, ar, v3d, base, 0);
2118 /* transp and X-ray afterdraw stuff */
2119 if(v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d);
2120 if(v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, 1); // clears zbuffer if it is used!
2121 if(v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v3d, 1);
2126 glDisable(GL_DEPTH_TEST);
2129 /* draw grease-pencil stuff */
2130 draw_gpencil_view3d_ext(scene, v3d, ar, 1);
2132 ED_region_pixelspace(ar);
2134 /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
2135 draw_gpencil_view3d_ext(scene, v3d, ar, 0);
2137 /* freeing the images again here could be done after the operator runs, leaving for now */
2138 GPU_free_images_anim();
2147 glColor4ub(255, 255, 255, 255); // XXX, without this the sequencer flickers with opengl draw enabled, need to find out why - campbell
2149 G.f &= ~G_RENDER_OGL;
2152 /* utility func for ED_view3d_draw_offscreen */
2153 ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256])
2155 RegionView3D *rv3d= ar->regiondata;
2159 /* state changes make normal drawing go weird otherwise */
2160 glPushAttrib(GL_LIGHTING_BIT);
2163 ofs= GPU_offscreen_create(&sizex, &sizey, err_out);
2167 GPU_offscreen_bind(ofs);
2169 /* render 3d view */
2170 if(rv3d->persp==RV3D_CAMOB && v3d->camera) {
2172 float _clipsta, _clipend, _lens, _yco, _dx, _dy;
2175 object_camera_matrix(&scene->r, v3d->camera, sizex, sizey, 0, winmat, &_viewplane, &_clipsta, &_clipend, &_lens, &_yco, &_dx, &_dy);
2177 ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
2180 ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, NULL);
2183 /* read in pixels & stamp */
2184 ibuf= IMB_allocImBuf(sizex, sizey, 32, flag);
2186 if(ibuf->rect_float)
2187 glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, ibuf->rect_float);
2189 glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2191 //if((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW))
2192 // BKE_stamp_buf(scene, NULL, rr->rectf, rr->rectx, rr->recty, 4);
2195 GPU_offscreen_unbind(ofs);
2196 GPU_offscreen_free(ofs);
2200 if(ibuf->rect_float && ibuf->rect)
2201 IMB_rect_from_float(ibuf);
2206 /* creates own 3d views, used by the sequencer */
2207 ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, int width, int height, unsigned int flag, int drawtype, char err_out[256])
2211 RegionView3D rv3d= {{{0}}};
2214 v3d.regionbase.first= v3d.regionbase.last= &ar;
2215 ar.regiondata= &rv3d;
2216 ar.regiontype= RGN_TYPE_WINDOW;
2218 v3d.camera= scene->camera;
2219 v3d.lay= scene->lay;
2220 v3d.drawtype = drawtype;
2221 v3d.flag2 = V3D_RENDER_OVERRIDE;
2223 rv3d.persp= RV3D_CAMOB;
2225 copy_m4_m4(rv3d.viewinv, v3d.camera->obmat);
2226 normalize_m4(rv3d.viewinv);
2227 invert_m4_m4(rv3d.viewmat, rv3d.viewinv);
2230 float _yco, _dx, _dy;
2232 object_camera_matrix(&scene->r, v3d.camera, width, height, 0, rv3d.winmat, &_viewplane, &v3d.near, &v3d.far, &v3d.lens, &_yco, &_dx, &_dy);
2235 mul_m4_m4m4(rv3d.persmat, rv3d.viewmat, rv3d.winmat);
2236 invert_m4_m4(rv3d.persinv, rv3d.viewinv);
2238 return ED_view3d_draw_offscreen_imbuf(scene, &v3d, &ar, width, height, flag, err_out);
2240 // seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty);
2244 /* NOTE: the info that this uses is updated in ED_refresh_viewport_fps(),
2245 * which currently gets called during SCREEN_OT_animation_step.
2247 static void draw_viewport_fps(Scene *scene, ARegion *ar)
2249 ScreenFrameRateInfo *fpsi= scene->fps_info;
2254 if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime)
2257 printable[0] = '\0';
2260 /* this is too simple, better do an average */
2261 fps = (float)(1.0/(fpsi->lredrawtime-fpsi->redrawtime))
2263 fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0/(fpsi->lredrawtime-fpsi->redrawtime));
2265 for (i=0, tot=0, fps=0.0f ; i < REDRAW_FRAME_AVERAGE ; i++) {
2266 if (fpsi->redrawtimes_fps[i]) {
2267 fps += fpsi->redrawtimes_fps[i];
2272 fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE;
2274 //fpsi->redrawtime_index++;
2275 //if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE)
2276 // fpsi->redrawtime = 0;
2282 /* is this more then half a frame behind? */
2283 if (fps+0.5 < FPS) {
2284 UI_ThemeColor(TH_REDALERT);
2285 BLI_snprintf(printable, sizeof(printable), "fps: %.2f", (float)fps);
2288 UI_ThemeColor(TH_TEXT_HI);
2289 BLI_snprintf(printable, sizeof(printable), "fps: %i", (int)(fps+0.5));
2292 BLF_draw_default(22, ar->winy-17, 0.0f, printable, sizeof(printable)-1);
2295 /* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */
2296 void view3d_main_area_draw(const bContext *C, ARegion *ar)
2298 Scene *scene= CTX_data_scene(C);
2299 View3D *v3d = CTX_wm_view3d(C);
2300 RegionView3D *rv3d= CTX_wm_region_view3d(C);
2304 unsigned int lay_used;
2305 const char *grid_unit= NULL;
2307 /* shadow buffers, before we setup matrices */
2308 if(draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
2309 gpu_update_lamps_shadows(scene, v3d);
2311 /* reset default OpenGL lights if needed (i.e. after preferences have been altered) */
2312 if (rv3d->rflag & RV3D_GPULIGHT_UPDATE) {
2313 rv3d->rflag &= ~RV3D_GPULIGHT_UPDATE;
2314 GPU_default_lights();
2317 /* clear background */
2318 if((v3d->flag2 & V3D_RENDER_OVERRIDE) && scene->world) {
2319 if(scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
2320 linearrgb_to_srgb_v3_v3(backcol, &scene->world->horr);
2322 copy_v3_v3(backcol, &scene->world->horr);
2323 glClearColor(backcol[0], backcol[1], backcol[2], 0.0);
2326 UI_ThemeClearColor(TH_BACK);
2328 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
2330 /* setup view matrices */
2331 view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL);
2333 ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
2335 if(rv3d->rflag & RV3D_CLIPPING)
2336 view3d_draw_clipping(rv3d);
2338 /* set zbuffer after we draw clipping region */
2339 if(v3d->drawtype > OB_WIRE) {
2341 glEnable(GL_DEPTH_TEST);
2346 /* enables anti-aliasing for 3D view drawing */
2347 /*if (!(U.gameflags & USER_DISABLE_AA))
2348 glEnable(GL_MULTISAMPLE_ARB);*/
2350 // needs to be done always, gridview is adjusted in drawgrid() now
2351 rv3d->gridview= v3d->grid;
2353 if(rv3d->view==0 || rv3d->persp != RV3D_ORTHO) {
2354 if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
2355 drawfloor(scene, v3d, &grid_unit);
2357 if(rv3d->persp==RV3D_CAMOB) {
2359 if(scene->world->mode & WO_STARS) {
2360 RE_make_stars(NULL, scene, star_stuff_init_func, star_stuff_vertex_func,
2361 star_stuff_term_func);
2364 if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
2365 if(v3d->flag & V3D_DISPBGPICS) draw_bgpic(scene, ar, v3d);
2370 if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
2371 ED_region_pixelspace(ar);
2372 drawgrid(&scene->unit, ar, v3d, &grid_unit);
2373 /* XXX make function? replaces persp(1) */
2374 glMatrixMode(GL_PROJECTION);
2375 glLoadMatrixf(rv3d->winmat);
2376 glMatrixMode(GL_MODELVIEW);
2377 glLoadMatrixf(rv3d->viewmat);
2379 if(v3d->flag & V3D_DISPBGPICS) {
2380 draw_bgpic(scene, ar, v3d);
2385 if(rv3d->rflag & RV3D_CLIPPING)
2386 view3d_set_clipping(rv3d);
2388 /* draw set first */
2391 for(SETLOOPER(scene->set, sce_iter, base)) {
2393 if(v3d->lay & base->lay) {
2395 UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
2396 draw_object(scene, ar, v3d, base, DRAW_CONSTCOLOR|DRAW_SCENESET);
2398 if(base->object->transflag & OB_DUPLI) {
2399 draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
2404 /* Transp and X-ray afterdraw stuff for sets is done later */
2409 /* then draw not selected and the duplis, but skip editmode object */
2410 for(base= scene->base.first; base; base= base->next) {
2411 lay_used |= base->lay & ((1<<20)-1);
2413 if(v3d->lay & base->lay) {
2416 if(base->object->transflag & OB_DUPLI) {
2417 draw_dupli_objects(scene, ar, v3d, base);
2419 if((base->flag & SELECT)==0) {
2420 if(base->object!=scene->obedit)
2421 draw_object(scene, ar, v3d, base, 0);
2426 if(v3d->lay_used != lay_used) { /* happens when loading old files or loading with UI load */
2428 ScrArea *sa= CTX_wm_area(C);
2430 /* find header and force tag redraw */
2431 for(ar_iter= sa->regionbase.first; ar_iter; ar_iter= ar_iter->next)
2432 if(ar_iter->regiontype==RGN_TYPE_HEADER) {
2433 ED_region_tag_redraw(ar_iter);
2437 v3d->lay_used= lay_used;
2440 /* draw selected and editmode */
2441 for(base= scene->base.first; base; base= base->next) {
2442 if(v3d->lay & base->lay) {
2443 if (base->object==scene->obedit || ( base->flag & SELECT) )
2444 draw_object(scene, ar, v3d, base, 0);
2450 /* Transp and X-ray afterdraw stuff */
2451 if(v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d);
2452 if(v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, 1); // clears zbuffer if it is used!
2453 if(v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v3d, 1);
2455 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
2457 if(rv3d->rflag & RV3D_CLIPPING)
2458 view3d_clr_clipping();
2460 BIF_draw_manipulator(C);
2462 /* Disable back anti-aliasing */
2463 /*if (!(U.gameflags & USER_DISABLE_AA))
2464 glDisable(GL_MULTISAMPLE_ARB);*/
2468 glDisable(GL_DEPTH_TEST);
2471 if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
2472 /* draw grease-pencil stuff (3d-space strokes) */
2473 //if (v3d->flag2 & V3D_DISPGP)
2474 draw_gpencil_view3d((bContext *)C, 1);
2479 ED_region_pixelspace(ar);
2481 // retopo_paint_view_update(v3d);
2482 // retopo_draw_paint_lines();
2484 /* Draw particle edit brush XXX (removed) */
2487 if(rv3d->persp==RV3D_CAMOB)
2488 drawviewborder(scene, ar, v3d);
2490 if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
2491 /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
2492 // if (v3d->flag2 & V3D_DISPGP)
2493 draw_gpencil_view3d((bContext *)C, 0);
2495 drawcursor(scene, ar, v3d);
2498 if(U.uiflag & USER_SHOW_ROTVIEWICON)
2499 draw_view_axis(rv3d);
2501 draw_view_icon(rv3d);
2503 if((U.uiflag & USER_SHOW_FPS) && (CTX_wm_screen(C)->animtimer)) {
2504 draw_viewport_fps(scene, ar);
2506 else if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
2507 draw_viewport_name(ar, v3d);
2509 if (grid_unit) { /* draw below the viewport name */
2512 UI_ThemeColor(TH_TEXT_HI);
2513 if(v3d->grid != 1.0f) {
2514 BLI_snprintf(tstr, sizeof(tstr), "%s x %.4g", grid_unit, v3d->grid);
2517 BLF_draw_default(22, ar->winy-(USER_SHOW_VIEWPORTNAME?40:20), 0.0f, tstr[0]?tstr : grid_unit, sizeof(tstr)); /* XXX, use real length */
2521 if(U.uiflag & USER_DRAWVIEWINFO)
2522 draw_selected_name(scene, ob, v3d);
2524 /* XXX here was the blockhandlers for floating panels */
2526 v3d->flag |= V3D_INVALID_BACKBUF;