GS/GL: Add basic clip control fallback.

When GLAD_GL_ARB_clip_control is not supported then change
the vertex shader depth ranges to make sure it matches -1 1.
This commit is contained in:
lightningterror
2026-06-10 09:59:35 -04:00
committed by Tyler Bochard
parent 02c5ab2fd6
commit 3481970d12
3 changed files with 21 additions and 21 deletions
+14 -12
View File
@@ -72,12 +72,13 @@ void vs_main()
// example: 133.0625 (133 + 1/16) should start from line 134, ceil(133.0625 - 0.05) still above 133
gl_Position.xy = vec2(i_p) - vec2(0.05f, 0.05f);
gl_Position.xy = gl_Position.xy * VertexScale - VertexOffset;
#if HAS_CLIP_CONTROL
gl_Position.z = float(z) * exp_min32;
#else
// GLES doesn't support ARB_clip_control, so remap [0,1] to [-1,1].
gl_Position.z = min(float(z) * exp2(-23.0f), 2.0f) - 1.0f;
#endif
#if HAS_CLIP_CONTROL
gl_Position.z = float(z) * exp_min32;
#else
gl_Position.z = (float(z) * exp_min32) * 2.0f - 1.0f;
#endif
gl_Position.w = 1.0f;
texture_coord();
@@ -133,12 +134,13 @@ ProcessedVertex load_vertex(uint index)
uint z = min(i_z, MaxDepth);
vtx.p.xy = vec2(i_p) - vec2(0.05f, 0.05f);
vtx.p.xy = vtx.p.xy * VertexScale - VertexOffset;
#if HAS_CLIP_CONTROL
vtx.p.z = float(z) * exp_min32;
#else
// GLES doesn't support ARB_clip_control, so remap [0,1] to [-1,1].
vtx.p.z = min(float(z) * exp2(-23.0f), 2.0f) - 1.0f;
#endif
#if HAS_CLIP_CONTROL
vtx.p.z = float(z) * exp_min32;
#else
vtx.p.z = (float(z) * exp_min32) * 2.0f - 1.0f;
#endif
vtx.p.w = 1.0f;
vec2 uv = vec2(i_uv) - TextureOffset;
+6 -8
View File
@@ -645,9 +645,8 @@ bool GSDeviceOGL::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
// This extension allow FS depth to range from -1 to 1. So
// gl_position.z could range from [0, 1]
// Change depth convention
if (!m_is_gles) {
if (GLAD_GL_ARB_clip_control)
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
}
// ****************************************************************
// HW renderer shader
@@ -835,15 +834,14 @@ bool GSDeviceOGL::CheckFeatures()
if (!GLAD_GL_VERSION_4_3 && !GLAD_GL_ARB_copy_image && !GLAD_GL_EXT_copy_image && !GLAD_GL_NV_copy_image)
{
Host::ReportFormattedErrorAsync(
"GS", "GL_ARB_copy_image is not supported, copies will be slower.");
Host::AddOSDMessage(
"GL_ARB_copy_image is not supported, copies will be slower.", Host::OSD_ERROR_DURATION);
}
if (!GLAD_GL_VERSION_4_5 && !GLAD_GL_ARB_clip_control)
{
Host::ReportFormattedErrorAsync(
"GS", "GL_ARB_clip_control is not supported, this is required for the OpenGL renderer.");
return false;
Host::AddOSDMessage(
"GL_ARB_clip_control is not supported, depth will be less accurate.", Host::OSD_ERROR_DURATION);
}
@@ -1692,7 +1690,7 @@ std::string GSDeviceOGL::GenGlslHeader(const std::string_view entry, GLenum type
header += "#define DEPTH_FEEDBACK_SUPPORT 2\n"; // Depth as RT
}
if (!m_is_gles && GLAD_GL_ARB_clip_control)
if (GLAD_GL_ARB_clip_control)
header += "#define HAS_CLIP_CONTROL 1\n";
else
header += "#define HAS_CLIP_CONTROL 0\n";
+1 -1
View File
@@ -3,4 +3,4 @@
/// Version number for GS and other shaders. Increment whenever any of the contents of the
/// shaders change, to invalidate the cache.
static constexpr u32 SHADER_CACHE_VERSION = 100; // Last changed in PR 14503
static constexpr u32 SHADER_CACHE_VERSION = 101; // Last changed in PR 14547