00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <OSGGL.h>
00049
00050 #include <OSGAction.h>
00051 #include <OSGDrawAction.h>
00052 #include <OSGGeometry.h>
00053
00054 #include <OSGStateChunk.h>
00055 #include <OSGState.h>
00056 #include <OSGMaterialChunk.h>
00057
00058 #include "OSGSimpleMaterial.h"
00059
00060 OSG_USING_NAMESPACE
00061
00062
00063
00064
00065
00066
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void SimpleMaterial::prepareLocalChunks(void)
00096 {
00097 if(_materialChunk == NullFC)
00098 {
00099 _materialChunk = MaterialChunk::create();
00100
00101 addRefCP(_materialChunk);
00102 }
00103
00104 if(_blendChunk == NullFC)
00105 {
00106 _blendChunk = BlendChunk ::create();
00107
00108 beginEditCP(_blendChunk);
00109 {
00110 _blendChunk->setSrcFactor (GL_SRC_ALPHA);
00111 _blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
00112 }
00113 endEditCP (_blendChunk);
00114
00115 addRefCP (_blendChunk);
00116 }
00117 }
00118
00119
00120
00121
00122
00123 void SimpleMaterial::initMethod (void)
00124 {
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 SimpleMaterial::SimpleMaterial(void) :
00138 Inherited(),
00139 _materialChunk(NullFC),
00140 _blendChunk (NullFC)
00141 {
00142 }
00143
00144 SimpleMaterial::SimpleMaterial(const SimpleMaterial &source) :
00145 Inherited (source ),
00146 _materialChunk(source._materialChunk),
00147 _blendChunk (source._blendChunk )
00148 {
00149 }
00150
00151 SimpleMaterial::~SimpleMaterial(void)
00152 {
00153 subRefCP(_materialChunk);
00154 subRefCP(_blendChunk );
00155 }
00156
00157 void SimpleMaterial::changed(BitVector whichField, UInt32 origin)
00158 {
00159 Inherited::changed(whichField, origin);
00160 }
00161
00162
00163
00164 StatePtr SimpleMaterial::makeState(void)
00165 {
00166 StatePtr state = State::create();
00167
00168 Color3f v3;
00169 Color4f v4;
00170 float alpha = 1.f - getTransparency();
00171
00172 prepareLocalChunks();
00173
00174 beginEditCP(_materialChunk);
00175 {
00176 v3 = getAmbient();
00177 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00178 _materialChunk->setAmbient(v4);
00179
00180 v3 = getDiffuse();
00181 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00182 _materialChunk->setDiffuse(v4);
00183
00184 v3 = getSpecular();
00185 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00186 _materialChunk->setSpecular(v4);
00187
00188 _materialChunk->setShininess(getShininess());
00189
00190 v3 = getEmission();
00191 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00192 _materialChunk->setEmission(v4);
00193
00194 _materialChunk->setLit(getLit());
00195 _materialChunk->setColorMaterial(getColorMaterial());
00196 }
00197 endEditCP (_materialChunk);
00198
00199 state->addChunk(_materialChunk);
00200
00201 if(isTransparent())
00202 {
00203 state->addChunk(_blendChunk);
00204 }
00205
00206 for(MFStateChunkPtr::iterator i = _mfChunks.begin();
00207 i != _mfChunks.end();
00208 ++i)
00209 {
00210 state->addChunk(*i);
00211 }
00212
00213 return state;
00214 }
00215
00216 void SimpleMaterial::rebuildState(void)
00217 {
00218 Color3f v3;
00219 Color4f v4;
00220 Real32 alpha = 1.f - getTransparency();
00221
00222 if(_pState != NullFC)
00223 {
00224 _pState->clearChunks();
00225 }
00226 else
00227 {
00228 _pState = State::create();
00229
00230 addRefCP(_pState);
00231 }
00232
00233 prepareLocalChunks();
00234
00235 beginEditCP(_materialChunk);
00236 {
00237 v3 = getAmbient();
00238 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00239
00240 _materialChunk->setAmbient(v4);
00241
00242 v3 = getDiffuse();
00243 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00244
00245 _materialChunk->setDiffuse(v4);
00246
00247 v3 = getSpecular();
00248 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00249
00250 _materialChunk->setSpecular(v4);
00251
00252 _materialChunk->setShininess(getShininess());
00253
00254 v3 = getEmission();
00255 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00256
00257 _materialChunk->setEmission(v4);
00258
00259 _materialChunk->setLit(getLit());
00260 _materialChunk->setColorMaterial(getColorMaterial());
00261 }
00262 endEditCP (_materialChunk);
00263
00264 _pState->addChunk(_materialChunk);
00265
00266 if(isTransparent())
00267 {
00268 _pState->addChunk(_blendChunk);
00269 }
00270
00271 MFStateChunkPtr::iterator it = _mfChunks.begin();
00272 MFStateChunkPtr::iterator chunksEnd = _mfChunks.end();
00273
00274 for(; it != chunksEnd; ++it)
00275 {
00276 _pState->addChunk(*it);
00277 }
00278 }
00279
00280 bool SimpleMaterial::isTransparent(void) const
00281 {
00282 return ((getTransparency() > Eps) || (Inherited::isTransparent()));
00283 }
00284
00285
00286
00287 void SimpleMaterial::dump( UInt32 uiIndent,
00288 const BitVector OSG_CHECK_ARG(bvFlags )) const
00289 {
00290
00291 SimpleMaterialPtr thisP(*this);
00292
00293 thisP.dump(uiIndent, FCDumpFlags::RefCount);
00294
00295 indentLog(uiIndent, PLOG);
00296 PLOG << "SimpleMaterial at " << this << std::endl;
00297
00298 indentLog(uiIndent, PLOG);
00299 PLOG << "\tambient: " << getAmbient() << std::endl;
00300
00301 indentLog(uiIndent, PLOG);
00302 PLOG << "\tdiffuse: " << getDiffuse() << std::endl;
00303
00304 indentLog(uiIndent, PLOG);
00305 PLOG << "\tspecular: " << getSpecular() << std::endl;
00306
00307 indentLog(uiIndent, PLOG);
00308 PLOG << "\tshininess: " << getShininess() << std::endl;
00309
00310 indentLog(uiIndent, PLOG);
00311 PLOG << "\temission: " << getEmission() << std::endl;
00312
00313 indentLog(uiIndent, PLOG);
00314 PLOG << "\ttransparency: " << getTransparency() << std::endl;
00315
00316 indentLog(uiIndent, PLOG);
00317 PLOG << "\tlit: " << getLit() << std::endl;
00318
00319 indentLog(uiIndent, PLOG);
00320 PLOG << "\tChunks: " << std::endl;
00321
00322 for(MFStateChunkPtr::const_iterator i = _mfChunks.begin();
00323 i != _mfChunks.end(); i++)
00324 {
00325 indentLog(uiIndent, PLOG);
00326 PLOG << "\t" << *i << std::endl;
00327 }
00328
00329 indentLog(uiIndent, PLOG);
00330 PLOG << "SimpleMaterial end " << this << std::endl;
00331 }
00332
00333
00334
00335
00336 #ifdef OSG_SGI_CC
00337 #pragma set woff 1174
00338 #endif
00339
00340 #ifdef OSG_LINUX_ICC
00341 #pragma warning(disable : 177)
00342 #endif
00343
00344 namespace
00345 {
00346 static Char8 cvsid_cpp [] = "@(#)$Id:$";
00347 static Char8 cvsid_hpp [] = OSGSIMPLEMATERIAL_HEADER_CVSID;
00348 static Char8 cvsid_inl [] = OSGSIMPLEMATERIAL_INLINE_CVSID;
00349
00350 static Char8 cvsid_fields_hpp[] = OSGSIMPLEMATERIALFIELDS_HEADER_CVSID;
00351 }
00352
00353 #ifdef __sgi
00354 #pragma reset woff 1174
00355 #endif
00356