1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGShaderProgramVariableChunk.h"
50 #include "OSGShaderVariables.h"
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 /***************************************************************************\
61 \***************************************************************************/
63 StateChunkClass
ShaderProgramVariableChunk::_class("ShaderProgramVariable",
67 volatile UInt16
ShaderProgramVariableChunk::_uiChunkCounter
= 1;
69 ShaderProgramVariableChunk::VarIdPool
*
70 ShaderProgramVariableChunk::_pVarIdPool
= NULL
;
73 void SimpleReusePool
<Int32
,
74 ShaderProgramVariableChunk::VariableIdPoolTag
,
75 SingleLockPolicy
>::initializeValue(void)
80 /***************************************************************************\
82 \***************************************************************************/
84 void ShaderProgramVariableChunk::initMethod(InitPhase ePhase
)
86 Inherited::initMethod(ePhase
);
88 if(ePhase
== TypeObject::SystemPost
)
94 /***************************************************************************\
96 \***************************************************************************/
98 /*-------------------------------------------------------------------------*\
100 \*-------------------------------------------------------------------------*/
102 /*----------------------- constructors & destructors ----------------------*/
104 ShaderProgramVariableChunk::ShaderProgramVariableChunk(void) :
111 ShaderProgramVariableChunk::ShaderProgramVariableChunk(
112 const ShaderProgramVariableChunk
&source
) :
120 ShaderProgramVariableChunk::~ShaderProgramVariableChunk(void)
124 void ShaderProgramVariableChunk::onCreate(
125 const ShaderProgramVariableChunk
*source
)
127 Inherited::onCreate(source
);
129 if(GlobalSystemState
== Startup
)
131 _pVarIdPool
= new VarIdPool
;
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
)
170 const StateChunkClass
*ShaderProgramVariableChunk::getClass(void) const
175 UInt16
ShaderProgramVariableChunk::getChunkId(void)
180 /*----------------------------- class specific ----------------------------*/
182 void ShaderProgramVariableChunk::changed(ConstFieldMaskArg whichField
,
186 if(0x0000 != (whichField
& VariablesFieldMask
))
188 ShaderProgramVariables
*pVars
= _sfVariables
.getValue();
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
,
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
);
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
);
258 bool ShaderProgramVariableChunk::subUniformBlock(const Char8
*name
)
260 if(_sfVariables
.getValue() != NULL
)
262 return _sfVariables
.getValue()->subUniformBlock(name
, NULL
, NULL
);
270 bool ShaderProgramVariableChunk::subShaderStorageBlock(const Char8
*name
)
272 if(_sfVariables
.getValue() != NULL
)
274 return _sfVariables
.getValue()->subShaderStorageBlock(name
, NULL
, NULL
);
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
,
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
)
317 (cfIt
->_func
)(this, 0x0000, ChangedOrigin::External
);
320 clearDestroyedFunctors();
322 Inherited::resolveLinks();