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

texState.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 
00020 #ifndef GLIFT_TEXSTATE_H_
00021 #define GLIFT_TEXSTATE_H_
00022 
00023 #include "../core/gliftObject.h"
00024 #include <GL/glew.h>
00025 #include "../state/stateGLI.h"
00026 #include <mathGutz.h>
00027 #include <vector>
00028 
00029 namespace glift {
00030 
00031 /// Typedefs
00032 class TexState;
00033 typedef std::vector<TexState>           VecTexState;
00034 typedef std::vector<TexState*>          VecTexStateP;
00035 
00036 class TexObjState;
00037 typedef std::vector<TexObjState>        VecTexOState;
00038 typedef std::vector<TexObjState*>       VecTexOStateP;
00039 
00040 class TexUnitState;
00041 typedef std::vector<TexUnitState>       VecTexUState;
00042 typedef std::vector<TexUnitState*>      VecTexUStateP;
00043 
00044 ////////////////////////////////////////////////////////
00045 /// Global, pre-defined TexState pointers
00046 /// - These are here for conveniently pre-defined states that are common
00047 ////////////////////////////////////////////////////////
00048 class EdgeModeTex;
00049 class FilterTex;
00050 class MipMapTex;
00051 class FuncTex;
00052 class CoordGenTex;
00053 
00054 extern const EdgeModeTex        *TS_S_CLAMP, *TS_T_CLAMP, *TS_R_CLAMP, 
00055                            *TS_S_CLAMP_TO_EDGE, *TS_T_CLAMP_TO_EDGE, *TS_R_CLAMP_TO_EDGE, 
00056                            *TS_S_REPEAT, *TS_T_REPEAT, *TS_R_REPEAT;
00057 extern const FilterTex          *TS_NEAREST, *TS_LINEAR;
00058 extern const MipMapTex          *TS_NEAREST_MIPMAP_NEAREST, *TS_LINEAR_MIPMAP_NEAREST, *TS_LINEAR_MIPMAP_LINEAR;
00059 extern const FuncTex               *TS_MODULATE, *TS_REPLACE, *TS_DECAL;
00060 
00061 
00062 /////////////////////////////////////////////////////////////////////////
00063 ///
00064 /// TexState - Abstract base class for all texture object state.
00065 ///                     - 'texType' is GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_CUBE_MAP_ARB, ...
00066 ///                     - Each subclass makes the appropriate OpenGL, texturing call when 'setTexState(...)' is called.
00067 ///                     - This is designed to be called after a texture is bound and only by 'SingleTex'.
00068 ///                       'setTexState(...)' has been left public for flexibility...use at your own risk.
00069 ///                     - This is _not_ part of the 'StateGLI' tree because of the need to pass 'texType' to
00070 ///                       'bind(texType)'. It is also justified because all of this OpenGL
00071 ///                       state is associated with a particular texture object or texture unit
00072 ///                       and is thus not general OpenGL state.
00073 ///                       
00074 /// TexObjState         - TexState associated with an OpenGL texture object. \n
00075 /// TexUnitState        - TexState associated with an OpenGL texture unit. \n
00076 ///
00077 ////////////////////
00078 /// Concrete classes:
00079 ////////////////////
00080 ///
00081 /// EdgeModeTex         - Boundary conditions. GL_REPEAT, GL_CLAMP, ... \n
00082 /// FilterTex      - Filter mode: GL_NEAREST, GL_LINEAR. No mipmapping allowed \n
00083 /// MipMapTex      - Filter modes for mipmapping, mipmap generation, LOD, ... \n
00084 /// FuncTex                - Texture function: GL_REPLACE, GL_MODULATE, ... \n
00085 /// PriorityTex - Texture priority: [0,1] \n
00086 /// BorderTex      - Texture border color: gutz::vec4f \n
00087 /// CoordGenTex - Automatic texture coordinate generation: GL_OBJECT_LINEAR,GL_NORMAL_MAP_ARB, .... \n
00088 ///
00089 ////////////////////////////////////////////////////////////////////////
00090 
00091 ////////////////////////////////////////////////////////
00092 /// TexState - Abstract base class for all texture state
00093 ////////////////////////////////////////////////////////
00094 class _export_ TexState : public GliftObject
00095 {
00096 public:
00097    virtual ~TexState() {}
00098    virtual void bind( GLenum texType ) const = 0;
00099    virtual void release() const {}                      /// Most subclasses will not be 'release()'able.
00100 };
00101 
00102 ////////////////////////////////////////////////////////
00103 /// TexObjState - Abstract base class for all texture 
00104 ///                              state associated with a texture object
00105 ////////////////////////////////////////////////////////
00106 class _export_ TexObjState : public TexState
00107 {
00108 public:
00109    virtual ~TexObjState() {}
00110    virtual void bind( GLenum texType ) const = 0;
00111    virtual void release() const {}                      /// Most subclasses will not be 'release()'able.
00112 };
00113 
00114 ////////////////////////////////////////////////////////
00115 /// TexUnitState - Abstract base class for all texture 
00116 ///                               state associated with a texture unit
00117 ////////////////////////////////////////////////////////
00118 class _export_ TexUnitState : public TexState
00119 {
00120 public:
00121    virtual ~TexUnitState() {}
00122    virtual void bind( GLenum texType ) const = 0;
00123    virtual void release() const {}                      /// Most subclasses will not be 'release()'able.
00124 };
00125 
00126 ////////////////////////////////////////////////////////
00127 /// EdgeModeTex         - 'coord' is GL_S, GL_T, GL_R, GL_Q
00128 ///                             - 'edgeMode' is GL_CLAMP, GL_REPEAT, ...
00129 ////////////////////////////////////////////////////////
00130 class _export_ EdgeModeTex : public TexObjState
00131 {
00132 public:
00133    EdgeModeTex( GLenum coord, GLenum edgeMode );
00134    virtual void bind( GLenum texType ) const;
00135 
00136    /// Set function
00137    void edgeMode( GLenum mode ) {m_edgeMode = mode;}
00138 
00139 private:
00140    GLenum m_coord;
00141    GLenum m_edgeMode;
00142 
00143    void checkInput();
00144 };
00145 
00146 ////////////////////////////////////////////////////////
00147 /// FilterTex - 'minFilter' is minification filter: GL_NEAREST or GL_LINEAR
00148 ///                      - 'magFilter' is magnification filter: GL_NEAREST or GL_LINEAR
00149 ///                      -  Note: To use mipmapping, use the 'MipMapTex' class
00150 ////////////////////////////////////////////////////////
00151 class _export_ FilterTex : public TexObjState
00152 {
00153 public:
00154    FilterTex( GLenum minFilter, GLenum magFilter );
00155    virtual void bind( GLenum texType ) const;
00156 
00157    /// Set functions
00158    void minFilter( GLenum filter ) {m_minFilter=filter;}
00159    void magFilter( GLenum filter ) {m_magFilter=filter;}
00160 
00161 private:
00162    GLenum m_minFilter;
00163    GLenum m_magFilter;
00164 
00165    void checkInput( GLenum minFilter, GLenum magFilter );
00166 };
00167 
00168 ////////////////////////////////////////////////////////
00169 /// MipMapTex - 'minFilter' is minification filter:
00170 ///                                     GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, 
00171 ///                                     GL_NEAREST_MIPMAP_LINEAR,  GL_LINEAR_MIPMAP_LINEAR
00172 ///                      - 'magFilter' is magnification filter: GL_NEAREST or GL_LINEAR
00173 ///                      - 'autoMipGen' enables/diables GL_GENERATE_MIPMAP_SGIS
00174 ///                      - 'minLevel' is minimum mipmap level
00175 ///                      - 'maxLevel' is maximum mipmap level
00176 ///                      - 'minLOD'   is minimum mipmap lambda value
00177 ///                      - 'maxLOD'       is maximum mipmap lambda value
00178 ///                        Note: lambda = lg( rho ) base2 
00179 ///                                      rho   = scale factor between texture size and polygon
00180 ////////////////////////////////////////////////////////
00181 class _export_ MipMapTex : public TexObjState
00182 {
00183 public:
00184    MipMapTex( GLenum minFilter, GLenum magFilter, bool autoMipGen=false );      /// Calls FilterTex constructor
00185    MipMapTex( GLenum minFilter, GLenum magFilter, bool autoMipGen,                      /// Calls FilterTex constructor
00186       int minLevel, int maxLevel, float minLOD, float maxLOD );
00187 
00188    virtual void bind( GLenum texType ) const;/// Calls FilterTex.bind(...)
00189    virtual void release() const;                          /// Disable autoMipGen, set level and LOD back to default (false, 0, 1000, -1000, +1000)
00190 
00191    /// Get/Set Functions
00192    bool         autoMipGen() const      {return m_autoMipGen;}
00193    int          minLevel() const        {return m_minLevel;}
00194    int          maxLevel() const        {return m_maxLevel;}
00195    float        minLOD() const          {return m_minLOD;}
00196    float        maxLOD() const          {return m_minLOD;}
00197 
00198    void minFilter( GLenum filt){m_minFilter = filt;}
00199    void magFilter( GLenum filt){m_magFilter = filt;}
00200    void autoMipGen( bool val )  {m_autoMipGen= val; }
00201    void minLevel( int val )     {m_minLevel      = val; }
00202    void maxLevel( int val )     {m_maxLevel      = val; }
00203    void minLOD(   float val )   {m_minLOD        = val; }
00204    void maxLOD(   float val )   {m_maxLOD        = val; }
00205 
00206 private:
00207    const int    m_MIN_LEVEL; /// OpenGL defaults (according to RedBook 1.2)
00208    const int    m_MAX_LEVEL;
00209    const float m_MIN_LOD;
00210    const float m_MAX_LOD;
00211 
00212    GLenum       m_minFilter;    /// Input params
00213    GLenum       m_magFilter;
00214    bool m_autoMipGen;    
00215    int  m_minLevel;
00216    int          m_maxLevel;
00217    float        m_minLOD;
00218    float        m_maxLOD;
00219 
00220    void checkInput( GLenum minFilter, GLenum magFilter );
00221 };
00222 
00223 //////////////////////////////////////////////////////////////
00224 /// FuncTex - 'texFunc' is GL_REPLACE, GL_MODULATE, GL_DECAL
00225 ///                -  Use the 'blendColor' constructor to use GL_BLEND
00226 //////////////////////////////////////////////////////////////
00227 class _export_ FuncTex : public TexUnitState
00228 {
00229 public:
00230    FuncTex( GLenum texFunc );                   
00231    FuncTex( const gutz::vec4f& blendColor );
00232 
00233    virtual void bind( GLenum texType ) const;
00234 
00235    gutz::vec4f color() const                    {return m_blendColor;}
00236    void  color( const gutz::vec4f& val ) {m_blendColor = val;}
00237    void  texFunc( GLenum mode ) {m_texFunc = mode;}
00238 
00239 private:
00240    GLenum       m_texFunc;
00241    gutz::vec4f  m_blendColor;
00242 };
00243 
00244 ////////////////////////////////////////////////////////////////////////////
00245 /// PriorityTex - 'priority' is in [0,1] and sets the texture object's priority
00246 ///                        - 0.0 is lowest, 1.0 is highest priority
00247 ////////////////////////////////////////////////////////////////////////////
00248 class _export_ PriorityTex : public TexObjState
00249 {
00250 public:
00251    PriorityTex( GLfloat priority );
00252    virtual void bind( GLenum texType ) const;
00253 
00254    GLfloat priority() const             {return m_priority;}
00255    void priority( GLfloat val ) {m_priority = val;}
00256 
00257 private:
00258    GLfloat m_priority;
00259 };
00260 
00261 //////////////////////////////////////////////////////////////
00262 /// BorderTex - 'color' sets the texture border color
00263 //////////////////////////////////////////////////////////////
00264 class _export_ BorderTex : public TexObjState
00265 {
00266 public:
00267    BorderTex( const gutz::vec4f& color );
00268 
00269    virtual void bind( GLenum texType ) const;
00270 
00271    gutz::vec4f color() const                    {return m_color;}
00272    void  color( const gutz::vec4f& col ) {m_color = col;}
00273 
00274 private:
00275    gutz::vec4f m_color;
00276 };
00277 
00278 ////////////////////////////////////////////////////////////////////////////
00279 /// CoordGenTex - Set state for automatic texture coordinate generation
00280 ///                        - 'coord' is GL_S, GL_T, GL_R, GL_S
00281 ///                        - 'genMode' is GL_OBJECT_LINEAR, GL_EYE_LINEAR, GL_SPHERE_MAP, 
00282 ///                                                       GL_REFLECTION_MAP_ARB, GL_NORMAL_MAP_ARB
00283 ///                        - 'planeCoeff' contains the coefficients for the plane equation
00284 ///                        - 'state' is a vector of GenState ptrs to set the state before 
00285 ///                          setting the plane eqn with GL_EYE_LINEAR.
00286 ///                          Note: bind() and release() will be called for all pts in 'state'
00287 ////////////////////////////////////////////////////////////////////////////
00288 class _export_ CoordGenTex : public TexUnitState
00289 {
00290 public:
00291    CoordGenTex( GLenum coord, GLenum genMode );
00292    CoordGenTex( GLenum coord, GLenum genMode, const gutz::vec4f& planeCoeff, const VecStateP& state=VecStateP() );
00293 
00294    virtual void bind( GLenum texType ) const;
00295    virtual void release() const;        /// Default: Disable automatic coordGen
00296 
00297    /// Accessors
00298    gutz::vec4f plane() const {return m_plane;}
00299 
00300    /// Set functions
00301    void plane( const gutz::vec4f& planeCoeff ) {m_plane = planeCoeff;}
00302    void genMode( GLenum mode )                    {m_genMode = mode;}
00303 
00304 private:
00305    GLenum                       m_coord;        /// GL_S, GL_T, ...
00306    GLenum                       m_genMode;      /// GL_OBJECT_LINEAR, ...
00307    gutz::vec4f  m_plane;        /// Plane equation coefficients
00308    GLenum                       m_coordGen; /// GL_TEXTURE_GEN_S, ...
00309    VecStateP            m_state;        /// Vector of GenState pointers for setting EyeLinear plane.
00310 
00311    void checkInput();
00312 };
00313 
00314 } /// End of namespace glift
00315 
00316 #endif

Send questions, comments, and bug reports to:
jmk