diff options
Diffstat (limited to 'backends/graphics/opengl')
-rw-r--r-- | backends/graphics/opengl/context.cpp | 103 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 78 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.h | 8 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-sys.h | 20 | ||||
-rw-r--r-- | backends/graphics/opengl/texture.cpp | 28 |
5 files changed, 130 insertions, 107 deletions
diff --git a/backends/graphics/opengl/context.cpp b/backends/graphics/opengl/context.cpp index a58a5e060a..905532c8be 100644 --- a/backends/graphics/opengl/context.cpp +++ b/backends/graphics/opengl/context.cpp @@ -22,6 +22,7 @@ #include "backends/graphics/opengl/opengl-sys.h" #include "backends/graphics/opengl/opengl-graphics.h" +#include "backends/graphics/opengl/shader.h" #include "common/tokenizer.h" @@ -38,6 +39,108 @@ void Context::reset() { #undef GL_FUNC_DEF } +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 + +#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(glEnableVertexAttribArray(kPositionAttribLocation)); + GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); + + 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 + } +#endif +} + +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) { +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES + GL_CALL(glVertexAttrib4f(kColorAttribLocation, r, g, b, a)); +#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(glVertexAttrib4fARB(kColorAttribLocation, r, g, b, a)); + } else { +#endif + GL_CALL(glColor4f(r, g, b, a)); +#if !USE_FORCED_GLES + } +#endif +#endif +#if !USE_FORCED_GL && !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) { +#endif +#if !USE_FORCED_GL && !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 + } 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 + } +#endif +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } +#endif +} + Context g_context; void OpenGLGraphicsManager::setContextType(ContextType type) { diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 624a5561b5..6d693a3a27 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -425,13 +425,13 @@ void OpenGLGraphicsManager::updateScreen() { } // Set the OSD transparency. - setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); + g_context.setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); // Draw the OSD texture. _osd->draw(0, 0, _outputScreenWidth, _outputScreenHeight); // Reset color. - setColor(1.0f, 1.0f, 1.0f, 1.0f); + g_context.setColor(1.0f, 1.0f, 1.0f, 1.0f); } #endif @@ -873,58 +873,16 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def GL_CALL(glDisable(GL_DEPTH_TEST)); GL_CALL(glDisable(GL_DITHER)); -#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 - // Default to black as clear color. GL_CALL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); - setColor(1.0f, 1.0f, 1.0f, 1.0f); + g_context.setColor(1.0f, 1.0f, 1.0f, 1.0f); // Setup alpha blend (for overlay and cursor). GL_CALL(glEnable(GL_BLEND)); GL_CALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#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(glEnableVertexAttribArray(kPositionAttribLocation)); - GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); - - 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 - } -#endif + // Initialize the context specific state of the pipeline. + g_context.initializePipeline(); // Setup scissor state accordingly. if (_overlayVisible) { @@ -1102,32 +1060,6 @@ Texture *OpenGLGraphicsManager::createTexture(const Graphics::PixelFormat &forma } } -void OpenGLGraphicsManager::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { -#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(glVertexAttrib4f(kColorAttribLocation, r, g, b, a)); -#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(glVertexAttrib4fARB(kColorAttribLocation, r, g, b, a)); - } else { -#endif - GL_CALL(glColor4f(r, g, b, a)); -#if !USE_FORCED_GLES - } -#endif -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - } -#endif -} - bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelFormat, GLenum &glIntFormat, GLenum &glFormat, GLenum &glType) const { #ifdef SCUMM_LITTLE_ENDIAN if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888 diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 55e18cf7f0..b6e3c1321b 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -303,14 +303,6 @@ private: */ void initializeGLContext(); - /** - * Set color which shall be multiplied with each pixel. - * - * This serves as a wrapper around glColor4f for fixed-function and our - * shader pipeline. - */ - void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a); - protected: /** * Query the address of an OpenGL function by name. diff --git a/backends/graphics/opengl/opengl-sys.h b/backends/graphics/opengl/opengl-sys.h index 239512bc8a..bae318f393 100644 --- a/backends/graphics/opengl/opengl-sys.h +++ b/backends/graphics/opengl/opengl-sys.h @@ -101,6 +101,26 @@ struct Context { #define GL_FUNC_DEF(ret, name, param) ret (GL_CALL_CONV *name)param #include "backends/graphics/opengl/opengl-func.h" #undef GL_FUNC_DEF + + // + // Wrapper functionality to handle fixed-function pipelines and + // programmable pipelines in the same fashion. + // + + /** + * Initializes the pipeline state. + */ + void initializePipeline(); + + /** + * Set color which shall be multiplied with each pixel. + */ + void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a); + + /** + * Set vertex and texture coordinates. + */ + void setDrawCoordinates(const GLfloat *vertices, const GLfloat *texCoords); }; /** diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp index e394f760f9..08f5e69f03 100644 --- a/backends/graphics/opengl/texture.cpp +++ b/backends/graphics/opengl/texture.cpp @@ -195,32 +195,8 @@ void Texture::draw(GLfloat x, GLfloat y, GLfloat w, GLfloat h) { x + w, y + h }; -#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(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 - } 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 - } -#endif -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - } -#endif + // Setup coordinates for drawing. + g_context.setDrawCoordinates(vertices, texcoords); // Draw the texture to the screen buffer. GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); |