]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.cpp
Convert framebuffers and related functionality to new state management
[libs/gl.git] / source / core / pipelinestate.cpp
index 7a38eab5e4136a12e490e4bdcbb079872e181de1..167e7de05bfb0c629ba08327b72c5a7d3085317d 100644 (file)
@@ -9,8 +9,10 @@
 #include "buffer.h"
 #include "deviceinfo.h"
 #include "depthtest.h"
+#include "framebuffer.h"
 #include "pipelinestate.h"
 #include "program.h"
+#include "rect.h"
 #include "stenciltest.h"
 #include "texture.h"
 #include "uniformblock.h"
@@ -25,6 +27,9 @@ const PipelineState *PipelineState::last_applied = 0;
 vector<int> PipelineState::bound_tex_targets;
 
 PipelineState::PipelineState():
+       framebuffer(0),
+       viewport(0),
+       scissor(0),
        shprog(0),
        vertex_setup(0),
        front_face(COUNTERCLOCKWISE),
@@ -55,6 +60,21 @@ void PipelineState::set(T &target, T value, unsigned flag)
        }
 }
 
+void PipelineState::set_framebuffer(const Framebuffer *f)
+{
+       set(framebuffer, f, FRAMEBUFFER|VIEWPORT);
+}
+
+void PipelineState::set_viewport(const Rect *v)
+{
+       set(viewport, v, VIEWPORT);
+}
+
+void PipelineState::set_scissor(const Rect *s)
+{
+       set(scissor, s, SCISSOR);
+}
+
 void PipelineState::set_shader_program(const Program *p)
 {
        set(shprog, p, SHPROG);
@@ -142,6 +162,35 @@ void PipelineState::apply() const
 
 void PipelineState::apply(unsigned mask) const
 {
+       if(mask&FRAMEBUFFER)
+       {
+               glBindFramebuffer(GL_FRAMEBUFFER, framebuffer ? framebuffer->get_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->get_id() : 0);