scummvm/backends/platform/android/texture.h

177 lines
3.8 KiB
C
Raw Normal View History

/* 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 "common/rect.h"
#include "common/array.h"
class GLESTexture {
public:
static void initGLExtensions();
protected:
GLESTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType,
size_t paletteSize);
virtual ~GLESTexture();
2011-02-19 16:18:15 +01:00
public:
void release();
void reinit();
void initSize();
virtual void allocBuffer(GLuint width, GLuint height);
2011-02-19 16:18:15 +01:00
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
const void *buf, int pitch);
virtual void fillBuffer(byte x);
2011-02-19 16:18:15 +01:00
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
2011-03-05 10:05:35 +01:00
inline void drawTexture() {
drawTexture(0, 0, _surface.w, _surface.h);
}
inline GLuint width() const {
2011-02-19 16:18:15 +01:00
return _surface.w;
}
inline GLuint height() const {
2011-02-19 16:18:15 +01:00
return _surface.h;
}
inline const Graphics::Surface *surface_const() const {
return &_surface;
2011-02-19 16:18:15 +01:00
}
inline Graphics::Surface *surface() {
setDirty();
return &_surface;
}
2011-02-19 16:18:15 +01:00
inline bool dirty() const {
return _all_dirty || !_dirty_rect.isEmpty();
}
2011-02-19 16:18:15 +01:00
protected:
inline void setDirty() {
_all_dirty = true;
_dirty_rect = Common::Rect();
}
2011-02-19 16:18:15 +01:00
inline void setDirtyRect(const Common::Rect& r) {
if (!_all_dirty) {
if (_dirty_rect.isEmpty())
_dirty_rect = r;
else
_dirty_rect.extend(r);
}
}
2011-02-19 16:18:15 +01:00
byte _bytesPerPixel;
GLenum _glFormat;
GLenum _glType;
size_t _paletteSize;
GLuint _texture_name;
Graphics::Surface _surface;
GLuint _texture_width;
GLuint _texture_height;
bool _all_dirty;
2011-02-19 16:18:15 +01:00
// Covers dirty area
Common::Rect _dirty_rect;
};
// RGBA4444 texture
class GLES4444Texture : public GLESTexture {
public:
GLES4444Texture();
virtual ~GLES4444Texture();
};
// RGB565 texture
class GLES565Texture : public GLESTexture {
public:
GLES565Texture();
virtual ~GLES565Texture();
};
class GLESPaletteTexture : public GLESTexture {
protected:
GLESPaletteTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType,
size_t paletteSize);
virtual ~GLESPaletteTexture();
2011-02-19 16:18:15 +01:00
public:
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
2011-02-19 16:18:15 +01:00
const void *buf, int pitch);
virtual void fillBuffer(byte x);
2011-02-19 16:18:15 +01:00
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
2011-02-19 16:18:15 +01:00
inline void drawTexture() {
drawTexture(0, 0, _surface.w, _surface.h);
}
2011-02-19 16:18:15 +01:00
inline const byte *palette_const() const {
2011-02-19 16:18:15 +01:00
return _texture;
};
inline byte *palette() {
setDirty();
return _texture;
};
2011-02-19 16:18:15 +01:00
protected:
2011-02-19 16:18:15 +01:00
byte *_texture;
};
// RGB888 256-entry paletted texture
class GLESPalette888Texture : public GLESPaletteTexture {
public:
GLESPalette888Texture();
virtual ~GLESPalette888Texture();
};
2011-02-19 16:18:15 +01:00
// RGBA8888 256-entry paletted texture
class GLESPalette8888Texture : public GLESPaletteTexture {
public:
GLESPalette8888Texture();
virtual ~GLESPalette8888Texture();
};
#endif
#endif