]> git.tdb.fi Git - libs/gl.git/commitdiff
Require shader for rendering
authorMikko Rasa <tdb@tdb.fi>
Mon, 18 May 2020 22:57:24 +0000 (01:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 18 May 2020 22:57:24 +0000 (01:57 +0300)
Being able to assume shaders are used will make implementing some
features easier.

source/renderer.cpp
source/technique.cpp

index d6090d7d2cd57db6fb7318f15df8d8752abcbe30..d4cbbfe3454e39ef91a881bcf72cb8e06e00628a 100644 (file)
@@ -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<float, 3> 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<float, 3> 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 ProgramData *>::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 ProgramData *>::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();
index e3233eff87cc5c6c7ba15550605b709ee4b55ad4..09799acee8841ac3eefe9d3fe1cfb5fa08801283 100644 (file)
@@ -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);
 }