aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android/texture.cpp
diff options
context:
space:
mode:
authordhewg2011-03-05 10:02:56 +0100
committerdhewg2011-03-05 11:00:36 +0100
commit68378150beb96159db7d959d9625107b721eef57 (patch)
treec16836d4aa47ffd00564819f2d84e591e51cec8e /backends/platform/android/texture.cpp
parentdbaad1a89633fe51eabb64a910568fe3995734ec (diff)
downloadscummvm-rg350-68378150beb96159db7d959d9625107b721eef57.tar.gz
scummvm-rg350-68378150beb96159db7d959d9625107b721eef57.tar.bz2
scummvm-rg350-68378150beb96159db7d959d9625107b721eef57.zip
ANDROID: Remove some vtable overhead on textures
Diffstat (limited to 'backends/platform/android/texture.cpp')
-rw-r--r--backends/platform/android/texture.cpp90
1 files changed, 61 insertions, 29 deletions
diff --git a/backends/platform/android/texture.cpp b/backends/platform/android/texture.cpp
index 7d87c144c9..f715f7bc66 100644
--- a/backends/platform/android/texture.cpp
+++ b/backends/platform/android/texture.cpp
@@ -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