diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 107 |
1 files changed, 73 insertions, 34 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 34eaab68379..969bf8f37b1 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -52,7 +52,6 @@ #include "BKE_colorband.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" #include "BKE_brush.h" #include "BKE_image.h" @@ -61,6 +60,8 @@ #include "BKE_node.h" #include "BKE_paint.h" +#include "DEG_depsgraph.h" + #include "UI_interface.h" #include "UI_view2d.h" @@ -78,9 +79,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" @@ -372,7 +373,7 @@ void ED_image_undo_restore(bContext *C, ListBase *lb) ibuf->userflags |= IB_MIPMAP_INVALID; /* force mipmap recreatiom */ 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); } @@ -589,11 +590,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 { @@ -721,12 +724,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); @@ -748,7 +767,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); @@ -1039,16 +1059,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); @@ -1352,19 +1376,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(); @@ -1404,15 +1430,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); @@ -1423,6 +1451,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); @@ -1449,9 +1479,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 { @@ -1482,8 +1513,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; @@ -1517,16 +1551,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; } @@ -1537,16 +1573,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); } |