diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint')
23 files changed, 672 insertions, 454 deletions
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index adead9a8b9e..040bcc10ca2 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -25,6 +25,7 @@ set(INC ../../blenlib ../../blentranslation ../../bmesh + ../../depsgraph ../../gpu ../../imbuf ../../makesdna diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index e6219b4fae1..6229b91a518 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -54,14 +54,14 @@ #include "WM_api.h" -#include "BIF_gl.h" -#include "BIF_glutil.h" - #include "IMB_imbuf_types.h" #include "ED_view3d.h" -#include "GPU_basic_shader.h" +#include "GPU_draw.h" +#include "GPU_immediate.h" +#include "GPU_immediate_util.h" +#include "GPU_matrix.h" #include "UI_resources.h" @@ -338,11 +338,12 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima size = target->old_size; } + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, target->overlay_texture); if (refresh) { - GLenum format = col ? GL_RGBA : GL_ALPHA; - GLenum internalformat = col ? GL_RGBA8 : GL_ALPHA8; + GLenum format = col ? GL_RGBA : GL_RED; + GLenum internalformat = col ? GL_RGBA8 : GL_R8; if (!init || (target->old_col != col)) { glTexImage2D(GL_TEXTURE_2D, 0, internalformat, size, size, 0, format, GL_UNSIGNED_BYTE, buffer); @@ -357,8 +358,6 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima target->old_col = col; } - GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -466,22 +465,21 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) size = cursor_snap.size; } + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, cursor_snap.overlay_texture); if (refresh) { if (!init) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, size, size, 0, GL_RED, GL_UNSIGNED_BYTE, buffer); } else { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_RED, GL_UNSIGNED_BYTE, buffer); } if (buffer) MEM_freeN(buffer); } - GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -615,22 +613,20 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush, glDepthMask(GL_FALSE); glDepthFunc(GL_ALWAYS); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - glLoadIdentity(); - if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { + gpuPushMatrix(); + /* brush rotation */ - glTranslatef(0.5, 0.5, 0); - glRotatef((double)RAD2DEGF((primary) ? ups->brush_rotation : ups->brush_rotation_sec), - 0.0, 0.0, 1.0); - glTranslatef(-0.5f, -0.5f, 0); + gpuTranslate2f(x, y); + gpuRotate2D(-RAD2DEGF(primary ? ups->brush_rotation : ups->brush_rotation_sec)); + gpuTranslate2f(-x, -y); /* scale based on tablet pressure */ if (primary && ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) { - glTranslatef(0.5f, 0.5f, 0); - glScalef(1.0f / ups->size_pressure_value, 1.0f / ups->size_pressure_value, 1); - glTranslatef(-0.5f, -0.5f, 0); + const float scale = ups->size_pressure_value; + gpuTranslate2f(x, y); + gpuScale2f(scale, scale); + gpuTranslate2f(-x, -y); } if (ups->draw_anchored) { @@ -668,41 +664,46 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush, quad.xmax = brush->mask_stencil_dimension[0]; quad.ymax = brush->mask_stencil_dimension[1]; } - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); + gpuPushMatrix(); if (primary) - glTranslate2fv(brush->stencil_pos); + gpuTranslate2fv(brush->stencil_pos); else - glTranslate2fv(brush->mask_stencil_pos); - glRotatef(RAD2DEGF(mtex->rot), 0, 0, 1); - glMatrixMode(GL_TEXTURE); + gpuTranslate2fv(brush->mask_stencil_pos); + gpuRotate2D(RAD2DEGF(mtex->rot)); } /* set quad color. Colored overlay does not get blending */ + Gwn_VertFormat *format = immVertexFormat(); + unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + unsigned int texCoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + if (col) { - glColor4f(1.0, 1.0, 1.0, overlay_alpha / 100.0f); + immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immUniformColor4f(1.0f, 1.0f, 1.0f, overlay_alpha * 0.01f); } else { - glColor4f(UNPACK3(U.sculpt_paint_overlay_col), overlay_alpha / 100.0f); + immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_ALPHA_COLOR); + immUniformColor3fvAlpha(U.sculpt_paint_overlay_col, overlay_alpha * 0.01f); } /* draw textured quad */ - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(quad.xmin, quad.ymin); - glTexCoord2f(1, 0); - glVertex2f(quad.xmax, quad.ymin); - glTexCoord2f(1, 1); - glVertex2f(quad.xmax, quad.ymax); - glTexCoord2f(0, 1); - glVertex2f(quad.xmin, quad.ymax); - glEnd(); - - glPopMatrix(); - - if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) { - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + immUniform1i("image", GL_TEXTURE0); + + immBegin(GWN_PRIM_TRI_FAN, 4); + immAttrib2f(texCoord, 0.0f, 0.0f); + immVertex2f(pos, quad.xmin, quad.ymin); + immAttrib2f(texCoord, 1.0f, 0.0f); + immVertex2f(pos, quad.xmax, quad.ymin); + immAttrib2f(texCoord, 1.0f, 1.0f); + immVertex2f(pos, quad.xmax, quad.ymax); + immAttrib2f(texCoord, 0.0f, 1.0f); + immVertex2f(pos, quad.xmin, quad.ymax); + immEnd(); + + immUnbindProgram(); + + if (ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_VIEW)) { + gpuPopMatrix(); } } } @@ -750,32 +751,41 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush, /* scale based on tablet pressure */ if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) { do_pop = true; - glPushMatrix(); - glLoadIdentity(); - glTranslate2fv(center); - glScalef(ups->size_pressure_value, ups->size_pressure_value, 1); - glTranslatef(-center[0], -center[1], 0); + gpuPushMatrix(); + gpuLoadIdentity(); + gpuTranslate2fv(center); + gpuScaleUniform(ups->size_pressure_value); + gpuTranslate2f(-center[0], -center[1]); } - glColor4f(U.sculpt_paint_overlay_col[0], - U.sculpt_paint_overlay_col[1], - U.sculpt_paint_overlay_col[2], - brush->cursor_overlay_alpha / 100.0f); + Gwn_VertFormat *format = immVertexFormat(); + unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + unsigned int texCoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + + immUniformColor3fvAlpha(U.sculpt_paint_overlay_col, brush->cursor_overlay_alpha * 0.01f); + + /* draw textured quad */ /* draw textured quad */ - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(quad.xmin, quad.ymin); - glTexCoord2f(1, 0); - glVertex2f(quad.xmax, quad.ymin); - glTexCoord2f(1, 1); - glVertex2f(quad.xmax, quad.ymax); - glTexCoord2f(0, 1); - glVertex2f(quad.xmin, quad.ymax); - glEnd(); + immUniform1i("image", 0); + + immBegin(GWN_PRIM_TRI_FAN, 4); + immAttrib2f(texCoord, 0.0f, 0.0f); + immVertex2f(pos, quad.xmin, quad.ymin); + immAttrib2f(texCoord, 1.0f, 0.0f); + immVertex2f(pos, quad.xmax, quad.ymin); + immAttrib2f(texCoord, 1.0f, 1.0f); + immVertex2f(pos, quad.xmax, quad.ymax); + immAttrib2f(texCoord, 0.0f, 1.0f); + immVertex2f(pos, quad.xmin, quad.ymax); + immEnd(); + + immUnbindProgram(); if (do_pop) - glPopMatrix(); + gpuPopMatrix(); } } @@ -785,19 +795,7 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush, /* color means that primary brush texture is colured and secondary is used for alpha/mask control */ bool col = ELEM(mode, ePaintTextureProjective, ePaintTexture2D, ePaintVertex) ? true : false; eOverlayControlFlags flags = BKE_paint_get_overlay_flags(); - /* save lots of GL state - * TODO: check on whether all of these are needed? */ - glPushAttrib(GL_COLOR_BUFFER_BIT | - GL_CURRENT_BIT | - GL_DEPTH_BUFFER_BIT | - GL_ENABLE_BIT | - GL_LINE_BIT | - GL_POLYGON_BIT | - GL_STENCIL_BUFFER_BIT | - GL_TRANSFORM_BIT | - GL_VIEWPORT_BIT | - GL_TEXTURE_BIT); - + gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_BLEND_BIT); /* coloured overlay should be drawn separately */ if (col) { @@ -815,86 +813,98 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush, paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom); } - glPopAttrib(); - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); + gpuPopAttrib(); } -BLI_INLINE void draw_tri_point(float *co, float width, bool selected) +BLI_INLINE void draw_tri_point( + unsigned int pos, float sel_col[4], float pivot_col[4], + float *co, float width, bool selected) { + immUniformColor4fv(selected ? sel_col : pivot_col); + + glLineWidth(3.0f); + float w = width / 2.0f; - if (selected) - UI_ThemeColor4(TH_VERTEX_SELECT); - else - UI_ThemeColor4(TH_PAINT_CURVE_PIVOT); - - glLineWidth(3.0); - - glBegin(GL_LINE_LOOP); - glVertex2f(co[0], co[1] + w); - glVertex2f(co[0] - w, co[1] - w); - glVertex2f(co[0] + w, co[1] - w); - glEnd(); - - glColor4f(1.0, 1.0, 1.0, 0.5); - glLineWidth(1.0); - - glBegin(GL_LINE_LOOP); - glVertex2f(co[0], co[1] + w); - glVertex2f(co[0] - w, co[1] - w); - glVertex2f(co[0] + w, co[1] - w); - glEnd(); + float tri[3][2] = { + {co[0], co[1] + w}, + {co[0] - w, co[1] - w}, + {co[0] + w, co[1] - w}, + }; + + immBegin(GWN_PRIM_LINE_LOOP, 3); + immVertex2fv(pos, tri[0]); + immVertex2fv(pos, tri[1]); + immVertex2fv(pos, tri[2]); + immEnd(); + + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); + glLineWidth(1.0f); + + immBegin(GWN_PRIM_LINE_LOOP, 3); + immVertex2fv(pos, tri[0]); + immVertex2fv(pos, tri[1]); + immVertex2fv(pos, tri[2]); + immEnd(); } -BLI_INLINE void draw_rect_point(float *co, float width, bool selected) +BLI_INLINE void draw_rect_point( + unsigned int pos, float sel_col[4], float handle_col[4], + float *co, float width, bool selected) { + immUniformColor4fv(selected ? sel_col : handle_col); + + glLineWidth(3.0f); + float w = width / 2.0f; - if (selected) - UI_ThemeColor4(TH_VERTEX_SELECT); - else - UI_ThemeColor4(TH_PAINT_CURVE_HANDLE); - glLineWidth(3.0); - - glBegin(GL_LINE_LOOP); - glVertex2f(co[0] + w, co[1] + w); - glVertex2f(co[0] - w, co[1] + w); - glVertex2f(co[0] - w, co[1] - w); - glVertex2f(co[0] + w, co[1] - w); - glEnd(); - - glColor4f(1.0, 1.0, 1.0, 0.5); - glLineWidth(1.0); - - glBegin(GL_LINE_LOOP); - glVertex2f(co[0] + w, co[1] + w); - glVertex2f(co[0] - w, co[1] + w); - glVertex2f(co[0] - w, co[1] - w); - glVertex2f(co[0] + w, co[1] - w); - glEnd(); + float minx = co[0] - w; + float miny = co[1] - w; + float maxx = co[0] + w; + float maxy = co[1] + w; + + imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy); + + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); + glLineWidth(1.0f); + + imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy); } -BLI_INLINE void draw_bezier_handle_lines(BezTriple *bez) +BLI_INLINE void draw_bezier_handle_lines(unsigned int pos, float sel_col[4], BezTriple *bez) { - short line1[] = {0, 1}; - short line2[] = {1, 2}; - - glVertexPointer(2, GL_FLOAT, 3 * sizeof(float), bez->vec); - glColor4f(0.0, 0.0, 0.0, 0.5); - glLineWidth(3.0); - glDrawArrays(GL_LINE_STRIP, 0, 3); - - glLineWidth(1.0); - if (bez->f1 || bez->f2) - UI_ThemeColor4(TH_VERTEX_SELECT); - else - glColor4f(1.0, 1.0, 1.0, 0.5); - glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, line1); - if (bez->f3 || bez->f2) - UI_ThemeColor4(TH_VERTEX_SELECT); - else - glColor4f(1.0, 1.0, 1.0, 0.5); - glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, line2); + immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f); + glLineWidth(3.0f); + + immBegin(GWN_PRIM_LINE_STRIP, 3); + immVertex2fv(pos, bez->vec[0]); + immVertex2fv(pos, bez->vec[1]); + immVertex2fv(pos, bez->vec[2]); + immEnd(); + + glLineWidth(1.0f); + + if (bez->f1 || bez->f2) { + immUniformColor4fv(sel_col); + } + else { + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); + } + immBegin(GWN_PRIM_LINES, 2); + immVertex2fv(pos, bez->vec[0]); + immVertex2fv(pos, bez->vec[1]); + immEnd(); + + if (bez->f3 || bez->f2) { + immUniformColor4fv(sel_col); + } + else { + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); + } + immBegin(GWN_PRIM_LINES, 2); + immVertex2fv(pos, bez->vec[1]); + immVertex2fv(pos, bez->vec[2]); + immEnd(); } static void paint_draw_curve_cursor(Brush *brush) @@ -906,18 +916,26 @@ static void paint_draw_curve_cursor(Brush *brush) glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glEnableClientState(GL_VERTEX_ARRAY); /* draw the bezier handles and the curve segment between the current and next point */ + unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + float selec_col[4], handle_col[4], pivot_col[4]; + UI_GetThemeColor4fv(TH_VERTEX_SELECT, selec_col); + UI_GetThemeColor4fv(TH_PAINT_CURVE_HANDLE, handle_col); + UI_GetThemeColor4fv(TH_PAINT_CURVE_PIVOT, pivot_col); + for (i = 0; i < pc->tot_points - 1; i++, cp++) { int j; PaintCurvePoint *cp_next = cp + 1; float data[(PAINT_CURVE_NUM_SEGMENTS + 1) * 2]; /* use color coding to distinguish handles vs curve segments */ - draw_bezier_handle_lines(&cp->bez); - draw_tri_point(&cp->bez.vec[1][0], 10.0, cp->bez.f2); - draw_rect_point(&cp->bez.vec[0][0], 8.0, cp->bez.f1 || cp->bez.f2); - draw_rect_point(&cp->bez.vec[2][0], 8.0, cp->bez.f3 || cp->bez.f2); + draw_bezier_handle_lines(pos, selec_col, &cp->bez); + draw_tri_point(pos, selec_col, pivot_col, &cp->bez.vec[1][0], 10.0f, cp->bez.f2); + draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[0][0], 8.0f, cp->bez.f1 || cp->bez.f2); + draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2); for (j = 0; j < 2; j++) BKE_curve_forward_diff_bezier( @@ -927,25 +945,35 @@ static void paint_draw_curve_cursor(Brush *brush) cp_next->bez.vec[1][j], data + j, PAINT_CURVE_NUM_SEGMENTS, sizeof(float[2])); - glVertexPointer(2, GL_FLOAT, 0, data); - glLineWidth(3.0); - glColor4f(0.0, 0.0, 0.0, 0.5); - glDrawArrays(GL_LINE_STRIP, 0, PAINT_CURVE_NUM_SEGMENTS + 1); + float (*v)[2] = (float(*)[2])data; + + immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f); + glLineWidth(3.0f); + immBegin(GWN_PRIM_LINE_STRIP, PAINT_CURVE_NUM_SEGMENTS + 1); + for (j = 0; j <= PAINT_CURVE_NUM_SEGMENTS; j++) { + immVertex2fv(pos, v[j]); + } + immEnd(); - glLineWidth(1.0); - glColor4f(0.9, 0.9, 1.0, 0.5); - glDrawArrays(GL_LINE_STRIP, 0, PAINT_CURVE_NUM_SEGMENTS + 1); + immUniformColor4f(0.9f, 0.9f, 1.0f, 0.5f); + glLineWidth(1.0f); + immBegin(GWN_PRIM_LINE_STRIP, PAINT_CURVE_NUM_SEGMENTS + 1); + for (j = 0; j <= PAINT_CURVE_NUM_SEGMENTS; j++) { + immVertex2fv(pos, v[j]); + } + immEnd(); } /* draw last line segment */ - draw_bezier_handle_lines(&cp->bez); - draw_tri_point(&cp->bez.vec[1][0], 10.0, cp->bez.f2); - draw_rect_point(&cp->bez.vec[0][0], 8.0, cp->bez.f1 || cp->bez.f2); - draw_rect_point(&cp->bez.vec[2][0], 8.0, cp->bez.f3 || cp->bez.f2); + draw_bezier_handle_lines(pos, selec_col, &cp->bez); + draw_tri_point(pos, selec_col, pivot_col, &cp->bez.vec[1][0], 10.0f, cp->bez.f2); + draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[0][0], 8.0f, cp->bez.f1 || cp->bez.f2); + draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); - glDisableClientState(GL_VERTEX_ARRAY); + + immUnbindProgram(); } } @@ -999,11 +1027,6 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) Paint *paint = BKE_paint_get_active_from_context(C); Brush *brush = BKE_paint_brush(paint); ePaintMode mode = BKE_paintmode_get_active_from_context(C); - ViewContext vc; - float final_radius; - float translation[2]; - float outline_alpha, *outline_col; - float zoomx, zoomy; /* check that brush drawing is enabled */ if (ommit_cursor_drawing(paint, mode, brush)) @@ -1011,6 +1034,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) /* can't use stroke vc here because this will be called during * mouse over too, not just during a stroke */ + ViewContext vc; ED_view3d_viewcontext_init(C, &vc); if (vc.rv3d && (vc.rv3d->rflag & RV3D_NAVIGATING)) { @@ -1023,15 +1047,15 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) return; } + float zoomx, zoomy; get_imapaint_zoom(C, &zoomx, &zoomy); zoomx = max_ff(zoomx, zoomy); /* set various defaults */ - translation[0] = x; - translation[1] = y; - outline_alpha = 0.5; - outline_col = brush->add_col; - final_radius = (BKE_brush_size_get(scene, brush) * zoomx); + const float *outline_col = brush->add_col; + const float outline_alpha = 0.5f; + float translation[2] = { x, y }; + float final_radius = (BKE_brush_size_get(scene, brush) * zoomx); /* don't calculate rake angles while a stroke is active because the rake variables are global and * we may get interference with the stroke itself. For line strokes, such interference is visible */ @@ -1047,10 +1071,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) if ((mode == ePaintSculpt) && vc.obact->sculpt) { float location[3]; int pixel_radius; - bool hit; /* test if brush is over the mesh */ - hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups); + bool hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups); if (BKE_brush_use_locked_size(scene, brush)) BKE_brush_size_set(scene, brush, pixel_radius); @@ -1077,24 +1100,25 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) /* make lines pretty */ glLineWidth(1.0f); - glEnable(GL_BLEND); + glEnable(GL_BLEND); /* TODO: also set blend mode? */ glEnable(GL_LINE_SMOOTH); + unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + /* set brush color */ - glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha); + immUniformColor3fvAlpha(outline_col, outline_alpha); /* draw brush outline */ - glTranslate2fv(translation); - - /* draw an inner brush */ if (ups->stroke_active && BKE_brush_use_size_pressure(scene, brush)) { /* inner at full alpha */ - glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->size_pressure_value, 40); + imm_draw_circle_wire_2d(pos, translation[0], translation[1], final_radius * ups->size_pressure_value, 40); /* outer at half alpha */ - glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha * 0.5f); + immUniformColor3fvAlpha(outline_col, outline_alpha * 0.5f); } - glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius, 40); - glTranslatef(-translation[0], -translation[1], 0); + imm_draw_circle_wire_2d(pos, translation[0], translation[1], final_radius, 40); + + immUnbindProgram(); /* restore GL state */ glDisable(GL_BLEND); diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index 8d9812f41d9..fb8dea2af0e 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -32,6 +32,7 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_view3d_types.h" +#include "DNA_workspace_types.h" #include "BLI_math_vector.h" @@ -39,6 +40,8 @@ #include "BKE_main.h" #include "BKE_paint.h" +#include "DEG_depsgraph.h" + #include "ED_view3d.h" #include "WM_api.h" @@ -56,12 +59,13 @@ int paint_curve_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); Paint *p; RegionView3D *rv3d = CTX_wm_region_view3d(C); SpaceImage *sima; - if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) + if (rv3d && !(ob && ((workspace->object_mode & OB_MODE_ALL_PAINT) != 0))) return false; sima = CTX_wm_space_image(C); diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index e2b318710a8..5d4451dd3d8 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -52,7 +52,7 @@ #include "BKE_paint.h" #include "BKE_subsurf.h" -#include "BIF_glutil.h" +#include "DEG_depsgraph.h" #include "WM_api.h" #include "WM_types.h" @@ -323,12 +323,10 @@ static void clip_planes_from_rect(bContext *C, { ViewContext vc; BoundBox bb; - bglMats mats = {{0}}; view3d_operator_needs_opengl(C); ED_view3d_viewcontext_init(C, &vc); - view3d_get_transformation(vc.ar, vc.rv3d, vc.obact, &mats); - ED_view3d_clipping_calc(&bb, clip_planes, &mats, rect); + ED_view3d_clipping_calc(&bb, clip_planes, vc.ar, vc.obact, rect); negate_m4(clip_planes); } @@ -364,6 +362,7 @@ static int hide_show_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); Object *ob = CTX_data_active_object(C); + EvaluationContext eval_ctx; Mesh *me = ob->data; PartialVisAction action; PartialVisArea area; @@ -375,6 +374,8 @@ static int hide_show_exec(bContext *C, wmOperator *op) rcti rect; int totnode, i; + CTX_data_eval_ctx(C, &eval_ctx); + /* read operator properties */ action = RNA_enum_get(op->ptr, "action"); area = RNA_enum_get(op->ptr, "area"); @@ -382,8 +383,8 @@ static int hide_show_exec(bContext *C, wmOperator *op) clip_planes_from_rect(C, clip_planes, &rect); - dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH); - pbvh = dm->getPBVH(ob, dm); + dm = mesh_get_derived_final(&eval_ctx, CTX_data_scene(C), ob, CD_MASK_BAREMESH); + pbvh = dm->getPBVH(ob, dm, eval_ctx.object_mode); ob->sculpt->pbvh = pbvh; get_pbvh_nodes(pbvh, &nodes, &totnode, clip_planes, area); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index c6472b258ca..b7cbdfecfe8 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -51,7 +51,6 @@ #include "BKE_colorband.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" #include "BKE_brush.h" #include "BKE_main.h" @@ -59,6 +58,8 @@ #include "BKE_node.h" #include "BKE_paint.h" +#include "DEG_depsgraph.h" + #include "UI_interface.h" #include "UI_view2d.h" @@ -76,9 +77,9 @@ #include "GPU_draw.h" #include "GPU_buffers.h" +#include "GPU_immediate.h" #include "BIF_gl.h" -#include "BIF_glutil.h" #include "IMB_colormanagement.h" @@ -264,11 +265,13 @@ static int image_paint_poll(bContext *C) { Object *obact; - if (!image_paint_brush(C)) + if (!image_paint_brush(C)) { return 0; + } + const WorkSpace *workspace = CTX_wm_workspace(C); obact = CTX_data_active_object(C); - if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { + if ((obact && workspace->object_mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { return 1; } else { @@ -397,12 +400,28 @@ static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customda glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); + Gwn_VertFormat *format = immVertexFormat(); + unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + glLineWidth(4.0); - glColor4ub(0, 0, 0, 255); - sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]); + immUniformColor4ub(0, 0, 0, 255); + + immBegin(GWN_PRIM_LINES, 2); + immVertex2i(pos, x, y); + immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]); + immEnd(); + glLineWidth(2.0); - glColor4ub(255, 255, 255, 255); - sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]); + immUniformColor4ub(255, 255, 255, 255); + + immBegin(GWN_PRIM_LINES, 2); + immVertex2i(pos, x, y); + immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]); + immEnd(); + + immUnbindProgram(); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); @@ -424,7 +443,8 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo /* initialize from context */ if (CTX_wm_region_view3d(C)) { - Object *ob = OBACT; + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); bool uvs, mat, tex, stencil; if (!BKE_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) { BKE_paint_data_warning(op->reports, uvs, mat, tex, stencil); @@ -706,16 +726,20 @@ static void toggle_paint_cursor(bContext *C, int enable) void ED_space_image_paint_update(wmWindowManager *wm, Scene *scene) { ToolSettings *settings = scene->toolsettings; - wmWindow *win; - ScrArea *sa; ImagePaintSettings *imapaint = &settings->imapaint; bool enabled = false; - for (win = wm->windows.first; win; win = win->next) - for (sa = win->screen->areabase.first; sa; sa = sa->next) - if (sa->spacetype == SPACE_IMAGE) - if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) + for (wmWindow *win = wm->windows.first; win; win = win->next) { + bScreen *screen = WM_window_get_active_screen(win); + + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_IMAGE) { + if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) { enabled = true; + } + } + } + } if (enabled) { BKE_paint_init(scene, ePaintTexture2D, PAINT_CURSOR_TEXTURE_PAINT); @@ -1019,19 +1043,21 @@ static int texture_paint_toggle_poll(bContext *C) static int texture_paint_toggle_exec(bContext *C, wmOperator *op) { + wmWindowManager *wm = CTX_wm_manager(C); + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_TEXTURE_PAINT; - const bool is_mode_set = (ob->mode & mode_flag) != 0; + const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } - if (ob->mode & mode_flag) { - ob->mode &= ~mode_flag; + if (workspace->object_mode & mode_flag) { + workspace->object_mode &= ~mode_flag; if (U.glreslimit != 0) GPU_free_images(); @@ -1071,15 +1097,17 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; - if (!sima->pin) - ED_space_image_set(sima, scene, scene->obedit, ima); + if (!sima->pin) { + Object *obedit = CTX_data_edit_object(C); + ED_space_image_set(sima, scene, obedit, ima); + } } } } } } - ob->mode |= mode_flag; + workspace->object_mode |= mode_flag; BKE_paint_init(scene, ePaintTextureProjective, PAINT_CURSOR_TEXTURE_PAINT); @@ -1090,6 +1118,8 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) toggle_paint_cursor(C, 1); } + ED_workspace_object_mode_sync_from_object(wm, workspace, ob); + GPU_drawobject_free(ob->derivedFinal); WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); @@ -1116,9 +1146,10 @@ static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op)) { UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; - Brush *br; + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - if (!(ob && (ob->mode & OB_MODE_VERTEX_PAINT))) { + Brush *br; + if (!(ob && (workspace->object_mode & OB_MODE_VERTEX_PAINT))) { br = image_paint_brush(C); } else { @@ -1149,8 +1180,11 @@ static int brush_colors_flip_poll(bContext *C) } else { Object *ob = CTX_data_active_object(C); - if (ob && (ob->mode & OB_MODE_VERTEX_PAINT)) { - return 1; + if (ob) { + WorkSpace *workspace = CTX_wm_workspace(C); + if (workspace->object_mode & OB_MODE_VERTEX_PAINT) { + return 1; + } } } return 0; @@ -1183,16 +1217,18 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op) ED_undo_paint_push_end(UNDO_PAINT_IMAGE); - DAG_id_tag_update(&ima->id, 0); + DEG_id_tag_update(&ima->id, 0); } static int texture_paint_poll(bContext *C) { - if (texture_paint_toggle_poll(C)) - if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT) + if (texture_paint_toggle_poll(C)) { + WorkSpace *workspace = CTX_wm_workspace(C); + if (workspace->object_mode & OB_MODE_TEXTURE_PAINT) { return 1; - + } + } return 0; } @@ -1203,16 +1239,19 @@ int image_texture_paint_poll(bContext *C) int facemask_paint_poll(bContext *C) { - return BKE_paint_select_face_test(CTX_data_active_object(C)); + const WorkSpace *workspace = CTX_wm_workspace(C); + return BKE_paint_select_face_test(CTX_data_active_object(C), workspace->object_mode); } int vert_paint_poll(bContext *C) { - return BKE_paint_select_vert_test(CTX_data_active_object(C)); + const WorkSpace *workspace = CTX_wm_workspace(C); + return BKE_paint_select_vert_test(CTX_data_active_object(C), workspace->object_mode); } int mask_paint_poll(bContext *C) { - return BKE_paint_select_elem_test(CTX_data_active_object(C)); + const WorkSpace *workspace = CTX_wm_workspace(C); + return BKE_paint_select_elem_test(CTX_data_active_object(C), workspace->object_mode); } diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 894277402a7..2ce7c51b6b4 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -46,12 +46,13 @@ #include "BKE_colorband.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_brush.h" #include "BKE_image.h" #include "BKE_paint.h" #include "BKE_report.h" +#include "DEG_depsgraph.h" + #include "ED_paint.h" #include "ED_screen.h" @@ -1365,7 +1366,7 @@ void paint_2d_redraw(const bContext *C, void *ps, bool final) /* compositor listener deals with updating */ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image); - DAG_id_tag_update(&s->image->id, 0); + DEG_id_tag_update(&s->image->id, 0); } else { if (!s->sima || !s->sima->lock) diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 60fe8555ba2..58c03330256 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -65,7 +65,6 @@ #include "BKE_colorband.h" #include "BKE_context.h" #include "BKE_colortools.h" -#include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" #include "BKE_idprop.h" #include "BKE_brush.h" @@ -81,6 +80,8 @@ #include "BKE_scene.h" #include "BKE_texture.h" +#include "DEG_depsgraph.h" + #include "UI_interface.h" #include "ED_mesh.h" @@ -226,6 +227,7 @@ typedef struct ProjPaintState { View3D *v3d; RegionView3D *rv3d; ARegion *ar; + const Depsgraph *depsgraph; Scene *scene; int source; /* PROJ_SRC_**** */ @@ -3132,7 +3134,7 @@ static void proj_paint_state_viewport_init( ED_view3d_ob_project_mat_get_from_obmat(ps->rv3d, ps->obmat, ps->projectMat); - ps->is_ortho = ED_view3d_clip_range_get(ps->v3d, ps->rv3d, &ps->clipsta, &ps->clipend, true); + ps->is_ortho = ED_view3d_clip_range_get(ps->depsgraph, ps->v3d, ps->rv3d, &ps->clipsta, &ps->clipend, true); } else { /* re-projection */ @@ -3421,12 +3423,15 @@ static void project_paint_bleed_add_face_user( #endif /* Return true if DM can be painted on, false otherwise */ -static bool proj_paint_state_dm_init(ProjPaintState *ps) +static bool proj_paint_state_dm_init(const bContext *C, ProjPaintState *ps) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + /* Workaround for subsurf selection, try the display mesh first */ if (ps->source == PROJ_SRC_IMAGE_CAM) { /* using render mesh, assume only camera was rendered from */ - ps->dm = mesh_create_derived_render(ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE); + ps->dm = mesh_create_derived_render(&eval_ctx, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE); ps->dm_release = true; } else if (ps->ob->derivedFinal && @@ -3438,7 +3443,7 @@ static bool proj_paint_state_dm_init(ProjPaintState *ps) } else { ps->dm = mesh_get_derived_final( - ps->scene, ps->ob, + &eval_ctx, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE | (ps->do_face_sel ? CD_ORIGINDEX : 0)); ps->dm_release = true; } @@ -3488,7 +3493,7 @@ static void proj_paint_layer_clone_init( /* use clone mtface? */ if (ps->do_layer_clone) { - const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY); + const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV); ps->dm_mloopuv_clone = MEM_mallocN(ps->dm_totpoly * sizeof(MLoopUV *), "proj_paint_mtfaces"); @@ -3818,7 +3823,7 @@ static void project_paint_prepare_all_faces( /* run once per stroke before projection painting */ static void project_paint_begin( - ProjPaintState *ps, + const bContext *C, ProjPaintState *ps, const bool is_multi_view, const char symmetry_flag) { ProjPaintLayerClone layer_clone; @@ -3841,7 +3846,7 @@ static void project_paint_begin( /* paint onto the derived mesh */ if (ps->is_shared_user == false) { - if (!proj_paint_state_dm_init(ps)) { + if (!proj_paint_state_dm_init(C, ps)) { return; } } @@ -3851,7 +3856,7 @@ static void project_paint_begin( if (ps->do_layer_stencil || ps->do_stencil_brush) { //int layer_num = CustomData_get_stencil_layer(&ps->dm->loopData, CD_MLOOPUV); - int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY); + int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV); if (layer_num != -1) ps->dm_mloopuv_stencil = CustomData_get_layer_n(&ps->dm->loopData, CD_MLOOPUV, layer_num); @@ -3939,7 +3944,7 @@ static void project_paint_end(ProjPaintState *ps) ProjPaintImage *projIma; for (a = 0, projIma = ps->projImages; a < ps->image_tot; a++, projIma++) { BKE_image_release_ibuf(projIma->ima, projIma->ibuf, NULL); - DAG_id_tag_update(&projIma->ima->id, 0); + DEG_id_tag_update(&projIma->ima->id, 0); } } @@ -5024,7 +5029,9 @@ void paint_proj_stroke( /* clone gets special treatment here to avoid going through image initialization */ if (ps_handle->is_clone_cursor_pick) { + EvaluationContext eval_ctx; Scene *scene = ps_handle->scene; + struct Depsgraph *graph = CTX_data_depsgraph(C); View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); float *cursor = ED_view3d_cursor3d_get(scene, v3d); @@ -5032,8 +5039,11 @@ void paint_proj_stroke( view3d_operator_needs_opengl(C); - if (!ED_view3d_autodist(scene, ar, v3d, mval_i, cursor, false, NULL)) + CTX_data_eval_ctx(C, &eval_ctx); + + if (!ED_view3d_autodist(&eval_ctx, graph, ar, v3d, mval_i, cursor, false, NULL)) { return; + } ED_region_tag_redraw(ar); @@ -5089,6 +5099,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int ps->rv3d = CTX_wm_region_view3d(C); ps->ar = CTX_wm_region(C); + ps->depsgraph = CTX_data_depsgraph(C); ps->scene = scene; ps->ob = ob; /* allow override of active object */ @@ -5211,7 +5222,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m project_state_init(C, ob, ps, mode); - if (ps->ob == NULL || !(ps->ob->lay & ps->v3d->lay)) { + if (ps->ob == NULL) { ps_handle->ps_views_tot = i + 1; goto fail; } @@ -5235,7 +5246,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m PROJ_PAINT_STATE_SHARED_MEMCPY(ps, ps_handle->ps_views[0]); } - project_paint_begin(ps, is_multi_view, symmetry_flag_views[i]); + project_paint_begin(C, ps, is_multi_view, symmetry_flag_views[i]); paint_proj_begin_clone(ps, mouse); @@ -5313,11 +5324,12 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op) { Image *image = BLI_findlink(&CTX_data_main(C)->image, RNA_enum_get(op->ptr, "image")); Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); ProjPaintState ps = {NULL}; int orig_brush_size; IDProperty *idgroup; IDProperty *view_data = NULL; - Object *ob = OBACT; + Object *ob = OBACT(view_layer); bool uvs, mat, tex; if (ob == NULL || ob->type != OB_MESH) { @@ -5387,7 +5399,7 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op) ED_image_undo_push_begin(op->type->name); /* allocate and initialize spatial data structures */ - project_paint_begin(&ps, false, 0); + project_paint_begin(C, &ps, false, 0); if (ps.dm == NULL) { BKE_brush_size_set(scene, ps.brush, orig_brush_size); @@ -5445,12 +5457,16 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) char filename[FILE_MAX]; Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + EvaluationContext eval_ctx; ToolSettings *settings = scene->toolsettings; int w = settings->imapaint.screen_grab_size[0]; int h = settings->imapaint.screen_grab_size[1]; int maxsize; char err_out[256] = "unknown"; + CTX_data_eval_ctx(C, &eval_ctx); + RNA_string_get(op->ptr, "filepath", filename); maxsize = GPU_max_texture_size(); @@ -5459,9 +5475,9 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) if (h > maxsize) h = maxsize; ibuf = ED_view3d_draw_offscreen_imbuf( - scene, CTX_wm_view3d(C), CTX_wm_region(C), + &eval_ctx, scene, view_layer, CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, - NULL, NULL, err_out); + NULL, err_out); if (!ibuf) { /* Mostly happens when OpenGL offscreen buffer was failed to create, */ /* but could be other reasons. Should be handled in the future. nazgul */ @@ -5493,7 +5509,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) array = (float *)IDP_Array(view_data); memcpy(array, rv3d->winmat, sizeof(rv3d->winmat)); array += sizeof(rv3d->winmat) / sizeof(float); memcpy(array, rv3d->viewmat, sizeof(rv3d->viewmat)); array += sizeof(rv3d->viewmat) / sizeof(float); - is_ortho = ED_view3d_clip_range_get(v3d, rv3d, &array[0], &array[1], true); + is_ortho = ED_view3d_clip_range_get(CTX_data_depsgraph(C), v3d, rv3d, &array[0], &array[1], true); /* using float for a bool is dodgy but since its an extra member in the array... * easier then adding a single bool prop */ array[2] = is_ortho ? 1.0f : 0.0f; @@ -5593,7 +5609,7 @@ bool BKE_paint_proj_mesh_data_check(Scene *scene, Object *ob, bool *uvs, bool *m } me = BKE_mesh_from_object(ob); - layernum = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY); + layernum = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); if (layernum == 0) { hasuvs = false; @@ -5742,7 +5758,7 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op) BKE_texpaint_slot_refresh_cache(scene, ma); BKE_image_signal(ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE); WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima); - DAG_id_tag_update(&ma->id, 0); + DEG_id_tag_update(&ma->id, 0); ED_area_tag_redraw(CTX_wm_area(C)); BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); @@ -5858,7 +5874,7 @@ static int texture_paint_delete_texture_paint_slot_exec(bContext *C, wmOperator ma->mtex[slot->index] = NULL; BKE_texpaint_slot_refresh_cache(scene, ma); - DAG_id_tag_update(&ma->id, 0); + DEG_id_tag_update(&ma->id, 0); WM_event_add_notifier(C, NC_MATERIAL, ma); /* we need a notifier for data change since we change the displayed modifier uvs */ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); @@ -5916,7 +5932,7 @@ static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op)) BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); - DAG_id_tag_update(ob->data, 0); + DEG_id_tag_update(ob->data, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, scene); return OPERATOR_FINISHED; @@ -5924,11 +5940,11 @@ static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op)) static int add_simple_uvs_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - - if (!ob || ob->type != OB_MESH || ob->mode != OB_MODE_TEXTURE_PAINT) + if (!ob || (ob->type != OB_MESH) || (workspace->object_mode != OB_MODE_TEXTURE_PAINT)) { return false; - + } return true; } diff --git a/source/blender/editors/sculpt_paint/paint_image_undo.c b/source/blender/editors/sculpt_paint/paint_image_undo.c index b5b64eb3e16..d080c324d6c 100644 --- a/source/blender/editors/sculpt_paint/paint_image_undo.c +++ b/source/blender/editors/sculpt_paint/paint_image_undo.c @@ -34,10 +34,11 @@ #include "IMB_imbuf_types.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_image.h" #include "BKE_main.h" +#include "DEG_depsgraph.h" + #include "ED_paint.h" #include "GPU_draw.h" @@ -327,7 +328,7 @@ static void image_undo_restore_list(bContext *C, ListBase *lb) } ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; - DAG_id_tag_update(&ima->id, 0); + DEG_id_tag_update(&ima->id, 0); BKE_image_release_ibuf(ima, ibuf, NULL); } diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 52be4be4c0d..ccca0d248a5 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -156,10 +156,10 @@ void PAINT_OT_weight_sample_group(struct wmOperatorType *ot); /* paint_vertex_proj.c */ struct VertProjHandle; struct VertProjHandle *ED_vpaint_proj_handle_create( - struct Scene *scene, struct Object *ob, + const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct DMCoNo **r_vcosnos); void ED_vpaint_proj_handle_update( - struct VertProjHandle *vp_handle, + const struct EvaluationContext *eval_ctx, struct VertProjHandle *vp_handle, /* runtime vars */ struct ARegion *ar, const float mval_fl[2]); void ED_vpaint_proj_handle_free( @@ -253,7 +253,6 @@ bool paint_convert_bb_to_rect(struct rcti *rect, * 2D screens-space bounding box into four 3D planes) */ void paint_calc_redraw_planes(float planes[4][4], const struct ARegion *ar, - struct RegionView3D *rv3d, struct Object *ob, const struct rcti *screen_rect); diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index 76b629395e2..162c067166c 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -35,8 +35,6 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" -#include "BIF_glutil.h" - #include "BLI_bitmap_draw_2d.h" #include "BLI_math_matrix.h" #include "BLI_math_geom.h" @@ -52,6 +50,8 @@ #include "BKE_paint.h" #include "BKE_subsurf.h" +#include "DEG_depsgraph.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -134,6 +134,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); struct Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); + EvaluationContext eval_ctx; PaintMaskFloodMode mode; float value; PBVH *pbvh; @@ -142,10 +143,12 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) bool multires; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; + CTX_data_eval_ctx(C, &eval_ctx); + mode = RNA_enum_get(op->ptr, "mode"); value = RNA_float_get(op->ptr, "value"); - BKE_sculpt_update_mesh_elements(scene, sd, ob, false, true); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, false, true); pbvh = ob->sculpt->pbvh; multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS); @@ -258,9 +261,9 @@ static void mask_box_select_task_cb( int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *rect, bool select, bool UNUSED(extend)) { + EvaluationContext eval_ctx; Sculpt *sd = vc->scene->toolsettings->sculpt; BoundBox bb; - bglMats mats = {{0}}; float clip_planes[4][4]; float clip_planes_final[4][4]; ARegion *ar = vc->ar; @@ -274,15 +277,16 @@ int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *r int totnode, symmpass; int symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + CTX_data_eval_ctx(C, &eval_ctx); + mode = PAINT_MASK_FLOOD_VALUE; value = select ? 1.0 : 0.0; /* transform the clip planes in object space */ - view3d_get_transformation(vc->ar, vc->rv3d, vc->obact, &mats); - ED_view3d_clipping_calc(&bb, clip_planes, &mats, rect); + ED_view3d_clipping_calc(&bb, clip_planes, vc->ar, vc->obact, rect); negate_m4(clip_planes); - BKE_sculpt_update_mesh_elements(scene, sd, ob, false, true); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, false, true); pbvh = ob->sculpt->pbvh; multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS); @@ -424,9 +428,9 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); if (mcords) { + EvaluationContext eval_ctx; float clip_planes[4][4], clip_planes_final[4][4]; BoundBox bb; - bglMats mats = {{0}}; Object *ob; ViewContext vc; LassoMaskData data; @@ -440,11 +444,12 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) PaintMaskFloodMode mode = RNA_enum_get(op->ptr, "mode"); float value = RNA_float_get(op->ptr, "value"); + CTX_data_eval_ctx(C, &eval_ctx); + /* Calculations of individual vertices are done in 2D screen space to diminish the amount of * calculations done. Bounding box PBVH collision is not computed against enclosing rectangle * of lasso */ ED_view3d_viewcontext_init(C, &vc); - view3d_get_transformation(vc.ar, vc.rv3d, vc.obact, &mats); /* lasso data calculations */ data.vc = &vc; @@ -460,10 +465,10 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) mcords, mcords_tot, mask_lasso_px_cb, &data); - ED_view3d_clipping_calc(&bb, clip_planes, &mats, &data.rect); + ED_view3d_clipping_calc(&bb, clip_planes, vc.ar, vc.obact, &data.rect); negate_m4(clip_planes); - BKE_sculpt_update_mesh_elements(scene, sd, ob, false, true); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, false, true); pbvh = ob->sculpt->pbvh; multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 004d2757a71..c031a733630 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -40,6 +40,8 @@ #include "BKE_paint.h" #include "BKE_main.h" +#include "DEG_depsgraph.h" + #include "ED_paint.h" #include "ED_screen.h" #include "ED_image.h" @@ -260,7 +262,9 @@ static void PALETTE_OT_color_delete(wmOperatorType *ot) } static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) + { + const WorkSpace *workspace = CTX_wm_workspace(C); Paint *paint = BKE_paint_get_active_from_context(C); Brush *brush = BKE_paint_brush(paint); Object *ob = CTX_data_active_object(C); @@ -268,7 +272,7 @@ static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) if (!ob || !brush) return OPERATOR_CANCELLED; /* TODO: other modes */ - if (ob->mode & OB_MODE_SCULPT) { + if (workspace->object_mode & OB_MODE_SCULPT) { BKE_brush_sculpt_reset(brush); } else { @@ -401,6 +405,7 @@ static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, static int brush_select_exec(bContext *C, wmOperator *op) { + WorkSpace *workspace = CTX_wm_workspace(C); Main *bmain = CTX_data_main(C); ToolSettings *toolsettings = CTX_data_tool_settings(C); Paint *paint = NULL; @@ -414,7 +419,7 @@ static int brush_select_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); if (ob) { /* select current paint mode */ - paint_mode = ob->mode & OB_MODE_ALL_PAINT; + paint_mode = workspace->object_mode & OB_MODE_ALL_PAINT; } else { return OPERATOR_CANCELLED; diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index e6a9fd9adf8..861015375cb 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -51,6 +51,7 @@ #include "BKE_curve.h" #include "BKE_colortools.h" #include "BKE_image.h" +#include "BKE_mesh.h" #include "WM_api.h" #include "WM_types.h" @@ -58,7 +59,7 @@ #include "BIF_gl.h" #include "BIF_glutil.h" -#include "GPU_basic_shader.h" +#include "GPU_immediate.h" #include "ED_screen.h" #include "ED_view3d.h" @@ -147,9 +148,18 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata if (stroke && brush) { glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glColor4ubv(paint->paint_cursor_col); - sdrawline(x, y, (int)stroke->last_mouse_position[0], - (int)stroke->last_mouse_position[1]); + + unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformColor4ubv(paint->paint_cursor_col); + + immBegin(GWN_PRIM_LINES, 2); + immVertex2f(pos, x, y); + immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); + immEnd(); + + immUnbindProgram(); + glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } @@ -161,36 +171,35 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) PaintStroke *stroke = customdata; glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); - GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); - GPU_basic_shader_line_stipple(3, 0xAAAA); - GPU_basic_shader_line_width(3.0); + uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - glColor4ub(0, 0, 0, paint->paint_cursor_col[3]); - if (stroke->constrain_line) { - sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1], - stroke->constrained_pos[0], stroke->constrained_pos[1]); - } - else { - sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1], - x, y); - } + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); + + immUniform1i("num_colors", 2); /* "advanced" mode */ + const float alpha = (float)paint->paint_cursor_col[3] / 255.0f; + immUniformArray4fv("colors", (float *)(float[][4]){{0.0f, 0.0f, 0.0f, alpha}, {1.0f, 1.0f, 1.0f, alpha}}, 2); + immUniform1f("dash_width", 6.0f); + + immBegin(GWN_PRIM_LINES, 2); - glColor4ub(255, 255, 255, paint->paint_cursor_col[3]); - GPU_basic_shader_line_width(1.0); if (stroke->constrain_line) { - sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1], - stroke->constrained_pos[0], stroke->constrained_pos[1]); + immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); + immVertex2f(shdr_pos, stroke->constrained_pos[0], stroke->constrained_pos[1]); } else { - sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1], - x, y); + immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); + immVertex2f(shdr_pos, x, y); } - GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); + immEnd(); + + immUnbindProgram(); - glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 70fd57830c0..a45e33e4654 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -56,11 +56,13 @@ #include "BKE_paint.h" #include "BKE_report.h" +#include "DEG_depsgraph.h" + #include "RNA_access.h" #include "RNA_define.h" -#include "BIF_gl.h" -#include "BIF_glutil.h" +#include "GPU_glew.h" +#include "GPU_matrix.h" #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" @@ -130,17 +132,12 @@ bool paint_convert_bb_to_rect(rcti *rect, * 2D screens-space bounding box into four 3D planes) */ void paint_calc_redraw_planes(float planes[4][4], const ARegion *ar, - RegionView3D *rv3d, Object *ob, const rcti *screen_rect) { BoundBox bb; - bglMats mats; rcti rect; - memset(&bb, 0, sizeof(BoundBox)); - view3d_get_transformation(ar, rv3d, ob, &mats); - /* use some extra space just in case */ rect = *screen_rect; rect.xmin -= 2; @@ -148,7 +145,7 @@ void paint_calc_redraw_planes(float planes[4][4], rect.ymin -= 2; rect.ymax += 2; - ED_view3d_clipping_calc(&bb, planes, &mats, &rect); + ED_view3d_clipping_calc(&bb, planes, ar, ob, &rect); negate_m4(planes); } @@ -277,9 +274,9 @@ static void imapaint_tri_weights(float matrix[4][4], GLint view[4], } /* compute uv coordinates of mouse in face */ -static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2]) +static void imapaint_pick_uv(EvaluationContext *eval_ctx, Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2]) { - DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); const int tottri = dm->getNumLoopTri(dm); int i, findex; float p[2], w[3], absw, minabsw; @@ -293,8 +290,8 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c /* get the needed opengl matrices */ glGetIntegerv(GL_VIEWPORT, view); - glGetFloatv(GL_MODELVIEW_MATRIX, (float *)matrix); - glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj); + gpuGetModelViewMatrix(matrix); + gpuGetProjectionMatrix(proj); view[0] = view[1] = 0; mul_m4_m4m4(matrix, matrix, ob->obmat); mul_m4_m4m4(matrix, proj, matrix); @@ -355,13 +352,15 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c } /* returns 0 if not found, otherwise 1 */ -static int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *r_index, unsigned int totpoly) +static int imapaint_pick_face( + const struct EvaluationContext *eval_ctx, ViewContext *vc, const int mval[2], + unsigned int *r_index, unsigned int totpoly) { if (totpoly == 0) return 0; /* sample only on the exact position */ - *r_index = ED_view3d_backbuf_sample(vc, mval[0], mval[1]); + *r_index = ED_view3d_backbuf_sample(eval_ctx, vc, mval[0], mval[1]); if ((*r_index) == 0 || (*r_index) > (unsigned int)totpoly) { return 0; @@ -427,6 +426,7 @@ void flip_qt_qt(float out[4], const float in[4], const char symm) void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette) { Scene *scene = CTX_data_scene(C); + EvaluationContext eval_ctx; Paint *paint = BKE_paint_get_active_from_context(C); Palette *palette = BKE_paint_palette(paint); PaletteColor *color = NULL; @@ -434,6 +434,8 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr unsigned int col; const unsigned char *cp; + CTX_data_eval_ctx(C, &eval_ctx); + CLAMP(x, 0, ar->winx); CLAMP(y, 0, ar->winy); @@ -450,14 +452,15 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr if (CTX_wm_view3d(C) && texpaint_proj) { /* first try getting a colour directly from the mesh faces if possible */ - Object *ob = OBACT; + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); bool sample_success = false; ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); if (ob) { Mesh *me = (Mesh *)ob->data; - DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, scene, ob, CD_MASK_BAREMESH); ViewContext vc; const int mval[2] = {x, y}; @@ -469,7 +472,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr view3d_operator_needs_opengl(C); - if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { + if (imapaint_pick_face(&eval_ctx, &vc, mval, &faceindex, totpoly)) { Image *image; if (use_material) @@ -482,7 +485,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr if (ibuf && ibuf->rect) { float uv[2]; float u, v; - imapaint_pick_uv(scene, ob, faceindex, mval, uv); + imapaint_pick_uv(&eval_ctx, scene, ob, faceindex, mval, uv); sample_success = true; u = fmodf(uv[0], 1.0f); @@ -563,9 +566,11 @@ static int brush_curve_preset_exec(bContext *C, wmOperator *op) Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); if (br) { + const WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); BKE_brush_curve_preset(br, RNA_enum_get(op->ptr, "shape")); - BKE_paint_invalidate_cursor_overlay(scene, br->curve); + BKE_paint_invalidate_cursor_overlay(scene, view_layer, br->curve, workspace->object_mode); } return OPERATOR_FINISHED; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 4b2eb0fdd30..f8ad943ffef 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -54,8 +54,9 @@ #include "BKE_brush.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_deform.h" +#include "BKE_global.h" +#include "BKE_main.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" #include "BKE_object_deform.h" @@ -63,6 +64,8 @@ #include "BKE_report.h" #include "BKE_subsurf.h" +#include "DEG_depsgraph.h" + #include "WM_api.h" #include "WM_types.h" @@ -198,9 +201,12 @@ static void paint_last_stroke_update(Scene *scene, ARegion *ar, const float mval /* Returns true if vertex paint mode is active */ int vertex_paint_mode_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - - return ob && ob->mode == OB_MODE_VERTEX_PAINT && ((Mesh *)ob->data)->totpoly; + return (ob && + (ob->type == OB_MESH) && + ((Mesh *)ob->data)->totpoly && + (workspace->object_mode & OB_MODE_VERTEX_PAINT)); } int vertex_paint_poll(bContext *C) @@ -220,18 +226,22 @@ int vertex_paint_poll(bContext *C) int weight_paint_mode_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - - return ob && ob->mode == OB_MODE_WEIGHT_PAINT && ((Mesh *)ob->data)->totpoly; + return (ob && + (ob->type == OB_MESH) && + ((Mesh *)ob->data)->totpoly && + (workspace->object_mode == OB_MODE_WEIGHT_PAINT)); } int weight_paint_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); ScrArea *sa; if ((ob != NULL) && - (ob->mode & OB_MODE_WEIGHT_PAINT) && + (workspace->object_mode & OB_MODE_WEIGHT_PAINT) && (BKE_paint_brush(&CTX_data_tool_settings(C)->wpaint->paint) != NULL) && (sa = CTX_wm_area(C)) && (sa->spacetype == SPACE_VIEW3D)) @@ -937,28 +947,29 @@ static void do_weight_paint_vertex( /* Toggle operator for turning vertex paint mode on or off (copied from sculpt.c) */ -static void vertex_paint_init_session(Scene *scene, Object *ob) +static void vertex_paint_init_session(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) { /* Create persistent sculpt mode data */ BKE_sculpt_toolsettings_data_ensure(scene); if (ob->sculpt == NULL) { ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); - BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false); + BKE_sculpt_update_mesh_elements(eval_ctx, scene, scene->toolsettings->sculpt, ob, 0, false); } } -static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) +static void vertex_paint_init_session_data( + const EvaluationContext *eval_ctx, const ToolSettings *ts, Object *ob) { /* Create maps */ struct SculptVertexPaintGeomMap *gmap = NULL; const Brush *brush = NULL; - if (ob->mode == OB_MODE_VERTEX_PAINT) { + if (eval_ctx->object_mode == OB_MODE_VERTEX_PAINT) { gmap = &ob->sculpt->mode.vpaint.gmap; brush = BKE_paint_brush(&ts->vpaint->paint); ob->sculpt->mode_type = OB_MODE_VERTEX_PAINT; } - else if (ob->mode == OB_MODE_WEIGHT_PAINT) { + else if (eval_ctx->object_mode == OB_MODE_WEIGHT_PAINT) { gmap = &ob->sculpt->mode.wpaint.gmap; brush = BKE_paint_brush(&ts->wpaint->paint); ob->sculpt->mode_type = OB_MODE_WEIGHT_PAINT; @@ -987,7 +998,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) } /* Create average brush arrays */ - if (ob->mode == OB_MODE_VERTEX_PAINT) { + if (eval_ctx->object_mode == OB_MODE_VERTEX_PAINT) { if (!brush_use_accumulate(brush)) { if (ob->sculpt->mode.vpaint.previous_color == NULL) { ob->sculpt->mode.vpaint.previous_color = @@ -998,7 +1009,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) MEM_SAFE_FREE(ob->sculpt->mode.vpaint.previous_color); } } - else if (ob->mode == OB_MODE_WEIGHT_PAINT) { + else if (eval_ctx->object_mode == OB_MODE_WEIGHT_PAINT) { if (!brush_use_accumulate(brush)) { if (ob->sculpt->mode.wpaint.alpha_weight == NULL) { ob->sculpt->mode.wpaint.alpha_weight = @@ -1031,11 +1042,12 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) * \{ */ static void ed_vwpaintmode_enter_generic( + const EvaluationContext *eval_ctx, wmWindowManager *wm, - Scene *scene, + WorkSpace *workspace, Scene *scene, Object *ob, const eObjectMode mode_flag) { - ob->mode |= mode_flag; + workspace->object_mode |= mode_flag; Mesh *me = BKE_mesh_from_object(ob); if (mode_flag == OB_MODE_VERTEX_PAINT) { @@ -1078,37 +1090,45 @@ static void ed_vwpaintmode_enter_generic( BKE_sculptsession_free(ob); } - vertex_paint_init_session(scene, ob); + vertex_paint_init_session(eval_ctx, scene, ob); + + ED_workspace_object_mode_sync_from_object(wm, workspace, ob); } void ED_object_vpaintmode_enter_ex( - wmWindowManager *wm, - Scene *scene, Object *ob) + const EvaluationContext *eval_ctx, wmWindowManager *wm, + WorkSpace *workspace, Scene *scene, Object *ob) { ed_vwpaintmode_enter_generic( - wm, scene, ob, OB_MODE_VERTEX_PAINT); + eval_ctx, wm, workspace, scene, ob, OB_MODE_VERTEX_PAINT); } void ED_object_vpaintmode_enter(struct bContext *C) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); wmWindowManager *wm = CTX_wm_manager(C); + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - ED_object_vpaintmode_enter_ex(wm, scene, ob); + ED_object_vpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); } void ED_object_wpaintmode_enter_ex( - wmWindowManager *wm, - Scene *scene, Object *ob) + const EvaluationContext *eval_ctx, wmWindowManager *wm, + WorkSpace *workspace, Scene *scene, Object *ob) { ed_vwpaintmode_enter_generic( - wm, scene, ob, OB_MODE_WEIGHT_PAINT); + eval_ctx, wm, workspace, scene, ob, OB_MODE_WEIGHT_PAINT); } void ED_object_wpaintmode_enter(struct bContext *C) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); wmWindowManager *wm = CTX_wm_manager(C); + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - ED_object_wpaintmode_enter_ex(wm, scene, ob); + ED_object_wpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); } /** \} */ @@ -1118,10 +1138,11 @@ void ED_object_wpaintmode_enter(struct bContext *C) * \{ */ static void ed_vwpaintmode_exit_generic( + WorkSpace *workspace, Object *ob, const eObjectMode mode_flag) { Mesh *me = BKE_mesh_from_object(ob); - ob->mode &= ~mode_flag; + workspace->object_mode &= ~mode_flag; if (mode_flag == OB_MODE_VERTEX_PAINT) { if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { @@ -1157,26 +1178,30 @@ static void ed_vwpaintmode_exit_generic( ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e'); ED_mesh_mirror_topo_table(NULL, NULL, 'e'); } + + ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, ob); } -void ED_object_vpaintmode_exit_ex(Object *ob) +void ED_object_vpaintmode_exit_ex(WorkSpace *workspace, Object *ob) { - ed_vwpaintmode_exit_generic(ob, OB_MODE_VERTEX_PAINT); + ed_vwpaintmode_exit_generic(workspace, ob, OB_MODE_VERTEX_PAINT); } void ED_object_vpaintmode_exit(struct bContext *C) { + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - ED_object_vpaintmode_exit_ex(ob); + ED_object_vpaintmode_exit_ex(workspace, ob); } -void ED_object_wpaintmode_exit_ex(Object *ob) +void ED_object_wpaintmode_exit_ex(WorkSpace *workspace, Object *ob) { - ed_vwpaintmode_exit_generic(ob, OB_MODE_WEIGHT_PAINT); + ed_vwpaintmode_exit_generic(workspace, ob, OB_MODE_WEIGHT_PAINT); } void ED_object_wpaintmode_exit(struct bContext *C) { + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - ED_object_wpaintmode_exit_ex(ob); + ED_object_wpaintmode_exit_ex(workspace, ob); } /** \} */ @@ -1188,13 +1213,14 @@ void ED_object_wpaintmode_exit(struct bContext *C) */ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) { + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_WEIGHT_PAINT; - const bool is_mode_set = (ob->mode & mode_flag) != 0; + const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; Scene *scene = CTX_data_scene(C); if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } @@ -1202,19 +1228,23 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) Mesh *me = BKE_mesh_from_object(ob); if (is_mode_set) { - ED_object_wpaintmode_exit_ex(ob); + ED_object_wpaintmode_exit_ex(workspace, ob); } else { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); wmWindowManager *wm = CTX_wm_manager(C); - ED_object_wpaintmode_enter_ex(wm, scene, ob); + ED_object_wpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); } + BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + /* Weightpaint works by overriding colors in mesh, * so need to make sure we recalc on enter and * exit (exit needs doing regardless because we * should redeform). */ - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); @@ -1397,11 +1427,14 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo bool *defbase_sel; SculptSession *ss = ob->sculpt; VPaint *vp = CTX_data_tool_settings(C)->wpaint; + EvaluationContext eval_ctx; if (ED_wpaint_ensure_data(C, op->reports, WPAINT_ENSURE_MIRROR, &vgroup_index) == false) { return false; } + CTX_data_eval_ctx(C, &eval_ctx); + { /* check if we are attempting to paint onto a locked vertex group, * and other options disallow it from doing anything useful */ @@ -1500,9 +1533,9 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo } /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_session(scene, ob); + vertex_paint_init_session(&eval_ctx, scene, ob); vwpaint_update_cache_invariants(C, vp, ss, op, mouse); - vertex_paint_init_session_data(ts, ob); + vertex_paint_init_session_data(&eval_ctx, ts, ob); if (ob->sculpt->mode.wpaint.dvert_prev != NULL) { MDeformVert *dv = ob->sculpt->mode.wpaint.dvert_prev; @@ -1941,7 +1974,8 @@ static void wpaint_paint_leaves( /* threaded loop over nodes */ SculptThreadedTaskData data = { - .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .wpd = wpd, .wpi = wpi, .me = me, .C = C, + .C = C, .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, + .vp = vp, .wpd = wpd, .wpi = wpi, .me = me, }; /* Use this so average can modify its weight without touching the brush. */ @@ -2169,7 +2203,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* also needed for "View Selected" on last stroke */ paint_last_stroke_update(scene, vc->ar, mval); - DAG_id_tag_update(ob->data, 0); + BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + + DEG_id_tag_update(ob->data, 0); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); swap_m4m4(wpd->vc.rv3d->persmat, mat); @@ -2233,7 +2269,7 @@ static void wpaint_stroke_done(const bContext *C, struct PaintStroke *stroke) } } - DAG_id_tag_update(ob->data, 0); + DEG_id_tag_update(ob->data, 0); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); @@ -2315,13 +2351,14 @@ void PAINT_OT_weight_paint(wmOperatorType *ot) */ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) { + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_VERTEX_PAINT; - const bool is_mode_set = (ob->mode & mode_flag) != 0; + const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; Scene *scene = CTX_data_scene(C); if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } @@ -2330,15 +2367,19 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) /* toggle: end vpaint */ if (is_mode_set) { - ED_object_vpaintmode_exit_ex(ob); + ED_object_vpaintmode_exit_ex(workspace, ob); } else { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); wmWindowManager *wm = CTX_wm_manager(C); - ED_object_vpaintmode_enter_ex(wm, scene, ob); + ED_object_vpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); } + BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + /* update modifier stack for mapping requirements */ - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); @@ -2424,6 +2465,9 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f Object *ob = CTX_data_active_object(C); Mesh *me; SculptSession *ss = ob->sculpt; + EvaluationContext eval_ctx; + + CTX_data_eval_ctx(C, &eval_ctx); /* context checks could be a poll() */ me = BKE_mesh_from_object(ob); @@ -2471,14 +2515,14 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f /* Create projection handle */ if (vpd->is_texbrush) { ob->sculpt->building_vp_handle = true; - vpd->vp_handle = ED_vpaint_proj_handle_create(scene, ob, &vpd->vertexcosnos); + vpd->vp_handle = ED_vpaint_proj_handle_create(&eval_ctx, scene, ob, &vpd->vertexcosnos); ob->sculpt->building_vp_handle = false; } /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_session(scene, ob); + vertex_paint_init_session(&eval_ctx, scene, ob); vwpaint_update_cache_invariants(C, vp, ss, op, mouse); - vertex_paint_init_session_data(ts, ob); + vertex_paint_init_session_data(&eval_ctx, ts, ob); if (ob->sculpt->mode.vpaint.previous_color != NULL) { memset(ob->sculpt->mode.vpaint.previous_color, 0, sizeof(uint) * me->totloop); @@ -2932,8 +2976,8 @@ static void vpaint_paint_leaves( const Brush *brush = ob->sculpt->cache->brush; SculptThreadedTaskData data = { - .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .vpd = vpd, - .lcol = (uint *)me->mloopcol, .me = me, .C = C, + .C = C, .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .vpd = vpd, + .lcol = (uint *)me->mloopcol, .me = me, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -3070,6 +3114,8 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P swap_m4m4(vc->rv3d->persmat, mat); + BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + if (vp->paint.brush->vertexpaint_tool == PAINT_BLEND_SMEAR) { memcpy(vpd->smear.color_prev, vpd->smear.color_curr, sizeof(uint) * ((Mesh *)ob->data)->totloop); } @@ -3083,7 +3129,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if (vpd->use_fast_update == false) { /* recalculate modifier stack to get new colors, slow, * avoid this if we can! */ - DAG_id_tag_update(ob->data, 0); + DEG_id_tag_update(ob->data, 0); } else { /* If using new VBO drawing, mark mcol as dirty to force colors gpu buffer refresh! */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c index b69ca32e5af..f442c12cbe9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c @@ -28,15 +28,17 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_workspace_types.h" #include "BLI_math_base.h" #include "BLI_math_color.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_mesh.h" #include "BKE_deform.h" +#include "DEG_depsgraph.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -50,9 +52,10 @@ static int vertex_weight_paint_mode_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); Mesh *me = BKE_mesh_from_object(ob); - return (ob && (ob->mode == OB_MODE_VERTEX_PAINT || ob->mode == OB_MODE_WEIGHT_PAINT)) && + return (ob && ELEM(workspace->object_mode, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT)) && (me && me->totpoly && me->dvert); } @@ -97,7 +100,7 @@ static bool vertex_color_set(Object *ob, uint paintcol) /* remove stale me->mcol, will be added later */ BKE_mesh_tessface_clear(me); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); return true; } @@ -168,7 +171,7 @@ static bool vertex_paint_from_weight(Object *ob) } while (j < mp->totloop); } - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); return true; } @@ -304,7 +307,7 @@ static bool vertex_color_smooth(Object *ob) MEM_freeN(mlooptag); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); return true; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c index 398512287c4..a8045232e05 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c @@ -38,9 +38,10 @@ #include "IMB_colormanagement.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_mesh.h" +#include "DEG_depsgraph.h" + #include "ED_mesh.h" #include "paint_intern.h" /* own include */ @@ -87,7 +88,7 @@ bool ED_vpaint_color_transform( /* remove stale me->mcol, will be added later */ BKE_mesh_tessface_clear(me); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); return true; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_proj.c b/source/blender/editors/sculpt_paint/paint_vertex_proj.c index 411a0ca9ec3..336f851d4c1 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_proj.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_proj.c @@ -42,6 +42,8 @@ #include "BKE_DerivedMesh.h" #include "BKE_context.h" +#include "DEG_depsgraph.h" + #include "ED_screen.h" #include "ED_view3d.h" @@ -100,13 +102,13 @@ static void vpaint_proj_dm_map_cosnos_init__map_cb( } static void vpaint_proj_dm_map_cosnos_init( - Scene *scene, Object *ob, + const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, struct VertProjHandle *vp_handle) { Mesh *me = ob->data; DerivedMesh *dm; - dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); if (dm->foreachMappedVert) { memset(vp_handle->vcosnos, 0, sizeof(DMCoNo) * me->totvert); @@ -174,7 +176,7 @@ static void vpaint_proj_dm_map_cosnos_update__map_cb( } static void vpaint_proj_dm_map_cosnos_update( - struct VertProjHandle *vp_handle, + const struct EvaluationContext *eval_ctx, struct VertProjHandle *vp_handle, ARegion *ar, const float mval_fl[2]) { struct VertProjUpdate vp_update = {vp_handle, ar, mval_fl}; @@ -187,7 +189,7 @@ static void vpaint_proj_dm_map_cosnos_update( /* quick sanity check - we shouldn't have to run this if there are no modifiers */ BLI_assert(BLI_listbase_is_empty(&ob->modifiers) == false); - dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); /* highly unlikely this will become unavailable once painting starts (perhaps with animated modifiers) */ if (LIKELY(dm->foreachMappedVert)) { @@ -204,7 +206,7 @@ static void vpaint_proj_dm_map_cosnos_update( /* Public Functions */ struct VertProjHandle *ED_vpaint_proj_handle_create( - Scene *scene, Object *ob, + const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, DMCoNo **r_vcosnos) { struct VertProjHandle *vp_handle = MEM_mallocN(sizeof(struct VertProjHandle), __func__); @@ -215,7 +217,7 @@ struct VertProjHandle *ED_vpaint_proj_handle_create( vp_handle->use_update = false; /* sets 'use_update' if needed */ - vpaint_proj_dm_map_cosnos_init(scene, ob, vp_handle); + vpaint_proj_dm_map_cosnos_init(eval_ctx, scene, ob, vp_handle); if (vp_handle->use_update) { vp_handle->dists_sq = MEM_mallocN(sizeof(float) * me->totvert, __func__); @@ -235,11 +237,11 @@ struct VertProjHandle *ED_vpaint_proj_handle_create( } void ED_vpaint_proj_handle_update( - struct VertProjHandle *vp_handle, + const struct EvaluationContext *eval_ctx, struct VertProjHandle *vp_handle, ARegion *ar, const float mval_fl[2]) { if (vp_handle->use_update) { - vpaint_proj_dm_map_cosnos_update(vp_handle, ar, mval_fl); + vpaint_proj_dm_map_cosnos_update(eval_ctx, vp_handle, ar, mval_fl); } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index 21435ef153a..7ff9c3851ac 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -49,7 +49,6 @@ #include "BKE_DerivedMesh.h" #include "BKE_brush.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_deform.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" @@ -59,6 +58,8 @@ #include "BKE_report.h" #include "BKE_colortools.h" +#include "DEG_depsgraph.h" + #include "WM_api.h" #include "WM_types.h" @@ -117,9 +118,10 @@ static void wpaint_prev_destroy(struct WPaintPrev *wpp) static int weight_from_bones_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - return (ob && (ob->mode & OB_MODE_WEIGHT_PAINT) && modifiers_isDeformedByArmature(ob)); + return (ob && (workspace->object_mode & OB_MODE_WEIGHT_PAINT) && modifiers_isDeformedByArmature(ob)); } static int weight_from_bones_exec(bContext *C, wmOperator *op) @@ -130,9 +132,13 @@ static int weight_from_bones_exec(bContext *C, wmOperator *op) Mesh *me = ob->data; int type = RNA_enum_get(op->ptr, "type"); - create_vgroups_from_armature(op->reports, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); + EvaluationContext eval_ctx; + + CTX_data_eval_ctx(C, &eval_ctx); + + create_vgroups_from_armature(op->reports, &eval_ctx, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; @@ -366,7 +372,7 @@ static int weight_sample_group_exec(bContext *C, wmOperator *op) BLI_assert(type + 1 >= 0); vc.obact->actdef = type + 1; - DAG_id_tag_update(&vc.obact->id, OB_RECALC_DATA); + DEG_id_tag_update(&vc.obact->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, vc.obact); return OPERATOR_FINISHED; } @@ -482,7 +488,7 @@ static bool weight_paint_set(Object *ob, float paintweight) wpaint_prev_destroy(&wpp); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); return true; } @@ -694,7 +700,7 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven } MEM_freeN(vert_cache); - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); } else if (ret & OPERATOR_FINISHED) { @@ -720,7 +726,12 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) float sco_start[2] = {x_start, y_start}; float sco_end[2] = {x_end, y_end}; const bool is_interactive = (gesture != NULL); - DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); + + EvaluationContext eval_ctx; + + CTX_data_eval_ctx(C, &eval_ctx); + + DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, scene, ob, scene->customdata_mask); DMGradient_userData data = {NULL}; @@ -792,7 +803,7 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) dm->foreachMappedVert(dm, gradientVertUpdate__mapFunc, &data, DM_FOREACH_NOP); } - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); if (is_interactive == false) { diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c index 4d70d82d5c6..51cd759b260 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c @@ -43,6 +43,7 @@ #include "BKE_modifier.h" #include "BKE_object_deform.h" #include "BKE_report.h" +#include "BKE_object.h" #include "WM_api.h" #include "WM_types.h" @@ -58,7 +59,6 @@ bool ED_wpaint_ensure_data( bContext *C, struct ReportList *reports, enum eWPaintFlag flag, struct WPaintVGroupIndex *vgroup_index) { - Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Mesh *me = BKE_mesh_from_object(ob); @@ -67,7 +67,7 @@ bool ED_wpaint_ensure_data( vgroup_index->mirror = -1; } - if (scene->obedit) { + if (BKE_object_is_in_editmode(ob)) { return false; } @@ -308,4 +308,4 @@ float ED_wpaint_blend_tool( } } -/** \} */
\ No newline at end of file +/** \} */ diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index ede1269e220..2d847d53877 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -56,7 +56,6 @@ #include "BKE_brush.h" #include "BKE_ccg.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_image.h" #include "BKE_key.h" @@ -73,6 +72,8 @@ #include "BKE_subsurf.h" #include "BKE_colortools.h" +#include "DEG_depsgraph.h" + #include "WM_api.h" #include "WM_types.h" @@ -500,8 +501,7 @@ bool sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, return 1; } -void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, - RegionView3D *rv3d, Object *ob) +void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, Object *ob) { PBVH *pbvh = ob->sculpt->pbvh; /* copy here, original will be used below */ @@ -509,7 +509,7 @@ void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, sculpt_extend_redraw_rect_previous(ob, &rect); - paint_calc_redraw_planes(planes, ar, rv3d, ob, &rect); + paint_calc_redraw_planes(planes, ar, ob, &rect); /* we will draw this rect, so now we can set it as the previous partial rect. * Note that we don't update with the union of previous/current (rect), only with @@ -2099,6 +2099,10 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); + /* XXX - this shouldn't be necessary, but sculpting crashes in blender2.8 otherwise + * initialize before threads so they can do curve mapping */ + curvemapping_initialize(brush->curve); + /* threaded loop over nodes */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, @@ -4079,8 +4083,9 @@ static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) int sculpt_mode_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - return ob && ob->mode & OB_MODE_SCULPT; + return ob && workspace->object_mode & OB_MODE_SCULPT; } int sculpt_mode_poll_view3d(bContext *C) @@ -4597,10 +4602,12 @@ static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob, const B SculptSession *ss = ob->sculpt; if (ss->kb || ss->modifiers_active) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); Scene *scene = CTX_data_scene(C); Sculpt *sd = scene->toolsettings->sculpt; bool need_pmap = sculpt_any_smooth_mode(brush, ss->cache, 0); - BKE_sculpt_update_mesh_elements(scene, sd, ob, need_pmap, false); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, need_pmap, false); } } @@ -4685,7 +4692,7 @@ static float sculpt_raycast_init( RegionView3D *rv3d = vc->ar->regiondata; /* TODO: what if the segment is totally clipped? (return == 0) */ - ED_view3d_win_to_segment(vc->ar, vc->v3d, mouse, ray_start, ray_end, true); + ED_view3d_win_to_segment(vc->depsgraph, vc->ar, vc->v3d, mouse, ray_start, ray_end, true); invert_m4_m4(obimat, ob->obmat); mul_m4_v3(obimat, ray_start); @@ -4806,12 +4813,15 @@ static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; + EvaluationContext eval_ctx; SculptSession *ss = CTX_data_active_object(C)->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); int mode = RNA_enum_get(op->ptr, "mode"); bool is_smooth; bool need_mask = false; + CTX_data_eval_ctx(C, &eval_ctx); + if (brush->sculpt_tool == SCULPT_TOOL_MASK) { need_mask = true; } @@ -4820,7 +4830,7 @@ static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) sculpt_brush_init_tex(scene, sd, ss); is_smooth = sculpt_any_smooth_mode(brush, NULL, mode); - BKE_sculpt_update_mesh_elements(scene, sd, ob, is_smooth, need_mask); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, is_smooth, need_mask); return 1; } @@ -4864,7 +4874,7 @@ static void sculpt_flush_update(bContext *C) GPU_drawobject_free(ob->derivedFinal); if (ss->kb || ss->modifiers_active) { - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); ED_region_tag_redraw(ar); } else { @@ -4894,6 +4904,9 @@ static void sculpt_flush_update(bContext *C) ED_region_tag_redraw_partial(ar, &r); } } + + /* 2.8x - avoid full mesh update! */ + BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_SCULPT_COORDS); } /* Returns whether the mouse/stylus is over the mesh (1) @@ -4977,7 +4990,7 @@ static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *UNUSED(st * Could be optimized later, but currently don't think it's so * much common scenario. * - * Same applies to the DAG_id_tag_update() invoked from + * Same applies to the DEG_id_tag_update() invoked from * sculpt_flush_update(). */ if (ss->modifiers_active) { @@ -5051,7 +5064,7 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str /* try to avoid calling this, only for e.g. linked duplicates now */ if (((Mesh *)ob->data)->id.us > 1) - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); } @@ -5207,7 +5220,7 @@ void sculpt_pbvh_clear(Object *ob) BKE_pbvh_free(ss->pbvh); ss->pbvh = NULL; if (dm) - dm->getPBVH(NULL, dm); + dm->getPBVH(NULL, dm, OB_MODE_OBJECT); BKE_object_free_derived_caches(ob); } @@ -5244,16 +5257,18 @@ void sculpt_dyntopo_node_layers_add(SculptSession *ss) void sculpt_update_after_dynamic_topology_toggle( + const EvaluationContext *eval_ctx, Scene *scene, Object *ob) { Sculpt *sd = scene->toolsettings->sculpt; /* Create the PBVH */ - BKE_sculpt_update_mesh_elements(scene, sd, ob, false, false); + BKE_sculpt_update_mesh_elements(eval_ctx, scene, sd, ob, false, false); WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob); } void sculpt_dynamic_topology_enable_ex( + const EvaluationContext *eval_ctx, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; @@ -5291,7 +5306,7 @@ void sculpt_dynamic_topology_enable_ex( ss->bm_log = BM_log_create(ss->bm); /* Refresh */ - sculpt_update_after_dynamic_topology_toggle(scene, ob); + sculpt_update_after_dynamic_topology_toggle(eval_ctx, scene, ob); } /* Free the sculpt BMesh and BMLog @@ -5299,6 +5314,7 @@ void sculpt_dynamic_topology_enable_ex( * If 'unode' is given, the BMesh's data is copied out to the unode * before the BMesh is deleted so that it can be restored from */ void sculpt_dynamic_topology_disable_ex( + const EvaluationContext *eval_ctx, Scene *scene, Object *ob, SculptUndoNode *unode) { SculptSession *ss = ob->sculpt; @@ -5349,35 +5365,38 @@ void sculpt_dynamic_topology_disable_ex( } /* Refresh */ - sculpt_update_after_dynamic_topology_toggle(scene, ob); + sculpt_update_after_dynamic_topology_toggle(eval_ctx, scene, ob); } void sculpt_dynamic_topology_disable(bContext *C, SculptUndoNode *unode) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - sculpt_dynamic_topology_disable_ex(scene, ob, unode); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + sculpt_dynamic_topology_disable_ex(&eval_ctx, scene, ob, unode); } static void sculpt_dynamic_topology_disable_with_undo( - Scene *scene, Object *ob) + const EvaluationContext *eval_ctx, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->bm) { sculpt_undo_push_begin("Dynamic topology disable"); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END); - sculpt_dynamic_topology_disable_ex(scene, ob, NULL); + sculpt_dynamic_topology_disable_ex(eval_ctx, scene, ob, NULL); sculpt_undo_push_end(); } } static void sculpt_dynamic_topology_enable_with_undo( + const EvaluationContext *eval_ctx, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->bm == NULL) { sculpt_undo_push_begin("Dynamic topology enable"); - sculpt_dynamic_topology_enable_ex(scene, ob); + sculpt_dynamic_topology_enable_ex(eval_ctx, scene, ob); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); sculpt_undo_push_end(); } @@ -5388,14 +5407,16 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(o Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); WM_cursor_wait(1); if (ss->bm) { - sculpt_dynamic_topology_disable_with_undo(scene, ob); + sculpt_dynamic_topology_disable_with_undo(&eval_ctx, scene, ob); } else { - sculpt_dynamic_topology_enable_with_undo(scene, ob); + sculpt_dynamic_topology_enable_with_undo(&eval_ctx, scene, ob); } WM_cursor_wait(0); @@ -5606,13 +5627,14 @@ static void SCULPT_OT_symmetrize(wmOperatorType *ot) /**** Toggle operator for turning sculpt mode on or off ****/ -static void sculpt_init_session(Scene *scene, Object *ob) +static void sculpt_init_session(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) { /* Create persistent sculpt mode data */ BKE_sculpt_toolsettings_data_ensure(scene); ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); - BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false); + ob->sculpt->mode_type = OB_MODE_SCULPT; + BKE_sculpt_update_mesh_elements(eval_ctx, scene, scene->toolsettings->sculpt, ob, 0, false); } static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, MultiresModifierData *mmd) @@ -5626,30 +5648,29 @@ static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, Mult } void ED_object_sculptmode_enter_ex( - Scene *scene, Object *ob, + const EvaluationContext *eval_ctx, + WorkSpace *workspace, Scene *scene, Object *ob, ReportList *reports) { const int mode_flag = OB_MODE_SCULPT; Mesh *me = BKE_mesh_from_object(ob); /* Enter sculptmode */ - ob->mode |= mode_flag; - + workspace->object_mode |= mode_flag; MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd); - if (flush_recalc) { - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - } + if (flush_recalc) + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* Create sculpt mode session data */ if (ob->sculpt) { BKE_sculptsession_free(ob); } - sculpt_init_session(scene, ob); + sculpt_init_session(eval_ctx, scene, ob); /* Mask layer is required */ if (mmd) { @@ -5707,7 +5728,7 @@ void ED_object_sculptmode_enter_ex( if (message_unsupported == NULL) { /* undo push is needed to prevent memory leak */ sculpt_undo_push_begin("Dynamic topology enable"); - sculpt_dynamic_topology_enable_ex(scene, ob); + sculpt_dynamic_topology_enable_ex(eval_ctx, scene, ob); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); } else { @@ -5718,6 +5739,8 @@ void ED_object_sculptmode_enter_ex( } } + ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, ob); + /* VBO no longer valid */ if (ob->derivedFinal) { GPU_drawobject_free(ob->derivedFinal); @@ -5726,13 +5749,17 @@ void ED_object_sculptmode_enter_ex( void ED_object_sculptmode_enter(struct bContext *C, ReportList *reports) { + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - ED_object_sculptmode_enter_ex(scene, ob, reports); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + ED_object_sculptmode_enter_ex(&eval_ctx, workspace, scene, ob, reports); } void ED_object_sculptmode_exit_ex( - Scene *scene, Object *ob) + const EvaluationContext *eval_ctx, + WorkSpace *workspace, Scene *scene, Object *ob) { const int mode_flag = OB_MODE_SCULPT; Mesh *me = BKE_mesh_from_object(ob); @@ -5741,7 +5768,7 @@ void ED_object_sculptmode_exit_ex( if (mmd) { multires_force_update(ob); } - + /* Not needed for now. */ #if 0 const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd); @@ -5751,21 +5778,23 @@ void ED_object_sculptmode_exit_ex( * a consistent state. */ if (true || /* flush_recalc || */ (ob->sculpt && ob->sculpt->bm)) { - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) { /* Dynamic topology must be disabled before exiting sculpt * mode to ensure the undo stack stays in a consistent * state */ - sculpt_dynamic_topology_disable_with_undo(scene, ob); + sculpt_dynamic_topology_disable_with_undo(eval_ctx, scene, ob); /* store so we know to re-enable when entering sculpt mode */ me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; } /* Leave sculptmode */ - ob->mode &= ~mode_flag; + workspace->object_mode &= ~mode_flag; + + ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, ob); BKE_sculptsession_free(ob); @@ -5779,29 +5808,36 @@ void ED_object_sculptmode_exit_ex( void ED_object_sculptmode_exit(bContext *C) { + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - ED_object_sculptmode_exit_ex(scene, ob); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + ED_object_sculptmode_exit_ex(&eval_ctx, workspace, scene, ob); } static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) { + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_SCULPT; - const bool is_mode_set = (ob->mode & mode_flag) != 0; + const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + if (is_mode_set) { - ED_object_sculptmode_exit_ex(scene, ob); + ED_object_sculptmode_exit_ex(&eval_ctx, workspace, scene, ob); } else { - ED_object_sculptmode_enter_ex(scene, ob, op->reports); + ED_object_sculptmode_enter_ex(&eval_ctx, workspace, scene, ob, op->reports); } WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index cf1937f14d4..54cdbb18693 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -61,12 +61,15 @@ bool sculpt_stroke_get_location(struct bContext *C, float out[3], const float mo void sculpt_pbvh_clear(Object *ob); void sculpt_dyntopo_node_layers_add(struct SculptSession *ss); void sculpt_update_after_dynamic_topology_toggle( + const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); void sculpt_dynamic_topology_enable_ex( + const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); void sculpt_dynamic_topology_enable(bContext *C); void sculpt_dynamic_topology_disable_ex( + const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct SculptUndoNode *unode); void sculpt_dynamic_topology_disable(bContext *C, struct SculptUndoNode *unode); diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 794ac14483a..55950a51fba 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -51,12 +51,12 @@ #include "BKE_ccg.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_multires.h" #include "BKE_paint.h" #include "BKE_key.h" #include "BKE_mesh.h" #include "BKE_subsurf.h" +#include "DEG_depsgraph.h" #include "WM_api.h" #include "WM_types.h" @@ -127,9 +127,12 @@ static bool sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoN Scene *scene = CTX_data_scene(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); + EvaluationContext eval_ctx; SculptSession *ss = ob->sculpt; MVert *mvert; int *index; + + CTX_data_eval_ctx(C, &eval_ctx); if (unode->maxvert) { /* regular mesh restore */ @@ -143,7 +146,7 @@ static bool sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoN if (kb) { ob->shapenr = BLI_findindex(&key->block, kb) + 1; - BKE_sculpt_update_mesh_elements(scene, sd, ob, 0, false); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, 0, false); WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob); } else { @@ -365,8 +368,8 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C, } /* Create empty sculpt BMesh and enable logging */ -static void sculpt_undo_bmesh_enable(Object *ob, - SculptUndoNode *unode) +static void sculpt_undo_bmesh_enable( + Object *ob, SculptUndoNode *unode) { SculptSession *ss = ob->sculpt; Mesh *me = ob->data; @@ -459,6 +462,7 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb) Scene *scene = CTX_data_scene(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); + EvaluationContext eval_ctx; DerivedMesh *dm; SculptSession *ss = ob->sculpt; SculptUndoNode *unode; @@ -466,6 +470,8 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb) bool need_mask = false; bool partial_update = true; + CTX_data_eval_ctx(C, &eval_ctx); + for (unode = lb->first; unode; unode = unode->next) { if (STREQ(unode->idname, ob->id.name)) { if (unode->type == SCULPT_UNDO_MASK) { @@ -477,10 +483,10 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb) } } - BKE_sculpt_update_mesh_elements(scene, sd, ob, 0, need_mask); + BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, 0, need_mask); /* call _after_ sculpt_update_mesh_elements() which may update 'ob->derivedFinal' */ - dm = mesh_get_derived_final(scene, ob, 0); + dm = mesh_get_derived_final(&eval_ctx, scene, ob, 0); if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss)) return; @@ -563,7 +569,7 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb) } if (tag_update) { - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { sculpt_update_object_bounding_box(ob); diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index e39750227c0..6928610f280 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -46,15 +46,19 @@ #include "BKE_paint.h" #include "BKE_colortools.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_mesh_mapping.h" #include "BKE_customdata.h" #include "BKE_editmesh.h" +#include "DEG_depsgraph.h" + #include "ED_screen.h" #include "ED_image.h" #include "ED_mesh.h" +#include "GPU_immediate.h" +#include "GPU_immediate_util.h" + #include "WM_api.h" #include "WM_types.h" @@ -64,9 +68,6 @@ #include "paint_intern.h" #include "uvedit_intern.h" -#include "BIF_gl.h" -#include "BIF_glutil.h" - #include "UI_view2d.h" #define MARK_BOUNDARY 1 @@ -212,18 +213,17 @@ static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(cu alpha *= (size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN); } - glPushMatrix(); - - glTranslatef((float)x, (float)y, 0.0f); + unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformColor3fvAlpha(brush->add_col, alpha); - glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size, 40); + imm_draw_circle_wire_2d(pos, (float)x, (float)y, size, 40); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); - glPopMatrix(); + immUnbindProgram(); } #undef PX_SIZE_FADE_MAX #undef PX_SIZE_FADE_MIN @@ -652,7 +652,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm UvElement *element; UvNearestHit hit = UV_NEAREST_HIT_INIT; Image *ima = CTX_data_edit_image(C); - uv_find_nearest_vert(scene, ima, em, co, 0.0f, &hit); + uv_find_nearest_vert(scene, ima, obedit, co, 0.0f, &hit); element = BM_uv_element_get(data->elementMap, hit.efa, hit.l); island_index = element->island; @@ -899,7 +899,7 @@ static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, const wmEvent *ev ED_region_tag_redraw(CTX_wm_region(C)); WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); - DAG_id_tag_update(obedit->data, 0); + DEG_id_tag_update(obedit->data, 0); return OPERATOR_RUNNING_MODAL; } |