00001 // /////////////////////////////////////////////////////////////////////////// 00002 // xrb_texture.hpp by Victor Dods, created 2005/04/13 00003 // /////////////////////////////////////////////////////////////////////////// 00004 // Unless a different license was explicitly granted in writing by the 00005 // copyright holder (Victor Dods), this software is freely distributable under 00006 // the terms of the GNU General Public License, version 2. Any works deriving 00007 // from this work must also be released under the GNU GPL. See the included 00008 // file LICENSE for details. 00009 // /////////////////////////////////////////////////////////////////////////// 00010 00011 #if !defined(_XRB_TEXTURE_HPP_) 00012 #define _XRB_TEXTURE_HPP_ 00013 00014 #include "xrb.hpp" 00015 00016 #include <string> 00017 00018 #include "xrb_screencoord.hpp" 00019 00020 namespace Xrb 00021 { 00022 00023 // notes: 00024 // 00025 // the png reading function should detect what channels/bit depths are 00026 // used and set some enums appropriately. these enums will be read later 00027 // by GLTextureHandle when glTexImage2D is called, so that the correct 00028 // flags are passed. 00029 // 00030 00043 class Texture 00044 { 00045 public: 00046 00047 // most of the PNG formats map onto a subset of these, but the 00048 // mapping is not necessarily invertible. these formats 00049 // are geared more towards the OpenGL formats. 00050 // NOTE: these aren't actually used (yet) 00051 enum Format 00052 { 00053 GRAYSCALE1 = 0, // 1 bit grayscale (monochrome) 00054 GRAYSCALE4, // 4 bit grayscale 00055 GRAYSCALE8, // 8 bit grayscale 00056 GRAYSCALE16, // 16 bit grayscale 00057 00058 GRAYSCALE_ALPHA1, // 1 bit grayscale (monochrome) + 1 bit alpha 00059 GRAYSCALE_ALPHA4, // 4 bit grayscale + 4 bit alpha 00060 GRAYSCALE_ALPHA8, // 8 bit grayscale + 8 bit alpha 00061 GRAYSCALE_ALPHA16, // 16 bit grayscale + 16 bit alpha 00062 00063 RGB332, // 3 bit red, 3 bit green, 2 bit blue 00064 RGB4, // 4 bit red, 4 bit green, 4 bit blue 00065 RGB565, // 5 bit red, 6 bit green, 5 bit blue 00066 RGB8, // 8 bit red, 8 bit green, 8 bit blue 00067 RGB16, // 16 bit red, 16 bit green, 16 bit blue 00068 00069 RGB5_A1, // 5 bit red, 5 bit green, 5 bit blue, 1 bit alpha 00070 RGBA4, // 4 bit red, 4 bit green, 4 bit blue, 4 bit alpha 00071 RGBA8, // 8 bit red, 8 bit green, 8 bit blue, 8 bit alpha 00072 RGBA16, // 16 bit red, 16 bit green, 16 bit blue, 16 bit alpha 00073 00074 FORMAT_COUNT 00075 }; // end enum Format 00076 00077 ~Texture (); 00078 00079 static Texture *Create (std::string const &path); 00080 static Texture *Create (ScreenCoordVector2 const &size, bool zero_out_the_data); 00081 // creates a texture using the given size and pixel buffer. the returned 00082 // Texture object will take ownership of the buffer, and delete[] it upon destruction. 00083 // this method trusts you to hand in a pointer to a sufficiently large pixel buffer. 00084 static Texture *Create (ScreenCoordVector2 const &size, Uint8 *data); 00085 00086 ScreenCoordVector2 Size () const 00087 { 00088 assert(m_data != NULL && "uninitialized Texture"); 00089 return m_size; 00090 } 00091 ScreenCoord Width () const 00092 { 00093 assert(m_data != NULL && "uninitialized Texture"); 00094 return m_size[Dim::X]; 00095 } 00096 ScreenCoord Height () const 00097 { 00098 assert(m_data != NULL && "uninitialized Texture"); 00099 return m_size[Dim::Y]; 00100 } 00101 Uint8 BitDepth () const 00102 { 00103 assert(m_data != NULL && "uninitialized Texture"); 00104 return m_bit_depth; 00105 } 00106 Uint32 DataLength () const 00107 { 00108 assert(m_data != NULL && "uninitialized Texture"); 00109 return m_data_length; 00110 } 00111 Uint8 *Data () const 00112 { 00113 assert(m_data != NULL && "uninitialized Texture"); 00114 return m_data; 00115 } 00116 00117 private: 00118 00119 // private constructor so you must use Create() 00120 Texture (); 00121 00122 ScreenCoordVector2 m_size; 00123 Uint8 m_bit_depth; 00124 Uint32 m_data_length; 00125 Uint8 *m_data; 00126 }; // end of class Texture 00127 00128 } // end of namespace Xrb 00129 00130 #endif // !defined(_XRB_TEXTURE_HPP_)