summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-16 16:43:21 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-22 22:16:07 +0100
commit90fd8f8cda72d8ce985f11c0f7bc1b3bcab68a6e (patch)
tree0b5f9651ebde6c713bf43a9cada854dc1f26a615 /src/video
parentacf59f6b68a3bdd068b4eddccd06749c5b411189 (diff)
downloadopenttd-90fd8f8cda72d8ce985f11c0f7bc1b3bcab68a6e.tar.xz
Codechange: [OpenGL] Use generic vertex attributes in the shader program.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/opengl.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp
index dbf196164..2f92b2717 100644
--- a/src/video/opengl.cpp
+++ b/src/video/opengl.cpp
@@ -64,6 +64,11 @@ static PFNGLGETSHADERINFOLOGPROC _glGetShaderInfoLog;
static PFNGLGETUNIFORMLOCATIONPROC _glGetUniformLocation;
static PFNGLUNIFORM1IPROC _glUniform1i;
+static PFNGLGETATTRIBLOCATIONPROC _glGetAttribLocation;
+static PFNGLENABLEVERTEXATTRIBARRAYPROC _glEnableVertexAttribArray;
+static PFNGLDISABLEVERTEXATTRIBARRAYPROC _glDisableVertexAttribArray;
+static PFNGLVERTEXATTRIBPOINTERARBPROC _glVertexAttribPointer;
+
/** A simple 2D vertex with just position and texture. */
struct Simple2DVertex {
float x, y;
@@ -209,6 +214,11 @@ static bool BindShaderExtensions()
_glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)GetOGLProcAddress("glGetShaderInfoLog");
_glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)GetOGLProcAddress("glGetUniformLocation");
_glUniform1i = (PFNGLUNIFORM1IPROC)GetOGLProcAddress("glUniform1i");
+
+ _glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)GetOGLProcAddress("glGetAttribLocation");
+ _glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)GetOGLProcAddress("glEnableVertexAttribArray");
+ _glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)GetOGLProcAddress("glDisableVertexAttribArray");
+ _glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERARBPROC)GetOGLProcAddress("glVertexAttribPointer");
} else {
/* In the ARB extension programs and shaders are in the same object space. */
_glCreateProgram = (PFNGLCREATEPROGRAMPROC)GetOGLProcAddress("glCreateProgramObjectARB");
@@ -226,11 +236,17 @@ static bool BindShaderExtensions()
_glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)GetOGLProcAddress("glGetInfoLogARB");
_glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)GetOGLProcAddress("glGetUniformLocationARB");
_glUniform1i = (PFNGLUNIFORM1IPROC)GetOGLProcAddress("glUniform1iARB");
+
+ _glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)GetOGLProcAddress("glGetAttribLocationARB");
+ _glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)GetOGLProcAddress("glEnableVertexAttribArrayARB");
+ _glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)GetOGLProcAddress("glDisableVertexAttribArrayARB");
+ _glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERARBPROC)GetOGLProcAddress("glVertexAttribPointerARB");
}
return _glCreateProgram != nullptr && _glDeleteProgram != nullptr && _glLinkProgram != nullptr && _glGetProgramiv != nullptr && _glGetProgramInfoLog != nullptr &&
_glCreateShader != nullptr && _glDeleteShader != nullptr && _glShaderSource != nullptr && _glCompileShader != nullptr && _glAttachShader != nullptr &&
- _glGetShaderiv != nullptr && _glGetShaderInfoLog != nullptr && _glGetUniformLocation != nullptr && _glUniform1i != nullptr;
+ _glGetShaderiv != nullptr && _glGetShaderInfoLog != nullptr && _glGetUniformLocation != nullptr && _glUniform1i != nullptr &&
+ _glGetAttribLocation != nullptr && _glEnableVertexAttribArray != nullptr && _glDisableVertexAttribArray != nullptr && _glVertexAttribPointer != nullptr;
}
/** Callback to receive OpenGL debug messages. */
@@ -417,10 +433,12 @@ const char *OpenGLBackend::Init()
if (glGetError() != GL_NO_ERROR) return "Can't generate VBO for fullscreen quad";
/* Set vertex state. */
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(2, GL_FLOAT, sizeof(Simple2DVertex), (GLvoid *)offsetof(Simple2DVertex, x));
- glTexCoordPointer(2, GL_FLOAT, sizeof(Simple2DVertex), (GLvoid *)offsetof(Simple2DVertex, u));
+ GLint loc_position = _glGetAttribLocation(this->vid_program, "position");
+ GLint colour_position = _glGetAttribLocation(this->vid_program, "colour_uv");
+ _glEnableVertexAttribArray(loc_position);
+ _glEnableVertexAttribArray(colour_position);
+ _glVertexAttribPointer(loc_position, 2, GL_FLOAT, GL_FALSE, sizeof(Simple2DVertex), (GLvoid *)offsetof(Simple2DVertex, x));
+ _glVertexAttribPointer(colour_position, 2, GL_FLOAT, GL_FALSE, sizeof(Simple2DVertex), (GLvoid *)offsetof(Simple2DVertex, u));
_glBindVertexArray(0);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);