]> git.tdb.fi Git - libs/gl.git/commitdiff
Query the attachments of the default framebuffer
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Sep 2021 11:04:02 +0000 (14:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Sep 2021 11:04:02 +0000 (14:04 +0300)
The exact pixel formats are unimportant for now and would be somewhat
convoluted to query.

source/core/framebuffer.cpp

index 1dd2f61f9bab10139772b8619075370df41b2849..01a4107494387cac61ce8c46e90dd7234e07d5b4 100644 (file)
@@ -34,6 +34,24 @@ Framebuffer::Framebuffer(unsigned i):
        if(id)
                throw invalid_argument("System framebuffer must have id 0");
 
+       if(EXT_framebuffer_object)
+       {
+               int value;
+               glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &value);
+               if(value==GL_NONE)
+                       glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &value);
+               if(value!=GL_NONE)
+                       format = (format,COLOR_ATTACHMENT);
+
+               glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &value);
+               if(value!=GL_NONE)
+                       format = (format,DEPTH_ATTACHMENT);
+
+               glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &value);
+               if(value!=GL_NONE)
+                       format = (format,STENCIL_ATTACHMENT);
+       }
+
        int view[4];
        glGetIntegerv(GL_VIEWPORT, view);
        width = view[2];
@@ -80,7 +98,7 @@ Framebuffer::~Framebuffer()
 
 void Framebuffer::set_format(const FrameFormat &fmt)
 {
-       if(!format.empty())
+       if(!format.empty() || !id)
                throw invalid_operation("Framebuffer::set_format");
        if(fmt.empty())
                throw invalid_argument("Framebuffer::set_format");