Cleanup: DRW: Refactor code for better readability and simplification
authorClément Foucault <foucault.clem@gmail.com>
Sun, 19 May 2019 14:54:01 +0000 (16:54 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 22 May 2019 11:29:04 +0000 (13:29 +0200)
- Remove DST.frontface and DST.backface.
- Separate uniform update into its own function draw_update_uniforms.

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

index d8afe4f..8ded73a 100644 (file)
@@ -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);
   }
index 8927d2e..96dcfb9 100644 (file)
@@ -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;
index 2c29ce3..49927b7 100644 (file)
@@ -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) {