OPENGL: Introduce pipeline abstraction to cleanup code.

This commit is contained in:
Johannes Schickel 2016-01-04 06:41:10 +01:00
parent 08553a09cf
commit f5f1b6eba0
8 changed files with 227 additions and 103 deletions

View file

@ -23,6 +23,7 @@
#include "backends/graphics/opengl/opengl-sys.h"
#include "backends/graphics/opengl/opengl-graphics.h"
#include "backends/graphics/opengl/shader.h"
#include "backends/graphics/opengl/pipeline.h"
#include "common/tokenizer.h"
#include "common/debug.h"
@ -40,94 +41,19 @@ void Context::reset() {
#define GL_FUNC_DEF(ret, name, param) name = nullptr;
#include "backends/graphics/opengl/opengl-func.h"
#undef GL_FUNC_DEF
activePipeline = nullptr;
}
void Context::initializePipeline() {
#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
if (g_context.type != kContextGLES2) {
#endif
#if !USE_FORCED_GLES2
GL_CALL(glDisable(GL_LIGHTING));
GL_CALL(glDisable(GL_FOG));
GL_CALL(glShadeModel(GL_FLAT));
GL_CALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST));
#endif
#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
}
#endif
Pipeline *Context::setPipeline(Pipeline *pipeline) {
Pipeline *oldPipeline = activePipeline;
// Enable rendering with vertex and coord arrays.
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
if (g_context.shadersSupported) {
#endif
#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
activePipeline = pipeline;
if (activePipeline) {
activePipeline->activate();
}
#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
GL_CALL(glEnable(GL_TEXTURE_2D));
#endif
#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2
}
#endif
}
void Context::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
if (g_context.shadersSupported) {
#endif
#if !USE_FORCED_GLES
GL_CALL(glVertexAttrib4f(kColorAttribLocation, r, g, b, a));
#endif
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
} else {
#endif
#if !USE_FORCED_GLES2
GL_CALL(glColor4f(r, g, b, a));
#endif
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
}
#endif
}
void Context::setDrawCoordinates(const GLfloat *vertices, const GLfloat *texCoords) {
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
if (g_context.shadersSupported) {
#endif
#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_GLES && !USE_FORCED_GLES2
} else {
#endif
#if !USE_FORCED_GLES2
GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texCoords));
GL_CALL(glVertexPointer(2, GL_FLOAT, 0, vertices));
#endif
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
}
#endif
return oldPipeline;
}
Context g_context;