OPENGL: Move color key handling for CLUT8 to TextureCLUT8.

This commit is contained in:
Johannes Schickel 2016-01-02 05:06:32 +01:00
parent db2917dde5
commit 618adec7b0
3 changed files with 30 additions and 20 deletions

View file

@ -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() {

View file

@ -346,6 +346,26 @@ Graphics::PixelFormat TextureCLUT8::getFormat() const {
return Graphics::PixelFormat::createFormatCLUT8();
}
void TextureCLUT8::setColorKey(uint colorKey) {
// 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 = getHardwareFormat();
const uint32 aMask = (0xFF >> hardwareFormat.aLoss) << hardwareFormat.aShift;
if (hardwareFormat.bytesPerPixel == 2) {
uint16 *palette = (uint16 *)_palette + colorKey;
*palette &= ~aMask;
} else if (hardwareFormat.bytesPerPixel == 4) {
uint32 *palette = (uint32 *)_palette + colorKey;
*palette &= ~aMask;
} else {
warning("TextureCLUT8::setColorKey: Unsupported pixel depth %d", hardwareFormat.bytesPerPixel);
}
// A palette changes means we need to refresh the whole surface.
flagDirty();
}
namespace {
template<typename ColorType>
inline void convertPalette(ColorType *dst, const byte *src, uint colors, const Graphics::PixelFormat &format) {

View file

@ -190,10 +190,15 @@ public:
*/
virtual bool hasPalette() const { return false; }
/**
* Set color key for paletted textures.
*
* This needs to be called after any palette update affecting the color
* key. Calling this multiple times will result in multiple color indices
* to be treated as color keys.
*/
virtual void setColorKey(uint colorKey) {}
virtual void setPalette(uint start, uint colors, const byte *palData) {}
virtual void *getPalette() { return 0; }
virtual const void *getPalette() const { return 0; }
protected:
virtual void updateTexture();
@ -222,11 +227,9 @@ public:
virtual bool hasPalette() const { return true; }
virtual void setColorKey(uint colorKey);
virtual void setPalette(uint start, uint colors, const byte *palData);
virtual void *getPalette() { return _palette; }
virtual const void *getPalette() const { return _palette; }
virtual Graphics::Surface *getSurface() { return &_clut8Data; }
virtual const Graphics::Surface *getSurface() const { return &_clut8Data; }