00001 ////////////////////////////////////////////////////////////////////// 00002 // 9/6/02 Aaron Lefohn Scientific Computing and Imaging Institute 00003 // School of Computing University of Utah 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 #ifndef GLIFT_TEXDATA_H_ 00020 #define GLIFT_TEXDATA_H_ 00021 00022 #include "../core/gliftObject.h" 00023 #include <GL/glew.h> 00024 #include "../util/gliftDecl.h" 00025 #include <mathGutz.h> 00026 #include <vector> 00027 00028 namespace glift { 00029 00030 /// Typedefs 00031 class TexData; 00032 typedef std::vector<TexData> VecTexData; 00033 typedef std::vector<TexData*> VecTexDataP; 00034 00035 ////////////////////////////////////////////////////////////////////////// 00036 /// 00037 /// TexData 00038 /// - Base wrapper class used to set texture data 00039 /// - 'setTexData(...)' calls glTexImage*D(...) 00040 /// - This class stores all information necessary to describe the data to OpenGL. 00041 /// - If mipmap generation is desired, include a 'AutoMipGen' TexState in the texState 00042 /// passed to the 'SingleTex' that will use this data. 00043 /// - Note that this does a SHALLOW copy of the input data!!\ 00044 /// - Use subclasses to provide constructors for your favorite data structures 00045 /// - NOTE: To have OpenGL compress a texture image, pass in a compressed format \n 00046 /// for the internal type 00047 /// 00048 /// To pass OpenGL a pre-compressed texture image, use the 2 default parameters in the ctor 00049 /// 00050 /// TexData - Wrapper for texture data. Makes the OpenGL calls to set the texture data 00051 ////////////////////////////////////////////////////////////////////////////////// 00052 class _export_ TexData : public GliftObject 00053 { 00054 public: 00055 TexData( GLenum texDimenName, 00056 const gutz::vec3i& origin, 00057 const gutz::vec3i& dimen, 00058 int borderW, 00059 GLenum internalFormat, 00060 GLenum dataFormat, 00061 GLenum dataType, 00062 void* data, 00063 bool isCompressed = false, // Use these 2 parameters for pre-compressed texture images 00064 int numDataBytes = 0 ); 00065 00066 /// Default copy constructor and assignment operator 00067 virtual ~TexData() {} 00068 00069 /// Make the OpenGL call to 'glTexImage*D(...)' or 'glTexSubImage*D(...)' 00070 void setTexData( GLenum texType, int mipLevel=0 ); /// Uses 'texType' for target 00071 00072 /// Accessors 00073 GLenum texType() const {return m_texDimenName;} 00074 gutz::vec3i dimen() const {return m_dimen;} 00075 void* data() const {return m_data;} 00076 00077 // Set functions 00078 void dataPtr(void* d) {m_data = d;} 00079 void orig( const gutz::vec3i& orig ) {m_texOrigin = orig;} 00080 void dimen(const gutz::vec3i& dim ) {m_dimen = dim;} 00081 00082 private: 00083 void* m_data; /// the data 00084 GLenum m_texDimenName; /// 1D, 2D, or 3D 00085 GLenum m_glFormat; /// internal format OpenGL 00086 GLenum m_dataFormat; /// external format OpenGL 00087 GLenum m_dataType; /// data type OpenGL 00088 gutz::vec3i m_texOrigin; /// location of data origin in texture map 00089 gutz::vec3i m_dimen; /// size of each dimen of the data 00090 int m_borderW; /// width of border in texels (embedded in data) 00091 bool m_isCompressed; /// Is this a compressed texture? 00092 int m_numBytes; /// Number of bytes in 'data' 00093 00094 void checkInput(); /// Check the input GLenum's 00095 void checkDimenName( GLenum texDimenName ); /// Only allow 1D, 2D, or 3D. Use multiple TexData objs for cubeMaps. 00096 void checkFormatData( GLenum format ); 00097 void checkFormatGL( GLenum format ); 00098 00099 // How many bytes are in 'data' 00100 int numBytes( const gutz::vec3i& size, GLenum dataFormat, GLenum dataType ); 00101 00102 /// Write the data to texture memory with 'glTexImage*D(...)' 00103 void texImageND( GLenum texType, int mipLevel ); 00104 00105 /// Replace part of all of the texture with 'glTexSubImage*D(...)' 00106 void texSubImageND( GLenum texType, int mipLevel ); 00107 }; 00108 00109 } /// End of namespace glift 00110 00111 #endif 00112