From fdc7fecc65f5f517d66abe3546a949a46836c4a6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 30 Nov 2012 22:58:52 +0200 Subject: [PATCH] Use a GL::Renderer to render widgets This eliminates a lot of texture and matrix thrashing. --- source/dropdown.cpp | 4 ++-- source/dropdown.h | 2 +- source/entry.cpp | 4 ++-- source/entry.h | 2 +- source/list.cpp | 4 ++-- source/list.h | 2 +- source/panel.cpp | 4 ++-- source/panel.h | 2 +- source/root.cpp | 3 ++- source/widget.cpp | 12 ++++++------ source/widget.h | 5 +++-- 11 files changed, 23 insertions(+), 21 deletions(-) diff --git a/source/dropdown.cpp b/source/dropdown.cpp index c2ceefa..41e42fa 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -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) diff --git a/source/dropdown.h b/source/dropdown.h index 4af5a5f..166eebf 100644 --- a/source/dropdown.h +++ b/source/dropdown.h @@ -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); diff --git a/source/entry.cpp b/source/entry.cpp index ca185be..6e2063d 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -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) diff --git a/source/entry.h b/source/entry.h index 968e399..3ee0b2c 100644 --- a/source/entry.h +++ b/source/entry.h @@ -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); diff --git a/source/list.cpp b/source/list.cpp index 19559d1..7041f73 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -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) diff --git a/source/list.h b/source/list.h index 2970bb4..1c7a65d 100644 --- a/source/list.h +++ b/source/list.h @@ -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); diff --git a/source/panel.cpp b/source/panel.cpp index 91e30cd..2ede2a9 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -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::const_iterator i=children.begin(); i!=children.end(); ++i) if((*i)->widget->is_visible()) - (*i)->widget->render(); + (*i)->widget->render(renderer); } } diff --git a/source/panel.h b/source/panel.h index a6a89c5..1126e83 100644 --- a/source/panel.h +++ b/source/panel.h @@ -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); diff --git a/source/root.cpp b/source/root.cpp index bce6adf..e7c0a92 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -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) diff --git a/source/widget.cpp b/source/widget.cpp index 4b48e8b..9dbd9da 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -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::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); } } diff --git a/source/widget.h b/source/widget.h index ba49b09..270d2a3 100644 --- a/source/widget.h +++ b/source/widget.h @@ -3,6 +3,7 @@ #include #include +#include #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 -- 2.43.0