mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: [OpenGL] Use GLSL version 1.50 if available.
This commit is contained in:
parent
90fd8f8cda
commit
821f30f735
|
@ -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);",
|
||||
"}",
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue