OpenGLRenderer: Fix FBO clearing when scissor is enabled
This commit is contained in:
parent
45d4195527
commit
0133a91c4d
|
|
@ -29,6 +29,8 @@ namespace Nz
|
||||||
|
|
||||||
void Activate() const override;
|
void Activate() const override;
|
||||||
|
|
||||||
|
inline const Vector2ui& GetAttachmentSize(std::size_t i) const;
|
||||||
|
|
||||||
std::size_t GetColorBufferCount() const override;
|
std::size_t GetColorBufferCount() const override;
|
||||||
|
|
||||||
const Vector2ui& GetSize() const override;
|
const Vector2ui& GetSize() const override;
|
||||||
|
|
@ -39,10 +41,11 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
GL::Framebuffer m_framebuffer;
|
GL::Framebuffer m_framebuffer;
|
||||||
std::size_t m_colorAttachmentCount;
|
std::size_t m_colorAttachmentCount;
|
||||||
|
std::vector<Vector2ui> m_attachmentSizes;
|
||||||
Vector2ui m_size;
|
Vector2ui m_size;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.inl>
|
||||||
|
|
||||||
#endif // NAZARA_OPENGLRENDERER_OPENGLFBOFRAMEBUFFER_HPP
|
#endif // NAZARA_OPENGLRENDERER_OPENGLFBOFRAMEBUFFER_HPP
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,14 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLFramebuffer.hpp>
|
|
||||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
inline const Vector2ui& OpenGLFboFramebuffer::GetAttachmentSize(std::size_t i) const
|
||||||
|
{
|
||||||
|
return m_attachmentSizes[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
|
||||||
|
|
@ -172,6 +173,8 @@ namespace Nz
|
||||||
|
|
||||||
if (command.framebuffer->GetType() == FramebufferType::Texture)
|
if (command.framebuffer->GetType() == FramebufferType::Texture)
|
||||||
{
|
{
|
||||||
|
const OpenGLFboFramebuffer& fboFramebuffer = static_cast<const OpenGLFboFramebuffer&>(*command.framebuffer);
|
||||||
|
|
||||||
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
|
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
|
||||||
|
|
||||||
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
|
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
|
||||||
|
|
@ -187,6 +190,11 @@ namespace Nz
|
||||||
if (attachmentInfo.loadOp == AttachmentLoadOp::Clear)
|
if (attachmentInfo.loadOp == AttachmentLoadOp::Clear)
|
||||||
{
|
{
|
||||||
context->ResetColorWriteMasks();
|
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());
|
context->glClearBufferfv(GL_COLOR, GLint(i), clearColor.data());
|
||||||
}
|
}
|
||||||
else if (attachmentInfo.loadOp == AttachmentLoadOp::Discard)
|
else if (attachmentInfo.loadOp == AttachmentLoadOp::Discard)
|
||||||
|
|
@ -199,6 +207,14 @@ namespace Nz
|
||||||
const auto& clearValues = command.clearValues[attachmentIndex];
|
const auto& clearValues = command.clearValues[attachmentIndex];
|
||||||
|
|
||||||
const auto& depthStencilAttachment = command.renderpass->GetAttachment(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)
|
if (depthStencilAttachment.loadOp == AttachmentLoadOp::Clear && depthStencilAttachment.stencilLoadOp == AttachmentLoadOp::Clear)
|
||||||
{
|
{
|
||||||
context->ResetDepthWriteMasks();
|
context->ResetDepthWriteMasks();
|
||||||
|
|
@ -287,9 +303,10 @@ namespace Nz
|
||||||
|
|
||||||
if (clearFields)
|
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();
|
const Vector2ui& size = command.framebuffer->GetSize();
|
||||||
context->SetScissorBox(0, 0, size.x, size.y);
|
context->SetScissorBox(0, 0, size.x, size.y);
|
||||||
context->SetViewport(0, 0, size.x, size.y);
|
|
||||||
context->glClear(clearFields);
|
context->glClear(clearFields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,14 @@ namespace Nz
|
||||||
bool hasDepth = false;
|
bool hasDepth = false;
|
||||||
bool hasStencil = false;
|
bool hasStencil = false;
|
||||||
|
|
||||||
|
m_attachmentSizes.resize(attachments.size());
|
||||||
for (std::size_t i = 0; i < attachments.size(); ++i)
|
for (std::size_t i = 0; i < attachments.size(); ++i)
|
||||||
{
|
{
|
||||||
assert(attachments[i]);
|
assert(attachments[i]);
|
||||||
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(*attachments[i]);
|
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(*attachments[i]);
|
||||||
|
|
||||||
Vector2ui textureSize = Vector2ui(glTexture.GetSize());
|
Vector2ui textureSize = Vector2ui(glTexture.GetSize());
|
||||||
|
m_attachmentSizes[i] = textureSize;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
m_size = textureSize;
|
m_size = textureSize;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue