Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Material.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
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 //  ignore private member class on documentation
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       // instantiation on stack is not permitted
00039       MaterialData();
00040       ~MaterialData();
00041       // assignment also not permitted
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; // shareable material data
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 );   //  nvutil::writeAccess performs a deep copy if necessary
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 );   //  nvutil::writeAccess performs a deep copy if necessary
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 );   //  nvutil::writeAccess performs a deep copy if necessary
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 );   //  nvutil::writeAccess performs a deep copy if necessary
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 );   //  nvutil::writeAccess performs a deep copy if necessary
00289     m_material->m_specularColor = sc;
00290   }
00291 
00292   inline void Material::setSpecularExponent( const float se )
00293   {
00294     __TRACE();
00295     nvutil::writeAccess( m_material );   //  nvutil::writeAccess performs a deep copy if neccessary
00296     m_material->m_specularExponent = se;
00297   }
00298 
00299 } //  namespace nvsg
00300 

Generated on Tue Mar 1 13:19:20 2005 for NVSGSDK by NVIDIA