arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

singleTex.h

Go to the documentation of this file.
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_SINGLE_TEXTURE_H_
00020 #define GLIFT_SINGLE_TEXTURE_H_
00021 
00022 #include "multiTexState.h"
00023 #include "texture.h"
00024 #include "texData.h"
00025 #include "../state/pbuffGlift.h"
00026 #include <GL/glew.h>
00027 #include <mathGutz.h>
00028 #include <arrayGutz.h>
00029 #include <vector>
00030 #include <smartptr.h>
00031 
00032 namespace glift {
00033 
00034 /////////////////////////////////////////////////////////////////////////
00035 ///
00036 /// SingleTex - Single texture base class.
00037 ///                      - NOT publicly constructable
00038 ///                      - Data may be passed in with 'setTexData(...)' or the pbuffer 
00039 ///                 memory may be used.
00040 ///                      - StateGLI is handled by calling 'setTexState(...)' 
00041 ///                 on the objects in the 'm_texState' array.
00042 ///                      - Designed to encapsulate all OpenGL texture functionality
00043 ///                      - Designed to be extensible by defining additional TexState classes
00044 ///
00045 /// SingleTex - Abstract base class for all 
00046 ///                             Single texture classes
00047 //////////////////////////////////////////////////
00048 class _export_ SingleTex : 
00049    public Texture
00050 {
00051 
00052 public:
00053    virtual ~SingleTex() {}
00054 
00055    /// The 'Texture' interface
00056    virtual int                  numTexUnits() const     {return 1;} 
00057    /// 1D, 2D, 3D, CUBE_MAP, ...
00058    virtual GLenum                       texType() const                 = 0;
00059    /// The OpenGL texture number (name)
00060    virtual GLuint                       texNum() const                  = 0;
00061    /// Ptr to the pbuffer
00062    virtual PBuffGlift*  pbuff() const                   = 0;
00063    /// Dimen of the current data
00064    virtual gutz::vec3i  dimen() const                   = 0;
00065    /// will it try to use a pbuffer
00066    virtual bool                 tryToBindPbuff() const  = 0;
00067 
00068    /// set/get the texture coordinate number this texture should use
00069    virtual void            setTexCoordNum(int texCNum) = 0;
00070    virtual int             getTexCoordNum()            = 0;
00071 
00072    // Read texture data back from the card
00073    virtual void                 getDataub( GLenum format, int mipLevel, gutz::arraybub& data ) = 0;
00074    virtual void                 getDataf(  GLenum format, int mipLevel, gutz::arraybf&  data ) = 0;
00075 
00076    /// Set Functions
00077    /// Assume no cube map (Cube map subclass handles this)
00078    virtual void setTexData( TexData* texData, int mipLevel=0, bool setTexSize=true ) = 0;
00079    /// Add texture object state
00080    virtual void setTexState( TexObjState* state )                               = 0; 
00081    /// Bind new texState vector and set the state therein
00082    virtual void setTexState( const MultiTexOState& texState )  = 0; 
00083    /// Should the pbuffer be bound with the texture?
00084    virtual void tryToBindPbuff( bool tryToUsePbuff )                    = 0; 
00085 
00086    /// Call correct copyToTex. "texOrig" will ignore unused components depending on dimension of texture
00087    virtual void copyToTex( int mipLevel,
00088       const gutz::vec3i& texOrig, 
00089       const gutz::vec2i& screenOrig, 
00090       const gutz::vec2i& copySize   ) = 0;
00091 
00092 protected:
00093    virtual void bindDef() = 0;
00094    virtual void releaseDef() = 0;
00095 };
00096 
00097 typedef gutz::SmartPtr<SingleTex> SingleTexSP;
00098 typedef std::vector<SingleTexSP>  SingleTexSPVec;
00099 typedef SingleTexSPVec::iterator  SingleTexSPVecIter;
00100 const SingleTexSPVec              SingleTexSPVec_empty;
00101 
00102 
00103 typedef std::vector<SingleTex*>  VecTexP;
00104 typedef VecTexP::iterator        VecTexPIter;
00105 const VecTexP  VecTexP_empty;
00106 
00107 ///////////////////////////////////////////////////////////////
00108 /// CoreTex base class
00109 //      - The "almost-concrete" implementation base class for single
00110 //    textures. The only pure-virtual function is 'copyToTex(...)'
00111 //  - Note: CoreTex does NOT own the 'texState' object...it just uses it.
00112 //      - Note: The constructor can only be called by a subclass.
00113 ///////////////////////////////////////////////////////////////
00114 class _export_ CoreTex : public SingleTex
00115 {
00116 public:
00117    /// Default copy constructor and assignment operator
00118    virtual ~CoreTex();
00119 
00120    /// Accessors
00121    virtual GLenum               texType() const                    {return m_texType; } /// 1D, 2D, 3D, CUBE_MAP, ...
00122    virtual GLuint                       texNum() const                     {return m_texNum;}           /// The OpenGL texture number
00123         virtual PBuffGlift*     pbuff() const                           {return m_pbuff; }              /// Ptr to the  pbuffer
00124    virtual gutz::vec3i  dimen() const                   {return m_dataDimen; }  /// Dimen of the current data
00125    virtual bool                 tryToBindPbuff() const  {return m_tryToBindPbuff; }
00126 
00127    /// set/get the texture coordinate number this texture should use
00128    virtual void            setTexCoordNum(int texCNum) {m_tcNum = texCNum;}
00129    virtual int             getTexCoordNum()            {return m_tcNum;}
00130 
00131 
00132    // Read texture data back from the card
00133    virtual void                 getDataub( GLenum format, int mipLevel, gutz::arraybub& data );
00134    virtual void                 getDataf(  GLenum format, int mipLevel, gutz::arraybf&  data );
00135 
00136    /// Set Functions
00137    /// Assume no cube map (Cube map subclass handles this)
00138    virtual void setTexData(  TexData* texData, int mipLevel=0, bool setTexSize=true );
00139    /// Set individual texObjState (gets added to m_texObjState)
00140    virtual void setTexState( TexObjState* state );                      
00141    /// Set all texture object state specified by 'texState'
00142    virtual void setTexState( const MultiTexOState& texState );  
00143    /// Should the pbuffer be bound with the texture?
00144    virtual void tryToBindPbuff( bool tryToUsePbuff ) {m_tryToBindPbuff = tryToUsePbuff;} 
00145 
00146 protected:
00147    CoreTex( GLenum texType, const MultiTexOState& texState, TexData* texData, PBuffGlift* pbuff=NULL );
00148 
00149    /// The 'StateGLI' interface
00150    virtual void bindDef();
00151    virtual void releaseDef();
00152 
00153    /// Sanity checkers
00154    void checkTexType( GLenum texType );                                         /// Check for valid texType (1D, 2D, 3D, or CUBE)       
00155 
00156    /// Set functions
00157    void dataDimen( const gutz::vec3i& dimen ) { m_dataDimen = dimen; }
00158 
00159 private:
00160    GLenum                        m_texType;        /// 1D, 2D, 3D, CUBE_MAP, ...
00161    //MultiTexOState m_texObjState;         /// Vector of TexObjState objects
00162    PBuffGlift*           m_pbuff;                  /// Ptr to pbuffer to bind as texture memory (or NULL)
00163    GLuint                        m_texNum;                 /// OpenGL texture object ID
00164    bool                     m_tryToBindPbuff; /// Should the pbuff be bound with the texture? (default to true)
00165    bool                     m_pbuffBound;          /// Is a pbuffer currently bound?
00166    gutz::vec3i   m_dataDimen;      /// Dimen of passed-in data
00167 
00168    int             m_tcNum;
00169 
00170    /// Ensure that texObj and data have compatible tex target types
00171    void checkTexType( GLenum objTexType, GLenum dataTexType );  
00172 
00173    CoreTex();           /// Disallow default construction                                         
00174 };
00175 
00176 } /// End of namespace glift
00177 
00178 #endif
00179 

Send questions, comments, and bug reports to:
jmk