Fixed OpenGL ES shader compilation on Linux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 29b050d..e882577 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -496,7 +496,7 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t
GLuint id = 0;
GLint compileSuccessful = GL_FALSE;
int attempt, num_src;
- const GLchar *shader_src_list[2];
+ const GLchar *shader_src_list[3];
const GLchar *shader_body = GLES2_GetShader(type);
if (!shader_body) {
@@ -506,6 +506,9 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t
for (attempt = 0; attempt < 2 && !compileSuccessful; ++attempt) {
num_src = 0;
+
+ shader_src_list[num_src++] = GLES2_GetShaderPrologue(type);
+
if (shader_type == GL_FRAGMENT_SHADER) {
if (attempt == 0) {
shader_src_list[num_src++] = GLES2_GetShaderInclude(data->texcoord_precision_hint);
@@ -513,6 +516,7 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t
shader_src_list[num_src++] = GLES2_GetShaderInclude(GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION);
}
}
+
shader_src_list[num_src++] = shader_body;
SDL_assert(num_src <= SDL_arraysize(shader_src_list));
diff --git a/src/render/opengles2/SDL_shaders_gles2.c b/src/render/opengles2/SDL_shaders_gles2.c
index 4d48e36..54a5896 100644
--- a/src/render/opengles2/SDL_shaders_gles2.c
+++ b/src/render/opengles2/SDL_shaders_gles2.c
@@ -326,11 +326,13 @@ static const char GLES2_Fragment_TextureNV21BT709[] = \
#endif
/* Custom Android video format texture */
-static const char GLES2_Fragment_TextureExternalOES[] = " \
+static const char GLES2_Fragment_TextureExternalOES_Prologue[] = " \
#extension GL_OES_EGL_image_external : require\n\
+";
+static const char GLES2_Fragment_TextureExternalOES[] = " \
uniform samplerExternalOES u_texture; \
- varying mediump vec4 v_color;\n\
- varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n\
+ varying mediump vec4 v_color; \
+ varying SDL_TEXCOORD_PRECISION vec2 v_texCoord; \
\
void main() \
{ \
@@ -344,7 +346,18 @@ static const char GLES2_Fragment_TextureExternalOES[] = " \
* Shader selector *
*************************************************************************************************/
-const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type) {
+const char *GLES2_GetShaderPrologue(GLES2_ShaderType type)
+{
+ switch (type) {
+ case GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES:
+ return GLES2_Fragment_TextureExternalOES_Prologue;
+ default:
+ return "";
+ }
+}
+
+const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type)
+{
switch (type) {
case GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION:
return GLES2_Fragment_Include_Undef_Precision;
@@ -359,7 +372,8 @@ const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type) {
}
}
-GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint() {
+GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint()
+{
const char *texcoord_hint = SDL_GetHint("SDL_RENDER_OPENGLES2_TEXCOORD_PRECISION");
GLES2_ShaderIncludeType value = GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION;
if (texcoord_hint) {
diff --git a/src/render/opengles2/SDL_shaders_gles2.h b/src/render/opengles2/SDL_shaders_gles2.h
index c3d5928..5a688cc 100644
--- a/src/render/opengles2/SDL_shaders_gles2.h
+++ b/src/render/opengles2/SDL_shaders_gles2.h
@@ -60,9 +60,10 @@ typedef enum
GLES2_SHADER_COUNT
} GLES2_ShaderType;
-const char *GLES2_GetShader(GLES2_ShaderType type);
-const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type);
-GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint(void);
+extern const char *GLES2_GetShaderPrologue(GLES2_ShaderType type);
+extern const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type);
+extern const char *GLES2_GetShader(GLES2_ShaderType type);
+extern GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint(void);
#endif /* SDL_VIDEO_RENDER_OGL_ES2 */