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 CgFXMaterial!
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 "OSGShaderProgramVariables.h" // Variables Class
66 #include "OSGCgFXTechnique.h" // Techniques Class
67 #include "OSGTextureObjChunk.h" // Textures Class
69 #include "OSGCgFXMaterialBase.h"
70 #include "OSGCgFXMaterial.h"
72 #include <boost/bind.hpp>
76 /***************************************************************************\
78 \***************************************************************************/
80 /*! \class OSG::CgFXMaterial
84 /***************************************************************************\
85 * Field Documentation *
86 \***************************************************************************/
88 /*! \var bool CgFXMaterialBase::_sfTreatTechniquesAsVariants
89 effect compiler options
92 /*! \var std::string CgFXMaterialBase::_sfEffectFile
96 /*! \var UInt8 CgFXMaterialBase::_sfParameterValueSource
97 Source to use for parameters when initializing the material.
98 DEFAULT: Uses the values that are read in from the .cgfx file or code
99 string. Will overwrite the current value for the corresponding
100 ShaderProgramVariable if there is one.
101 CURRENT: Checks if the material already has a ShaderProgramVariable of
102 the same name, and if it does, it uses that value instead of the default
106 /*! \var std::string CgFXMaterialBase::_sfEffectString
110 /*! \var std::string CgFXMaterialBase::_mfCompilerOptions
111 effect compiler options
114 /*! \var ShaderProgramVariables * CgFXMaterialBase::_sfVariables
118 /*! \var std::string CgFXMaterialBase::_sfSelectedTechnique
122 /*! \var UInt32 CgFXMaterialBase::_sfStateVariables
126 /*! \var CgFXTechnique * CgFXMaterialBase::_mfTechniques
130 /*! \var TextureObjChunk * CgFXMaterialBase::_mfTextures
134 /*! \var GLenum CgFXMaterialBase::_sfGLId
135 The OpenGL texture id for this texture.
139 /***************************************************************************\
140 * FieldType/FieldTrait Instantiation *
141 \***************************************************************************/
143 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
144 PointerType FieldTraits
<CgFXMaterial
*, nsOSG
>::_type(
146 "VariantMaterialPtr",
147 CgFXMaterial::getClassType(),
151 OSG_FIELDTRAITS_GETTYPE_NS(CgFXMaterial
*, nsOSG
)
153 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField
,
157 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField
,
161 /***************************************************************************\
162 * Field Description *
163 \***************************************************************************/
165 void CgFXMaterialBase::classDescInserter(TypeObject
&oType
)
167 FieldDescriptionBase
*pDesc
= NULL
;
170 pDesc
= new SFBool::Description(
171 SFBool::getClassType(),
172 "treatTechniquesAsVariants",
173 "effect compiler options\n",
174 TreatTechniquesAsVariantsFieldId
, TreatTechniquesAsVariantsFieldMask
,
176 (Field::SFDefaultFlags
| Field::FStdAccess
),
177 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleTreatTechniquesAsVariants
),
178 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleTreatTechniquesAsVariants
));
180 oType
.addInitialDesc(pDesc
);
182 pDesc
= new SFString::Description(
183 SFString::getClassType(),
186 EffectFileFieldId
, EffectFileFieldMask
,
188 (Field::SFDefaultFlags
| Field::FStdAccess
),
189 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleEffectFile
),
190 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleEffectFile
));
192 oType
.addInitialDesc(pDesc
);
194 pDesc
= new SFUInt8::Description(
195 SFUInt8::getClassType(),
196 "ParameterValueSource",
197 "Source to use for parameters when initializing the material.\n"
198 "DEFAULT: Uses the values that are read in from the .cgfx file or code\n"
199 "string. Will overwrite the current value for the corresponding \n"
200 "ShaderProgramVariable if there is one.\n"
201 "CURRENT: Checks if the material already has a ShaderProgramVariable of\n"
202 "the same name, and if it does, it uses that value instead of the default\n"
204 ParameterValueSourceFieldId
, ParameterValueSourceFieldMask
,
206 (Field::SFDefaultFlags
| Field::FStdAccess
),
207 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleParameterValueSource
),
208 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleParameterValueSource
));
210 oType
.addInitialDesc(pDesc
);
212 pDesc
= new SFString::Description(
213 SFString::getClassType(),
216 EffectStringFieldId
, EffectStringFieldMask
,
218 (Field::SFDefaultFlags
| Field::FStdAccess
),
219 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleEffectString
),
220 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleEffectString
));
222 oType
.addInitialDesc(pDesc
);
224 pDesc
= new MFString::Description(
225 MFString::getClassType(),
227 "effect compiler options\n",
228 CompilerOptionsFieldId
, CompilerOptionsFieldMask
,
230 (Field::MFDefaultFlags
| Field::FStdAccess
),
231 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleCompilerOptions
),
232 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleCompilerOptions
));
234 oType
.addInitialDesc(pDesc
);
236 pDesc
= new SFUnrecChildShaderProgramVariablesPtr::Description(
237 SFUnrecChildShaderProgramVariablesPtr::getClassType(),
240 VariablesFieldId
, VariablesFieldMask
,
242 (Field::SFDefaultFlags
| Field::FStdAccess
),
243 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleVariables
),
244 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleVariables
));
246 oType
.addInitialDesc(pDesc
);
248 pDesc
= new SFString::Description(
249 SFString::getClassType(),
252 SelectedTechniqueFieldId
, SelectedTechniqueFieldMask
,
254 (Field::SFDefaultFlags
| Field::FStdAccess
),
255 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleSelectedTechnique
),
256 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleSelectedTechnique
));
258 oType
.addInitialDesc(pDesc
);
260 pDesc
= new SFUInt32::Description(
261 SFUInt32::getClassType(),
264 StateVariablesFieldId
, StateVariablesFieldMask
,
266 (Field::SFDefaultFlags
| Field::FStdAccess
),
267 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleStateVariables
),
268 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleStateVariables
));
270 oType
.addInitialDesc(pDesc
);
272 pDesc
= new MFUnrecCgFXTechniquePtr::Description(
273 MFUnrecCgFXTechniquePtr::getClassType(),
276 TechniquesFieldId
, TechniquesFieldMask
,
278 (Field::FStdAccess
| Field::FClusterLocal
| Field::FThreadLocal
),
279 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleTechniques
),
280 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleTechniques
));
282 oType
.addInitialDesc(pDesc
);
284 pDesc
= new MFUnrecTextureObjChunkPtr::Description(
285 MFUnrecTextureObjChunkPtr::getClassType(),
288 TexturesFieldId
, TexturesFieldMask
,
290 (Field::MFDefaultFlags
| Field::FStdAccess
),
291 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleTextures
),
292 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleTextures
));
294 oType
.addInitialDesc(pDesc
);
296 pDesc
= new SFGLenum::Description(
297 SFGLenum::getClassType(),
299 "The OpenGL texture id for this texture.\n",
300 GLIdFieldId
, GLIdFieldMask
,
302 (Field::FClusterLocal
),
303 static_cast<FieldEditMethodSig
>(&CgFXMaterial::editHandleGLId
),
304 static_cast<FieldGetMethodSig
>(&CgFXMaterial::getHandleGLId
));
306 oType
.addInitialDesc(pDesc
);
310 CgFXMaterialBase::TypeObject
CgFXMaterialBase::_type(
311 CgFXMaterialBase::getClassname(),
312 Inherited::getClassname(),
315 reinterpret_cast<PrototypeCreateF
>(&CgFXMaterialBase::createEmptyLocal
),
316 reinterpret_cast<InitContainerF
>(&CgFXMaterial::initMethod
),
317 reinterpret_cast<ExitContainerF
>(&CgFXMaterial::exitMethod
),
318 reinterpret_cast<InitalInsertDescFunc
>(
319 reinterpret_cast<void *>(&CgFXMaterial::classDescInserter
)),
321 TreatTechniquesAsVariantsFieldMask
| EffectStringFieldMask
| EffectFileFieldMask
,
322 "<?xml version=\"1.0\"?>\n"
325 " name=\"CgFXMaterial\"\n"
326 " parent=\"VariantMaterial\"\n"
327 " library=\"ContribCgFX\"\n"
328 " pointerfieldtypes=\"both\"\n"
329 " structure=\"concrete\"\n"
330 " systemcomponent=\"true\"\n"
331 " parentsystemcomponent=\"true\"\n"
332 " decoratable=\"false\"\n"
333 " useLocalIncludes=\"false\"\n"
334 " fieldsUnmarkedOnCreate=\"TreatTechniquesAsVariantsFieldMask | EffectStringFieldMask | EffectFileFieldMask\"\n"
337 " name=\"treatTechniquesAsVariants\"\n"
339 " cardinality=\"single\"\n"
340 " visibility=\"external\"\n"
341 " access=\"public\"\n"
342 " defaultValue=\"false\"\n"
344 " effect compiler options\n"
347 " name=\"effectFile\"\n"
348 " type=\"std::string\"\n"
349 " cardinality=\"single\"\n"
350 " visibility=\"external\"\n"
351 " access=\"public\"\n"
356 " name=\"ParameterValueSource\"\n"
358 " cardinality=\"single\"\n"
359 " visibility=\"external\"\n"
360 " access=\"public\"\n"
361 " defaultValue=\"CgFXMaterial::DEFAULT\"\n"
363 " Source to use for parameters when initializing the material.\n"
364 " DEFAULT: Uses the values that are read in from the .cgfx file or code\n"
365 " string. Will overwrite the current value for the corresponding \n"
366 " ShaderProgramVariable if there is one.\n"
367 " CURRENT: Checks if the material already has a ShaderProgramVariable of\n"
368 " the same name, and if it does, it uses that value instead of the default\n"
372 " name=\"effectString\"\n"
373 " type=\"std::string\"\n"
374 " cardinality=\"single\"\n"
375 " visibility=\"external\"\n"
376 " access=\"public\"\n"
381 " name=\"compilerOptions\"\n"
382 " type=\"std::string\"\n"
383 " cardinality=\"multi\"\n"
384 " visibility=\"external\"\n"
385 " access=\"public\"\n"
387 " effect compiler options\n"
390 " name=\"variables\"\n"
391 " type=\"ShaderProgramVariables\"\n"
392 " cardinality=\"single\"\n"
393 " visibility=\"external\"\n"
394 " access=\"protected\"\n"
395 " category=\"childpointer\"\n"
396 " childParentType=\"FieldContainer\"\n"
397 " linkParentField=\"Parents\"\n"
401 " name=\"selectedTechnique\"\n"
402 " type=\"std::string\"\n"
403 " cardinality=\"single\"\n"
404 " visibility=\"external\"\n"
405 " access=\"protected\"\n"
409 " name=\"stateVariables\"\n"
411 " category=\"data\"\n"
412 " cardinality=\"single\"\n"
413 " visibility=\"internal\"\n"
414 " access=\"protected\"\n"
415 " defaultValue=\"0\"\n"
419 " name=\"techniques\"\n"
420 " type=\"CgFXTechnique\"\n"
421 " cardinality=\"multi\"\n"
422 " visibility=\"internal\"\n"
423 " access=\"protected\"\n"
424 " category=\"pointer\"\n"
425 " fieldFlags=\"FStdAccess, FClusterLocal, FThreadLocal\"\n"
429 " name=\"textures\"\n"
430 " type=\"TextureObjChunk\"\n"
431 " category=\"pointer\"\n"
432 " cardinality=\"multi\"\n"
433 " visibility=\"external\"\n"
434 " access=\"protected\"\n"
440 " cardinality=\"single\"\n"
441 " visibility=\"internal\"\n"
442 " access=\"public\"\n"
443 " defaultValue=\"0\"\n"
444 " fieldFlags=\"FClusterLocal\"\n"
446 " The OpenGL texture id for this texture.\n"
448 "</FieldContainer>\n",
452 /*------------------------------ get -----------------------------------*/
454 FieldContainerType
&CgFXMaterialBase::getType(void)
459 const FieldContainerType
&CgFXMaterialBase::getType(void) const
464 UInt32
CgFXMaterialBase::getContainerSize(void) const
466 return sizeof(CgFXMaterial
);
469 /*------------------------- decorator get ------------------------------*/
472 SFBool
*CgFXMaterialBase::editSFTreatTechniquesAsVariants(void)
474 editSField(TreatTechniquesAsVariantsFieldMask
);
476 return &_sfTreatTechniquesAsVariants
;
479 const SFBool
*CgFXMaterialBase::getSFTreatTechniquesAsVariants(void) const
481 return &_sfTreatTechniquesAsVariants
;
485 SFString
*CgFXMaterialBase::editSFEffectFile(void)
487 editSField(EffectFileFieldMask
);
489 return &_sfEffectFile
;
492 const SFString
*CgFXMaterialBase::getSFEffectFile(void) const
494 return &_sfEffectFile
;
498 SFUInt8
*CgFXMaterialBase::editSFParameterValueSource(void)
500 editSField(ParameterValueSourceFieldMask
);
502 return &_sfParameterValueSource
;
505 const SFUInt8
*CgFXMaterialBase::getSFParameterValueSource(void) const
507 return &_sfParameterValueSource
;
511 SFString
*CgFXMaterialBase::editSFEffectString(void)
513 editSField(EffectStringFieldMask
);
515 return &_sfEffectString
;
518 const SFString
*CgFXMaterialBase::getSFEffectString(void) const
520 return &_sfEffectString
;
524 MFString
*CgFXMaterialBase::editMFCompilerOptions(void)
526 editMField(CompilerOptionsFieldMask
, _mfCompilerOptions
);
528 return &_mfCompilerOptions
;
531 const MFString
*CgFXMaterialBase::getMFCompilerOptions(void) const
533 return &_mfCompilerOptions
;
537 //! Get the CgFXMaterial::_sfVariables field.
538 const SFUnrecChildShaderProgramVariablesPtr
*CgFXMaterialBase::getSFVariables(void) const
540 return &_sfVariables
;
543 SFUnrecChildShaderProgramVariablesPtr
*CgFXMaterialBase::editSFVariables (void)
545 editSField(VariablesFieldMask
);
547 return &_sfVariables
;
550 //! Get the value of the CgFXMaterial::_sfVariables field.
551 ShaderProgramVariables
* CgFXMaterialBase::getVariables(void) const
553 return _sfVariables
.getValue();
556 //! Set the value of the CgFXMaterial::_sfVariables field.
557 void CgFXMaterialBase::setVariables(ShaderProgramVariables
* const value
)
559 editSField(VariablesFieldMask
);
561 _sfVariables
.setValue(value
);
565 SFString
*CgFXMaterialBase::editSFSelectedTechnique(void)
567 editSField(SelectedTechniqueFieldMask
);
569 return &_sfSelectedTechnique
;
572 const SFString
*CgFXMaterialBase::getSFSelectedTechnique(void) const
574 return &_sfSelectedTechnique
;
578 SFUInt32
*CgFXMaterialBase::editSFStateVariables(void)
580 editSField(StateVariablesFieldMask
);
582 return &_sfStateVariables
;
585 const SFUInt32
*CgFXMaterialBase::getSFStateVariables(void) const
587 return &_sfStateVariables
;
591 //! Get the CgFXMaterial::_mfTechniques field.
592 const MFUnrecCgFXTechniquePtr
*CgFXMaterialBase::getMFTechniques(void) const
594 return &_mfTechniques
;
597 MFUnrecCgFXTechniquePtr
*CgFXMaterialBase::editMFTechniques (void)
599 editMField(TechniquesFieldMask
, _mfTechniques
);
601 return &_mfTechniques
;
603 CgFXTechnique
* CgFXMaterialBase::getTechniques(const UInt32 index
) const
605 return _mfTechniques
[index
];
608 //! Get the CgFXMaterial::_mfTextures field.
609 const MFUnrecTextureObjChunkPtr
*CgFXMaterialBase::getMFTextures(void) const
614 MFUnrecTextureObjChunkPtr
*CgFXMaterialBase::editMFTextures (void)
616 editMField(TexturesFieldMask
, _mfTextures
);
620 TextureObjChunk
* CgFXMaterialBase::getTextures(const UInt32 index
) const
622 return _mfTextures
[index
];
625 SFGLenum
*CgFXMaterialBase::editSFGLId(void)
627 editSField(GLIdFieldMask
);
632 const SFGLenum
*CgFXMaterialBase::getSFGLId(void) const
640 void CgFXMaterialBase::pushToTechniques(CgFXTechnique
* const value
)
642 editMField(TechniquesFieldMask
, _mfTechniques
);
644 _mfTechniques
.push_back(value
);
647 void CgFXMaterialBase::assignTechniques(const MFUnrecCgFXTechniquePtr
&value
)
649 MFUnrecCgFXTechniquePtr::const_iterator elemIt
=
651 MFUnrecCgFXTechniquePtr::const_iterator elemEnd
=
654 static_cast<CgFXMaterial
*>(this)->clearTechniques();
656 while(elemIt
!= elemEnd
)
658 this->pushToTechniques(*elemIt
);
664 void CgFXMaterialBase::removeFromTechniques(UInt32 uiIndex
)
666 if(uiIndex
< _mfTechniques
.size())
668 editMField(TechniquesFieldMask
, _mfTechniques
);
670 _mfTechniques
.erase(uiIndex
);
674 void CgFXMaterialBase::removeObjFromTechniques(CgFXTechnique
* const value
)
676 Int32 iElemIdx
= _mfTechniques
.findIndex(value
);
680 editMField(TechniquesFieldMask
, _mfTechniques
);
682 _mfTechniques
.erase(iElemIdx
);
685 void CgFXMaterialBase::clearTechniques(void)
687 editMField(TechniquesFieldMask
, _mfTechniques
);
690 _mfTechniques
.clear();
693 void CgFXMaterialBase::pushToTextures(TextureObjChunk
* const value
)
695 editMField(TexturesFieldMask
, _mfTextures
);
697 _mfTextures
.push_back(value
);
700 void CgFXMaterialBase::assignTextures (const MFUnrecTextureObjChunkPtr
&value
)
702 MFUnrecTextureObjChunkPtr::const_iterator elemIt
=
704 MFUnrecTextureObjChunkPtr::const_iterator elemEnd
=
707 static_cast<CgFXMaterial
*>(this)->clearTextures();
709 while(elemIt
!= elemEnd
)
711 this->pushToTextures(*elemIt
);
717 void CgFXMaterialBase::removeFromTextures(UInt32 uiIndex
)
719 if(uiIndex
< _mfTextures
.size())
721 editMField(TexturesFieldMask
, _mfTextures
);
723 _mfTextures
.erase(uiIndex
);
727 void CgFXMaterialBase::removeObjFromTextures(TextureObjChunk
* const value
)
729 Int32 iElemIdx
= _mfTextures
.findIndex(value
);
733 editMField(TexturesFieldMask
, _mfTextures
);
735 _mfTextures
.erase(iElemIdx
);
738 void CgFXMaterialBase::clearTextures(void)
740 editMField(TexturesFieldMask
, _mfTextures
);
748 /*------------------------------ access -----------------------------------*/
750 SizeT
CgFXMaterialBase::getBinSize(ConstFieldMaskArg whichField
)
752 SizeT returnValue
= Inherited::getBinSize(whichField
);
754 if(FieldBits::NoField
!= (TreatTechniquesAsVariantsFieldMask
& whichField
))
756 returnValue
+= _sfTreatTechniquesAsVariants
.getBinSize();
758 if(FieldBits::NoField
!= (EffectFileFieldMask
& whichField
))
760 returnValue
+= _sfEffectFile
.getBinSize();
762 if(FieldBits::NoField
!= (ParameterValueSourceFieldMask
& whichField
))
764 returnValue
+= _sfParameterValueSource
.getBinSize();
766 if(FieldBits::NoField
!= (EffectStringFieldMask
& whichField
))
768 returnValue
+= _sfEffectString
.getBinSize();
770 if(FieldBits::NoField
!= (CompilerOptionsFieldMask
& whichField
))
772 returnValue
+= _mfCompilerOptions
.getBinSize();
774 if(FieldBits::NoField
!= (VariablesFieldMask
& whichField
))
776 returnValue
+= _sfVariables
.getBinSize();
778 if(FieldBits::NoField
!= (SelectedTechniqueFieldMask
& whichField
))
780 returnValue
+= _sfSelectedTechnique
.getBinSize();
782 if(FieldBits::NoField
!= (StateVariablesFieldMask
& whichField
))
784 returnValue
+= _sfStateVariables
.getBinSize();
786 if(FieldBits::NoField
!= (TechniquesFieldMask
& whichField
))
788 returnValue
+= _mfTechniques
.getBinSize();
790 if(FieldBits::NoField
!= (TexturesFieldMask
& whichField
))
792 returnValue
+= _mfTextures
.getBinSize();
794 if(FieldBits::NoField
!= (GLIdFieldMask
& whichField
))
796 returnValue
+= _sfGLId
.getBinSize();
802 void CgFXMaterialBase::copyToBin(BinaryDataHandler
&pMem
,
803 ConstFieldMaskArg whichField
)
805 Inherited::copyToBin(pMem
, whichField
);
807 if(FieldBits::NoField
!= (TreatTechniquesAsVariantsFieldMask
& whichField
))
809 _sfTreatTechniquesAsVariants
.copyToBin(pMem
);
811 if(FieldBits::NoField
!= (EffectFileFieldMask
& whichField
))
813 _sfEffectFile
.copyToBin(pMem
);
815 if(FieldBits::NoField
!= (ParameterValueSourceFieldMask
& whichField
))
817 _sfParameterValueSource
.copyToBin(pMem
);
819 if(FieldBits::NoField
!= (EffectStringFieldMask
& whichField
))
821 _sfEffectString
.copyToBin(pMem
);
823 if(FieldBits::NoField
!= (CompilerOptionsFieldMask
& whichField
))
825 _mfCompilerOptions
.copyToBin(pMem
);
827 if(FieldBits::NoField
!= (VariablesFieldMask
& whichField
))
829 _sfVariables
.copyToBin(pMem
);
831 if(FieldBits::NoField
!= (SelectedTechniqueFieldMask
& whichField
))
833 _sfSelectedTechnique
.copyToBin(pMem
);
835 if(FieldBits::NoField
!= (StateVariablesFieldMask
& whichField
))
837 _sfStateVariables
.copyToBin(pMem
);
839 if(FieldBits::NoField
!= (TechniquesFieldMask
& whichField
))
841 _mfTechniques
.copyToBin(pMem
);
843 if(FieldBits::NoField
!= (TexturesFieldMask
& whichField
))
845 _mfTextures
.copyToBin(pMem
);
847 if(FieldBits::NoField
!= (GLIdFieldMask
& whichField
))
849 _sfGLId
.copyToBin(pMem
);
853 void CgFXMaterialBase::copyFromBin(BinaryDataHandler
&pMem
,
854 ConstFieldMaskArg whichField
)
856 Inherited::copyFromBin(pMem
, whichField
);
858 if(FieldBits::NoField
!= (TreatTechniquesAsVariantsFieldMask
& whichField
))
860 editSField(TreatTechniquesAsVariantsFieldMask
);
861 _sfTreatTechniquesAsVariants
.copyFromBin(pMem
);
863 if(FieldBits::NoField
!= (EffectFileFieldMask
& whichField
))
865 editSField(EffectFileFieldMask
);
866 _sfEffectFile
.copyFromBin(pMem
);
868 if(FieldBits::NoField
!= (ParameterValueSourceFieldMask
& whichField
))
870 editSField(ParameterValueSourceFieldMask
);
871 _sfParameterValueSource
.copyFromBin(pMem
);
873 if(FieldBits::NoField
!= (EffectStringFieldMask
& whichField
))
875 editSField(EffectStringFieldMask
);
876 _sfEffectString
.copyFromBin(pMem
);
878 if(FieldBits::NoField
!= (CompilerOptionsFieldMask
& whichField
))
880 editMField(CompilerOptionsFieldMask
, _mfCompilerOptions
);
881 _mfCompilerOptions
.copyFromBin(pMem
);
883 if(FieldBits::NoField
!= (VariablesFieldMask
& whichField
))
885 editSField(VariablesFieldMask
);
886 _sfVariables
.copyFromBin(pMem
);
888 if(FieldBits::NoField
!= (SelectedTechniqueFieldMask
& whichField
))
890 editSField(SelectedTechniqueFieldMask
);
891 _sfSelectedTechnique
.copyFromBin(pMem
);
893 if(FieldBits::NoField
!= (StateVariablesFieldMask
& whichField
))
895 editSField(StateVariablesFieldMask
);
896 _sfStateVariables
.copyFromBin(pMem
);
898 if(FieldBits::NoField
!= (TechniquesFieldMask
& whichField
))
900 editMField(TechniquesFieldMask
, _mfTechniques
);
901 _mfTechniques
.copyFromBin(pMem
);
903 if(FieldBits::NoField
!= (TexturesFieldMask
& whichField
))
905 editMField(TexturesFieldMask
, _mfTextures
);
906 _mfTextures
.copyFromBin(pMem
);
908 if(FieldBits::NoField
!= (GLIdFieldMask
& whichField
))
910 editSField(GLIdFieldMask
);
911 _sfGLId
.copyFromBin(pMem
);
915 //! create a new instance of the class
916 CgFXMaterialTransitPtr
CgFXMaterialBase::createLocal(BitVector bFlags
)
918 CgFXMaterialTransitPtr fc
;
920 if(getClassType().getPrototype() != NULL
)
922 FieldContainerTransitPtr tmpPtr
=
923 getClassType().getPrototype()-> shallowCopyLocal(bFlags
);
925 fc
= dynamic_pointer_cast
<CgFXMaterial
>(tmpPtr
);
931 //! create a new instance of the class, copy the container flags
932 CgFXMaterialTransitPtr
CgFXMaterialBase::createDependent(BitVector bFlags
)
934 CgFXMaterialTransitPtr fc
;
936 if(getClassType().getPrototype() != NULL
)
938 FieldContainerTransitPtr tmpPtr
=
939 getClassType().getPrototype()-> shallowCopyDependent(bFlags
);
941 fc
= dynamic_pointer_cast
<CgFXMaterial
>(tmpPtr
);
947 //! create a new instance of the class
948 CgFXMaterialTransitPtr
CgFXMaterialBase::create(void)
950 CgFXMaterialTransitPtr fc
;
952 if(getClassType().getPrototype() != NULL
)
954 FieldContainerTransitPtr tmpPtr
=
955 getClassType().getPrototype()-> shallowCopy();
957 fc
= dynamic_pointer_cast
<CgFXMaterial
>(tmpPtr
);
963 CgFXMaterial
*CgFXMaterialBase::createEmptyLocal(BitVector bFlags
)
965 CgFXMaterial
*returnValue
;
967 newPtr
<CgFXMaterial
>(returnValue
, bFlags
);
969 returnValue
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
974 //! create an empty new instance of the class, do not copy the prototype
975 CgFXMaterial
*CgFXMaterialBase::createEmpty(void)
977 CgFXMaterial
*returnValue
;
979 newPtr
<CgFXMaterial
>(returnValue
, Thread::getCurrentLocalFlags());
981 returnValue
->_pFieldFlags
->_bNamespaceMask
&=
982 ~Thread::getCurrentLocalFlags();
988 FieldContainerTransitPtr
CgFXMaterialBase::shallowCopyLocal(
989 BitVector bFlags
) const
991 CgFXMaterial
*tmpPtr
;
993 newPtr(tmpPtr
, dynamic_cast<const CgFXMaterial
*>(this), bFlags
);
995 FieldContainerTransitPtr
returnValue(tmpPtr
);
997 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
1002 FieldContainerTransitPtr
CgFXMaterialBase::shallowCopyDependent(
1003 BitVector bFlags
) const
1005 CgFXMaterial
*tmpPtr
;
1007 newPtr(tmpPtr
, dynamic_cast<const CgFXMaterial
*>(this), ~bFlags
);
1009 FieldContainerTransitPtr
returnValue(tmpPtr
);
1011 tmpPtr
->_pFieldFlags
->_bNamespaceMask
= bFlags
;
1016 FieldContainerTransitPtr
CgFXMaterialBase::shallowCopy(void) const
1018 CgFXMaterial
*tmpPtr
;
1021 dynamic_cast<const CgFXMaterial
*>(this),
1022 Thread::getCurrentLocalFlags());
1024 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~Thread::getCurrentLocalFlags();
1026 FieldContainerTransitPtr
returnValue(tmpPtr
);
1034 /*------------------------- constructors ----------------------------------*/
1036 CgFXMaterialBase::CgFXMaterialBase(void) :
1038 _sfTreatTechniquesAsVariants(bool(false)),
1040 _sfParameterValueSource (UInt8(CgFXMaterial::DEFAULT
)),
1042 _mfCompilerOptions (),
1045 ShaderProgramVariables::ParentsFieldId
),
1046 _sfSelectedTechnique (),
1047 _sfStateVariables (UInt32(0)),
1054 CgFXMaterialBase::CgFXMaterialBase(const CgFXMaterialBase
&source
) :
1056 _sfTreatTechniquesAsVariants(source
._sfTreatTechniquesAsVariants
),
1057 _sfEffectFile (source
._sfEffectFile
),
1058 _sfParameterValueSource (source
._sfParameterValueSource
),
1059 _sfEffectString (source
._sfEffectString
),
1060 _mfCompilerOptions (source
._mfCompilerOptions
),
1063 ShaderProgramVariables::ParentsFieldId
),
1064 _sfSelectedTechnique (source
._sfSelectedTechnique
),
1065 _sfStateVariables (source
._sfStateVariables
),
1068 _sfGLId (source
._sfGLId
)
1073 /*-------------------------- destructors ----------------------------------*/
1075 CgFXMaterialBase::~CgFXMaterialBase(void)
1079 /*-------------------------------------------------------------------------*/
1082 bool CgFXMaterialBase::unlinkChild(
1083 FieldContainer
* const pChild
,
1084 UInt16
const childFieldId
)
1086 if(childFieldId
== VariablesFieldId
)
1088 ShaderProgramVariables
* pTypedChild
=
1089 dynamic_cast<ShaderProgramVariables
*>(pChild
);
1091 if(pTypedChild
!= NULL
)
1093 if(_sfVariables
.getValue() == pTypedChild
)
1095 editSField(VariablesFieldMask
);
1097 _sfVariables
.setValue(NULL
);
1102 SWARNING
<< "Parent ([" << this
1103 << "] id [" << this->getId()
1104 << "] type [" << this->getType().getCName()
1105 << "] childFieldId [" << childFieldId
1106 << "]) - Child ([" << pChild
1107 << "] id [" << pChild
->getId()
1108 << "] type [" << pChild
->getType().getCName()
1109 << "]): link inconsistent!"
1119 return Inherited::unlinkChild(pChild
, childFieldId
);
1122 void CgFXMaterialBase::onCreate(const CgFXMaterial
*source
)
1124 Inherited::onCreate(source
);
1128 CgFXMaterial
*pThis
= static_cast<CgFXMaterial
*>(this);
1130 pThis
->setVariables(source
->getVariables());
1132 MFUnrecCgFXTechniquePtr::const_iterator TechniquesIt
=
1133 source
->_mfTechniques
.begin();
1134 MFUnrecCgFXTechniquePtr::const_iterator TechniquesEnd
=
1135 source
->_mfTechniques
.end ();
1137 while(TechniquesIt
!= TechniquesEnd
)
1139 pThis
->pushToTechniques(*TechniquesIt
);
1144 MFUnrecTextureObjChunkPtr::const_iterator TexturesIt
=
1145 source
->_mfTextures
.begin();
1146 MFUnrecTextureObjChunkPtr::const_iterator TexturesEnd
=
1147 source
->_mfTextures
.end ();
1149 while(TexturesIt
!= TexturesEnd
)
1151 pThis
->pushToTextures(*TexturesIt
);
1158 GetFieldHandlePtr
CgFXMaterialBase::getHandleTreatTechniquesAsVariants (void) const
1160 SFBool::GetHandlePtr
returnValue(
1161 new SFBool::GetHandle(
1162 &_sfTreatTechniquesAsVariants
,
1163 this->getType().getFieldDesc(TreatTechniquesAsVariantsFieldId
),
1164 const_cast<CgFXMaterialBase
*>(this)));
1169 EditFieldHandlePtr
CgFXMaterialBase::editHandleTreatTechniquesAsVariants(void)
1171 SFBool::EditHandlePtr
returnValue(
1172 new SFBool::EditHandle(
1173 &_sfTreatTechniquesAsVariants
,
1174 this->getType().getFieldDesc(TreatTechniquesAsVariantsFieldId
),
1178 editSField(TreatTechniquesAsVariantsFieldMask
);
1183 GetFieldHandlePtr
CgFXMaterialBase::getHandleEffectFile (void) const
1185 SFString::GetHandlePtr
returnValue(
1186 new SFString::GetHandle(
1188 this->getType().getFieldDesc(EffectFileFieldId
),
1189 const_cast<CgFXMaterialBase
*>(this)));
1194 EditFieldHandlePtr
CgFXMaterialBase::editHandleEffectFile (void)
1196 SFString::EditHandlePtr
returnValue(
1197 new SFString::EditHandle(
1199 this->getType().getFieldDesc(EffectFileFieldId
),
1203 editSField(EffectFileFieldMask
);
1208 GetFieldHandlePtr
CgFXMaterialBase::getHandleParameterValueSource (void) const
1210 SFUInt8::GetHandlePtr
returnValue(
1211 new SFUInt8::GetHandle(
1212 &_sfParameterValueSource
,
1213 this->getType().getFieldDesc(ParameterValueSourceFieldId
),
1214 const_cast<CgFXMaterialBase
*>(this)));
1219 EditFieldHandlePtr
CgFXMaterialBase::editHandleParameterValueSource(void)
1221 SFUInt8::EditHandlePtr
returnValue(
1222 new SFUInt8::EditHandle(
1223 &_sfParameterValueSource
,
1224 this->getType().getFieldDesc(ParameterValueSourceFieldId
),
1228 editSField(ParameterValueSourceFieldMask
);
1233 GetFieldHandlePtr
CgFXMaterialBase::getHandleEffectString (void) const
1235 SFString::GetHandlePtr
returnValue(
1236 new SFString::GetHandle(
1238 this->getType().getFieldDesc(EffectStringFieldId
),
1239 const_cast<CgFXMaterialBase
*>(this)));
1244 EditFieldHandlePtr
CgFXMaterialBase::editHandleEffectString (void)
1246 SFString::EditHandlePtr
returnValue(
1247 new SFString::EditHandle(
1249 this->getType().getFieldDesc(EffectStringFieldId
),
1253 editSField(EffectStringFieldMask
);
1258 GetFieldHandlePtr
CgFXMaterialBase::getHandleCompilerOptions (void) const
1260 MFString::GetHandlePtr
returnValue(
1261 new MFString::GetHandle(
1262 &_mfCompilerOptions
,
1263 this->getType().getFieldDesc(CompilerOptionsFieldId
),
1264 const_cast<CgFXMaterialBase
*>(this)));
1269 EditFieldHandlePtr
CgFXMaterialBase::editHandleCompilerOptions(void)
1271 MFString::EditHandlePtr
returnValue(
1272 new MFString::EditHandle(
1273 &_mfCompilerOptions
,
1274 this->getType().getFieldDesc(CompilerOptionsFieldId
),
1278 editMField(CompilerOptionsFieldMask
, _mfCompilerOptions
);
1283 GetFieldHandlePtr
CgFXMaterialBase::getHandleVariables (void) const
1285 SFUnrecChildShaderProgramVariablesPtr::GetHandlePtr
returnValue(
1286 new SFUnrecChildShaderProgramVariablesPtr::GetHandle(
1288 this->getType().getFieldDesc(VariablesFieldId
),
1289 const_cast<CgFXMaterialBase
*>(this)));
1294 EditFieldHandlePtr
CgFXMaterialBase::editHandleVariables (void)
1296 SFUnrecChildShaderProgramVariablesPtr::EditHandlePtr
returnValue(
1297 new SFUnrecChildShaderProgramVariablesPtr::EditHandle(
1299 this->getType().getFieldDesc(VariablesFieldId
),
1302 returnValue
->setSetMethod(
1303 boost::bind(&CgFXMaterial::setVariables
,
1304 static_cast<CgFXMaterial
*>(this), _1
));
1306 editSField(VariablesFieldMask
);
1311 GetFieldHandlePtr
CgFXMaterialBase::getHandleSelectedTechnique (void) const
1313 SFString::GetHandlePtr
returnValue(
1314 new SFString::GetHandle(
1315 &_sfSelectedTechnique
,
1316 this->getType().getFieldDesc(SelectedTechniqueFieldId
),
1317 const_cast<CgFXMaterialBase
*>(this)));
1322 EditFieldHandlePtr
CgFXMaterialBase::editHandleSelectedTechnique(void)
1324 SFString::EditHandlePtr
returnValue(
1325 new SFString::EditHandle(
1326 &_sfSelectedTechnique
,
1327 this->getType().getFieldDesc(SelectedTechniqueFieldId
),
1331 editSField(SelectedTechniqueFieldMask
);
1336 GetFieldHandlePtr
CgFXMaterialBase::getHandleStateVariables (void) const
1338 SFUInt32::GetHandlePtr
returnValue(
1339 new SFUInt32::GetHandle(
1341 this->getType().getFieldDesc(StateVariablesFieldId
),
1342 const_cast<CgFXMaterialBase
*>(this)));
1347 EditFieldHandlePtr
CgFXMaterialBase::editHandleStateVariables (void)
1349 SFUInt32::EditHandlePtr
returnValue(
1350 new SFUInt32::EditHandle(
1352 this->getType().getFieldDesc(StateVariablesFieldId
),
1356 editSField(StateVariablesFieldMask
);
1361 GetFieldHandlePtr
CgFXMaterialBase::getHandleTechniques (void) const
1363 MFUnrecCgFXTechniquePtr::GetHandlePtr
returnValue(
1364 new MFUnrecCgFXTechniquePtr::GetHandle(
1366 this->getType().getFieldDesc(TechniquesFieldId
),
1367 const_cast<CgFXMaterialBase
*>(this)));
1372 EditFieldHandlePtr
CgFXMaterialBase::editHandleTechniques (void)
1374 MFUnrecCgFXTechniquePtr::EditHandlePtr
returnValue(
1375 new MFUnrecCgFXTechniquePtr::EditHandle(
1377 this->getType().getFieldDesc(TechniquesFieldId
),
1380 returnValue
->setAddMethod(
1381 boost::bind(&CgFXMaterial::pushToTechniques
,
1382 static_cast<CgFXMaterial
*>(this), _1
));
1383 returnValue
->setRemoveMethod(
1384 boost::bind(&CgFXMaterial::removeFromTechniques
,
1385 static_cast<CgFXMaterial
*>(this), _1
));
1386 returnValue
->setRemoveObjMethod(
1387 boost::bind(&CgFXMaterial::removeObjFromTechniques
,
1388 static_cast<CgFXMaterial
*>(this), _1
));
1389 returnValue
->setClearMethod(
1390 boost::bind(&CgFXMaterial::clearTechniques
,
1391 static_cast<CgFXMaterial
*>(this)));
1393 editMField(TechniquesFieldMask
, _mfTechniques
);
1398 GetFieldHandlePtr
CgFXMaterialBase::getHandleTextures (void) const
1400 MFUnrecTextureObjChunkPtr::GetHandlePtr
returnValue(
1401 new MFUnrecTextureObjChunkPtr::GetHandle(
1403 this->getType().getFieldDesc(TexturesFieldId
),
1404 const_cast<CgFXMaterialBase
*>(this)));
1409 EditFieldHandlePtr
CgFXMaterialBase::editHandleTextures (void)
1411 MFUnrecTextureObjChunkPtr::EditHandlePtr
returnValue(
1412 new MFUnrecTextureObjChunkPtr::EditHandle(
1414 this->getType().getFieldDesc(TexturesFieldId
),
1417 returnValue
->setAddMethod(
1418 boost::bind(&CgFXMaterial::pushToTextures
,
1419 static_cast<CgFXMaterial
*>(this), _1
));
1420 returnValue
->setRemoveMethod(
1421 boost::bind(&CgFXMaterial::removeFromTextures
,
1422 static_cast<CgFXMaterial
*>(this), _1
));
1423 returnValue
->setRemoveObjMethod(
1424 boost::bind(&CgFXMaterial::removeObjFromTextures
,
1425 static_cast<CgFXMaterial
*>(this), _1
));
1426 returnValue
->setClearMethod(
1427 boost::bind(&CgFXMaterial::clearTextures
,
1428 static_cast<CgFXMaterial
*>(this)));
1430 editMField(TexturesFieldMask
, _mfTextures
);
1435 GetFieldHandlePtr
CgFXMaterialBase::getHandleGLId (void) const
1437 SFGLenum::GetHandlePtr
returnValue(
1438 new SFGLenum::GetHandle(
1440 this->getType().getFieldDesc(GLIdFieldId
),
1441 const_cast<CgFXMaterialBase
*>(this)));
1446 EditFieldHandlePtr
CgFXMaterialBase::editHandleGLId (void)
1448 SFGLenum::EditHandlePtr
returnValue(
1449 new SFGLenum::EditHandle(
1451 this->getType().getFieldDesc(GLIdFieldId
),
1455 editSField(GLIdFieldMask
);
1461 #ifdef OSG_MT_CPTR_ASPECT
1462 void CgFXMaterialBase::execSyncV( FieldContainer
&oFrom
,
1463 ConstFieldMaskArg whichField
,
1464 AspectOffsetStore
&oOffsets
,
1465 ConstFieldMaskArg syncMode
,
1466 const UInt32 uiSyncInfo
)
1468 CgFXMaterial
*pThis
= static_cast<CgFXMaterial
*>(this);
1470 pThis
->execSync(static_cast<CgFXMaterial
*>(&oFrom
),
1479 #ifdef OSG_MT_CPTR_ASPECT
1480 FieldContainer
*CgFXMaterialBase::createAspectCopy(
1481 const FieldContainer
*pRefAspect
) const
1483 CgFXMaterial
*returnValue
;
1485 newAspectCopy(returnValue
,
1486 dynamic_cast<const CgFXMaterial
*>(pRefAspect
),
1487 dynamic_cast<const CgFXMaterial
*>(this));
1493 void CgFXMaterialBase::resolveLinks(void)
1495 Inherited::resolveLinks();
1497 static_cast<CgFXMaterial
*>(this)->setVariables(NULL
);
1499 static_cast<CgFXMaterial
*>(this)->clearTechniques();
1501 static_cast<CgFXMaterial
*>(this)->clearTextures();
1503 #ifdef OSG_MT_CPTR_ASPECT
1504 AspectOffsetStore oOffsets
;
1506 _pAspectStore
->fillOffsetArray(oOffsets
, this);
1509 #ifdef OSG_MT_CPTR_ASPECT
1510 _mfCompilerOptions
.terminateShare(Thread::getCurrentAspect(),