DRW: Only change VAO if geometry changes
authorClément Foucault <foucault.clem@gmail.com>
Wed, 22 May 2019 11:27:43 +0000 (13:27 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 22 May 2019 11:29:05 +0000 (13:29 +0200)
source/blender/draw/intern/draw_manager.h
source/blender/draw/intern/draw_manager_exec.c

index 69de448..6cf70f5 100644 (file)
@@ -293,6 +293,7 @@ typedef struct DRWManager {
 
   /* Rendering state */
   GPUShader *shader;
+  GPUBatch *batch;
 
   /* Managed by `DRW_state_set`, `DRW_state_reset` */
   DRWState state;
index 0535674..7c53d8f 100644 (file)
@@ -587,18 +587,22 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
   }
 }
 
-static void draw_geometry_execute(DRWShadingGroup *shgroup,
-                                  GPUBatch *geom,
-                                  uint vert_first,
-                                  uint vert_count,
-                                  uint inst_first,
-                                  uint inst_count)
+BLI_INLINE void draw_geometry_execute(DRWShadingGroup *shgroup,
+                                      GPUBatch *geom,
+                                      uint vert_first,
+                                      uint vert_count,
+                                      uint inst_first,
+                                      uint inst_count)
 {
   /* bind vertex array */
-  GPU_batch_program_set_no_use(
-      geom, GPU_shader_get_program(shgroup->shader), GPU_shader_get_interface(shgroup->shader));
+  if (DST.batch != geom) {
+    DST.batch = geom;
 
-  GPU_batch_bind(geom);
+    GPU_batch_program_set_no_use(
+        geom, GPU_shader_get_program(shgroup->shader), GPU_shader_get_interface(shgroup->shader));
+
+    GPU_batch_bind(geom);
+  }
 
   /* XXX hacking gawain. we don't want to call glUseProgram! (huge performance loss) */
   geom->program_in_use = true;
@@ -898,6 +902,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
     }
     GPU_shader_bind(shgroup->shader);
     DST.shader = shgroup->shader;
+    DST.batch = NULL;
   }
 
   if (shgroup->tfeedback_target != NULL) {