aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorJohannes Schickel2011-02-24 05:11:00 +0100
committerJohannes Schickel2011-02-24 05:11:00 +0100
commitf5e10f33f59dd21c82768dd12dd13cc9e021c760 (patch)
tree43262275d6c07e48aa0cce4ba0c1547bcf1423c2 /backends/graphics
parente04d983f683871d455394fcbf50e2f964aaad365 (diff)
downloadscummvm-rg350-f5e10f33f59dd21c82768dd12dd13cc9e021c760.tar.gz
scummvm-rg350-f5e10f33f59dd21c82768dd12dd13cc9e021c760.tar.bz2
scummvm-rg350-f5e10f33f59dd21c82768dd12dd13cc9e021c760.zip
OPENGL: Properly setup pixel data alignment.
If we do not do this, we might end up with a default alignment of 4, which will fail (as in the graphics will be messed up) in case the screen resolution is not divisible by 4. Thanks to digitall for noticing this problem and finding out about GL_UNPACK_ALIGNMENT.
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index beac2f6d3e..d1804e77eb 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -341,9 +341,9 @@ void OpenGLGraphicsManager::copyRectToScreen(const byte *buf, int pitch, int x,
// Copy buffer data to game screen internal buffer
const byte *src = buf;
- byte *dst = (byte *)_screenData.pixels + y * _screenData.pitch;
+ byte *dst = (byte *)_screenData.pixels + y * _screenData.pitch + x * _screenData.bytesPerPixel;
for (int i = 0; i < h; i++) {
- memcpy(dst + x * _screenData.bytesPerPixel, src, w * _screenData.bytesPerPixel);
+ memcpy(dst, src, w * _screenData.bytesPerPixel);
src += pitch;
dst += _screenData.pitch;
}
@@ -1063,6 +1063,8 @@ void OpenGLGraphicsManager::loadTextures() {
delete _gameTexture;
#endif
+ uint gameScreenBPP = 0;
+
if (!_gameTexture) {
byte bpp;
GLenum intformat;
@@ -1073,6 +1075,7 @@ 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();
@@ -1119,6 +1122,14 @@ void OpenGLGraphicsManager::loadTextures() {
_overlayNeedsRedraw = true;
_cursorNeedsRedraw = true;
+ // 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));
+
#ifdef USE_OSD
if (!_osdTexture)
_osdTexture = new GLTexture(2, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);