diff options
Diffstat (limited to 'backends/graphics')
-rw-r--r-- | backends/graphics/maemosdl/maemosdl-graphics.cpp | 60 | ||||
-rw-r--r-- | backends/graphics/maemosdl/maemosdl-graphics.h | 40 | ||||
-rw-r--r-- | backends/graphics/null/null-graphics.h | 3 | ||||
-rw-r--r-- | backends/graphics/opengl/glerrorcheck.cpp | 10 | ||||
-rw-r--r-- | backends/graphics/opengl/gltexture.cpp | 15 | ||||
-rw-r--r-- | backends/graphics/opengl/gltexture.h | 17 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 180 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.h | 23 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.cpp | 23 |
9 files changed, 236 insertions, 135 deletions
diff --git a/backends/graphics/maemosdl/maemosdl-graphics.cpp b/backends/graphics/maemosdl/maemosdl-graphics.cpp new file mode 100644 index 0000000000..527ef82b9d --- /dev/null +++ b/backends/graphics/maemosdl/maemosdl-graphics.cpp @@ -0,0 +1,60 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#if defined(MAEMO) + +#include "SDL_syswm.h" + +#include "common/scummsys.h" + +#include "backends/platform/maemo/maemo.h" +#include "backends/events/maemosdl/maemosdl-events.h" +#include "backends/graphics/maemosdl/maemosdl-graphics.h" + +MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource) + : SurfaceSdlGraphicsManager(sdlEventSource) { +} + +bool MaemoSdlGraphicsManager::loadGFXMode() { + bool success = SurfaceSdlGraphicsManager::loadGFXMode(); + + // fix the problematic zoom key capture in Maemo5/N900 + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + if (SDL_GetWMInfo(&info)) { + Display *dpy = info.info.x11.display; + Window win; + unsigned long val = 1; + Atom atom_zoom = XInternAtom(dpy, "_HILDON_ZOOM_KEY_ATOM", 0); + info.info.x11.lock_func(); + win = info.info.x11.fswindow; + if (win) + XChangeProperty(dpy, win, atom_zoom, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &val, 1); // grab zoom keys + win = info.info.x11.wmwindow; + if (win) + XChangeProperty(dpy, win, atom_zoom, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &val, 1); // grab zoom keys + info.info.x11.unlock_func(); + } + + return success; +} + +#endif diff --git a/backends/graphics/maemosdl/maemosdl-graphics.h b/backends/graphics/maemosdl/maemosdl-graphics.h new file mode 100644 index 0000000000..81064d2d5f --- /dev/null +++ b/backends/graphics/maemosdl/maemosdl-graphics.h @@ -0,0 +1,40 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#if defined(MAEMO) + +#ifndef BACKENDS_GRAPHICS_MAEMOSDL_GRAPHICS_H +#define BACKENDS_GRAPHICS_MAEMOSDL_GRAPHICS_H + +#include "backends/graphics/surfacesdl/surfacesdl-graphics.h" + +class MaemoSdlGraphicsManager : public SurfaceSdlGraphicsManager { +public: + MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource); + +protected: + virtual bool loadGFXMode(); +}; + +#endif + +#endif diff --git a/backends/graphics/null/null-graphics.h b/backends/graphics/null/null-graphics.h index 28b24f6aca..2e6b24d147 100644 --- a/backends/graphics/null/null-graphics.h +++ b/backends/graphics/null/null-graphics.h @@ -27,7 +27,7 @@ static const OSystem::GraphicsMode s_noGraphicsModes[] = { {0, 0, 0} }; -class NullGraphicsManager : GraphicsManager { +class NullGraphicsManager : public GraphicsManager { public: virtual ~NullGraphicsManager() {} @@ -38,6 +38,7 @@ public: const OSystem::GraphicsMode *getSupportedGraphicsModes() const { return s_noGraphicsModes; } int getDefaultGraphicsMode() const { return 0; } bool setGraphicsMode(int mode) { return true; } + void resetGraphicsScale(){} int getGraphicsMode() const { return 0; } inline Graphics::PixelFormat getScreenFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); diff --git a/backends/graphics/opengl/glerrorcheck.cpp b/backends/graphics/opengl/glerrorcheck.cpp index 682207c7ef..439593577d 100644 --- a/backends/graphics/opengl/glerrorcheck.cpp +++ b/backends/graphics/opengl/glerrorcheck.cpp @@ -26,6 +26,7 @@ #include "backends/graphics/opengl/glerrorcheck.h" #include "common/textconsole.h" +#include "common/str.h" #ifdef WIN32 #if defined(ARRAYSIZE) && !defined(_WINDOWS_) @@ -44,7 +45,7 @@ #include <GL/gl.h> #endif -static const char *getGlErrStr(GLenum error) { +static Common::String getGlErrStr(GLenum error) { switch (error) { case GL_NO_ERROR: return "GL_NO_ERROR"; case GL_INVALID_ENUM: return "GL_INVALID_ENUM"; @@ -54,16 +55,13 @@ static const char *getGlErrStr(GLenum error) { case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY"; } - // FIXME: Convert to use Common::String::format() - static char buf[40]; - snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error); - return buf; + return Common::String::format("(Unknown GL error code 0x%x)", error); } void checkGlError(const char *file, int line) { GLenum error = glGetError(); if (error != GL_NO_ERROR) - warning("%s:%d: GL error: %s", file, line, getGlErrStr(error)); + warning("%s:%d: GL error: %s", file, line, getGlErrStr(error).c_str()); } #endif diff --git a/backends/graphics/opengl/gltexture.cpp b/backends/graphics/opengl/gltexture.cpp index b7f5c90105..ce69dc4aab 100644 --- a/backends/graphics/opengl/gltexture.cpp +++ b/backends/graphics/opengl/gltexture.cpp @@ -11,7 +11,7 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License @@ -60,8 +60,7 @@ void GLTexture::initGLExtensions() { return; // Get a string with all extensions - const char* ext_string = - reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); + const char *ext_string = (const char *)glGetString(GL_EXTENSIONS); CHECK_GL_ERROR(); Common::StringTokenizer tokenizer(ext_string, " "); // Iterate all string tokens @@ -132,7 +131,7 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) { // Allocate room for the texture glTexImage2D(GL_TEXTURE_2D, 0, _internalFormat, - _textureWidth, _textureHeight, 0, _glFormat, _glType, NULL); CHECK_GL_ERROR(); + _textureWidth, _textureHeight, 0, _glFormat, _glType, NULL); CHECK_GL_ERROR(); _refresh = false; } @@ -146,15 +145,15 @@ void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLu glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR(); // Check if the buffer has its data contiguously - if (static_cast<int>(w) * _bytesPerPixel == pitch) { + if ((int)w * _bytesPerPixel == pitch) { glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, - _glFormat, _glType, buf); CHECK_GL_ERROR(); + _glFormat, _glType, buf); CHECK_GL_ERROR(); } else { // Update the texture row by row - const byte *src = static_cast<const byte *>(buf); + const byte *src = (const byte *)buf; do { glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, - w, 1, _glFormat, _glType, src); CHECK_GL_ERROR(); + w, 1, _glFormat, _glType, src); CHECK_GL_ERROR(); ++y; src += pitch; } while (--h); diff --git a/backends/graphics/opengl/gltexture.h b/backends/graphics/opengl/gltexture.h index 71f1eeb78f..8ff9838ff7 100644 --- a/backends/graphics/opengl/gltexture.h +++ b/backends/graphics/opengl/gltexture.h @@ -68,29 +68,29 @@ public: static void initGLExtensions(); GLTexture(byte bpp, GLenum internalFormat, GLenum format, GLenum type); - virtual ~GLTexture(); + ~GLTexture(); /** * Refresh the texture after a context change. The * process will be completed on next allocBuffer call. */ - virtual void refresh(); + void refresh(); /** * Allocates memory needed for the given size. */ - virtual void allocBuffer(GLuint width, GLuint height); + void allocBuffer(GLuint width, GLuint height); /** * Updates the texture pixels. */ - virtual void updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, + void updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLuint w, GLuint h); /** * Draws the texture to the screen buffer. */ - virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h); + void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h); /** * Get the texture width. @@ -103,12 +103,17 @@ public: GLuint getHeight() const { return _realHeight; } /** + * Get the bytes per pixel. + */ + uint getBytesPerPixel() const { return _bytesPerPixel; } + + /** * Set the texture filter. * @filter the filter type, GL_NEAREST or GL_LINEAR */ void setFilter(GLint filter) { _filter = filter; } -protected: +private: const byte _bytesPerPixel; const GLenum _internalFormat; const GLenum _glFormat; diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 8e01e76f16..45804b5d6e 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -81,8 +81,8 @@ OpenGLGraphicsManager::~OpenGLGraphicsManager() { bool OpenGLGraphicsManager::hasFeature(OSystem::Feature f) { return - (f == OSystem::kFeatureAspectRatioCorrection) || - (f == OSystem::kFeatureCursorPalette); + (f == OSystem::kFeatureAspectRatioCorrection) || + (f == OSystem::kFeatureCursorPalette); } void OpenGLGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) { @@ -269,9 +269,9 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() { } if (_videoMode.fullscreen == _oldVideoMode.fullscreen && - _videoMode.mode == _oldVideoMode.mode && - _videoMode.screenWidth == _oldVideoMode.screenWidth && - _videoMode.screenHeight == _oldVideoMode.screenHeight) { + _videoMode.mode == _oldVideoMode.mode && + _videoMode.screenWidth == _oldVideoMode.screenWidth && + _videoMode.screenHeight == _oldVideoMode.screenHeight) { _oldVideoMode.setup = false; } @@ -420,7 +420,7 @@ void OpenGLGraphicsManager::setShakePos(int shakeOffset) { _shakePos = shakeOffset; } -void OpenGLGraphicsManager::setFocusRectangle(const Common::Rect& rect) { +void OpenGLGraphicsManager::setFocusRectangle(const Common::Rect &rect) { } void OpenGLGraphicsManager::clearFocusRectangle() { @@ -487,7 +487,8 @@ void OpenGLGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch } if (y < 0) { - h += y; buf -= y * pitch; + h += y; + buf -= y * pitch; y = 0; } @@ -500,26 +501,13 @@ void OpenGLGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch if (w <= 0 || h <= 0) return; - if (_overlayFormat.aBits() == 1) { - // Copy buffer with the alpha bit on for all pixels for correct - // overlay drawing. - const uint16 *src = (const uint16 *)buf; - uint16 *dst = (uint16 *)_overlayData.pixels + y * _overlayData.w + x; - for (int i = 0; i < h; i++) { - for (int e = 0; e < w; e++) - dst[e] = src[e] | 0x1; - src += pitch; - dst += _overlayData.w; - } - } else { - // Copy buffer data to internal overlay surface - const byte *src = (const byte *)buf; - byte *dst = (byte *)_overlayData.pixels + y * _overlayData.pitch; - for (int i = 0; i < h; i++) { - memcpy(dst + x * _overlayData.format.bytesPerPixel, src, w * _overlayData.format.bytesPerPixel); - src += pitch * sizeof(buf[0]); - dst += _overlayData.pitch; - } + // Copy buffer data to internal overlay surface + const byte *src = (const byte *)buf; + byte *dst = (byte *)_overlayData.pixels + y * _overlayData.pitch; + for (int i = 0; i < h; i++) { + memcpy(dst + x * _overlayData.format.bytesPerPixel, src, w * _overlayData.format.bytesPerPixel); + src += pitch * sizeof(buf[0]); + dst += _overlayData.pitch; } // Extend dirty area if not full screen redraw is flagged @@ -594,10 +582,8 @@ void OpenGLGraphicsManager::warpMouse(int x, int y) { scaledY += _displayY; } + setMousePosition(scaledX, scaledY); setInternalMousePosition(scaledX, scaledY); - - _cursorState.x = scaledX; - _cursorState.y = scaledY; } void OpenGLGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { @@ -613,7 +599,7 @@ void OpenGLGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int // Allocate space for cursor data if (_cursorData.w != w || _cursorData.h != h || - _cursorData.format.bytesPerPixel != _cursorFormat.bytesPerPixel) + _cursorData.format.bytesPerPixel != _cursorFormat.bytesPerPixel) _cursorData.create(w, h, _cursorFormat); // Save cursor data @@ -717,7 +703,7 @@ void OpenGLGraphicsManager::refreshGameScreen() { } else { // Update the texture _gameTexture->updateBuffer((byte *)_screenData.pixels + y * _screenData.pitch + - x * _screenData.format.bytesPerPixel, _screenData.pitch, x, y, w, h); + x * _screenData.format.bytesPerPixel, _screenData.pitch, x, y, w, h); } _screenNeedsRedraw = false; @@ -759,7 +745,7 @@ void OpenGLGraphicsManager::refreshOverlay() { } else { // Update the texture _overlayTexture->updateBuffer((byte *)_overlayData.pixels + y * _overlayData.pitch + - x * _overlayData.format.bytesPerPixel, _overlayData.pitch, x, y, w, h); + x * _overlayData.format.bytesPerPixel, _overlayData.pitch, x, y, w, h); } _overlayNeedsRedraw = false; @@ -838,38 +824,50 @@ void OpenGLGraphicsManager::refreshCursor() { } void OpenGLGraphicsManager::refreshCursorScale() { - // Get the window minimum scale factor. The cursor will mantain its original aspect - // ratio, and we do not want it to get too big if only one dimension is resized - uint screenScaleFactor = MIN(_videoMode.hardwareWidth * 10000 / _videoMode.screenWidth, - _videoMode.hardwareHeight * 10000 / _videoMode.screenHeight); - - // Do not scale cursor if original size is used - if (_videoMode.mode == OpenGL::GFX_ORIGINAL) - screenScaleFactor = _videoMode.scaleFactor * 10000; - - if ((uint)_cursorTargetScale * 10000 >= screenScaleFactor && (uint)_videoMode.scaleFactor * 10000 >= screenScaleFactor) { - // If the cursor target scale and the video mode scale factor are bigger than - // the current window scale, do not scale the cursor for the overlay - _cursorState.rW = _cursorState.w; - _cursorState.rH = _cursorState.h; - _cursorState.rHotX = _cursorState.hotX; - _cursorState.rHotY = _cursorState.hotY; - } else { - // Otherwise, scale the cursor for the overlay - int targetScaleFactor = MIN(_cursorTargetScale, _videoMode.scaleFactor); - // We limit the maximum scale to 3 here to avoid too big cursors, for large overlay resolutions - int actualFactor = MIN<uint>(3, screenScaleFactor - (targetScaleFactor - 1)) * 10000; - _cursorState.rW = (int16)(_cursorState.w * actualFactor / 10000); - _cursorState.rH = (int16)(_cursorState.h * actualFactor / 10000); - _cursorState.rHotX = (int16)(_cursorState.hotX * actualFactor / 10000); - _cursorState.rHotY = (int16)(_cursorState.hotY * actualFactor / 10000); - } - - // Always scale the cursor for the game - _cursorState.vW = (int16)(_cursorState.w * screenScaleFactor / 10000); - _cursorState.vH = (int16)(_cursorState.h * screenScaleFactor / 10000); - _cursorState.vHotX = (int16)(_cursorState.hotX * screenScaleFactor / 10000); - _cursorState.vHotY = (int16)(_cursorState.hotY * screenScaleFactor / 10000); + // Calculate the scale factors of the screen. We limit ourselves to 3 at + // most here to avoid really big (and ugly) cursors for big resolutions. + // It might be noteworthy that 3 is the (current) target scale for the + // modern theme and thus assures the cursor is *never* scaled. + // We also totally ignore the aspect of the overlay cursor, since aspect + // ratio correction only applies to the game screen. + uint screenScaleFactorX = MIN(30000, _videoMode.hardwareWidth * 10000 / _videoMode.screenWidth); + uint screenScaleFactorY = MIN(30000, _videoMode.hardwareHeight * 10000 / _videoMode.screenHeight); + + // Apply the target scale factor to the cursor. + // It might be noteworthy we only apply any scaling to the cursor in case + // the current scale factor is bigger than the target scale to match + // SurfaceSdlGraphicsManager's behavior. Otherwise we would downscale the + // GUI cursor of the modern theme for example. + if (screenScaleFactorX > uint(_cursorTargetScale * 10000)) + screenScaleFactorX /= _cursorTargetScale; + else + screenScaleFactorX = 10000; + if (screenScaleFactorY > uint(_cursorTargetScale * 10000)) + screenScaleFactorY /= _cursorTargetScale; + else + screenScaleFactorY = 10000; + + // Apply them (without any possible) aspect ratio correction to the + // overlay. + _cursorState.rW = (int16)(_cursorState.w * screenScaleFactorX / 10000); + _cursorState.rH = (int16)(_cursorState.h * screenScaleFactorY / 10000); + _cursorState.rHotX = (int16)(_cursorState.hotX * screenScaleFactorX / 10000); + _cursorState.rHotY = (int16)(_cursorState.hotY * screenScaleFactorY / 10000); + + // Make sure we properly scale the cursor according to the desired aspect. + // It might be noteworthy that, unlike with the overlay, we do not limit + // the scale factor here to avoid odd looks if the game uses items as + // mouse cursor, which would otherwise suddenly be smaller. + int width, height; + calculateDisplaySize(width, height); + screenScaleFactorX = (width * 10000 / _videoMode.screenWidth) / _cursorTargetScale; + screenScaleFactorY = (height * 10000 / _videoMode.screenHeight) / _cursorTargetScale; + + // Always scale the cursor for the game. + _cursorState.vW = (int16)(_cursorState.w * screenScaleFactorX / 10000); + _cursorState.vH = (int16)(_cursorState.h * screenScaleFactorY / 10000); + _cursorState.vHotX = (int16)(_cursorState.hotX * screenScaleFactorX / 10000); + _cursorState.vHotY = (int16)(_cursorState.hotY * screenScaleFactorY / 10000); } void OpenGLGraphicsManager::calculateDisplaySize(int &width, int &height) { @@ -1031,10 +1029,10 @@ void OpenGLGraphicsManager::internUpdateScreen() { // Draw the cursor if (_overlayVisible) _cursorTexture->drawTexture(_cursorState.x - _cursorState.rHotX, - _cursorState.y - _cursorState.rHotY, _cursorState.rW, _cursorState.rH); + _cursorState.y - _cursorState.rHotY, _cursorState.rW, _cursorState.rH); else _cursorTexture->drawTexture(_cursorState.x - _cursorState.vHotX, - _cursorState.y - _cursorState.vHotY, _cursorState.vW, _cursorState.vH); + _cursorState.y - _cursorState.vHotY, _cursorState.vW, _cursorState.vH); glPopMatrix(); } @@ -1115,8 +1113,6 @@ void OpenGLGraphicsManager::loadTextures() { } #endif - uint gameScreenBPP = 0; - if (!_gameTexture) { byte bpp; GLenum intformat; @@ -1127,7 +1123,6 @@ void OpenGLGraphicsManager::loadTextures() { #else getGLPixelFormat(Graphics::PixelFormat::createFormatCLUT8(), bpp, intformat, format, type); #endif - gameScreenBPP = bpp; _gameTexture = new GLTexture(bpp, intformat, format, type); } else _gameTexture->refresh(); @@ -1161,23 +1156,23 @@ void OpenGLGraphicsManager::loadTextures() { if ( #ifdef USE_RGB_COLOR - _transactionDetails.formatChanged || + _transactionDetails.formatChanged || #endif - _oldVideoMode.screenWidth != _videoMode.screenWidth || - _oldVideoMode.screenHeight != _videoMode.screenHeight) + _oldVideoMode.screenWidth != _videoMode.screenWidth || + _oldVideoMode.screenHeight != _videoMode.screenHeight) _screenData.create(_videoMode.screenWidth, _videoMode.screenHeight, #ifdef USE_RGB_COLOR - _screenFormat + _screenFormat #else - Graphics::PixelFormat::createFormatCLUT8() + Graphics::PixelFormat::createFormatCLUT8() #endif - ); + ); if (_oldVideoMode.overlayWidth != _videoMode.overlayWidth || - _oldVideoMode.overlayHeight != _videoMode.overlayHeight) + _oldVideoMode.overlayHeight != _videoMode.overlayHeight) _overlayData.create(_videoMode.overlayWidth, _videoMode.overlayHeight, - _overlayFormat); + _overlayFormat); _screenNeedsRedraw = true; _overlayNeedsRedraw = true; @@ -1186,10 +1181,11 @@ void OpenGLGraphicsManager::loadTextures() { // We need to setup a proper unpack alignment value here, else we will // get problems with the texture updates, in case the surface data is // not properly aligned. - // For now we use the gcd of the game screen format and 2, since 2 is - // the BPP value for the overlay and the OSD. - if (gameScreenBPP) - glPixelStorei(GL_UNPACK_ALIGNMENT, Common::gcd<uint>(gameScreenBPP, 2)); + // It is noteworthy this assumes the OSD uses the same BPP as the overlay + // and that the cursor works with any alignment setting. + int newAlignment = Common::gcd(_gameTexture->getBytesPerPixel(), _overlayTexture->getBytesPerPixel()); + assert(newAlignment == 1 || newAlignment == 2 || newAlignment == 4); + glPixelStorei(GL_UNPACK_ALIGNMENT, newAlignment); // 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 @@ -1253,8 +1249,8 @@ uint OpenGLGraphicsManager::getAspectRatio() const { // ratio correction is enabled, but it's better than the previous 4/3 mode // mess at least... if (_videoMode.aspectRatioCorrection - && ((_videoMode.screenWidth == 320 && _videoMode.screenHeight == 200) - || (_videoMode.screenWidth == 640 && _videoMode.screenHeight == 400))) + && ((_videoMode.screenWidth == 320 && _videoMode.screenHeight == 200) + || (_videoMode.screenWidth == 640 && _videoMode.screenHeight == 400))) return 13333; else if (_videoMode.mode == OpenGL::GFX_NORMAL) return _videoMode.hardwareWidth * 10000 / _videoMode.hardwareHeight; @@ -1266,15 +1262,13 @@ void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) { if (_overlayVisible) return; - if (!_overlayVisible) { - x -= _displayX; - y -= _displayY; + x -= _displayX; + y -= _displayY; - if (_displayWidth != _videoMode.screenWidth) - x = x * _videoMode.screenWidth / _displayWidth; - if (_displayHeight != _videoMode.screenHeight) - y = y * _videoMode.screenHeight / _displayHeight; - } + if (_displayWidth != _videoMode.screenWidth) + x = x * _videoMode.screenWidth / _displayWidth; + if (_displayHeight != _videoMode.screenHeight) + y = y * _videoMode.screenHeight / _displayHeight; } bool OpenGLGraphicsManager::saveScreenshot(const char *filename) { @@ -1349,7 +1343,7 @@ const char *OpenGLGraphicsManager::getCurrentModeName() { #ifdef USE_OSD const Graphics::Font *OpenGLGraphicsManager::getFontOSD() { - return FontMan.getFontByUsage(Graphics::FontManager::kLocalizedFont); + return FontMan.getFontByUsage(Graphics::FontManager::kLocalizedFont); } void OpenGLGraphicsManager::updateOSD() { diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 6ded680eae..ad8765bab1 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -217,6 +217,7 @@ protected: uint getAspectRatio() const; + void setFormatIsBGR(bool isBGR) { _formatBGR = isBGR; } bool _formatBGR; // @@ -285,6 +286,14 @@ protected: int _cursorTargetScale; bool _cursorNeedsRedraw; + /** + * Set up the mouse position for graphics output. + * + * @param x X coordinate in native coordinates. + * @param y Y coordinate in native coordinates. + */ + void setMousePosition(int x, int y) { _cursorState.x = x; _cursorState.y = y; } + virtual void refreshCursor(); virtual void refreshCursorScale(); @@ -312,20 +321,20 @@ protected: #ifdef USE_OSD /** - * The OSD contents. + * Returns the font used for on screen display */ - Common::Array<Common::String> _osdLines; - - /** - * Returns the font used for on screen display - */ - virtual const Graphics::Font *getFontOSD(); + virtual const Graphics::Font *getFontOSD(); /** * Update the OSD texture / surface. */ void updateOSD(); + /** + * The OSD contents. + */ + Common::Array<Common::String> _osdLines; + GLTexture *_osdTexture; Graphics::Surface _osdSurface; uint8 _osdAlpha; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index cfc78cfcac..b37d631c6d 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -318,12 +318,12 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() { // only used to ensure that the original pixel size aspect for these // modes is used. // (Non-square pixels on old monitors vs square pixel on new ones). - if (_videoMode.aspectRatioCorrection - && ((_videoMode.screenWidth == 320 && _videoMode.screenHeight == 200) - || (_videoMode.screenWidth == 640 && _videoMode.screenHeight == 400))) - _videoMode.overlayHeight = _videoMode.hardwareHeight = 240 * scaleFactor; - else - _videoMode.overlayHeight = _videoMode.hardwareHeight = _videoMode.screenHeight * scaleFactor; + if (_videoMode.aspectRatioCorrection) { + if (_videoMode.screenWidth == 320 && _videoMode.screenHeight == 200) + _videoMode.overlayHeight = _videoMode.hardwareHeight = 240 * scaleFactor; + else if (_videoMode.screenWidth == 640 && _videoMode.screenHeight == 400) + _videoMode.overlayHeight = _videoMode.hardwareHeight = 480 * scaleFactor; + } } _screenResized = false; @@ -376,7 +376,7 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() { } // Check if the screen is BGR format - _formatBGR = _hwscreen->format->Rshift != 0; + setFormatIsBGR(_hwscreen->format->Rshift != 0); if (isFullscreen) { _lastFullscreenModeWidth = _videoMode.hardwareWidth; @@ -460,10 +460,6 @@ void OpenGLSdlGraphicsManager::toggleFullScreen(int loop) { _activeFullscreenMode = -2; setFullscreenMode(!isFullscreen); } - - // HACK: We need to force a refresh here, since we change the - // fullscreen mode. - _transactionDetails.needRefresh = true; endGFXTransaction(); // Ignore resize events for the next 10 frames @@ -486,7 +482,7 @@ void OpenGLSdlGraphicsManager::toggleFullScreen(int loop) { } bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { - switch ((int)event.type) { + switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.hasFlags(Common::KBD_ALT)) { // Alt-Return and Alt-Enter toggle full screen mode @@ -671,8 +667,7 @@ void OpenGLSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { } void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) { - _cursorState.x = mouse.x; - _cursorState.y = mouse.y; + setMousePosition(mouse.x, mouse.y); } #endif |