GL::Bind bind_depth(GL::DepthTest::lequal());
GL::Renderer renderer(0);
renderer.set_material(&material);
- renderer.set_shader(&shprog, &shdata);
+ renderer.set_shader_program(&shprog, &shdata);
renderer.set_texture(&texture);
renderer.matrix_stack() *= GL::Matrix::translation(0, 0, -7);
{
GL::Renderer renderer(0);
renderer.set_material(&mat);
renderer.set_texturing(&texturing);
+ renderer.add_shader_data(progdata);
for(unsigned i=0; i<12; ++i)
{
GL::MatrixStack::Push push(renderer.matrix_stack());
- renderer.set_shader(programs[i], &progdata);
+ renderer.set_shader_program(programs[i]);
renderer.matrix_stack() *= GL::Matrix::translation(-3.3+(i%4)*2.2, 0, -3.5+(i/4)*3.0);
renderer.matrix_stack() *= GL::Matrix::rotation(angle, 0, 0, 1);
mesh.draw(renderer);
{
renderer.matrix_stack() *= matrix;
if(shdata)
- renderer.add_shader_data(shdata);
+ renderer.add_shader_data(*shdata);
}
} // namespace GL
return;
Renderer::Push push(renderer);
- renderer.set_shader(pass->get_shader_program(), pass->get_shader_data());
+ renderer.set_shader_program(pass->get_shader_program(), pass->get_shader_data());
renderer.set_material(pass->get_material());
renderer.set_texturing(pass->get_texturing());
return;
Renderer::Push push(renderer);
- renderer.set_shader(pass->get_shader_program(), pass->get_shader_data());
+ renderer.set_shader_program(pass->get_shader_program(), pass->get_shader_data());
renderer.set_material(pass->get_material());
renderer.set_texturing(pass->get_texturing());
state->material = m;
}
-void Renderer::set_shader(const Program *p, const ProgramData *d)
+void Renderer::set_shader_program(const Program *p, const ProgramData *d)
{
state->shprog = p;
- if(d)
- state->shdata.assign(1, d);
- else
- state->shdata.clear();
+ if(p && d)
+ add_shader_data(*d);
shdata_changed = true;
}
-void Renderer::add_shader_data(const ProgramData *d)
+void Renderer::add_shader_data(const ProgramData &d)
{
- if(!state->shprog)
- throw invalid_operation("Renderer::add_shader_data");
-
- state->shdata.push_back(d);
+ state->shdata.push_back(&d);
shdata_changed = true;
}
void set_texture(const Texture *);
void set_texturing(const Texturing *);
void set_material(const Material *);
- void set_shader(const Program *, const ProgramData *);
- void add_shader_data(const ProgramData *);
+
+ /** 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);
+
+ /** Adds another set of data to be use with shader programs. The data is
+ independent of any shader program changes and remains in effect until the
+ Renderer state is popped. */
+ void add_shader_data(const ProgramData &data);
+
void set_vertex_array(const VertexArray *);
void set_element_buffer(const Buffer *);
void set_winding_test(const WindingTest *);