#include <OSGMaterialChunk.h>
Inheritance diagram for osg::MaterialChunk:

This chunk wraps glMaterial() (osg::MaterialChunk::_sfDiffuse, osg::MaterialChunk::_sfSpecular, osg::MaterialChunk::_sfEmission, osg::MaterialChunk::_sfShininess, osg::MaterialChunk::_sfAmbient), glEnable(GL_LIGHTING)(osg::MaterialChunk::_sfLit) and glColorMaterial() (osg::MaterialChunk::_sfColorMaterial).
Definition at line 55 of file OSGMaterialChunk.h.
|
|
Reimplemented from osg::MaterialChunkBase. Definition at line 140 of file OSGMaterialChunk.h. |
|
|
Reimplemented from osg::StateChunkBase. Definition at line 103 of file OSGMaterialChunkBase.h. |
|
|
Reimplemented from osg::Attachment. Definition at line 105 of file OSGMaterialChunkBase.h. 00106 { 00107 DiffuseFieldId = Inherited::NextFieldId, 00108 AmbientFieldId = DiffuseFieldId + 1, 00109 SpecularFieldId = AmbientFieldId + 1, 00110 EmissionFieldId = SpecularFieldId + 1, 00111 ShininessFieldId = EmissionFieldId + 1, 00112 LitFieldId = ShininessFieldId + 1, 00113 ColorMaterialFieldId = LitFieldId + 1, 00114 BackMaterialFieldId = ColorMaterialFieldId + 1, 00115 BackDiffuseFieldId = BackMaterialFieldId + 1, 00116 BackAmbientFieldId = BackDiffuseFieldId + 1, 00117 BackSpecularFieldId = BackAmbientFieldId + 1, 00118 BackEmissionFieldId = BackSpecularFieldId + 1, 00119 BackShininessFieldId = BackEmissionFieldId + 1, 00120 BackColorMaterialFieldId = BackShininessFieldId + 1, 00121 NextFieldId = BackColorMaterialFieldId + 1 00122 };
|
|
|
Definition at line 94 of file OSGMaterialChunk.cpp. 00094 : 00095 Inherited() 00096 { 00097 }
|
|
|
Definition at line 99 of file OSGMaterialChunk.cpp. 00099 : 00100 Inherited(source) 00101 { 00102 }
|
|
|
Definition at line 104 of file OSGMaterialChunk.cpp.
|
|
|
Reimplemented from osg::StateChunk. Definition at line 110 of file OSGMaterialChunk.cpp. References _class. 00111 { 00112 return &_class; 00113 }
|
|
|
Reimplemented from osg::StateChunk. Definition at line 46 of file OSGMaterialChunk.inl. References osg::StateChunkClass::getId(), and getStaticClass(). Referenced by osg::VRMLWriteAction::writeMaterial(). 00047 { 00048 return getStaticClass()->getId(); 00049 }
|
|
|
Reimplemented from osg::StateChunk. Definition at line 52 of file OSGMaterialChunk.inl. References _class. Referenced by getStaticClassId(). 00053 { 00054 return &MaterialChunk::_class; 00055 }
|
|
||||||||||||
|
Reimplemented from osg::StateChunk. Definition at line 117 of file OSGMaterialChunk.cpp. References osg::StateChunk::changed(). 00118 { 00119 Inherited::changed(whichField, origin); 00120 }
|
|
||||||||||||
|
Reimplemented from osg::StateChunk. Definition at line 124 of file OSGMaterialChunk.cpp. References SLOG. 00126 { 00127 SLOG << "Dump MaterialChunk NI" << std::endl; 00128 }
|
|
||||||||||||
|
Activate the chunk, i.e. set the OpenGl state covered by the chunk which is different from the default state to the given state. Reimplemented from osg::StateChunk. Definition at line 132 of file OSGMaterialChunk.cpp. References osg::MaterialChunkBase::_sfAmbient, osg::MaterialChunkBase::_sfBackAmbient, osg::MaterialChunkBase::_sfBackDiffuse, osg::MaterialChunkBase::_sfBackEmission, osg::MaterialChunkBase::_sfBackShininess, osg::MaterialChunkBase::_sfBackSpecular, osg::MaterialChunkBase::_sfDiffuse, osg::MaterialChunkBase::_sfEmission, osg::MaterialChunkBase::_sfShininess, osg::MaterialChunkBase::_sfSpecular, osg::MaterialChunkBase::getBackColorMaterial(), osg::MaterialChunkBase::getBackMaterial(), osg::MaterialChunkBase::getColorMaterial(), osg::MaterialChunkBase::getLit(), osg::SField< FieldTypeT, fieldNameSpace >::getValue(), GLenum, and glErr. 00133 { 00134 glErr("material:activate:precheck"); 00135 00136 GLenum target; 00137 00138 if(getBackMaterial()) 00139 { 00140 target = GL_FRONT; 00141 } 00142 else 00143 { 00144 target = GL_FRONT_AND_BACK; 00145 } 00146 00147 if(getColorMaterial() == GL_NONE) 00148 { 00149 glDisable(GL_COLOR_MATERIAL); 00150 } 00151 else 00152 { 00153 glColorMaterial(target, getColorMaterial()); 00154 if(getBackMaterial()) 00155 { 00156 glColorMaterial(GL_BACK, getBackColorMaterial()); 00157 } 00158 glEnable(GL_COLOR_MATERIAL); 00159 } 00160 00161 glColor4fv(_sfDiffuse.getValue().getValuesRGBA()); 00162 00163 if(getLit()) 00164 { 00165 glMaterialfv(target, GL_DIFFUSE, 00166 _sfDiffuse.getValue().getValuesRGBA()); 00167 glMaterialfv(target, GL_AMBIENT, 00168 _sfAmbient.getValue().getValuesRGBA()); 00169 glMaterialfv(target, GL_SPECULAR, 00170 _sfSpecular.getValue().getValuesRGBA()); 00171 glMaterialfv(target, GL_EMISSION, 00172 _sfEmission.getValue().getValuesRGBA()); 00173 glMaterialf (target, GL_SHININESS, _sfShininess.getValue()); 00174 00175 if(getBackMaterial()) 00176 { 00177 glMaterialfv(GL_BACK, GL_DIFFUSE, 00178 _sfBackDiffuse.getValue().getValuesRGBA()); 00179 glMaterialfv(GL_BACK, GL_AMBIENT, 00180 _sfBackAmbient.getValue().getValuesRGBA()); 00181 glMaterialfv(GL_BACK, GL_SPECULAR, 00182 _sfBackSpecular.getValue().getValuesRGBA()); 00183 glMaterialfv(GL_BACK, GL_EMISSION, 00184 _sfBackEmission.getValue().getValuesRGBA()); 00185 glMaterialf (GL_BACK, GL_SHININESS, _sfBackShininess.getValue()); 00186 } 00187 00188 glEnable(GL_LIGHTING); 00189 } 00190 else 00191 { 00192 glDisable(GL_LIGHTING); 00193 } 00194 00195 glErr("material:activate:postcheck"); 00196 }
|
|
||||||||||||||||
|
Change from an old chunk of the same type to this chunk. Note that in general no type checking is done, make sure to use this on a legal combination of chunks! Reimplemented from osg::StateChunk. Definition at line 198 of file OSGMaterialChunk.cpp. References osg::MaterialChunkBase::_sfAmbient, osg::MaterialChunkBase::_sfBackAmbient, osg::MaterialChunkBase::_sfBackDiffuse, osg::MaterialChunkBase::_sfBackEmission, osg::MaterialChunkBase::_sfBackShininess, osg::MaterialChunkBase::_sfBackSpecular, osg::MaterialChunkBase::_sfDiffuse, osg::MaterialChunkBase::_sfEmission, osg::MaterialChunkBase::_sfShininess, osg::MaterialChunkBase::_sfSpecular, osg::MaterialChunkBase::getBackColorMaterial(), osg::MaterialChunkBase::getBackMaterial(), osg::MaterialChunkBase::getBackShininess(), osg::MaterialChunkBase::getColorMaterial(), osg::MaterialChunkBase::getLit(), osg::MaterialChunkBase::getShininess(), osg::SField< FieldTypeT, fieldNameSpace >::getValue(), GLenum, glErr, and osg::osgabs(). 00199 { 00200 glErr("material:changed:precheck"); 00201 00202 MaterialChunk const *old = dynamic_cast<MaterialChunk const*>(old_chunk); 00203 00204 // change from me to me? 00205 // this assumes I haven't changed in the meantime. is that a valid assumption? 00206 if(old == this) 00207 { 00208 // Reset it, as Geometry colors might have changed it 00209 if(getColorMaterial() != GL_NONE || 00210 (getBackMaterial() && getBackColorMaterial() != GL_NONE) 00211 ) 00212 glColor4fv(_sfDiffuse.getValue().getValuesRGBA()); 00213 00214 return; 00215 } 00216 00217 if(getColorMaterial() == GL_NONE && 00218 ((getBackColorMaterial() == GL_NONE) || ! getBackMaterial()) && 00219 (old->getColorMaterial() != GL_NONE || 00220 old->getBackColorMaterial() != GL_NONE 00221 ) 00222 ) 00223 { 00224 glDisable(GL_COLOR_MATERIAL); 00225 } 00226 else if(getColorMaterial() != old->getColorMaterial() || 00227 getBackColorMaterial() != old->getBackColorMaterial() 00228 ) 00229 { 00230 if(getBackMaterial()) 00231 { 00232 glColorMaterial(GL_FRONT, getColorMaterial()); 00233 glColorMaterial(GL_BACK, getBackColorMaterial()); 00234 } 00235 else 00236 { 00237 glColorMaterial(GL_FRONT_AND_BACK, getColorMaterial()); 00238 00239 } 00240 glEnable(GL_COLOR_MATERIAL); 00241 } 00242 00243 if(getColorMaterial() != GL_NONE || getBackColorMaterial() != GL_NONE) 00244 glColor4fv(_sfDiffuse.getValue().getValuesRGBA()); 00245 00246 if(getLit() && ! old->getLit()) 00247 glEnable(GL_LIGHTING); 00248 else if(! getLit() && old->getLit()) 00249 glDisable(GL_LIGHTING); 00250 00251 if(getLit()) 00252 { 00253 GLenum target; 00254 00255 if(getBackMaterial()) 00256 { 00257 target = GL_FRONT; 00258 } 00259 else 00260 { 00261 target = GL_FRONT_AND_BACK; 00262 } 00263 00264 glMaterialfv(target, GL_DIFFUSE, 00265 _sfDiffuse.getValue().getValuesRGBA()); 00266 glMaterialfv(target, GL_AMBIENT, 00267 _sfAmbient.getValue().getValuesRGBA()); 00268 glMaterialfv(target, GL_SPECULAR, 00269 _sfSpecular.getValue().getValuesRGBA()); 00270 glMaterialfv(target, GL_EMISSION, 00271 _sfEmission.getValue().getValuesRGBA()); 00272 // adjust shininess only if it differs enough 00273 if(osgabs(_sfShininess.getValue() - old->getShininess()) > 1e-4) 00274 glMaterialf( target, GL_SHININESS, _sfShininess.getValue()); 00275 00276 if(getBackMaterial()) 00277 { 00278 glMaterialfv(GL_BACK, GL_DIFFUSE, 00279 _sfBackDiffuse.getValue().getValuesRGBA()); 00280 glMaterialfv(GL_BACK, GL_AMBIENT, 00281 _sfBackAmbient.getValue().getValuesRGBA()); 00282 glMaterialfv(GL_BACK, GL_SPECULAR, 00283 _sfBackSpecular.getValue().getValuesRGBA()); 00284 glMaterialfv(GL_BACK, GL_EMISSION, 00285 _sfBackEmission.getValue().getValuesRGBA()); 00286 // adjust shininess only if it differs enough 00287 if(osgabs(_sfBackShininess.getValue() - 00288 old->getBackShininess() 00289 ) > 1e-4) 00290 glMaterialf( GL_BACK, GL_SHININESS, _sfBackShininess.getValue()); 00291 } 00292 } 00293 00294 glErr("material:changed:precheck"); 00295 }
|
|
||||||||||||
|
Deactivate the chunk, i.e. set the OpenGl state covered by the chunk which is different from the default state to the default state. Reimplemented from osg::StateChunk. Definition at line 297 of file OSGMaterialChunk.cpp. References osg::MaterialChunkBase::getColorMaterial(), and osg::MaterialChunkBase::getLit(). 00298 { 00299 if(getLit()) 00300 glDisable(GL_LIGHTING); 00301 00302 if(getColorMaterial() != GL_NONE) 00303 glDisable(GL_COLOR_MATERIAL); 00304 }
|
|
|
Check if the chunk is transparent, i.e. needs to be rendered after the opaque objects. Reimplemented from osg::StateChunk. Definition at line 314 of file OSGMaterialChunk.cpp. References osg::Eps, and osg::MaterialChunkBase::getDiffuse(). 00315 { 00316 return(getDiffuse()[3] <(1. - Eps)); 00317 }
|
|
|
Calculate how expensive it is to switch from one instance of the chunk class to another. In most cases not implemented yet, will return 0. Reimplemented from osg::StateChunk. Definition at line 309 of file OSGMaterialChunk.cpp.
|
|
|
Calculate how expensive it is to switch from one instance of the chunk class to another. In most cases not implemented yet, will return 0. Reimplemented from osg::StateChunk. Definition at line 320 of file OSGMaterialChunk.cpp.
|
|
|
Compare two chunks. In most cases not implemented yet, will return false. Reimplemented from osg::StateChunk. Definition at line 325 of file OSGMaterialChunk.cpp. References osg::Eps, osg::Color4< ValueTypeT >::equals(), osg::MaterialChunkBase::getAmbient(), osg::MaterialChunkBase::getColorMaterial(), osg::MaterialChunkBase::getDiffuse(), osg::MaterialChunkBase::getEmission(), osg::MaterialChunkBase::getLit(), osg::MaterialChunkBase::getShininess(), and osg::MaterialChunkBase::getSpecular(). 00326 { 00327 MaterialChunk const *tother = dynamic_cast<MaterialChunk const*>(&other); 00328 00329 if(!tother) 00330 return false; 00331 00332 if(tother == this) 00333 return true; 00334 00335 if(!getAmbient ().equals(tother->getAmbient (), Eps) || 00336 !getDiffuse ().equals(tother->getDiffuse (), Eps) || 00337 !getSpecular ().equals(tother->getSpecular (), Eps) || 00338 !getEmission ().equals(tother->getEmission (), Eps) || 00339 getShininess() != tother->getShininess() || 00340 getLit() != tother->getLit() || 00341 getColorMaterial() != tother->getColorMaterial() 00342 ) 00343 return false; 00344 00345 return true; 00346 }
|
|
|
Calculate how expensive it is to switch from one instance of the chunk class to another. In most cases not implemented yet, will return 0. Reimplemented from osg:: |