Mercurial > hg > openttd
changeset 20547:a33f1173fca7 draft
-Codechange: [OpenGL] Explicitly assign which framebuffer target receives the colour values.
author | Michael Lutz <michi@icosahedron.de> |
---|---|
date | Sun, 02 Jun 2013 16:30:12 +0200 |
parents | 9b3254738575 |
children | d15aa0fab335 |
files | src/table/opengl_shader.h src/video/opengl.cpp |
diffstat | 2 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/table/opengl_shader.h +++ b/src/table/opengl_shader.h @@ -37,7 +37,7 @@ "uniform sampler2D colour_tex;", "varying vec2 colour_tex_uv;", "void main() {", - " gl_FragColor = texture2D(colour_tex, colour_tex_uv);", + " gl_FragData[0] = texture2D(colour_tex, colour_tex_uv);", "}", };
--- a/src/video/opengl.cpp +++ b/src/video/opengl.cpp @@ -68,6 +68,7 @@ static PFNGLENABLEVERTEXATTRIBARRAYPROC _glEnableVertexAttribArray; static PFNGLDISABLEVERTEXATTRIBARRAYPROC _glDisableVertexAttribArray; static PFNGLVERTEXATTRIBPOINTERARBPROC _glVertexAttribPointer; +static PFNGLBINDFRAGDATALOCATIONPROC _glBindFragDataLocation; /** A simple 2D vertex with just position and texture. */ struct Simple2DVertex { @@ -263,6 +264,15 @@ _glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERARBPROC)GetOGLProcAddress("glVertexAttribPointerARB"); } + /* Bind functions only needed when using GLSL 1.50 shaders. */ + if (IsOpenGLVersionAtLeast(3, 0)) { + _glBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC)GetOGLProcAddress("glBindFragDataLocation"); + } else if (IsOpenGLExtensionSupported("GL_EXT_gpu_shader4")) { + _glBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC)GetOGLProcAddress("glBindFragDataLocationEXT"); + } else { + _glBindFragDataLocation = NULL; + } + return _glCreateProgram != NULL && _glDeleteProgram != NULL && _glLinkProgram != NULL && _glGetProgramiv != NULL && _glGetProgramInfoLog != NULL && _glCreateShader != NULL && _glDeleteShader != NULL && _glShaderSource != NULL && _glCompileShader != NULL && _glAttachShader != NULL && _glGetShaderiv != NULL && _glGetShaderInfoLog != NULL && _glGetUniformLocation != NULL && _glUniform1i != NULL && @@ -322,6 +332,7 @@ if (!IsOpenGLExtensionSupported("GL_ARB_vertex_shader")) return "Vertex shaders not supported"; } if (!BindShaderExtensions()) return "Failed to bind shader extension functions"; + if (IsOpenGLVersionAtLeast(3,2) && _glBindFragDataLocation == NULL) return "OpenGL claims to support version 3.2 but doesn't have glBindFragDataLocation"; DEBUG(driver, 2, "OpenGL shading language version: %s", (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION)); @@ -453,6 +464,12 @@ this->vid_program = _glCreateProgram(); _glAttachShader(this->vid_program, vert_shader); _glAttachShader(this->vid_program, frag_shader); + + if (glsl_150) { + /* Bind fragment shader outputs. */ + _glBindFragDataLocation(this->vid_program, 0, "colour"); + } + _glLinkProgram(this->vid_program); if (!VerifyProgram(this->vid_program)) return false;