- for(vector<BoundTexture>::const_iterator i=texture_stack.begin(); i!=texture_stack.end(); ++i)
- {
- int unit = (i->tag.id ? state->shprog->get_uniform_binding(i->tag) : i->unit);
- if(unit>=0)
- pipeline_state.set_texture(unit, i->texture, i->sampler);
- }
+ PipelineState &ps = get_pipeline_state();
+
+ ps.set_framebuffer(state.framebuffer);
+ static const Rect default_rect = Rect::max();
+ ps.set_viewport(state.viewport ? *state.viewport : default_rect);
+ ps.set_scissor(state.scissor ? *state.scissor : default_rect);
+}
+
+void Renderer::apply_state()
+{
+ State &state = get_state();
+
+ if(!state.shprog)
+ throw invalid_operation("Renderer::apply_state");
+
+ apply_framebuffer();
+
+ PipelineState &ps = get_pipeline_state();
+ bool pipeline_changed = (&ps!=last_pipeline);
+ last_pipeline = &ps;
+
+ bool shprog_changed = (state.shprog!=ps.get_shader_program());
+ ps.set_shader_program(state.shprog);