]> git.tdb.fi Git - libs/gltk.git/commitdiff
Use a GL::Renderer to render widgets
authorMikko Rasa <tdb@tdb.fi>
Fri, 30 Nov 2012 20:58:52 +0000 (22:58 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 30 Nov 2012 20:58:52 +0000 (22:58 +0200)
This eliminates a lot of texture and matrix thrashing.

source/dropdown.cpp
source/dropdown.h
source/entry.cpp
source/entry.h
source/list.cpp
source/list.h
source/panel.cpp
source/panel.h
source/root.cpp
source/widget.cpp
source/widget.h

index c2ceefa78957348ee6edd188e71e8ec1faf1fd95..41e42fa72fa4b45b399ede99167d3a45d0bbe869 100644 (file)
@@ -91,10 +91,10 @@ void Dropdown::rebuild_special(const Part &part, CachedPart &cache)
        }
 }
 
-void Dropdown::render_special(const Part &part) const
+void Dropdown::render_special(const Part &part, GL::Renderer &renderer) const
 {
        if(part.get_name()=="list" && dropped)
-               list.render();
+               list.render(renderer);
 }
 
 void Dropdown::button_press(int x, int y, unsigned btn)
index 4af5a5fe9a265cb484a509950ee5982d8d486713..166eebf53da3943040c2565b9f4d471cca7d9919 100644 (file)
@@ -46,7 +46,7 @@ public:
 
 private:
        virtual void rebuild_special(const Part &, CachedPart &);
-       virtual void render_special(const Part &) const;
+       virtual void render_special(const Part &, GL::Renderer &) const;
 
 public:
        virtual void button_press(int, int, unsigned);
index ca185bea0168c4e40b1accf63055136443ced6e2..6e2063d04abec1de23c73baeb8417094c9ca0a73 100644 (file)
@@ -136,10 +136,10 @@ void Entry::rebuild_special(const Part &part, CachedPart &cache)
        }
 }
 
-void Entry::render_special(const Part &part) const
+void Entry::render_special(const Part &part, GL::Renderer &renderer) const
 {
        if(part.get_name()=="slider" && multiline)
-               slider->render();
+               slider->render(renderer);
 }
 
 void Entry::key_press(unsigned key, unsigned)
index 968e3994580b042e35d19c3a4813ec5c6fcc1ec0..3ee0b2c2b2c132ef8164f0e66593dabcec07a620 100644 (file)
@@ -53,7 +53,7 @@ public:
 
 private:
        virtual void rebuild_special(const Part &, CachedPart &);
-       virtual void render_special(const Part &) const;
+       virtual void render_special(const Part &, GL::Renderer &) const;
 
 public:
        virtual void key_press(unsigned, unsigned);
index 19559d1d05b8f51606fc2cd36a4bce5689344901..7041f733759da99585d2b4dde562458a9684ea3e 100644 (file)
@@ -199,10 +199,10 @@ void List::rebuild_special(const Part &part, CachedPart &cache)
        }
 }
 
-void List::render_special(const Part &part) const
+void List::render_special(const Part &part, GL::Renderer &renderer) const
 {
        if(part.get_name()=="slider")
-               slider.render();
+               slider.render(renderer);
 }
 
 void List::button_press(int x, int y, unsigned btn)
index 2970bb454b19425a5a3626de1c025facd8ccebc3..1c7a65dc161e0eae62011cbad1a50a14b06014d7 100644 (file)
@@ -60,7 +60,7 @@ public:
 
 private:
        virtual void rebuild_special(const Part &, CachedPart &);
-       virtual void render_special(const Part &) const;
+       virtual void render_special(const Part &, GL::Renderer &) const;
 
 public:
        virtual void button_press(int, int, unsigned);
index 91e30cdcbafadd63b98714c6cd1a8f3969fb1f07..2ede2a9c77fd8b32a105971b894fb5fba66d3919 100644 (file)
@@ -73,13 +73,13 @@ Widget *Panel::get_final_input_focus() const
        return input_focus;
 }
 
-void Panel::render_special(const Part &part) const
+void Panel::render_special(const Part &part, GL::Renderer &renderer) const
 {
        if(part.get_name()=="children")
        {
                for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
                        if((*i)->widget->is_visible())
-                               (*i)->widget->render();
+                               (*i)->widget->render(renderer);
        }
 }
 
index a6a89c5ba18e8dd956fe2580262bf5b4627f8aca..1126e837836e46f5d88590e2cf94df3b14efc174 100644 (file)
@@ -72,7 +72,7 @@ public:
        Widget *get_final_input_focus() const;
 
 protected:
-       virtual void render_special(const Part &) const;
+       virtual void render_special(const Part &, GL::Renderer &) const;
 
 public:
        virtual void button_press(int, int, unsigned);
index bce6adf8f7a9799fd9811696969737cc6ddc178f..e7c0a9251eadebfe8863e3549e4571737c0b24aa 100644 (file)
@@ -81,7 +81,8 @@ void Root::render() const
        GL::MatrixStack::modelview() = GL::Matrix();
        GL::Bind bind_blend(GL::Blend::alpha());
 
-       Widget::render();
+       GL::Renderer renderer(0);
+       Widget::render(renderer);
 }
 
 void Root::button_press_event(unsigned btn)
index 4b48e8ba11400d2f410790de92b8464e890b68b3..9dbd9da5ba2df7f60f44d824a8a7989d11d917dd 100644 (file)
@@ -160,24 +160,24 @@ void Widget::rebuild()
        }
 }
 
-void Widget::render() const
+void Widget::render(GL::Renderer &renderer) const
 {
        if(!style)
                throw logic_error(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
 
-       GL::MatrixStack::Push _pushm(GL::MatrixStack::modelview());
-       GL::MatrixStack::modelview() *= GL::Matrix::translation(geom.x, geom.y, 0);
+       GL::MatrixStack::Push _pushm(renderer.matrix_stack());
+       renderer.matrix_stack() *= GL::Matrix::translation(geom.x, geom.y, 0);
        const Style::PartSeq &parts = style->get_parts();
        list<CachedPart>::const_iterator j = cached_parts.begin();
        for(Style::PartSeq::const_iterator i=parts.begin(); (i!=parts.end() && j!=cached_parts.end()); ++i, ++j)
        {
                if(j->mesh && j->texture)
                {
-                       GL::Bind bind_tex(j->texture);
-                       j->mesh->draw();
+                       renderer.set_texture(j->texture);
+                       j->mesh->draw(renderer);
                }
                else if(!i->get_name().empty())
-                       render_special(*i);
+                       render_special(*i, renderer);
        }
 }
 
index ba49b09e44c90a5abd1644dbbd4f9f3ee276afdd..270d2a3f67eb2e1d890dbfc1426a8adac65fe0db 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <msp/datafile/objectloader.h>
+#include <msp/gl/renderer.h>
 #include "geometry.h"
 #include "partcache.h"
 #include "state.h"
@@ -108,9 +109,9 @@ protected:
        virtual void rebuild_special(const Part &, CachedPart &) { }
 
 public:
-       void render() const;
+       void render(GL::Renderer &) const;
 protected:
-       virtual void render_special(const Part &) const { }
+       virtual void render_special(const Part &, GL::Renderer &) const { }
 
 public:
        // Events