]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.cpp
Use default member initializers for simple types
[libs/gl.git] / source / core / pipelinestate.cpp
index 31bde278f44b9405a9cd6bad27c750a33babe80a..23a2ed6a96b9b61dfcabe7e044324da797773572 100644 (file)
@@ -1,61 +1,12 @@
 #include <stdexcept>
 #include <msp/core/algorithm.h>
-#include <msp/gl/extensions/arb_direct_state_access.h>
-#include <msp/gl/extensions/arb_sampler_objects.h>
-#include <msp/gl/extensions/arb_shader_objects.h>
-#include <msp/gl/extensions/arb_uniform_buffer_object.h>
-#include <msp/gl/extensions/arb_vertex_array_object.h>
-#include <msp/gl/extensions/msp_primitive_restart.h>
-#include "blend.h"
-#include "buffer.h"
-#include "deviceinfo.h"
-#include "depthtest.h"
-#include "framebuffer.h"
 #include "pipelinestate.h"
-#include "program.h"
-#include "rect.h"
-#include "sampler.h"
-#include "stenciltest.h"
-#include "texture.h"
-#include "uniformblock.h"
-#include "vertexsetup.h"
 
 using namespace std;
 
 namespace Msp {
 namespace GL {
 
-const PipelineState *PipelineState::last_applied = 0;
-vector<int> PipelineState::bound_tex_targets;
-vector<char> PipelineState::bound_uniform_blocks;
-unsigned PipelineState::restart_index = 0;
-
-PipelineState::PipelineState():
-       framebuffer(0),
-       viewport(0),
-       scissor(0),
-       shprog(0),
-       vertex_setup(0),
-       front_face(COUNTERCLOCKWISE),
-       face_cull(NO_CULL),
-       enabled_clip_planes(0),
-       depth_test(0),
-       stencil_test(0),
-       blend(0),
-       changes(0)
-{
-       if(bound_tex_targets.empty())
-               bound_tex_targets.resize(Limits::get_global().max_texture_bindings);
-       if(bound_uniform_blocks.empty())
-               bound_uniform_blocks.resize(Limits::get_global().max_uniform_bindings);
-}
-
-PipelineState::~PipelineState()
-{
-       if(this==last_applied)
-               last_applied = 0;
-}
-
 template<typename T>
 void PipelineState::set(T &target, T value, unsigned flag)
 {
@@ -68,7 +19,7 @@ void PipelineState::set(T &target, T value, unsigned flag)
 
 void PipelineState::set_framebuffer(const Framebuffer *f)
 {
-       set(framebuffer, f, FRAMEBUFFER|VIEWPORT);
+       set(framebuffer, f, FRAMEBUFFER);
 }
 
 void PipelineState::set_viewport(const Rect *v)
@@ -123,17 +74,7 @@ void PipelineState::set_texture(unsigned binding, const Texture *tex, const Samp
        }
 }
 
-void PipelineState::set_uniforms(const DefaultUniformBlock *block)
-{
-       set_uniform_block_(-1, block);
-}
-
-void PipelineState::set_uniform_block(unsigned binding, const BufferBackedUniformBlock *block)
-{
-       set_uniform_block_(binding, block);
-}
-
-void PipelineState::set_uniform_block_(int binding, const UniformBlock *block)
+void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
 {
        auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
        if(i==uniform_blocks.end() || i->binding!=binding)
@@ -161,222 +102,6 @@ void PipelineState::set_blend(const Blend *b)
        set(blend, b, BLEND);
 }
 
-void PipelineState::apply() const
-{
-       if(!last_applied)
-               Texture::unbind_scratch();
-
-       apply(this==last_applied ? changes : ~0U);
-}
-
-void PipelineState::apply(unsigned mask) const
-{
-       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 = Limits::get_global().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.changed = false;
-                       }
-       }
-
-       if(mask&UNIFORMS)
-       {
-               for(const BoundUniformBlock &u: uniform_blocks)
-                       if(u.changed || mask==~0U)
-                       {
-                               if(u.block)
-                               {
-                                       if(u.binding>=0)
-                                       {
-                                               const BufferBackedUniformBlock *block = static_cast<const BufferBackedUniformBlock *>(u.block);
-                                               glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, block->get_buffer()->id, block->get_offset(), block->get_data_size());
-                                               bound_uniform_blocks[u.binding] = 1;
-                                       }
-                                       else
-                                               static_cast<const DefaultUniformBlock *>(u.block)->apply();
-                               }
-
-                               u.changed = false;
-                       }
-       }
-
-       if(mask&DEPTH_TEST)
-       {
-               if(depth_test && depth_test->enabled)
-               {
-                       glEnable(GL_DEPTH_TEST);
-                       glDepthFunc(get_gl_predicate(depth_test->compare));
-               }
-               else
-                       glDisable(GL_DEPTH_TEST);
-
-               glDepthMask(!depth_test || depth_test->write);
-       }
-
-       if(mask&STENCIL_TEST)
-       {
-               if(stencil_test && stencil_test->enabled)
-               {
-                       glEnable(GL_STENCIL_TEST);
-                       glStencilFunc(get_gl_predicate(stencil_test->compare), stencil_test->reference, 0xFFFFFFFF);
-                       glStencilOp(get_gl_stencil_op(stencil_test->stencil_fail_op), get_gl_stencil_op(stencil_test->depth_fail_op), get_gl_stencil_op(stencil_test->depth_pass_op));
-               }
-               else
-                       glDisable(GL_STENCIL_TEST);
-       }
-
-       if(mask&BLEND)
-       {
-               if(blend && blend->enabled)
-               {
-                       glEnable(GL_BLEND);
-                       glBlendEquation(get_gl_blend_equation(blend->equation));
-                       glBlendFunc(get_gl_blend_factor(blend->src_factor), get_gl_blend_factor(blend->dst_factor));
-                       glBlendColor(blend->constant.r, blend->constant.g, blend->constant.b, blend->constant.a);
-               }
-               else
-                       glDisable(GL_BLEND);
-       }
-
-       last_applied = this;
-       changes &= ~mask;
-}
-
-void PipelineState::clear()
-{
-       if(last_applied)
-       {
-               glUseProgram(0);
-               glBindVertexArray(0);
-
-               unsigned max_clip_planes = Limits::get_global().max_clip_planes;
-               for(unsigned i=0; i<max_clip_planes; ++i)
-                       if((last_applied->enabled_clip_planes>>i)&1)
-                               glDisable(GL_CLIP_PLANE0+i);
-
-               for(unsigned i=0; i<bound_tex_targets.size(); ++i)
-                       if(bound_tex_targets[i])
-                       {
-                               if(ARB_direct_state_access)
-                                       glBindTextureUnit(i, 0);
-                               else
-                               {
-                                       glActiveTexture(GL_TEXTURE0+i);
-                                       glBindTexture(bound_tex_targets[i], 0);
-                               }
-                               bound_tex_targets[i] = 0;
-                       }
-
-               for(unsigned i=0; i<bound_uniform_blocks.size(); ++i)
-                       if(bound_uniform_blocks[i])
-                       {
-                               glBindBufferBase(GL_UNIFORM_BUFFER, i, 0);
-                               bound_uniform_blocks[i] = 0;
-                       }
-
-               glDisable(GL_DEPTH_TEST);
-               glDepthMask(true);
-               glDisable(GL_STENCIL_TEST);
-               glDisable(GL_BLEND);
-
-               last_applied = 0;
-       }
-}
-
 
 PipelineState::BoundTexture::BoundTexture(unsigned b):
        binding(b),