]> git.tdb.fi Git - libs/gltk.git/commitdiff
Use a shader for rendering if available
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:45:57 +0000 (23:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:46:14 +0000 (23:46 +0200)
source/root.cpp
source/root.h

index f4bad55beb546dfa91ee0dd9d960a7a0451b2fed..8b06f4788f9f4ae45b8837ed63f6c1569b8bc62a 100644 (file)
@@ -1,4 +1,7 @@
 #include <msp/gl/blend.h>
+#include <msp/gl/extensions/arb_shader_objects.h>
+#include <msp/gl/programbuilder.h>
+#include <msp/gl/uniform.h>
 #include <msp/input/keys.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
@@ -38,6 +41,18 @@ void Root::init(Graphics::Window *window)
        camera.set_orthographic(geom.w, geom.h);
        update_camera();
 
+       if(GL::ARB_shader_objects)
+       {
+               shprog = new GL::Program;
+               GL::ProgramBuilder::StandardFeatures features;
+               features.material = true;
+               features.texture = true;
+               GL::ProgramBuilder(features).add_shaders(*shprog);
+               shprog->link();
+       }
+       else
+               shprog = 0;
+
        update_style();
 
        if(mouse)
@@ -57,6 +72,7 @@ void Root::init(Graphics::Window *window)
 
 Root::~Root()
 {
+       delete shprog;
        if(own_input)
        {
                delete keyboard;
@@ -115,6 +131,7 @@ void Root::render() const
        GL::Bind bind_blend(GL::Blend::alpha());
 
        GL::Renderer renderer(&camera);
+       renderer.set_shader_program(shprog);
        Widget::render(renderer);
 }
 
index b79bca367d3e22c51ca3c86ad61bf6683728337e..8e1bed9247e00bd2693bd9fe904ab16995591c9a 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <sigc++/trackable.h>
 #include <msp/gl/camera.h>
+#include <msp/gl/program.h>
 #include <msp/graphics/window.h>
 #include <msp/input/keyboard.h>
 #include <msp/input/mouse.h>
@@ -34,6 +35,7 @@ private:
        Time::TimeStamp tooltip_timeout;
        Widget *tooltip_target;
        Msp::GL::Camera camera;
+       Msp::GL::Program *shprog;
 
 public:
        /** Creates a Root widget for a window.  The geometry is set to match the