OpenGLRenderer: Fix FBO clearing when scissor is enabled

This commit is contained in:
Lynix 2022-11-06 15:31:55 +01:00
parent 45d4195527
commit 0133a91c4d
4 changed files with 28 additions and 3 deletions

View File

@ -29,6 +29,8 @@ namespace Nz
void Activate() const override;
inline const Vector2ui& GetAttachmentSize(std::size_t i) const;
std::size_t GetColorBufferCount() const override;
const Vector2ui& GetSize() const override;
@ -39,10 +41,11 @@ namespace Nz
private:
GL::Framebuffer m_framebuffer;
std::size_t m_colorAttachmentCount;
std::vector<Vector2ui> m_attachmentSizes;
Vector2ui m_size;
};
}
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.inl>
#endif // NAZARA_OPENGLRENDERER_OPENGLFBOFRAMEBUFFER_HPP

View File

@ -3,11 +3,14 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
inline const Vector2ui& OpenGLFboFramebuffer::GetAttachmentSize(std::size_t i) const
{
return m_attachmentSizes[i];
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@ -4,6 +4,7 @@
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
@ -172,6 +173,8 @@ namespace Nz
if (command.framebuffer->GetType() == FramebufferType::Texture)
{
const OpenGLFboFramebuffer& fboFramebuffer = static_cast<const OpenGLFboFramebuffer&>(*command.framebuffer);
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
@ -187,6 +190,11 @@ namespace Nz
if (attachmentInfo.loadOp == AttachmentLoadOp::Clear)
{
context->ResetColorWriteMasks();
// Reset scissor as it affects clear commands if enabled (disabling it would work too but it seems more expansive)
const Vector2ui& attachmentSize = fboFramebuffer.GetAttachmentSize(i);
context->SetScissorBox(0, 0, attachmentSize.x, attachmentSize.y);
context->glClearBufferfv(GL_COLOR, GLint(i), clearColor.data());
}
else if (attachmentInfo.loadOp == AttachmentLoadOp::Discard)
@ -199,6 +207,14 @@ namespace Nz
const auto& clearValues = command.clearValues[attachmentIndex];
const auto& depthStencilAttachment = command.renderpass->GetAttachment(attachmentIndex);
// Reset scissor as it affects clear commands if enabled (disabling it would work too but it seems more expansive)
if (depthStencilAttachment.loadOp == AttachmentLoadOp::Clear || depthStencilAttachment.stencilLoadOp == AttachmentLoadOp::Clear)
{
const Vector2ui& attachmentSize = fboFramebuffer.GetAttachmentSize(attachmentIndex);
context->SetScissorBox(0, 0, attachmentSize.x, attachmentSize.y);
}
if (depthStencilAttachment.loadOp == AttachmentLoadOp::Clear && depthStencilAttachment.stencilLoadOp == AttachmentLoadOp::Clear)
{
context->ResetDepthWriteMasks();
@ -287,9 +303,10 @@ namespace Nz
if (clearFields)
{
// Reset scissor as it affects clear commands if enabled (disabling it would work too but it seems more expansive)
const Vector2ui& size = command.framebuffer->GetSize();
context->SetScissorBox(0, 0, size.x, size.y);
context->SetViewport(0, 0, size.x, size.y);
context->glClear(clearFields);
}
}

View File

@ -20,12 +20,14 @@ namespace Nz
bool hasDepth = false;
bool hasStencil = false;
m_attachmentSizes.resize(attachments.size());
for (std::size_t i = 0; i < attachments.size(); ++i)
{
assert(attachments[i]);
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(*attachments[i]);
Vector2ui textureSize = Vector2ui(glTexture.GetSize());
m_attachmentSizes[i] = textureSize;
if (i == 0)
m_size = textureSize;