OpenGLRenderer: Setup draw buffers only once

This commit is contained in:
SirLynix
2022-12-06 07:49:41 +01:00
parent 8eed1161e5
commit ccf77ac459
4 changed files with 26 additions and 7 deletions

View File

@@ -61,10 +61,6 @@ namespace Nz
{
const GL::Context* context = GL::Context::GetCurrentContext();
StackArray<GLenum> fboDrawBuffers = NazaraStackArrayNoInit(GLenum, m_maxColorBufferCount);
for (std::size_t i = 0; i < m_maxColorBufferCount; ++i)
fboDrawBuffers[i] = GLenum(GL_COLOR_ATTACHMENT0 + i);
StackArray<std::size_t> colorIndexes = NazaraStackArrayNoInit(std::size_t, m_maxColorBufferCount);
for (const auto& commandVariant : m_commands)
@@ -129,7 +125,7 @@ namespace Nz
context = GL::Context::GetCurrentContext();
std::size_t colorBufferCount = command.framebuffer->GetColorBufferCount();
assert(colorBufferCount <= fboDrawBuffers.size());
assert(colorBufferCount <= colorIndexes.size());
colorIndexes.fill(0);
std::size_t colorIndex = 0;
@@ -175,8 +171,6 @@ namespace Nz
{
const OpenGLFboFramebuffer& fboFramebuffer = static_cast<const OpenGLFboFramebuffer&>(*command.framebuffer);
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
for (std::size_t i = 0; i < colorBufferCount; ++i)

View File

@@ -5,6 +5,7 @@
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>
@@ -85,6 +86,20 @@ namespace Nz
throw std::runtime_error("invalid framebuffer: 0x" + NumberToString(status, 16));
m_colorAttachmentCount = colorAttachmentCount;
if (m_colorAttachmentCount > 0)
{
StackArray<GLenum> fboDrawBuffers = NazaraStackArrayNoInit(GLenum, m_colorAttachmentCount);
for (std::size_t i = 0; i < m_colorAttachmentCount; ++i)
fboDrawBuffers[i] = GLenum(GL_COLOR_ATTACHMENT0 + i);
m_framebuffer.DrawBuffers(SafeCast<GLsizei>(m_colorAttachmentCount), fboDrawBuffers.data());
}
else
{
GLenum buffer = GL_NONE;
m_framebuffer.DrawBuffers(1, &buffer);
}
}
void OpenGLFboFramebuffer::Activate() const