1 //------------------------------------------------------------------------------
2 // File : SkyMaterial.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 SkyMaterial.hpp
21 * Interface definition for class SkyMaterial, a meterial property object.
23 #ifndef __SKYMATERIAL_HPP__
24 #define __SKYMATERIAL_HPP__
26 // #pragma warning( disable : 4786)
29 # include <simgear_config.h>
39 #include "SkyUtil.hpp"
40 #include "SkyTextureManager.hpp"
41 #include "SkyTextureState.hpp"
47 //------------------------------------------------------------------------------
50 * @brief A class for organizing and caching material state.
52 * This class handles setting and querying material state. By calling the Activate()
53 * method, the material's state can be made current in OpenGL. The material will not
54 * set states that are currently active in the current OpenGL context.
65 // Getters for basic material properties
67 //! Returns the material identifier.
68 int GetMaterialID() const { return _iMaterialID; }
69 //! Returns the material diffuse color.
70 const Vec4f& GetDiffuse() const { return _vecDiffuse; }
71 //! Returns the material specular color.
72 const Vec4f& GetSpecular() const { return _vecSpecular; }
73 //! Returns the material ambient color.
74 const Vec4f& GetAmbient() const { return _vecAmbient; }
75 //! Returns the material emissive color.
76 const Vec4f& GetEmissive() const { return _vecEmissive; }
77 //! Returns the material specular power (shininess).
78 const float GetSpecularPower() const { return _rSpecularPower; }
81 //! Returns true if lighting is enabled for this material.
82 bool IsLightingEnabled() const { return _bLighting; }
84 // color material (which material property tracks color calls)
85 //! Returns the face for which color material tracking is enabled.
86 GLenum GetColorMaterialFace() const { return _eColorMaterialFace; }
87 //! Returns the color material tracking mode.
88 GLenum GetColorMaterialMode() const { return _eColorMaterialMode; }
89 //! Returns true if color material tracking is enabled.
90 bool IsColorMaterialEnabled() const { return _bColorMaterial; }
92 //! Returns the fog density or start / end distance.
93 float GetFogParameter(GLenum eParameter) const;
94 //! Returns the fog mode (exponential, linear, etc.)
95 GLenum GetFogMode() const { return _eFogMode; }
96 //! Returns the fog color.
97 const Vec4f& GetFogColor() const { return _vecFogColor; }
98 //! Returns true if fog is enabled for this material.
99 bool IsFogEnabled() const { return _bFog; }
102 //! Returns the active texture target for texture unit @a iTextureUnit.
103 GLenum GetActiveTarget(unsigned int iTextureUnit) const
104 { return _textureState.GetActiveTarget(iTextureUnit); }
105 //! Returns the bound texture ID for texture unit @a iTextureUnit.
106 unsigned int GetTextureID(unsigned int iTextureUnit) const
107 { return _textureState.GetTextureID(iTextureUnit); }
108 //! Returns true if texturing is enabled for texture unit @a iTextureUnit.
109 bool IsTextureEnabled(unsigned int iTextureUnit) const
110 { return _textureState.IsTextureEnabled(iTextureUnit); }
111 //! Returns the value of the texture parameter @a eParameter for texture unit @a iTextureUnit.
112 GLenum GetTextureParameter(unsigned int iTextureUnit, GLenum eParameter) const
113 { return _textureState.GetTextureParameter(iTextureUnit, eParameter); }
114 //! Returns the texture application mode of the texture environment.
115 GLenum GetTextureApplicationMode() const { return _eTextureEnvMode; }
117 //! Returns a reference to the texture state object owned by this materal.
118 SkyTextureState& GetTextureState() { return _textureState; }
121 //! Returns true if depth testing is enabled for this material.
122 bool IsDepthTestEnabled() const { return _bDepthTest; }
123 //! Returns the depth test function for this material.
124 GLenum GetDepthFunc() const { return _eDepthFunc; }
125 //! Returns true if depth writes are enabled for this material, false if not.
126 bool GetDepthMask() const { return _bDepthMask; }
129 //! Returns true if alpha testing is enabled for this material.
130 bool IsAlphaTestEnabled() const { return _bAlphaTest; }
131 //! Returns the alpha test function for this material.
132 GLenum GetAlphaFunc() const { return _eAlphaFunc; }
133 //! Returns the reference value for alpha comparison.
134 float GetAlphaRef() const { return _rAlphaRef; }
137 //! Returns true if blending is enabled for this material.
138 bool IsBlendingEnabled() const { return _bBlending; }
139 //! Returns the source blending factor for this material.
140 GLenum GetBlendingSourceFactor() const { return _eBlendSrcFactor; }
141 //! Returns the destination blending factor for this material.
142 GLenum GetBlendingDestFactor() const { return _eBlendDstFactor; }
144 //! Returns true if face culling enabled for this material.
145 bool IsFaceCullingEnabled() const { return _bFaceCulling; }
146 //! Returns which faces are culled -- front-facing or back-facing.
147 GLenum GetFaceCullingMode() const { return _eFaceCullingMode; }
149 // Setters for basic material properties
151 //! Sets the material identifier.
152 void SetMaterialID(int ID) { _iMaterialID = ID; }
153 //! Sets the diffuse material color.
154 void SetDiffuse( const Vec4f& d) { _vecDiffuse = d; }
155 //! Sets the specular material color.
156 void SetSpecular(const Vec4f& d) { _vecSpecular = d; }
157 //! Sets the ambient material color.
158 void SetAmbient( const Vec4f& d) { _vecAmbient = d; }
159 //! Sets the emissive material color.
160 void SetEmissive(const Vec4f& d) { _vecEmissive = d; }
161 //! Sets the material specular power (shininess).
162 void SetSpecularPower(float power) { _rSpecularPower = power; }
165 //! Enables / Disables lighting for this material.
166 void EnableLighting(bool bEnable) { _bLighting = bEnable; }
168 // color material (which material property tracks color calls)
169 //! Sets which faces (front or back) track color calls.
170 void SetColorMaterialFace(GLenum eFace) { _eColorMaterialFace = eFace; }
171 //! Sets which material property tracks color calls.
172 void SetColorMaterialMode(GLenum eMode) { _eColorMaterialMode = eMode; }
173 //! Enables / Disables material color tracking for this material.
174 void EnableColorMaterial(bool bEnable) { _bColorMaterial = bEnable; }
176 //! Sets the fog density or start / end distance.
177 SKYRESULT SetFogParameter(GLenum eParameter, float rValue);
178 //! Sets the fog mode (exponential, linear, etc.)
179 void SetFogMode(GLenum eMode) { _eFogMode = eMode; }
180 //! Sets the fog color.
181 void SetFogColor(const Vec4f& color) { _vecFogColor = color; }
182 //! Enables / Disables fog for this material.
183 void EnableFog(bool bEnable) { _bFog = bEnable; }
186 //! Sets the bound texture and texture target for texture unit @a iTextureUnit.
187 SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, SkyTexture& texture)
188 { return _textureState.SetTexture(iTextureUnit, eTarget, texture); }
189 //! Sets the bound texture and texture target for texture unit @a iTextureUnit.
190 SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, unsigned int iTextureID)
191 { return _textureState.SetTexture(iTextureUnit, eTarget, iTextureID); }
192 //! Enables / Disables texture unit @a iTextureUnit for this material.
193 SKYRESULT EnableTexture(unsigned int iTextureUnit, bool bEnable)
194 { return _textureState.EnableTexture(iTextureUnit, bEnable); }
195 //! Sets the value of the texture parameter @a eParameter for texture unit @a iTextureUnit.
196 SKYRESULT SetTextureParameter(unsigned int iTextureUnit, GLenum eParameter, GLenum eMode)
197 { return _textureState.SetTextureParameter(iTextureUnit, eParameter, eMode); }
199 //! Sets the texture application mode of the texture environment.
200 void SetTextureApplicationMode(GLenum eMode){ _eTextureEnvMode = eMode;}
203 //! Enables / Disables depth test for this material.
204 void EnableDepthTest(bool bEnable) { _bDepthTest = bEnable; }
205 //! Sets the depth test function (greater, less than, equal, etc.).
206 void SetDepthFunc(GLenum eDepthFunc) { _eDepthFunc = eDepthFunc;}
207 //! If @a bDepthMask is true, then depth writes are enabled, otherwise they are not.
208 void SetDepthMask(bool bDepthMask) { _bDepthMask = bDepthMask;}
211 //! Enables / Disables alpha test for this material.
212 void EnableAlphaTest(bool bEnable) { _bAlphaTest = bEnable; }
213 //! Sets the alpha test function (greater, less than, equal, etc.).
214 void SetAlphaFunc(GLenum eAlphaFunc) { _eAlphaFunc = eAlphaFunc;}
215 //! Sets the reference value against which fragment alpha values are compared.
216 void SetAlphaRef(float rAlphaRef) { _rAlphaRef = rAlphaRef; }
219 //! Enables / Disables blending for this material.
220 void EnableBlending(bool bEnable) { _bBlending = bEnable; }
221 //! Sets the source and destination blending factors for this material.
222 void SetBlendFunc(GLenum eSrcFactor, GLenum eDstFactor)
223 { _eBlendSrcFactor = eSrcFactor; _eBlendDstFactor = eDstFactor; }
225 //! Enables / Disables face culling for this material.
226 void EnableFaceCulling(bool bEnable) { _bFaceCulling = bEnable; }
227 //! Sets which faces will be culled -- front facing or back facing.
228 void SetFaceCullingMode(GLenum eMode) { _eFaceCullingMode = eMode; }
238 float _rSpecularPower;
242 GLenum _eColorMaterialFace;
243 GLenum _eColorMaterialMode;
244 bool _bColorMaterial;
256 float _rFogParams[SKY_FOG_NUM_PARAMS];
267 GLenum _eBlendSrcFactor;
268 GLenum _eBlendDstFactor;
272 GLenum _eFaceCullingMode;
274 SkyTextureState _textureState;
275 GLenum _eTextureEnvMode;
278 #endif //__SKYMATERIAL_HPP__