[Bf-blender-cvs] [1c00b2ef70e] master: Cleanup: move paint_cursor.c and paint_image_proj.c to C++

Jacques Lucke noreply at git.blender.org
Wed Nov 23 12:57:11 CET 2022


Commit: 1c00b2ef70ed145e4715821c9fa7d3b2ef9df8f7
Author: Jacques Lucke
Date:   Wed Nov 23 12:56:34 2022 +0100
Branches: master
https://developer.blender.org/rB1c00b2ef70ed145e4715821c9fa7d3b2ef9df8f7

Cleanup: move paint_cursor.c and paint_image_proj.c to C++

This makes it easier to use c++ when improving the internal node api.

===================================================================

M	source/blender/editors/sculpt_paint/CMakeLists.txt
R096	source/blender/editors/sculpt_paint/paint_cursor.c	source/blender/editors/sculpt_paint/paint_cursor.cc
R092	source/blender/editors/sculpt_paint/paint_image_proj.c	source/blender/editors/sculpt_paint/paint_image_proj.cc

===================================================================

diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index b29fc0e9e7d..393f9a376af 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -42,7 +42,7 @@ set(SRC
   curves_sculpt_smooth.cc
   curves_sculpt_snake_hook.cc
   paint_canvas.cc
-  paint_cursor.c
+  paint_cursor.cc
   paint_curve.c
   paint_curve_undo.c
   paint_hide.c
@@ -50,7 +50,7 @@ set(SRC
   paint_image_2d.c
   paint_image_2d_curve_mask.cc
   paint_image_ops_paint.cc
-  paint_image_proj.c
+  paint_image_proj.cc
   paint_mask.c
   paint_ops.c
   paint_stroke.c
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.cc
similarity index 96%
rename from source/blender/editors/sculpt_paint/paint_cursor.c
rename to source/blender/editors/sculpt_paint/paint_cursor.cc
index b6e83187c86..85f52c73ca5 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.cc
@@ -64,21 +64,21 @@
  * There is also some ugliness with sculpt-specific code.
  */
 
-typedef struct TexSnapshot {
+struct TexSnapshot {
   GPUTexture *overlay_texture;
   int winx;
   int winy;
   int old_size;
   float old_zoom;
   bool old_col;
-} TexSnapshot;
+};
 
-typedef struct CursorSnapshot {
+struct CursorSnapshot {
   GPUTexture *overlay_texture;
   int size;
   int zoom;
   int curve_preset;
-} CursorSnapshot;
+};
 
 static TexSnapshot primary_snap = {0};
 static TexSnapshot secondary_snap = {0};
@@ -140,7 +140,7 @@ static void load_tex_task_cb_ex(void *__restrict userdata,
                                 const int j,
                                 const TaskParallelTLS *__restrict tls)
 {
-  LoadTexData *data = userdata;
+  LoadTexData *data = static_cast<LoadTexData *>(userdata);
   Brush *br = data->br;
   ViewContext *vc = data->vc;
 
@@ -154,14 +154,14 @@ static void load_tex_task_cb_ex(void *__restrict userdata,
   const float radius = data->radius;
 
   bool convert_to_linear = false;
-  struct ColorSpace *colorspace = NULL;
+  struct ColorSpace *colorspace = nullptr;
 
   const int thread_id = BLI_task_parallel_thread_id(tls);
 
   if (mtex->tex && mtex->tex->type == TEX_IMAGE && mtex->tex->ima) {
     ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf(mtex->tex->ima, &mtex->tex->iuser, pool);
     /* For consistency, sampling always returns color in linear space. */
-    if (tex_ibuf && tex_ibuf->rect_float == NULL) {
+    if (tex_ibuf && tex_ibuf->rect_float == nullptr) {
       convert_to_linear = true;
       colorspace = tex_ibuf->rect_colorspace;
     }
@@ -239,7 +239,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
 
   MTex *mtex = (primary) ? &br->mtex : &br->mask_mtex;
   ePaintOverlayControlFlags overlay_flags = BKE_paint_get_overlay_flags();
-  uchar *buffer = NULL;
+  uchar *buffer = nullptr;
 
   int size;
   bool refresh;
@@ -254,7 +254,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
   init = (target->overlay_texture != 0);
 
   if (refresh) {
-    struct ImagePool *pool = NULL;
+    struct ImagePool *pool = nullptr;
     /* Stencil is rotated later. */
     const float rotation = (mtex->brush_map_mode != MTEX_MAP_MODE_STENCIL) ? -mtex->rot : 0.0f;
     const float radius = BKE_brush_size_get(vc->scene, br) * zoom;
@@ -286,7 +286,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
     if (target->old_size != size || target->old_col != col) {
       if (target->overlay_texture) {
         GPU_texture_free(target->overlay_texture);
-        target->overlay_texture = NULL;
+        target->overlay_texture = nullptr;
       }
       init = false;
 
@@ -294,10 +294,10 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
       target->old_col = col;
     }
     if (col) {
-      buffer = MEM_mallocN(sizeof(uchar) * size * size * 4, "load_tex");
+      buffer = static_cast<uchar *>(MEM_mallocN(sizeof(uchar) * size * size * 4, "load_tex"));
     }
     else {
-      buffer = MEM_mallocN(sizeof(uchar) * size * size, "load_tex");
+      buffer = static_cast<uchar *>(MEM_mallocN(sizeof(uchar) * size * size, "load_tex"));
     }
 
     pool = BKE_image_pool_new();
@@ -307,17 +307,16 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
       ntreeTexBeginExecTree(mtex->tex->nodetree);
     }
 
-    LoadTexData data = {
-        .br = br,
-        .vc = vc,
-        .mtex = mtex,
-        .buffer = buffer,
-        .col = col,
-        .pool = pool,
-        .size = size,
-        .rotation = rotation,
-        .radius = radius,
-    };
+    LoadTexData data{};
+    data.br = br;
+    data.vc = vc;
+    data.mtex = mtex;
+    data.buffer = buffer;
+    data.col = col;
+    data.pool = pool;
+    data.size = size;
+    data.rotation = rotation;
+    data.radius = radius;
 
     TaskParallelSettings settings;
     BLI_parallel_range_settings_defaults(&settings);
@@ -334,7 +333,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
     if (!target->overlay_texture) {
       eGPUTextureFormat format = col ? GPU_RGBA8 : GPU_R8;
       target->overlay_texture = GPU_texture_create_2d(
-          "paint_cursor_overlay", size, size, 1, format, NULL);
+          "paint_cursor_overlay", size, size, 1, format, nullptr);
       GPU_texture_update(target->overlay_texture, GPU_DATA_UBYTE, buffer);
 
       if (!col) {
@@ -363,7 +362,7 @@ static void load_tex_cursor_task_cb(void *__restrict userdata,
                                     const int j,
                                     const TaskParallelTLS *__restrict UNUSED(tls))
 {
-  LoadTexData *data = userdata;
+  LoadTexData *data = static_cast<LoadTexData *>(userdata);
   Brush *br = data->br;
 
   uchar *buffer = data->buffer;
@@ -396,7 +395,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
   bool init;
 
   ePaintOverlayControlFlags overlay_flags = BKE_paint_get_overlay_flags();
-  uchar *buffer = NULL;
+  uchar *buffer = nullptr;
 
   int size;
   const bool refresh = !cursor_snap.overlay_texture ||
@@ -430,22 +429,21 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
     if (cursor_snap.size != size) {
       if (cursor_snap.overlay_texture) {
         GPU_texture_free(cursor_snap.overlay_texture);
-        cursor_snap.overlay_texture = NULL;
+        cursor_snap.overlay_texture = nullptr;
       }
 
       init = false;
 
       cursor_snap.size = size;
     }
-    buffer = MEM_mallocN(sizeof(uchar) * size * size, "load_tex");
+    buffer = static_cast<uchar *>(MEM_mallocN(sizeof(uchar) * size * size, "load_tex"));
 
     BKE_curvemapping_init(br->curve);
 
-    LoadTexData data = {
-        .br = br,
-        .buffer = buffer,
-        .size = size,
-    };
+    LoadTexData data{};
+    data.br = br;
+    data.buffer = buffer;
+    data.size = size;
 
     TaskParallelSettings settings;
     BLI_parallel_range_settings_defaults(&settings);
@@ -453,7 +451,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
 
     if (!cursor_snap.overlay_texture) {
       cursor_snap.overlay_texture = GPU_texture_create_2d(
-          "cursor_snap_overaly", size, size, 1, GPU_R8, NULL);
+          "cursor_snap_overaly", size, size, 1, GPU_R8, nullptr);
       GPU_texture_update(cursor_snap.overlay_texture, GPU_DATA_UBYTE, buffer);
 
       GPU_texture_swizzle_set(cursor_snap.overlay_texture, "rrrr");
@@ -1096,7 +1094,7 @@ static void cursor_draw_point_with_symmetry(const uint gpuattr,
     if (i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || !ELEM(i, 3, 5)))) {
 
       /* Axis Symmetry. */
-      flip_v3_v3(location, true_location, (char)i);
+      flip_v3_v3(location, true_location, ePaintSymmetryFlags(i));
       cursor_draw_point_screen_space(gpuattr, region, location, ob->object_to_world, 3);
 
       /* Tiling. */
@@ -1106,7 +1104,7 @@ static void cursor_draw_point_with_symmetry(const uint gpuattr,
       for (char raxis = 0; raxis < 3; raxis++) {
         for (int r = 1; r < sd->radial_symm[raxis]; r++) {
           float angle = 2 * M_PI * r / sd->radial_symm[(int)raxis];
-          flip_v3_v3(location, true_location, (char)i);
+          flip_v3_v3(location, true_location, ePaintSymmetryFlags(i));
           unit_m4(symm_rot_mat);
           rotate_m4(symm_rot_mat, raxis + 'X', angle);
           mul_m4_v3(symm_rot_mat, location);
@@ -1263,11 +1261,11 @@ static bool paint_cursor_context_init(bContext *C,
   pcontext->scene = CTX_data_scene(C);
   pcontext->ups = &pcontext->scene->toolsettings->unified_paint_settings;
   pcontext->paint = BKE_paint_get_active_from_context(C);
-  if (pcontext->paint == NULL) {
+  if (pcontext->paint == nullptr) {
     return false;
   }
   pcontext->brush = BKE_paint_brush(pcontext->paint);
-  if (pcontext->brush == NULL) {
+  if (pcontext->brush == nullptr) {
     return false;
   }
   pcontext->mode = BKE_paintmode_get_active_from_context(C);
@@ -1306,7 +1304,7 @@ static bool paint_cursor_context_init(bContext *C,
   pcontext->outline_alpha = pcontext->brush->add_col[3];
 
   Object *active_object = pcontext->vc.obact;
-  pcontext->ss = active_object ? active_object->sculpt : NULL;
+  pcontext->ss = active_object ? active_object->sculpt : nullptr;
 
   if (pcontext->ss && pcontext->ss->draw_faded_cursor) {
     pcontext->outline_alpha = 0.3f;
@@ -1351,7 +1349,7 @@ static void paint_cursor_update_pixel_radius(PaintCursorContext *pcontext)
 
 static void paint_cursor_sculpt_session_update_and_init(PaintCursorContext *pcontext)
 {
-  BLI_assert(pcontext->ss != NULL);
+  BLI_assert(pcontext->ss != nullptr);
   BLI_assert(pcontext->mode == PAINT_MODE_SCULPT);
 
   bContext *C = pcontext->C;
@@ -1363,8 +1361,8 @@ static void paint_cursor_sculpt_session_update_and_init(PaintCursorContext *pcon
   SculptCursorGeometryInfo gi;
 
   const float mval_fl[2] = {
-      pcontext->x - pcontext->region->winrct.xmin,
-      pcontext->y - pcontext->region->winrct.ymin,
+      float(pcontext->x - pcontext->region->winrct.xmin),
+    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list