From b781d8d1d713e28ec21a66a9d78eb3fc01f327e5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 26 Oct 2016 20:29:54 +0300 Subject: [PATCH] Track whether implicit shader data needs to be re-applied --- source/renderer.cpp | 18 +++++++++++++++--- source/renderer.h | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/source/renderer.cpp b/source/renderer.cpp index 8daa13ce..3ddb3a65 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -92,6 +92,7 @@ unsigned Renderer::allocate_effect_texunit() void Renderer::set_material(const Material *m) { state->material = m; + changed |= MATERIAL_SHDATA; } void Renderer::set_lighting(const Lighting *l) @@ -99,7 +100,10 @@ void Renderer::set_lighting(const Lighting *l) state->lighting = l; state->lighting_matrix = mtx_stack.top(); if(l) + { l->update_shader_data(standard_shdata, mtx_stack.top()); + changed |= STANDARD_SHDATA; + } changed |= LIGHTING; } @@ -305,12 +309,20 @@ void Renderer::apply_state() LinAl::SquareMatrix nm = m.block<3, 3>(0, 0); nm = transpose(invert(nm)); standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0)); - changed &= ~MODERN_MATRIX; + changed = (changed&~MODERN_MATRIX)|STANDARD_SHDATA; } - if(state->material) + if(state->material && (changed&MATERIAL_SHDATA)) + { state->material->get_shader_data().apply(); - standard_shdata.apply(); + changed &= ~MATERIAL_SHDATA; + } + + if(changed&STANDARD_SHDATA) + { + standard_shdata.apply(); + changed &= ~STANDARD_SHDATA; + } } if((changed&SHADER_DATA) || shprog_changed) diff --git a/source/renderer.h b/source/renderer.h index 3d561b4f..a4c5ef03 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -99,7 +99,9 @@ private: MATRIX = LEGACY_MATRIX|MODERN_MATRIX, LIGHTING = 4, CLIPPING = 8, - SHADER_DATA = 16 + SHADER_DATA = 16, + MATERIAL_SHDATA = 32, + STANDARD_SHDATA = 64 }; MtxStack mtx_stack; -- 2.45.2