- if(mask&FRAMEBUFFER)
- {
- glBindFramebuffer(GL_FRAMEBUFFER, framebuffer ? framebuffer->id : 0);
- if(framebuffer)
- {
- framebuffer->refresh();
- framebuffer->require_complete();
- }
- }
-
- if(mask&VIEWPORT)
- {
- if(viewport)
- glViewport(viewport->left, viewport->bottom, viewport->width, viewport->height);
- else if(framebuffer)
- glViewport(0, 0, framebuffer->get_width(), framebuffer->get_height());
- }
-
- if(mask&SCISSOR)
- {
- if(scissor)
- {
- glEnable(GL_SCISSOR_TEST);
- glScissor(scissor->left, scissor->bottom, scissor->width, scissor->height);
- }
- else
- glDisable(GL_SCISSOR_TEST);
- }
-
- if(mask&SHPROG)
- glUseProgram(shprog ? shprog->id : 0);
-
- if(mask&VERTEX_SETUP)
- {
- glBindVertexArray(vertex_setup ? vertex_setup->id : 0);
- if(vertex_setup)
- {
- static Require _req(MSP_primitive_restart);
-
- vertex_setup->refresh();
- unsigned ri = (vertex_setup->get_index_type()==UNSIGNED_INT ? 0xFFFFFFFF : 0xFFFF);
- if(ri!=restart_index)
- {
- if(!restart_index)
- glEnable(GL_PRIMITIVE_RESTART);
- glPrimitiveRestartIndex(ri);
- restart_index = ri;
- }
- }
- }
-
- if(mask&FACE_CULL)
- {
- glFrontFace(front_face==CLOCKWISE ? GL_CW : GL_CCW);
-
- if(face_cull!=NO_CULL && front_face!=NON_MANIFOLD)
- {
- glEnable(GL_CULL_FACE);
- glCullFace(face_cull==CULL_FRONT ? GL_FRONT : GL_BACK);
- }
- else
- glDisable(GL_CULL_FACE);
- }
-
- if(mask&CLIP_PLANES)
- {
- unsigned max_clip_planes = DeviceInfo::get_global().limits.max_clip_planes;
- for(unsigned i=0; i<max_clip_planes; ++i)
- {
- if((enabled_clip_planes>>i)&1)
- glEnable(GL_CLIP_PLANE0+i);
- else
- glDisable(GL_CLIP_PLANE0+i);
- }
- }
-
- if(mask&TEXTURES)
- {
- for(const BoundTexture &t: textures)
- if(t.changed || mask==~0U)
- {
- if(t.texture && t.sampler)
- {
- if(ARB_direct_state_access)
- glBindTextureUnit(t.binding, t.texture->id);
- else
- {
- glActiveTexture(GL_TEXTURE0+t.binding);
- if(bound_tex_targets[t.binding] && static_cast<int>(t.texture->target)!=bound_tex_targets[t.binding])
- glBindTexture(bound_tex_targets[t.binding], 0);
- glBindTexture(t.texture->target, t.texture->id);
- }
-
- bound_tex_targets[t.binding] = t.texture->target;
-
- glBindSampler(t.binding, t.sampler->id);
- t.sampler->refresh();
- }
-
- t.changed = false;
- }
- }
-
- if(mask&UNIFORMS)
- {
- for(const BoundUniformBlock &u: uniform_blocks)
- if(u.changed || mask==~0U)
- {
- if(u.block)
- {
- if(u.binding>=0)
- {
- glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, u.block->get_buffer()->id, u.block->get_offset(), u.block->get_data_size());
- bound_uniform_blocks[u.binding] = 1;
- }
- else if(shprog)
- {
- const char *data = static_cast<const char *>(u.block->get_data_pointer());
- for(const Program::UniformCall &call: shprog->uniform_calls)
- call.func(call.location, call.size, data+call.location*16);
- }
- }