]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/renderer.cpp
Move WindowView::render to the backend
[libs/gl.git] / source / render / renderer.cpp
index aa6c9b55a4d4206ef458012e280efdacb3e9aba5..b935ce14c3e88bf94636135cc5ae0fe084574cbf 100644 (file)
@@ -1,9 +1,8 @@
 #include "batch.h"
 #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"
@@ -21,15 +20,13 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Renderer::Renderer():
-       changed(0)
+Renderer::Renderer()
 {
        state_stack.reserve(16);
        state_stack.push_back(State());
        shdata_stack.reserve(32);
        state = &state_stack.back();
        add_shader_data(standard_shdata);
-       commands.use_pipeline(pipeline_state);
 }
 
 Renderer::~Renderer()
@@ -125,13 +122,6 @@ void Renderer::set_lighting(const Lighting *l)
                add_shader_data(l->get_shader_data());
 }
 
-void Renderer::set_clipping(const Clipping *c)
-{
-       state->clipping = c;
-       if(c)
-               add_shader_data(c->get_shader_data());
-}
-
 void Renderer::set_shader_program(const Program *p, const ProgramData *d)
 {
        state->shprog = p;
@@ -222,30 +212,16 @@ void Renderer::end()
        *state = State();
        shdata_stack.clear();
        add_shader_data(standard_shdata);
-       excluded.clear();
-
-       PipelineState::clear();
-}
 
-void Renderer::exclude(const Renderable &renderable)
-{
-       excluded.insert(&renderable);
-}
-
-void Renderer::include(const Renderable &renderable)
-{
-       excluded.erase(&renderable);
-}
-
-void Renderer::render(const Renderable &renderable, Tag tag)
-{
-       if(!excluded.count(&renderable))
-               renderable.render(*this, tag);
+       commands.use_pipeline(0);
 }
 
 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);
 }
 
@@ -253,6 +229,7 @@ void Renderer::draw(const Batch &batch)
 {
        apply_state();
        batch.refresh();
+       commands.use_pipeline(&pipeline_state);
        commands.draw(batch);
 }
 
@@ -260,10 +237,11 @@ 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, BufferBits buffers)
+void Renderer::resolve_multisample(Framebuffer &target)
 {
        if(!state->framebuffer)
                throw invalid_operation("Renderer::resolve_multisample");
@@ -274,7 +252,18 @@ void Renderer::resolve_multisample(Framebuffer &target, BufferBits buffers)
                throw incompatible_data("Renderer::resolve_multisample");
 
        pipeline_state.set_framebuffer(state->framebuffer);
-       commands.resolve_multisample(target, buffers);
+       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()
@@ -309,17 +298,18 @@ void Renderer::apply_state()
 
        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(const BoundTexture &t: texture_stack)
-       {
-               int unit = (t.tag.id ? state->shprog->get_uniform_binding(t.tag) : t.unit);
-               if(unit>=0)
-                       pipeline_state.set_texture(unit, t.texture, t.sampler);
-       }
+               if(t.texture && t.replaced<0)
+               {
+                       if(t.binding<0 || shprog_changed)
+                               t.binding = state->shprog->get_uniform_binding(t.tag);
+                       if(t.binding>=0)
+                               pipeline_state.set_texture(t.binding, t.texture, t.sampler);
+               }
 
        bool shdata_changed = changed&SHADER_DATA;
        for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
@@ -344,36 +334,8 @@ void Renderer::apply_state()
 }
 
 
-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),
-       framebuffer(0),
-       viewport(0),
-       scissor(0),
-       texture_count(0),
-       clipping(0),
-       shprog(0),
-       shdata_count(0),
-       vertex_setup(0),
-       front_face(NON_MANIFOLD),
-       face_cull(NO_CULL),
-       depth_test(0),
-       stencil_test(0),
-       blend(0),
-       object_lod_bias(0)
+       shdata(d)
 { }
 
 } // namespace GL