[Bf-blender-cvs] [600f12002be] master: ClangFormat: adjust '#if 0' to fix gpu_buffers.c indent

Campbell Barton noreply at git.blender.org
Wed Apr 17 08:58:45 CEST 2019


Commit: 600f12002be41e78e44da1c821ce4390d4f3725a
Author: Campbell Barton
Date:   Wed Apr 17 08:56:59 2019 +0200
Branches: master
https://developer.blender.org/rB600f12002be41e78e44da1c821ce4390d4f3725a

ClangFormat: adjust '#if 0' to fix gpu_buffers.c indent

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

M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 0b5b2e469a0..743e43014a0 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -104,10 +104,12 @@ static struct {
  * Return is false it indicates that the memory map failed. */
 static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, uint vert_len)
 {
+  /* Keep so we can test #GPU_USAGE_DYNAMIC buffer use.
+   * Not that format initialization match in both blocks.
+   * Do this to keep braces balanced - otherwise indentation breaks. */
+#if 0
   if (buffers->vert_buf == NULL) {
-    /* Initialize vertex buffer */
-    /* match 'VertexBufferFormat' */
-
+    /* Initialize vertex buffer (match 'VertexBufferFormat'). */
     static GPUVertFormat format = {0};
     if (format.attr_len == 0) {
       g_vbo_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
@@ -115,7 +117,6 @@ static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, uint vert_len)
           &format, "nor", GPU_COMP_I16, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
       g_vbo_id.msk = GPU_vertformat_attr_add(&format, "msk", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
     }
-#if 0
     buffers->vert_buf = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_DYNAMIC);
     GPU_vertbuf_data_alloc(buffers->vert_buf, vert_len);
   }
@@ -123,896 +124,900 @@ static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, uint vert_len)
     GPU_vertbuf_data_resize(buffers->vert_buf, vert_len);
   }
 #else
+  if (buffers->vert_buf == NULL) {
+    /* Initialize vertex buffer (match 'VertexBufferFormat'). */
+    static GPUVertFormat format = {0};
+    if (format.attr_len == 0) {
+      g_vbo_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+      g_vbo_id.nor = GPU_vertformat_attr_add(
+          &format, "nor", GPU_COMP_I16, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
+      g_vbo_id.msk = GPU_vertformat_attr_add(&format, "msk", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+    }
     buffers->vert_buf = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_STATIC);
   }
   GPU_vertbuf_data_alloc(buffers->vert_buf, vert_len);
 #endif
-    return buffers->vert_buf->data != NULL;
-  }
+  return buffers->vert_buf->data != NULL;
+}
 
-  static void gpu_pbvh_batch_init(GPU_PBVH_Buffers * buffers, GPUPrimType prim)
-  {
-    /* force flushing to the GPU */
-    if (buffers->vert_buf->data) {
-      GPU_vertbuf_use(buffers->vert_buf);
-    }
+static void gpu_pbvh_batch_init(GPU_PBVH_Buffers *buffers, GPUPrimType prim)
+{
+  /* force flushing to the GPU */
+  if (buffers->vert_buf->data) {
+    GPU_vertbuf_use(buffers->vert_buf);
+  }
 
-    if (buffers->triangles == NULL) {
-      buffers->triangles = GPU_batch_create(prim,
-                                            buffers->vert_buf,
-                                            /* can be NULL */
-                                            buffers->index_buf);
-    }
+  if (buffers->triangles == NULL) {
+    buffers->triangles = GPU_batch_create(prim,
+                                          buffers->vert_buf,
+                                          /* can be NULL */
+                                          buffers->index_buf);
+  }
 
-    if ((buffers->triangles_fast == NULL) && buffers->index_buf_fast) {
-      buffers->triangles_fast = GPU_batch_create(prim, buffers->vert_buf, buffers->index_buf_fast);
-    }
+  if ((buffers->triangles_fast == NULL) && buffers->index_buf_fast) {
+    buffers->triangles_fast = GPU_batch_create(prim, buffers->vert_buf, buffers->index_buf_fast);
+  }
 
-    if (buffers->lines == NULL) {
-      BLI_assert(buffers->index_lines_buf != NULL);
-      buffers->lines = GPU_batch_create(
-          GPU_PRIM_LINES, buffers->vert_buf, buffers->index_lines_buf);
-    }
+  if (buffers->lines == NULL) {
+    BLI_assert(buffers->index_lines_buf != NULL);
+    buffers->lines = GPU_batch_create(GPU_PRIM_LINES, buffers->vert_buf, buffers->index_lines_buf);
+  }
 
-    if ((buffers->lines_fast == NULL) && buffers->index_lines_buf_fast) {
-      buffers->lines_fast = GPU_batch_create(
-          GPU_PRIM_LINES, buffers->vert_buf, buffers->index_lines_buf_fast);
-    }
+  if ((buffers->lines_fast == NULL) && buffers->index_lines_buf_fast) {
+    buffers->lines_fast = GPU_batch_create(
+        GPU_PRIM_LINES, buffers->vert_buf, buffers->index_lines_buf_fast);
   }
+}
 
-  /** \} */
+/** \} */
 
-  /* -------------------------------------------------------------------- */
-  /** \name Mesh PBVH
+/* -------------------------------------------------------------------- */
+/** \name Mesh PBVH
  * \{ */
 
-  void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers * buffers,
-                                    const MVert *mvert,
-                                    const int *vert_indices,
-                                    int totvert,
-                                    const float *vmask,
-                                    const int(*face_vert_indices)[3],
-                                    const int update_flags)
-  {
-    const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
-    bool empty_mask = true;
+void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
+                                  const MVert *mvert,
+                                  const int *vert_indices,
+                                  int totvert,
+                                  const float *vmask,
+                                  const int (*face_vert_indices)[3],
+                                  const int update_flags)
+{
+  const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
+  bool empty_mask = true;
 
-    {
-      int totelem = (buffers->smooth ? totvert : (buffers->tot_tri * 3));
+  {
+    int totelem = (buffers->smooth ? totvert : (buffers->tot_tri * 3));
 
-      /* Build VBO */
-      if (gpu_pbvh_vert_buf_data_set(buffers, totelem)) {
-        /* Vertex data is shared if smooth-shaded, but separate
+    /* Build VBO */
+    if (gpu_pbvh_vert_buf_data_set(buffers, totelem)) {
+      /* Vertex data is shared if smooth-shaded, but separate
        * copies are made for flat shading because normals
        * shouldn't be shared. */
-        if (buffers->smooth) {
-          for (uint i = 0; i < totvert; ++i) {
-            const MVert *v = &mvert[vert_indices[i]];
-            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, i, v->co);
-            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, i, v->no);
-          }
-
-          if (vmask && show_mask) {
-            for (uint i = 0; i < buffers->face_indices_len; i++) {
-              const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
-              for (uint j = 0; j < 3; j++) {
-                int vidx = face_vert_indices[i][j];
-                int v_index = buffers->mloop[lt->tri[j]].v;
-                float fmask = vmask[v_index];
-                GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.msk, vidx, &fmask);
-                empty_mask = empty_mask && (fmask == 0.0f);
-              }
-            }
-          }
+      if (buffers->smooth) {
+        for (uint i = 0; i < totvert; ++i) {
+          const MVert *v = &mvert[vert_indices[i]];
+          GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, i, v->co);
+          GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, i, v->no);
         }
-        else {
-          /* calculate normal for each polygon only once */
-          uint mpoly_prev = UINT_MAX;
-          short no[3];
-          int vbo_index = 0;
 
+        if (vmask && show_mask) {
           for (uint i = 0; i < buffers->face_indices_len; i++) {
             const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
-            const uint vtri[3] = {
-                buffers->mloop[lt->tri[0]].v,
-                buffers->mloop[lt->tri[1]].v,
-                buffers->mloop[lt->tri[2]].v,
-            };
-
-            if (paint_is_face_hidden(lt, mvert, buffers->mloop))
-              continue;
-
-            /* Face normal and mask */
-            if (lt->poly != mpoly_prev) {
-              const MPoly *mp = &buffers->mpoly[lt->poly];
-              float fno[3];
-              BKE_mesh_calc_poly_normal(mp, &buffers->mloop[mp->loopstart], mvert, fno);
-              normal_float_to_short_v3(no, fno);
-              mpoly_prev = lt->poly;
-            }
-
-            float fmask = 0.0f;
-            if (vmask && show_mask) {
-              fmask = (vmask[vtri[0]] + vmask[vtri[1]] + vmask[vtri[2]]) / 3.0f;
+            for (uint j = 0; j < 3; j++) {
+              int vidx = face_vert_indices[i][j];
+              int v_index = buffers->mloop[lt->tri[j]].v;
+              float fmask = vmask[v_index];
+              GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.msk, vidx, &fmask);
+              empty_mask = empty_mask && (fmask == 0.0f);
             }
+          }
+        }
+      }
+      else {
+        /* calculate normal for each polygon only once */
+        uint mpoly_prev = UINT_MAX;
+        short no[3];
+        int vbo_index = 0;
+
+        for (uint i = 0; i < buffers->face_indices_len; i++) {
+          const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
+          const uint vtri[3] = {
+              buffers->mloop[lt->tri[0]].v,
+              buffers->mloop[lt->tri[1]].v,
+              buffers->mloop[lt->tri[2]].v,
+          };
+
+          if (paint_is_face_hidden(lt, mvert, buffers->mloop))
+            continue;
+
+          /* Face normal and mask */
+          if (lt->poly != mpoly_prev) {
+            const MPoly *mp = &buffers->mpoly[lt->poly];
+            float fno[3];
+            BKE_mesh_calc_poly_normal(mp, &buffers->mloop[mp->loopstart], mvert, fno);
+            normal_float_to_short_v3(no, fno);
+            mpoly_prev = lt->poly;
+          }
 
-            for (uint j = 0; j < 3; j++) {
-              const MVert *v = &mvert[vtri[j]];
+          float fmask = 0.0f;
+          if (vmask && show_mask) {
+            fmask = (vmask[vtri[0]] + vmask[vtri[1]] + vmask[vtri[2]]) / 3.0f;
+          }
 
-              GPU_vert

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list