From: Mikko Rasa Date: Sat, 7 Aug 2021 12:07:44 +0000 (+0300) Subject: Deprecated setting Material or Lighting on Renderer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=45de0062950ad822ed0379ed4fe807d333e1b8f1;p=libs%2Fgl.git Deprecated setting Material or Lighting on Renderer Those no longer have any special state of their own and can be set as ProgramData instead. --- diff --git a/source/materials/renderpass.cpp b/source/materials/renderpass.cpp index 62056ff9..4ab72b56 100644 --- a/source/materials/renderpass.cpp +++ b/source/materials/renderpass.cpp @@ -139,8 +139,9 @@ void RenderPass::apply(Renderer &renderer) const { for(vector::const_iterator i=textures.begin(); i!=textures.end(); ++i) renderer.set_texture(i->tag, i->texture, i->sampler); - renderer.set_material(material); renderer.set_shader_program(shprog, shdata.get()); + if(material) + renderer.add_shader_data(material->get_shader_data()); renderer.set_reverse_winding(back_faces); } diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 2da4bd78..7389298a 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -147,14 +147,14 @@ unsigned Renderer::allocate_effect_texunit() void Renderer::set_material(const Material *m) { - state->material = m; - changed |= MATERIAL_SHDATA; + if(m) + add_shader_data(m->get_shader_data()); } void Renderer::set_lighting(const Lighting *l) { - state->lighting = l; - changed |= LIGHTING_SHDATA; + if(l) + add_shader_data(l->get_shader_data()); } void Renderer::set_clipping(const Clipping *c) @@ -226,7 +226,6 @@ void Renderer::pop_state() throw stack_underflow("Renderer::pop_state"); const Camera *old_camera = state->camera; - const Lighting *old_lighting = state->lighting; const Clipping *old_clipping = state->clipping; state_stack.pop_back(); state = &state_stack.back(); @@ -234,8 +233,6 @@ void Renderer::pop_state() bool camera_changed = (state->camera!=old_camera); if(camera_changed) changed |= CAMERA_SHDATA; - if(state->lighting!=old_lighting) - changed |= LIGHTING_SHDATA; if(state->clipping!=old_clipping) changed |= CLIPPING_SHDATA; } @@ -341,18 +338,6 @@ void Renderer::apply_state() changed &= ~CAMERA_SHDATA; } - if(state->material && ((changed&MATERIAL_SHDATA) || shprog_changed)) - { - state->material->get_shader_data().apply(); - changed &= ~MATERIAL_SHDATA; - } - - if(state->lighting && ((changed&LIGHTING_SHDATA) || shprog_changed)) - { - state->lighting->get_shader_data().apply(); - changed &= ~LIGHTING_SHDATA; - } - if(state->clipping && ((changed&CLIPPING_SHDATA) || shprog_changed)) { state->clipping->get_shader_data().apply(); @@ -417,8 +402,6 @@ Renderer::State::State(): camera(0), texture_count(0), lowest_effect_texunit(TexUnit::get_n_units()), - material(0), - lighting(0), clipping(0), shprog(0), shdata_count(0), diff --git a/source/render/renderer.h b/source/render/renderer.h index 197cf95a..69474d40 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -89,8 +89,6 @@ private: Matrix model_matrix; unsigned texture_count; unsigned lowest_effect_texunit; - const Material *material; - const Lighting *lighting; const Clipping *clipping; const Program *shprog; unsigned shdata_count; @@ -106,10 +104,8 @@ private: { MATRIX = 2, SHADER_DATA = 16, - MATERIAL_SHDATA = 32, STANDARD_SHDATA = 64, CAMERA_SHDATA = 128, - LIGHTING_SHDATA = 256, CLIPPING_SHDATA = 512 }; @@ -155,9 +151,9 @@ public: DEPRECATED void set_texturing(const Texturing *); DEPRECATED unsigned allocate_effect_texunit(); #pragma GCC diagnostic pop - void set_material(const Material *); + DEPRECATED void set_material(const Material *); - void set_lighting(const Lighting *); + DEPRECATED void set_lighting(const Lighting *); void set_clipping(const Clipping *); /** Sets the shader program to use. An initial set of data can be set as diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 05cbafff..9161c751 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -185,7 +185,8 @@ void Sequence::render(Renderer &renderer, Tag tag) const else Blend::unbind(); - renderer.set_lighting(i->get_lighting()); + if (const Lighting *lighting = i->get_lighting()) + renderer.add_shader_data(lighting->get_shader_data()); renderer.set_clipping(i->get_clipping()); if(const Renderable *renderable = i->get_renderable())