]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/renderer.cpp
Use default member initializers for simple types
[libs/gl.git] / source / render / renderer.cpp
index 4acf3deda9dded4cabc903e5bfc42d718f0c2f3d..ad5f87d5a4fd6fd8add9613b7562cb4415de0156 100644 (file)
@@ -2,8 +2,8 @@
 #include "buffer.h"
 #include "camera.h"
 #include "clipping.h"
-#include "deviceinfo.h"
 #include "error.h"
+#include "framebuffer.h"
 #include "lighting.h"
 #include "material.h"
 #include "program.h"
 #include "texture.h"
 #include "vertexarray.h"
 #include "vertexsetup.h"
-#include "windingtest.h"
 
 using namespace std;
 
 namespace Msp {
 namespace GL {
 
-Renderer::Renderer()
+Renderer::Renderer():
+       changed(0)
 {
        state_stack.reserve(16);
        state_stack.push_back(State());
@@ -55,6 +55,21 @@ void Renderer::transform(const Matrix &matrix)
        changed |= MATRIX;
 }
 
+void Renderer::set_framebuffer(const Framebuffer *f)
+{
+       state->framebuffer = f;
+}
+
+void Renderer::set_viewport(const Rect *v)
+{
+       state->viewport = v;
+}
+
+void Renderer::set_scissor(const Rect *s)
+{
+       state->scissor = s;
+}
+
 void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
 {
        if(tex)
@@ -73,7 +88,7 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
                        flush_textures();
        }
 
-       for(vector<BoundTexture>::iterator i=texture_stack.end(); i!=texture_stack.begin(); )
+       for(auto i=texture_stack.end(); i!=texture_stack.begin(); )
                if((--i)->tag==tag)
                {
                        i->replaced = texture_stack.size();
@@ -152,14 +167,29 @@ void Renderer::set_vertex_setup(const VertexSetup *vs)
        state->vertex_setup = vs;
 }
 
-void Renderer::set_winding_test(const WindingTest *w)
+void Renderer::set_front_face(FaceWinding winding)
+{
+       state->front_face = winding;
+}
+
+void Renderer::set_face_cull(CullMode cull)
+{
+       state->face_cull = cull;
+}
+
+void Renderer::set_depth_test(const DepthTest *dt)
 {
-       state->winding_test = w;
+       state->depth_test = dt;
 }
 
-void Renderer::set_reverse_winding(bool r)
+void Renderer::set_stencil_test(const StencilTest *st)
 {
-       state->reverse_winding = r;
+       state->stencil_test = st;
+}
+
+void Renderer::set_blend(const Blend *b)
+{
+       state->blend = b;
 }
 
 void Renderer::set_object_lod_bias(unsigned b)
@@ -193,7 +223,7 @@ void Renderer::end()
        add_shader_data(standard_shdata);
        excluded.clear();
 
-       PipelineState::clear();
+       commands.use_pipeline(0);
 }
 
 void Renderer::exclude(const Renderable &renderable)
@@ -212,18 +242,54 @@ void Renderer::render(const Renderable &renderable, Tag tag)
                renderable.render(*this, tag);
 }
 
+void Renderer::clear(const ClearValue *values)
+{
+       pipeline_state.set_framebuffer(state->framebuffer);
+       pipeline_state.set_viewport(state->viewport);
+       pipeline_state.set_scissor(state->scissor);
+       commands.use_pipeline(&pipeline_state);
+       commands.clear(values);
+}
+
 void Renderer::draw(const Batch &batch)
 {
        apply_state();
-
-       batch.draw();
+       batch.refresh();
+       commands.use_pipeline(&pipeline_state);
+       commands.draw(batch);
 }
 
 void Renderer::draw_instanced(const Batch &batch, unsigned count)
 {
        apply_state();
+       batch.refresh();
+       commands.use_pipeline(&pipeline_state);
+       commands.draw_instanced(batch, count);
+}
+
+void Renderer::resolve_multisample(Framebuffer &target)
+{
+       if(!state->framebuffer)
+               throw invalid_operation("Renderer::resolve_multisample");
 
-       batch.draw_instanced(count);
+       unsigned width = state->framebuffer->get_width();
+       unsigned height = state->framebuffer->get_height();
+       if(target.get_width()!=width || target.get_height()!=height)
+               throw incompatible_data("Renderer::resolve_multisample");
+
+       pipeline_state.set_framebuffer(state->framebuffer);
+       commands.use_pipeline(&pipeline_state);
+       commands.resolve_multisample(target);
+}
+
+void Renderer::begin_query(const QueryPool &pool, unsigned index)
+{
+       commands.begin_query(pool, index);
+}
+
+void Renderer::end_query(const QueryPool &pool, unsigned index)
+{
+       commands.end_query(pool, index);
 }
 
 void Renderer::apply_state()
@@ -240,6 +306,10 @@ void Renderer::apply_state()
                changed &= ~MATRIX;
        }
 
+       pipeline_state.set_framebuffer(state->framebuffer);
+       pipeline_state.set_viewport(state->viewport);
+       pipeline_state.set_scissor(state->scissor);
+
        bool shprog_changed = (state->shprog!=pipeline_state.get_shader_program());
        pipeline_state.set_shader_program(state->shprog);
 
@@ -252,21 +322,22 @@ void Renderer::apply_state()
        }
        pipeline_state.set_vertex_setup(state->vertex_setup);
 
-       pipeline_state.set_winding_test((state->winding_test && state->reverse_winding) ? &state->winding_test->get_reverse() : state->winding_test);
+       pipeline_state.set_front_face(state->front_face);
+       pipeline_state.set_face_cull(state->face_cull);
        pipeline_state.set_enabled_clip_planes(state->clipping ? (1<<state->clipping->get_n_planes())-1 : 0);
 
        if(state->texture_count<texture_stack.size())
                flush_textures();
 
-       for(vector<BoundTexture>::const_iterator i=texture_stack.begin(); i!=texture_stack.end(); ++i)
+       for(const BoundTexture &t: texture_stack)
        {
-               int unit = (i->tag.id ? state->shprog->get_uniform_binding(i->tag) : i->unit);
+               int unit = (t.tag.id ? state->shprog->get_uniform_binding(t.tag) : t.unit);
                if(unit>=0)
-                       pipeline_state.set_texture(unit, i->texture, i->sampler);
+                       pipeline_state.set_texture(unit, t.texture, t.sampler);
        }
 
        bool shdata_changed = changed&SHADER_DATA;
-       for(vector<BoundProgramData>::const_iterator i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
+       for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
                shdata_changed = (i->shdata->get_generation()!=i->generation);
        bool extra_shdata = (shdata_stack.size()>state->shdata_count);
 
@@ -274,43 +345,22 @@ void Renderer::apply_state()
        {
                if(extra_shdata)
                        shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end());
-               for(vector<BoundProgramData>::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i)
+               for(const BoundProgramData &d: shdata_stack)
                {
-                       i->shdata->apply(*state->shprog, pipeline_state);
-                       i->generation = i->shdata->get_generation();
+                       d.shdata->apply(*state->shprog, pipeline_state);
+                       d.generation = d.shdata->get_generation();
                }
                changed &= ~SHADER_DATA;
        }
 
-       pipeline_state.apply();
+       pipeline_state.set_depth_test(state->depth_test);
+       pipeline_state.set_stencil_test(state->stencil_test);
+       pipeline_state.set_blend(state->blend);
 }
 
 
-Renderer::BoundTexture::BoundTexture():
-       unit(-1),
-       texture(0),
-       sampler(0),
-       replaced(-1)
-{ }
-
-
 Renderer::BoundProgramData::BoundProgramData(const ProgramData *d):
-       shdata(d),
-       generation(0)
-{ }
-
-
-Renderer::State::State():
-       camera(0),
-       texture_count(0),
-       lowest_effect_texunit(Limits::get_global().max_texture_bindings),
-       clipping(0),
-       shprog(0),
-       shdata_count(0),
-       vertex_setup(0),
-       winding_test(0),
-       reverse_winding(false),
-       object_lod_bias(0)
+       shdata(d)
 { }
 
 } // namespace GL