From fe2ee9ecf5709d49279265f0e5d3b2d0a5688265 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 11 Dec 2015 19:23:41 +0100 Subject: OPENGL: Refactor screen refresh handling. Subclasses of OpenGLGraphicsManager are now supposed to supply a refreshScreen function which handles actual screen updating (for example, buffer swapping). --- backends/graphics/opengl/opengl-graphics.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 5821856c30..301813c23f 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -431,6 +431,8 @@ void OpenGLGraphicsManager::updateScreen() { GLCALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); } #endif + + refreshScreen(); } Graphics::Surface *OpenGLGraphicsManager::lockScreen() { -- cgit v1.2.3 From f65a8b26898db3bd870010fc3a0b0b71e50e16b7 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 11 Dec 2015 19:54:47 +0100 Subject: OPENGL: Only redraw screen when actual changes happened. --- backends/graphics/opengl/opengl-graphics.cpp | 35 ++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 301813c23f..05e24675fd 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -51,7 +51,8 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() _overlayVisible(false), _cursor(nullptr), _cursorX(0), _cursorY(0), _cursorDisplayX(0),_cursorDisplayY(0), _cursorHotspotX(0), _cursorHotspotY(0), _cursorHotspotXScaled(0), _cursorHotspotYScaled(0), _cursorWidthScaled(0), _cursorHeightScaled(0), - _cursorKeyColor(0), _cursorVisible(false), _cursorDontScale(false), _cursorPaletteEnabled(false) + _cursorKeyColor(0), _cursorVisible(false), _cursorDontScale(false), _cursorPaletteEnabled(false), + _forceRedraw(false) #ifdef USE_OSD , _osdAlpha(0), _osdFadeStartTime(0), _osd(nullptr) #endif @@ -343,7 +344,10 @@ void OpenGLGraphicsManager::fillScreen(uint32 col) { } void OpenGLGraphicsManager::setShakePos(int shakeOffset) { - _gameScreenShakeOffset = shakeOffset; + if (_gameScreenShakeOffset != shakeOffset) { + _gameScreenShakeOffset = shakeOffset; + _forceRedraw = true; + } } void OpenGLGraphicsManager::updateScreen() { @@ -351,6 +355,16 @@ void OpenGLGraphicsManager::updateScreen() { return; } + // We only update the screen when there actually have been any changes. + if ( !_forceRedraw + && !_gameScreen->isDirty() + && !(_overlayVisible && _overlay->isDirty()) + && !(_cursorVisible && _cursor && _cursor->isDirty()) + && _osdAlpha == 0) { + return; + } + _forceRedraw = false; + // Clear the screen buffer. GLCALL(glClear(GL_COLOR_BUFFER_BIT)); @@ -467,6 +481,7 @@ int16 OpenGLGraphicsManager::getOverlayHeight() { void OpenGLGraphicsManager::showOverlay() { _overlayVisible = true; + _forceRedraw = true; // Update cursor position. setMousePosition(_cursorX, _cursorY); @@ -474,6 +489,7 @@ void OpenGLGraphicsManager::showOverlay() { void OpenGLGraphicsManager::hideOverlay() { _overlayVisible = false; + _forceRedraw = true; // Update cursor position. setMousePosition(_cursorX, _cursorY); @@ -505,6 +521,12 @@ void OpenGLGraphicsManager::grabOverlay(void *buf, int pitch) { } bool OpenGLGraphicsManager::showMouse(bool visible) { + // In case the mouse cursor visibility changed we need to redraw the whole + // screen even when nothing else changed. + if (_cursorVisible != visible) { + _forceRedraw = true; + } + bool last = _cursorVisible; _cursorVisible = visible; return last; @@ -940,6 +962,12 @@ void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) { } void OpenGLGraphicsManager::setMousePosition(int x, int y) { + // Whenever the mouse position changed we force a screen redraw to reflect + // changes properly. + if (_cursorX != x || _cursorY != y) { + _forceRedraw = true; + } + _cursorX = x; _cursorY = y; @@ -1100,6 +1128,9 @@ void OpenGLGraphicsManager::recalculateDisplayArea() { // Update the cursor position to adjust for new display area. setMousePosition(_cursorX, _cursorY); + + // Force a redraw to assure screen is properly redrawn. + _forceRedraw = true; } void OpenGLGraphicsManager::updateCursorPalette() { -- cgit v1.2.3 From 693834e8c6e9bf01925dc1731dad44d15f880be9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 11 Dec 2015 21:22:42 +0100 Subject: OPENGL: Implement black borders using scissor test. --- backends/graphics/opengl/opengl-graphics.cpp | 90 +++++++++++++--------------- 1 file changed, 42 insertions(+), 48 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 05e24675fd..df74e110bb 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -52,7 +52,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() _cursorX(0), _cursorY(0), _cursorDisplayX(0),_cursorDisplayY(0), _cursorHotspotX(0), _cursorHotspotY(0), _cursorHotspotXScaled(0), _cursorHotspotYScaled(0), _cursorWidthScaled(0), _cursorHeightScaled(0), _cursorKeyColor(0), _cursorVisible(false), _cursorDontScale(false), _cursorPaletteEnabled(false), - _forceRedraw(false) + _forceRedraw(false), _scissorOverride(3) #ifdef USE_OSD , _osdAlpha(0), _osdFadeStartTime(0), _osd(nullptr) #endif @@ -366,7 +366,19 @@ void OpenGLGraphicsManager::updateScreen() { _forceRedraw = false; // Clear the screen buffer. - GLCALL(glClear(GL_COLOR_BUFFER_BIT)); + if (_scissorOverride) { + // In certain cases we need to assure that the whole screen area is + // cleared. For example, when switching from overlay visible to + // invisible, we need to assure that all contents are cleared to + // properly remove all overlay contents. + GLCALL(glDisable(GL_SCISSOR_TEST)); + GLCALL(glClear(GL_COLOR_BUFFER_BIT)); + GLCALL(glEnable(GL_SCISSOR_TEST)); + + --_scissorOverride; + } else { + GLCALL(glClear(GL_COLOR_BUFFER_BIT)); + } const GLfloat shakeOffset = _gameScreenShakeOffset * (GLfloat)_displayHeight / _gameScreen->getHeight(); @@ -389,37 +401,8 @@ void OpenGLGraphicsManager::updateScreen() { _cursorWidthScaled, _cursorHeightScaled); } - // Fourth step: Draw black borders around the game screen when no overlay - // is visible. This makes sure that the mouse cursor etc. is only drawn - // in the actual game screen area in this case. - if (!_overlayVisible) { - GLCALL(glColor4f(0.0f, 0.0f, 0.0f, 1.0f)); - - GLCALL(glDisable(GL_TEXTURE_2D)); - GLCALL(glDisableClientState(GL_TEXTURE_COORD_ARRAY)); - - // Top border. - drawRect(0, 0, _outputScreenWidth, _displayY); - - // Left border. - drawRect(0, 0, _displayX, _outputScreenHeight); - - // Bottom border. - const int y = _displayY + _displayHeight; - drawRect(0, y, _outputScreenWidth, _outputScreenHeight - y); - - // Right border. - const int x = _displayX + _displayWidth; - drawRect(x, 0, _outputScreenWidth - x, _outputScreenHeight); - - GLCALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - GLCALL(glEnable(GL_TEXTURE_2D)); - - GLCALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); - } - #ifdef USE_OSD - // Fifth step: Draw the OSD. + // Fourth step: Draw the OSD. if (_osdAlpha > 0) { Common::StackLock lock(_osdMutex); @@ -483,6 +466,9 @@ void OpenGLGraphicsManager::showOverlay() { _overlayVisible = true; _forceRedraw = true; + // Allow drawing inside full screen area. + GLCALL(glDisable(GL_SCISSOR_TEST)); + // Update cursor position. setMousePosition(_cursorX, _cursorY); } @@ -491,6 +477,10 @@ void OpenGLGraphicsManager::hideOverlay() { _overlayVisible = false; _forceRedraw = true; + // Limit drawing to screen area. + GLCALL(glEnable(GL_SCISSOR_TEST)); + _scissorOverride = 3; + // Update cursor position. setMousePosition(_cursorX, _cursorY); } @@ -875,6 +865,16 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def GLCALL(glEnable(GL_TEXTURE_2D)); + // Setup scissor state accordingly. + if (_overlayVisible) { + GLCALL(glDisable(GL_SCISSOR_TEST)); + } else { + GLCALL(glEnable(GL_SCISSOR_TEST)); + } + // Clear the whole screen for the first three frames to assure any + // leftovers are cleared. + _scissorOverride = 3; + // We use a "pack" alignment (when reading from textures) to 4 here, // since the only place where we really use it is the BMP screenshot // code and that requires the same alignment too. @@ -1126,6 +1126,16 @@ void OpenGLGraphicsManager::recalculateDisplayArea() { _displayX = (_outputScreenWidth - _displayWidth ) / 2; _displayY = (_outputScreenHeight - _displayHeight) / 2; + // Setup drawing limitation for game graphics. + // This invovles some trickery because OpenGL's viewport coordinate system + // is upside down compared to ours. + GLCALL(glScissor(_displayX, + _outputScreenHeight - _displayHeight - _displayY, + _displayWidth, + _displayHeight)); + // Clear the whole screen for the first three frames to remove leftovers. + _scissorOverride = 3; + // Update the cursor position to adjust for new display area. setMousePosition(_cursorX, _cursorY); @@ -1248,20 +1258,4 @@ void OpenGLGraphicsManager::saveScreenshot(const Common::String &filename) const delete[] pixels; } -void OpenGLGraphicsManager::drawRect(GLfloat x, GLfloat y, GLfloat w, GLfloat h) { - if (w < 0 || h < 0) { - return; - } - - const GLfloat vertices[4*2] = { - x, y, - x + w, y, - x, y + h, - x + w, y + h - }; - GLCALL(glVertexPointer(2, GL_FLOAT, 0, vertices)); - - GLCALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); -} - } // End of namespace OpenGL -- cgit v1.2.3 From 942d0fdad46d2105f1606ddea8cd9146acec70d8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 13 Dec 2015 19:05:18 +0100 Subject: OPENGL: Limit scissor override to invisible overlay. This fixes some corner cases which caused black bars to appear for a few screen updates when the overlay is visible. --- backends/graphics/opengl/opengl-graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index df74e110bb..c80f57a40e 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -366,7 +366,7 @@ void OpenGLGraphicsManager::updateScreen() { _forceRedraw = false; // Clear the screen buffer. - if (_scissorOverride) { + if (_scissorOverride && !_overlayVisible) { // In certain cases we need to assure that the whole screen area is // cleared. For example, when switching from overlay visible to // invisible, we need to assure that all contents are cleared to -- cgit v1.2.3 From 64f9c902ddf0c8294fd9e5f66cf96661eb12040b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 14 Dec 2015 20:09:29 +0100 Subject: OPENGL: Smooth mouse experience when black bars are visible. This gets rid of the feeling of the mouse sticking to black borders by using the full output resolution as area for tracking game mouse movement. The same behavior is present in plain SDL output with SDL2. --- backends/graphics/opengl/opengl-graphics.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index c80f57a40e..ac6d41d47d 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -551,11 +551,8 @@ void OpenGLGraphicsManager::warpMouse(int x, int y) { return; } - x = (x * _displayWidth) / _gameScreen->getWidth(); - y = (y * _displayHeight) / _gameScreen->getHeight(); - - x += _displayX; - y += _displayY; + x = (x * _outputScreenWidth) / _gameScreen->getWidth(); + y = (y * _outputScreenHeight) / _gameScreen->getHeight(); } setMousePosition(x, y); @@ -946,18 +943,11 @@ void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) { y = (y * _overlay->getHeight()) / _outputScreenHeight; } } else if (_gameScreen) { - x -= _displayX; - y -= _displayY; - const int16 width = _gameScreen->getWidth(); const int16 height = _gameScreen->getHeight(); - x = (x * width) / (int)_displayWidth; - y = (y * height) / (int)_displayHeight; - - // Make sure we only supply valid coordinates. - x = CLIP(x, 0, width - 1); - y = CLIP(y, 0, height - 1); + x = (x * width) / (int)_outputScreenWidth; + y = (y * height) / (int)_outputScreenHeight; } } @@ -975,8 +965,8 @@ void OpenGLGraphicsManager::setMousePosition(int x, int y) { _cursorDisplayX = x; _cursorDisplayY = y; } else { - _cursorDisplayX = CLIP(x, _displayX, _displayX + _displayWidth - 1); - _cursorDisplayY = CLIP(y, _displayY, _displayY + _displayHeight - 1); + _cursorDisplayX = _displayX + (x * _displayWidth) / _outputScreenWidth; + _cursorDisplayY = _displayY + (y * _displayHeight) / _outputScreenHeight; } } -- cgit v1.2.3 From e5e234b864e75862a2de72ee6c3b8bda47f41c23 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 10 Dec 2015 16:42:56 +0100 Subject: OPENGL: Refactor GL extension handling slightly. --- backends/graphics/opengl/opengl-graphics.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index ac6d41d47d..d738f31a37 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -58,6 +58,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); + g_extensions.reset(); } OpenGLGraphicsManager::~OpenGLGraphicsManager() { -- cgit v1.2.3 From b3b3d37e3b8231ec345a2d4172279373d53a0c79 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 11 Dec 2015 23:58:11 +0100 Subject: OPENGL: Define GLCALL in opengl-sys.h. debug.h is now always included and all calls should be made through GLCALL. --- backends/graphics/opengl/opengl-graphics.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index d738f31a37..54c4906413 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -23,7 +23,6 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/texture.h" -#include "backends/graphics/opengl/debug.h" #include "backends/graphics/opengl/extensions.h" #include "common/textconsole.h" -- cgit v1.2.3 From 4a781737c1da77015df4547f64f2f88966816343 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 12 Dec 2015 01:18:46 +0100 Subject: OPENGL: Resolve OpenGL functions on run-time. Formerly we relied on static linkage. However, in the presense of modern OpenGL (ES) implementations it is not easily identifable which library to link against. For example, on Linux amd64 with nVidia drivers and SDL2 setup to create a GLES 1.1 context one would need to link against libGL.so. However, traditionally GLES 1.1 required to link against libGLESv1_CM.so. To prevent a huge mess we simply resolve the OpenGL functions on run-time now and stop linking against a static library (in most cases). GLES support needs to be enabled manually on configure time for now. Tizen changes have NOT been tested. --- backends/graphics/opengl/opengl-graphics.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 54c4906413..2af7da5f1f 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -23,7 +23,6 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/texture.h" -#include "backends/graphics/opengl/extensions.h" #include "common/textconsole.h" #include "common/translation.h" @@ -57,7 +56,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); - g_extensions.reset(); + g_context.reset(); } OpenGLGraphicsManager::~OpenGLGraphicsManager() { @@ -836,8 +835,8 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { } void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha) { - // Initialize all extensions. - initializeGLExtensions(); + // Initialize context for use. + initializeGLContext(); // Disable 3D properties. GLCALL(glDisable(GL_CULL_FACE)); -- cgit v1.2.3 From e11f4df1118eb0858f4d3bfda697e63174d5e2d1 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 12 Dec 2015 03:22:51 +0100 Subject: OPENGL: Rename GLCALL to GL_CALL. --- backends/graphics/opengl/opengl-graphics.cpp | 68 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 2af7da5f1f..34d4ca888c 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -370,13 +370,13 @@ void OpenGLGraphicsManager::updateScreen() { // cleared. For example, when switching from overlay visible to // invisible, we need to assure that all contents are cleared to // properly remove all overlay contents. - GLCALL(glDisable(GL_SCISSOR_TEST)); - GLCALL(glClear(GL_COLOR_BUFFER_BIT)); - GLCALL(glEnable(GL_SCISSOR_TEST)); + GL_CALL(glDisable(GL_SCISSOR_TEST)); + GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); + GL_CALL(glEnable(GL_SCISSOR_TEST)); --_scissorOverride; } else { - GLCALL(glClear(GL_COLOR_BUFFER_BIT)); + GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); } const GLfloat shakeOffset = _gameScreenShakeOffset * (GLfloat)_displayHeight / _gameScreen->getHeight(); @@ -418,13 +418,13 @@ void OpenGLGraphicsManager::updateScreen() { } // Set the OSD transparency. - GLCALL(glColor4f(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f)); + GL_CALL(glColor4f(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f)); // Draw the OSD texture. _osd->draw(0, 0, _outputScreenWidth, _outputScreenHeight); // Reset color. - GLCALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); + GL_CALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); } #endif @@ -466,7 +466,7 @@ void OpenGLGraphicsManager::showOverlay() { _forceRedraw = true; // Allow drawing inside full screen area. - GLCALL(glDisable(GL_SCISSOR_TEST)); + GL_CALL(glDisable(GL_SCISSOR_TEST)); // Update cursor position. setMousePosition(_cursorX, _cursorY); @@ -477,7 +477,7 @@ void OpenGLGraphicsManager::hideOverlay() { _forceRedraw = true; // Limit drawing to screen area. - GLCALL(glEnable(GL_SCISSOR_TEST)); + GL_CALL(glEnable(GL_SCISSOR_TEST)); _scissorOverride = 3; // Update cursor position. @@ -755,17 +755,17 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { _outputScreenHeight = height; // Setup coordinates system. - GLCALL(glViewport(0, 0, _outputScreenWidth, _outputScreenHeight)); + GL_CALL(glViewport(0, 0, _outputScreenWidth, _outputScreenHeight)); - GLCALL(glMatrixMode(GL_PROJECTION)); - GLCALL(glLoadIdentity()); + GL_CALL(glMatrixMode(GL_PROJECTION)); + GL_CALL(glLoadIdentity()); #ifdef USE_GLES - GLCALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); + GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); #else - GLCALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); + GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); #endif - GLCALL(glMatrixMode(GL_MODELVIEW)); - GLCALL(glLoadIdentity()); + GL_CALL(glMatrixMode(GL_MODELVIEW)); + GL_CALL(glLoadIdentity()); uint overlayWidth = width; uint overlayHeight = height; @@ -839,33 +839,33 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def initializeGLContext(); // Disable 3D properties. - GLCALL(glDisable(GL_CULL_FACE)); - GLCALL(glDisable(GL_DEPTH_TEST)); - GLCALL(glDisable(GL_LIGHTING)); - GLCALL(glDisable(GL_FOG)); - GLCALL(glDisable(GL_DITHER)); - GLCALL(glShadeModel(GL_FLAT)); - GLCALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); + GL_CALL(glDisable(GL_CULL_FACE)); + GL_CALL(glDisable(GL_DEPTH_TEST)); + GL_CALL(glDisable(GL_LIGHTING)); + GL_CALL(glDisable(GL_FOG)); + GL_CALL(glDisable(GL_DITHER)); + GL_CALL(glShadeModel(GL_FLAT)); + GL_CALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); // Default to black as clear color. - GLCALL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); - GLCALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); + GL_CALL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); + GL_CALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); // Setup alpha blend (for overlay and cursor). - GLCALL(glEnable(GL_BLEND)); - GLCALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + GL_CALL(glEnable(GL_BLEND)); + GL_CALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); // Enable rendering with vertex and coord arrays. - GLCALL(glEnableClientState(GL_VERTEX_ARRAY)); - GLCALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); + GL_CALL(glEnableClientState(GL_VERTEX_ARRAY)); + GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - GLCALL(glEnable(GL_TEXTURE_2D)); + GL_CALL(glEnable(GL_TEXTURE_2D)); // Setup scissor state accordingly. if (_overlayVisible) { - GLCALL(glDisable(GL_SCISSOR_TEST)); + GL_CALL(glDisable(GL_SCISSOR_TEST)); } else { - GLCALL(glEnable(GL_SCISSOR_TEST)); + GL_CALL(glEnable(GL_SCISSOR_TEST)); } // Clear the whole screen for the first three frames to assure any // leftovers are cleared. @@ -874,7 +874,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // We use a "pack" alignment (when reading from textures) to 4 here, // since the only place where we really use it is the BMP screenshot // code and that requires the same alignment too. - GLCALL(glPixelStorei(GL_PACK_ALIGNMENT, 4)); + GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 4)); // Query information needed by textures. Texture::queryTextureInformation(); @@ -1118,7 +1118,7 @@ void OpenGLGraphicsManager::recalculateDisplayArea() { // Setup drawing limitation for game graphics. // This invovles some trickery because OpenGL's viewport coordinate system // is upside down compared to ours. - GLCALL(glScissor(_displayX, + GL_CALL(glScissor(_displayX, _outputScreenHeight - _displayHeight - _displayY, _displayWidth, _displayHeight)); @@ -1206,7 +1206,7 @@ void OpenGLGraphicsManager::saveScreenshot(const Common::String &filename) const uint8 *pixels = new uint8[lineSize * height]; // Get pixel data from OpenGL buffer - GLCALL(glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels)); + GL_CALL(glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels)); // BMP stores as BGR. Since we can't assume that GL_BGR is supported we // will swap the components from the RGB we read to BGR on our own. -- cgit v1.2.3 From 9816e4f35035b6fa461dc1bc255ced533f5feaf9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 12 Dec 2015 04:00:09 +0100 Subject: OPENGL: Remove support for ARGB8888. This used to be used by Sword25. Since it is not supported by GLES and no engine code uses it we drop support. Hopefully, this helps people to realize they should not use that format in their engine. --- backends/graphics/opengl/opengl-graphics.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 34d4ca888c..1024ee546e 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -1029,11 +1029,6 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_BGRA; glType = GL_UNSIGNED_SHORT_1_5_5_5_REV; return true; - } else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24)) { // ARGB8888 - glIntFormat = GL_RGBA; - glFormat = GL_BGRA; - glType = GL_UNSIGNED_INT_8_8_8_8_REV; - return true; } else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)) { // ARGB4444 glIntFormat = GL_RGBA; glFormat = GL_BGRA; -- cgit v1.2.3 From d6d3e17d53754acedce0b1706e73f929d29b5eb8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 12 Dec 2015 22:08:33 +0100 Subject: OPENGL: Allow runtime specification of OpenGL mode. Formerly, we required that the OpenGL mode was fixed at compile time. Now we allow the code to work with whatever it is given at runtime. It is still possible to force a context type on compile time. --- backends/graphics/opengl/opengl-graphics.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 1024ee546e..78ae27d8a6 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -759,10 +759,16 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { GL_CALL(glMatrixMode(GL_PROJECTION)); GL_CALL(glLoadIdentity()); -#ifdef USE_GLES +#if USE_FORCED_GLES GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); -#else +#elif USE_FORCED_GL GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); +#else + if (isGLESContext()) { + GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); + } else { + GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); + } #endif GL_CALL(glMatrixMode(GL_MODELVIEW)); GL_CALL(glLoadIdentity()); @@ -834,9 +840,9 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { ++_screenChangeID; } -void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha) { +void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type) { // Initialize context for use. - initializeGLContext(); + initializeGLContext(type); // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); @@ -1014,7 +1020,11 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_4_4_4_4; return true; -#ifndef USE_GLES +#if !USE_FORCED_GLES + // The formats below are not supported by every GLES implementation. + // Thus, we do not mark them as supported when a GLES context is setup. + } else if (isGLESContext()) { + return false; #ifdef SCUMM_LITTLE_ENDIAN } else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888 glIntFormat = GL_RGBA; @@ -1023,8 +1033,6 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF return true; #endif } else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) { // RGB555 - // GL_BGRA does not exist in every GLES implementation so should not be configured if - // USE_GLES is set. glIntFormat = GL_RGB; glFormat = GL_BGRA; glType = GL_UNSIGNED_SHORT_1_5_5_5_REV; @@ -1066,7 +1074,7 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_BGRA; glType = GL_UNSIGNED_SHORT_4_4_4_4; return true; -#endif +#endif // !USE_FORCED_GLES } else { return false; } -- cgit v1.2.3 From 22771446238784eede905b5471c3ae8784523641 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 15 Dec 2015 02:48:42 +0100 Subject: OPENGL: Support RGB555 for OpenGL ES output. This mode should *not* be used by any new engines/code. If someone is going to use it and says it works with the OpenGL output, please make them wear a red uniform and beam them onto a remote planet. --- backends/graphics/opengl/opengl-graphics.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 78ae27d8a6..8db5f6a934 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -985,6 +985,15 @@ Texture *OpenGLGraphicsManager::createTexture(const Graphics::PixelFormat &forma } else { return new TextureCLUT8(glIntFormat, glFormat, glType, virtFormat); } +#if !USE_FORCED_GL + } else if (isGLESContext() && format == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) { + // OpenGL ES does not support a texture format usable for RGB555. + // Since SCUMM uses this pixel format for some games (and there is no + // hope for this to change anytime soon) we use pixel format + // conversion to a supported texture format. However, this is a one + // time exception. + return new TextureRGB555(); +#endif // !USE_FORCED_GL } else { const bool supported = getGLPixelFormat(format, glIntFormat, glFormat, glType); if (!supported) { -- cgit v1.2.3 From af727afe0ceb66eaf51985ceceb2ac842b3358ee Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 18 Dec 2015 21:14:48 +0100 Subject: OPENGL: Simplify context type setting. --- backends/graphics/opengl/opengl-graphics.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 8db5f6a934..78c6b2aff1 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -56,7 +56,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); - g_context.reset(); + g_context.reset(true); } OpenGLGraphicsManager::~OpenGLGraphicsManager() { @@ -840,9 +840,9 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { ++_screenChangeID; } -void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type) { +void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha) { // Initialize context for use. - initializeGLContext(type); + initializeGLContext(); // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); -- cgit v1.2.3 From c5ce812711c68ea546926f243b9f6f0ece8ca736 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 19 Dec 2015 18:06:10 +0100 Subject: OPENGL: Simplify orthogonal projection setup. --- backends/graphics/opengl/opengl-graphics.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 78c6b2aff1..108366744d 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -757,19 +757,17 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { // Setup coordinates system. GL_CALL(glViewport(0, 0, _outputScreenWidth, _outputScreenHeight)); + // Orthogonal projection matrix in column major order. + const GLfloat orthoProjection[4*4] = { + 2.0f / _outputScreenWidth, 0.0f , 0.0f, 0.0f, + 0.0f , -2.0f / _outputScreenHeight, 0.0f, 0.0f, + 0.0f , 0.0f , -1.0f, 0.0f, + -1.0f , 1.0f , 0.0f, 1.0f + }; + GL_CALL(glMatrixMode(GL_PROJECTION)); - GL_CALL(glLoadIdentity()); -#if USE_FORCED_GLES - GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); -#elif USE_FORCED_GL - GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); -#else - if (isGLESContext()) { - GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); - } else { - GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); - } -#endif + GL_CALL(glLoadMatrixf(orthoProjection)); + GL_CALL(glMatrixMode(GL_MODELVIEW)); GL_CALL(glLoadIdentity()); -- cgit v1.2.3 From e9310186735f34c6b085a58629b140a031d1da4e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 19 Dec 2015 18:18:35 +0100 Subject: OPENGL: Typo. --- backends/graphics/opengl/opengl-graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 108366744d..15e6f40271 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -754,7 +754,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { _outputScreenWidth = width; _outputScreenHeight = height; - // Setup coordinates system. + // Setup coordinate system. GL_CALL(glViewport(0, 0, _outputScreenWidth, _outputScreenHeight)); // Orthogonal projection matrix in column major order. -- cgit v1.2.3 From fe88375ff376cbb0d940c96ac6ec1667be4acab0 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Dec 2015 05:42:54 +0100 Subject: OPENGL: Support GLES2 contexts. --- backends/graphics/opengl/opengl-graphics.cpp | 125 +++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 17 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 15e6f40271..1b20a31363 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -23,6 +23,7 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/texture.h" +#include "backends/graphics/opengl/shader.h" #include "common/textconsole.h" #include "common/translation.h" @@ -53,6 +54,9 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() _forceRedraw(false), _scissorOverride(3) #ifdef USE_OSD , _osdAlpha(0), _osdFadeStartTime(0), _osd(nullptr) +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES + , _shader(nullptr), _projectionMatrix() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); @@ -66,6 +70,9 @@ OpenGLGraphicsManager::~OpenGLGraphicsManager() { #ifdef USE_OSD delete _osd; #endif +#if !USE_FORCED_GL && !USE_FORCED_GLES + delete _shader; +#endif } bool OpenGLGraphicsManager::hasFeature(OSystem::Feature f) { @@ -418,13 +425,13 @@ void OpenGLGraphicsManager::updateScreen() { } // Set the OSD transparency. - GL_CALL(glColor4f(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f)); + setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); // Draw the OSD texture. _osd->draw(0, 0, _outputScreenWidth, _outputScreenHeight); // Reset color. - GL_CALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); + setColor(1.0f, 1.0f, 1.0f, 1.0f); } #endif @@ -765,11 +772,29 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { -1.0f , 1.0f , 0.0f, 1.0f }; - GL_CALL(glMatrixMode(GL_PROJECTION)); - GL_CALL(glLoadMatrixf(orthoProjection)); +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + if (g_context.type != kContextGLES2) { +#endif +#if !USE_FORCED_GLES2 + GL_CALL(glMatrixMode(GL_PROJECTION)); + GL_CALL(glLoadMatrixf(orthoProjection)); - GL_CALL(glMatrixMode(GL_MODELVIEW)); - GL_CALL(glLoadIdentity()); + GL_CALL(glMatrixMode(GL_MODELVIEW)); + GL_CALL(glLoadIdentity()); +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } else { +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES + assert(sizeof(_projectionMatrix) == sizeof(orthoProjection)); + memcpy(_projectionMatrix, orthoProjection, sizeof(_projectionMatrix)); + if (_shader) { + _shader->activate(_projectionMatrix); + } +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } +#endif uint overlayWidth = width; uint overlayHeight = height; @@ -845,25 +870,51 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); GL_CALL(glDisable(GL_DEPTH_TEST)); - GL_CALL(glDisable(GL_LIGHTING)); - GL_CALL(glDisable(GL_FOG)); GL_CALL(glDisable(GL_DITHER)); - GL_CALL(glShadeModel(GL_FLAT)); - GL_CALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); + +#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)); - GL_CALL(glColor4f(1.0f, 1.0f, 1.0f, 1.0f)); + 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)); - // Enable rendering with vertex and coord arrays. - GL_CALL(glEnableClientState(GL_VERTEX_ARRAY)); - GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + if (g_context.type != kContextGLES2) { +#endif +#if !USE_FORCED_GLES2 + // Enable rendering with vertex and coord arrays. + GL_CALL(glEnableClientState(GL_VERTEX_ARRAY)); + GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); + + GL_CALL(glEnable(GL_TEXTURE_2D)); +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } else { +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES + GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation)); + GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); - GL_CALL(glEnable(GL_TEXTURE_2D)); + GL_CALL(glActiveTexture(GL_TEXTURE0)); +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } +#endif // Setup scissor state accordingly. if (_overlayVisible) { @@ -883,6 +934,22 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Query information needed by textures. Texture::queryTextureInformation(); +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + if (g_context.type == kContextGLES2) { +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES + if (!_shader) { + _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); + } + + // TODO: What do we do on failure? + _shader->recreate(); + _shader->activate(_projectionMatrix); +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } +#endif + // Refresh the output screen dimensions if some are set up. if (_outputScreenWidth != 0 && _outputScreenHeight != 0) { setActualScreenSize(_outputScreenWidth, _outputScreenHeight); @@ -931,6 +998,12 @@ void OpenGLGraphicsManager::notifyContextDestroy() { _osd->releaseInternalTexture(); } #endif + +#if !USE_FORCED_GL && !USE_FORCED_GLES + if (_shader) { + _shader->destroy(); + } +#endif } void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) { @@ -1002,6 +1075,24 @@ 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_GLES2 + GL_CALL(glColor4f(r, g, b, a)); +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 + } else { +#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 + } +#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 @@ -1027,7 +1118,7 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_4_4_4_4; return true; -#if !USE_FORCED_GLES +#if !USE_FORCED_GLES && !USE_FORCED_GLES2 // The formats below are not supported by every GLES implementation. // Thus, we do not mark them as supported when a GLES context is setup. } else if (isGLESContext()) { @@ -1081,7 +1172,7 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_BGRA; glType = GL_UNSIGNED_SHORT_4_4_4_4; return true; -#endif // !USE_FORCED_GLES +#endif // !USE_FORCED_GLES && !USE_FORCED_GLES2 } else { return false; } -- cgit v1.2.3 From 19abd8ccbba339c2ea9691ef017a447b7c47701e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Dec 2015 05:55:20 +0100 Subject: OPENGL: Reset context description on context destroy. --- backends/graphics/opengl/opengl-graphics.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 1b20a31363..7078aa896f 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -1004,6 +1004,9 @@ void OpenGLGraphicsManager::notifyContextDestroy() { _shader->destroy(); } #endif + + // Rest our context description since the context is gone soon. + g_context.reset(); } void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) { -- cgit v1.2.3 From fee1aa550203c3f46ff19afbe19a7baa4771a5cd Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Dec 2015 09:30:11 +0100 Subject: OPENGL: Add support for shaders with GL contexts. --- backends/graphics/opengl/opengl-graphics.cpp | 86 +++++++++++++++++++--------- 1 file changed, 59 insertions(+), 27 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 7078aa896f..9203390489 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -55,7 +55,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #ifdef USE_OSD , _osdAlpha(0), _osdFadeStartTime(0), _osd(nullptr) #endif -#if !USE_FORCED_GL && !USE_FORCED_GLES +#if !USE_FORCED_GLES , _shader(nullptr), _projectionMatrix() #endif { @@ -70,7 +70,7 @@ OpenGLGraphicsManager::~OpenGLGraphicsManager() { #ifdef USE_OSD delete _osd; #endif -#if !USE_FORCED_GL && !USE_FORCED_GLES +#if !USE_FORCED_GLES delete _shader; #endif } @@ -773,7 +773,8 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { }; #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - if (g_context.type != kContextGLES2) { + if (g_context.type == kContextGLES + || (g_context.type == kContextGL && !g_context.shadersSupported)) { #endif #if !USE_FORCED_GLES2 GL_CALL(glMatrixMode(GL_PROJECTION)); @@ -785,7 +786,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 } else { #endif -#if !USE_FORCED_GL && !USE_FORCED_GLES +#if !USE_FORCED_GLES assert(sizeof(_projectionMatrix) == sizeof(orthoProjection)); memcpy(_projectionMatrix, orthoProjection, sizeof(_projectionMatrix)); if (_shader) { @@ -894,23 +895,32 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def 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) { + if (g_context.type == kContextGLES2) { #endif -#if !USE_FORCED_GLES2 - // Enable rendering with vertex and coord arrays. - GL_CALL(glEnableClientState(GL_VERTEX_ARRAY)); - GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); +#if !USE_FORCED_GL && !USE_FORCED_GLES + GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation)); + GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); - GL_CALL(glEnable(GL_TEXTURE_2D)); + GL_CALL(glActiveTexture(GL_TEXTURE0)); #endif #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 } else { #endif -#if !USE_FORCED_GL && !USE_FORCED_GLES - GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation)); - GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); +#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(glActiveTexture(GL_TEXTURE0)); + GL_CALL(glEnable(GL_TEXTURE_2D)); #endif #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 } @@ -934,19 +944,33 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Query information needed by textures. Texture::queryTextureInformation(); -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - if (g_context.type == kContextGLES2) { +#if !USE_FORCED_GLES + if (!_shader) { +#if !USE_FORCED_GL && !USE_FORCED_GLES2 + if (g_context.type == kContextGLES2) { #endif -#if !USE_FORCED_GL && !USE_FORCED_GLES - if (!_shader) { - _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); +#if !USE_FORCED_GL + _shader = new ShaderGLES2(g_defaultVertexShader, g_defaultFragmentShaderGLES2); +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES2 + } else { +#endif +#if !USE_FORCED_GLES2 + if (g_context.shadersSupported) { + _shader = new ShaderARB(g_defaultVertexShader, g_defaultFragmentShaderGL); + } +#endif +#if !USE_FORCED_GL && !USE_FORCED_GLES2 } +#endif + } +#endif +#if !USE_FORCED_GLES + if (_shader) { // TODO: What do we do on failure? _shader->recreate(); _shader->activate(_projectionMatrix); -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 } #endif @@ -999,7 +1023,7 @@ void OpenGLGraphicsManager::notifyContextDestroy() { } #endif -#if !USE_FORCED_GL && !USE_FORCED_GLES +#if !USE_FORCED_GLES if (_shader) { _shader->destroy(); } @@ -1080,16 +1104,24 @@ 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) { + if (g_context.type == kContextGLES2) { #endif -#if !USE_FORCED_GLES2 - GL_CALL(glColor4f(r, g, b, a)); +#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_GL && !USE_FORCED_GLES - GL_CALL(glVertexAttrib4f(kColorAttribLocation, r, g, b, a)); +#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 } -- cgit v1.2.3 From 5752f125e1a0d334c3a5bfcea314c4ffceede640 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 21 Dec 2015 04:49:25 +0100 Subject: OPENGL: Make Context::reset explicitly reset state. --- backends/graphics/opengl/opengl-graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 9203390489..624a5561b5 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -60,7 +60,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); - g_context.reset(true); + g_context.reset(); } OpenGLGraphicsManager::~OpenGLGraphicsManager() { -- cgit v1.2.3 From c7c870bf7f269229d069d47c22b61c237737cdae Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 21 Dec 2015 05:05:37 +0100 Subject: OPENGL: (Partly) move context specific handling to Context. This does not include (most) shader setup, and projection matrices yet. --- backends/graphics/opengl/opengl-graphics.cpp | 78 ++-------------------------- 1 file changed, 5 insertions(+), 73 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') 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 -- cgit v1.2.3 From 8a3eecb73a9eb5d885e3585835db6bee738c1de5 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 21 Dec 2015 06:35:13 +0100 Subject: OPENGL: Unify shader implementation for GL and GLES2. --- backends/graphics/opengl/opengl-graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 6d693a3a27..eb9eed170c 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -908,14 +908,14 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def if (g_context.type == kContextGLES2) { #endif #if !USE_FORCED_GL - _shader = new ShaderGLES2(g_defaultVertexShader, g_defaultFragmentShaderGLES2); + _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShaderGLES2); #endif #if !USE_FORCED_GL && !USE_FORCED_GLES2 } else { #endif #if !USE_FORCED_GLES2 if (g_context.shadersSupported) { - _shader = new ShaderARB(g_defaultVertexShader, g_defaultFragmentShaderGL); + _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShaderGL); } #endif #if !USE_FORCED_GL && !USE_FORCED_GLES2 -- cgit v1.2.3 From 9844d89231de0fc2234199620390dbd057e79103 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 2 Jan 2016 02:20:28 +0100 Subject: OPENGL: Move max texture size information to Context. --- backends/graphics/opengl/opengl-graphics.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index eb9eed170c..363fe40b2f 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -221,8 +221,8 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() { // a context existing before, which means we don't know the maximum // supported texture size before this. Thus, we check whether the // requested game resolution is supported over here. - || ( _currentState.gameWidth > (uint)Texture::getMaximumTextureSize() - || _currentState.gameHeight > (uint)Texture::getMaximumTextureSize())) { + || ( _currentState.gameWidth > (uint)g_context._maxTextureSize + || _currentState.gameHeight > (uint)g_context._maxTextureSize)) { if (_transactionMode == kTransactionActive) { // Try to setup the old state in case its valid and is // actually different from the new one. @@ -806,15 +806,15 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { // possible and then scale it to the physical display size. This sounds // bad but actually all recent chips should support full HD resolution // anyway. Thus, it should not be a real issue for modern hardware. - if ( overlayWidth > (uint)Texture::getMaximumTextureSize() - || overlayHeight > (uint)Texture::getMaximumTextureSize()) { + if ( overlayWidth > (uint)g_context._maxTextureSize + || overlayHeight > (uint)g_context._maxTextureSize) { const frac_t outputAspect = intToFrac(_outputScreenWidth) / _outputScreenHeight; if (outputAspect > (frac_t)FRAC_ONE) { - overlayWidth = Texture::getMaximumTextureSize(); + overlayWidth = g_context._maxTextureSize; overlayHeight = intToFrac(overlayWidth) / outputAspect; } else { - overlayHeight = Texture::getMaximumTextureSize(); + overlayHeight = g_context._maxTextureSize; overlayWidth = fracToInt(overlayHeight * outputAspect); } } @@ -899,9 +899,6 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // code and that requires the same alignment too. GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 4)); - // Query information needed by textures. - Texture::queryTextureInformation(); - #if !USE_FORCED_GLES if (!_shader) { #if !USE_FORCED_GL && !USE_FORCED_GLES2 -- cgit v1.2.3 From db2917dde5e8aaf9514e19772b8f0f6646b18deb Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 2 Jan 2016 02:22:09 +0100 Subject: OPENGL: Fix texture format for BGR565. --- backends/graphics/opengl/opengl-graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 363fe40b2f..ffc50ec64b 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -1118,8 +1118,8 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF return true; } else if (pixelFormat == Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0)) { // BGR565 glIntFormat = GL_RGB; - glFormat = GL_BGR; - glType = GL_UNSIGNED_SHORT_5_6_5; + glFormat = GL_RGB; + glType = GL_UNSIGNED_SHORT_5_6_5_REV; return true; } else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 1, 1, 6, 11, 0)) { // BGRA5551 glIntFormat = GL_RGBA; -- cgit v1.2.3 From 618adec7b06546e81028cb9fcce6151cb388fe98 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 2 Jan 2016 05:06:32 +0100 Subject: OPENGL: Move color key handling for CLUT8 to TextureCLUT8. --- backends/graphics/opengl/opengl-graphics.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index ffc50ec64b..69af586988 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -1208,20 +1208,7 @@ void OpenGLGraphicsManager::updateCursorPalette() { _cursor->setPalette(0, 256, _gamePalette); } - // We remove all alpha bits from the palette entry of the color key. - // This makes sure its properly handled as color key. - const Graphics::PixelFormat &hardwareFormat = _cursor->getHardwareFormat(); - const uint32 aMask = (0xFF >> hardwareFormat.aLoss) << hardwareFormat.aShift; - - if (hardwareFormat.bytesPerPixel == 2) { - uint16 *palette = (uint16 *)_cursor->getPalette() + _cursorKeyColor; - *palette &= ~aMask; - } else if (hardwareFormat.bytesPerPixel == 4) { - uint32 *palette = (uint32 *)_cursor->getPalette() + _cursorKeyColor; - *palette &= ~aMask; - } else { - warning("OpenGLGraphicsManager::updateCursorPalette: Unsupported pixel depth %d", hardwareFormat.bytesPerPixel); - } + _cursor->setColorKey(_cursorKeyColor); } void OpenGLGraphicsManager::recalculateCursorScaling() { -- cgit v1.2.3 From de3846923c9a00ff6a8563e33858e12a72bfebda Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 2 Jan 2016 05:54:08 +0100 Subject: OPENGL: Introduce simple abstraction for surfaces. This is basically an interface extracted from Texture without any knowledge about any actual implementation, except for copyRectToTexture, fill, and dirty rect handling. These are convenient helpers. --- backends/graphics/opengl/opengl-graphics.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 69af586988..6784bfe6ab 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -273,9 +273,9 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() { _gameScreen = nullptr; #ifdef USE_RGB_COLOR - _gameScreen = createTexture(_currentState.gameFormat); + _gameScreen = createSurface(_currentState.gameFormat); #else - _gameScreen = createTexture(Graphics::PixelFormat::createFormatCLUT8()); + _gameScreen = createSurface(Graphics::PixelFormat::createFormatCLUT8()); #endif assert(_gameScreen); if (_gameScreen->hasPalette()) { @@ -615,7 +615,7 @@ void OpenGLGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int } else { textureFormat = _defaultFormatAlpha; } - _cursor = createTexture(textureFormat, true); + _cursor = createSurface(textureFormat, true); assert(_cursor); _cursor->enableLinearFiltering(_currentState.graphicsMode == GFX_LINEAR); } @@ -830,7 +830,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { delete _overlay; _overlay = nullptr; - _overlay = createTexture(_defaultFormatAlpha); + _overlay = createSurface(_defaultFormatAlpha); assert(_overlay); // We always filter the overlay with GL_LINEAR. This assures it's // readable in case it needs to be scaled and does not affect it @@ -845,7 +845,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { delete _osd; _osd = nullptr; - _osd = createTexture(_defaultFormatAlpha); + _osd = createSurface(_defaultFormatAlpha); assert(_osd); // We always filter the osd with GL_LINEAR. This assures it's // readable in case it needs to be scaled and does not affect it @@ -941,40 +941,40 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def _defaultFormatAlpha = defaultFormatAlpha; if (_gameScreen) { - _gameScreen->recreateInternalTexture(); + _gameScreen->recreate(); } if (_overlay) { - _overlay->recreateInternalTexture(); + _overlay->recreate(); } if (_cursor) { - _cursor->recreateInternalTexture(); + _cursor->recreate(); } #ifdef USE_OSD if (_osd) { - _osd->recreateInternalTexture(); + _osd->recreate(); } #endif } void OpenGLGraphicsManager::notifyContextDestroy() { if (_gameScreen) { - _gameScreen->releaseInternalTexture(); + _gameScreen->destroy(); } if (_overlay) { - _overlay->releaseInternalTexture(); + _overlay->destroy(); } if (_cursor) { - _cursor->releaseInternalTexture(); + _cursor->destroy(); } #ifdef USE_OSD if (_osd) { - _osd->releaseInternalTexture(); + _osd->destroy(); } #endif @@ -1028,7 +1028,7 @@ void OpenGLGraphicsManager::setMousePosition(int x, int y) { } } -Texture *OpenGLGraphicsManager::createTexture(const Graphics::PixelFormat &format, bool wantAlpha) { +Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &format, bool wantAlpha) { GLenum glIntFormat, glFormat, glType; if (format.bytesPerPixel == 1) { const Graphics::PixelFormat &virtFormat = wantAlpha ? _defaultFormatAlpha : _defaultFormat; -- cgit v1.2.3 From e66e9e44d358b0cc90d128c31e695a8ace4177fa Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 2 Jan 2016 14:09:41 +0100 Subject: OPENGL: Accelerate palette lookups with shaders. This currently is limited to GL contexts. --- backends/graphics/opengl/opengl-graphics.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 6784bfe6ab..df939fb3d8 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -1031,6 +1031,12 @@ void OpenGLGraphicsManager::setMousePosition(int x, int y) { Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &format, bool wantAlpha) { GLenum glIntFormat, glFormat, glType; if (format.bytesPerPixel == 1) { +#if !USE_FORCED_GLES && !USE_FORCED_GLES2 + if (TextureCLUT8GPU::isSupportedByContext()) { + return new TextureCLUT8GPU(); + } +#endif + const Graphics::PixelFormat &virtFormat = wantAlpha ? _defaultFormatAlpha : _defaultFormat; const bool supported = getGLPixelFormat(virtFormat, glIntFormat, glFormat, glType); if (!supported) { -- cgit v1.2.3 From 2319fcd2289f604f2a9c00942a9cd2e88ea2acc8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 3 Jan 2016 11:58:50 +0100 Subject: OPENGL: Handle GLES2 and GL shaders uniformly. GLES2 requires precision qualifiers to be set and allows use of precision qualifiers. For GLES2 we define a default precision now. Since precision qualifiers are not supported in the GLSL version we use for GL, we introduce compatibility #defines. --- backends/graphics/opengl/opengl-graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index df939fb3d8..7f4fcf73bb 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -905,14 +905,14 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def if (g_context.type == kContextGLES2) { #endif #if !USE_FORCED_GL - _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShaderGLES2); + _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); #endif #if !USE_FORCED_GL && !USE_FORCED_GLES2 } else { #endif #if !USE_FORCED_GLES2 if (g_context.shadersSupported) { - _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShaderGL); + _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); } #endif #if !USE_FORCED_GL && !USE_FORCED_GLES2 -- cgit v1.2.3 From 18306ee20602e79a2af4556658dc0f141a4ad78f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 3 Jan 2016 12:50:51 +0100 Subject: OPENGL: Simplify shader support checks. --- backends/graphics/opengl/opengl-graphics.cpp | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 7f4fcf73bb..d9c9377e51 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -773,8 +773,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { }; #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - if (g_context.type == kContextGLES - || (g_context.type == kContextGL && !g_context.shadersSupported)) { + if (!g_context.shadersSupported) { #endif #if !USE_FORCED_GLES2 GL_CALL(glMatrixMode(GL_PROJECTION)); @@ -901,23 +900,9 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def #if !USE_FORCED_GLES if (!_shader) { -#if !USE_FORCED_GL && !USE_FORCED_GLES2 - if (g_context.type == kContextGLES2) { -#endif -#if !USE_FORCED_GL + if (g_context.shadersSupported) { _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES2 - } else { -#endif -#if !USE_FORCED_GLES2 - if (g_context.shadersSupported) { - _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); - } -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES2 } -#endif } #endif -- cgit v1.2.3 From 08553a09cfa2110d56b200bf6c69d01d5adbc6bb Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 3 Jan 2016 14:06:02 +0100 Subject: OPENGL: Support GLSL based CLUT8 look up for GLES2+. --- backends/graphics/opengl/opengl-graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index d9c9377e51..1ec40015af 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -1016,7 +1016,7 @@ void OpenGLGraphicsManager::setMousePosition(int x, int y) { Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &format, bool wantAlpha) { GLenum glIntFormat, glFormat, glType; if (format.bytesPerPixel == 1) { -#if !USE_FORCED_GLES && !USE_FORCED_GLES2 +#if !USE_FORCED_GLES if (TextureCLUT8GPU::isSupportedByContext()) { return new TextureCLUT8GPU(); } -- cgit v1.2.3 From f5f1b6eba0d409abcda2a3c037a177d6f6e41a2e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 06:41:10 +0100 Subject: OPENGL: Introduce pipeline abstraction to cleanup code. --- backends/graphics/opengl/opengl-graphics.cpp | 34 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 1ec40015af..0a9b040f83 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -23,6 +23,7 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/texture.h" +#include "backends/graphics/opengl/pipeline.h" #include "backends/graphics/opengl/shader.h" #include "common/textconsole.h" @@ -44,6 +45,7 @@ namespace OpenGL { OpenGLGraphicsManager::OpenGLGraphicsManager() : _currentState(), _oldState(), _transactionMode(kTransactionNone), _screenChangeID(1 << (sizeof(int) * 8 - 2)), + _pipeline(nullptr), _outputScreenWidth(0), _outputScreenHeight(0), _displayX(0), _displayY(0), _displayWidth(0), _displayHeight(0), _defaultFormat(), _defaultFormatAlpha(), _gameScreen(nullptr), _gameScreenShakeOffset(0), _overlay(nullptr), @@ -425,13 +427,13 @@ void OpenGLGraphicsManager::updateScreen() { } // Set the OSD transparency. - g_context.setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); + g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); // Draw the OSD texture. _osd->draw(0, 0, _outputScreenWidth, _outputScreenHeight); // Reset color. - g_context.setColor(1.0f, 1.0f, 1.0f, 1.0f); + g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, 1.0f); } #endif @@ -867,6 +869,24 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Initialize context for use. initializeGLContext(); + // Initialize pipeline. + delete _pipeline; + _pipeline = nullptr; + +#if !USE_FORCED_GLES + if (g_context.shadersSupported) { + _pipeline = new ShaderPipeline(); + } +#endif + +#if !USE_FORCED_GLES2 + if (_pipeline == nullptr) { + _pipeline = new FixedPipeline(); + } +#endif + + g_context.setPipeline(_pipeline); + // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); GL_CALL(glDisable(GL_DEPTH_TEST)); @@ -874,15 +894,12 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Default to black as clear color. GL_CALL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); - g_context.setColor(1.0f, 1.0f, 1.0f, 1.0f); + g_context.activePipeline->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)); - // Initialize the context specific state of the pipeline. - g_context.initializePipeline(); - // Setup scissor state accordingly. if (_overlayVisible) { GL_CALL(glDisable(GL_SCISSOR_TEST)); @@ -969,6 +986,11 @@ void OpenGLGraphicsManager::notifyContextDestroy() { } #endif + // Destroy rendering pipeline. + g_context.setPipeline(nullptr); + delete _pipeline; + _pipeline = nullptr; + // Rest our context description since the context is gone soon. g_context.reset(); } -- cgit v1.2.3 From 5498982a3754edccb498521587c553e0ecbe7328 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 07:07:37 +0100 Subject: OPENGL: Introduce ShaderManager to handle builtin shaders. --- backends/graphics/opengl/opengl-graphics.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 0a9b040f83..a8301482d3 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -58,7 +58,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() , _osdAlpha(0), _osdFadeStartTime(0), _osd(nullptr) #endif #if !USE_FORCED_GLES - , _shader(nullptr), _projectionMatrix() + , _projectionMatrix() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); @@ -73,7 +73,7 @@ OpenGLGraphicsManager::~OpenGLGraphicsManager() { delete _osd; #endif #if !USE_FORCED_GLES - delete _shader; + ShaderManager::destroy(); #endif } @@ -790,9 +790,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { #if !USE_FORCED_GLES assert(sizeof(_projectionMatrix) == sizeof(orthoProjection)); memcpy(_projectionMatrix, orthoProjection, sizeof(_projectionMatrix)); - if (_shader) { - _shader->activate(_projectionMatrix); - } + ShaderMan.query(ShaderManager::kDefault)->activate(_projectionMatrix); #endif #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 } @@ -916,18 +914,9 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 4)); #if !USE_FORCED_GLES - if (!_shader) { - if (g_context.shadersSupported) { - _shader = new Shader(g_defaultVertexShader, g_defaultFragmentShader); - } - } -#endif - -#if !USE_FORCED_GLES - if (_shader) { - // TODO: What do we do on failure? - _shader->recreate(); - _shader->activate(_projectionMatrix); + if (g_context.shadersSupported) { + ShaderMan.notifyCreate(); + ShaderMan.query(ShaderManager::kDefault)->activate(_projectionMatrix); } #endif @@ -981,8 +970,8 @@ void OpenGLGraphicsManager::notifyContextDestroy() { #endif #if !USE_FORCED_GLES - if (_shader) { - _shader->destroy(); + if (g_context.shadersSupported) { + ShaderMan.notifyDestroy(); } #endif -- cgit v1.2.3 From c4e65732befdfb675111387c3c7edb616bf2f976 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 10:18:15 +0100 Subject: OPENGL: Introduce abstraction for framebuffer. This allows us to use various framebuffer settings easily. Now the GPU accelerated CLUT8 surface implementation does not need to query former framebuffer state anymore. --- backends/graphics/opengl/opengl-graphics.cpp | 61 ++++++++++++---------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index a8301482d3..36fc7b88aa 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -56,9 +56,6 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() _forceRedraw(false), _scissorOverride(3) #ifdef USE_OSD , _osdAlpha(0), _osdFadeStartTime(0), _osd(nullptr) -#endif -#if !USE_FORCED_GLES - , _projectionMatrix() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); @@ -379,9 +376,9 @@ void OpenGLGraphicsManager::updateScreen() { // cleared. For example, when switching from overlay visible to // invisible, we need to assure that all contents are cleared to // properly remove all overlay contents. - GL_CALL(glDisable(GL_SCISSOR_TEST)); + _backBuffer.enableScissorTest(false); GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); - GL_CALL(glEnable(GL_SCISSOR_TEST)); + _backBuffer.enableScissorTest(true); --_scissorOverride; } else { @@ -475,7 +472,7 @@ void OpenGLGraphicsManager::showOverlay() { _forceRedraw = true; // Allow drawing inside full screen area. - GL_CALL(glDisable(GL_SCISSOR_TEST)); + _backBuffer.enableScissorTest(false); // Update cursor position. setMousePosition(_cursorX, _cursorY); @@ -486,7 +483,7 @@ void OpenGLGraphicsManager::hideOverlay() { _forceRedraw = true; // Limit drawing to screen area. - GL_CALL(glEnable(GL_SCISSOR_TEST)); + _backBuffer.enableScissorTest(true); _scissorOverride = 3; // Update cursor position. @@ -763,23 +760,15 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { _outputScreenWidth = width; _outputScreenHeight = height; - // Setup coordinate system. - GL_CALL(glViewport(0, 0, _outputScreenWidth, _outputScreenHeight)); - - // Orthogonal projection matrix in column major order. - const GLfloat orthoProjection[4*4] = { - 2.0f / _outputScreenWidth, 0.0f , 0.0f, 0.0f, - 0.0f , -2.0f / _outputScreenHeight, 0.0f, 0.0f, - 0.0f , 0.0f , -1.0f, 0.0f, - -1.0f , 1.0f , 0.0f, 1.0f - }; + // Setup backbuffer size. + _backBuffer.setDimensions(width, height); #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 if (!g_context.shadersSupported) { #endif #if !USE_FORCED_GLES2 GL_CALL(glMatrixMode(GL_PROJECTION)); - GL_CALL(glLoadMatrixf(orthoProjection)); + GL_CALL(glLoadMatrixf(_backBuffer.getProjectionMatrix())); GL_CALL(glMatrixMode(GL_MODELVIEW)); GL_CALL(glLoadIdentity()); @@ -788,9 +777,7 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { } else { #endif #if !USE_FORCED_GLES - assert(sizeof(_projectionMatrix) == sizeof(orthoProjection)); - memcpy(_projectionMatrix, orthoProjection, sizeof(_projectionMatrix)); - ShaderMan.query(ShaderManager::kDefault)->activate(_projectionMatrix); + ShaderMan.query(ShaderManager::kDefault)->activate(_backBuffer.getProjectionMatrix()); #endif #if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 } @@ -890,20 +877,21 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def GL_CALL(glDisable(GL_DEPTH_TEST)); GL_CALL(glDisable(GL_DITHER)); - // Default to black as clear color. - GL_CALL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); g_context.activePipeline->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)); + // Setup backbuffer state. + + // Default to black as clear color. + _backBuffer.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); + // Setup alpha blend (for overlay and cursor). + _backBuffer.enableBlend(true); // Setup scissor state accordingly. - if (_overlayVisible) { - GL_CALL(glDisable(GL_SCISSOR_TEST)); - } else { - GL_CALL(glEnable(GL_SCISSOR_TEST)); - } + _backBuffer.enableScissorTest(!_overlayVisible); + + g_context.setFramebuffer(&_backBuffer); + // Clear the whole screen for the first three frames to assure any // leftovers are cleared. _scissorOverride = 3; @@ -916,7 +904,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def #if !USE_FORCED_GLES if (g_context.shadersSupported) { ShaderMan.notifyCreate(); - ShaderMan.query(ShaderManager::kDefault)->activate(_projectionMatrix); + ShaderMan.query(ShaderManager::kDefault)->activate(_backBuffer.getProjectionMatrix()); } #endif @@ -975,6 +963,9 @@ void OpenGLGraphicsManager::notifyContextDestroy() { } #endif + // Unset back buffer. + g_context.setFramebuffer(nullptr); + // Destroy rendering pipeline. g_context.setPipeline(nullptr); delete _pipeline; @@ -1185,10 +1176,10 @@ void OpenGLGraphicsManager::recalculateDisplayArea() { // Setup drawing limitation for game graphics. // This invovles some trickery because OpenGL's viewport coordinate system // is upside down compared to ours. - GL_CALL(glScissor(_displayX, - _outputScreenHeight - _displayHeight - _displayY, - _displayWidth, - _displayHeight)); + _backBuffer.setScissorBox(_displayX, + _outputScreenHeight - _displayHeight - _displayY, + _displayWidth, + _displayHeight); // Clear the whole screen for the first three frames to remove leftovers. _scissorOverride = 3; -- cgit v1.2.3 From 0b46af2f0e5eef939daa73d5b38b6b817c78c7d8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 11:00:58 +0100 Subject: OPENGL: Don't prefix maxTextureSize variable for consistency. --- backends/graphics/opengl/opengl-graphics.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 36fc7b88aa..8832597f33 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -220,8 +220,8 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() { // a context existing before, which means we don't know the maximum // supported texture size before this. Thus, we check whether the // requested game resolution is supported over here. - || ( _currentState.gameWidth > (uint)g_context._maxTextureSize - || _currentState.gameHeight > (uint)g_context._maxTextureSize)) { + || ( _currentState.gameWidth > (uint)g_context.maxTextureSize + || _currentState.gameHeight > (uint)g_context.maxTextureSize)) { if (_transactionMode == kTransactionActive) { // Try to setup the old state in case its valid and is // actually different from the new one. @@ -792,15 +792,15 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { // possible and then scale it to the physical display size. This sounds // bad but actually all recent chips should support full HD resolution // anyway. Thus, it should not be a real issue for modern hardware. - if ( overlayWidth > (uint)g_context._maxTextureSize - || overlayHeight > (uint)g_context._maxTextureSize) { + if ( overlayWidth > (uint)g_context.maxTextureSize + || overlayHeight > (uint)g_context.maxTextureSize) { const frac_t outputAspect = intToFrac(_outputScreenWidth) / _outputScreenHeight; if (outputAspect > (frac_t)FRAC_ONE) { - overlayWidth = g_context._maxTextureSize; + overlayWidth = g_context.maxTextureSize; overlayHeight = intToFrac(overlayWidth) / outputAspect; } else { - overlayHeight = g_context._maxTextureSize; + overlayHeight = g_context.maxTextureSize; overlayWidth = fracToInt(overlayHeight * outputAspect); } } -- cgit v1.2.3 From 0fe580d10c6fb73a90eccb046c8dcbf84b062b16 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 4 Jan 2016 11:38:21 +0100 Subject: OPENGL: Make shader/framebuffer part of pipeline state. --- backends/graphics/opengl/opengl-graphics.cpp | 40 +++++++--------------------- 1 file changed, 9 insertions(+), 31 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 8832597f33..e32753ee3e 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -763,26 +763,6 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { // Setup backbuffer size. _backBuffer.setDimensions(width, height); -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - if (!g_context.shadersSupported) { -#endif -#if !USE_FORCED_GLES2 - GL_CALL(glMatrixMode(GL_PROJECTION)); - GL_CALL(glLoadMatrixf(_backBuffer.getProjectionMatrix())); - - GL_CALL(glMatrixMode(GL_MODELVIEW)); - GL_CALL(glLoadIdentity()); -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - } else { -#endif -#if !USE_FORCED_GLES - ShaderMan.query(ShaderManager::kDefault)->activate(_backBuffer.getProjectionMatrix()); -#endif -#if !USE_FORCED_GL && !USE_FORCED_GLES && !USE_FORCED_GLES2 - } -#endif - uint overlayWidth = width; uint overlayHeight = height; @@ -872,6 +852,14 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def g_context.setPipeline(_pipeline); +#if !USE_FORCED_GLES + if (g_context.shadersSupported) { + ShaderMan.notifyCreate(); + + g_context.activePipeline->setShader(ShaderMan.query(ShaderManager::kDefault)); + } +#endif + // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); GL_CALL(glDisable(GL_DEPTH_TEST)); @@ -890,7 +878,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Setup scissor state accordingly. _backBuffer.enableScissorTest(!_overlayVisible); - g_context.setFramebuffer(&_backBuffer); + g_context.activePipeline->setFramebuffer(&_backBuffer); // Clear the whole screen for the first three frames to assure any // leftovers are cleared. @@ -901,13 +889,6 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // code and that requires the same alignment too. GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 4)); -#if !USE_FORCED_GLES - if (g_context.shadersSupported) { - ShaderMan.notifyCreate(); - ShaderMan.query(ShaderManager::kDefault)->activate(_backBuffer.getProjectionMatrix()); - } -#endif - // Refresh the output screen dimensions if some are set up. if (_outputScreenWidth != 0 && _outputScreenHeight != 0) { setActualScreenSize(_outputScreenWidth, _outputScreenHeight); @@ -963,9 +944,6 @@ void OpenGLGraphicsManager::notifyContextDestroy() { } #endif - // Unset back buffer. - g_context.setFramebuffer(nullptr); - // Destroy rendering pipeline. g_context.setPipeline(nullptr); delete _pipeline; -- cgit v1.2.3 From b17c035642cc33ee614046be011bf8ad9f9db95d Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 6 Jan 2016 16:52:03 +0100 Subject: OPENGL: Implement texture drawing in Pipeline instead of Surface. --- backends/graphics/opengl/opengl-graphics.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index e32753ee3e..a685f34bbf 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -370,6 +370,14 @@ void OpenGLGraphicsManager::updateScreen() { } _forceRedraw = false; + // Update changes to textures. + _gameScreen->updateGLTexture(); + if (_cursor) { + _cursor->updateGLTexture(); + } + _overlay->updateGLTexture(); + _osd->updateGLTexture(); + // Clear the screen buffer. if (_scissorOverride && !_overlayVisible) { // In certain cases we need to assure that the whole screen area is @@ -388,11 +396,11 @@ void OpenGLGraphicsManager::updateScreen() { const GLfloat shakeOffset = _gameScreenShakeOffset * (GLfloat)_displayHeight / _gameScreen->getHeight(); // First step: Draw the (virtual) game screen. - _gameScreen->draw(_displayX, _displayY + shakeOffset, _displayWidth, _displayHeight); + g_context.activePipeline->drawTexture(_gameScreen->getGLTexture(), _displayX, _displayY + shakeOffset, _displayWidth, _displayHeight); // Second step: Draw the overlay if visible. if (_overlayVisible) { - _overlay->draw(0, 0, _outputScreenWidth, _outputScreenHeight); + g_context.activePipeline->drawTexture(_overlay->getGLTexture(), 0, 0, _outputScreenWidth, _outputScreenHeight); } // Third step: Draw the cursor if visible. @@ -401,9 +409,10 @@ void OpenGLGraphicsManager::updateScreen() { // visible. const GLfloat cursorOffset = _overlayVisible ? 0 : shakeOffset; - _cursor->draw(_cursorDisplayX - _cursorHotspotXScaled, - _cursorDisplayY - _cursorHotspotYScaled + cursorOffset, - _cursorWidthScaled, _cursorHeightScaled); + g_context.activePipeline->drawTexture(_cursor->getGLTexture(), + _cursorDisplayX - _cursorHotspotXScaled, + _cursorDisplayY - _cursorHotspotYScaled + cursorOffset, + _cursorWidthScaled, _cursorHeightScaled); } #ifdef USE_OSD @@ -427,7 +436,7 @@ void OpenGLGraphicsManager::updateScreen() { g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); // Draw the OSD texture. - _osd->draw(0, 0, _outputScreenWidth, _outputScreenHeight); + g_context.activePipeline->drawTexture(_osd->getGLTexture(), 0, 0, _outputScreenWidth, _outputScreenHeight); // Reset color. g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, 1.0f); -- cgit v1.2.3 From ed6689d4fcfd30a36cb01392bbd9705732cfac4a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 28 Feb 2016 17:02:19 +0100 Subject: OPENGL: Do not allow direct access to Context::activePipeline. --- backends/graphics/opengl/opengl-graphics.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index a685f34bbf..6ede6a296c 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -396,11 +396,11 @@ void OpenGLGraphicsManager::updateScreen() { const GLfloat shakeOffset = _gameScreenShakeOffset * (GLfloat)_displayHeight / _gameScreen->getHeight(); // First step: Draw the (virtual) game screen. - g_context.activePipeline->drawTexture(_gameScreen->getGLTexture(), _displayX, _displayY + shakeOffset, _displayWidth, _displayHeight); + g_context.getActivePipeline()->drawTexture(_gameScreen->getGLTexture(), _displayX, _displayY + shakeOffset, _displayWidth, _displayHeight); // Second step: Draw the overlay if visible. if (_overlayVisible) { - g_context.activePipeline->drawTexture(_overlay->getGLTexture(), 0, 0, _outputScreenWidth, _outputScreenHeight); + g_context.getActivePipeline()->drawTexture(_overlay->getGLTexture(), 0, 0, _outputScreenWidth, _outputScreenHeight); } // Third step: Draw the cursor if visible. @@ -409,7 +409,7 @@ void OpenGLGraphicsManager::updateScreen() { // visible. const GLfloat cursorOffset = _overlayVisible ? 0 : shakeOffset; - g_context.activePipeline->drawTexture(_cursor->getGLTexture(), + g_context.getActivePipeline()->drawTexture(_cursor->getGLTexture(), _cursorDisplayX - _cursorHotspotXScaled, _cursorDisplayY - _cursorHotspotYScaled + cursorOffset, _cursorWidthScaled, _cursorHeightScaled); @@ -433,13 +433,13 @@ void OpenGLGraphicsManager::updateScreen() { } // Set the OSD transparency. - g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); + g_context.getActivePipeline()->setColor(1.0f, 1.0f, 1.0f, _osdAlpha / 100.0f); // Draw the OSD texture. - g_context.activePipeline->drawTexture(_osd->getGLTexture(), 0, 0, _outputScreenWidth, _outputScreenHeight); + g_context.getActivePipeline()->drawTexture(_osd->getGLTexture(), 0, 0, _outputScreenWidth, _outputScreenHeight); // Reset color. - g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, 1.0f); + g_context.getActivePipeline()->setColor(1.0f, 1.0f, 1.0f, 1.0f); } #endif @@ -865,7 +865,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def if (g_context.shadersSupported) { ShaderMan.notifyCreate(); - g_context.activePipeline->setShader(ShaderMan.query(ShaderManager::kDefault)); + g_context.getActivePipeline()->setShader(ShaderMan.query(ShaderManager::kDefault)); } #endif @@ -874,7 +874,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def GL_CALL(glDisable(GL_DEPTH_TEST)); GL_CALL(glDisable(GL_DITHER)); - g_context.activePipeline->setColor(1.0f, 1.0f, 1.0f, 1.0f); + g_context.getActivePipeline()->setColor(1.0f, 1.0f, 1.0f, 1.0f); GL_CALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); @@ -887,7 +887,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Setup scissor state accordingly. _backBuffer.enableScissorTest(!_overlayVisible); - g_context.activePipeline->setFramebuffer(&_backBuffer); + g_context.getActivePipeline()->setFramebuffer(&_backBuffer); // Clear the whole screen for the first three frames to assure any // leftovers are cleared. -- cgit v1.2.3 From 8a4938f82b05b86c8f0ed010210eb6d1847c04c9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 28 Feb 2016 18:15:00 +0100 Subject: OPENGL: Move pipeline code to pipelines/. --- backends/graphics/opengl/opengl-graphics.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 6ede6a296c..3322ff5c55 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -23,7 +23,9 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/texture.h" -#include "backends/graphics/opengl/pipeline.h" +#include "backends/graphics/opengl/pipelines/pipeline.h" +#include "backends/graphics/opengl/pipelines/fixed.h" +#include "backends/graphics/opengl/pipelines/shader.h" #include "backends/graphics/opengl/shader.h" #include "common/textconsole.h" -- cgit v1.2.3 From 26f106497a863b84c502d122b5ba749176b2c426 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 28 Feb 2016 23:58:04 +0100 Subject: OPENGL: Implement CLUT8 look up as Pipeline. --- backends/graphics/opengl/opengl-graphics.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 3322ff5c55..c5bc99eb70 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -866,7 +866,6 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def #if !USE_FORCED_GLES if (g_context.shadersSupported) { ShaderMan.notifyCreate(); - g_context.getActivePipeline()->setShader(ShaderMan.query(ShaderManager::kDefault)); } #endif -- cgit v1.2.3 From 3f9852eb202b55b93f6e3121ce473951bff033cd Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 29 Feb 2016 00:04:33 +0100 Subject: OPENGL: Make shader pipelines use fixed shaders. --- backends/graphics/opengl/opengl-graphics.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.cpp') diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index c5bc99eb70..4d6a00a3b3 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -851,7 +851,8 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def #if !USE_FORCED_GLES if (g_context.shadersSupported) { - _pipeline = new ShaderPipeline(); + ShaderMan.notifyCreate(); + _pipeline = new ShaderPipeline(ShaderMan.query(ShaderManager::kDefault)); } #endif @@ -863,13 +864,6 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def g_context.setPipeline(_pipeline); -#if !USE_FORCED_GLES - if (g_context.shadersSupported) { - ShaderMan.notifyCreate(); - g_context.getActivePipeline()->setShader(ShaderMan.query(ShaderManager::kDefault)); - } -#endif - // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); GL_CALL(glDisable(GL_DEPTH_TEST)); -- cgit v1.2.3