From e246ab24f150ae47df055af42487d267d905075d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 19 May 2020 01:57:24 +0300 Subject: [PATCH] Require shader for rendering Being able to assume shaders are used will make implementing some features easier. --- source/renderer.cpp | 64 +++++++++++++++++++++----------------------- source/technique.cpp | 3 +++ 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/source/renderer.cpp b/source/renderer.cpp index d6090d7d..d4cbbfe3 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -271,6 +271,9 @@ void Renderer::draw_instanced(const Batch &batch, unsigned count) void Renderer::apply_state() { + if(!state->shprog) + throw invalid_operation("Renderer::apply_state"); + /* We (mostly) let the objects themselves figure out if the binding has changed */ @@ -290,45 +293,40 @@ void Renderer::apply_state() else Clipping::unbind(); - if(state->shprog) - { - bool shprog_changed = (state->shprog!=Program::current()); - state->shprog->bind(); + bool shprog_changed = (state->shprog!=Program::current()); + state->shprog->bind(); - if(changed&MATRIX) - { - standard_shdata.uniform("eye_obj_matrix", state->modelview_matrix); - LinAl::SquareMatrix nm = state->modelview_matrix.block<3, 3>(0, 0); - nm = transpose(invert(nm)); - standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0)); - changed = (changed&~MATRIX)|STANDARD_SHDATA; - } + if(changed&MATRIX) + { + standard_shdata.uniform("eye_obj_matrix", state->modelview_matrix); + LinAl::SquareMatrix nm = state->modelview_matrix.block<3, 3>(0, 0); + nm = transpose(invert(nm)); + standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0)); + changed = (changed&~MATRIX)|STANDARD_SHDATA; + } - if(state->material && ((changed&MATERIAL_SHDATA) || shprog_changed)) - { - state->material->get_shader_data().apply(); - changed &= ~MATERIAL_SHDATA; - } + if(state->material && ((changed&MATERIAL_SHDATA) || shprog_changed)) + { + state->material->get_shader_data().apply(); + changed &= ~MATERIAL_SHDATA; + } - if((changed&STANDARD_SHDATA) || shprog_changed) - { - standard_shdata.apply(); - changed &= ~STANDARD_SHDATA; - } + if((changed&STANDARD_SHDATA) || shprog_changed) + { + standard_shdata.apply(); + changed &= ~STANDARD_SHDATA; + } - bool extra_shdata = (shdata_stack.size()>state->shdata_count); + bool extra_shdata = (shdata_stack.size()>state->shdata_count); - if((changed&SHADER_DATA) || shprog_changed || extra_shdata) - { - if(extra_shdata) - shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end()); - for(vector::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i) - (*i)->apply(); - changed &= ~SHADER_DATA; - } + if((changed&SHADER_DATA) || shprog_changed || extra_shdata) + { + if(extra_shdata) + shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end()); + for(vector::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i) + (*i)->apply(); + changed &= ~SHADER_DATA; } - else - Program::unbind(); if(state->vertex_setup) state->vertex_setup->bind(); diff --git a/source/technique.cpp b/source/technique.cpp index e3233eff..09799ace 100644 --- a/source/technique.cpp +++ b/source/technique.cpp @@ -135,6 +135,9 @@ void Technique::Loader::pass(const string &n) else load_sub(p); + if(!p.get_shader_program()) + throw logic_error("no shader program in pass"); + insert_unique(obj.passes, n, p); } -- 2.45.2