ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

texture.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef _ANDROID_TEXTURE_H_
00024 #define _ANDROID_TEXTURE_H_
00025 
00026 #if defined(__ANDROID__)
00027 
00028 #define GL_GLEXT_PROTOTYPES
00029 #include <GLES/gl.h>
00030 
00031 #include "graphics/surface.h"
00032 #include "graphics/pixelformat.h"
00033 
00034 #include "common/rect.h"
00035 #include "common/array.h"
00036 
00037 class GLESBaseTexture {
00038 public:
00039     static void initGL();
00040 
00041 protected:
00042     GLESBaseTexture(GLenum glFormat, GLenum glType,
00043                     Graphics::PixelFormat pixelFormat);
00044 
00045 public:
00046     virtual ~GLESBaseTexture();
00047 
00048     void release();
00049     void reinit();
00050     void initSize();
00051 
00052     void setLinearFilter(bool value);
00053 
00054     virtual void allocBuffer(GLuint w, GLuint h);
00055 
00056     virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
00057                                 const void *buf, int pitch_buf) = 0;
00058     virtual void fillBuffer(uint32 color) = 0;
00059 
00060     virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
00061         drawTexture(x, y, w, h, Common::Rect(0, 0, width(), height()));
00062     }
00063     virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h, const Common::Rect &clip);
00064 
00065 
00066     inline void setDrawRect(const Common::Rect &rect) {
00067         _draw_rect = rect;
00068     }
00069 
00070     inline void setDrawRect(int16 w, int16 h) {
00071         _draw_rect = Common::Rect(w, h);
00072     }
00073 
00074     inline void setDrawRect(int16 x1, int16 y1, int16 x2, int16 y2) {
00075         _draw_rect = Common::Rect(x1, y1, x2, y2);
00076     }
00077 
00078     inline const Common::Rect &getDrawRect() const {
00079         return _draw_rect;
00080     }
00081 
00082     inline void drawTextureRect() {
00083         drawTexture(_draw_rect.left, _draw_rect.top,
00084                     _draw_rect.width(), _draw_rect.height());
00085     }
00086 
00087     inline void drawTextureOrigin() {
00088             drawTexture(0, 0, _surface.w, _surface.h);
00089     }
00090 
00091     inline GLuint width() const {
00092         return _surface.w;
00093     }
00094 
00095     inline GLuint height() const {
00096         return _surface.h;
00097     }
00098 
00099     inline GLuint texWidth() const {
00100         return _texture_width;
00101     }
00102 
00103     inline GLuint texHeight() const {
00104         return _texture_height;
00105     }
00106 
00107     inline uint16 pitch() const {
00108         return _surface.pitch;
00109     }
00110 
00111     inline bool isEmpty() const {
00112         return _surface.w == 0 || _surface.h == 0;
00113     }
00114 
00115     inline const Graphics::Surface *surface_const() const {
00116         return &_surface;
00117     }
00118 
00119     inline Graphics::Surface *surface() {
00120         setDirty();
00121         return &_surface;
00122     }
00123 
00124     virtual const byte *palette_const() const {
00125         return 0;
00126     };
00127 
00128     virtual byte *palette() {
00129         return 0;
00130     };
00131 
00132     inline bool hasPalette() const {
00133         return _palettePixelFormat.bytesPerPixel > 0;
00134     }
00135 
00136     inline bool dirty() const {
00137         return _all_dirty || !_dirty_rect.isEmpty();
00138     }
00139 
00140     virtual const Graphics::PixelFormat &getPixelFormat() const;
00141 
00142     inline const Graphics::PixelFormat &getPalettePixelFormat() const {
00143         return _palettePixelFormat;
00144     }
00145 
00146     GLuint getTextureName() const {
00147         return _texture_name;
00148     }
00149 
00150     void setGameTexture() {
00151         _is_game_texture = true;
00152     }
00153 
00154 protected:
00155     inline void setDirty() {
00156         _all_dirty = true;
00157     }
00158 
00159     inline void clearDirty() {
00160         _all_dirty = false;
00161         _dirty_rect.top = 0;
00162         _dirty_rect.left = 0;
00163         _dirty_rect.bottom = 0;
00164         _dirty_rect.right = 0;
00165     }
00166 
00167     inline void setDirtyRect(const Common::Rect& r) {
00168         if (!_all_dirty) {
00169             if (_dirty_rect.isEmpty())
00170                 _dirty_rect = r;
00171             else
00172                 _dirty_rect.extend(r);
00173         }
00174     }
00175 
00176     GLenum _glFormat;
00177     GLenum _glType;
00178     GLint _glFilter;
00179 
00180     GLuint _texture_name;
00181     Graphics::Surface _surface;
00182     GLuint _texture_width;
00183     GLuint _texture_height;
00184 
00185     Common::Rect _draw_rect;
00186 
00187     bool _all_dirty;
00188     Common::Rect _dirty_rect;
00189 
00190     Graphics::PixelFormat _pixelFormat;
00191     Graphics::PixelFormat _palettePixelFormat;
00192 
00193     bool _is_game_texture;
00194 };
00195 
00196 class GLESTexture : public GLESBaseTexture {
00197 protected:
00198     GLESTexture(GLenum glFormat, GLenum glType,
00199                 Graphics::PixelFormat pixelFormat);
00200 
00201 public:
00202     virtual ~GLESTexture();
00203 
00204     virtual void allocBuffer(GLuint w, GLuint h);
00205 
00206     virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
00207                                 const void *buf, int pitch_buf);
00208     virtual void fillBuffer(uint32 color);
00209 
00210     virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
00211         drawTexture(x, y, w, h, Common::Rect(0, 0, width(), height()));
00212     }
00213     virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h, const Common::Rect &clip);
00214 
00215 protected:
00216     byte *_pixels;
00217     byte *_buf;
00218 };
00219 
00220 class GLES8888Texture : public GLESTexture {
00221 public:
00222     GLES8888Texture();
00223     virtual ~GLES8888Texture();
00224 
00225     static Graphics::PixelFormat pixelFormat() {
00226         return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
00227     }
00228 };
00229 
00230 // RGBA4444 texture
00231 class GLES4444Texture : public GLESTexture {
00232 public:
00233     GLES4444Texture();
00234     virtual ~GLES4444Texture();
00235 
00236     static Graphics::PixelFormat pixelFormat() {
00237         return Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0);
00238     }
00239 };
00240 
00241 // RGBA5551 texture
00242 class GLES5551Texture : public GLESTexture {
00243 public:
00244     GLES5551Texture();
00245     virtual ~GLES5551Texture();
00246 
00247     static inline Graphics::PixelFormat pixelFormat() {
00248         return Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0);
00249     }
00250 };
00251 
00252 // RGB565 texture
00253 class GLES565Texture : public GLESTexture {
00254 public:
00255     GLES565Texture();
00256     virtual ~GLES565Texture();
00257 
00258     static inline Graphics::PixelFormat pixelFormat() {
00259         return Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
00260     }
00261 };
00262 
00263 class GLESFakePaletteTexture : public GLESBaseTexture {
00264 protected:
00265     GLESFakePaletteTexture(GLenum glFormat, GLenum glType,
00266                             Graphics::PixelFormat pixelFormat);
00267 
00268 public:
00269     virtual ~GLESFakePaletteTexture();
00270 
00271     virtual void allocBuffer(GLuint w, GLuint h);
00272     virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
00273                                 const void *buf, int pitch_buf);
00274     virtual void fillBuffer(uint32 color);
00275 
00276     virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
00277         drawTexture(x, y, w, h, Common::Rect(0, 0, width(), height()));
00278     }
00279     virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h, const Common::Rect &clip);
00280 
00281     virtual const byte *palette_const() const {
00282         return (byte *)_palette;
00283     };
00284 
00285     virtual byte *palette() {
00286         setDirty();
00287         return (byte *)_palette;
00288     };
00289 
00290     virtual const Graphics::PixelFormat &getPixelFormat() const;
00291 
00292 protected:
00293     Graphics::PixelFormat _fake_format;
00294     uint16 *_palette;
00295     byte *_pixels;
00296     uint16 *_buf;
00297 };
00298 
00299 class GLESFakePalette565Texture : public GLESFakePaletteTexture {
00300 public:
00301     GLESFakePalette565Texture();
00302     virtual ~GLESFakePalette565Texture();
00303 };
00304 
00305 class GLESFakePalette5551Texture : public GLESFakePaletteTexture {
00306 public:
00307     GLESFakePalette5551Texture();
00308     virtual ~GLESFakePalette5551Texture();
00309 };
00310 
00311 #endif
00312 #endif


Generated on Sat Dec 7 2019 05:00:27 for ResidualVM by doxygen 1.7.1
curved edge   curved edge