Skip to content

Commit

Permalink
OPENGL: Implement support for non CLUT8 cursor.
Browse files Browse the repository at this point in the history
Currently all the cursor data is converted to RGBA8888 to allow for
easy colorkeying.
  • Loading branch information
Johannes Schickel committed Feb 25, 2011
1 parent 4f3a244 commit f1b16fe
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions backends/graphics/opengl/opengl-graphics.cpp
Expand Up @@ -754,6 +754,9 @@ void OpenGLGraphicsManager::refreshOverlay() {
void OpenGLGraphicsManager::refreshCursor() {
_cursorNeedsRedraw = false;

// Allocate a texture big enough for cursor
_cursorTexture->allocBuffer(_cursorState.w, _cursorState.h);

if (_cursorFormat.bytesPerPixel == 1) {
// Create a temporary RGBA8888 surface
byte *surface = new byte[_cursorState.w * _cursorState.h * 4];
Expand All @@ -780,8 +783,46 @@ void OpenGLGraphicsManager::refreshCursor() {
dst += 4;
}

// Allocate a texture big enough for cursor
_cursorTexture->allocBuffer(_cursorState.w, _cursorState.h);
// Update the texture with new cursor
_cursorTexture->updateBuffer(surface, _cursorState.w * 4, 0, 0, _cursorState.w, _cursorState.h);

// Free the temp surface
delete[] surface;
} else {
// Create a temporary RGBA8888 surface
byte *surface = new byte[_cursorState.w * _cursorState.h * 4];
memset(surface, 0, _cursorState.w * _cursorState.h * 4);

// Convert the paletted cursor to RGBA8888
byte *dst = surface;

const bool gotNoAlpha = (_cursorFormat.aLoss == 8);

if (_cursorFormat.bytesPerPixel == 2) {
const uint16 *src = (uint16 *)_cursorData.pixels;
for (int i = 0; i < _cursorState.w * _cursorState.h; i++) {
// Check for keycolor
if (src[i] != _cursorKeyColor) {
_cursorFormat.colorToARGB(src[i], dst[3], dst[0], dst[1], dst[2]);

if (gotNoAlpha)
dst[3] = 255;
}
dst += 4;
}
} else if (_cursorFormat.bytesPerPixel == 4) {
const uint32 *src = (uint32 *)_cursorData.pixels;
for (int i = 0; i < _cursorState.w * _cursorState.h; i++) {
// Check for keycolor
if (src[i] != _cursorKeyColor) {
_cursorFormat.colorToARGB(src[i], dst[3], dst[0], dst[1], dst[2]);

if (gotNoAlpha)
dst[3] = 255;
}
dst += 4;
}
}

// Update the texture with new cursor
_cursorTexture->updateBuffer(surface, _cursorState.w * 4, 0, 0, _cursorState.w, _cursorState.h);
Expand Down

0 comments on commit f1b16fe

Please sign in to comment.