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 addChunks(state);
00207
00208 return state;
00209 }
00210
00211 void SimpleMaterial::rebuildState(void)
00212 {
00213 Color3f v3;
00214 Color4f v4;
00215 Real32 alpha = 1.f - getTransparency();
00216
00217 if(_pState != NullFC)
00218 {
00219 _pState->clearChunks();
00220 }
00221 else
00222 {
00223 _pState = State::create();
00224
00225 addRefCP(_pState);
00226 }
00227
00228 prepareLocalChunks();
00229
00230 beginEditCP(_materialChunk);
00231 {
00232 v3 = getAmbient();
00233 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00234
00235 _materialChunk->setAmbient(v4);
00236
00237 v3 = getDiffuse();
00238 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00239
00240 _materialChunk->setDiffuse(v4);
00241
00242 v3 = getSpecular();
00243 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00244
00245 _materialChunk->setSpecular(v4);
00246
00247 _materialChunk->setShininess(getShininess());
00248
00249 v3 = getEmission();
00250 v4.setValuesRGBA(v3[0], v3[1], v3[2], alpha);
00251
00252 _materialChunk->setEmission(v4);
00253
00254 _materialChunk->setLit(getLit());
00255 _materialChunk->setColorMaterial(getColorMaterial());
00256 }
00257 endEditCP (_materialChunk);
00258
00259 _pState->addChunk(_materialChunk);
00260
00261 if(isTransparent())
00262 {
00263 _pState->addChunk(_blendChunk);
00264 }
00265
00266 addChunks(_pState);
00267 }
00268
00269 bool SimpleMaterial::isTransparent(void) const
00270 {
00271 return ((getTransparency() > Eps) || (Inherited::isTransparent()));
00272 }
00273
00274
00275
00276 void SimpleMaterial::dump( UInt32 uiIndent,
00277 const BitVector OSG_CHECK_ARG(bvFlags )) const
00278 {
00279
00280 SimpleMaterialPtr thisP(*this);
00281
00282 thisP.dump(uiIndent, FCDumpFlags::RefCount);
00283
00284 indentLog(uiIndent, PLOG);
00285 PLOG << "SimpleMaterial at " << this << std::endl;
00286
00287 indentLog(uiIndent, PLOG);
00288 PLOG << "\tambient: " << getAmbient() << std::endl;
00289
00290 indentLog(uiIndent, PLOG);
00291 PLOG << "\tdiffuse: " << getDiffuse() << std::endl;
00292
00293 indentLog(uiIndent, PLOG);
00294 PLOG << "\tspecular: " << getSpecular() << std::endl;
00295
00296 indentLog(uiIndent, PLOG);
00297 PLOG << "\tshininess: " << getShininess() << std::endl;
00298
00299 indentLog(uiIndent, PLOG);
00300 PLOG << "\temission: " << getEmission() << std::endl;
00301
00302 indentLog(uiIndent, PLOG);
00303 PLOG << "\ttransparency: " << getTransparency() << std::endl;
00304
00305 indentLog(uiIndent, PLOG);
00306 PLOG << "\tlit: " << getLit() << std::endl;
00307
00308 indentLog(uiIndent, PLOG);
00309 PLOG << "\tChunks: " << std::endl;
00310
00311 for(MFStateChunkPtr::const_iterator i = _mfChunks.begin();
00312 i != _mfChunks.end(); i++)
00313 {
00314 indentLog(uiIndent, PLOG);
00315 PLOG << "\t" << *i << std::endl;
00316 }
00317
00318 indentLog(uiIndent, PLOG);
00319 PLOG << "SimpleMaterial end " << this << std::endl;
00320 }
00321
00322
00323
00324
00325 #ifdef OSG_SGI_CC
00326 #pragma set woff 1174
00327 #endif
00328
00329 #ifdef OSG_LINUX_ICC
00330 #pragma warning(disable : 177)
00331 #endif
00332
00333 namespace
00334 {
00335 static Char8 cvsid_cpp [] = "@(#)$Id:$";
00336 static Char8 cvsid_hpp [] = OSGSIMPLEMATERIAL_HEADER_CVSID;
00337 static Char8 cvsid_inl [] = OSGSIMPLEMATERIAL_INLINE_CVSID;
00338
00339 static Char8 cvsid_fields_hpp[] = OSGSIMPLEMATERIALFIELDS_HEADER_CVSID;
00340 }
00341
00342 #ifdef __sgi
00343 #pragma reset woff 1174
00344 #endif
00345