diff options
author | Ton Roosendaal <ton@blender.org> | 2018-04-19 18:34:44 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-19 18:35:25 +0300 |
commit | 51b796ff1528c52cc8b4079fab1003671652a4d9 (patch) | |
tree | 0dfc2d2dabe5e77959264f5b6667897569290a41 /source/blender/editors/space_view3d/view3d_draw.c | |
parent | 785e8a636a293941a4295e669cb5aeecfafae039 (diff) |
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_draw.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 848 |
1 files changed, 19 insertions, 829 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 1910f7e27c0..5316520ccab 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -98,23 +98,6 @@ /* ******************** general functions ***************** */ -static bool use_depth_doit(View3D *v3d, Object *obedit) -{ - if (v3d->drawtype > OB_WIRE) - return true; - - /* special case (depth for wire color) */ - if (v3d->drawtype <= OB_WIRE) { - if (obedit && obedit->type == OB_MESH) { - Mesh *me = obedit->data; - if (me->drawflag & ME_DRAWEIGHT) { - return true; - } - } - } - return false; -} - /** * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore */ @@ -742,16 +725,7 @@ void ED_view3d_draw_depth( v3d->zbuf = true; glEnable(GL_DEPTH_TEST); -#ifdef WITH_OPENGL_LEGACY - if (IS_VIEWPORT_LEGACY(vc->v3d)) { - /* temp, calls into view3d_draw_legacy.c */ - ED_view3d_draw_depth_loop(scene, ar, v3d); - } - else -#endif /* WITH_OPENGL_LEGACY */ - { - DRW_draw_depth_loop(depsgraph, ar, v3d); - } + DRW_draw_depth_loop(depsgraph, ar, v3d); if (rv3d->rflag & RV3D_CLIPPING) { ED_view3d_clipping_disable(); @@ -768,536 +742,8 @@ void ED_view3d_draw_depth( UI_Theme_Restore(&theme_state); } -/* ******************** background plates ***************** */ - -static void view3d_draw_background_gradient(void) -{ - /* TODO: finish 2D API & draw background with that */ - - Gwn_VertFormat *format = immVertexFormat(); - unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT); - unsigned char col_hi[3], col_lo[3]; - - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); - - UI_GetThemeColor3ubv(TH_LOW_GRAD, col_lo); - UI_GetThemeColor3ubv(TH_HIGH_GRAD, col_hi); - - immBegin(GWN_PRIM_TRI_FAN, 4); - immAttrib3ubv(color, col_lo); - immVertex2f(pos, -1.0f, -1.0f); - immVertex2f(pos, 1.0f, -1.0f); - - immAttrib3ubv(color, col_hi); - immVertex2f(pos, 1.0f, 1.0f); - immVertex2f(pos, -1.0f, 1.0f); - immEnd(); - - immUnbindProgram(); -} - -static void view3d_draw_background_none(void) -{ - UI_ThemeClearColorAlpha(TH_HIGH_GRAD, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); -} - -static void view3d_draw_background_world(Scene *scene, RegionView3D *rv3d) -{ - if (scene->world) { - GPUMaterial *gpumat = GPU_material_world(scene, scene->world); - - /* calculate full shader for background */ - GPU_material_bind(gpumat, 1, 1, 1.0f, false, rv3d->viewmat, rv3d->viewinv, rv3d->viewcamtexcofac); - - if (GPU_material_bound(gpumat)) { - /* TODO viewport (dfelinto): GPU_material_bind relies on immediate mode, - * we can't get rid of the following code without a bigger refactor - * or we dropping this functionality. */ - - glBegin(GL_TRIANGLE_STRIP); - glVertex2f(-1.0f, -1.0f); - glVertex2f(1.0f, -1.0f); - glVertex2f(-1.0f, 1.0f); - glVertex2f(1.0f, 1.0f); - glEnd(); - - GPU_material_unbind(gpumat); - return; - } - } - - /* if any of the above fails */ - view3d_draw_background_none(); -} - /* ******************** other elements ***************** */ - -#define DEBUG_GRID 0 - -static void gridline_range(double x0, double dx, double max, int *r_first, int *r_count) -{ - /* determine range of gridlines that appear in this Area -- similar calc but separate ranges for x & y - * x0 is gridline 0, the axis in screen space - * Area covers [0 .. max) pixels */ - - int first = (int)ceil(-x0 / dx); - int last = (int)floor((max - x0) / dx); - - if (first <= last) { - *r_first = first; - *r_count = last - first + 1; - } - else { - *r_first = 0; - *r_count = 0; - } - -#if DEBUG_GRID - printf(" first %d * dx = %f\n", first, x0 + first * dx); - printf(" last %d * dx = %f\n", last, x0 + last * dx); - printf(" count = %d\n", *count_out); -#endif -} - -static int gridline_count(ARegion *ar, double x0, double y0, double dx) -{ - /* x0 & y0 establish the "phase" of the grid within this 2D region - * dx is the frequency, shared by x & y directions - * pass in dx of smallest (highest precision) grid we want to draw */ - -#if DEBUG_GRID - printf(" %s(%f, %f, dx:%f)\n", __FUNCTION__, x0, y0, dx); -#endif - - int first, x_ct, y_ct; - - gridline_range(x0, dx, ar->winx, &first, &x_ct); - gridline_range(y0, dx, ar->winy, &first, &y_ct); - - int total_ct = x_ct + y_ct; - -#if DEBUG_GRID - printf(" %d + %d = %d gridlines\n", x_ct, y_ct, total_ct); -#endif - - return total_ct; -} - -static bool drawgrid_draw(ARegion *ar, double x0, double y0, double dx, int skip_mod, unsigned pos, unsigned col, GLubyte col_value[3]) -{ - /* skip every skip_mod lines relative to each axis; they will be overlaid by another drawgrid_draw - * always skip exact x0 & y0 axes; they will be drawn later in color - * - * set grid color once, just before the first line is drawn - * it's harmless to set same color for every line, or every vertex - * but if no lines are drawn, color must not be set! */ - -#if DEBUG_GRID - printf(" %s(%f, %f, dx:%f, skip_mod:%d)\n", __FUNCTION__, x0, y0, dx, skip_mod); -#endif - - const float x_max = (float)ar->winx; - const float y_max = (float)ar->winy; - - int first, ct; - int x_ct = 0, y_ct = 0; /* count of lines actually drawn */ - int lines_skipped_for_next_unit = 0; - - /* draw vertical lines */ - gridline_range(x0, dx, x_max, &first, &ct); - - for (int i = first; i < first + ct; ++i) { - if (i == 0) - continue; - else if (skip_mod && (i % skip_mod) == 0) { - ++lines_skipped_for_next_unit; - continue; - } - - if (x_ct == 0) - immAttrib3ub(col, col_value[0], col_value[1], col_value[2]); - - float x = (float)(x0 + i * dx); - immVertex2f(pos, x, 0.0f); - immVertex2f(pos, x, y_max); - ++x_ct; - } - - /* draw horizontal lines */ - gridline_range(y0, dx, y_max, &first, &ct); - - for (int i = first; i < first + ct; ++i) { - if (i == 0) - continue; - else if (skip_mod && (i % skip_mod) == 0) { - ++lines_skipped_for_next_unit; - continue; - } - - if (x_ct + y_ct == 0) - immAttrib3ub(col, col_value[0], col_value[1], col_value[2]); - - float y = (float)(y0 + i * dx); - immVertex2f(pos, 0.0f, y); - immVertex2f(pos, x_max, y); - ++y_ct; - } - -#if DEBUG_GRID - int total_ct = x_ct + y_ct; - printf(" %d + %d = %d gridlines drawn, %d skipped for next unit\n", x_ct, y_ct, total_ct, lines_skipped_for_next_unit); -#endif - - return lines_skipped_for_next_unit > 0; -} - -#define GRID_MIN_PX_D 6.0 -#define GRID_MIN_PX_F 6.0f - -static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit) -{ - RegionView3D *rv3d = ar->regiondata; - -#if DEBUG_GRID - printf("%s width %d, height %d\n", __FUNCTION__, ar->winx, ar->winy); -#endif - - double fx = rv3d->persmat[3][0]; - double fy = rv3d->persmat[3][1]; - double fw = rv3d->persmat[3][3]; - - const double wx = 0.5 * ar->winx; /* use double precision to avoid rounding errors */ - const double wy = 0.5 * ar->winy; - - double x = wx * fx / fw; - double y = wy * fy / fw; - - double vec4[4] = { v3d->grid, v3d->grid, 0.0, 1.0 }; - mul_m4_v4d(rv3d->persmat, vec4); - fx = vec4[0]; - fy = vec4[1]; - fw = vec4[3]; - - double dx = fabs(x - wx * fx / fw); - if (dx == 0) dx = fabs(y - wy * fy / fw); - - x += wx; - y += wy; - - /* now x, y, and dx have their final values - * (x,y) is the world origin (0,0,0) mapped to Area-relative screen space - * dx is the distance in pixels between grid lines -- same for horiz or vert grid lines */ - - glLineWidth(1.0f); - -#if 0 /* TODO: write to UI/widget depth buffer, not scene depth */ - glDepthMask(GL_FALSE); /* disable write in zbuffer */ -#endif - - Gwn_VertFormat *format = immVertexFormat(); - unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT); - - immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); - - unsigned char col[3], col2[3]; - UI_GetThemeColor3ubv(TH_GRID, col); - - if (unit->system) { - const void *usys; - int len; - - bUnit_GetSystem(unit->system, B_UNIT_LENGTH, &usys, &len); - - bool first = true; - - if (usys) { - int i = len; - while (i--) { - double scalar = bUnit_GetScaler(usys, i); - - double dx_scalar = dx * scalar / (double)unit->scale_length; - if (dx_scalar < (GRID_MIN_PX_D * 2.0)) { - /* very very small grid items are less useful when dealing with units */ - continue; - } - - if (first) { - first = false; - - /* Store the smallest drawn grid size units name so users know how big each grid cell is */ - *grid_unit = bUnit_GetNameDisplay(usys, i); - rv3d->gridview = (float)((scalar * (double)v3d->grid) / (double)unit->scale_length); - - int gridline_ct = gridline_count(ar, x, y, dx_scalar); - if (gridline_ct == 0) - goto drawgrid_cleanup; /* nothing to draw */ - - immBegin(GWN_PRIM_LINES, gridline_ct * 2); - } - - float blend_fac = 1.0f - ((GRID_MIN_PX_F * 2.0f) / (float)dx_scalar); - /* tweak to have the fade a bit nicer */ - blend_fac = (blend_fac * blend_fac) * 2.0f; - CLAMP(blend_fac, 0.3f, 1.0f); - - UI_GetThemeColorBlend3ubv(TH_HIGH_GRAD, TH_GRID, blend_fac, col2); - - const int skip_mod = (i == 0) ? 0 : (int)round(bUnit_GetScaler(usys, i - 1) / scalar); -#if DEBUG_GRID - printf("%s %f, ", bUnit_GetNameDisplay(usys, i), scalar); - if (i > 0) - printf("next unit is %d times larger\n", skip_mod); - else - printf("largest unit\n"); -#endif - if (!drawgrid_draw(ar, x, y, dx_scalar, skip_mod, pos, color, col2)) - break; - } - } - } - else { - const double sublines = v3d->gridsubdiv; - const float sublines_fl = v3d->gridsubdiv; - - int grids_to_draw = 2; /* first the faint fine grid, then the bold coarse grid */ - - if (dx < GRID_MIN_PX_D) { - rv3d->gridview *= sublines_fl; - dx *= sublines; - if (dx < GRID_MIN_PX_D) { - rv3d->gridview *= sublines_fl; - dx *= sublines; - if (dx < GRID_MIN_PX_D) { - rv3d->gridview *= sublines_fl; - dx *= sublines; - grids_to_draw = (dx < GRID_MIN_PX_D) ? 0 : 1; - } - } - } - else { - if (dx > (GRID_MIN_PX_D * 10.0)) { /* start blending in */ - rv3d->gridview /= sublines_fl; - dx /= sublines; - if (dx > (GRID_MIN_PX_D * 10.0)) { /* start blending in */ - rv3d->gridview /= sublines_fl; - dx /= sublines; - if (dx > (GRID_MIN_PX_D * 10.0)) { - grids_to_draw = 1; - } - } - } - } - - int gridline_ct = gridline_count(ar, x, y, dx); - if (gridline_ct == 0) - goto drawgrid_cleanup; /* nothing to draw */ - - immBegin(GWN_PRIM_LINES, gridline_ct * 2); - - if (grids_to_draw == 2) { - UI_GetThemeColorBlend3ubv(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0), col2); - if (drawgrid_draw(ar, x, y, dx, v3d->gridsubdiv, pos, color, col2)) - drawgrid_draw(ar, x, y, dx * sublines, 0, pos, color, col); - } - else if (grids_to_draw == 1) { - drawgrid_draw(ar, x, y, dx, 0, pos, color, col); - } - } - - /* draw visible axes */ - /* horizontal line */ - if (0 <= y && y < ar->winy) { - UI_make_axis_color(col, col2, ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT) ? 'Y' : 'X'); - immAttrib3ub(color, col2[0], col2[1], col2[2]); - immVertex2f(pos, 0.0f, y); - immVertex2f(pos, (float)ar->winx, y); - } - - /* vertical line */ - if (0 <= x && x < ar->winx) { - UI_make_axis_color(col, col2, ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM) ? 'Y' : 'Z'); - immAttrib3ub(color, col2[0], col2[1], col2[2]); - immVertex2f(pos, x, 0.0f); - immVertex2f(pos, x, (float)ar->winy); - } - - immEnd(); - -drawgrid_cleanup: - immUnbindProgram(); - -#if 0 /* depth write is left enabled above */ - glDepthMask(GL_TRUE); /* enable write in zbuffer */ -#endif -} - -#undef DEBUG_GRID -#undef GRID_MIN_PX_D -#undef GRID_MIN_PX_F - -static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool write_depth) -{ - /* draw only if there is something to draw */ - if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) { - /* draw how many lines? - * trunc(v3d->gridlines / 2) * 4 - * + 2 for xy axes (possibly with special colors) - * + 1 for z axis (the only line not in xy plane) - * even v3d->gridlines are honored, odd rounded down */ - const int gridlines = v3d->gridlines / 2; - const float grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit); - const float grid = gridlines * grid_scale; - - const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) && gridlines >= 1; - - bool show_axis_x = v3d->gridflag & V3D_SHOW_X; - bool show_axis_y = v3d->gridflag & V3D_SHOW_Y; - bool show_axis_z = v3d->gridflag & V3D_SHOW_Z; - - unsigned char col_grid[3], col_axis[3]; - - glLineWidth(1.0f); - - UI_GetThemeColor3ubv(TH_GRID, col_grid); - - if (!write_depth) - glDepthMask(GL_FALSE); - - if (show_floor) { - const unsigned vertex_ct = 2 * (gridlines * 4 + 2); - const int sublines = v3d->gridsubdiv; - - unsigned char col_bg[3], col_grid_emphasise[3], col_grid_light[3]; - - Gwn_VertFormat *format = immVertexFormat(); - unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT); - - immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR); - - immBegin(GWN_PRIM_LINES, vertex_ct); - - /* draw normal grid lines */ - UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10); - - for (int a = 1; a <= gridlines; a++) { - /* skip emphasised divider lines */ - if (a % sublines != 0) { - const float line = a * grid_scale; - - immAttrib3ubv(color, col_grid_light); - - immVertex2f(pos, -grid, -line); - immVertex2f(pos, +grid, -line); - immVertex2f(pos, -grid, +line); - immVertex2f(pos, +grid, +line); - - immVertex2f(pos, -line, -grid); - immVertex2f(pos, -line, +grid); - immVertex2f(pos, +line, -grid); - immVertex2f(pos, +line, +grid); - } - } - - /* draw emphasised grid lines */ - UI_GetThemeColor3ubv(TH_BACK, col_bg); - /* emphasise division lines lighter instead of darker, if background is darker than grid */ - UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise, - (col_grid[0] + col_grid[1] + col_grid[2] + 30 > - col_bg[0] + col_bg[1] + col_bg[2]) ? 20 : -10); - - if (sublines <= gridlines) { - immAttrib3ubv(color, col_grid_emphasise); - - for (int a = sublines; a <= gridlines; a += sublines) { - const float line = a * grid_scale; - - immVertex2f(pos, -grid, -line); - immVertex2f(pos, +grid, -line); - immVertex2f(pos, -grid, +line); - immVertex2f(pos, +grid, +line); - - immVertex2f(pos, -line, -grid); - immVertex2f(pos, -line, +grid); - immVertex2f(pos, +line, -grid); - immVertex2f(pos, +line, +grid); - } - } - - /* draw X axis */ - if (show_axis_x) { - show_axis_x = false; /* drawing now, won't need to draw later */ - UI_make_axis_color(col_grid, col_axis, 'X'); - immAttrib3ubv(color, col_axis); - } - else - immAttrib3ubv(color, col_grid_emphasise); - - immVertex2f(pos, -grid, 0.0f); - immVertex2f(pos, +grid, 0.0f); - - /* draw Y axis */ - if (show_axis_y) { - show_axis_y = false; /* drawing now, won't need to draw later */ - UI_make_axis_color(col_grid, col_axis, 'Y'); - immAttrib3ubv(color, col_axis); - } - else - immAttrib3ubv(color, col_grid_emphasise); - - immVertex2f(pos, 0.0f, -grid); - immVertex2f(pos, 0.0f, +grid); - - immEnd(); - immUnbindProgram(); - - /* done with XY plane */ - } - - if (show_axis_x || show_axis_y || show_axis_z) { - /* draw axis lines -- sometimes grid floor is off, other times we still need to draw the Z axis */ - - Gwn_VertFormat *format = immVertexFormat(); - unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); - unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT); - - immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR); - immBegin(GWN_PRIM_LINES, (show_axis_x + show_axis_y + show_axis_z) * 2); - - if (show_axis_x) { - UI_make_axis_color(col_grid, col_axis, 'X'); - immAttrib3ubv(color, col_axis); - immVertex3f(pos, -grid, 0.0f, 0.0f); - immVertex3f(pos, +grid, 0.0f, 0.0f); - } - - if (show_axis_y) { - UI_make_axis_color(col_grid, col_axis, 'Y'); - immAttrib3ubv(color, col_axis); - immVertex3f(pos, 0.0f, -grid, 0.0f); - immVertex3f(pos, 0.0f, +grid, 0.0f); - } - - if (show_axis_z) { - UI_make_axis_color(col_grid, col_axis, 'Z'); - immAttrib3ubv(color, col_axis); - immVertex3f(pos, 0.0f, 0.0f, -grid); - immVertex3f(pos, 0.0f, 0.0f, +grid); - } - - immEnd(); - immUnbindProgram(); - } - - if (!write_depth) - glDepthMask(GL_TRUE); - } -} - /** could move this elsewhere, but tied into #ED_view3d_grid_scale */ float ED_scene_grid_scale(Scene *scene, const char **grid_unit) { @@ -1324,102 +770,6 @@ float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) return v3d->grid * ED_scene_grid_scale(scene, grid_unit); } -static bool is_cursor_visible(Scene *scene, ViewLayer *view_layer) -{ - if (U.app_flag & USER_APP_VIEW3D_HIDE_CURSOR) { - return false; - } - - Object *ob = OBACT(view_layer); - - /* don't draw cursor in paint modes, but with a few exceptions */ - if (ob && ob->mode & OB_MODE_ALL_PAINT) { - /* exception: object is in weight paint and has deforming armature in pose mode */ - if (ob->mode & OB_MODE_WEIGHT_PAINT) { - if (BKE_object_pose_armature_get(ob) != NULL) { - return true; - } - } - /* exception: object in texture paint mode, clone brush, use_clone_layer disabled */ - else if (ob->mode & OB_MODE_TEXTURE_PAINT) { - const Paint *p = BKE_paint_get_active(scene, view_layer); - - if (p && p->brush && p->brush->imagepaint_tool == PAINT_TOOL_CLONE) { - if ((scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) == 0) { - return true; - } - } - } - - /* no exception met? then don't draw cursor! */ - return false; - } - - return true; -} - -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, ED_view3d_cursor3d_get(scene, v3d), co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { - const float f5 = 0.25f * U.widget_unit; - const float f10 = 0.5f * U.widget_unit; - const float f20 = U.widget_unit; - - glLineWidth(1.0f); - - Gwn_VertFormat *format = immVertexFormat(); - unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT); - - immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); - - const int segments = 16; - - immBegin(GWN_PRIM_LINE_LOOP, segments); - - for (int i = 0; i < segments; ++i) { - float angle = 2 * M_PI * ((float)i / (float)segments); - float x = co[0] + f10 * cosf(angle); - float y = co[1] + f10 * sinf(angle); - - if (i % 2 == 0) - immAttrib3ub(color, 255, 0, 0); - else - immAttrib3ub(color, 255, 255, 255); - - immVertex2f(pos, x, y); - } - immEnd(); - - immUnbindProgram(); - - GWN_vertformat_clear(format); - pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - unsigned char crosshair_color[3]; - UI_GetThemeColor3ubv(TH_VIEW_OVERLAY, crosshair_color); - immUniformColor3ubv(crosshair_color); - - immBegin(GWN_PRIM_LINES, 8); - immVertex2f(pos, co[0] - f20, co[1]); - immVertex2f(pos, co[0] - f5, co[1]); - immVertex2f(pos, co[0] + f5, co[1]); - immVertex2f(pos, co[0] + f20, co[1]); - immVertex2f(pos, co[0], co[1] - f20); - immVertex2f(pos, co[0], co[1] - f5); - immVertex2f(pos, co[0], co[1] + f5); - immVertex2f(pos, co[0], co[1] + f20); - immEnd(); - - immUnbindProgram(); - } -} - static void draw_view_axis(RegionView3D *rv3d, const rcti *rect) { const float k = U.rvisize * U.pixelsize; /* axis size */ @@ -1909,16 +1259,8 @@ RenderEngineType *ED_view3d_engine_type(Scene *scene, int drawtype) void view3d_main_region_draw(const bContext *C, ARegion *ar) { - Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = ar->regiondata; - RenderEngineType *type = ED_view3d_engine_type(scene, v3d->drawtype); - - /* Provisory Blender Internal drawing */ - if (type->flag & RE_USE_LEGACY_PIPELINE) { - view3d_main_region_draw_legacy(C, ar); - return; - } if (!rv3d->viewport) { rv3d->viewport = GPU_viewport_create(); @@ -1965,50 +1307,17 @@ static void view3d_stereo3d_setup_offscreen( } } -void ED_view3d_draw_offscreen_init(Depsgraph *depsgraph, - Scene *scene, - ViewLayer *view_layer, - View3D *v3d, - int drawtype) -{ - RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); - - if (engine_type->flag & RE_USE_LEGACY_PIPELINE) { - /* shadow buffers, before we setup matrices */ - if (draw_glsl_material(scene, view_layer, NULL, v3d, drawtype)) { - VP_deprecated_gpu_update_lamps_shadows_world(depsgraph, scene, v3d); - } - } -} - -/* - * Function to clear the view - */ -static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) -{ - glClear(GL_DEPTH_BUFFER_BIT); - - if (scene->world && (v3d->flag3 & V3D_SHOW_WORLD)) { - VP_view3d_draw_background_world(scene, ar->regiondata); - } - else { - VP_view3d_draw_background_none(); - } -} - -/* ED_view3d_draw_offscreen_init should be called before this to initialize - * stuff like shadow buffers - */ void ED_view3d_draw_offscreen( Depsgraph *depsgraph, Scene *scene, - ViewLayer *view_layer, int drawtype, + int drawtype, View3D *v3d, ARegion *ar, int winx, int winy, float viewmat[4][4], float winmat[4][4], - bool do_bgpic, bool do_sky, bool UNUSED(is_persp), const char *viewname, + bool do_sky, bool UNUSED(is_persp), const char *viewname, GPUFXSettings *UNUSED(fx_settings), GPUOffScreen *ofs, GPUViewport *viewport) { RegionView3D *rv3d = ar->regiondata; + RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); /* set temporary new size */ int bwinx = ar->winx; @@ -2046,29 +1355,9 @@ void ED_view3d_draw_offscreen( view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL); /* main drawing call */ - RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); - - if (engine_type->flag & RE_USE_LEGACY_PIPELINE) { - VP_deprecated_view3d_draw_objects(NULL, depsgraph, scene, v3d, ar, NULL, do_bgpic, true); - - if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) { - /* draw grease-pencil stuff */ - ED_region_pixelspace(ar); - - if (v3d->flag2 & V3D_SHOW_GPENCIL) { - /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ - ED_gpencil_draw_view3d(NULL, scene, view_layer, depsgraph, v3d, ar, false); - } - - /* freeing the images again here could be done after the operator runs, leaving for now */ - GPU_free_images_anim(); - } - } - else { - DRW_draw_render_loop_offscreen( - depsgraph, engine_type, ar, v3d, - do_sky, ofs, viewport); - } + DRW_draw_render_loop_offscreen( + depsgraph, engine_type, ar, v3d, + do_sky, ofs, viewport); /* restore size */ ar->winx = bwinx; @@ -2091,7 +1380,7 @@ void ED_view3d_draw_offscreen( */ ImBuf *ED_view3d_draw_offscreen_imbuf( Depsgraph *depsgraph, Scene *scene, - ViewLayer *view_layer, int drawtype, + int drawtype, View3D *v3d, ARegion *ar, int sizex, int sizey, unsigned int flag, unsigned int draw_flags, int alpha_mode, int samples, const char *viewname, @@ -2100,7 +1389,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( { RegionView3D *rv3d = ar->regiondata; const bool draw_sky = (alpha_mode == R_ADDSKY); - const bool draw_background = (draw_flags & V3D_OFSDRAW_USE_BACKGROUND); const bool use_full_sample = (draw_flags & V3D_OFSDRAW_USE_FULL_SAMPLE); /* view state */ @@ -2125,8 +1413,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( } } - ED_view3d_draw_offscreen_init(depsgraph, scene, view_layer, v3d, drawtype); - GPU_offscreen_bind(ofs, true); /* read in pixels & stamp */ @@ -2167,9 +1453,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( if ((samples && use_full_sample) == 0) { /* Single-pass render, common case */ ED_view3d_draw_offscreen( - depsgraph, scene, view_layer, drawtype, + depsgraph, scene, drawtype, v3d, ar, sizex, sizey, NULL, winmat, - draw_background, draw_sky, !is_ortho, viewname, + draw_sky, !is_ortho, viewname, &fx_settings, ofs, NULL); if (ibuf->rect_float) { @@ -2192,9 +1478,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( /* first sample buffer, also initializes 'rv3d->persmat' */ ED_view3d_draw_offscreen( - depsgraph, scene, view_layer, drawtype, + depsgraph, scene, drawtype, v3d, ar, sizex, sizey, NULL, winmat, - draw_background, draw_sky, !is_ortho, viewname, + draw_sky, !is_ortho, viewname, &fx_settings, ofs, viewport); GPU_offscreen_read_pixels(ofs, GL_FLOAT, accum_buffer); @@ -2207,9 +1493,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( (jit_ofs[j][1] * 2.0f) / sizey); ED_view3d_draw_offscreen( - depsgraph, scene, view_layer, drawtype, + depsgraph, scene, drawtype, v3d, ar, sizex, sizey, NULL, winmat_jitter, - draw_background, draw_sky, !is_ortho, viewname, + draw_sky, !is_ortho, viewname, &fx_settings, ofs, viewport); GPU_offscreen_read_pixels(ofs, GL_FLOAT, rect_temp); @@ -2272,7 +1558,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( */ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( Depsgraph *depsgraph, Scene *scene, - ViewLayer *view_layer, int drawtype, + int drawtype, Object *camera, int width, int height, unsigned int flag, unsigned int draw_flags, int alpha_mode, int samples, const char *viewname, @@ -2298,9 +1584,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( if (draw_flags & V3D_OFSDRAW_USE_SOLID_TEX) { v3d.flag2 |= V3D_SOLID_TEX; } - if (draw_flags & V3D_OFSDRAW_USE_BACKGROUND) { - v3d.flag3 |= V3D_SHOW_WORLD; - } + + v3d.flag3 |= V3D_SHOW_WORLD; + if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) { if (camera->type == OB_CAMERA) { v3d.fx_settings.dof = &((Camera *)camera->data)->gpu_dof; @@ -2334,105 +1620,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( invert_m4_m4(rv3d.persinv, rv3d.viewinv); return ED_view3d_draw_offscreen_imbuf( - depsgraph, scene, view_layer, drawtype, + depsgraph, scene, drawtype, &v3d, &ar, width, height, flag, draw_flags, alpha_mode, samples, viewname, ofs, err_out); } /** \} */ - - -/* -------------------------------------------------------------------- */ - -/** \name Legacy Interface - * - * This will be removed once the viewport gets replaced - * meanwhile it should keep the old viewport working. - * - * \{ */ - -void VP_legacy_drawcursor(Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d) -{ - if (is_cursor_visible(scene, view_layer)) { - drawcursor(scene, ar, v3d); - } -} - -void VP_legacy_draw_view_axis(RegionView3D *rv3d, const rcti *rect) -{ - draw_view_axis(rv3d, rect); -} - -void VP_legacy_draw_viewport_name(ARegion *ar, View3D *v3d, const rcti *rect) -{ - draw_viewport_name(ar, v3d, rect); -} - -void VP_legacy_draw_selected_name(Scene *scene, Object *ob, rcti *rect) -{ - draw_selected_name(scene, ob, rect); -} - -void VP_legacy_drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit) -{ - drawgrid(unit, ar, v3d, grid_unit); -} - -void VP_legacy_drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool write_depth) -{ - drawfloor(scene, v3d, grid_unit, write_depth); -} - -void VP_legacy_view3d_main_region_setup_view( - Depsgraph *depsgraph, Scene *scene, View3D *v3d, - ARegion *ar, float viewmat[4][4], float winmat[4][4]) -{ - view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL); -} - -bool VP_legacy_view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d) -{ - return view3d_stereo3d_active(win, scene, v3d, rv3d); -} - -void VP_legacy_view3d_stereo3d_setup(Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar) -{ - view3d_stereo3d_setup(depsgraph, scene, v3d, ar, NULL); -} - -bool VP_legacy_use_depth(View3D *v3d, Object *obedit) -{ - return use_depth_doit(v3d, obedit); -} - -void VP_drawviewborder(Scene *scene, struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d) -{ - drawviewborder(scene, depsgraph, ar, v3d); -} - -void VP_drawrenderborder(ARegion *ar, View3D *v3d) -{ - drawrenderborder(ar, v3d); -} - -void VP_view3d_draw_background_none(void) -{ - if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) { - view3d_draw_background_gradient(); - } - else { - view3d_draw_background_none(); - } -} - -void VP_view3d_draw_background_world(Scene *scene, RegionView3D *rv3d) -{ - view3d_draw_background_world(scene, rv3d); -} - -void VP_view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) -{ - view3d_main_region_clear(scene, v3d, ar); -} - -/** \} */ |