X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frenderer.cpp;h=3a44dcd3c0b21bd5afd1fac151405d6e0936f5d1;hb=31f4e9f522ba3009cfa74467bec380a263eabf73;hp=442728135274576129ff0da16c82531ae9837b07;hpb=d108cd5fc13aca16e38b54c1946c65797a869073;p=libs%2Fgl.git diff --git a/source/renderer.cpp b/source/renderer.cpp index 44272813..3a44dcd3 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -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)