1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 /*****************************************************************************\
40 *****************************************************************************
42 ** This file is automatically generated. **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
47 ** Do not change this file, changes should be done in the derived **
48 ** class ShaderProgramVariables!
50 *****************************************************************************
51 \*****************************************************************************/
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
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>
75 /***************************************************************************\
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",
108 ShaderProgramVariables::getClassType(),
112 OSG_FIELDTRAITS_GETTYPE_NS(ShaderProgramVariables
*, nsOSG
)
114 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField
,
115 ShaderProgramVariables
*,
118 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField
,
119 ShaderProgramVariables
*,
122 DataType
&FieldTraits
< ShaderProgramVariables
*, nsOSG
+ 1 >::getType(void)
124 return FieldTraits
<ShaderProgramVariables
*, nsOSG
>::getType();
128 OSG_EXPORT_PTR_SFIELD(ChildPointerSField
,
129 ShaderProgramVariables
*,
130 UnrecordedRefCountPolicy
,
134 /***************************************************************************\
135 * Field Description *
136 \***************************************************************************/
138 void ShaderProgramVariablesBase::classDescInserter(TypeObject
&oType
)
140 FieldDescriptionBase
*pDesc
= NULL
;
143 pDesc
= new MFUnrecShaderValueVariablePtr::Description(
144 MFUnrecShaderValueVariablePtr::getClassType(),
147 VariablesFieldId
, VariablesFieldMask
,
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
,
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(),
170 "fragment program object\n",
171 VariableChangedFieldId
, VariableChangedFieldMask
,
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",
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
)),
193 "<?xml version=\"1.0\"?>\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"
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"
218 " pushToFieldAs=\"addVariable\"\n"
219 " removeFromMFieldIndexAs=\"subVariable\"\n"
220 " clearFieldAs=\"clearVariables\"\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"
235 " pushToFieldAs=\"addProceduralVariable\"\n"
236 " removeFromMFieldIndexAs=\"subProceduralVariable\"\n"
237 " clearFieldAs=\"clearProceduralVariables\"\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"
248 "\tfragment program object\n"
250 "</FieldContainer>\n",
254 /*------------------------------ get -----------------------------------*/
256 FieldContainerType
&ShaderProgramVariablesBase::getType(void)
261 const FieldContainerType
&ShaderProgramVariablesBase::getType(void) const
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();
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
);
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
);
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
);
424 ShaderProgramVariables
*ShaderProgramVariablesBase::createEmptyLocal(BitVector bFlags
)
426 ShaderProgramVariables
*returnValue
;
428 newPtr
<ShaderProgramVariables
>(returnValue
, bFlags
);
430 returnValue
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
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();
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
;
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
;
477 FieldContainerTransitPtr
ShaderProgramVariablesBase::shallowCopy(void) const
479 ShaderProgramVariables
*tmpPtr
;
482 dynamic_cast<const ShaderProgramVariables
*>(this),
483 Thread::getCurrentLocalFlags());
485 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~Thread::getCurrentLocalFlags();
487 FieldContainerTransitPtr
returnValue(tmpPtr
);
495 /*------------------------- constructors ----------------------------------*/
497 ShaderProgramVariablesBase::ShaderProgramVariablesBase(void) :
500 _mfProceduralVariables (this,
501 ProceduralVariablesFieldId
,
502 ShaderProcVariable::ParentsFieldId
),
503 _mfVariableChanged ()
507 ShaderProgramVariablesBase::ShaderProgramVariablesBase(const ShaderProgramVariablesBase
&source
) :
510 _mfProceduralVariables (this,
511 ProceduralVariablesFieldId
,
512 ShaderProcVariable::ParentsFieldId
),
513 _mfVariableChanged (source
._mfVariableChanged
)
518 /*-------------------------- destructors ----------------------------------*/
520 ShaderProgramVariablesBase::~ShaderProgramVariablesBase(void)
524 /*-------------------------------------------------------------------------*/
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
);
542 editMField(ProceduralVariablesFieldMask
, _mfProceduralVariables
);
544 _mfProceduralVariables
.erase(iChildIdx
);
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!"
566 return Inherited::unlinkChild(pChild
, childFieldId
);
569 void ShaderProgramVariablesBase::onCreate(const ShaderProgramVariables
*source
)
571 Inherited::onCreate(source
);
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
);
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(
608 this->getType().getFieldDesc(VariablesFieldId
),
609 const_cast<ShaderProgramVariablesBase
*>(this)));
614 EditFieldHandlePtr
ShaderProgramVariablesBase::editHandleVariables (void)
616 MFUnrecShaderValueVariablePtr::EditHandlePtr
returnValue(
617 new MFUnrecShaderValueVariablePtr::EditHandle(
619 this->getType().getFieldDesc(VariablesFieldId
),
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
);
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)));
648 EditFieldHandlePtr
ShaderProgramVariablesBase::editHandleProceduralVariables(void)
650 MFUnrecChildShaderProcVariablePtr::EditHandlePtr
returnValue(
651 new MFUnrecChildShaderProcVariablePtr::EditHandle(
652 &_mfProceduralVariables
,
653 this->getType().getFieldDesc(ProceduralVariablesFieldId
),
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
);
671 GetFieldHandlePtr
ShaderProgramVariablesBase::getHandleVariableChanged (void) const
673 MFUInt8::GetHandlePtr
returnValue(
674 new MFUInt8::GetHandle(
676 this->getType().getFieldDesc(VariableChangedFieldId
),
677 const_cast<ShaderProgramVariablesBase
*>(this)));
682 EditFieldHandlePtr
ShaderProgramVariablesBase::editHandleVariableChanged(void)
684 MFUInt8::EditHandlePtr
returnValue(
685 new MFUInt8::EditHandle(
687 this->getType().getFieldDesc(VariableChangedFieldId
),
691 editMField(VariableChangedFieldMask
, _mfVariableChanged
);
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
),
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));
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);
743 #ifdef OSG_MT_CPTR_ASPECT
744 _mfVariableChanged
.terminateShare(Thread::getCurrentAspect(),