scummvm/backends/platform/android/texture.h
dhewg a93229cae5 ANDROID: Don't use compressed textures for the game screen
Some GLES drivers suck so much that uploading data to the GPU takes
ages. CLUT8 games now use a faked paletted texture, which internally
uses a RGB565 hardware texture (Android's native pixel format).
This seems to be the only way to efficiently implement constant
changing textures with GLES1 - at the cost of extra buffers.
Then again, we can now use glTexSubImage2D to only update the dirty
rects, which wasn't possible before because glCompressedTexSubImage2D
is only usable on GLES2. This commit does exactly that.
Overall, the CPU usage is massively reduced for CLUT8 games.
2011-03-13 16:50:43 +01:00

293 lines
6.5 KiB
C++

/* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _ANDROID_TEXTURE_H_
#define _ANDROID_TEXTURE_H_
#if defined(__ANDROID__)
#include <GLES/gl.h>
#include "graphics/surface.h"
#include "graphics/pixelformat.h"
#include "common/rect.h"
#include "common/array.h"
class GLESTexture {
public:
static void initGLExtensions();
protected:
GLESTexture(GLenum glFormat, GLenum glType,
Graphics::PixelFormat pixelFormat);
public:
virtual ~GLESTexture();
void release();
void reinit();
void initSize();
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
const void *buf, int pitch_buf);
virtual void fillBuffer(uint32 color);
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
inline void drawTexture() {
drawTexture(0, 0, _surface.w, _surface.h);
}
inline GLuint width() const {
return _surface.w;
}
inline GLuint height() const {
return _surface.h;
}
inline uint16 pitch() const {
return _surface.pitch;
}
inline const Graphics::Surface *surface_const() const {
return &_surface;
}
inline Graphics::Surface *surface() {
setDirty();
return &_surface;
}
virtual const byte *palette_const() const {
return 0;
};
virtual byte *palette() {
return 0;
};
inline bool hasPalette() const {
return _palettePixelFormat.bytesPerPixel > 0;
}
inline bool dirty() const {
return _all_dirty || !_dirty_rect.isEmpty();
}
virtual const Graphics::PixelFormat &getPixelFormat() const;
inline const Graphics::PixelFormat &getPalettePixelFormat() const {
return _palettePixelFormat;
}
protected:
inline void setDirty() {
_all_dirty = true;
}
inline void clearDirty() {
_all_dirty = false;
_dirty_rect.top = 0;
_dirty_rect.left = 0;
_dirty_rect.bottom = 0;
_dirty_rect.right = 0;
}
inline void setDirtyRect(const Common::Rect& r) {
if (!_all_dirty) {
if (_dirty_rect.isEmpty())
_dirty_rect = r;
else
_dirty_rect.extend(r);
}
}
GLenum _glFormat;
GLenum _glType;
GLuint _texture_name;
Graphics::Surface _surface;
GLuint _texture_width;
GLuint _texture_height;
// Covers dirty area
bool _all_dirty;
Common::Rect _dirty_rect;
Graphics::PixelFormat _pixelFormat;
Graphics::PixelFormat _palettePixelFormat;
};
// RGBA4444 texture
class GLES4444Texture : public GLESTexture {
public:
GLES4444Texture();
virtual ~GLES4444Texture();
static Graphics::PixelFormat pixelFormat() {
return Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0);
}
};
// RGBA5551 texture
class GLES5551Texture : public GLESTexture {
public:
GLES5551Texture();
virtual ~GLES5551Texture();
static inline Graphics::PixelFormat pixelFormat() {
return Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0);
}
};
// RGB565 texture
class GLES565Texture : public GLESTexture {
public:
GLES565Texture();
virtual ~GLES565Texture();
static inline Graphics::PixelFormat pixelFormat() {
return Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
}
};
class GLESPaletteTexture : public GLESTexture {
protected:
GLESPaletteTexture(GLenum glFormat, GLenum glType,
Graphics::PixelFormat palettePixelFormat);
public:
virtual ~GLESPaletteTexture();
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
const void *buf, int pitch_buf);
virtual void fillBuffer(uint32 color);
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
inline void drawTexture() {
drawTexture(0, 0, _surface.w, _surface.h);
}
virtual const byte *palette_const() const {
return _texture;
};
virtual byte *palette() {
setDirty();
return _texture;
};
protected:
byte *_texture;
size_t _paletteSize;
};
// RGB888 256-entry paletted texture
class GLESPalette888Texture : public GLESPaletteTexture {
public:
GLESPalette888Texture();
virtual ~GLESPalette888Texture();
};
// RGBA8888 256-entry paletted texture
class GLESPalette8888Texture : public GLESPaletteTexture {
public:
GLESPalette8888Texture();
virtual ~GLESPalette8888Texture();
};
// RGB565 256-entry paletted texture
class GLESPalette565Texture : public GLESPaletteTexture {
public:
GLESPalette565Texture();
virtual ~GLESPalette565Texture();
};
// RGBA4444 256-entry paletted texture
class GLESPalette4444Texture : public GLESPaletteTexture {
public:
GLESPalette4444Texture();
virtual ~GLESPalette4444Texture();
};
// RGBA5551 256-entry paletted texture
class GLESPalette5551Texture : public GLESPaletteTexture {
public:
GLESPalette5551Texture();
virtual ~GLESPalette5551Texture();
};
class GLESFakePaletteTexture : public GLESTexture {
protected:
GLESFakePaletteTexture(GLenum glFormat, GLenum glType,
Graphics::PixelFormat pixelFormat);
public:
virtual ~GLESFakePaletteTexture();
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
const void *buf, int pitch_buf);
virtual void fillBuffer(uint32 color);
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
inline void drawTexture() {
drawTexture(0, 0, _surface.w, _surface.h);
}
virtual const byte *palette_const() const {
return (byte *)_palette;
};
virtual byte *palette() {
setDirty();
return (byte *)_palette;
};
virtual const Graphics::PixelFormat &getPixelFormat() const;
protected:
Graphics::PixelFormat _fake_format;
uint16 *_palette;
byte *_pixels;
uint16 *_buf;
};
class GLESFakePalette565Texture : public GLESFakePaletteTexture {
public:
GLESFakePalette565Texture();
virtual ~GLESFakePalette565Texture();
};
#endif
#endif