[Bf-blender-cvs] [2b1da51b2fc] master: Cleanup: DRW: Refactor code for better readability and simplification

Clément Foucault noreply at git.blender.org
Wed May 22 13:30:13 CEST 2019


Commit: 2b1da51b2fc2482411c10ce5c387d3b1c6ee87b0
Author: Clément Foucault
Date:   Sun May 19 16:54:01 2019 +0200
Branches: master
https://developer.blender.org/rB2b1da51b2fc2482411c10ce5c387d3b1c6ee87b0

Cleanup: DRW: Refactor code for better readability and simplification

- Remove DST.frontface and DST.backface.
- Separate uniform update into its own function draw_update_uniforms.

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

M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager.h
M	source/blender/draw/intern/draw_manager_exec.c

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

diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index d8afe4f248c..8ded73aa678 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -663,11 +663,6 @@ static void drw_viewport_var_init(void)
     copy_v4_fl4(DST.view_data.viewcamtexcofac, 1.0f, 1.0f, 0.0f, 0.0f);
   }
 
-  /* Reset facing */
-  DST.frontface = GL_CCW;
-  DST.backface = GL_CW;
-  glFrontFace(DST.frontface);
-
   if (DST.draw_ctx.object_edit) {
     ED_view3d_init_mats_rv3d(DST.draw_ctx.object_edit, rv3d);
   }
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index 8927d2e5927..96dcfb9d07d 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -281,8 +281,6 @@ typedef struct DRWManager {
   float screenvecs[2][3];
   float pixsize;
 
-  GLenum backface, frontface;
-
   struct {
     uint is_select : 1;
     uint is_depth : 1;
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 2c29ce343dd..49927b74e72 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -1023,6 +1023,67 @@ static void release_ubo_slots(bool with_persist)
   }
 }
 
+static void draw_update_uniforms(DRWShadingGroup *shgroup)
+{
+  for (DRWUniform *uni = shgroup->uniforms; uni; uni = uni->next) {
+    GPUTexture *tex;
+    GPUUniformBuffer *ubo;
+    if (uni->location == -2) {
+      uni->location = GPU_shader_get_uniform_ensure(shgroup->shader,
+                                                    DST.uniform_names.buffer + uni->name_ofs);
+      if (uni->location == -1) {
+        continue;
+      }
+    }
+    const void *data = uni->pvalue;
+    if (ELEM(uni->type, DRW_UNIFORM_INT_COPY, DRW_UNIFORM_FLOAT_COPY)) {
+      data = uni->fvalue;
+    }
+    switch (uni->type) {
+      case DRW_UNIFORM_INT_COPY:
+      case DRW_UNIFORM_INT:
+        GPU_shader_uniform_vector_int(
+            shgroup->shader, uni->location, uni->length, uni->arraysize, data);
+        break;
+      case DRW_UNIFORM_FLOAT_COPY:
+      case DRW_UNIFORM_FLOAT:
+        GPU_shader_uniform_vector(
+            shgroup->shader, uni->location, uni->length, uni->arraysize, data);
+        break;
+      case DRW_UNIFORM_TEXTURE:
+        tex = (GPUTexture *)uni->pvalue;
+        BLI_assert(tex);
+        bind_texture(tex, BIND_TEMP);
+        GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
+        break;
+      case DRW_UNIFORM_TEXTURE_PERSIST:
+        tex = (GPUTexture *)uni->pvalue;
+        BLI_assert(tex);
+        bind_texture(tex, BIND_PERSIST);
+        GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
+        break;
+      case DRW_UNIFORM_TEXTURE_REF:
+        tex = *((GPUTexture **)uni->pvalue);
+        BLI_assert(tex);
+        bind_texture(tex, BIND_TEMP);
+        GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
+        break;
+      case DRW_UNIFORM_BLOCK:
+        ubo = (GPUUniformBuffer *)uni->pvalue;
+        bind_ubo(ubo, BIND_TEMP);
+        GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
+        break;
+      case DRW_UNIFORM_BLOCK_PERSIST:
+        ubo = (GPUUniformBuffer *)uni->pvalue;
+        bind_ubo(ubo, BIND_PERSIST);
+        GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
+        break;
+    }
+  }
+
+  BLI_assert(ubo_bindings_validate(shgroup));
+}
+
 BLI_INLINE bool draw_select_do_call(DRWShadingGroup *shgroup, DRWCall *call)
 {
 #ifdef USE_GPU_SELECT
@@ -1070,8 +1131,6 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
 {
   BLI_assert(shgroup->shader);
 
-  GPUTexture *tex;
-  GPUUniformBuffer *ubo;
   const bool shader_changed = (DST.shader != shgroup->shader);
   bool use_tfeedback = false;
 
@@ -1094,62 +1153,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
   drw_state_set((pass_state & shgroup->state_extra_disable) | shgroup->state_extra);
   drw_stencil_set(shgroup->stencil_mask);
 
-  /* Binding Uniform */
-  for (DRWUniform *uni = shgroup->uniforms; uni; uni = uni->next) {
-    if (uni->location == -2) {
-      uni->location = GPU_shader_get_uniform_ensure(shgroup->shader,
-                                                    DST.uniform_names.buffer + uni->name_ofs);
-      if (uni->location == -1) {
-        continue;
-      }
-    }
-    const void *data = uni->pvalue;
-    if (ELEM(uni->type, DRW_UNIFORM_INT_COPY, DRW_UNIFORM_FLOAT_COPY)) {
-      data = uni->fvalue;
-    }
-    switch (uni->type) {
-      case DRW_UNIFORM_INT_COPY:
-      case DRW_UNIFORM_INT:
-        GPU_shader_uniform_vector_int(
-            shgroup->shader, uni->location, uni->length, uni->arraysize, data);
-        break;
-      case DRW_UNIFORM_FLOAT_COPY:
-      case DRW_UNIFORM_FLOAT:
-        GPU_shader_uniform_vector(
-            shgroup->shader, uni->location, uni->length, uni->arraysize, data);
-        break;
-      case DRW_UNIFORM_TEXTURE:
-        tex = (GPUTexture *)uni->pvalue;
-        BLI_assert(tex);
-        bind_texture(tex, BIND_TEMP);
-        GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
-        break;
-      case DRW_UNIFORM_TEXTURE_PERSIST:
-        tex = (GPUTexture *)uni->pvalue;
-        BLI_assert(tex);
-        bind_texture(tex, BIND_PERSIST);
-        GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
-        break;
-      case DRW_UNIFORM_TEXTURE_REF:
-        tex = *((GPUTexture **)uni->pvalue);
-        BLI_assert(tex);
-        bind_texture(tex, BIND_TEMP);
-        GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
-        break;
-      case DRW_UNIFORM_BLOCK:
-        ubo = (GPUUniformBuffer *)uni->pvalue;
-        bind_ubo(ubo, BIND_TEMP);
-        GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
-        break;
-      case DRW_UNIFORM_BLOCK_PERSIST:
-        ubo = (GPUUniformBuffer *)uni->pvalue;
-        bind_ubo(ubo, BIND_PERSIST);
-        GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
-        break;
-    }
-  }
-
-  BLI_assert(ubo_bindings_validate(shgroup));
+  draw_update_uniforms(shgroup);
 
   /* Rendering Calls */
   {
@@ -1159,10 +1163,8 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
 
       /* OPTI/IDEA(clem): Do this preparation in another thread. */
       draw_visibility_eval(call->state);
-      draw_matrices_model_prepare(call->state);
 
-      if ((call->state->flag & DRW_CALL_CULLED) != 0 &&
-          (call->state->flag & DRW_CALL_BYPASS_CULLING) == 0) {
+      if ((call->state->flag & DRW_CALL_CULLED) != 0) {
         continue;
       }
 
@@ -1175,7 +1177,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
       /* Negative scale objects */
       bool neg_scale = call->state->flag & DRW_CALL_NEGSCALE;
       if (neg_scale != prev_neg_scale) {
-        glFrontFace((neg_scale) ? DST.backface : DST.frontface);
+        glFrontFace((neg_scale) ? GL_CW : GL_CCW);
         prev_neg_scale = neg_scale;
       }
 
@@ -1194,7 +1196,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
       }
     }
     /* Reset state */
-    glFrontFace(DST.frontface);
+    glFrontFace(GL_CCW);
   }
 
   if (use_tfeedback) {



More information about the Bf-blender-cvs mailing list