Texture.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2002  Ryan Nunn and The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef TEXTURE_H
00020 #define TEXTURE_H
00021 
00022 //
00023 // Texturing Helper Macros
00024 //
00025 
00026 // 32 Bit Texture bit operations
00027 #define TEX32_A_SHIFT                   24
00028 #define TEX32_A_MASK                    0xFF000000
00029 #define TEX32_A(col32)                  (((col32)&TEX32_A_MASK)>>TEX32_A_SHIFT)
00030 
00031 #define TEX32_G_SHIFT                   8
00032 #define TEX32_G_MASK                    0x0000FF00
00033 #define TEX32_G(col32)                  (((col32)&TEX32_G_MASK)>>TEX32_G_SHIFT)
00034 
00035 #define TEX32_B_SHIFT                   16
00036 #define TEX32_B_MASK                    0x00FF0000
00037 #define TEX32_B(col32)                  (((col32)&TEX32_B_MASK)>>TEX32_B_SHIFT)
00038 
00039 #define TEX32_R_SHIFT                   0
00040 #define TEX32_R_MASK                    0x000000FF
00041 #define TEX32_R(col32)                  (((col32)&TEX32_R_MASK)>>TEX32_R_SHIFT)
00042 
00043 #define TEX32_AG(col32)                 (((col32) >> 8) & 0x00FF00FF)
00044 #define TEX32_RB(col32)                 (((col32) >> 0) & 0x00FF00FF)
00045 
00046 #define TEX32_PACK_RGBA(r,g,b,a)        (((a)<<TEX32_A_SHIFT)|((r)<<TEX32_R_SHIFT)|\
00047                                                                         ((g)<<TEX32_G_SHIFT)|((b)<<TEX32_B_SHIFT))
00048 
00049 // 64 Bit Texture bit operations
00050 #define TEX64_A_SHIFT                   16
00051 #define TEX64_A_MASK                    0xFFFF0000
00052 #define TEX64_A_MASK_H                  0xFF000000
00053 
00054 #define TEX64_G_SHIFT                   0
00055 #define TEX64_G_MASK                    0x0000FFFF
00056 #define TEX64_G_MASK_H                  0x0000FF00
00057 
00058 #define TEX64_B_SHIFT                   16
00059 #define TEX64_B_MASK                    0xFFFF0000
00060 #define TEX64_B_MASK_H                  0xFF000000
00061 
00062 #define TEX64_R_SHIFT                   0
00063 #define TEX64_R_MASK                    0x0000FFFF
00064 #define TEX64_R_MASK_H                  0x0000FF00
00065 
00066 enum TextureFormat
00067 {
00068         TEX_FMT_STANDARD                = 0,    // Standard texture format as defined using Macros above
00069         TEX_FMT_NATIVE                  = 1             // The native format of the RenderSurface
00070 };
00071 
00072 
00073 class IDataSource;
00074 
00075 //
00076 // Basic 32 Bit Texture
00077 //
00078 struct Texture
00079 {
00080         uint32                  *buffer;
00081         sint32                  width;
00082         sint32                  height;
00083         uint32                  format; 
00084 
00085         // Use CalcLOG2s to calculate these (can be -1 which indicates not log2)
00086         sint32                  wlog2;
00087         sint32                  hlog2;
00088 
00089         // For OpenGL
00090         uint32                  gl_tex;
00091         Texture                 *next;
00092 
00093         Texture() : buffer(0), format(TEX_FMT_STANDARD), gl_tex(0), next(0)
00094         {
00095         }
00096 
00097         virtual ~Texture();
00098 
00099         // Clear all texture data
00100         virtual bool Clear();
00101 
00102         // Calc texture log2's 
00103         void CalcLOG2s() {
00104                 wlog2 = -1;
00105                 hlog2 = -1;
00106                 for (int i = 0; i < 32; i++) {
00107                         if (width == (1 << i))
00108                                 wlog2 = i;
00109 
00110                         if (height == (1 << i))
00111                                 hlog2 = i;
00112                 }
00113         }
00114 
00115         // Create a texture from a Data Source (filename is use to help detection of type)
00116         static Texture * Create(IDataSource *ds, const char *filename = NULL);
00117 
00118 protected:
00119 
00120         // Read from a File. No filetype supported by this class
00121         virtual bool Read(IDataSource * /*ds*/) { return false; }
00122 };
00123 
00124 #endif //TEXTURE_H

Generated on Fri Jul 27 22:27:41 2007 for pentagram by  doxygen 1.4.7