]> git.tdb.fi Git - libs/gl.git/commitdiff
Better tracking of Renderer matrix changes
authorMikko Rasa <tdb@tdb.fi>
Tue, 11 Jan 2011 20:03:37 +0000 (20:03 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 11 Jan 2011 20:03:37 +0000 (20:03 +0000)
Make MatrixStack::top() const

source/matrix.cpp
source/matrix.h
source/renderer.cpp
source/renderer.h

index 4c3a7ee6a477d64733d1665c9766caedda5ac0ec..caa728d0c366708403f31a0776cb85012253e774 100644 (file)
@@ -294,7 +294,7 @@ MatrixStack::MatrixStack():
        matrices.push_back(Matrix());
 }
 
-const Matrix &MatrixStack::top()
+const Matrix &MatrixStack::top() const
 {
        return matrices.back();
 }
index 42e70c985d5d78d0cc22d408e187f1dda7a5f025..1782dc66a958257e90a439ec0bd2a180b6e58e41 100644 (file)
@@ -98,13 +98,13 @@ private:
 public:
        MatrixStack();
 
-       const Matrix &top();
+       const Matrix &top() const;
        void load(const Matrix &);
        void multiply(const Matrix &);
        void push();
        void pop();
 private:
-       void update();
+       virtual void update();
 
 public:
        MatrixStack &operator=(const Matrix &);
index 71a7dedff1ea09e094fd2b2c9b31ae3246dfadb9..bfd446e9f42ccc30aa47306d26f6d535fe1b4ea9 100644 (file)
@@ -23,6 +23,7 @@ namespace Msp {
 namespace GL {
 
 Renderer::Renderer(const Camera *c):
+       mtx_stack(*this),
        mtx_changed(false),
        camera(c),
        state_stack(1),
@@ -36,10 +37,10 @@ Renderer::Renderer(const Camera *c):
        {
                MatrixStack::projection().push();
                camera->apply();
-               mtx_stack = camera->get_matrix();
+               mtx_stack.load(camera->get_matrix());
        }
        else
-               mtx_stack = MatrixStack::modelview().top();
+               mtx_stack.load(MatrixStack::modelview().top());
 }
 
 Renderer::~Renderer()
@@ -55,12 +56,6 @@ Renderer::~Renderer()
        Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
 }
 
-MatrixStack &Renderer::matrix_stack()
-{
-       mtx_changed = true;
-       return mtx_stack;
-}
-
 void Renderer::set_texture(const Texture *t)
 {
        state->texture = t;
@@ -121,6 +116,7 @@ void Renderer::pop_state()
        state_stack.pop_back();
        state = &state_stack.back();
        mtx_stack.pop();
+       mtx_changed = true;
 }
 
 void Renderer::escape()
@@ -192,5 +188,15 @@ Renderer::State::State():
        shprog(0)
 { }
 
+
+Renderer::MtxStack::MtxStack(Renderer &r):
+       renderer(r)
+{ }
+
+void Renderer::MtxStack::update()
+{
+       renderer.mtx_changed = true;
+}
+
 } // namespace GL
 } // namespace Msp
index c06c17e96b4d18be0c61d7d0b8c1af24f67a81b6..8dbe779f32b78f6a8e1bf108c084ad7a4f2afba7 100644 (file)
@@ -56,7 +56,18 @@ private:
                State();
        };
 
-       MatrixStack mtx_stack;
+       class MtxStack: public MatrixStack
+       {
+       private:
+               Renderer &renderer;
+
+       public:
+               MtxStack(Renderer &);
+       private:        
+               virtual void update();
+       };
+
+       MtxStack mtx_stack;
        bool mtx_changed;
        const Camera *camera;
        std::list<State> state_stack;
@@ -69,7 +80,7 @@ public:
        Renderer(const Camera *);
        ~Renderer();
 
-       MatrixStack &matrix_stack();
+       MatrixStack &matrix_stack() { return mtx_stack; }
 
        const Camera *get_camera() const { return camera; }