changed: gcc8 base update
[opensg.git] / Source / System / State / Shader / Chunks / OSGShaderProgramVariableChunk.cpp
blobb8f4ffda457bca63ef27f45370e60e654e70c4bf
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGShaderProgramVariableChunk.h"
50 #include "OSGShaderVariables.h"
52 OSG_BEGIN_NAMESPACE
54 // Documentation for this class is emitted in the
55 // OSGShaderProgramVariableChunkBase.cpp file.
56 // To modify it, please change the .fcd file
57 // (OSGShaderProgramVariableChunk.fcd) and regenerate the base file.
59 /***************************************************************************\
60 * Class variables *
61 \***************************************************************************/
63 StateChunkClass ShaderProgramVariableChunk::_class("ShaderProgramVariable",
64 1,
65 5);
67 volatile UInt16 ShaderProgramVariableChunk::_uiChunkCounter = 1;
69 ShaderProgramVariableChunk::VarIdPool *
70 ShaderProgramVariableChunk::_pVarIdPool = NULL;
72 template<> inline
73 void SimpleReusePool<Int32,
74 ShaderProgramVariableChunk::VariableIdPoolTag,
75 SingleLockPolicy >::initializeValue(void)
77 _currentValue = 1;
80 /***************************************************************************\
81 * Class methods *
82 \***************************************************************************/
84 void ShaderProgramVariableChunk::initMethod(InitPhase ePhase)
86 Inherited::initMethod(ePhase);
88 if(ePhase == TypeObject::SystemPost)
94 /***************************************************************************\
95 * Instance methods *
96 \***************************************************************************/
98 /*-------------------------------------------------------------------------*\
99 - private -
100 \*-------------------------------------------------------------------------*/
102 /*----------------------- constructors & destructors ----------------------*/
104 ShaderProgramVariableChunk::ShaderProgramVariableChunk(void) :
105 Inherited( ),
106 _uiVarId (0),
107 _uiChunkId(0)
111 ShaderProgramVariableChunk::ShaderProgramVariableChunk(
112 const ShaderProgramVariableChunk &source) :
114 Inherited(source),
115 _uiVarId (0 ),
116 _uiChunkId(0 )
120 ShaderProgramVariableChunk::~ShaderProgramVariableChunk(void)
124 void ShaderProgramVariableChunk::onCreate(
125 const ShaderProgramVariableChunk *source)
127 Inherited::onCreate(source);
129 if(GlobalSystemState == Startup)
131 _pVarIdPool = new VarIdPool;
133 return;
136 _uiChunkId = _uiChunkCounter++;
137 _uiVarId = _pVarIdPool->create();
139 markFieldsClusterLocal(ParentsFieldMask);
142 void ShaderProgramVariableChunk::onCreateAspect(
143 const ShaderProgramVariableChunk *createAspect,
144 const ShaderProgramVariableChunk *source )
146 Inherited::onCreateAspect(createAspect, source);
148 _uiChunkId = createAspect->_uiChunkId;
149 _uiVarId = createAspect->_uiVarId;
151 markFieldsClusterLocal(ParentsFieldMask);
154 void ShaderProgramVariableChunk::onDestroy(UInt32 uiId)
156 Inherited::onDestroy(uiId);
158 if(GlobalSystemState == OSG::Running)
160 _pVarIdPool->release(_uiVarId);
162 else if(GlobalSystemState == OSG::Shutdown)
164 delete _pVarIdPool;
166 _pVarIdPool = NULL;
170 const StateChunkClass *ShaderProgramVariableChunk::getClass(void) const
172 return &_class;
175 UInt16 ShaderProgramVariableChunk::getChunkId(void)
177 return _uiChunkId;
180 /*----------------------------- class specific ----------------------------*/
182 void ShaderProgramVariableChunk::changed(ConstFieldMaskArg whichField,
183 UInt32 origin,
184 BitVector details)
186 if(0x0000 != (whichField & VariablesFieldMask))
188 ShaderProgramVariables *pVars = _sfVariables.getValue();
190 if(pVars != NULL)
192 if(details == 0x0001)
194 MFParentFieldContainerPtr::const_iterator parentsIt =
195 this->_mfParents.begin();
197 MFParentFieldContainerPtr::const_iterator parentsEnd =
198 this->_mfParents.end();
200 for(; parentsIt != parentsEnd; ++parentsIt)
202 (*parentsIt)->changed(
203 TypeTraits<BitVector>::One <<
204 parentsIt.getParentFieldPos(),
205 ChangedOrigin::Child,
206 VariablesFieldMask);
213 Inherited::changed(whichField, origin, details);
217 void ShaderProgramVariableChunk::addParent(
218 FieldContainer * const pParent,
219 UInt16 uiParentFieldId)
221 editMField(ParentsFieldMask, _mfParents);
223 OSG_ASSERT(pParent != NULL);
225 _mfParents.push_back(pParent, uiParentFieldId);
228 void ShaderProgramVariableChunk::subParent(FieldContainer * const pParent)
230 Int32 iParentIdx = _mfParents.findIndex(pParent);
232 if(iParentIdx != -1)
234 editMField(ParentsFieldMask, _mfParents);
236 _mfParents.erase(iParentIdx);
240 void ShaderProgramVariableChunk::dump( UInt32 ,
241 const BitVector ) const
243 SLOG << "Dump ShaderProgramVariableChunk NI" << std::endl;
246 bool ShaderProgramVariableChunk::subUniformVariable(const Char8 *name)
248 if(_sfVariables.getValue() != NULL)
250 return _sfVariables.getValue()->subUniformVariable(name, NULL, NULL);
252 else
254 return false;
258 bool ShaderProgramVariableChunk::subUniformBlock(const Char8 *name)
260 if(_sfVariables.getValue() != NULL)
262 return _sfVariables.getValue()->subUniformBlock(name, NULL, NULL);
264 else
266 return false;
270 bool ShaderProgramVariableChunk::subShaderStorageBlock(const Char8 *name)
272 if(_sfVariables.getValue() != NULL)
274 return _sfVariables.getValue()->subShaderStorageBlock(name, NULL, NULL);
276 else
278 return false;
282 void ShaderProgramVariableChunk::clearUniformVariables(void)
284 if(_sfVariables.getValue() == NULL)
286 _sfVariables.getValue()->clearUniformVariables();
290 void ShaderProgramVariableChunk::activate(DrawEnv *pEnv, UInt32)
292 SFATAL << "ShaderProgramVariableChunk::activate" << std::endl;
295 void ShaderProgramVariableChunk::changeFrom(DrawEnv *pEnv,
296 StateChunk *pOther,
297 UInt32 )
299 SFATAL << "ShaderProgramVariableChunk::changeFrom" << std::endl;
302 void ShaderProgramVariableChunk::deactivate(DrawEnv*, UInt32)
304 SFATAL << "ShaderProgramVariableChunk::deactivate" << std::endl;
307 void ShaderProgramVariableChunk::resolveLinks(void)
309 MFChangedFunctorCallback::iterator cfIt =
310 _mfDestroyedFunctors.begin();
311 MFChangedFunctorCallback::const_iterator cfEnd=
312 _mfDestroyedFunctors.end();
314 for(; cfIt != cfEnd; ++cfIt)
316 if(cfIt->_func)
317 (cfIt->_func)(this, 0x0000, ChangedOrigin::External);
320 clearDestroyedFunctors();
322 Inherited::resolveLinks();
325 OSG_END_NAMESPACE