]> git.tdb.fi Git - libs/gl.git/commitdiff
Handle clipping in Pipeline and Renderer
authorMikko Rasa <tdb@tdb.fi>
Fri, 12 Aug 2016 20:38:50 +0000 (23:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 12 Aug 2016 20:38:50 +0000 (23:38 +0300)
source/pipeline.cpp
source/pipeline.h
source/renderer.cpp
source/renderer.h

index bcbbb05fe3b63aa0064c6e71db0fa5142f28d867..1833001ff1288fb00257450fe694bd9e44ae62a1 100644 (file)
@@ -178,6 +178,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
                Bind bind_depth_test(i->get_depth_test());
                Bind bind_blend(i->get_blend());
                renderer.set_lighting(i->get_lighting());
+               renderer.set_clipping(i->get_clipping());
 
                for(vector<Slot>::const_iterator j=renderables.begin(); j!=renderables.end(); ++j)
                        if(j->passes.empty() || j->passes.count(i->get_tag()))
@@ -241,7 +242,8 @@ Pipeline::Pass::Pass(const Tag &t):
        tag(t),
        lighting(0),
        depth_test(0),
-       blend(0)
+       blend(0),
+       clipping(0)
 { }
 
 void Pipeline::Pass::set_lighting(const Lighting *l)
@@ -259,6 +261,11 @@ void Pipeline::Pass::set_blend(const Blend *b)
        blend = b;
 }
 
+void Pipeline::Pass::set_clipping(const Clipping *c)
+{
+       clipping =c;
+}
+
 
 Pipeline::Slot::Slot(const Renderable *r):
        renderable(r)
index 515ca1a48db7992c1ae8c3bebc1a6bfd9fd10085..2c61a53791ae02ce36e3aa8c97cc68fda3b94b95 100644 (file)
@@ -13,6 +13,7 @@ namespace GL {
 
 class Blend;
 class Camera;
+class Clipping;
 class DepthTest;
 class Lighting;
 class PostProcessor;
@@ -49,6 +50,7 @@ public:
                const Lighting *lighting;
                const DepthTest *depth_test;
                const Blend *blend;
+               const Clipping *clipping;
 
        public:
                Pass(const Tag &);
@@ -58,9 +60,11 @@ public:
                void set_lighting(const Lighting *);
                void set_depth_test(const DepthTest *);
                void set_blend(const Blend *);
+               void set_clipping(const Clipping *);
                const Lighting *get_lighting() const { return lighting; }
                const DepthTest *get_depth_test() const { return depth_test; }
                const Blend *get_blend() const { return blend; }
+               const Clipping *get_clipping() const { return clipping; }
        };
 
 private:
index c558757f885654e0646f6392d9866b4bf52b205e..6a4c488f0b0ed81dcf1a9e35ce6f407f2651cf4f 100644 (file)
@@ -1,6 +1,7 @@
 #include "batch.h"
 #include "buffer.h"
 #include "camera.h"
+#include "clipping.h"
 #include "error.h"
 #include "lighting.h"
 #include "material.h"
@@ -102,6 +103,15 @@ void Renderer::set_lighting(const Lighting *l)
        changed |= LIGHTING;
 }
 
+void Renderer::set_clipping(const Clipping *c)
+{
+       state->clipping = c;
+       state->clipping_matrix = mtx_stack.top();
+       if(c)
+               c->update_shader_data(standard_shdata, mtx_stack.top());
+       changed |= CLIPPING;
+}
+
 void Renderer::set_shader_program(const Program *p, const ProgramData *d)
 {
        state->shprog = p;
@@ -144,6 +154,7 @@ void Renderer::pop_state()
                throw stack_underflow("Renderer::pop_state");
 
        const Lighting *old_lighting = state->lighting;
+       const Clipping *old_clipping = state->clipping;
        state_stack.pop_back();
        state = &state_stack.back();
        if(shdata_stack.size()>state->shdata_count)
@@ -160,6 +171,12 @@ void Renderer::pop_state()
                        state->lighting->update_shader_data(standard_shdata, state->lighting_matrix);
                changed |= LIGHTING;
        }
+       if(state->clipping!=old_clipping)
+       {
+               if(state->clipping)
+                       state->clipping->update_shader_data(standard_shdata, state->clipping_matrix);
+               changed |= CLIPPING;
+       }
 }
 
 void Renderer::escape()
@@ -256,6 +273,23 @@ void Renderer::apply_state()
                }
        }
 
+       if(changed&CLIPPING)
+       {
+               if(state->clipping)
+               {
+                       if(legacy_bindings)
+                       {
+                               MatrixStack::modelview() = state->clipping_matrix;
+                               state->clipping->bind(true);
+                               changed = (changed&~CLIPPING)|LEGACY_MATRIX;
+                       }
+                       else
+                               state->clipping->bind(false);
+               }
+               else
+                       Clipping::unbind();
+       }
+
        if(state->shprog)
        {
                bool shprog_changed = (state->shprog!=Program::current());
@@ -357,6 +391,7 @@ Renderer::State::State():
        lowest_effect_texunit(TexUnit::get_n_units()),
        material(0),
        lighting(0),
+       clipping(0),
        shprog(0),
        shdata_count(0),
        mesh(0),
index 18d3a41a7bf49dcf19737ce53a01f5a08cfc93e3..3d561b4fd8f0daea3cc69afa0fc0d1c7b8be86f1 100644 (file)
@@ -13,6 +13,7 @@ namespace GL {
 class Batch;
 class Buffer;
 class Camera;
+class Clipping;
 class Material;
 class Mesh;
 class Lighting;
@@ -69,6 +70,8 @@ private:
                const Material *material;
                const Lighting *lighting;
                Matrix lighting_matrix;
+               const Clipping *clipping;
+               Matrix clipping_matrix;
                const Program *shprog;
                unsigned shdata_count;
                const Mesh *mesh;
@@ -95,7 +98,8 @@ private:
                MODERN_MATRIX = 2,
                MATRIX = LEGACY_MATRIX|MODERN_MATRIX,
                LIGHTING = 4,
-               SHADER_DATA = 8
+               CLIPPING = 8,
+               SHADER_DATA = 16
        };
 
        MtxStack mtx_stack;
@@ -138,6 +142,7 @@ public:
        void set_material(const Material *);
 
        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
        well, with the same semantics as add_shader_data. */