[Bf-blender-cvs] [277c7d96ee6] temp-3d-texture-brush-prototype: Move image paint brush to its own compile unit.
Jeroen Bakker
noreply at git.blender.org
Tue Feb 22 13:33:42 CET 2022
Commit: 277c7d96ee6be370efb1d85ed593eaab4ced615e
Author: Jeroen Bakker
Date: Tue Feb 22 11:46:38 2022 +0100
Branches: temp-3d-texture-brush-prototype
https://developer.blender.org/rB277c7d96ee6be370efb1d85ed593eaab4ced615e
Move image paint brush to its own compile unit.
===================================================================
M source/blender/editors/sculpt_paint/CMakeLists.txt
M source/blender/editors/sculpt_paint/paint_image.cc
A source/blender/editors/sculpt_paint/paint_image_ops_paint.cc
M source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index c1febe5c86b..de7888aa1e8 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -30,6 +30,7 @@ set(SRC
paint_curve_undo.c
paint_hide.c
paint_image.cc
+ paint_image_ops_paint.cc
paint_image_2d.c
paint_image_2d_curve_mask.cc
paint_image_proj.c
diff --git a/source/blender/editors/sculpt_paint/paint_image.cc b/source/blender/editors/sculpt_paint/paint_image.cc
index eda686d808d..9413f872c3a 100644
--- a/source/blender/editors/sculpt_paint/paint_image.cc
+++ b/source/blender/editors/sculpt_paint/paint_image.cc
@@ -286,7 +286,7 @@ static bool image_paint_poll_ex(bContext *C, bool check_tool)
return false;
}
-static bool image_paint_poll(bContext *C)
+bool image_paint_poll(bContext *C)
{
return image_paint_poll_ex(C, true);
}
@@ -312,24 +312,6 @@ static bool image_paint_2d_clone_poll(bContext *C)
}
/************************ paint operator ************************/
-enum class eTexPaintMode {
- _2D,
- _3D_PROJECT,
-};
-
-struct PaintOperation {
- eTexPaintMode mode;
-
- void *stroke_handle;
-
- float prevmouse[2];
- float startmouse[2];
- double starttime;
-
- wmPaintCursor *cursor;
- ViewContext vc;
-};
-
bool paint_use_opacity_masking(Brush *brush)
{
return ((brush->flag & BRUSH_AIRBRUSH) || (brush->flag & BRUSH_DRAG_DOT) ||
@@ -419,366 +401,6 @@ void paint_brush_exit_tex(Brush *brush)
}
}
-static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customdata)
-{
- PaintOperation *pop = (PaintOperation *)customdata;
-
- if (pop) {
- GPU_line_smooth(true);
- GPU_blend(GPU_BLEND_ALPHA);
-
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
-
- ARegion *region = pop->vc.region;
-
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- GPU_line_width(4.0);
- immUniformColor4ub(0, 0, 0, 255);
-
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2i(pos, x, y);
- immVertex2i(
- pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin);
- immEnd();
-
- GPU_line_width(2.0);
- immUniformColor4ub(255, 255, 255, 255);
-
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2i(pos, x, y);
- immVertex2i(
- pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin);
- immEnd();
-
- immUnbindProgram();
-
- GPU_blend(GPU_BLEND_NONE);
- GPU_line_smooth(false);
- }
-}
-
-static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const float mouse[2])
-{
- Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- Scene *scene = CTX_data_scene(C);
- ToolSettings *settings = scene->toolsettings;
- PaintOperation *pop = MEM_cnew<PaintOperation>("PaintOperation"); /* caller frees */
- Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
- int mode = RNA_enum_get(op->ptr, "mode");
- ED_view3d_viewcontext_init(C, &pop->vc, depsgraph);
-
- copy_v2_v2(pop->prevmouse, mouse);
- copy_v2_v2(pop->startmouse, mouse);
-
- /* initialize from context */
- if (CTX_wm_region_view3d(C)) {
- ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
- bool uvs, mat, tex, stencil;
- if (!ED_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) {
- ED_paint_data_warning(op->reports, uvs, mat, tex, stencil);
- MEM_delete(pop);
- WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, nullptr);
- return nullptr;
- }
- pop->mode = eTexPaintMode::_3D_PROJECT;
- pop->stroke_handle = paint_proj_new_stroke(C, ob, mouse, mode);
- }
- else {
- pop->mode = eTexPaintMode::_2D;
- pop->stroke_handle = paint_2d_new_stroke(C, op, mode);
- }
-
- if (!pop->stroke_handle) {
- MEM_delete(pop);
- return nullptr;
- }
-
- if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
- pop->cursor = WM_paint_cursor_activate(
- SPACE_TYPE_ANY, RGN_TYPE_ANY, image_paint_poll, gradient_draw_line, pop);
- }
-
- settings->imapaint.flag |= IMAGEPAINT_DRAWING;
- ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_2D);
-
- return pop;
-}
-
-static void paint_stroke_update_step(bContext *C,
- wmOperator *UNUSED(op),
- struct PaintStroke *stroke,
- PointerRNA *itemptr)
-{
- PaintOperation *pop = static_cast<PaintOperation *>(paint_stroke_mode_data(stroke));
- Scene *scene = CTX_data_scene(C);
- ToolSettings *toolsettings = CTX_data_tool_settings(C);
- UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
- Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
-
- float alphafac = (brush->flag & BRUSH_ACCUMULATE) ? ups->overlap_factor : 1.0f;
-
- /* initial brush values. Maybe it should be considered moving these to stroke system */
- float startalpha = BKE_brush_alpha_get(scene, brush);
-
- float mouse[2];
- float pressure;
- float size;
- float distance = paint_stroke_distance_get(stroke);
- int eraser;
-
- RNA_float_get_array(itemptr, "mouse", mouse);
- pressure = RNA_float_get(itemptr, "pressure");
- eraser = RNA_boolean_get(itemptr, "pen_flip");
- size = RNA_float_get(itemptr, "size");
-
- /* stroking with fill tool only acts on stroke end */
- if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
- copy_v2_v2(pop->prevmouse, mouse);
- return;
- }
-
- if (BKE_brush_use_alpha_pressure(brush)) {
- BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac));
- }
- else {
- BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac));
- }
-
- if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) {
- UndoStack *ustack = CTX_wm_manager(C)->undo_stack;
- ED_image_undo_restore(ustack->step_init);
- }
-
- switch (pop->mode) {
- case eTexPaintMode::_2D:
- paint_2d_stroke(pop->stroke_handle, pop->prevmouse, mouse, eraser, pressure, distance, size);
- break;
-
- case eTexPaintMode::_3D_PROJECT:
- paint_proj_stroke(
- C, pop->stroke_handle, pop->prevmouse, mouse, eraser, pressure, distance, size);
- break;
- }
-
- copy_v2_v2(pop->prevmouse, mouse);
-
- /* restore brush values */
- BKE_brush_alpha_set(scene, brush, startalpha);
-}
-
-static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
-{
- PaintOperation *pop = static_cast<PaintOperation *>(paint_stroke_mode_data(stroke));
-
- switch (pop->mode) {
- case eTexPaintMode::_2D:
- paint_2d_redraw(C, pop->stroke_handle, final);
- break;
-
- case eTexPaintMode::_3D_PROJECT:
- paint_proj_redraw(C, pop->stroke_handle, final);
- break;
- }
-}
-
-static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
-{
- Scene *scene = CTX_data_scene(C);
- ToolSettings *toolsettings = scene->toolsettings;
- PaintOperation *pop = static_cast<PaintOperation *>(paint_stroke_mode_data(stroke));
- Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
-
- toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
-
- if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
- if (brush->flag & BRUSH_USE_GRADIENT) {
- switch (pop->mode) {
- case eTexPaintMode::_2D:
- paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->stroke_handle);
- break;
-
- case eTexPaintMode::_3D_PROJECT:
- paint_proj_stroke(C,
- pop->stroke_handle,
- pop->startmouse,
- pop->prevmouse,
- paint_stroke_flipped(stroke),
- 1.0,
- 0.0,
- BKE_brush_size_get(scene, brush));
- /* two redraws, one for GPU update, one for notification */
- paint_proj_redraw(C, pop->stroke_handle, false);
- paint_proj_redraw(C, pop->stroke_handle, true);
- break;
- }
- }
- else {
- switch (pop->mode) {
- case eTexPaintMode::_2D: {
- float color[3];
- if (paint_stroke_inverted(stroke)) {
- srgb_to_linearrgb_v3_v3(color, BKE_brush_secondary_color_get(scene, brush));
- }
- else {
- srgb_to_linearrgb_v3_v3(color, BKE_brush_color_get(scene, brush));
- }
- paint_2d_bucket_fill(
- C, color, brush, pop->startmouse, pop->prevmouse, pop->stroke_handle);
- break;
- }
-
- case eTexPaintMode::_3D_PROJECT:
- paint_proj_stroke(C,
- pop->stroke_handle,
- pop->startmouse,
- pop->prevmouse,
- paint_stroke_flipped(stroke),
- 1.0,
- 0.0,
- BKE_brush_size_get(scene, brush));
- /* two redraws, one for GPU update, one for notification */
- paint_proj_redraw(C, pop->stroke_handle, false);
- paint_proj_redraw(C, pop->stroke_handle, true);
- break;
- }
- }
- }
-
- switch (pop->mode) {
- case eTexPaintMode::_2D:
- paint_2d_stroke_done(pop->stroke_handle);
- break;
-
- case eTexPaintMode::_3D_PROJECT:
- paint_proj_stroke_done(pop->stroke_handle);
- break;
- }
-
- if (pop->cursor) {
- WM_paint_cursor_end(pop->cursor);
- }
-
- ED_image_undo_push_end();
-
- /* duplicate warning, see texpaint_init */
-#if 0
- if (pop->s.warnmultifile) {
- BKE_reportf(op->reports,
- RPT_WARNING,
- "Image requires 4 color channels to paint: %s",
- pop->s.warnmultifile);
- }
- if (pop->s.warnpackedfile) {
- BKE_reportf(op->reports,
- RPT_WARNING,
- "Packed MultiLayer files cannot be painted: %s",
- pop->s.warnpackedfile);
- }
-#endif
- MEM_delete(pop);
-}
-
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list