Fixed OpenGL ES shader compilation on Linux

This commit is contained in:
Sam Lantinga 2022-09-15 06:57:41 -07:00
parent 8a15a738f3
commit bc57d3e35c
3 changed files with 28 additions and 9 deletions

View File

@ -496,7 +496,7 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t
GLuint id = 0; GLuint id = 0;
GLint compileSuccessful = GL_FALSE; GLint compileSuccessful = GL_FALSE;
int attempt, num_src; int attempt, num_src;
const GLchar *shader_src_list[2]; const GLchar *shader_src_list[3];
const GLchar *shader_body = GLES2_GetShader(type); const GLchar *shader_body = GLES2_GetShader(type);
if (!shader_body) { 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) { for (attempt = 0; attempt < 2 && !compileSuccessful; ++attempt) {
num_src = 0; num_src = 0;
shader_src_list[num_src++] = GLES2_GetShaderPrologue(type);
if (shader_type == GL_FRAGMENT_SHADER) { if (shader_type == GL_FRAGMENT_SHADER) {
if (attempt == 0) { if (attempt == 0) {
shader_src_list[num_src++] = GLES2_GetShaderInclude(data->texcoord_precision_hint); 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++] = GLES2_GetShaderInclude(GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION);
} }
} }
shader_src_list[num_src++] = shader_body; shader_src_list[num_src++] = shader_body;
SDL_assert(num_src <= SDL_arraysize(shader_src_list)); SDL_assert(num_src <= SDL_arraysize(shader_src_list));

View File

@ -326,11 +326,13 @@ static const char GLES2_Fragment_TextureNV21BT709[] = \
#endif #endif
/* Custom Android video format texture */ /* 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\ #extension GL_OES_EGL_image_external : require\n\
";
static const char GLES2_Fragment_TextureExternalOES[] = " \
uniform samplerExternalOES u_texture; \ uniform samplerExternalOES u_texture; \
varying mediump vec4 v_color;\n\ varying mediump vec4 v_color; \
varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n\ varying SDL_TEXCOORD_PRECISION vec2 v_texCoord; \
\ \
void main() \ void main() \
{ \ { \
@ -344,7 +346,18 @@ static const char GLES2_Fragment_TextureExternalOES[] = " \
* Shader selector * * 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) { switch (type) {
case GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION: case GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION:
return GLES2_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"); const char *texcoord_hint = SDL_GetHint("SDL_RENDER_OPENGLES2_TEXCOORD_PRECISION");
GLES2_ShaderIncludeType value = GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION; GLES2_ShaderIncludeType value = GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION;
if (texcoord_hint) { if (texcoord_hint) {

View File

@ -60,9 +60,10 @@ typedef enum
GLES2_SHADER_COUNT GLES2_SHADER_COUNT
} GLES2_ShaderType; } GLES2_ShaderType;
const char *GLES2_GetShader(GLES2_ShaderType type); extern const char *GLES2_GetShaderPrologue(GLES2_ShaderType type);
const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type); extern const char *GLES2_GetShaderInclude(GLES2_ShaderIncludeType type);
GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint(void); extern const char *GLES2_GetShader(GLES2_ShaderType type);
extern GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint(void);
#endif /* SDL_VIDEO_RENDER_OGL_ES2 */ #endif /* SDL_VIDEO_RENDER_OGL_ES2 */