diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-06-09 23:08:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-09 23:09:11 +0300 |
commit | efd547f3da10a247fdcff66e74f9b98ec3abdd39 (patch) | |
tree | ef4a5d2b3fc8cc7c03eeefc00dfa87a4a0bb238e /source/blender/gpu/intern | |
parent | 6798809c7ec8388509f541a64359b3d107e6fd3f (diff) |
GPU: avoid multiple bind calls in GPU_draw_pbvh_buffers
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
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_basic_shader.c | 10 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 23 |
2 files changed, 25 insertions, 8 deletions
diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c index c5a2d07bdc8..1e60944c23d 100644 --- a/source/blender/gpu/intern/gpu_basic_shader.c +++ b/source/blender/gpu/intern/gpu_basic_shader.c @@ -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 diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 35bfc687052..36d297fb9fe 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -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); } } } |