OpenGLRenderer: Setup draw buffers only once
This commit is contained in:
parent
8eed1161e5
commit
ccf77ac459
|
|
@ -24,6 +24,7 @@ namespace Nz::GL
|
||||||
|
|
||||||
inline GLenum Check() const;
|
inline GLenum Check() const;
|
||||||
|
|
||||||
|
inline void DrawBuffers(GLsizei n, const GLenum* bufs);
|
||||||
inline void Renderbuffer(GLenum attachment, GLenum renderbuffer);
|
inline void Renderbuffer(GLenum attachment, GLenum renderbuffer);
|
||||||
inline void Texture2D(GLenum attachment, GLenum textarget, GLuint texture, GLint level = 0);
|
inline void Texture2D(GLenum attachment, GLenum textarget, GLuint texture, GLint level = 0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,15 @@ namespace Nz::GL
|
||||||
return context.glCheckFramebufferStatus(target);
|
return context.glCheckFramebufferStatus(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Framebuffer::DrawBuffers(GLsizei n, const GLenum* bufs)
|
||||||
|
{
|
||||||
|
assert(m_objectId);
|
||||||
|
|
||||||
|
const Context& context = EnsureContext();
|
||||||
|
context.BindFramebuffer(FramebufferTarget::Draw, m_objectId);
|
||||||
|
context.glDrawBuffers(n, bufs);
|
||||||
|
}
|
||||||
|
|
||||||
inline void Framebuffer::Renderbuffer(GLenum attachment, GLenum renderbuffer)
|
inline void Framebuffer::Renderbuffer(GLenum attachment, GLenum renderbuffer)
|
||||||
{
|
{
|
||||||
assert(m_objectId);
|
assert(m_objectId);
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,6 @@ namespace Nz
|
||||||
{
|
{
|
||||||
const GL::Context* context = GL::Context::GetCurrentContext();
|
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);
|
StackArray<std::size_t> colorIndexes = NazaraStackArrayNoInit(std::size_t, m_maxColorBufferCount);
|
||||||
|
|
||||||
for (const auto& commandVariant : m_commands)
|
for (const auto& commandVariant : m_commands)
|
||||||
|
|
@ -129,7 +125,7 @@ namespace Nz
|
||||||
context = GL::Context::GetCurrentContext();
|
context = GL::Context::GetCurrentContext();
|
||||||
|
|
||||||
std::size_t colorBufferCount = command.framebuffer->GetColorBufferCount();
|
std::size_t colorBufferCount = command.framebuffer->GetColorBufferCount();
|
||||||
assert(colorBufferCount <= fboDrawBuffers.size());
|
assert(colorBufferCount <= colorIndexes.size());
|
||||||
|
|
||||||
colorIndexes.fill(0);
|
colorIndexes.fill(0);
|
||||||
std::size_t colorIndex = 0;
|
std::size_t colorIndex = 0;
|
||||||
|
|
@ -175,8 +171,6 @@ namespace Nz
|
||||||
{
|
{
|
||||||
const OpenGLFboFramebuffer& fboFramebuffer = static_cast<const OpenGLFboFramebuffer&>(*command.framebuffer);
|
const OpenGLFboFramebuffer& fboFramebuffer = static_cast<const OpenGLFboFramebuffer&>(*command.framebuffer);
|
||||||
|
|
||||||
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
|
|
||||||
|
|
||||||
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
|
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < colorBufferCount; ++i)
|
for (std::size_t i = 0; i < colorBufferCount; ++i)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
|
||||||
|
#include <Nazara/Utils/StackArray.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -85,6 +86,20 @@ namespace Nz
|
||||||
throw std::runtime_error("invalid framebuffer: 0x" + NumberToString(status, 16));
|
throw std::runtime_error("invalid framebuffer: 0x" + NumberToString(status, 16));
|
||||||
|
|
||||||
m_colorAttachmentCount = colorAttachmentCount;
|
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
|
void OpenGLFboFramebuffer::Activate() const
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue