aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/opengl
diff options
context:
space:
mode:
authorJohannes Schickel2015-12-21 05:47:29 +0100
committerJohannes Schickel2016-03-16 20:29:25 +0100
commitfc52f730506422ac99e44cd74f229e6a0c5c2121 (patch)
tree02dc620cf8924ae9d691b38e51250c0ce3a83134 /backends/graphics/opengl
parentc7c870bf7f269229d069d47c22b61c237737cdae (diff)
downloadscummvm-rg350-fc52f730506422ac99e44cd74f229e6a0c5c2121.tar.gz
scummvm-rg350-fc52f730506422ac99e44cd74f229e6a0c5c2121.tar.bz2
scummvm-rg350-fc52f730506422ac99e44cd74f229e6a0c5c2121.zip
OPENGL: Slightly cleanup programmable pipeline handling.
Diffstat (limited to 'backends/graphics/opengl')
-rw-r--r--backends/graphics/opengl/context.cpp107
-rw-r--r--backends/graphics/opengl/opengl-func.h34
-rw-r--r--backends/graphics/opengl/shader.cpp4
3 files changed, 82 insertions, 63 deletions
diff --git a/backends/graphics/opengl/context.cpp b/backends/graphics/opengl/context.cpp
index 905532c8be..2da4cab158 100644
--- a/backends/graphics/opengl/context.cpp
+++ b/backends/graphics/opengl/context.cpp
@@ -28,6 +28,16 @@
namespace OpenGL {
+#if USE_FORCED_GL
+#define HAS_SHADERS_CHECK shadersSupported
+#elif USE_FORCED_GLES
+#define HAS_SHADERS_CHECK false
+#elif USE_FORCED_GLES2
+#define HAS_SHADERS_CHECK true
+#else
+#define HAS_SHADERS_CHECK (type == kContextGLES2 || shadersSupported)
+#endif
+
void Context::reset() {
NPOTSupported = false;
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
@@ -53,32 +63,35 @@ void Context::initializePipeline() {
}
#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
- if (g_context.type == kContextGLES2) {
+ // Enable rendering with vertex and coord arrays.
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+ if (HAS_SHADERS_CHECK) {
#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES
+#if !USE_FORCED_GLES
GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation));
GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation));
+#endif
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+ } else {
+#endif
+#if !USE_FORCED_GLES2
+ GL_CALL(glEnableClientState(GL_VERTEX_ARRAY));
+ GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
+#endif
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+ }
+#endif
+#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
+ if (g_context.type == kContextGLES2) {
+#endif
+#if !USE_FORCED_GL && !USE_FORCED_GLES
GL_CALL(glActiveTexture(GL_TEXTURE0));
#endif
#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
} else {
#endif
#if !USE_FORCED_GLES2
-#if !USE_FORCED_GLES
- if (g_context.shadersSupported) {
- GL_CALL(glEnableVertexAttribArrayARB(kPositionAttribLocation));
- GL_CALL(glEnableVertexAttribArrayARB(kTexCoordAttribLocation));
- } else {
-#endif
- // Enable rendering with vertex and coord arrays.
- GL_CALL(glEnableClientState(GL_VERTEX_ARRAY));
- GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
-#if !USE_FORCED_GLES
- }
-#endif
-
GL_CALL(glEnable(GL_TEXTURE_2D));
#endif
#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
@@ -87,56 +100,39 @@ void Context::initializePipeline() {
}
void Context::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
- if (g_context.type == kContextGLES2) {
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+ if (HAS_SHADERS_CHECK) {
#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES
+#if !USE_FORCED_GLES
GL_CALL(glVertexAttrib4f(kColorAttribLocation, r, g, b, a));
#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
} else {
#endif
#if !USE_FORCED_GLES2
-#if !USE_FORCED_GLES
- if (g_context.shadersSupported) {
- GL_CALL(glVertexAttrib4fARB(kColorAttribLocation, r, g, b, a));
- } else {
-#endif
- GL_CALL(glColor4f(r, g, b, a));
-#if !USE_FORCED_GLES
- }
+ GL_CALL(glColor4f(r, g, b, a));
#endif
-#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
}
#endif
}
void Context::setDrawCoordinates(const GLfloat *vertices, const GLfloat *texCoords) {
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
- if (g_context.type == kContextGLES2) {
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+ if (HAS_SHADERS_CHECK) {
#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES
+#if !USE_FORCED_GLES
GL_CALL(glVertexAttribPointer(kTexCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texCoords));
GL_CALL(glVertexAttribPointer(kPositionAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, vertices));
#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
} else {
#endif
#if !USE_FORCED_GLES2
-#if !USE_FORCED_GLES
- if (g_context.shadersSupported) {
- GL_CALL(glVertexAttribPointerARB(kTexCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texCoords));
- GL_CALL(glVertexAttribPointerARB(kPositionAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, vertices));
- } else {
-#endif
- GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texCoords));
- GL_CALL(glVertexPointer(2, GL_FLOAT, 0, vertices));
-#if !USE_FORCED_GLES
- }
+ GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texCoords));
+ GL_CALL(glVertexPointer(2, GL_FLOAT, 0, vertices));
#endif
-#endif
-#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
}
#endif
}
@@ -164,17 +160,30 @@ void OpenGLGraphicsManager::initializeGLContext() {
// See backends/plugins/sdl/sdl-provider.cpp for more information.
assert(sizeof(void (*)()) == sizeof(void *));
void *fn = nullptr;
-#define GL_EXT_FUNC_DEF(ret, name, param) \
- fn = getProcAddress(#name); \
+
+#define LOAD_FUNC(name, loadName) \
+ fn = getProcAddress(#loadName); \
memcpy(&g_context.name, &fn, sizeof(fn))
+
+#define GL_EXT_FUNC_DEF(ret, name, param) LOAD_FUNC(name, name)
+
#ifdef USE_BUILTIN_OPENGL
#define GL_FUNC_DEF(ret, name, param) g_context.name = &name
+#define GL_FUNC_2_DEF GL_FUNC_DEF
#else
#define GL_FUNC_DEF GL_EXT_FUNC_DEF
+#define GL_FUNC_2_DEF(ret, name, extName, param) \
+ if (g_context.type == kContextGL) { \
+ LOAD_FUNC(name, extName); \
+ } else { \
+ LOAD_FUNC(name, name); \
+ }
#endif
#include "backends/graphics/opengl/opengl-func.h"
-#undef GL_EXT_FUNC_DEF
+#undef GL_FUNC_2_DEF
#undef GL_FUNC_DEF
+#undef GL_EXT_FUNC_DEF
+#undef LOAD_FUNC
const char *extString = (const char *)g_context.glGetString(GL_EXTENSIONS);
diff --git a/backends/graphics/opengl/opengl-func.h b/backends/graphics/opengl/opengl-func.h
index f870214754..c85d936497 100644
--- a/backends/graphics/opengl/opengl-func.h
+++ b/backends/graphics/opengl/opengl-func.h
@@ -58,11 +58,18 @@
* does not contain include guards because it can be required to include it
* multiple times in a source file.
*
- * Functions are defined by two different user supplied macros:
- * GL_FUNC_DEF: Define a (builtin) OpenGL (ES) function.
+ * Functions are defined by three different user supplied macros:
+ * GL_FUNC_DEF: Define a (builtin) OpenGL (ES) function.
+ * GL_FUNC_2_DEF: Define a OpenGL (ES) 2.0 function which can be provided by
+ * extensions in OpenGL 1.x contexts.
* GL_EXT_FUNC_DEF: Define an OpenGL (ES) extension function.
*/
+#if !defined(GL_FUNC_2_DEF)
+#define GL_FUNC_2_DEF(ret, name, extName, param) GL_FUNC_DEF(ret, name, param)
+#define DEFINED_GL_FUNC_2_DEF
+#endif
+
#if !defined(GL_EXT_FUNC_DEF)
#define GL_EXT_FUNC_DEF(ret, name, param) GL_FUNC_DEF(ret, name, param)
#define DEFINED_GL_EXT_FUNC_DEF
@@ -97,11 +104,15 @@ GL_FUNC_DEF(void, glTexSubImage2D, (GLenum target, GLint level, GLint xoffset, G
GL_FUNC_DEF(const GLubyte *, glGetString, (GLenum name));
GL_FUNC_DEF(GLenum, glGetError, ());
+#if !USE_FORCED_GLES
+GL_FUNC_2_DEF(void, glEnableVertexAttribArray, glEnableVertexAttribArrayARB, (GLuint index));
+GL_FUNC_2_DEF(void, glUniform1i, glUniform1iARB, (GLint location, GLint v0));
+GL_FUNC_2_DEF(void, glUniformMatrix4fv, glUniformMatrix4fvARB, (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value));
+GL_FUNC_2_DEF(void, glVertexAttrib4f, glVertexAttrib4fARB, (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w));
+GL_FUNC_2_DEF(void, glVertexAttribPointer, glVertexAttribPointerARB, (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer));
+#endif
+
#if !USE_FORCED_GL && !USE_FORCED_GLES
-GL_FUNC_DEF(void, glVertexAttrib4f, (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w));
-GL_FUNC_DEF(void, glVertexAttribPointer, (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer));
-GL_FUNC_DEF(void, glUniformMatrix4fv, (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value));
-GL_FUNC_DEF(void, glUniform1i, (GLint location, GLint v0));
GL_FUNC_DEF(void, glDeleteProgram, (GLuint program));
GL_FUNC_DEF(void, glDeleteShader, (GLuint shader));
GL_FUNC_DEF(GLuint, glCreateProgram, ());
@@ -118,7 +129,6 @@ GL_FUNC_DEF(void, glShaderSource, (GLuint shader, GLsizei count, const GLchar *c
GL_FUNC_DEF(void, glCompileShader, (GLuint shader));
GL_FUNC_DEF(void, glGetShaderiv, (GLuint shader, GLenum pname, GLint *params));
GL_FUNC_DEF(void, glGetShaderInfoLog, (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog));
-GL_FUNC_DEF(void, glEnableVertexAttribArray, (GLuint index));
GL_FUNC_DEF(void, glActiveTexture, (GLenum texture));
#endif
@@ -133,17 +143,17 @@ GL_EXT_FUNC_DEF(void, glGetObjectParameterivARB, (GLhandleARB obj, GLenum pname,
GL_EXT_FUNC_DEF(GLint, glGetUniformLocationARB, (GLhandleARB programObj, const GLcharARB *name));
GL_EXT_FUNC_DEF(void, glGetInfoLogARB, (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog));
GL_EXT_FUNC_DEF(void, glUseProgramObjectARB, (GLhandleARB programObj));
-GL_EXT_FUNC_DEF(void, glUniformMatrix4fvARB, (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value));
-GL_EXT_FUNC_DEF(void, glUniform1iARB, (GLint location, GLint v0));
GL_EXT_FUNC_DEF(GLhandleARB, glCreateShaderObjectARB, (GLenum shaderType));
GL_EXT_FUNC_DEF(void, glShaderSourceARB, (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length));
GL_EXT_FUNC_DEF(void, glCompileShaderARB, (GLhandleARB shaderObj));
-GL_EXT_FUNC_DEF(void, glVertexAttribPointerARB, (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer));
-GL_EXT_FUNC_DEF(void, glVertexAttrib4fARB, (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w));
-GL_EXT_FUNC_DEF(void, glEnableVertexAttribArrayARB, (GLuint index));
#endif
#ifdef DEFINED_GL_EXT_FUNC_DEF
#undef DEFINED_GL_EXT_FUNC_DEF
#undef GL_EXT_FUNC_DEF
#endif
+
+#ifdef DEFINED_GL_FUNC_2_DEF
+#undef DEFINED_GL_FUNC_2_DEF
+#undef GL_FUNC_2_DEF
+#endif
diff --git a/backends/graphics/opengl/shader.cpp b/backends/graphics/opengl/shader.cpp
index d7fc20574b..7fdebed493 100644
--- a/backends/graphics/opengl/shader.cpp
+++ b/backends/graphics/opengl/shader.cpp
@@ -167,10 +167,10 @@ void ShaderARB::activate(const GLfloat *projectionMatrix) {
GL_CALL(glUseProgramObjectARB(_program));
// Set projection matrix.
- GL_CALL(glUniformMatrix4fvARB(_projectionLocation, 1, GL_FALSE, projectionMatrix));
+ GL_CALL(glUniformMatrix4fv(_projectionLocation, 1, GL_FALSE, projectionMatrix));
// We always use texture unit 0.
- GL_CALL(glUniform1iARB(_textureLocation, 0));
+ GL_CALL(glUniform1i(_textureLocation, 0));
}
GLhandleARB ShaderARB::compileShader(const char *source, GLenum shaderType) {