From 3a8f48504dcee021729aac0d79bab25b3ab84091 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 3 Aug 2017 12:09:38 -0400 Subject: [PATCH] opengl: Fix multiple render target setup with glDrawBuffers --- src/backend/opengl/CommandBufferGL.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/backend/opengl/CommandBufferGL.cpp b/src/backend/opengl/CommandBufferGL.cpp index 5894266b22..00c04f092a 100644 --- a/src/backend/opengl/CommandBufferGL.cpp +++ b/src/backend/opengl/CommandBufferGL.cpp @@ -106,15 +106,22 @@ namespace opengl { const auto& info = currentRenderPass->GetSubpassInfo(currentSubpass); - for (uint32_t index = 0; index < info.colorAttachments.size(); ++index) { - uint32_t attachment = info.colorAttachments[index]; + std::array drawBuffers; + drawBuffers.fill(GL_NONE); + unsigned int attachmentCount = 0; + for (unsigned int attachmentSlot : IterateBitSet(info.colorAttachmentsSet)) { + uint32_t attachment = info.colorAttachments[attachmentSlot]; auto textureView = currentFramebuffer->GetTextureView(attachment); GLuint texture = ToBackend(textureView->GetTexture())->GetHandle(); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0 + index, - GL_TEXTURE_2D, texture, 0); + GL_COLOR_ATTACHMENT0 + attachmentSlot, + GL_TEXTURE_2D, texture, 0); + drawBuffers[attachmentSlot] = GL_COLOR_ATTACHMENT0 + attachmentSlot; + attachmentCount = attachmentSlot + 1; } + glDrawBuffers(attachmentCount, &drawBuffers[0]); + if (info.depthStencilAttachmentSet) { uint32_t attachment = info.depthStencilAttachment;