Skip to content

Commit dd01b3c

Browse files
GS/GL: Check if function pointers are actually supported for extensions.
On older mesa versions GLAD_GL_ARB_draw_buffers_blend flag is set enabled as supported, however glBlendFuncSeparatei is null which results in a crash so what we can do is also check if the pointers are working. Also check for GLAD_GL_ARB_viewport_array , GLAD_GL_ARB_texture_barrier , GLAD_GL_ARB_direct_state_access. We want to make sure they are supported, otherwise it will result in a crash.
1 parent ac69bb2 commit dd01b3c

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,29 @@ namespace ReplaceGL
4343
glViewport(GLint(x), GLint(y), GLsizei(w), GLsizei(h));
4444
}
4545

46+
static void GLAPIENTRY BlendEquationSeparatei(GLuint index, GLenum op, GLenum op_alpha)
47+
{
48+
glBlendEquationSeparate(op, op_alpha);
49+
}
50+
51+
static void GLAPIENTRY BlendFuncSeparatei(GLuint index, GLenum src_factor, GLenum dst_factor, GLenum src_factor_alpha, GLenum dst_factor_alpha)
52+
{
53+
glBlendFuncSeparate(src_factor, dst_factor, src_factor_alpha, dst_factor_alpha);
54+
}
55+
56+
static void GLAPIENTRY Enablei(GLenum target, GLuint index)
57+
{
58+
glEnable(target);
59+
}
60+
61+
static void GLAPIENTRY Disablei(GLenum target, GLuint index)
62+
{
63+
glDisable(target);
64+
}
65+
4666
static void GLAPIENTRY TextureBarrier()
4767
{
68+
4869
}
4970

5071
} // namespace ReplaceGL
@@ -742,21 +763,49 @@ bool GSDeviceOGL::CheckFeatures()
742763
return false;
743764
}
744765

745-
if (!GLAD_GL_ARB_viewport_array)
766+
// GLAD_GL_ARB_viewport_array
767+
const bool viewport_array_function_pointers = glScissorIndexed &&
768+
glViewportIndexedf;
769+
if (!GLAD_GL_ARB_viewport_array || !viewport_array_function_pointers)
746770
{
747771
glScissorIndexed = ReplaceGL::ScissorIndexed;
748772
glViewportIndexedf = ReplaceGL::ViewportIndexedf;
749773
Console.Warning("GL_ARB_viewport_array is not supported! Function pointer will be replaced.");
750774
}
751775

752-
if (!GLAD_GL_ARB_texture_barrier)
776+
// GLAD_GL_ARB_draw_buffers_blend
777+
const bool draw_buffers_blend_function_pointers = glEnablei &&
778+
glDisablei &&
779+
glBlendEquationSeparatei &&
780+
glBlendFuncSeparatei;
781+
if (!GLAD_GL_ARB_draw_buffers_blend || !draw_buffers_blend_function_pointers)
782+
{
783+
glEnablei = ReplaceGL::Enablei;
784+
glDisablei = ReplaceGL::Disablei;
785+
glBlendEquationSeparatei = ReplaceGL::BlendEquationSeparatei;
786+
glBlendFuncSeparatei = ReplaceGL::BlendFuncSeparatei;
787+
Console.Warning("GL_ARB_draw_buffers_blend is not supported! Function pointer will be replaced.");
788+
}
789+
790+
// GLAD_GL_ARB_texture_barrier
791+
if (!GLAD_GL_ARB_texture_barrier || !glTextureBarrier)
753792
{
754793
glTextureBarrier = ReplaceGL::TextureBarrier;
755794
Host::AddOSDMessage(
756795
"GL_ARB_texture_barrier is not supported, blending will not be accurate.", Host::OSD_ERROR_DURATION);
757796
}
758797

759-
if (!GLAD_GL_ARB_direct_state_access)
798+
// GLAD_GL_ARB_direct_state_access
799+
const bool direct_state_access_init_function_pointers = glBindTextureUnit &&
800+
glCreateTextures &&
801+
glTextureStorage2D &&
802+
glTextureSubImage2D &&
803+
glCompressedTextureSubImage2D &&
804+
glGetTextureImage &&
805+
glTextureParameteri &&
806+
glGenerateTextureMipmap &&
807+
glCreateSamplers;
808+
if (!GLAD_GL_ARB_direct_state_access || !direct_state_access_init_function_pointers)
760809
{
761810
Console.Warning("GL_ARB_direct_state_access is not supported, this will reduce performance.");
762811
Emulate_DSA::Init();

0 commit comments

Comments
 (0)