]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyTextureState.hpp
Clouds3D crashes because there is no Light
[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 Force();
45   SKYRESULT Activate();
46
47   SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, SkyTexture& texture);
48   SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, unsigned int iTextureID);
49   SKYRESULT EnableTexture(unsigned int iTextureUnit, bool bEnable);
50   SKYRESULT SetTextureParameter(unsigned int  iTextureUnit, 
51                                 GLenum        eParameter, 
52                                 GLenum        eMode);
53
54   inline GLenum       GetActiveTarget(unsigned int iTextureUnit) const;
55   inline unsigned int GetTextureID(unsigned int iTextureUnit) const;
56   inline bool         IsTextureEnabled(unsigned int iTextureUnit) const;
57   inline GLenum       GetTextureParameter(unsigned int iTextureUnit, GLenum eParameter) const;
58
59 protected: // datatypes    
60   struct TexState
61   {
62     TexState() : eActiveTarget(GL_TEXTURE_2D), iBoundTexture(0), bEnabled(false)
63     {
64       // set state to GL defaults.
65       int i;
66       for (i = 0; i < SKY_TEXCOORD_COUNT; ++i) { eWrapMode[i] = GL_REPEAT; }
67       eFilterMode[SKY_FILTER_MIN] = GL_NEAREST_MIPMAP_LINEAR;
68       eFilterMode[SKY_FILTER_MAG] = GL_LINEAR;
69     }
70
71     enum TexCoord
72     {
73       SKY_TEXCOORD_S,
74       SKY_TEXCOORD_T,
75       SKY_TEXCOORD_R,
76       SKY_TEXCOORD_COUNT
77     };
78     
79     enum TexFilter
80     {
81       SKY_FILTER_MIN,
82       SKY_FILTER_MAG,
83       SKY_FILTER_COUNT
84     };
85     
86     GLenum        eActiveTarget;
87     unsigned int  iBoundTexture; 
88     bool          bEnabled;
89     GLenum        eWrapMode[SKY_TEXCOORD_COUNT];       
90     GLenum        eFilterMode[SKY_FILTER_COUNT];  
91   };
92
93 protected: // data
94
95   TexState        *_pTextureUnitState;  // one per texture unit
96     
97   static unsigned int  s_iNumTextureUnits;
98 };
99
100
101 //------------------------------------------------------------------------------
102 // Function               : SkyTextureState::GetActiveTarget
103 // Description      : 
104 //------------------------------------------------------------------------------
105 /**
106  * @fn SkyTextureState::GetActiveTarget(unsigned int iTextureUnit) const
107  * @brief Returns the active texture target for the specified texture unit.
108  * 
109  * If an invalid texture unit is specifed, returns GL_NONE.
110  */ 
111 inline GLenum SkyTextureState::GetActiveTarget(unsigned int iTextureUnit) const
112 {
113   if (iTextureUnit >= s_iNumTextureUnits)
114   {
115     SkyTrace("SkyTextureState::GetActiveTexture(): Invalid texture unit.");
116     return GL_NONE;
117   }
118   return _pTextureUnitState[iTextureUnit].eActiveTarget;
119 }
120
121
122 //------------------------------------------------------------------------------
123 // Function               : int SkyTextureState::GetTextureID
124 // Description      : 
125 //------------------------------------------------------------------------------
126 /**
127 * @fn int SkyTextureState::GetTextureID(unsigned int iTextureUnit) const
128 * @brief Returns the texture ID associated with the specified texture unit.
129
130 * If an invalid texture unit is specifed, returns GL_NONE.
131 */ 
132 inline unsigned int SkyTextureState::GetTextureID(unsigned int iTextureUnit) const
133 {
134   if (iTextureUnit >= s_iNumTextureUnits)
135   {
136     SkyTrace("SkyTextureState::GetTextureID(): Invalid texture unit.");
137     return GL_NONE;
138   }
139   return _pTextureUnitState[iTextureUnit].iBoundTexture;
140 }
141
142
143 //------------------------------------------------------------------------------
144 // Function               : SkyTextureState::IsTextureEnabled
145 // Description      : 
146 //------------------------------------------------------------------------------
147 /**
148 * @fn SkyTextureState::IsTextureEnabled(unsigned int iTextureUnit) const
149 * @brief Returns the status (enabled or disabled) of the specified texture unit.
150
151 * If an invalid texture unit is specifed, returns false.
152 */ 
153 inline bool SkyTextureState::IsTextureEnabled(unsigned int iTextureUnit) const
154 {
155   if (iTextureUnit >= s_iNumTextureUnits)
156   {
157     SkyTrace("SkyTextureState::IsTextureEnabled(): Invalid texture unit.");
158     return false;
159   }
160   return _pTextureUnitState[iTextureUnit].bEnabled;
161 }
162
163
164 //------------------------------------------------------------------------------
165 // Function               : SkyTextureState::GetTextureParameter
166 // Description      : 
167 //------------------------------------------------------------------------------
168 /**
169  * @fn SkyTextureState::GetTextureParameter(unsigned int iTextureUnit, GLenum eParamter) const
170  * @brief Returns the current value of @eParameter on the specified texture unit.
171  * 
172  * If an invalid texture unit or parameter is specified, returns GL_NONE.
173  */ 
174 inline GLenum SkyTextureState::GetTextureParameter(unsigned int iTextureUnit, GLenum eParameter) const
175 {
176   if (iTextureUnit >= s_iNumTextureUnits)
177   {
178     SkyTrace("SkyTextureState::GetTextureParamter(): Invalid texture unit.");
179     return GL_NONE;
180   }
181
182   switch (eParameter)
183   {
184   case GL_TEXTURE_WRAP_S:
185     return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_S];
186     break;
187   case GL_TEXTURE_WRAP_T:
188     return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_T];
189     break;
190   case GL_TEXTURE_WRAP_R:
191     return _pTextureUnitState[iTextureUnit].eWrapMode[TexState::SKY_TEXCOORD_R];
192     break;
193   case GL_TEXTURE_MIN_FILTER:
194     return _pTextureUnitState[iTextureUnit].eFilterMode[TexState::SKY_FILTER_MIN];
195     break;
196   case GL_TEXTURE_MAG_FILTER:
197     return _pTextureUnitState[iTextureUnit].eFilterMode[TexState::SKY_FILTER_MAG];
198     break;
199   default:
200     SkyTrace("SkyTExtureState::SetTextureParameter(): Invalid parameter.");
201     break;
202   }
203   return GL_NONE;
204 }
205
206 #endif //__SKYTEXTURESTATE_HPP__