1 //------------------------------------------------------------------------------
2 // File : SkyTextureState.hpp
3 //------------------------------------------------------------------------------
4 // SkyWorks : Copyright 2002 Mark J. Harris and
5 // The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its
8 // documentation for any purpose is hereby granted without fee, provided that
9 // the above copyright notice appear in all copies and that both that copyright
10 // notice and this permission notice appear in supporting documentation.
11 // Binaries may be compiled with this software without any royalties or
14 // The author(s) and The University of North Carolina at Chapel Hill make no
15 // representations about the suitability of this software for any purpose.
16 // It is provided "as is" without express or
19 * @file SkyTextureState.hpp
21 * Interface Definition for class SkyTextureState, which encapsulates OpenGL texture state.
23 #ifndef __SKYTEXTURESTATE_HPP__
24 #define __SKYTEXTURESTATE_HPP__
26 #include "SkyUtil.hpp"
27 #include "SkyTexture.hpp"
28 #include "SkyContext.hpp"
31 //------------------------------------------------------------------------------
33 * @class SkyTextureState
34 * @brief A wrapper for texture unit state.
36 * @todo <WRITE EXTENDED CLASS DESCRIPTION>
46 SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, SkyTexture& texture);
47 SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, unsigned int iTextureID);
48 SKYRESULT EnableTexture(unsigned int iTextureUnit, bool bEnable);
49 SKYRESULT SetTextureParameter(unsigned int iTextureUnit,
53 inline GLenum GetActiveTarget(unsigned int iTextureUnit) const;
54 inline unsigned int GetTextureID(unsigned int iTextureUnit) const;
55 inline bool IsTextureEnabled(unsigned int iTextureUnit) const;
56 inline GLenum GetTextureParameter(unsigned int iTextureUnit, GLenum eParameter) const;
58 protected: // datatypes
61 TexState() : eActiveTarget(GL_TEXTURE_2D), iBoundTexture(0), bEnabled(false)
63 // set state to GL defaults.
65 for (i = 0; i < SKY_TEXCOORD_COUNT; ++i) { eWrapMode[i] = GL_REPEAT; }
66 eFilterMode[SKY_FILTER_MIN] = GL_NEAREST_MIPMAP_LINEAR;
67 eFilterMode[SKY_FILTER_MAG] = GL_LINEAR;
86 unsigned int iBoundTexture;
88 GLenum eWrapMode[SKY_TEXCOORD_COUNT];
89 GLenum eFilterMode[SKY_FILTER_COUNT];
94 TexState *_pTextureUnitState; // one per texture unit
96 static unsigned int s_iNumTextureUnits;
100 //------------------------------------------------------------------------------
101 // Function : SkyTextureState::GetActiveTarget
103 //------------------------------------------------------------------------------
105 * @fn SkyTextureState::GetActiveTarget(unsigned int iTextureUnit) const
106 * @brief Returns the active texture target for the specified texture unit.
108 * If an invalid texture unit is specifed, returns GL_NONE.
110 inline GLenum SkyTextureState::GetActiveTarget(unsigned int iTextureUnit) const
112 if (iTextureUnit >= s_iNumTextureUnits)
114 SkyTrace("SkyTextureState::GetActiveTexture(): Invalid texture unit.");
117 return _pTextureUnitState[iTextureUnit].eActiveTarget;
121 //------------------------------------------------------------------------------
122 // Function : int SkyTextureState::GetTextureID
124 //------------------------------------------------------------------------------
126 * @fn int SkyTextureState::GetTextureID(unsigned int iTextureUnit) const
127 * @brief Returns the texture ID associated with the specified texture unit.
129 * If an invalid texture unit is specifed, returns GL_NONE.
131 inline unsigned int SkyTextureState::GetTextureID(unsigned int iTextureUnit) const
133 if (iTextureUnit >= s_iNumTextureUnits)
135 SkyTrace("SkyTextureState::GetTextureID(): Invalid texture unit.");
138 return _pTextureUnitState[iTextureUnit].iBoundTexture;
142 //------------------------------------------------------------------------------
143 // Function : SkyTextureState::IsTextureEnabled
145 //------------------------------------------------------------------------------
147 * @fn SkyTextureState::IsTextureEnabled(unsigned int iTextureUnit) const
148 * @brief Returns the status (enabled or disabled) of the specified texture unit.
150 * If an invalid texture unit is specifed, returns false.
152 inline bool SkyTextureState::IsTextureEnabled(unsigned int iTextureUnit) const
154 if (iTextureUnit >= s_iNumTextureUnits)
156 SkyTrace("SkyTextureState::IsTextureEnabled(): Invalid texture unit.");
159 return _pTextureUnitState[iTextureUnit].bEnabled;
163 //------------------------------------------------------------------------------
164 // Function : SkyTextureState::GetTextureParameter
166 //------------------------------------------------------------------------------
168 * @fn SkyTextureState::GetTextureParameter(unsigned int iTextureUnit, GLenum eParamter) const
169 * @brief Returns the current value of @eParameter on the specified texture unit.
171 * If an invalid texture unit or parameter is specified, returns GL_NONE.
173 inline GLenum SkyTextureState::GetTextureParameter(unsigned int iTextureUnit, GLenum eParameter) const
175 if (iTextureUnit >= s_iNumTextureUnits)
177 SkyTrace("SkyTextureState::GetTextureParamter(): Invalid texture unit.");
183 case GL_TEXTURE_WRAP_S:
184 return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_S];
186 case GL_TEXTURE_WRAP_T:
187 return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_T];
189 case GL_TEXTURE_WRAP_R:
190 return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_R];
192 case GL_TEXTURE_MIN_FILTER:
193 return _pTextureUnitState[iTextureUnit].eFilterMode[TexState::SKY_FILTER_MIN];
195 case GL_TEXTURE_MAG_FILTER:
196 return _pTextureUnitState[iTextureUnit].eFilterMode[TexState::SKY_FILTER_MAG];
199 SkyTrace("SkyTExtureState::SetTextureParameter(): Invalid parameter.");
205 #endif //__SKYTEXTURESTATE_HPP__