From: Mikko Rasa Date: Mon, 9 Aug 2021 12:10:11 +0000 (+0300) Subject: Handle all shader data in Renderer through the generic mechanism X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e24dcc10ff0d78203331eabae6b934c9e064105d;p=libs%2Fgl.git Handle all shader data in Renderer through the generic mechanism --- diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index a8f5ce3a..1d43a939 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -44,6 +44,7 @@ void Renderer::init() state_stack.push_back(State()); shdata_stack.reserve(32); state = &state_stack.back(); + add_shader_data(standard_shdata); } Renderer::~Renderer() @@ -54,7 +55,7 @@ Renderer::~Renderer() void Renderer::set_camera(const Camera &c) { state->camera = &c; - changed |= CAMERA_SHDATA; + add_shader_data(c.get_shader_data()); set_matrix(Matrix()); } @@ -161,7 +162,8 @@ void Renderer::set_lighting(const Lighting *l) void Renderer::set_clipping(const Clipping *c) { state->clipping = c; - changed |= CLIPPING_SHDATA; + if(c) + add_shader_data(c->get_shader_data()); } void Renderer::set_shader_program(const Program *p, const ProgramData *d) @@ -226,16 +228,9 @@ void Renderer::pop_state() if(state_stack.size()==1) throw stack_underflow("Renderer::pop_state"); - const Camera *old_camera = state->camera; - const Clipping *old_clipping = state->clipping; state_stack.pop_back(); state = &state_stack.back(); changed |= MATRIX; - bool camera_changed = (state->camera!=old_camera); - if(camera_changed) - changed |= CAMERA_SHDATA; - if(state->clipping!=old_clipping) - changed |= CLIPPING_SHDATA; } void Renderer::end() @@ -330,25 +325,7 @@ void Renderer::apply_state() LinAl::SquareMatrix nm = state->model_matrix.block<3, 3>(0, 0); nm = transpose(invert(nm)); standard_shdata.uniform("world_obj_normal_matrix", nm); - changed = (changed&~MATRIX)|STANDARD_SHDATA; - } - - if(state->camera && ((changed&CAMERA_SHDATA) || shprog_changed)) - { - state->camera->get_shader_data().apply(); - changed &= ~CAMERA_SHDATA; - } - - if(state->clipping && ((changed&CLIPPING_SHDATA) || shprog_changed)) - { - state->clipping->get_shader_data().apply(); - changed &= ~CLIPPING_SHDATA; - } - - if((changed&STANDARD_SHDATA) || shprog_changed) - { - standard_shdata.apply(); - changed &= ~STANDARD_SHDATA; + changed &= ~MATRIX; } bool shdata_changed = changed&SHADER_DATA; diff --git a/source/render/renderer.h b/source/render/renderer.h index 489cebb8..50254cdf 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -103,10 +103,7 @@ private: enum ChangeMask { MATRIX = 2, - SHADER_DATA = 16, - STANDARD_SHDATA = 64, - CAMERA_SHDATA = 128, - CLIPPING_SHDATA = 512 + SHADER_DATA = 16 }; const Camera *default_camera;