OpenGLRenderer: Fix clear values
This commit is contained in:
parent
08c2f711b0
commit
a6b5246633
|
|
@ -132,6 +132,7 @@ namespace Nz
|
|||
|
||||
struct SetFrameBufferData
|
||||
{
|
||||
std::array<CommandBufferBuilder::ClearValues, 16> clearValues; //< TODO: Remove hard limit?
|
||||
const OpenGLFramebuffer* framebuffer;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,9 @@ namespace Nz
|
|||
SetFrameBufferData setFramebuffer;
|
||||
setFramebuffer.framebuffer = &framebuffer;
|
||||
|
||||
assert(clearValues.size() < setFramebuffer.clearValues.size());
|
||||
std::copy(clearValues.begin(), clearValues.end(), setFramebuffer.clearValues.begin());
|
||||
|
||||
m_commands.emplace_back(std::move(setFramebuffer));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ namespace Nz
|
|||
|
||||
virtual void Activate() const = 0;
|
||||
|
||||
virtual std::size_t GetColorBufferCount() const = 0;
|
||||
|
||||
inline Type GetType() const;
|
||||
|
||||
OpenGLFramebuffer& operator=(const OpenGLFramebuffer&) = delete;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ namespace Nz
|
|||
|
||||
void Activate() const override;
|
||||
|
||||
std::size_t GetColorBufferCount() const override;
|
||||
|
||||
OpenGLWindowFramebuffer& operator=(const OpenGLWindowFramebuffer&) = delete;
|
||||
OpenGLWindowFramebuffer& operator=(OpenGLWindowFramebuffer&&) = delete;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G
|
|||
cb(glBufferData, PFNGLBUFFERDATAPROC) \
|
||||
cb(glBufferSubData, PFNGLBUFFERSUBDATAPROC) \
|
||||
cb(glClear, PFNGLCLEARPROC) \
|
||||
cb(glClearBufferfi, PFNGLCLEARBUFFERFIPROC) \
|
||||
cb(glClearBufferuiv, PFNGLCLEARBUFFERUIVPROC) \
|
||||
cb(glClearColor, PFNGLCLEARCOLORPROC) \
|
||||
cb(glClearDepthf, PFNGLCLEARDEPTHFPROC) \
|
||||
cb(glClearStencil, PFNGLCLEARSTENCILPROC) \
|
||||
|
|
|
|||
|
|
@ -93,7 +93,24 @@ namespace Nz
|
|||
command.framebuffer->Activate();
|
||||
|
||||
context = GL::Context::GetCurrentContext();
|
||||
context->glClearColor(0.5, 0.5, 0.5, 1.0);
|
||||
|
||||
if (command.framebuffer->GetType() == OpenGLFramebuffer::Type::FBO)
|
||||
{
|
||||
std::size_t colorBufferCount = command.framebuffer->GetColorBufferCount();
|
||||
for (std::size_t i = 0; i < colorBufferCount; ++i)
|
||||
{
|
||||
Nz::Color color = command.clearValues[i].color;
|
||||
std::array<GLuint, 4> clearColor = { color.r, color.g, color.b, color.a };
|
||||
|
||||
context->glClearBufferuiv(GL_COLOR, GLint(i), clearColor.data());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Nz::Color color = command.clearValues[0].color;
|
||||
context->glClearColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
context->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -17,4 +17,9 @@ namespace Nz
|
|||
|
||||
context.BindFramebuffer(GL::FramebufferTarget::Draw, 0);
|
||||
}
|
||||
|
||||
std::size_t OpenGLWindowFramebuffer::GetColorBufferCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue