00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include "nvmath/Vec3f.h"
00018 #include "nvsg/StateAttribute.h"
00019
00020
00021 namespace nvsg
00022 {
00023 class Material;
00024
00025
00026 # if ! defined( DOXYGEN_IGNORE )
00027 class MaterialData : public nvutil::RCObject
00028 {
00029 friend class Material;
00030
00031 public:
00033
00035 NVSG_API MaterialData(const MaterialData& rhs);
00036
00037 private:
00038
00039 MaterialData();
00040 ~MaterialData();
00041
00042 MaterialData& operator=(const MaterialData& rhs) {}
00043
00044 nvmath::Vec3f m_ambientColor;
00045 nvmath::Vec3f m_diffuseColor;
00046 nvmath::Vec3f m_emissiveColor;
00047 float m_opacity;
00048 nvmath::Vec3f m_specularColor;
00049 float m_specularExponent;
00050 };
00051 #endif // DOXYGEN_IGNORE
00052
00054
00061 class Material : public StateAttribute
00062 {
00063 public:
00065
00066 NVSG_API static const Material * create( void );
00067
00069
00070 NVSG_API static const Material * createFromBase( const StateAttribute &rhs
00071 );
00072
00074
00075 NVSG_API virtual const Material * clone( void ) const;
00076
00078
00079 NVSG_API virtual bool isDataShared( void ) const;
00080
00082
00083 NVSG_API virtual DataID getDataID( void ) const;
00084
00086
00091 NVSG_API const nvmath::Vec3f& getAmbientColor( void ) const;
00092
00094
00102 NVSG_API const nvmath::Vec3f& getDiffuseColor( void ) const;
00103
00105
00113 NVSG_API const nvmath::Vec3f& getEmissiveColor( void ) const;
00114
00116
00121 NVSG_API float getOpacity( void ) const;
00122
00124
00130 NVSG_API const nvmath::Vec3f& getSpecularColor( void ) const;
00131
00133
00139 NVSG_API float getSpecularExponent( void ) const;
00140
00142
00146 NVSG_API void setAmbientColor( const nvmath::Vec3f &ac );
00147
00149
00156 NVSG_API void setDiffuseColor( const nvmath::Vec3f &dc );
00157
00159
00166 NVSG_API void setEmissiveColor( const nvmath::Vec3f &ec );
00167
00169
00174 NVSG_API void setOpacity( const float o );
00175
00177
00183 NVSG_API void setSpecularColor( const nvmath::Vec3f &sc );
00184
00186
00192 NVSG_API void setSpecularExponent( const float se );
00193
00195
00196 NVSG_API virtual bool containsTransparentMaterial( void ) const;
00197
00198 protected:
00200 NVSG_API Material( void );
00201
00203 NVSG_API Material( const StateAttribute &rhs );
00204
00206 NVSG_API Material( const Material &rhs );
00207
00209 NVSG_API virtual ~Material();
00210
00211 private:
00212 nvutil::RCPtr<MaterialData> m_material;
00213 };
00214
00215 inline const nvmath::Vec3f& Material::getAmbientColor( void ) const
00216 {
00217 __TRACE();
00218 return( m_material->m_ambientColor );
00219 }
00220
00221 inline const nvmath::Vec3f& Material::getDiffuseColor( void ) const
00222 {
00223 __TRACE();
00224 return( m_material->m_diffuseColor );
00225 }
00226
00227 inline const nvmath::Vec3f& Material::getEmissiveColor( void ) const
00228 {
00229 __TRACE();
00230 return( m_material->m_emissiveColor );
00231 }
00232
00233 inline float Material::getOpacity( void ) const
00234 {
00235 __TRACE();
00236 return( m_material->m_opacity );
00237 }
00238
00239 inline const nvmath::Vec3f& Material::getSpecularColor( void ) const
00240 {
00241 __TRACE();
00242 return( m_material->m_specularColor );
00243 }
00244
00245 inline float Material::getSpecularExponent( void ) const
00246 {
00247 __TRACE();
00248 return( m_material->m_specularExponent );
00249 }
00250
00251 inline void Material::setAmbientColor( const nvmath::Vec3f &ac )
00252 {
00253 __TRACE();
00254 nvutil::writeAccess( m_material );
00255 m_material->m_ambientColor = ac;
00256 }
00257
00258 inline void Material::setDiffuseColor( const nvmath::Vec3f &dc )
00259 {
00260 __TRACE();
00261 nvutil::writeAccess( m_material );
00262 m_material->m_diffuseColor = dc;
00263 }
00264
00265 inline void Material::setEmissiveColor( const nvmath::Vec3f &ec )
00266 {
00267 __TRACE();
00268 nvutil::writeAccess( m_material );
00269 m_material->m_emissiveColor = ec;
00270 }
00271
00272 inline void Material::setOpacity( const float o )
00273 {
00274 __TRACE();
00275 __ASSERT( ( 0.0f <= o ) && ( o <= 1.0f ) );
00276 nvutil::writeAccess( m_material );
00277 if ( ( ( m_material->m_opacity == 1.0f ) && ( o < 1.0f ) )
00278 || ( ( m_material->m_opacity < 1.0f ) && ( o == 1.0f ) ) )
00279 {
00280 invalidateTransparentMaterialContainment();
00281 }
00282 m_material->m_opacity = o;
00283 }
00284
00285 inline void Material::setSpecularColor( const nvmath::Vec3f &sc )
00286 {
00287 __TRACE();
00288 nvutil::writeAccess( m_material );
00289 m_material->m_specularColor = sc;
00290 }
00291
00292 inline void Material::setSpecularExponent( const float se )
00293 {
00294 __TRACE();
00295 nvutil::writeAccess( m_material );
00296 m_material->m_specularExponent = se;
00297 }
00298
00299 }
00300