[Bf-blender-cvs] [d6b6050e5b8] master: Cleanup: use function style casts in C++

Campbell Barton noreply at git.blender.org
Mon Feb 6 02:51:10 CET 2023


Commit: d6b6050e5b8a9e2534edd9ae8963a85a26164bc7
Author: Campbell Barton
Date:   Mon Feb 6 12:35:51 2023 +1100
Branches: master
https://developer.blender.org/rBd6b6050e5b8a9e2534edd9ae8963a85a26164bc7

Cleanup: use function style casts in C++

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

M	source/blender/blenkernel/intern/pbvh.cc
M	source/blender/blenkernel/intern/pbvh_bmesh.cc
M	source/blender/blenkernel/intern/pbvh_pixels.cc
M	source/blender/draw/engines/workbench/workbench_mesh_passes.cc
M	source/blender/draw/engines/workbench/workbench_shader_cache.cc

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

diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc
index 1f3583a7f7e..b45a136f28c 100644
--- a/source/blender/blenkernel/intern/pbvh.cc
+++ b/source/blender/blenkernel/intern/pbvh.cc
@@ -393,8 +393,8 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
   /* grid hidden layer is present, so have to check each grid for
    * visibility */
 
-  int depth1 = int(log2((double)gridsize - 1.0) + DBL_EPSILON);
-  int depth2 = int(log2((double)display_gridsize - 1.0) + DBL_EPSILON);
+  int depth1 = int(log2(double(gridsize) - 1.0) + DBL_EPSILON);
+  int depth2 = int(log2(double(display_gridsize) - 1.0) + DBL_EPSILON);
 
   int skip = depth2 < depth1 ? 1 << (depth1 - depth2 - 1) : 1;
 
@@ -3667,7 +3667,7 @@ static void pbvh_face_iter_step(PBVHFaceIter *fd, bool do_step)
       }
 
       BMFace *f = (BMFace *)BLI_gsetIterator_getKey(&fd->bm_faces_iter_);
-      fd->face.i = (intptr_t)f;
+      fd->face.i = intptr_t(f);
       fd->index = f->head.index;
 
       if (fd->cd_face_set_ != -1) {
@@ -3683,7 +3683,7 @@ static void pbvh_face_iter_step(PBVHFaceIter *fd, bool do_step)
 
       BMLoop *l = f->l_first;
       do {
-        fd->verts[vertex_i++].i = (intptr_t)l->v;
+        fd->verts[vertex_i++].i = intptr_t(l->v);
       } while ((l = l->next) != f->l_first);
 
       break;
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.cc b/source/blender/blenkernel/intern/pbvh_bmesh.cc
index e7a9266c423..f8d4bdc88da 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.cc
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.cc
@@ -1528,7 +1528,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
             if (j == 0 || len_squared_v3v3(location, cos[j]) <
                               len_squared_v3v3(location, nearest_vertex_co)) {
               copy_v3_v3(nearest_vertex_co, cos[j]);
-              r_active_vertex->i = (intptr_t)node->bm_orvert[node->bm_ortri[i][j]];
+              r_active_vertex->i = intptr_t(node->bm_orvert[node->bm_ortri[i][j]]);
             }
           }
         }
@@ -1560,7 +1560,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
               if (j == 0 || len_squared_v3v3(location, v_tri[j]->co) <
                                 len_squared_v3v3(location, nearest_vertex_co)) {
                 copy_v3_v3(nearest_vertex_co, v_tri[j]->co);
-                r_active_vertex->i = (intptr_t)v_tri[j];
+                r_active_vertex->i = intptr_t(v_tri[j]);
               }
             }
           }
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index 4a792fedf23..f18345b9eab 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -116,7 +116,7 @@ static void split_pixel_node(
   const int axis = BB_widest_axis(&cb);
   const float mid = (cb.bmax[axis] + cb.bmin[axis]) * 0.5f;
 
-  node->flag = (PBVHNodeFlags)((int)node->flag & (int)~PBVH_TexLeaf);
+  node->flag = (PBVHNodeFlags)(int(node->flag) & int(~PBVH_TexLeaf));
 
   SplitNodePair *split1 = MEM_new<SplitNodePair>("split_pixel_node split1", split);
   SplitNodePair *split2 = MEM_new<SplitNodePair>("split_pixel_node split1", split);
@@ -188,7 +188,7 @@ static void split_pixel_node(
 
       float2 delta = uv_prim.delta_barycentric_coord_u;
       float2 uv1 = row.start_barycentric_coord;
-      float2 uv2 = row.start_barycentric_coord + delta * (float)row.num_pixels;
+      float2 uv2 = row.start_barycentric_coord + delta * float(row.num_pixels);
 
       float co1[3];
       float co2[3];
@@ -210,7 +210,7 @@ static void split_pixel_node(
           t = (mid - co1[axis]) / (co2[axis] - co1[axis]);
         }
 
-        int num_pixels = (int)floorf((float)row.num_pixels * t);
+        int num_pixels = int(floorf(float(row.num_pixels) * t));
 
         if (num_pixels) {
           row1.num_pixels = num_pixels;
@@ -223,7 +223,7 @@ static void split_pixel_node(
           row2.num_pixels = row.num_pixels - num_pixels;
 
           row2.start_barycentric_coord = row.start_barycentric_coord +
-                                         uv_prim.delta_barycentric_coord_u * (float)num_pixels;
+                                         uv_prim.delta_barycentric_coord_u * float(num_pixels);
           row2.start_image_coordinate = row.start_image_coordinate;
           row2.start_image_coordinate[0] += num_pixels;
 
@@ -731,7 +731,7 @@ static bool update_pixels(PBVH *pbvh, Mesh *mesh, Image *image, ImageUser *image
     PBVHNode &node = pbvh->nodes[i];
 
     if (node.flag & PBVH_Leaf) {
-      node.flag = (PBVHNodeFlags)((int)node.flag | (int)PBVH_TexLeaf);
+      node.flag = (PBVHNodeFlags)(int(node.flag) | int(PBVH_TexLeaf));
     }
   }
 
diff --git a/source/blender/draw/engines/workbench/workbench_mesh_passes.cc b/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
index ae522541e89..9e6d746cfa0 100644
--- a/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
+++ b/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
@@ -76,8 +76,7 @@ void MeshPass::draw(ObjectRef &ref,
     }
     if (texture) {
       auto add_cb = [&] {
-        PassMain::Sub *sub_pass =
-            passes_[static_cast<int>(geometry_type)][static_cast<int>(eShaderType::TEXTURE)];
+        PassMain::Sub *sub_pass = passes_[int(geometry_type)][int(eShaderType::TEXTURE)];
         sub_pass = &sub_pass->sub(image->id.name);
         if (tilemap) {
           sub_pass->bind_texture(WB_TILE_ARRAY_SLOT, texture, sampler_state);
@@ -100,8 +99,7 @@ void MeshPass::draw(ObjectRef &ref,
       return;
     }
   }
-  passes_[static_cast<int>(geometry_type)][static_cast<int>(eShaderType::MATERIAL)]->draw(batch,
-                                                                                          handle);
+  passes_[int(geometry_type)][int(eShaderType::MATERIAL)]->draw(batch, handle);
 }
 
 /** \} */
diff --git a/source/blender/draw/engines/workbench/workbench_shader_cache.cc b/source/blender/draw/engines/workbench/workbench_shader_cache.cc
index d544535d146..40760c28539 100644
--- a/source/blender/draw/engines/workbench/workbench_shader_cache.cc
+++ b/source/blender/draw/engines/workbench/workbench_shader_cache.cc
@@ -34,9 +34,8 @@ GPUShader *ShaderCache::prepass_shader_get(ePipelineType pipeline_type,
                                            eLightingType lighting_type,
                                            bool clip)
 {
-  GPUShader *&shader_ptr = prepass_shader_cache_[static_cast<int>(pipeline_type)][static_cast<int>(
-      geometry_type)][static_cast<int>(shader_type)][static_cast<int>(lighting_type)]
-                                                [clip ? 1 : 0];
+  GPUShader *&shader_ptr = prepass_shader_cache_[int(pipeline_type)][int(geometry_type)][int(
+      shader_type)][int(lighting_type)][clip ? 1 : 0];
 
   if (shader_ptr != nullptr) {
     return shader_ptr;
@@ -93,8 +92,8 @@ GPUShader *ShaderCache::resolve_shader_get(ePipelineType pipeline_type,
                                            bool cavity,
                                            bool curvature)
 {
-  GPUShader *&shader_ptr = resolve_shader_cache_[static_cast<int>(pipeline_type)][static_cast<int>(
-      lighting_type)][cavity][curvature];
+  GPUShader *&shader_ptr =
+      resolve_shader_cache_[int(pipeline_type)][int(lighting_type)][cavity][curvature];
 
   if (shader_ptr != nullptr) {
     return shader_ptr;



More information about the Bf-blender-cvs mailing list