mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-29 21:24:53 +00:00
ANDROID: Remove some vtable overhead on textures
This commit is contained in:
parent
dbaad1a896
commit
68378150be
@ -326,9 +326,9 @@ void OSystem_Android::initBackend() {
|
||||
initSurface();
|
||||
initViewport();
|
||||
|
||||
_game_texture = new GLESPaletteTexture();
|
||||
_game_texture = new GLESPalette888Texture();
|
||||
_overlay_texture = new GLES4444Texture();
|
||||
_mouse_texture = new GLESPaletteATexture();
|
||||
_mouse_texture = new GLESPalette8888Texture();
|
||||
|
||||
// renice this thread to boost the audio thread
|
||||
if (setpriority(PRIO_PROCESS, 0, 19) < 0)
|
||||
|
@ -103,7 +103,7 @@ private:
|
||||
bool _force_redraw;
|
||||
|
||||
// Game layer
|
||||
GLESPaletteTexture *_game_texture;
|
||||
GLESPalette888Texture *_game_texture;
|
||||
int _shake_offset;
|
||||
Common::Rect _focus_rect;
|
||||
|
||||
@ -112,7 +112,7 @@ private:
|
||||
bool _show_overlay;
|
||||
|
||||
// Mouse layer
|
||||
GLESPaletteATexture *_mouse_texture;
|
||||
GLESPalette8888Texture *_mouse_texture;
|
||||
Common::Point _mouse_hotspot;
|
||||
int _mouse_targetscale;
|
||||
bool _show_mouse;
|
||||
|
@ -82,7 +82,12 @@ void GLESTexture::initGLExtensions() {
|
||||
}
|
||||
}
|
||||
|
||||
GLESTexture::GLESTexture() :
|
||||
GLESTexture::GLESTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType,
|
||||
size_t paletteSize) :
|
||||
_bytesPerPixel(bytesPerPixel),
|
||||
_glFormat(glFormat),
|
||||
_glType(glType),
|
||||
_paletteSize(paletteSize),
|
||||
_texture_width(0),
|
||||
_texture_height(0),
|
||||
_all_dirty(true)
|
||||
@ -92,7 +97,7 @@ GLESTexture::GLESTexture() :
|
||||
// This all gets reset later in allocBuffer:
|
||||
_surface.w = 0;
|
||||
_surface.h = 0;
|
||||
_surface.pitch = _texture_width;
|
||||
_surface.pitch = 0;
|
||||
_surface.pixels = 0;
|
||||
_surface.bytesPerPixel = 0;
|
||||
}
|
||||
@ -109,7 +114,7 @@ void GLESTexture::release() {
|
||||
void GLESTexture::reinit() {
|
||||
GLCALL(glGenTextures(1, &_texture_name));
|
||||
|
||||
if (paletteSize()) {
|
||||
if (_paletteSize) {
|
||||
// paletted textures are in a local buffer, don't wipe it
|
||||
initSize();
|
||||
} else {
|
||||
@ -132,16 +137,15 @@ void GLESTexture::initSize() {
|
||||
GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||
GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
||||
GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||
GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, glFormat(),
|
||||
GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, _glFormat,
|
||||
_texture_width, _texture_height,
|
||||
0, glFormat(), glType(), 0));
|
||||
0, _glFormat, _glType, 0));
|
||||
}
|
||||
|
||||
void GLESTexture::allocBuffer(GLuint w, GLuint h) {
|
||||
int bpp = bytesPerPixel();
|
||||
_surface.w = w;
|
||||
_surface.h = h;
|
||||
_surface.bytesPerPixel = bpp;
|
||||
_surface.bytesPerPixel = _bytesPerPixel;
|
||||
|
||||
// Already allocated a sufficiently large buffer?
|
||||
if (w <= _texture_width && h <= _texture_height)
|
||||
@ -155,7 +159,7 @@ void GLESTexture::allocBuffer(GLuint w, GLuint h) {
|
||||
_texture_height = nextHigher2(_surface.h);
|
||||
}
|
||||
|
||||
_surface.pitch = _texture_width * bpp;
|
||||
_surface.pitch = _texture_width * _bytesPerPixel;
|
||||
|
||||
initSize();
|
||||
}
|
||||
@ -169,14 +173,14 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
|
||||
|
||||
setDirtyRect(Common::Rect(x, y, x + w, y + h));
|
||||
|
||||
if (static_cast<int>(w) * bytesPerPixel() == pitch) {
|
||||
if (static_cast<int>(w) * _bytesPerPixel == pitch) {
|
||||
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
|
||||
glFormat(), glType(), buf));
|
||||
_glFormat, _glType, buf));
|
||||
} else {
|
||||
// GLES removed the ability to specify pitch, so we
|
||||
// have to do this ourselves.
|
||||
#if TEXSUBIMAGE_IS_EXPENSIVE
|
||||
byte *tmp = new byte[w * h * bytesPerPixel()];
|
||||
byte *tmp = new byte[w * h * _bytesPerPixel];
|
||||
assert(tmp);
|
||||
|
||||
const byte *src = static_cast<const byte *>(buf);
|
||||
@ -184,13 +188,13 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
|
||||
GLuint count = h;
|
||||
|
||||
do {
|
||||
memcpy(dst, src, w * bytesPerPixel());
|
||||
dst += w * bytesPerPixel();
|
||||
memcpy(dst, src, w * _bytesPerPixel);
|
||||
dst += w * _bytesPerPixel;
|
||||
src += pitch;
|
||||
} while (--count);
|
||||
|
||||
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
|
||||
glFormat(), glType(), tmp));
|
||||
_glFormat, _glType, tmp));
|
||||
|
||||
delete[] tmp;
|
||||
#else
|
||||
@ -199,7 +203,7 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
|
||||
const byte *src = static_cast<const byte *>(buf);
|
||||
do {
|
||||
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
|
||||
w, 1, glFormat(), glType(), src));
|
||||
w, 1, _glFormat, _glType, src));
|
||||
++y;
|
||||
src += pitch;
|
||||
} while (--h);
|
||||
@ -208,7 +212,7 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
|
||||
}
|
||||
|
||||
void GLESTexture::fillBuffer(byte x) {
|
||||
uint rowbytes = _surface.w * bytesPerPixel();
|
||||
uint rowbytes = _surface.w * _bytesPerPixel;
|
||||
|
||||
byte *tmp = new byte[_surface.h * rowbytes];
|
||||
assert(tmp);
|
||||
@ -225,7 +229,7 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
|
||||
#ifdef GL_OES_draw_texture
|
||||
// Great extension, but only works under specific conditions.
|
||||
// Still a work-in-progress - disabled for now.
|
||||
if (false && draw_tex_supported && paletteSize() == 0) {
|
||||
if (false && draw_tex_supported && _paletteSize == 0) {
|
||||
//GLCALL(glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE));
|
||||
const GLint crop[4] = { 0, _surface.h, _surface.w, -_surface.h };
|
||||
|
||||
@ -266,8 +270,23 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
|
||||
_dirty_rect = Common::Rect();
|
||||
}
|
||||
|
||||
GLESPaletteTexture::GLESPaletteTexture() :
|
||||
GLESTexture(),
|
||||
GLES4444Texture::GLES4444Texture() :
|
||||
GLESTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 0) {
|
||||
}
|
||||
|
||||
GLES4444Texture::~GLES4444Texture() {
|
||||
}
|
||||
|
||||
GLES565Texture::GLES565Texture() :
|
||||
GLESTexture(2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0) {
|
||||
}
|
||||
|
||||
GLES565Texture::~GLES565Texture() {
|
||||
}
|
||||
|
||||
GLESPaletteTexture::GLESPaletteTexture(byte bytesPerPixel, GLenum glFormat,
|
||||
GLenum glType, size_t paletteSize) :
|
||||
GLESTexture(bytesPerPixel, glFormat, glType, paletteSize),
|
||||
_texture(0)
|
||||
{
|
||||
}
|
||||
@ -277,10 +296,9 @@ GLESPaletteTexture::~GLESPaletteTexture() {
|
||||
}
|
||||
|
||||
void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) {
|
||||
int bpp = bytesPerPixel();
|
||||
_surface.w = w;
|
||||
_surface.h = h;
|
||||
_surface.bytesPerPixel = bpp;
|
||||
_surface.bytesPerPixel = _bytesPerPixel;
|
||||
|
||||
// Already allocated a sufficiently large buffer?
|
||||
if (w <= _texture_width && h <= _texture_height)
|
||||
@ -293,20 +311,20 @@ void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) {
|
||||
_texture_width = nextHigher2(_surface.w);
|
||||
_texture_height = nextHigher2(_surface.h);
|
||||
}
|
||||
_surface.pitch = _texture_width * bpp;
|
||||
_surface.pitch = _texture_width * _bytesPerPixel;
|
||||
|
||||
// Texture gets uploaded later (from drawTexture())
|
||||
|
||||
byte *new_buffer = new byte[paletteSize() +
|
||||
_texture_width * _texture_height * bytesPerPixel()];
|
||||
byte *new_buffer = new byte[_paletteSize +
|
||||
_texture_width * _texture_height * _bytesPerPixel];
|
||||
if (_texture) {
|
||||
// preserve palette
|
||||
memcpy(new_buffer, _texture, paletteSize());
|
||||
memcpy(new_buffer, _texture, _paletteSize);
|
||||
delete[] _texture;
|
||||
}
|
||||
|
||||
_texture = new_buffer;
|
||||
_surface.pixels = _texture + paletteSize();
|
||||
_surface.pixels = _texture + _paletteSize;
|
||||
}
|
||||
|
||||
void GLESPaletteTexture::fillBuffer(byte x) {
|
||||
@ -324,7 +342,7 @@ void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y,
|
||||
byte *dst = static_cast<byte *>(_surface.getBasePtr(x, y));
|
||||
|
||||
do {
|
||||
memcpy(dst, src, w * bytesPerPixel());
|
||||
memcpy(dst, src, w * _bytesPerPixel);
|
||||
dst += _surface.pitch;
|
||||
src += pitch;
|
||||
} while (--h);
|
||||
@ -332,9 +350,9 @@ void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y,
|
||||
|
||||
void GLESPaletteTexture::uploadTexture() const {
|
||||
const size_t texture_size =
|
||||
paletteSize() + _texture_width * _texture_height * bytesPerPixel();
|
||||
_paletteSize + _texture_width * _texture_height * _bytesPerPixel;
|
||||
|
||||
GLCALL(glCompressedTexImage2D(GL_TEXTURE_2D, 0, glType(),
|
||||
GLCALL(glCompressedTexImage2D(GL_TEXTURE_2D, 0, _glType,
|
||||
_texture_width, _texture_height,
|
||||
0, texture_size, _texture));
|
||||
}
|
||||
@ -358,5 +376,19 @@ void GLESPaletteTexture::drawTexture(GLshort x, GLshort y, GLshort w,
|
||||
GLESTexture::drawTexture(x, y, w, h);
|
||||
}
|
||||
|
||||
GLESPalette888Texture::GLESPalette888Texture() :
|
||||
GLESPaletteTexture(1, GL_RGB, GL_PALETTE8_RGB8_OES, 256 * 3) {
|
||||
}
|
||||
|
||||
GLESPalette888Texture::~GLESPalette888Texture() {
|
||||
}
|
||||
|
||||
GLESPalette8888Texture::GLESPalette8888Texture() :
|
||||
GLESPaletteTexture(1, GL_RGBA, GL_PALETTE8_RGBA8_OES, 256 * 4) {
|
||||
}
|
||||
|
||||
GLESPalette8888Texture::~GLESPalette8888Texture() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -39,9 +39,12 @@ class GLESTexture {
|
||||
public:
|
||||
static void initGLExtensions();
|
||||
|
||||
GLESTexture();
|
||||
protected:
|
||||
GLESTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType,
|
||||
size_t paletteSize);
|
||||
virtual ~GLESTexture();
|
||||
|
||||
public:
|
||||
void release();
|
||||
void reinit();
|
||||
void initSize();
|
||||
@ -80,14 +83,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual byte bytesPerPixel() const = 0;
|
||||
virtual GLenum glFormat() const = 0;
|
||||
virtual GLenum glType() const = 0;
|
||||
|
||||
virtual size_t paletteSize() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void setDirty() {
|
||||
_all_dirty = true;
|
||||
_dirty_rect = Common::Rect();
|
||||
@ -102,6 +97,11 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
byte _bytesPerPixel;
|
||||
GLenum _glFormat;
|
||||
GLenum _glType;
|
||||
size_t _paletteSize;
|
||||
|
||||
GLuint _texture_name;
|
||||
Graphics::Surface _surface;
|
||||
GLuint _texture_width;
|
||||
@ -114,42 +114,25 @@ protected:
|
||||
|
||||
// RGBA4444 texture
|
||||
class GLES4444Texture : public GLESTexture {
|
||||
protected:
|
||||
virtual byte bytesPerPixel() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
virtual GLenum glFormat() const {
|
||||
return GL_RGBA;
|
||||
}
|
||||
|
||||
virtual GLenum glType() const {
|
||||
return GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
}
|
||||
public:
|
||||
GLES4444Texture();
|
||||
virtual ~GLES4444Texture();
|
||||
};
|
||||
|
||||
// RGB565 texture
|
||||
class GLES565Texture : public GLESTexture {
|
||||
protected:
|
||||
virtual byte bytesPerPixel() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
virtual GLenum glFormat() const {
|
||||
return GL_RGB;
|
||||
}
|
||||
|
||||
virtual GLenum glType() const {
|
||||
return GL_UNSIGNED_SHORT_5_6_5;
|
||||
}
|
||||
public:
|
||||
GLES565Texture();
|
||||
virtual ~GLES565Texture();
|
||||
};
|
||||
|
||||
// RGB888 256-entry paletted texture
|
||||
class GLESPaletteTexture : public GLESTexture {
|
||||
public:
|
||||
GLESPaletteTexture();
|
||||
protected:
|
||||
GLESPaletteTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType,
|
||||
size_t paletteSize);
|
||||
virtual ~GLESPaletteTexture();
|
||||
|
||||
public:
|
||||
virtual void allocBuffer(GLuint width, GLuint height);
|
||||
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
|
||||
const void *buf, int pitch);
|
||||
@ -171,41 +154,23 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual byte bytesPerPixel() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual GLenum glFormat() const {
|
||||
return GL_RGB;
|
||||
}
|
||||
|
||||
virtual GLenum glType() const {
|
||||
return GL_PALETTE8_RGB8_OES;
|
||||
}
|
||||
|
||||
virtual size_t paletteSize() const {
|
||||
return 256 * 3;
|
||||
}
|
||||
|
||||
void uploadTexture() const;
|
||||
|
||||
byte *_texture;
|
||||
};
|
||||
|
||||
// RGB888 256-entry paletted texture
|
||||
class GLESPalette888Texture : public GLESPaletteTexture {
|
||||
public:
|
||||
GLESPalette888Texture();
|
||||
virtual ~GLESPalette888Texture();
|
||||
};
|
||||
|
||||
// RGBA8888 256-entry paletted texture
|
||||
class GLESPaletteATexture : public GLESPaletteTexture {
|
||||
protected:
|
||||
virtual GLenum glFormat() const {
|
||||
return GL_RGBA;
|
||||
}
|
||||
|
||||
virtual GLenum glType() const {
|
||||
return GL_PALETTE8_RGBA8_OES;
|
||||
}
|
||||
|
||||
virtual size_t paletteSize() const {
|
||||
return 256 * 4;
|
||||
}
|
||||
class GLESPalette8888Texture : public GLESPaletteTexture {
|
||||
public:
|
||||
GLESPalette8888Texture();
|
||||
virtual ~GLESPalette8888Texture();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user