summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-16 16:43:22 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-22 22:16:07 +0100
commit821f30f7358ec3f0217b05a8d4af7101daf61678 (patch)
tree37e05e1df5237f7aad6ff93e52bdd83fd21731e1 /src
parent90fd8f8cda72d8ce985f11c0f7bc1b3bcab68a6e (diff)
downloadopenttd-821f30f7358ec3f0217b05a8d4af7101daf61678.tar.xz
Codechange: [OpenGL] Use GLSL version 1.50 if available.
Diffstat (limited to 'src')
-rw-r--r--src/table/opengl_shader.h22
-rw-r--r--src/video/opengl.cpp12
2 files changed, 32 insertions, 2 deletions
diff --git a/src/table/opengl_shader.h b/src/table/opengl_shader.h
index c59bcbcab..e3d5e0b3a 100644
--- a/src/table/opengl_shader.h
+++ b/src/table/opengl_shader.h
@@ -20,6 +20,17 @@ static const char *_vertex_shader_direct[] = {
"}",
};
+/** GLSL 1.50 vertex shader that just passes colour and tex coords through. */
+static const char *_vertex_shader_direct_150[] = {
+ "#version 150\n",
+ "in vec2 position, colour_uv;",
+ "out vec2 colour_tex_uv;",
+ "void main() {",
+ " colour_tex_uv = colour_uv;",
+ " gl_Position = vec4(position, 0.0, 1.0);",
+ "}",
+};
+
/** Fragment shader that reads the fragment colour from a 32bpp texture. */
static const char *_frag_shader_direct[] = {
"#version 110\n",
@@ -29,3 +40,14 @@ static const char *_frag_shader_direct[] = {
" gl_FragColor = texture2D(colour_tex, colour_tex_uv);",
"}",
};
+
+/** GLSL 1.50 fragment shader that reads the fragment colour from a 32bpp texture. */
+static const char *_frag_shader_direct_150[] = {
+ "#version 150\n",
+ "uniform sampler2D colour_tex;",
+ "in vec2 colour_tex_uv;",
+ "out vec4 colour;",
+ "void main() {",
+ " colour = texture(colour_tex, colour_tex_uv);",
+ "}",
+};
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp
index 2f92b2717..b5ce12dee 100644
--- a/src/video/opengl.cpp
+++ b/src/video/opengl.cpp
@@ -500,15 +500,23 @@ static bool VerifyProgram(GLuint program)
*/
bool OpenGLBackend::InitShaders()
{
+ const char *ver = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
+ if (ver == nullptr) return false;
+
+ int glsl_major = ver[0] - '0';
+ int glsl_minor = ver[2] - '0';
+
+ bool glsl_150 = (IsOpenGLVersionAtLeast(3, 2) || glsl_major > 1 || (glsl_major == 1 && glsl_minor >= 5));
+
/* Create vertex shader. */
GLuint vert_shader = _glCreateShader(GL_VERTEX_SHADER);
- _glShaderSource(vert_shader, lengthof(_vertex_shader_direct), _vertex_shader_direct, nullptr);
+ _glShaderSource(vert_shader, glsl_150 ? lengthof(_vertex_shader_direct_150) : lengthof(_vertex_shader_direct), glsl_150 ? _vertex_shader_direct_150 : _vertex_shader_direct, nullptr);
_glCompileShader(vert_shader);
if (!VerifyShader(vert_shader)) return false;
/* Create fragment shader. */
GLuint frag_shader = _glCreateShader(GL_FRAGMENT_SHADER);
- _glShaderSource(frag_shader, lengthof(_frag_shader_direct), _frag_shader_direct, nullptr);
+ _glShaderSource(frag_shader, glsl_150 ? lengthof(_frag_shader_direct_150) : lengthof(_frag_shader_direct), glsl_150 ? _frag_shader_direct_150 : _frag_shader_direct, nullptr);
_glCompileShader(frag_shader);
if (!VerifyShader(frag_shader)) return false;