From 42c6a785c74c200b19ceef6db5003f334c3edf29 Mon Sep 17 00:00:00 2001 From: dhewg Date: Sun, 6 Mar 2011 21:27:34 +0100 Subject: ANDROID: Texture cleanup --- backends/platform/android/texture.cpp | 51 ++++++++--------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) (limited to 'backends/platform/android/texture.cpp') diff --git a/backends/platform/android/texture.cpp b/backends/platform/android/texture.cpp index ee41d3aeee..24e6549b1a 100644 --- a/backends/platform/android/texture.cpp +++ b/backends/platform/android/texture.cpp @@ -88,19 +88,15 @@ GLESTexture::GLESTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType, _glFormat(glFormat), _glType(glType), _paletteSize(paletteSize), - _pixelFormat(pixelFormat), + _texture_name(0), + _surface(), _texture_width(0), _texture_height(0), - _all_dirty(true) + _all_dirty(false), + _dirty_rect(), + _pixelFormat(pixelFormat) { GLCALL(glGenTextures(1, &_texture_name)); - - // This all gets reset later in allocBuffer: - _surface.w = 0; - _surface.h = 0; - _surface.pitch = 0; - _surface.pixels = 0; - _surface.bytesPerPixel = 0; } GLESTexture::~GLESTexture() { @@ -280,8 +276,7 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { GLCALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices) / 2)); } - _all_dirty = false; - _dirty_rect = Common::Rect(); + clearDirty(); } GLES4444Texture::GLES4444Texture() : @@ -318,28 +313,13 @@ GLESPaletteTexture::~GLESPaletteTexture() { } void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) { - _surface.w = w; - _surface.h = h; - _surface.bytesPerPixel = _bytesPerPixel; - - // Already allocated a sufficiently large buffer? - if (w <= _texture_width && h <= _texture_height) - return; - - if (npot_supported) { - _texture_width = _surface.w; - _texture_height = _surface.h; - } else { - _texture_width = nextHigher2(_surface.w); - _texture_height = nextHigher2(_surface.h); - } - - _surface.pitch = _texture_width * _bytesPerPixel; + GLESTexture::allocBuffer(w, h); // Texture gets uploaded later (from drawTexture()) byte *new_buffer = new byte[_paletteSize + _texture_width * _texture_height * _bytesPerPixel]; + assert(new_buffer); if (_texture) { // preserve palette @@ -357,10 +337,9 @@ void GLESPaletteTexture::fillBuffer(uint32 color) { setDirty(); } -void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y, - GLuint w, GLuint h, +void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h, const void *buf, int pitch_buf) { - _all_dirty = true; + setDirtyRect(Common::Rect(x, y, x + w, y + h)); const byte * src = static_cast(buf); byte *dst = static_cast(_surface.getBasePtr(x, y)); @@ -374,16 +353,8 @@ void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y, void GLESPaletteTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { - if (_all_dirty) { + if (dirty()) { GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name)); - GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, - GL_NEAREST)); - 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)); const size_t texture_size = _paletteSize + _texture_width * _texture_height * _bytesPerPixel; -- cgit v1.2.3