OpenGLDevice: Use glClearBuffer() instead of glClear()

This commit is contained in:
Stenzek 2023-11-24 21:35:54 +10:00
parent 603531f916
commit e75c1a3b0a
No known key found for this signature in database
2 changed files with 10 additions and 30 deletions

View file

@ -20,6 +20,8 @@
Log_SetChannel(OpenGLDevice); Log_SetChannel(OpenGLDevice);
static constexpr std::array<float, 4> s_clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
OpenGLDevice::OpenGLDevice() OpenGLDevice::OpenGLDevice()
{ {
// Something which won't be matched.. // Something which won't be matched..
@ -598,12 +600,9 @@ void OpenGLDevice::SetSwapInterval()
void OpenGLDevice::RenderBlankFrame() void OpenGLDevice::RenderBlankFrame()
{ {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glDisable(GL_SCISSOR_TEST); glClearBufferfv(GL_COLOR, 0, s_clear_color.data());
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
m_gl_context->SwapBuffers(); m_gl_context->SwapBuffers();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0);
glEnable(GL_SCISSOR_TEST);
} }
GPUDevice::AdapterAndModeList OpenGLDevice::GetAdapterAndModeList() GPUDevice::AdapterAndModeList OpenGLDevice::GetAdapterAndModeList()
@ -697,6 +696,7 @@ bool OpenGLDevice::BeginPresent(bool skip_present)
} }
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearBufferfv(GL_COLOR, 0, s_clear_color.data());
const Common::Rectangle<s32> window_rc = const Common::Rectangle<s32> window_rc =
Common::Rectangle<s32>::FromExtents(0, 0, m_window_info.surface_width, m_window_info.surface_height); Common::Rectangle<s32>::FromExtents(0, 0, m_window_info.surface_width, m_window_info.surface_height);
@ -705,9 +705,6 @@ bool OpenGLDevice::BeginPresent(bool skip_present)
m_last_scissor = window_rc; m_last_scissor = window_rc;
UpdateViewport(); UpdateViewport();
UpdateScissor(); UpdateScissor();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
return true; return true;
} }

View file

@ -481,22 +481,16 @@ void OpenGLDevice::CommitClear(OpenGLTexture* tex)
const GLenum attachment = tex->IsDepthStencil() ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0; const GLenum attachment = tex->IsDepthStencil() ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0;
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, tex->GetGLTarget(), tex->GetGLId(), 0); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, tex->GetGLTarget(), tex->GetGLId(), 0);
glDisable(GL_SCISSOR_TEST);
if (tex->IsDepthStencil()) if (tex->IsDepthStencil())
{ {
if (glClearDepthf) const float depth = tex->GetClearDepth();
glClearDepthf(tex->GetClearDepth()); glClearBufferfv(GL_DEPTH, 0, &depth);
else
glClearDepth(tex->GetClearDepth());
glClear(GL_DEPTH_BUFFER_BIT);
} }
else else
{ {
const auto color = tex->GetUNormClearColor(); const auto color = tex->GetUNormClearColor();
glClearColor(color[0], color[1], color[2], color[3]); glClearBufferfv(GL_COLOR, 0, color.data());
glClear(GL_COLOR_BUFFER_BIT);
} }
glEnable(GL_SCISSOR_TEST);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, 0, 0); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, 0, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0);
@ -515,7 +509,6 @@ void OpenGLDevice::CommitClear(OpenGLTexture* tex)
void OpenGLDevice::CommitClear(OpenGLFramebuffer* fb) void OpenGLDevice::CommitClear(OpenGLFramebuffer* fb)
{ {
GLenum clear_flags = 0;
GLenum invalidate_attachments[2]; GLenum invalidate_attachments[2];
GLuint num_invalidate_attachments = 0; GLuint num_invalidate_attachments = 0;
@ -533,8 +526,7 @@ void OpenGLDevice::CommitClear(OpenGLFramebuffer* fb)
case GPUTexture::State::Cleared: case GPUTexture::State::Cleared:
{ {
const auto color = FB->GetUNormClearColor(); const auto color = FB->GetUNormClearColor();
glClearColor(color[0], color[1], color[2], color[3]); glClearBufferfv(GL_COLOR, 0, color.data());
clear_flags |= GL_COLOR_BUFFER_BIT;
FB->SetState(GPUTexture::State::Dirty); FB->SetState(GPUTexture::State::Dirty);
} }
@ -559,11 +551,8 @@ void OpenGLDevice::CommitClear(OpenGLFramebuffer* fb)
case GPUTexture::State::Cleared: case GPUTexture::State::Cleared:
{ {
if (glClearDepthf) const float depth = DS->GetClearDepth();
glClearDepthf(DS->GetClearDepth()); glClearBufferfv(GL_DEPTH, 0, &depth);
else
glClearDepth(DS->GetClearDepth());
clear_flags |= GL_DEPTH_BUFFER_BIT;
DS->SetState(GPUTexture::State::Dirty); DS->SetState(GPUTexture::State::Dirty);
} }
break; break;
@ -577,12 +566,6 @@ void OpenGLDevice::CommitClear(OpenGLFramebuffer* fb)
} }
} }
if (clear_flags != 0)
{
glDisable(GL_SCISSOR_TEST);
glClear(clear_flags);
glEnable(GL_SCISSOR_TEST);
}
if (num_invalidate_attachments > 0 && glInvalidateFramebuffer) if (num_invalidate_attachments > 0 && glInvalidateFramebuffer)
glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, num_invalidate_attachments, invalidate_attachments); glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, num_invalidate_attachments, invalidate_attachments);
} }