- if(state->camera && ((changed&CAMERA_SHDATA) || shprog_changed))
- {
- state->camera->get_shader_data().apply();
- changed &= ~CAMERA_SHDATA;
- }
+ 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);
+
+ bool shdata_changed = changed&SHADER_DATA;
+ for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
+ shdata_changed = (i->shdata->get_generation()!=i->generation);
+ bool extra_shdata = (shdata_stack.size()>state.shdata_count);