diff --git a/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp b/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp index ced3f8922..0a840a8bf 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp @@ -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 m_attachmentSizes; Vector2ui m_size; }; } -#include +#include #endif // NAZARA_OPENGLRENDERER_OPENGLFBOFRAMEBUFFER_HPP diff --git a/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.inl b/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.inl index c4f62d50d..f412e8d19 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.inl +++ b/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.inl @@ -3,11 +3,14 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include namespace Nz { + inline const Vector2ui& OpenGLFboFramebuffer::GetAttachmentSize(std::size_t i) const + { + return m_attachmentSizes[i]; + } } #include diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp index 7d03286ca..bc802c787 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -172,6 +173,8 @@ namespace Nz if (command.framebuffer->GetType() == FramebufferType::Texture) { + const OpenGLFboFramebuffer& fboFramebuffer = static_cast(*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); } } diff --git a/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp index 76cdcd2f2..acff90fae 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp @@ -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(*attachments[i]); Vector2ui textureSize = Vector2ui(glTexture.GetSize()); + m_attachmentSizes[i] = textureSize; if (i == 0) m_size = textureSize;