From: Mikko Rasa Date: Tue, 11 Jan 2011 20:03:37 +0000 (+0000) Subject: Better tracking of Renderer matrix changes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=90a26a1740d5843b60d07d9c39d8567bfed5189c;p=libs%2Fgl.git Better tracking of Renderer matrix changes Make MatrixStack::top() const --- diff --git a/source/matrix.cpp b/source/matrix.cpp index 4c3a7ee6..caa728d0 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -294,7 +294,7 @@ MatrixStack::MatrixStack(): matrices.push_back(Matrix()); } -const Matrix &MatrixStack::top() +const Matrix &MatrixStack::top() const { return matrices.back(); } diff --git a/source/matrix.h b/source/matrix.h index 42e70c98..1782dc66 100644 --- a/source/matrix.h +++ b/source/matrix.h @@ -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 &); diff --git a/source/renderer.cpp b/source/renderer.cpp index 71a7dedf..bfd446e9 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -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 diff --git a/source/renderer.h b/source/renderer.h index c06c17e9..8dbe779f 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -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_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; }