1 /* 2 Copyright (C) 2007, 2010 - Bit-Blot 3 4 This file is part of Aquaria. 5 6 Aquaria is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 15 See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 #ifndef __texture__ 22 #define __texture__ 23 24 #include "Base.h" 25 26 enum TextureLoadResult 27 { 28 TEX_FAILED = 0x00, 29 TEX_SUCCESS = 0x01, 30 TEX_LOADED = 0x02, 31 }; 32 33 struct ImageTGA 34 { 35 int channels; // The channels in the image (3 = RGB : 4 = RGBA) 36 int sizeX; // The width of the image in pixels 37 int sizeY; // The height of the image in pixels 38 unsigned char *data; // The image pixel data 39 }; 40 41 class Texture : public Refcounted 42 { 43 public: 44 Texture(); 45 ~Texture(); 46 47 bool load(std::string file); 48 void apply(bool repeatOverride=false); 49 void unbind(); 50 void unload(); 51 52 int getPixelWidth(); 53 int getPixelHeight(); 54 55 void destroy(); 56 57 58 int width, height; 59 60 static ImageTGA *TGAload(const char* filename); 61 static ImageTGA *TGAloadMem(void *mem, int size); 62 63 static bool useMipMaps; 64 bool repeat, repeating; 65 66 #ifdef BBGE_BUILD_OPENGL 67 static GLint filter; 68 static GLint format; 69 GLuint textures[1]; 70 #endif 71 #ifdef BBGE_BUILD_DIRECTX 72 LPDIRECT3DTEXTURE9 d3dTexture; 73 #endif 74 75 void reload(); 76 77 void write(int tx, int ty, int w, int h, const unsigned char *pixels); 78 void read(int tx, int ty, int w, int h, unsigned char *pixels); 79 80 unsigned char *getBufferAndSize(int *w, int *h, unsigned int *size); // returned memory must be free()'d 81 82 std::string name; 83 84 protected: 85 std::string loadName; 86 87 // internal load functions 88 bool loadPNG(const std::string &file); 89 bool loadTGA(const std::string &file); 90 bool loadZGA(const std::string &file); 91 bool loadTGA(ImageTGA *tga); 92 93 int ow, oh; 94 95 }; 96 97 #define UNREFTEX(x) if (x) {x = NULL;} 98 99 #endif 100