Skip to content

Commit

Permalink
OPENGL: Always set the unpack alignment when refreshing the textures.
Browse files Browse the repository at this point in the history
This should hopefully make sure we are always having the correct alignment set
up. This might fix bug #3435655 "OpenGL display corruption with various Sierra
games Daily B.".
  • Loading branch information
Johannes Schickel committed Nov 9, 2011
1 parent 17027a7 commit 949b30d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions backends/graphics/opengl/gltexture.h
Expand Up @@ -102,6 +102,11 @@ class GLTexture {
*/
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
Expand Down
12 changes: 5 additions & 7 deletions backends/graphics/opengl/opengl-graphics.cpp
Expand Up @@ -1115,8 +1115,6 @@ void OpenGLGraphicsManager::loadTextures() {
}
#endif

uint gameScreenBPP = 0;

if (!_gameTexture) {
byte bpp;
GLenum intformat;
Expand All @@ -1127,7 +1125,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();
Expand Down Expand Up @@ -1186,10 +1183,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
Expand Down

0 comments on commit 949b30d

Please sign in to comment.