GPU: avoid multiple bind calls in GPU_draw_pbvh_buffers
authorCampbell Barton <ideasman42@gmail.com>
Thu, 9 Jun 2016 20:08:39 +0000 (06:08 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 9 Jun 2016 20:09:11 +0000 (06:09 +1000)
Also add utility functions: GPU_basic_shader_bind_enable/disable
so we don't have to get the previous state every time and manipulate it

source/blender/editors/interface/interface_draw.c
source/blender/gpu/GPU_basic_shader.h
source/blender/gpu/intern/gpu_basic_shader.c
source/blender/gpu/intern/gpu_buffers.c

index d78b41820b4df19816af4fe9a9a4a4d3c7a06143..3afea54bc0a73b85f6fb8112fd95a1589cd81f72 100644 (file)
@@ -1205,8 +1205,7 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
                
                qobj = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL);
-               int bound_options = GPU_basic_shader_bound_options();
-               GPU_basic_shader_bind(bound_options);
+               GPU_basic_shader_bind(GPU_basic_shader_bound_options());
                gluSphere(qobj, 100.0, 32, 24);
                gluDeleteQuadric(qobj);
                
index 6c78aec2ec78da4883035793084a2ebbaa409516..d9bf3d1ced337313c1c80f509da7e5e9987e57bf 100644 (file)
@@ -76,6 +76,9 @@ void GPU_basic_shaders_init(void);
 void GPU_basic_shaders_exit(void);
 
 void GPU_basic_shader_bind(int options);
+void GPU_basic_shader_bind_enable(int options);
+void GPU_basic_shader_bind_disable(int options);
+
 int GPU_basic_shader_bound_options(void);
 
 /* Only use for small blocks of code that don't support glsl shader. */
index c5a2d07bdc8c8b7d57f2ff7cc924117aaf36c32a..1e60944c23d31434270c04c04d61f61789ab441f 100644 (file)
@@ -520,6 +520,16 @@ void GPU_basic_shader_bind(int options)
        GPU_MATERIAL_STATE.bound_options = options;
 }
 
+void GPU_basic_shader_bind_enable(int options)
+{
+       GPU_basic_shader_bind(GPU_MATERIAL_STATE.bound_options | options);
+}
+
+void GPU_basic_shader_bind_disable(int options)
+{
+       GPU_basic_shader_bind(GPU_MATERIAL_STATE.bound_options & ~options);
+}
+
 int GPU_basic_shader_bound_options(void)
 {
        /* ideally this should disappear, anything that uses this is making fragile
index 35bfc687052bb9a6095d4fc8f5b4795a78ab7461..36d297fb9fe06c90bb5e0f6f332b7f7078c31ad1 100644 (file)
@@ -1843,15 +1843,15 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
        if (buffers->vert_buf) {
                char *base = NULL;
                char *index_base = NULL;
-               int bound_options = 0;
+               /* weak inspection of bound options, should not be necessary ideally */
+               const int bound_options_old = GPU_basic_shader_bound_options();
+               int bound_options_new = 0;
                glEnableClientState(GL_VERTEX_ARRAY);
                if (!wireframe) {
                        glEnableClientState(GL_NORMAL_ARRAY);
                        glEnableClientState(GL_COLOR_ARRAY);
 
-                       /* weak inspection of bound options, should not be necessary ideally */
-                       bound_options = GPU_basic_shader_bound_options();
-                       GPU_basic_shader_bind(bound_options | GPU_SHADER_USE_COLOR);
+                       bound_options_new |= GPU_SHADER_USE_COLOR;
                }
 
                GPU_buffer_bind(buffers->vert_buf, GPU_BINDING_ARRAY);
@@ -1867,9 +1867,13 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
                        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
                }
                else {
-                       bound_options = GPU_basic_shader_bound_options();
-                       GPU_basic_shader_bind(bound_options | ((buffers->smooth || buffers->face_indices_len) ?
-                                             0 : GPU_SHADER_FLAT_NORMAL));
+                       if ((buffers->smooth == false) && (buffers->face_indices_len == 0)) {
+                               bound_options_new |= GPU_SHADER_FLAT_NORMAL;
+                       }
+               }
+
+               if (bound_options_new & ~bound_options_old) {
+                       GPU_basic_shader_bind(bound_options_old | bound_options_new);
                }
 
                if (buffers->tot_quad) {
@@ -1944,7 +1948,10 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
                if (!wireframe) {
                        glDisableClientState(GL_NORMAL_ARRAY);
                        glDisableClientState(GL_COLOR_ARRAY);
-                       GPU_basic_shader_bind(bound_options);
+               }
+
+               if (bound_options_new & ~bound_options_old) {
+                       GPU_basic_shader_bind(bound_options_old);
                }
        }
 }