+ pipeline_state.set_framebuffer(state->framebuffer);
+ pipeline_state.set_viewport(state->viewport);
+ pipeline_state.set_scissor(state->scissor);
+
+ bool shprog_changed = (state->shprog!=pipeline_state.get_shader_program());
+ pipeline_state.set_shader_program(state->shprog);
+
+ if(state->vertex_setup)
+ {
+ if(const VertexArray *array = state->vertex_setup->get_vertex_array())
+ array->refresh();
+ if(const VertexArray *array = state->vertex_setup->get_instance_array())
+ array->refresh();
+ }
+ pipeline_state.set_vertex_setup(state->vertex_setup);
+
+ pipeline_state.set_front_face(state->front_face);
+ pipeline_state.set_face_cull(state->face_cull);
+ pipeline_state.set_enabled_clip_planes(state->clipping ? (1<<state->clipping->get_n_planes())-1 : 0);
+
+ if(state->texture_count<texture_stack.size())
+ flush_textures();
+
+ 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);
+ }
+