Renderer::Renderer(const Camera *c):
mtx_stack(*this),
- mtx_changed(true),
+ changed(MATRIX),
matrices_loaded(false),
camera(c),
state_stack(1),
- lighting_changed(false),
element_buffer(0)
{
state_stack.reserve(16);
state->lighting_matrix = mtx_stack.top();
if(l)
l->update_shader_data(standard_shdata, mtx_stack.top());
- lighting_changed = true;
+ changed |= LIGHTING;
}
void Renderer::set_shader_program(const Program *p, const ProgramData *d)
{
shdata_stack.push_back(&d);
state->shdata_count = shdata_stack.size();
- shdata_changed = true;
+ changed |= SHADER_DATA;
}
void Renderer::set_mesh(const Mesh *m)
if(shdata_stack.size()>state->shdata_count)
shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end());
mtx_stack.pop();
- mtx_changed = true;
- shdata_changed = true;
+ changed |= MATRIX|SHADER_DATA;
}
void Renderer::escape()
else
Material::unbind();
- if(lighting_changed)
+ if(changed&LIGHTING)
{
if(state->lighting)
{
MatrixStack::modelview() = state->lighting_matrix;
state->lighting->bind();
- mtx_changed = true;
- lighting_changed = false;
+ changed = (changed&~LIGHTING)|MATRIX;
}
else
Lighting::unbind();
standard_shdata.apply();
}
- if(shdata_changed)
+ if(changed&SHADER_DATA)
{
for(vector<const ProgramData *>::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i)
(*i)->apply();
- shdata_changed = false;
+ changed &= ~SHADER_DATA;
}
}
else
matrices_loaded = true;
}
- if(mtx_changed)
+ if(changed&MATRIX)
{
MatrixStack::modelview() = mtx_stack.top();
- mtx_changed = false;
+ changed &= ~MATRIX;
}
}
}
void Renderer::MtxStack::update()
{
- renderer.mtx_changed = true;
+ renderer.changed |= MATRIX;
}
} // namespace GL
virtual void update();
};
+ enum ChangeMask
+ {
+ MATRIX = 1,
+ LIGHTING = 4,
+ SHADER_DATA = 8
+ };
+
MtxStack mtx_stack;
- bool mtx_changed;
+ unsigned char changed;
bool matrices_loaded;
const Camera *camera;
std::vector<State> state_stack;
State *state;
- bool lighting_changed;
ProgramData standard_shdata;
std::vector<const ProgramData *> shdata_stack;
- bool shdata_changed;
const Buffer *element_buffer;
std::set<const Renderable *> excluded;