]> git.tdb.fi Git - libs/gl.git/commitdiff
Set all color attachments of a Framebuffer as draw buffers
authorMikko Rasa <tdb@tdb.fi>
Tue, 11 Sep 2012 20:29:22 +0000 (23:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 11 Sep 2012 20:29:22 +0000 (23:29 +0300)
Indexing gl_FragData selects from the active draw buffers, so this is
required for multiple fragment shader outputs.

source/arb_draw_buffers.cpp [new file with mode: 0644]
source/arb_draw_buffers.h [new file with mode: 0644]
source/framebuffer.cpp

diff --git a/source/arb_draw_buffers.cpp b/source/arb_draw_buffers.cpp
new file mode 100644 (file)
index 0000000..5f84349
--- /dev/null
@@ -0,0 +1,26 @@
+#include "arb_draw_buffers.h"
+
+namespace Msp {
+namespace GL {
+
+PFNGLDRAWBUFFERSPROC glDrawBuffers = 0;
+
+Extension::SupportLevel init_arb_draw_buffers()
+{
+       if(is_version_at_least(2, 0))
+       {
+               glDrawBuffers = reinterpret_cast<PFNGLDRAWBUFFERSPROC>(get_proc_address("glDrawBuffers"));
+               return Extension::CORE;
+       }
+       if(is_supported("GL_ARB_draw_buffers"))
+       {
+               glDrawBuffers = reinterpret_cast<PFNGLDRAWBUFFERSPROC>(get_proc_address("glDrawBuffersARB"));
+               return Extension::EXTENSION;
+       }
+       return Extension::UNSUPPORTED;
+}
+
+Extension ARB_draw_buffers("GL_ARB_draw_buffers", init_arb_draw_buffers);
+
+} // namespace GL
+} // namespace Msp
diff --git a/source/arb_draw_buffers.h b/source/arb_draw_buffers.h
new file mode 100644 (file)
index 0000000..cd2c71b
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef MSP_GL_ARB_DRAW_BUFFERS_
+#define MSP_GL_ARB_DRAW_BUFFERS_
+
+#include "extension.h"
+#include "gl.h"
+#include <GL/glext.h>
+
+namespace Msp {
+namespace GL {
+
+extern PFNGLDRAWBUFFERSPROC glDrawBuffers;
+
+extern Extension ARB_draw_buffers;
+
+} // namespace GL
+} // namespace Msp
+
+#endif
index 43b0f94b82e4c882327ef686491453a1bc7cf263..98722195e32e8b10d40a43ab3d458d4c1ae5f4af 100644 (file)
@@ -1,3 +1,4 @@
+#include "arb_draw_buffers.h"
 #include "error.h"
 #include "ext_framebuffer_blit.h"
 #include "ext_framebuffer_object.h"
@@ -46,7 +47,8 @@ void Framebuffer::update_attachment(unsigned mask) const
 {
        if(current()==this)
        {
-               GLenum color_buf = GL_NONE;
+               std::vector<GLenum> color_bufs;
+               color_bufs.reserve(attachments.size());
                for(unsigned i=0; i<attachments.size(); ++i)
                {
                        const Attachment &attch = attachments[i];
@@ -69,10 +71,18 @@ void Framebuffer::update_attachment(unsigned mask) const
                        }
 
                        if(attch.attachment>=COLOR_ATTACHMENT0 && attch.attachment<=COLOR_ATTACHMENT3)
-                               color_buf = attch.attachment;
+                               color_bufs.push_back(attch.attachment);
                }
 
-               glDrawBuffer(color_buf);
+               if(color_bufs.empty())
+                       glDrawBuffer(GL_NONE);
+               else if(color_bufs.size()==1)
+                       glDrawBuffer(color_bufs.front());
+               else
+               {
+                       static Require _req(ARB_draw_buffers);
+                       glDrawBuffers(color_bufs.size(), &color_bufs[0]);
+               }
        }
        else
                dirty |= mask;