]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/framebuffer.cpp
Remove the FramebufferStatus enum
[libs/gl.git] / source / core / framebuffer.cpp
index 97b5c8b1394e428bcc640339af98d58a68607462..ffd92a22f8329e05b2c604802d05467a3065f555 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gl/extensions/ext_texture3d.h>
 #include <msp/gl/extensions/msp_buffer_control.h>
 #include <msp/gl/extensions/khr_debug.h>
+#include <msp/strings/format.h>
 #include "error.h"
 #include "framebuffer.h"
 #include "misc.h"
@@ -18,54 +19,14 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-void operator<<(LexicalConverter &conv, FramebufferStatus status)
-{
-       switch(status)
-       {
-       case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
-               conv.result("incomplete attachment");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
-               conv.result("missing attachment");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
-               conv.result("mismatched attachment dimensions");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_FORMATS:
-               conv.result("mismatched attachment formats");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
-               conv.result("missing draw buffer attachment");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
-               conv.result("missing read buffer attachment");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
-               conv.result("mismatched attachment sample counts");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_LAYER_COUNT:
-               conv.result("mismatched attachment layer counts");
-               break;
-       case FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
-               conv.result("mismatched attachment layering");
-               break;
-       case FRAMEBUFFER_UNSUPPORTED:
-               conv.result("unsupported");
-               break;
-       default:
-               conv.result(lexical_cast<string, unsigned>(status, "%#x"));
-               break;
-       }
-}
-
-framebuffer_incomplete::framebuffer_incomplete(FramebufferStatus status):
-       runtime_error(lexical_cast<string>(status))
+framebuffer_incomplete::framebuffer_incomplete(const std::string &reason):
+       runtime_error(reason)
 { }
 
 
 Framebuffer::Framebuffer(unsigned i):
        id(i),
-       status(FRAMEBUFFER_COMPLETE),
+       status(GL_FRAMEBUFFER_COMPLETE),
        dirty(0)
 {
        if(id)
@@ -100,7 +61,7 @@ void Framebuffer::init()
 
        width = 0;
        height = 0;
-       status = FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
+       status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
        dirty = 0;
 
        if(ARB_direct_state_access)
@@ -192,9 +153,9 @@ void Framebuffer::update() const
        }
 
        if(ARB_direct_state_access)
-               status = static_cast<FramebufferStatus>(glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER));
+               status = glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER);
        else
-               status = static_cast<FramebufferStatus>(glCheckFramebufferStatus(GL_FRAMEBUFFER));
+               status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
 
        dirty = 0;
 }
@@ -326,8 +287,24 @@ void Framebuffer::resize(const WindowView &view)
 
 void Framebuffer::require_complete() const
 {
-       if(status!=FRAMEBUFFER_COMPLETE)
-               throw framebuffer_incomplete(status);
+       if(!id)
+               return;
+
+       bool layered = (!attachments.empty() && attachments.front().layer<0);
+       for(const Attachment &a: attachments)
+       {
+               if(!a.tex)
+                       throw framebuffer_incomplete("missing attachment");
+               if(layered!=(a.layer<0))
+                       throw framebuffer_incomplete("inconsistent layering");
+       }
+
+       if(status==GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
+               throw framebuffer_incomplete("incomplete or unsupported attachment");
+       if(status==GL_FRAMEBUFFER_UNSUPPORTED)
+               throw framebuffer_incomplete("unsupported configuration");
+       if(status!=GL_FRAMEBUFFER_COMPLETE)
+               throw framebuffer_incomplete(Msp::format("incomplete (%#x)", status));
 }
 
 void Framebuffer::set_debug_name(const string &name)