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 <OSGAttachmentContainerPtr.h>
00051 #include <OSGState.h>
00052 #include <OSGDrawActionBase.h>
00053 #include <OSGGeometry.h>
00054
00055 #include "OSGChunkMaterial.h"
00056
00057 OSG_USING_NAMESPACE
00058
00059
00060
00061
00062
00063
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 void ChunkMaterial::initMethod(void)
00090 {
00091 }
00092
00093
00094
00095
00096
00097
00098
00099 ChunkMaterial::ChunkMaterial(void) :
00100 Inherited()
00101 {
00102 }
00103
00104 ChunkMaterial::ChunkMaterial(const ChunkMaterial &source) :
00105 Inherited(source)
00106 {
00107 }
00108
00109 ChunkMaterial::~ChunkMaterial(void)
00110 {
00111 clearChunks();
00112 }
00113
00114 void ChunkMaterial::changed(BitVector whichField, UInt32 origin)
00115 {
00116 if(origin & ChangedOrigin::Abstract)
00117 {
00118 MFStateChunkPtr::iterator matIt = _mfChunks.begin();
00119 MFStateChunkPtr::iterator matEnd = _mfChunks.end ();
00120
00121 while(matIt != matEnd)
00122 {
00123 addRefCP(*matIt);
00124
00125 ++matIt;
00126 }
00127 }
00128
00129 Inherited::changed(whichField, origin);
00130 }
00131
00132
00133
00134
00140 bool ChunkMaterial::addChunk(StateChunkPtr chunk, Int32 slot)
00141 {
00142 if(slot != State::AutoSlotReplace)
00143 {
00144 while(_mfSlots.size() < _mfChunks.size())
00145 _mfSlots.push_back(State::AutoSlotReplace);
00146 }
00147
00148 _mfChunks.push_back(chunk);
00149
00150 if(slot != State::AutoSlotReplace)
00151 _mfSlots.push_back(slot);
00152
00153 addRefCP(chunk);
00154
00155 return true;
00156 }
00157
00162 bool ChunkMaterial::subChunk(StateChunkPtr chunk, Int32 slot)
00163 {
00164 UInt32 i;
00165
00166 for(i = 0; i < _mfChunks.size(); ++i)
00167 {
00168 if(_mfChunks[i] == chunk &&
00169 ((i < _mfSlots.size() && _mfSlots[i] == slot) ||
00170 slot == State::AutoSlotReplace))
00171 {
00172 subRefCP(chunk);
00173 _mfChunks.erase(_mfChunks.begin() + i);
00174 if(i < _mfSlots.size())
00175 _mfSlots.erase(_mfSlots.begin() + i);
00176 return false;
00177 }
00178 }
00179
00180 SWARNING << "ChunkMaterial::subChunk(" << this << ") has no chunk "
00181 << chunk << " with slot " << slot << std::endl;
00182
00183 return true;
00184 }
00185
00190 Int32 ChunkMaterial::find(StateChunkPtr chunk)
00191 {
00192 UInt32 i;
00193
00194 for(i = 0; i < _mfChunks.size(); ++i)
00195 {
00196 if(_mfChunks[i] == chunk)
00197 return i;
00198 }
00199
00200 return -1;
00201 }
00202
00210 StateChunkPtr ChunkMaterial::find(const FieldContainerType &type,
00211 Int32 slot)
00212 {
00213 UInt32 index = 0;
00214 for(UInt32 i = 0; i < _mfChunks.size(); ++i)
00215 {
00216 StateChunkPtr p = _mfChunks[i];
00217 Int32 s = State::AutoSlotReplace;
00218
00219 if(i < getSlots().size())
00220 s = getSlots(i);
00221
00222 if(s == State::AutoSlotReplace)
00223 s = index;
00224
00225 if(p->getType() == type)
00226 {
00227 if(slot == State::AutoSlotReplace || slot == s)
00228 return (p);
00229 ++index;
00230 }
00231 }
00232 return NullFC;
00233 }
00234
00235 void ChunkMaterial::clearChunks(void)
00236 {
00237 MFStateChunkPtr::iterator matIt = _mfChunks.begin();
00238 MFStateChunkPtr::iterator matEnd = _mfChunks.end ();
00239
00240 while(matIt != matEnd)
00241 {
00242 subRefCP(*matIt);
00243 ++matIt;
00244 }
00245 _mfChunks.clear();
00246 }
00247
00248 bool ChunkMaterial::operator==(const Material& other)
00249 {
00250 Material& thisBase = *this;
00251 if (!(thisBase == other))
00252 return false;
00253
00254 const ChunkMaterial* othercm = dynamic_cast<const ChunkMaterial*>(&other);
00255 if (!othercm)
00256 return false;
00257
00258
00259 return false;
00260 }
00261
00265 void ChunkMaterial::draw(Geometry* geo, DrawActionBase * action)
00266 {
00267 StatePtr state = makeState();
00268
00269 addRefCP(state);
00270
00271 state->activate(action);
00272
00273 geo->drawPrimitives(action);
00274
00275 state->deactivate(action);
00276
00277 subRefCP(state);
00278 }
00279
00285 void ChunkMaterial::draw(DrawFunctor& func, DrawActionBase * action)
00286 {
00287 StatePtr state = makeState();
00288
00289 addRefCP(state);
00290
00291 state->activate(action);
00292
00293 func.call(action);
00294
00295 state->deactivate(action);
00296
00297 subRefCP(state);
00298 }
00299
00304 void ChunkMaterial::addChunks(StatePtr state)
00305 {
00306 UInt32 i;
00307
00308 for(i = 0; i < _mfChunks.size(); ++i)
00309 state->addChunk(_mfChunks[i],
00310 (i < _mfSlots.size()) ? _mfSlots[i]
00311 : State::AutoSlotReplace);
00312 }
00313
00317 StatePtr ChunkMaterial::makeState(void)
00318 {
00319 StatePtr state = State::create();
00320
00321 addChunks(state);
00322
00323 return state;
00324 }
00325
00329 void ChunkMaterial::rebuildState(void)
00330 {
00331 if(_pState != NullFC)
00332 {
00333 _pState->clearChunks();
00334 }
00335 else
00336 {
00337 _pState = State::create();
00338
00339 addRefCP(_pState);
00340 }
00341
00342 addChunks(_pState);
00343 }
00344
00348 bool ChunkMaterial::isTransparent(void) const
00349 {
00350 Int32 tm = getTransparencyMode();
00351 if(tm != Material::TransparencyAutoDetection)
00352 {
00353 return (tm == Material::TransparencyForceTransparent);
00354 }
00355
00356 bool returnValue = false;
00357
00358 MFStateChunkPtr::const_iterator it = _mfChunks.begin();
00359 MFStateChunkPtr::const_iterator chunksEnd = _mfChunks.end();
00360
00361 for(; it != chunksEnd && returnValue == false; ++it)
00362 {
00363 returnValue =(*it)->isTransparent();
00364 }
00365
00366 return returnValue;
00367 }
00368
00369
00370
00371 void ChunkMaterial::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00372 const BitVector OSG_CHECK_ARG(bvFlags )) const
00373 {
00374 SLOG << "ChunkMaterial at " << this << std::endl;
00375 SLOG << "Chunks: " << std::endl;
00376
00377 UInt32 i;
00378
00379 for(i = 0; i < _mfChunks.size(); ++i)
00380 SLOG << _mfChunks[i] << " "
00381 << static_cast<Int32>((i < _mfSlots.size())
00382 ? _mfSlots[i]
00383 : State::AutoSlotReplace)
00384 << std::endl;
00385 }
00386
00387
00388
00389
00390
00391 #ifdef OSG_SGI_CC
00392 #pragma set woff 1174
00393 #endif
00394
00395 #ifdef OSG_LINUX_ICC
00396 #pragma warning(disable : 177)
00397 #endif
00398
00399 namespace
00400 {
00401 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00402 static Char8 cvsid_hpp [] = OSGCHUNKMATERIAL_HEADER_CVSID;
00403 static Char8 cvsid_inl [] = OSGCHUNKMATERIAL_INLINE_CVSID;
00404
00405 static Char8 cvsid_fields_hpp[] = OSGCHUNKMATERIALFIELDS_HEADER_CVSID;
00406 }
00407
00408 #ifdef __sgi
00409 #pragma reset woff 1174
00410 #endif
00411
00412