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
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].
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
14 [1] - https://wiki.libsdl.org/SDL_GLattr#OpenGL
16 gemrb/plugins/SDLVideo/GLSLProgram.cpp | 10 ++++++++--
17 gemrb/plugins/SDLVideo/SDL20GLVideo.cpp | 8 +++++---
18 2 files changed, 13 insertions(+), 5 deletions(-)
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);
28 -GLuint GLSLProgram::buildShader(GLenum type, std::string source)
29 +GLuint GLSLProgram::buildShader(GLenum type, const std::string source)
31 + std::string shader_source = source;
33 + shader_source.insert(0, "#version 110\n");
35 + shader_source.insert(0, "#version 100\n");
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);
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);
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());
56 context = SDL_GL_CreateContext(window);
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());
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));
67 renderer = SDL_CreateRenderer(window, -1, 0);
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());
75 SDL_RenderSetLogicalSize(renderer, width, height);