]> git.pld-linux.org Git - packages/gemrb.git/blob - gemrb-gles.patch
upstream fix for crash with GLES backend
[packages/gemrb.git] / gemrb-gles.patch
1 From df493a7da7251eb5ea33b62a65580d09b440dd74 Mon Sep 17 00:00:00 2001
2 From: cmitu <31816814+cmitu@users.noreply.github.com>
3 Date: Wed, 2 Sep 2020 04:27:00 +0100
4 Subject: [PATCH] add OpenGL shaders versioning for GLSL compatibility
5
6 The GL context initialization in 'GLVideoDriver' requests OpenGL (ES) 2.0 from SDL2,
7 but SDL2 doesn't guarantee the context returned will have the same version [1].
8
9 To avoid any compatibility issues with a superior GLSL version, add the GLSL version to the shader code,
10 depending on the GL context requested (non-ES vs. ES).
11  * when expecting an OpenGL 2.0 context, set version to 110
12  * when expecting an OpenGL ES 2.0 context, set version to 100
13
14 [1] - https://wiki.libsdl.org/SDL_GLattr#OpenGL
15 ---
16  gemrb/plugins/SDLVideo/GLSLProgram.cpp  | 10 ++++++++--
17  gemrb/plugins/SDLVideo/SDL20GLVideo.cpp |  8 +++++---
18  2 files changed, 13 insertions(+), 5 deletions(-)
19
20 diff --git a/gemrb/plugins/SDLVideo/GLSLProgram.cpp b/gemrb/plugins/SDLVideo/GLSLProgram.cpp
21 index 1d5ec51633..34f141002b 100644
22 --- a/gemrb/plugins/SDLVideo/GLSLProgram.cpp
23 +++ b/gemrb/plugins/SDLVideo/GLSLProgram.cpp
24 @@ -102,10 +102,16 @@ GLSLProgram* GLSLProgram::CreateFromFiles(std::string vertexSourceFileName, std:
25         return GLSLProgram::Create(vertexContent, fragmentContent);
26  }
27  
28 -GLuint GLSLProgram::buildShader(GLenum type, std::string source)
29 +GLuint GLSLProgram::buildShader(GLenum type, const std::string source)
30  {
31 +       std::string shader_source = source;
32 +#ifdef USE_GL
33 +       shader_source.insert(0, "#version 110\n");
34 +#else
35 +       shader_source.insert(0, "#version 100\n");
36 +#endif
37      GLuint id = glCreateShader(type);
38 -       const char* src = source.c_str();
39 +       const char* src = shader_source.c_str();
40         glShaderSource(id, 1, &src, 0);
41      glCompileShader(id);
42      GLint result = GL_FALSE;
43 diff --git a/gemrb/plugins/SDLVideo/SDL20GLVideo.cpp b/gemrb/plugins/SDLVideo/SDL20GLVideo.cpp
44 index b28738317e..62eb361238 100644
45 --- a/gemrb/plugins/SDLVideo/SDL20GLVideo.cpp
46 +++ b/gemrb/plugins/SDLVideo/SDL20GLVideo.cpp
47 @@ -66,23 +66,25 @@ int GLVideoDriver::CreateDisplay(int w, int h, int bpp, bool fs, const char* tit
48         window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, winFlags);
49         if (window == NULL) 
50         {
51 -               Log(ERROR, "SDL 2 GL Driver", "couldnt create window:%s", SDL_GetError());
52 +               Log(ERROR, "SDL 2 GL Driver", "Unable to create window:%s", SDL_GetError());
53                 return GEM_ERROR;
54         }
55  
56         context = SDL_GL_CreateContext(window);
57         if (context == NULL) 
58         {
59 -               Log(ERROR, "SDL 2 GL Driver", "couldnt create GL context:%s", SDL_GetError());
60 +               Log(ERROR, "SDL 2 GL Driver", "Unable to create GL context:%s", SDL_GetError());
61                 return GEM_ERROR;
62         }
63         SDL_GL_MakeCurrent(window, context);
64 +       Log(MESSAGE, "SDL 2 GL Driver", "OpenGL version: %s, renderer: %s, vendor: %s", glGetString(GL_VERSION), glGetString(GL_RENDERER), glGetString(GL_VENDOR));
65 +       Log(MESSAGE, "SDL 2 GL Driver", "  GLSL version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
66  
67         renderer = SDL_CreateRenderer(window, -1, 0);
68  
69         if (renderer == NULL) 
70         {
71 -               Log(ERROR, "SDL 2 GL Driver", "couldnt create renderer:%s", SDL_GetError());
72 +               Log(ERROR, "SDL 2 GL Driver", "Unable to create renderer:%s", SDL_GetError());
73                 return GEM_ERROR;
74         }
75         SDL_RenderSetLogicalSize(renderer, width, height);
This page took 0.060457 seconds and 3 git commands to generate.