fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Shader / Base / OSGShaderProgramVariablesBase.cpp
blob0e79075dabfb8b6ff93e00a07a5cbfcb88db9a18
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 *****************************************************************************
41 ** **
42 ** This file is automatically generated. **
43 ** **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
46 ** **
47 ** Do not change this file, changes should be done in the derived **
48 ** class ShaderProgramVariables!
49 ** **
50 *****************************************************************************
51 \*****************************************************************************/
53 #include <cstdlib>
54 #include <cstdio>
56 #ifdef WIN32
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
59 #endif
61 #include "OSGConfig.h"
65 #include "OSGShaderValueVariable.h" // Variables Class
66 #include "OSGShaderProcVariable.h" // ProceduralVariables Class
68 #include "OSGShaderProgramVariablesBase.h"
69 #include "OSGShaderProgramVariables.h"
71 #include <boost/bind.hpp>
73 OSG_BEGIN_NAMESPACE
75 /***************************************************************************\
76 * Description *
77 \***************************************************************************/
79 /*! \class OSG::ShaderProgramVariables
83 /***************************************************************************\
84 * Field Documentation *
85 \***************************************************************************/
87 /*! \var ShaderValueVariable * ShaderProgramVariablesBase::_mfVariables
91 /*! \var ShaderProcVariable * ShaderProgramVariablesBase::_mfProceduralVariables
95 /*! \var UInt8 ShaderProgramVariablesBase::_mfVariableChanged
96 fragment program object
100 /***************************************************************************\
101 * FieldType/FieldTrait Instantiation *
102 \***************************************************************************/
104 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
105 PointerType FieldTraits<ShaderProgramVariables *, nsOSG>::_type(
106 "ShaderProgramVariablesPtr",
107 "AttachmentPtr",
108 ShaderProgramVariables::getClassType(),
109 nsOSG);
110 #endif
112 OSG_FIELDTRAITS_GETTYPE_NS(ShaderProgramVariables *, nsOSG)
114 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
115 ShaderProgramVariables *,
116 nsOSG)
118 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
119 ShaderProgramVariables *,
120 nsOSG)
122 DataType &FieldTraits< ShaderProgramVariables *, nsOSG + 1 >::getType(void)
124 return FieldTraits<ShaderProgramVariables *, nsOSG>::getType();
128 OSG_EXPORT_PTR_SFIELD(ChildPointerSField,
129 ShaderProgramVariables *,
130 UnrecordedRefCountPolicy,
131 nsOSG + 1)
134 /***************************************************************************\
135 * Field Description *
136 \***************************************************************************/
138 void ShaderProgramVariablesBase::classDescInserter(TypeObject &oType)
140 FieldDescriptionBase *pDesc = NULL;
143 pDesc = new MFUnrecShaderValueVariablePtr::Description(
144 MFUnrecShaderValueVariablePtr::getClassType(),
145 "variables",
147 VariablesFieldId, VariablesFieldMask,
148 false,
149 (Field::MFDefaultFlags | Field::FCustomAccess),
150 static_cast<FieldEditMethodSig>(&ShaderProgramVariables::editHandleVariables),
151 static_cast<FieldGetMethodSig >(&ShaderProgramVariables::getHandleVariables));
153 oType.addInitialDesc(pDesc);
155 pDesc = new MFUnrecChildShaderProcVariablePtr::Description(
156 MFUnrecChildShaderProcVariablePtr::getClassType(),
157 "proceduralVariables",
159 ProceduralVariablesFieldId, ProceduralVariablesFieldMask,
160 false,
161 (Field::MFDefaultFlags | Field::FCustomAccess),
162 static_cast<FieldEditMethodSig>(&ShaderProgramVariables::editHandleProceduralVariables),
163 static_cast<FieldGetMethodSig >(&ShaderProgramVariables::getHandleProceduralVariables));
165 oType.addInitialDesc(pDesc);
167 pDesc = new MFUInt8::Description(
168 MFUInt8::getClassType(),
169 "variableChanged",
170 "fragment program object\n",
171 VariableChangedFieldId, VariableChangedFieldMask,
172 true,
173 (Field::MFDefaultFlags | Field::FStdAccess),
174 static_cast<FieldEditMethodSig>(&ShaderProgramVariables::editHandleVariableChanged),
175 static_cast<FieldGetMethodSig >(&ShaderProgramVariables::getHandleVariableChanged));
177 oType.addInitialDesc(pDesc);
181 ShaderProgramVariablesBase::TypeObject ShaderProgramVariablesBase::_type(
182 ShaderProgramVariablesBase::getClassname(),
183 Inherited::getClassname(),
184 "ShaderProgramVariables",
185 nsOSG, //Namespace
186 reinterpret_cast<PrototypeCreateF>(&ShaderProgramVariablesBase::createEmptyLocal),
187 reinterpret_cast<InitContainerF>(&ShaderProgramVariables::initMethod),
188 reinterpret_cast<ExitContainerF>(&ShaderProgramVariables::exitMethod),
189 reinterpret_cast<InitalInsertDescFunc>(
190 reinterpret_cast<void *>(&ShaderProgramVariables::classDescInserter)),
191 false,
193 "<?xml version=\"1.0\"?>\n"
194 "\n"
195 "<FieldContainer\n"
196 " name=\"ShaderProgramVariables\"\n"
197 " parent=\"Attachment\"\n"
198 " library=\"System\"\n"
199 " structure=\"concrete\"\n"
200 " pointerfieldtypes=\"both\"\n"
201 " systemcomponent=\"true\"\n"
202 " parentsystemcomponent=\"true\"\n"
203 " decoratable=\"false\"\n"
204 " useLocalIncludes=\"false\"\n"
205 " childFields=\"single\"\n"
206 " docGroupBase=\"GrpSystemShader\"\n"
207 " >\n"
208 "\n"
209 " <Field\n"
210 " name=\"variables\"\n"
211 " type=\"ShaderValueVariable\"\n"
212 " cardinality=\"multi\"\n"
213 " visibility=\"external\"\n"
214 " access=\"protected\"\n"
215 " category=\"pointer\"\n"
216 " ptrFieldAccess=\"custom\"\n"
217 "\n"
218 " pushToFieldAs=\"addVariable\"\n"
219 " removeFromMFieldIndexAs=\"subVariable\"\n"
220 " clearFieldAs=\"clearVariables\"\n"
221 " >\n"
222 " </Field>\n"
223 "\n"
224 " <Field\n"
225 " name=\"proceduralVariables\"\n"
226 " type=\"ShaderProcVariable\"\n"
227 " cardinality=\"multi\"\n"
228 " visibility=\"external\"\n"
229 " access=\"protected\"\n"
230 " category=\"childpointer\"\n"
231 " childParentType=\"FieldContainer\"\n"
232 " linkParentField=\"Parents\"\n"
233 " ptrFieldAccess=\"custom\"\n"
234 "\n"
235 " pushToFieldAs=\"addProceduralVariable\"\n"
236 " removeFromMFieldIndexAs=\"subProceduralVariable\"\n"
237 " clearFieldAs=\"clearProceduralVariables\"\n"
238 " >\n"
239 " </Field>\n"
240 "\n"
241 " <Field\n"
242 "\t name=\"variableChanged\"\n"
243 "\t type=\"UInt8\"\n"
244 "\t cardinality=\"multi\"\n"
245 "\t visibility=\"internal\"\n"
246 "\t access=\"public\"\n"
247 "\t >\n"
248 "\tfragment program object\n"
249 " </Field>\n"
250 "</FieldContainer>\n",
254 /*------------------------------ get -----------------------------------*/
256 FieldContainerType &ShaderProgramVariablesBase::getType(void)
258 return _type;
261 const FieldContainerType &ShaderProgramVariablesBase::getType(void) const
263 return _type;
266 UInt32 ShaderProgramVariablesBase::getContainerSize(void) const
268 return sizeof(ShaderProgramVariables);
271 /*------------------------- decorator get ------------------------------*/
274 //! Get the ShaderProgramVariables::_mfVariables field.
275 const MFUnrecShaderValueVariablePtr *ShaderProgramVariablesBase::getMFVariables(void) const
277 return &_mfVariables;
279 ShaderValueVariable * ShaderProgramVariablesBase::getVariables(const UInt32 index) const
281 return _mfVariables[index];
284 //! Get the ShaderProgramVariables::_mfProceduralVariables field.
285 const MFUnrecChildShaderProcVariablePtr *ShaderProgramVariablesBase::getMFProceduralVariables(void) const
287 return &_mfProceduralVariables;
289 ShaderProcVariable * ShaderProgramVariablesBase::getProceduralVariables(const UInt32 index) const
291 return _mfProceduralVariables[index];
294 MFUInt8 *ShaderProgramVariablesBase::editMFVariableChanged(void)
296 editMField(VariableChangedFieldMask, _mfVariableChanged);
298 return &_mfVariableChanged;
301 const MFUInt8 *ShaderProgramVariablesBase::getMFVariableChanged(void) const
303 return &_mfVariableChanged;
313 /*------------------------------ access -----------------------------------*/
315 SizeT ShaderProgramVariablesBase::getBinSize(ConstFieldMaskArg whichField)
317 SizeT returnValue = Inherited::getBinSize(whichField);
319 if(FieldBits::NoField != (VariablesFieldMask & whichField))
321 returnValue += _mfVariables.getBinSize();
323 if(FieldBits::NoField != (ProceduralVariablesFieldMask & whichField))
325 returnValue += _mfProceduralVariables.getBinSize();
327 if(FieldBits::NoField != (VariableChangedFieldMask & whichField))
329 returnValue += _mfVariableChanged.getBinSize();
332 return returnValue;
335 void ShaderProgramVariablesBase::copyToBin(BinaryDataHandler &pMem,
336 ConstFieldMaskArg whichField)
338 Inherited::copyToBin(pMem, whichField);
340 if(FieldBits::NoField != (VariablesFieldMask & whichField))
342 _mfVariables.copyToBin(pMem);
344 if(FieldBits::NoField != (ProceduralVariablesFieldMask & whichField))
346 _mfProceduralVariables.copyToBin(pMem);
348 if(FieldBits::NoField != (VariableChangedFieldMask & whichField))
350 _mfVariableChanged.copyToBin(pMem);
354 void ShaderProgramVariablesBase::copyFromBin(BinaryDataHandler &pMem,
355 ConstFieldMaskArg whichField)
357 Inherited::copyFromBin(pMem, whichField);
359 if(FieldBits::NoField != (VariablesFieldMask & whichField))
361 editMField(VariablesFieldMask, _mfVariables);
362 _mfVariables.copyFromBin(pMem);
364 if(FieldBits::NoField != (ProceduralVariablesFieldMask & whichField))
366 editMField(ProceduralVariablesFieldMask, _mfProceduralVariables);
367 _mfProceduralVariables.copyFromBin(pMem);
369 if(FieldBits::NoField != (VariableChangedFieldMask & whichField))
371 editMField(VariableChangedFieldMask, _mfVariableChanged);
372 _mfVariableChanged.copyFromBin(pMem);
376 //! create a new instance of the class
377 ShaderProgramVariablesTransitPtr ShaderProgramVariablesBase::createLocal(BitVector bFlags)
379 ShaderProgramVariablesTransitPtr fc;
381 if(getClassType().getPrototype() != NULL)
383 FieldContainerTransitPtr tmpPtr =
384 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
386 fc = dynamic_pointer_cast<ShaderProgramVariables>(tmpPtr);
389 return fc;
392 //! create a new instance of the class, copy the container flags
393 ShaderProgramVariablesTransitPtr ShaderProgramVariablesBase::createDependent(BitVector bFlags)
395 ShaderProgramVariablesTransitPtr fc;
397 if(getClassType().getPrototype() != NULL)
399 FieldContainerTransitPtr tmpPtr =
400 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
402 fc = dynamic_pointer_cast<ShaderProgramVariables>(tmpPtr);
405 return fc;
408 //! create a new instance of the class
409 ShaderProgramVariablesTransitPtr ShaderProgramVariablesBase::create(void)
411 ShaderProgramVariablesTransitPtr fc;
413 if(getClassType().getPrototype() != NULL)
415 FieldContainerTransitPtr tmpPtr =
416 getClassType().getPrototype()-> shallowCopy();
418 fc = dynamic_pointer_cast<ShaderProgramVariables>(tmpPtr);
421 return fc;
424 ShaderProgramVariables *ShaderProgramVariablesBase::createEmptyLocal(BitVector bFlags)
426 ShaderProgramVariables *returnValue;
428 newPtr<ShaderProgramVariables>(returnValue, bFlags);
430 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
432 return returnValue;
435 //! create an empty new instance of the class, do not copy the prototype
436 ShaderProgramVariables *ShaderProgramVariablesBase::createEmpty(void)
438 ShaderProgramVariables *returnValue;
440 newPtr<ShaderProgramVariables>(returnValue, Thread::getCurrentLocalFlags());
442 returnValue->_pFieldFlags->_bNamespaceMask &=
443 ~Thread::getCurrentLocalFlags();
445 return returnValue;
449 FieldContainerTransitPtr ShaderProgramVariablesBase::shallowCopyLocal(
450 BitVector bFlags) const
452 ShaderProgramVariables *tmpPtr;
454 newPtr(tmpPtr, dynamic_cast<const ShaderProgramVariables *>(this), bFlags);
456 FieldContainerTransitPtr returnValue(tmpPtr);
458 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
460 return returnValue;
463 FieldContainerTransitPtr ShaderProgramVariablesBase::shallowCopyDependent(
464 BitVector bFlags) const
466 ShaderProgramVariables *tmpPtr;
468 newPtr(tmpPtr, dynamic_cast<const ShaderProgramVariables *>(this), ~bFlags);
470 FieldContainerTransitPtr returnValue(tmpPtr);
472 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
474 return returnValue;
477 FieldContainerTransitPtr ShaderProgramVariablesBase::shallowCopy(void) const
479 ShaderProgramVariables *tmpPtr;
481 newPtr(tmpPtr,
482 dynamic_cast<const ShaderProgramVariables *>(this),
483 Thread::getCurrentLocalFlags());
485 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
487 FieldContainerTransitPtr returnValue(tmpPtr);
489 return returnValue;
495 /*------------------------- constructors ----------------------------------*/
497 ShaderProgramVariablesBase::ShaderProgramVariablesBase(void) :
498 Inherited(),
499 _mfVariables (),
500 _mfProceduralVariables (this,
501 ProceduralVariablesFieldId,
502 ShaderProcVariable::ParentsFieldId),
503 _mfVariableChanged ()
507 ShaderProgramVariablesBase::ShaderProgramVariablesBase(const ShaderProgramVariablesBase &source) :
508 Inherited(source),
509 _mfVariables (),
510 _mfProceduralVariables (this,
511 ProceduralVariablesFieldId,
512 ShaderProcVariable::ParentsFieldId),
513 _mfVariableChanged (source._mfVariableChanged )
518 /*-------------------------- destructors ----------------------------------*/
520 ShaderProgramVariablesBase::~ShaderProgramVariablesBase(void)
524 /*-------------------------------------------------------------------------*/
525 /* Child linking */
527 bool ShaderProgramVariablesBase::unlinkChild(
528 FieldContainer * const pChild,
529 UInt16 const childFieldId)
531 if(childFieldId == ProceduralVariablesFieldId)
533 ShaderProcVariable * pTypedChild =
534 dynamic_cast<ShaderProcVariable *>(pChild);
536 if(pTypedChild != NULL)
538 Int32 iChildIdx = _mfProceduralVariables.findIndex(pTypedChild);
540 if(iChildIdx != -1)
542 editMField(ProceduralVariablesFieldMask, _mfProceduralVariables);
544 _mfProceduralVariables.erase(iChildIdx);
546 return true;
549 SWARNING << "Parent ([" << this
550 << "] id [" << this->getId()
551 << "] type [" << this->getType().getCName()
552 << "] childFieldId [" << childFieldId
553 << "]) - Child ([" << pChild
554 << "] id [" << pChild->getId()
555 << "] type [" << pChild->getType().getCName()
556 << "]): link inconsistent!"
557 << std::endl;
559 return false;
562 return false;
566 return Inherited::unlinkChild(pChild, childFieldId);
569 void ShaderProgramVariablesBase::onCreate(const ShaderProgramVariables *source)
571 Inherited::onCreate(source);
573 if(source != NULL)
575 ShaderProgramVariables *pThis = static_cast<ShaderProgramVariables *>(this);
577 MFUnrecShaderValueVariablePtr::const_iterator VariablesIt =
578 source->_mfVariables.begin();
579 MFUnrecShaderValueVariablePtr::const_iterator VariablesEnd =
580 source->_mfVariables.end ();
582 while(VariablesIt != VariablesEnd)
584 pThis->addVariable(*VariablesIt);
586 ++VariablesIt;
589 MFUnrecChildShaderProcVariablePtr::const_iterator ProceduralVariablesIt =
590 source->_mfProceduralVariables.begin();
591 MFUnrecChildShaderProcVariablePtr::const_iterator ProceduralVariablesEnd =
592 source->_mfProceduralVariables.end ();
594 while(ProceduralVariablesIt != ProceduralVariablesEnd)
596 pThis->addProceduralVariable(*ProceduralVariablesIt);
598 ++ProceduralVariablesIt;
603 GetFieldHandlePtr ShaderProgramVariablesBase::getHandleVariables (void) const
605 MFUnrecShaderValueVariablePtr::GetHandlePtr returnValue(
606 new MFUnrecShaderValueVariablePtr::GetHandle(
607 &_mfVariables,
608 this->getType().getFieldDesc(VariablesFieldId),
609 const_cast<ShaderProgramVariablesBase *>(this)));
611 return returnValue;
614 EditFieldHandlePtr ShaderProgramVariablesBase::editHandleVariables (void)
616 MFUnrecShaderValueVariablePtr::EditHandlePtr returnValue(
617 new MFUnrecShaderValueVariablePtr::EditHandle(
618 &_mfVariables,
619 this->getType().getFieldDesc(VariablesFieldId),
620 this));
622 returnValue->setAddMethod(
623 boost::bind(&ShaderProgramVariables::addVariable,
624 static_cast<ShaderProgramVariables *>(this), _1));
625 returnValue->setRemoveMethod(
626 boost::bind(&ShaderProgramVariables::subVariable,
627 static_cast<ShaderProgramVariables *>(this), _1));
628 returnValue->setClearMethod(
629 boost::bind(&ShaderProgramVariables::clearVariables,
630 static_cast<ShaderProgramVariables *>(this)));
632 editMField(VariablesFieldMask, _mfVariables);
634 return returnValue;
637 GetFieldHandlePtr ShaderProgramVariablesBase::getHandleProceduralVariables (void) const
639 MFUnrecChildShaderProcVariablePtr::GetHandlePtr returnValue(
640 new MFUnrecChildShaderProcVariablePtr::GetHandle(
641 &_mfProceduralVariables,
642 this->getType().getFieldDesc(ProceduralVariablesFieldId),
643 const_cast<ShaderProgramVariablesBase *>(this)));
645 return returnValue;
648 EditFieldHandlePtr ShaderProgramVariablesBase::editHandleProceduralVariables(void)
650 MFUnrecChildShaderProcVariablePtr::EditHandlePtr returnValue(
651 new MFUnrecChildShaderProcVariablePtr::EditHandle(
652 &_mfProceduralVariables,
653 this->getType().getFieldDesc(ProceduralVariablesFieldId),
654 this));
656 returnValue->setAddMethod(
657 boost::bind(&ShaderProgramVariables::addProceduralVariable,
658 static_cast<ShaderProgramVariables *>(this), _1));
659 returnValue->setRemoveMethod(
660 boost::bind(&ShaderProgramVariables::subProceduralVariable,
661 static_cast<ShaderProgramVariables *>(this), _1));
662 returnValue->setClearMethod(
663 boost::bind(&ShaderProgramVariables::clearProceduralVariables,
664 static_cast<ShaderProgramVariables *>(this)));
666 editMField(ProceduralVariablesFieldMask, _mfProceduralVariables);
668 return returnValue;
671 GetFieldHandlePtr ShaderProgramVariablesBase::getHandleVariableChanged (void) const
673 MFUInt8::GetHandlePtr returnValue(
674 new MFUInt8::GetHandle(
675 &_mfVariableChanged,
676 this->getType().getFieldDesc(VariableChangedFieldId),
677 const_cast<ShaderProgramVariablesBase *>(this)));
679 return returnValue;
682 EditFieldHandlePtr ShaderProgramVariablesBase::editHandleVariableChanged(void)
684 MFUInt8::EditHandlePtr returnValue(
685 new MFUInt8::EditHandle(
686 &_mfVariableChanged,
687 this->getType().getFieldDesc(VariableChangedFieldId),
688 this));
691 editMField(VariableChangedFieldMask, _mfVariableChanged);
693 return returnValue;
697 #ifdef OSG_MT_CPTR_ASPECT
698 void ShaderProgramVariablesBase::execSyncV( FieldContainer &oFrom,
699 ConstFieldMaskArg whichField,
700 AspectOffsetStore &oOffsets,
701 ConstFieldMaskArg syncMode,
702 const UInt32 uiSyncInfo)
704 ShaderProgramVariables *pThis = static_cast<ShaderProgramVariables *>(this);
706 pThis->execSync(static_cast<ShaderProgramVariables *>(&oFrom),
707 whichField,
708 oOffsets,
709 syncMode,
710 uiSyncInfo);
712 #endif
715 #ifdef OSG_MT_CPTR_ASPECT
716 FieldContainer *ShaderProgramVariablesBase::createAspectCopy(
717 const FieldContainer *pRefAspect) const
719 ShaderProgramVariables *returnValue;
721 newAspectCopy(returnValue,
722 dynamic_cast<const ShaderProgramVariables *>(pRefAspect),
723 dynamic_cast<const ShaderProgramVariables *>(this));
725 return returnValue;
727 #endif
729 void ShaderProgramVariablesBase::resolveLinks(void)
731 Inherited::resolveLinks();
733 static_cast<ShaderProgramVariables *>(this)->clearVariables();
735 static_cast<ShaderProgramVariables *>(this)->clearProceduralVariables();
737 #ifdef OSG_MT_CPTR_ASPECT
738 AspectOffsetStore oOffsets;
740 _pAspectStore->fillOffsetArray(oOffsets, this);
741 #endif
743 #ifdef OSG_MT_CPTR_ASPECT
744 _mfVariableChanged.terminateShare(Thread::getCurrentAspect(),
745 oOffsets);
746 #endif
750 OSG_END_NAMESPACE