{
Bind bind_depth_test(i->get_depth_test());
Bind bind_blend(i->get_blend());
- Bind bind_lighting(i->get_lighting());
+ renderer.set_lighting(i->get_lighting());
for(vector<Slot>::const_iterator j=renderables.begin(); j!=renderables.end(); ++j)
if(j->passes.empty() || j->passes.count(i->get_tag()))
#include "buffer.h"
#include "camera.h"
#include "error.h"
+#include "lighting.h"
#include "material.h"
#include "program.h"
#include "programdata.h"
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;
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();
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();
texture(0),
texturing(0),
material(0),
+ lighting(0),
shprog(0),
shdata_count(0),
winding_test(0)
class Buffer;
class Camera;
class Material;
+class Lighting;
class Program;
class ProgramData;
class Renderable;
const Texture *texture;
const Texturing *texturing;
const Material *material;
+ const Lighting *lighting;
+ Matrix lighting_matrix;
const Program *shprog;
unsigned shdata_count;
const WindingTest *winding_test;
+ bool reverse_winding;
State();
};
const Camera *camera;
std::vector<State> state_stack;
State *state;
+ bool lighting_changed;
std::vector<const ProgramData *> shdata_stack;
bool shdata_changed;
const VertexArray *vertex_array;
void set_texturing(const Texturing *);
void set_material(const Material *);
+ void set_lighting(const Lighting *);
+
/** 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);