diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_draw.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 215 |
1 files changed, 123 insertions, 92 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 176ef119cb9..2c85dc62edb 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -331,7 +331,9 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char ** if (dx < GRID_MIN_PX_D) { rv3d->gridview *= sublines; dx *= sublines; - if (dx < GRID_MIN_PX_D) ; + if (dx < GRID_MIN_PX_D) { + /* pass */ + } else { UI_ThemeColor(TH_GRID); drawgrid_draw(ar, wx, wy, x, y, dx); @@ -513,7 +515,7 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) GPU_print_error("sdsd"); } - /* draw the Z axis line */ + /* draw the Z axis line */ /* check for the 'show Z axis' preference */ if (v3d->gridflag & (V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) { int axis; @@ -540,12 +542,8 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) gpuEnd(); gpuImmediateUnformat(); } - - - - - if (v3d->zbuf && scene->obedit) glDepthMask(1); + if (v3d->zbuf && scene->obedit) glDepthMask(1); } static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d) @@ -553,7 +551,7 @@ static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d) int co[2]; /* we don't want the clipping for cursor */ - if (ED_view3d_project_int_global(ar, give_cursor(scene, v3d), co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) { + if (ED_view3d_project_int_global(ar, give_cursor(scene, v3d), co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { gpuImmediateFormat_V2(); // DOODLE: view3d cursor, 2 stippled circles, 4 mono lines setlinestyle(0); @@ -640,7 +638,7 @@ static void draw_view_axis(RegionView3D *rv3d) /* axis alpha (rvibright has range 0-10) */ const int bright = 25*U.rvibright + U.rvibright/51; - + float axis[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, @@ -656,12 +654,8 @@ static void draw_view_axis(RegionView3D *rv3d) const unsigned char label[] = "xyz"; GLboolean showLabel[3]; - const GLubyte color[3][4] = { - { 220, 0, 0, bright }, - { 0, 220, 0, bright }, - { 30, 30, 220, bright }, - }; - + GLubyte color[3][4]; + const GLfloat jitter[4][3] = { { -size/2, 0, 0 }, { 0, -size/2, 0 }, @@ -673,6 +667,12 @@ static void draw_view_axis(RegionView3D *rv3d) int i; + UI_GetThemeColor3ubv(TH_AXIS_X, color[0]); + UI_GetThemeColor3ubv(TH_AXIS_Y, color[1]); + UI_GetThemeColor3ubv(TH_AXIS_Z, color[2]); + + color[0][3] = color[1][3] = color [2][3] = bright; + for (i = 0; i < 3; i++) { mul_qt_v3(rv3d->viewquat, axis[i]); mul_qt_v3(rv3d->viewquat, offset[i]); @@ -1111,7 +1111,7 @@ static void drawviewborder_triangle(float x1, float x2, float y1, float y2, cons static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) { - float fac, a; + float hmargin, vmargin; float x1, x2, y1, y2; float x1i, x2i, y1i, y2i; float x3, y3, x4, y4; @@ -1263,20 +1263,15 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) gpuImmediateUnformat(); if (ca->flag & CAM_SHOWTITLESAFE) { - fac = 0.1; - - a = fac * (x2 - x1); - x1 += a; - x2 -= a; - - a = fac * (y2 - y1); - y1 += a; - y2 -= a; - UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0); - uiSetRoundBox(UI_CNR_ALL); - uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0); + hmargin = 0.1f * (x2 - x1); + vmargin = 0.05f * (y2 - y1); + uiDrawBox(GL_LINE_LOOP, x1 + hmargin, y1 + vmargin, x2 - hmargin, y2 - vmargin, 2.0f); + + hmargin = 0.035f * (x2 - x1); + vmargin = 0.035f * (y2 - y1); + uiDrawBox(GL_LINE_LOOP, x1 + hmargin, y1+vmargin, x2 - hmargin, y2 - vmargin, 2.0f); } if (ca && (ca->flag & CAM_SHOWSENSOR)) { /* determine sensor fit, and get sensor x/y, for auto fit we @@ -1477,7 +1472,7 @@ ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax, (ymaxc - yminc + 1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); - glReadBuffer(GL_BACK); + glReadBuffer(GL_BACK); if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); @@ -1510,7 +1505,7 @@ ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax, /* smart function to sample a rect spiralling outside, nice for backbuf selection */ unsigned int view3d_sample_backbuf_rect(ViewContext *vc, const int mval[2], int size, - unsigned int min, unsigned int max, int *dist, short strict, + unsigned int min, unsigned int max, float *r_dist, short strict, void *handle, unsigned int (*indextest)(void *handle, unsigned int index)) { struct ImBuf *buf; @@ -1519,7 +1514,7 @@ unsigned int view3d_sample_backbuf_rect(ViewContext *vc, const int mval[2], int int a, b, rc, nr, amount, dirvec[4][2]; int distance = 0; unsigned int index = 0; - short indexok = 0; + short indexok = 0; amount = (size - 1) / 2; @@ -1548,13 +1543,13 @@ unsigned int view3d_sample_backbuf_rect(ViewContext *vc, const int mval[2], int if (strict) { indexok = indextest(handle, *tbuf - min + 1); if (indexok) { - *dist = (short) sqrt( (float)distance); + *r_dist = sqrtf((float)distance); index = *tbuf - min + 1; goto exit; } } else { - *dist = (short) sqrt( (float)distance); /* XXX, this distance is wrong - */ + *r_dist = sqrtf((float)distance); /* XXX, this distance is wrong - */ index = *tbuf - min + 1; /* messy yah, but indices start at 1 */ goto exit; } @@ -1688,7 +1683,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, /* apply offset last - camera offset is different to offset in blender units */ /* so this has some sane way of working - this matches camera's shift _exactly_ */ { - const float max_dim = maxf(x2 - x1, y2 - y1); + const float max_dim = max_ff(x2 - x1, y2 - y1); const float xof_scale = bgpic->xof * max_dim; const float yof_scale = bgpic->yof * max_dim; @@ -1737,7 +1732,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, /* calc window coord */ initgrabz(rv3d, 0.0, 0.0, 0.0); ED_view3d_win_to_delta(ar, mval_f, tvec); - fac = maxf(fabsf(tvec[0]), maxf(fabsf(tvec[1]), fabsf(tvec[2]))); /* largest abs axis */ + fac = max_ff(fabsf(tvec[0]), max_ff(fabsf(tvec[1]), fabsf(tvec[2]))); /* largest abs axis */ fac = 1.0f / fac; asp = (float)ibuf->y / (float)ibuf->x; @@ -1765,7 +1760,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */ if (zoomx < 1.0f || zoomy < 1.0f) { - float tzoom = minf(zoomx, zoomy); + float tzoom = min_ff(zoomx, zoomy); int mip = 0; if ((ibuf->userflags & IB_MIPMAP_INVALID) != 0) { @@ -2071,7 +2066,7 @@ static void draw_dupli_objects(Scene *scene, ARegion *ar, View3D *v3d, Base *bas void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect) { - int x, y, w, h; + int x, y, w, h; rcti r; /* clamp rect by area */ @@ -2169,7 +2164,7 @@ float view3d_depth_near(ViewDepths *d) int i = (int)d->w * (int)d->h; /* cast to avoid short overflow */ /* far is both the starting 'far' value - * and the closest value found. */ + * and the closest value found. */ while (i--) { depth = *depths++; if ((depth < far) && (depth > near)) { @@ -2185,7 +2180,7 @@ void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d) short zbuf = v3d->zbuf; RegionView3D *rv3d = ar->regiondata; - setwinmatrixview3d(ar, v3d, NULL); /* 0= no pick rect */ + setwinmatrixview3d(ar, v3d, NULL); setviewmatrixview3d(scene, v3d, rv3d); /* note: calls BKE_object_where_is_calc for camera... */ mult_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); @@ -2220,7 +2215,7 @@ void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (*func)(void *)) U.glalphaclip = 0.5; /* not that nice but means we wont zoom into billboards */ U.obcenter_dia = 0; - setwinmatrixview3d(ar, v3d, NULL); /* 0= no pick rect */ + setwinmatrixview3d(ar, v3d, NULL); setviewmatrixview3d(scene, v3d, rv3d); /* note: calls BKE_object_where_is_calc for camera... */ mult_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); @@ -2418,6 +2413,7 @@ static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d) mult_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat); invert_m4_m4(rv3d.persinv, rv3d.viewinv); + /* no need to call ED_view3d_draw_offscreen_init since shadow buffers were already updated */ ED_view3d_draw_offscreen(scene, v3d, &ar, winsize, winsize, viewmat, winmat, FALSE, FALSE); GPU_lamp_shadow_buffer_unbind(shadow->lamp); @@ -2507,7 +2503,7 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view if (winmat) copy_m4_m4(rv3d->winmat, winmat); else - setwinmatrixview3d(ar, v3d, NULL); /* NULL= no pickrect */ + setwinmatrixview3d(ar, v3d, NULL); /* setup view matrix */ if (viewmat) @@ -2525,7 +2521,7 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view /* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])' * because of float point precision problems at large values [#23908] */ float v1[3], v2[3]; - float len1, len2; + float len_px, len_sc; v1[0] = rv3d->persmat[0][0]; v1[1] = rv3d->persmat[1][0]; @@ -2535,10 +2531,10 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view v2[1] = rv3d->persmat[1][1]; v2[2] = rv3d->persmat[2][1]; - len1 = 1.0f / len_v3(v1); - len2 = 1.0f / len_v3(v2); + len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2))); + len_sc = (float)MAX2(ar->winx, ar->winy); - rv3d->pixsize = (2.0f * MAX2(len1, len2)) / (float)MAX2(ar->winx, ar->winy); + rv3d->pixsize = len_px / len_sc; } } @@ -2555,6 +2551,16 @@ static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar, gpuLoadMatrix(rv3d->viewmat); } +void ED_view3d_draw_offscreen_init(Scene *scene, View3D *v3d) +{ + /* shadow buffers, before we setup matrices */ + if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype)) + gpu_update_lamps_shadows(scene, v3d); +} + +/* ED_view3d_draw_offscreen_init should be called before this to initialize + * stuff like shadow buffers + */ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy, float viewmat[][4], float winmat[][4], int do_bgpic, int colormanage_background) @@ -2588,10 +2594,6 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, /* free images which can have changed on frame-change * warning! can be slow so only free animated images - campbell */ GPU_free_images_anim(); - - /* shadow buffers, before we setup matrices */ - if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype)) - gpu_update_lamps_shadows(scene, v3d); /* set background color, fallback on the view background color * (if active clip is set but frame is failed to load fallback to horizon color as background) */ @@ -2734,6 +2736,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, if (ofs == NULL) return NULL; + ED_view3d_draw_offscreen_init(scene, v3d); + GPU_offscreen_bind(ofs); /* render 3d view */ @@ -2862,7 +2866,7 @@ static void draw_viewport_fps(Scene *scene, ARegion *ar) if (fps + 0.5f < (float)(FPS)) { UI_ThemeColor(TH_REDALERT); BLI_snprintf(printable, sizeof(printable), "fps: %.2f", fps); - } + } else { UI_ThemeColor(TH_TEXT_HI); BLI_snprintf(printable, sizeof(printable), "fps: %i", (int)(fps + 0.5f)); @@ -2900,8 +2904,8 @@ static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar, int draw engine = RE_engine_create(type); - engine->tile_x = ceil(ar->winx / (float)scene->r.xparts); - engine->tile_y = ceil(ar->winy / (float)scene->r.yparts); + engine->tile_x = scene->r.tilex; + engine->tile_y = scene->r.tiley; type->view_update(engine, C); @@ -2919,12 +2923,20 @@ static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar, int draw rctf viewborder; rcti cliprct; - ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, FALSE); + if (rv3d->persp == RV3D_CAMOB) { + ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, FALSE); - cliprct.xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder); - cliprct.ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder); - cliprct.xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder); - cliprct.ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder); + cliprct.xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder); + cliprct.ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder); + cliprct.xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder); + cliprct.ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder); + } + else { + cliprct.xmin = v3d->render_border.xmin * ar->winx; + cliprct.xmax = v3d->render_border.xmax * ar->winx; + cliprct.ymin = v3d->render_border.ymin * ar->winy; + cliprct.ymax = v3d->render_border.ymax * ar->winy; + } cliprct.xmin += ar->winrct.xmin; cliprct.xmax += ar->winrct.xmin; @@ -3024,10 +3036,10 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const v3d->zbuf = FALSE; /* enables anti-aliasing for 3D view drawing */ -#if 0 - if (!(U.gameflags & USER_DISABLE_AA)) - glEnable(GL_MULTISAMPLE_ARB); -#endif + if (U.ogl_multisamples) + if (!(U.gameflags & USER_DISABLE_AA)) + glEnable(GL_MULTISAMPLE_ARB); + /* needs to be done always, gridview is adjusted in drawgrid() now */ rv3d->gridview = v3d->grid; @@ -3140,12 +3152,12 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const BIF_draw_manipulator(C); -#if 0 /* Disable back anti-aliasing */ - if (!(U.gameflags & USER_DISABLE_AA)) - glDisable(GL_MULTISAMPLE_ARB); -#endif + if (U.ogl_multisamples) + if (!(U.gameflags & USER_DISABLE_AA)) + glDisable(GL_MULTISAMPLE_ARB); + if (v3d->zbuf) { v3d->zbuf = FALSE; glDisable(GL_DEPTH_TEST); @@ -3168,50 +3180,64 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - Object *ob; - - if (rv3d->persp == RV3D_CAMOB) + if (rv3d->persp == RV3D_CAMOB) { drawviewborder(scene, ar, v3d); + } + else if (v3d->flag2 & V3D_RENDER_BORDER) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + setlinestyle(3); + gpuColor3x(0x4040FF); + + glRectf(v3d->render_border.xmin * ar->winx, v3d->render_border.ymin * ar->winy, + v3d->render_border.xmax * ar->winx, v3d->render_border.ymax * ar->winy); + + setlinestyle(0); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { + Object *ob; + /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ // if (v3d->flag2 & V3D_DISPGP) draw_gpencil_view3d(scene, v3d, ar, 0); drawcursor(scene, ar, v3d); + + if (U.uiflag & USER_SHOW_ROTVIEWICON) + draw_view_axis(rv3d); + else + draw_view_icon(rv3d); + + ob = OBACT; + if (U.uiflag & USER_DRAWVIEWINFO) + draw_selected_name(scene, ob); } - - if (U.uiflag & USER_SHOW_ROTVIEWICON) - draw_view_axis(rv3d); - else - draw_view_icon(rv3d); - - ob = OBACT; - if (U.uiflag & USER_DRAWVIEWINFO) - draw_selected_name(scene, ob); if (rv3d->render_engine) { view3d_main_area_draw_engine_info(rv3d, ar); return; } - if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_playing(wm)) { - draw_viewport_fps(scene, ar); - } - else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { - draw_viewport_name(ar, v3d); - } + if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { + if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_playing(wm)) { + draw_viewport_fps(scene, ar); + } + else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { + draw_viewport_name(ar, v3d); + } - if (grid_unit) { /* draw below the viewport name */ - char numstr[32] = ""; + if (grid_unit) { /* draw below the viewport name */ + char numstr[32] = ""; - UI_ThemeColor(TH_TEXT_HI); - if (v3d->grid != 1.0f) { - BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid); - } + UI_ThemeColor(TH_TEXT_HI); + if (v3d->grid != 1.0f) { + BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid); + } - BLF_draw_default_ascii(22, ar->winy - (USER_SHOW_VIEWPORTNAME ? 40 : 20), 0.0f, - numstr[0] ? numstr : grid_unit, sizeof(numstr)); + BLF_draw_default_ascii(22, ar->winy - (USER_SHOW_VIEWPORTNAME ? 40 : 20), 0.0f, + numstr[0] ? numstr : grid_unit, sizeof(numstr)); + } } } @@ -3221,7 +3247,12 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); const char *grid_unit = NULL; - int draw_border = (rv3d->persp == RV3D_CAMOB && (scene->r.mode & R_BORDER)); + int draw_border = FALSE; + + if (rv3d->persp == RV3D_CAMOB) + draw_border = scene->r.mode & R_BORDER; + else + draw_border = v3d->flag2 & V3D_RENDER_BORDER; /* draw viewport using opengl */ if (v3d->drawtype != OB_RENDER || !view3d_main_area_do_render_draw(C) || draw_border) { |