From: Mikko Rasa Date: Tue, 11 Sep 2012 20:29:22 +0000 (+0300) Subject: Set all color attachments of a Framebuffer as draw buffers X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e1df3aa732d4d2d03f6ac72a8dead099937a0468;p=libs%2Fgl.git Set all color attachments of a Framebuffer as draw buffers Indexing gl_FragData selects from the active draw buffers, so this is required for multiple fragment shader outputs. --- diff --git a/source/arb_draw_buffers.cpp b/source/arb_draw_buffers.cpp new file mode 100644 index 00000000..5f843498 --- /dev/null +++ b/source/arb_draw_buffers.cpp @@ -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(get_proc_address("glDrawBuffers")); + return Extension::CORE; + } + if(is_supported("GL_ARB_draw_buffers")) + { + glDrawBuffers = reinterpret_cast(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 index 00000000..cd2c71bc --- /dev/null +++ b/source/arb_draw_buffers.h @@ -0,0 +1,18 @@ +#ifndef MSP_GL_ARB_DRAW_BUFFERS_ +#define MSP_GL_ARB_DRAW_BUFFERS_ + +#include "extension.h" +#include "gl.h" +#include + +namespace Msp { +namespace GL { + +extern PFNGLDRAWBUFFERSPROC glDrawBuffers; + +extern Extension ARB_draw_buffers; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 43b0f94b..98722195 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -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 color_bufs; + color_bufs.reserve(attachments.size()); for(unsigned i=0; i=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;