GPU/OpenGL: Support GL_EXT_blend_func_extended for dual-source blend

This commit is contained in:
Connor McLaughlin 2020-11-10 20:36:17 +10:00
parent e3c07b562c
commit 92a4551bb2
3 changed files with 24 additions and 7 deletions

View File

@ -225,6 +225,21 @@ protected:
}
}
/// Returns true if alpha blending should be enabled for drawing the current batch.
ALWAYS_INLINE bool UseAlphaBlending(TransparencyMode transparency_mode, BatchRenderMode render_mode) const
{
if (m_texture_filtering == GPUTextureFilter::Bilinear || m_texture_filtering == GPUTextureFilter::JINC2 ||
m_texture_filtering == GPUTextureFilter::xBR)
{
return true;
}
if (transparency_mode == TransparencyMode::Disabled || render_mode == BatchRenderMode::OnlyOpaque)
return false;
return true;
}
void FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) override;
void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data) override;
void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) override;

View File

@ -240,7 +240,8 @@ void GPU_HW_OpenGL::SetCapabilities(HostDisplay* host_display)
int max_dual_source_draw_buffers = 0;
glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, &max_dual_source_draw_buffers);
m_supports_dual_source_blend =
(max_dual_source_draw_buffers > 0) && (GLAD_GL_VERSION_3_3 || GLAD_GL_ARB_blend_func_extended);
(max_dual_source_draw_buffers > 0) &&
(GLAD_GL_VERSION_3_3 || GLAD_GL_ARB_blend_func_extended || GLAD_GL_EXT_blend_func_extended);
if (!m_supports_dual_source_blend)
Log_WarningPrintf("Dual-source blending is not supported, this may break some mask effects.");
@ -588,12 +589,7 @@ void GPU_HW_OpenGL::DrawBatchVertices(BatchRenderMode render_mode, u32 base_vert
void GPU_HW_OpenGL::SetBlendMode()
{
if (m_texture_filtering == GPUTextureFilter::Nearest && (m_current_transparency_mode == TransparencyMode::Disabled ||
m_current_render_mode == BatchRenderMode::OnlyOpaque))
{
glDisable(GL_BLEND);
}
else
if (UseAlphaBlending(m_current_transparency_mode, m_current_render_mode))
{
glEnable(GL_BLEND);
glBlendEquationSeparate(m_current_transparency_mode == TransparencyMode::BackgroundMinusForeground ?
@ -602,6 +598,10 @@ void GPU_HW_OpenGL::SetBlendMode()
GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE, m_supports_dual_source_blend ? GL_SRC1_ALPHA : GL_SRC_ALPHA, GL_ONE, GL_ZERO);
}
else
{
glDisable(GL_BLEND);
}
}
void GPU_HW_OpenGL::SetDepthFunc()

View File

@ -89,6 +89,8 @@ void ShaderGen::WriteHeader(std::stringstream& ss)
// Enable EXT_blend_func_extended for dual-source blend on OpenGL ES.
if (GLAD_GL_EXT_blend_func_extended)
ss << "#extension GL_EXT_blend_func_extended : require\n";
if (GLAD_GL_ARB_blend_func_extended)
ss << "#extension GL_ARB_blend_func_extended : require\n";
}
else if (m_render_api == HostDisplay::RenderAPI::OpenGL)
{