X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frenderer.cpp;h=31d9621ef89195688ed0febaed9e9cbc67d12169;hb=9cf5d10abe5bdff0708c41544f6e8b15aca5151f;hp=442728135274576129ff0da16c82531ae9837b07;hpb=d108cd5fc13aca16e38b54c1946c65797a869073;p=libs%2Fgl.git diff --git a/source/renderer.cpp b/source/renderer.cpp index 44272813..31d9621e 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; @@ -104,6 +112,11 @@ void Renderer::set_winding_test(const WindingTest *w) state->winding_test = w; } +void Renderer::set_reverse_winding(bool r) +{ + state->reverse_winding = r; +} + void Renderer::push_state() { state_stack.push_back(state_stack.back()); @@ -166,7 +179,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 +198,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(); @@ -198,7 +225,12 @@ void Renderer::apply_state() Program::unbind(); if(state->winding_test) - state->winding_test->bind(); + { + if(state->reverse_winding) + state->winding_test->get_reverse().bind(); + else + state->winding_test->bind(); + } else WindingTest::unbind(); @@ -214,6 +246,7 @@ Renderer::State::State(): texture(0), texturing(0), material(0), + lighting(0), shprog(0), shdata_count(0), winding_test(0)