]> git.tdb.fi Git - libs/gl.git/blobdiff - source/renderer.cpp
Use Renderer to bind Lighting
[libs/gl.git] / source / renderer.cpp
index 442728135274576129ff0da16c82531ae9837b07..3a44dcd3c0b21bd5afd1fac151405d6e0936f5d1 100644 (file)
@@ -2,6 +2,7 @@
 #include "buffer.h"
 #include "camera.h"
 #include "error.h"
+#include "lighting.h"
 #include "material.h"
 #include "program.h"
 #include "programdata.h"
@@ -71,6 +72,13 @@ void Renderer::set_material(const Material *m)
        state->material = m;
 }
 
+void Renderer::set_lighting(const Lighting *l)
+{
+       state->lighting = l;
+       state->lighting_matrix = mtx_stack.top();
+       lighting_changed = true;
+}
+
 void Renderer::set_shader_program(const Program *p, const ProgramData *d)
 {
        state->shprog = p;
@@ -166,7 +174,8 @@ void Renderer::draw(const Batch &batch)
 
 void Renderer::apply_state()
 {
-       // We let the objects themselves figure out if the binding has changed
+       /* We (mostly) let the objects themselves figure out if the binding has
+       changed */
 
        if(state->texturing)
                state->texturing->bind();
@@ -184,6 +193,19 @@ void Renderer::apply_state()
        else
                Material::unbind();
 
+       if(lighting_changed)
+       {
+               if(state->lighting)
+               {
+                       MatrixStack::modelview() = state->lighting_matrix;
+                       state->lighting->bind();
+                       mtx_changed = true;
+                       lighting_changed = false;
+               }
+               else
+                       Lighting::unbind();
+       }
+
        if(state->shprog)
        {
                state->shprog->bind();
@@ -214,6 +236,7 @@ Renderer::State::State():
        texture(0),
        texturing(0),
        material(0),
+       lighting(0),
        shprog(0),
        shdata_count(0),
        winding_test(0)