Skip to content

Commit cfc59db

Browse files
Improve GLSL ES version detection (#18272)
1 parent 7c7edb7 commit cfc59db

6 files changed

Lines changed: 32 additions & 22 deletions

File tree

gfx/drivers/gl_shaders/core_pipeline_xmb_ribbon.glsl.frag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "shaders_common.h"
22

3-
static const char *core_stock_fragment_xmb = GLSL(
3+
static const char *core_stock_fragment_xmb = GLSL_STANDARD_DERIVATIVES(
44
uniform float time;
55
in vec3 fragVertexEc;
66
vec3 up = vec3(0, 0, 1);

gfx/drivers/gl_shaders/legacy_pipeline_xmb_ribbon.glsl.vert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "shaders_common.h"
22

3-
static const char *stock_vertex_xmb_ribbon_legacy = GLSL(
3+
static const char *stock_vertex_xmb_ribbon_legacy = GLSL_STANDARD_DERIVATIVES(
44
attribute vec3 VertexCoord;
55
uniform float time;
66
varying vec3 fragVertexEc;

gfx/drivers/gl_shaders/modern_pipeline_xmb_ribbon.glsl.vert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "shaders_common.h"
22

3-
static const char *stock_vertex_xmb_ribbon_modern = GLSL(
3+
static const char *stock_vertex_xmb_ribbon_modern = GLSL_STANDARD_DERIVATIVES(
44
in vec3 VertexCoord;
55
uniform float time;
66
out vec3 fragVertexEc;

gfx/drivers/gl_shaders/pipeline_xmb_ribbon.glsl.frag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "shaders_common.h"
22

3-
static const char *stock_fragment_xmb = GLSL(
3+
static const char *stock_fragment_xmb = GLSL_STANDARD_DERIVATIVES(
44
uniform float time;
55
varying vec3 fragVertexEc;
66
vec3 up = vec3(0, 0, 1);

gfx/drivers/gl_shaders/shaders_common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"#else\n" \
1414
" precision mediump float;\n" \
1515
"#endif\n" #src
16-
#define GLSL_330(src) "#version 330 es\n" \
16+
#define GLSL_STANDARD_DERIVATIVES(src) "#version 130\n" \
17+
"#extension GL_OES_standard_derivatives : enable\n" \
1718
"#ifdef GL_ES\n" \
1819
" #ifdef GL_FRAGMENT_PRECISION_HIGH\n" \
1920
" precision highp float;\n" \
@@ -26,8 +27,7 @@
2627
#else
2728
#define CG(src) "" #src
2829
#define GLSL(src) "" #src
29-
#define GLSL_300(src) "#version 300 es\n" #src
30-
#define GLSL_330(src) "#version 330 core\n" #src
30+
#define GLSL_STANDARD_DERIVATIVES(src) "" #src
3131
#endif
3232

3333
#endif

gfx/drivers_shader/shader_glsl.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,22 +376,27 @@ static bool gl_glsl_compile_shader(glsl_shader_data_t *glsl,
376376
strtoul(existing_version + 8, (char**)&program, 10);
377377

378378
#ifdef HAVE_OPENGLES
379-
if (version_no >= 130 && version_no < 330)
379+
if (gl_check_capability(GL_CAPS_GLES3_SUPPORTED))
380380
{
381-
version_extra = " es";
382-
version_no = 300;
383-
}
384-
else if (version_no == 330)
385-
{
386-
version_extra = " es";
387-
version_no = 310;
388-
}
389-
else if (version_no > 330)
390-
{
391-
version_extra = " es";
392-
version_no = 320;
381+
if (version_no >= 130 && version_no < 330)
382+
{
383+
version_extra = " es";
384+
version_no = 300;
385+
}
386+
else if (version_no == 330)
387+
{
388+
version_extra = " es";
389+
version_no = 310;
390+
}
391+
else if (version_no > 330)
392+
{
393+
version_extra = " es";
394+
version_no = 320;
395+
}
396+
else version_no = 100;
393397
}
394-
else version_no = 100;
398+
/* Avoid versions that definitely aren't supported. */
399+
else version_no = 100;
395400
#endif
396401
snprintf(version,
397402
sizeof(version), "#version %u%s\n", version_no, version_extra);
@@ -895,7 +900,12 @@ static void gl_glsl_init_menu_shaders(void *data)
895900
shader_prog_info.vertex = stock_vertex_xmb_ribbon_modern;
896901
shader_prog_info.fragment = stock_fragment_xmb;
897902
#else
898-
if (gl_query_extension("GL_OES_standard_derivatives"))
903+
if (gl_check_capability(GL_CAPS_GLES3_SUPPORTED))
904+
{
905+
shader_prog_info.vertex = stock_vertex_xmb_ribbon_modern;
906+
shader_prog_info.fragment = core_stock_fragment_xmb;
907+
}
908+
else if (gl_query_extension("GL_OES_standard_derivatives"))
899909
{
900910
shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_ribbon_modern : stock_vertex_xmb_ribbon_legacy;
901911
shader_prog_info.fragment = glsl_core ? core_stock_fragment_xmb : stock_fragment_xmb;

0 commit comments

Comments
 (0)