]> git.tdb.fi Git - libs/gl.git/commitdiff
Tweak the shader functions in Renderer
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 07:39:19 +0000 (10:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 07:39:19 +0000 (10:39 +0300)
Since ProgramData is no longer tied to a single Program, we can retain it
over program changes.  This opens up some new possibilities, in
particular for Effects.

Also rename set_shader to set_shader_program.

demos/cubemap.cpp
demos/shaders.cpp
source/animatedobject.cpp
source/object.cpp
source/renderer.cpp
source/renderer.h

index 1778fb7fbfa1567cbb9c6fb2314710096f45d180..98d0ba245f0ab8bab0c6d4a7cd35a7f603bc8280 100644 (file)
@@ -112,7 +112,7 @@ int main()
                        GL::Bind bind_depth(GL::DepthTest::lequal());
                        GL::Renderer renderer(0);
                        renderer.set_material(&material);
-                       renderer.set_shader(&shprog, &shdata);
+                       renderer.set_shader_program(&shprog, &shdata);
                        renderer.set_texture(&texture);
                        renderer.matrix_stack() *= GL::Matrix::translation(0, 0, -7);
                        {
index ae5c98fbb727cd42e4259a44d446148dc9b56d47..27538e4eb2e6a2c35e1bf5aa9e7fa4465a5b8bd8 100644 (file)
@@ -112,10 +112,11 @@ int main()
                        GL::Renderer renderer(0);
                        renderer.set_material(&mat);
                        renderer.set_texturing(&texturing);
+                       renderer.add_shader_data(progdata);
                        for(unsigned i=0; i<12; ++i)
                        {
                                GL::MatrixStack::Push push(renderer.matrix_stack());
-                               renderer.set_shader(programs[i], &progdata);
+                               renderer.set_shader_program(programs[i]);
                                renderer.matrix_stack() *= GL::Matrix::translation(-3.3+(i%4)*2.2, 0, -3.5+(i/4)*3.0);
                                renderer.matrix_stack() *= GL::Matrix::rotation(angle, 0, 0, 1);
                                mesh.draw(renderer);
index eec54aa74f38d24ddb40e57d7e1bf922e951d76c..63a25112a769428374e37dd0634251b4f2c2c8b7 100644 (file)
@@ -45,7 +45,7 @@ void AnimatedObject::setup_render(Renderer &renderer, const Tag &) const
 {
        renderer.matrix_stack() *= matrix;
        if(shdata)
-               renderer.add_shader_data(shdata);
+               renderer.add_shader_data(*shdata);
 }
 
 } // namespace GL
index 06062fc099da69e169f0f23431c5445ce931216b..964099e51e4022c09335c16b7ca023d491de7c26 100644 (file)
@@ -77,7 +77,7 @@ void Object::render(Renderer &renderer, const Tag &tag) const
                return;
 
        Renderer::Push push(renderer);
-       renderer.set_shader(pass->get_shader_program(), pass->get_shader_data());
+       renderer.set_shader_program(pass->get_shader_program(), pass->get_shader_data());
        renderer.set_material(pass->get_material());
        renderer.set_texturing(pass->get_texturing());
 
@@ -91,7 +91,7 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, const Tag &t
                return;
 
        Renderer::Push push(renderer);
-       renderer.set_shader(pass->get_shader_program(), pass->get_shader_data());
+       renderer.set_shader_program(pass->get_shader_program(), pass->get_shader_data());
        renderer.set_material(pass->get_material());
        renderer.set_texturing(pass->get_texturing());
 
index ee845e08b12d18d66c864cf936b3b48a8eae935f..c751b0e3629d77b8bd93fee9aa4049f3a75cc57f 100644 (file)
@@ -68,22 +68,17 @@ void Renderer::set_material(const Material *m)
        state->material = m;
 }
 
-void Renderer::set_shader(const Program *p, const ProgramData *d)
+void Renderer::set_shader_program(const Program *p, const ProgramData *d)
 {
        state->shprog = p;
-       if(d)
-               state->shdata.assign(1, d);
-       else
-               state->shdata.clear();
+       if(p && d)
+               add_shader_data(*d);
        shdata_changed = true;
 }
 
-void Renderer::add_shader_data(const ProgramData *d)
+void Renderer::add_shader_data(const ProgramData &d)
 {
-       if(!state->shprog)
-               throw invalid_operation("Renderer::add_shader_data");
-
-       state->shdata.push_back(d);
+       state->shdata.push_back(&d);
        shdata_changed = true;
 }
 
index dd54ca1691dfaf49233608ff85f2ff5de9e69440..5536702b751a6d83288f14307eb6b6609b185dab 100644 (file)
@@ -85,8 +85,16 @@ public:
        void set_texture(const Texture *);
        void set_texturing(const Texturing *);
        void set_material(const Material *);
-       void set_shader(const Program *, const ProgramData *);
-       void add_shader_data(const ProgramData *);
+
+       /** Sets the shader program to use.  An initial set of data can be set as
+       well, with the same semantics as add_shader_data. */
+       void set_shader_program(const Program *prog, const ProgramData *data = 0);
+
+       /** Adds another set of data to be use with shader programs.  The data is
+       independent of any shader program changes and remains in effect until the
+       Renderer state is popped. */
+       void add_shader_data(const ProgramData &data);
+
        void set_vertex_array(const VertexArray *);
        void set_element_buffer(const Buffer *);
        void set_winding_test(const WindingTest *);