From fc55a95ad69fbaaefde3071712bf36a470970bc0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 Sep 2021 13:36:23 +0300 Subject: [PATCH] Remove the FramebufferStatus enum It's not easily supportable on Vulkan. --- source/core/framebuffer.cpp | 73 +++++++++++++------------------------ source/core/framebuffer.h | 23 +----------- 2 files changed, 27 insertions(+), 69 deletions(-) diff --git a/source/core/framebuffer.cpp b/source/core/framebuffer.cpp index 97b5c8b1..ffd92a22 100644 --- a/source/core/framebuffer.cpp +++ b/source/core/framebuffer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #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(status, "%#x")); - break; - } -} - -framebuffer_incomplete::framebuffer_incomplete(FramebufferStatus status): - runtime_error(lexical_cast(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(glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER)); + status = glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER); else - status = static_cast(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) diff --git a/source/core/framebuffer.h b/source/core/framebuffer.h index 2f867e6c..acb0d3ee 100644 --- a/source/core/framebuffer.h +++ b/source/core/framebuffer.h @@ -19,21 +19,6 @@ class Texture2DMultisample; class Texture3D; class WindowView; -enum FramebufferStatus -{ - FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, - FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, - FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT, - FRAMEBUFFER_INCOMPLETE_FORMATS = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT, - FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER, - FRAMEBUFFER_INCOMPLETE_READ_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER, - FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, - FRAMEBUFFER_INCOMPLETE_LAYER_COUNT = GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB, - FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS, - FRAMEBUFFER_UNSUPPORTED = GL_FRAMEBUFFER_UNSUPPORTED, - FRAMEBUFFER_COMPLETE = GL_FRAMEBUFFER_COMPLETE -}; - enum BufferBits { COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT, @@ -44,7 +29,7 @@ enum BufferBits class framebuffer_incomplete: public std::runtime_error { public: - framebuffer_incomplete(FramebufferStatus); + framebuffer_incomplete(const std::string &); virtual ~framebuffer_incomplete() throw() { } }; @@ -82,7 +67,7 @@ private: std::vector attachments; unsigned width; unsigned height; - mutable FramebufferStatus status; + mutable unsigned status; mutable unsigned dirty; Framebuffer(unsigned); @@ -132,10 +117,6 @@ public: void resize(const WindowView &); - /** Returns FRAMEBUFFER_COMPLETE if the framebuffer is complete and can be - rendered to, or one of the error status codes otherwise. */ - FramebufferStatus get_status() const { return status; } - /** Ensures that the framebuffer is complete, throwing an exception if it isn't. */ void require_complete() const; -- 2.45.2