]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyTextureState.hpp
Tweak lib name.
[simgear.git] / simgear / scene / sky / clouds3d / SkyTextureState.hpp
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 
12 // restrictions. 
13 //
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 
17 // implied warranty.
18 /**
19 * @file SkyTextureState.hpp
20
21 * Interface Definition for class SkyTextureState, which encapsulates OpenGL texture state.
22 */
23 #ifndef __SKYTEXTURESTATE_HPP__
24 #define __SKYTEXTURESTATE_HPP__
25
26 #include "SkyUtil.hpp"
27 #include "SkyTexture.hpp"
28 #include "SkyContext.hpp"
29 #include <map>
30
31 //------------------------------------------------------------------------------
32 /**
33 * @class SkyTextureState
34 * @brief A wrapper for texture unit state.
35
36 * @todo <WRITE EXTENDED CLASS DESCRIPTION>
37 */
38 class SkyTextureState
39 {
40 public: // methods
41         SkyTextureState();
42         ~SkyTextureState();
43
44   SKYRESULT Activate();
45
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, 
50                                 GLenum        eParameter, 
51                                 GLenum        eMode);
52
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;
57
58 protected: // datatypes    
59   struct TexState
60   {
61     TexState() : eActiveTarget(GL_TEXTURE_2D), iBoundTexture(0), bEnabled(false)
62     {
63       // set state to GL defaults.
64       int i;
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;
68     }
69
70     enum TexCoord
71     {
72       SKY_TEXCOORD_S,
73       SKY_TEXCOORD_T,
74       SKY_TEXCOORD_R,
75       SKY_TEXCOORD_COUNT
76     };
77     
78     enum TexFilter
79     {
80       SKY_FILTER_MIN,
81       SKY_FILTER_MAG,
82       SKY_FILTER_COUNT
83     };
84     
85     GLenum        eActiveTarget;
86     unsigned int  iBoundTexture; 
87     bool          bEnabled;
88     GLenum        eWrapMode[SKY_TEXCOORD_COUNT];       
89     GLenum        eFilterMode[SKY_FILTER_COUNT];  
90   };
91
92 protected: // data
93
94   TexState        *_pTextureUnitState;  // one per texture unit
95     
96   static unsigned int  s_iNumTextureUnits;
97 };
98
99
100 //------------------------------------------------------------------------------
101 // Function               : SkyTextureState::GetActiveTarget
102 // Description      : 
103 //------------------------------------------------------------------------------
104 /**
105  * @fn SkyTextureState::GetActiveTarget(unsigned int iTextureUnit) const
106  * @brief Returns the active texture target for the specified texture unit.
107  * 
108  * If an invalid texture unit is specifed, returns GL_NONE.
109  */ 
110 inline GLenum SkyTextureState::GetActiveTarget(unsigned int iTextureUnit) const
111 {
112   if (iTextureUnit >= s_iNumTextureUnits)
113   {
114     SkyTrace("SkyTextureState::GetActiveTexture(): Invalid texture unit.");
115     return GL_NONE;
116   }
117   return _pTextureUnitState[iTextureUnit].eActiveTarget;
118 }
119
120
121 //------------------------------------------------------------------------------
122 // Function               : int SkyTextureState::GetTextureID
123 // Description      : 
124 //------------------------------------------------------------------------------
125 /**
126 * @fn int SkyTextureState::GetTextureID(unsigned int iTextureUnit) const
127 * @brief Returns the texture ID associated with the specified texture unit.
128
129 * If an invalid texture unit is specifed, returns GL_NONE.
130 */ 
131 inline unsigned int SkyTextureState::GetTextureID(unsigned int iTextureUnit) const
132 {
133   if (iTextureUnit >= s_iNumTextureUnits)
134   {
135     SkyTrace("SkyTextureState::GetTextureID(): Invalid texture unit.");
136     return GL_NONE;
137   }
138   return _pTextureUnitState[iTextureUnit].iBoundTexture;
139 }
140
141
142 //------------------------------------------------------------------------------
143 // Function               : SkyTextureState::IsTextureEnabled
144 // Description      : 
145 //------------------------------------------------------------------------------
146 /**
147 * @fn SkyTextureState::IsTextureEnabled(unsigned int iTextureUnit) const
148 * @brief Returns the status (enabled or disabled) of the specified texture unit.
149
150 * If an invalid texture unit is specifed, returns false.
151 */ 
152 inline bool SkyTextureState::IsTextureEnabled(unsigned int iTextureUnit) const
153 {
154   if (iTextureUnit >= s_iNumTextureUnits)
155   {
156     SkyTrace("SkyTextureState::IsTextureEnabled(): Invalid texture unit.");
157     return false;
158   }
159   return _pTextureUnitState[iTextureUnit].bEnabled;
160 }
161
162
163 //------------------------------------------------------------------------------
164 // Function               : SkyTextureState::GetTextureParameter
165 // Description      : 
166 //------------------------------------------------------------------------------
167 /**
168  * @fn SkyTextureState::GetTextureParameter(unsigned int iTextureUnit, GLenum eParamter) const
169  * @brief Returns the current value of @eParameter on the specified texture unit.
170  * 
171  * If an invalid texture unit or parameter is specified, returns GL_NONE.
172  */ 
173 inline GLenum SkyTextureState::GetTextureParameter(unsigned int iTextureUnit, GLenum eParameter) const
174 {
175   if (iTextureUnit >= s_iNumTextureUnits)
176   {
177     SkyTrace("SkyTextureState::GetTextureParamter(): Invalid texture unit.");
178     return GL_NONE;
179   }
180
181   switch (eParameter)
182   {
183   case GL_TEXTURE_WRAP_S:
184     return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_S];
185     break;
186   case GL_TEXTURE_WRAP_T:
187     return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_T];
188     break;
189   case GL_TEXTURE_WRAP_R:
190     return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_R];
191     break;
192   case GL_TEXTURE_MIN_FILTER:
193     return _pTextureUnitState[iTextureUnit].eFilterMode[TexState::SKY_FILTER_MIN];
194     break;
195   case GL_TEXTURE_MAG_FILTER:
196     return _pTextureUnitState[iTextureUnit].eFilterMode[TexState::SKY_FILTER_MAG];
197     break;
198   default:
199     SkyTrace("SkyTExtureState::SetTextureParameter(): Invalid parameter.");
200     break;
201   }
202   return GL_NONE;
203 }
204
205 #endif //__SKYTEXTURESTATE_HPP__