changed: gcc8 base update
[opensg.git] / Source / Contrib / CgFXMaterial / OSGCgFXMaterialBase.cpp
blob063baa036f5108d6d03202d6c5d1d0e2374b947f
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 CgFXMaterial!
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 "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>
74 OSG_BEGIN_NAMESPACE
76 /***************************************************************************\
77 * Description *
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
93 cgfx file
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
103 value.
106 /*! \var std::string CgFXMaterialBase::_sfEffectString
107 cgfx file
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(
145 "CgFXMaterialPtr",
146 "VariantMaterialPtr",
147 CgFXMaterial::getClassType(),
148 nsOSG);
149 #endif
151 OSG_FIELDTRAITS_GETTYPE_NS(CgFXMaterial *, nsOSG)
153 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
154 CgFXMaterial *,
155 nsOSG)
157 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
158 CgFXMaterial *,
159 nsOSG)
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,
175 false,
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(),
184 "effectFile",
185 "cgfx file\n",
186 EffectFileFieldId, EffectFileFieldMask,
187 false,
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"
203 "value. \n",
204 ParameterValueSourceFieldId, ParameterValueSourceFieldMask,
205 false,
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(),
214 "effectString",
215 "cgfx file\n",
216 EffectStringFieldId, EffectStringFieldMask,
217 false,
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(),
226 "compilerOptions",
227 "effect compiler options\n",
228 CompilerOptionsFieldId, CompilerOptionsFieldMask,
229 false,
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(),
238 "variables",
240 VariablesFieldId, VariablesFieldMask,
241 false,
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(),
250 "selectedTechnique",
252 SelectedTechniqueFieldId, SelectedTechniqueFieldMask,
253 false,
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(),
262 "stateVariables",
264 StateVariablesFieldId, StateVariablesFieldMask,
265 true,
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(),
274 "techniques",
276 TechniquesFieldId, TechniquesFieldMask,
277 true,
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(),
286 "textures",
288 TexturesFieldId, TexturesFieldMask,
289 false,
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(),
298 "GLId",
299 "The OpenGL texture id for this texture.\n",
300 GLIdFieldId, GLIdFieldMask,
301 true,
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(),
313 "NULL",
314 nsOSG, //Namespace
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)),
320 false,
321 TreatTechniquesAsVariantsFieldMask | EffectStringFieldMask | EffectFileFieldMask,
322 "<?xml version=\"1.0\"?>\n"
323 "\n"
324 "<FieldContainer\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"
335 " >\n"
336 " <Field\n"
337 " name=\"treatTechniquesAsVariants\"\n"
338 " type=\"bool\"\n"
339 " cardinality=\"single\"\n"
340 " visibility=\"external\"\n"
341 " access=\"public\"\n"
342 " defaultValue=\"false\"\n"
343 " >\n"
344 " effect compiler options\n"
345 " </Field>\n"
346 " <Field\n"
347 " name=\"effectFile\"\n"
348 " type=\"std::string\"\n"
349 " cardinality=\"single\"\n"
350 " visibility=\"external\"\n"
351 " access=\"public\"\n"
352 " >\n"
353 " cgfx file\n"
354 " </Field>\n"
355 " <Field\n"
356 " name=\"ParameterValueSource\"\n"
357 " type=\"UInt8\"\n"
358 " cardinality=\"single\"\n"
359 " visibility=\"external\"\n"
360 " access=\"public\"\n"
361 " defaultValue=\"CgFXMaterial::DEFAULT\"\n"
362 " >\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"
369 " value. \n"
370 " </Field>\n"
371 " <Field\n"
372 " name=\"effectString\"\n"
373 " type=\"std::string\"\n"
374 " cardinality=\"single\"\n"
375 " visibility=\"external\"\n"
376 " access=\"public\"\n"
377 " >\n"
378 " cgfx file\n"
379 " </Field>\n"
380 " <Field\n"
381 " name=\"compilerOptions\"\n"
382 " type=\"std::string\"\n"
383 " cardinality=\"multi\"\n"
384 " visibility=\"external\"\n"
385 " access=\"public\"\n"
386 " >\n"
387 " effect compiler options\n"
388 " </Field>\n"
389 " <Field\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"
398 " >\n"
399 " </Field>\n"
400 " <Field\n"
401 " name=\"selectedTechnique\"\n"
402 " type=\"std::string\"\n"
403 " cardinality=\"single\"\n"
404 " visibility=\"external\"\n"
405 " access=\"protected\"\n"
406 " >\n"
407 " </Field>\n"
408 " <Field\n"
409 " name=\"stateVariables\"\n"
410 " type=\"UInt32\"\n"
411 " category=\"data\"\n"
412 " cardinality=\"single\"\n"
413 " visibility=\"internal\"\n"
414 " access=\"protected\"\n"
415 " defaultValue=\"0\"\n"
416 " >\n"
417 " </Field>\n"
418 " <Field\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"
426 " >\n"
427 " </Field>\n"
428 " <Field\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"
435 " >\n"
436 " </Field>\n"
437 " <Field\n"
438 " name=\"GLId\"\n"
439 " type=\"GLenum\"\n"
440 " cardinality=\"single\"\n"
441 " visibility=\"internal\"\n"
442 " access=\"public\"\n"
443 " defaultValue=\"0\"\n"
444 " fieldFlags=\"FClusterLocal\"\n"
445 " >\n"
446 " The OpenGL texture id for this texture.\n"
447 " </Field>\n"
448 "</FieldContainer>\n",
452 /*------------------------------ get -----------------------------------*/
454 FieldContainerType &CgFXMaterialBase::getType(void)
456 return _type;
459 const FieldContainerType &CgFXMaterialBase::getType(void) const
461 return _type;
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
611 return &_mfTextures;
614 MFUnrecTextureObjChunkPtr *CgFXMaterialBase::editMFTextures (void)
616 editMField(TexturesFieldMask, _mfTextures);
618 return &_mfTextures;
620 TextureObjChunk * CgFXMaterialBase::getTextures(const UInt32 index) const
622 return _mfTextures[index];
625 SFGLenum *CgFXMaterialBase::editSFGLId(void)
627 editSField(GLIdFieldMask);
629 return &_sfGLId;
632 const SFGLenum *CgFXMaterialBase::getSFGLId(void) const
634 return &_sfGLId;
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 =
650 value.begin();
651 MFUnrecCgFXTechniquePtr::const_iterator elemEnd =
652 value.end ();
654 static_cast<CgFXMaterial *>(this)->clearTechniques();
656 while(elemIt != elemEnd)
658 this->pushToTechniques(*elemIt);
660 ++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);
678 if(iElemIdx != -1)
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 =
703 value.begin();
704 MFUnrecTextureObjChunkPtr::const_iterator elemEnd =
705 value.end ();
707 static_cast<CgFXMaterial *>(this)->clearTextures();
709 while(elemIt != elemEnd)
711 this->pushToTextures(*elemIt);
713 ++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);
731 if(iElemIdx != -1)
733 editMField(TexturesFieldMask, _mfTextures);
735 _mfTextures.erase(iElemIdx);
738 void CgFXMaterialBase::clearTextures(void)
740 editMField(TexturesFieldMask, _mfTextures);
743 _mfTextures.clear();
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();
799 return returnValue;
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);
928 return fc;
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);
944 return fc;
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);
960 return fc;
963 CgFXMaterial *CgFXMaterialBase::createEmptyLocal(BitVector bFlags)
965 CgFXMaterial *returnValue;
967 newPtr<CgFXMaterial>(returnValue, bFlags);
969 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
971 return returnValue;
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();
984 return returnValue;
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;
999 return returnValue;
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;
1013 return returnValue;
1016 FieldContainerTransitPtr CgFXMaterialBase::shallowCopy(void) const
1018 CgFXMaterial *tmpPtr;
1020 newPtr(tmpPtr,
1021 dynamic_cast<const CgFXMaterial *>(this),
1022 Thread::getCurrentLocalFlags());
1024 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
1026 FieldContainerTransitPtr returnValue(tmpPtr);
1028 return returnValue;
1034 /*------------------------- constructors ----------------------------------*/
1036 CgFXMaterialBase::CgFXMaterialBase(void) :
1037 Inherited(),
1038 _sfTreatTechniquesAsVariants(bool(false)),
1039 _sfEffectFile (),
1040 _sfParameterValueSource (UInt8(CgFXMaterial::DEFAULT)),
1041 _sfEffectString (),
1042 _mfCompilerOptions (),
1043 _sfVariables (this,
1044 VariablesFieldId,
1045 ShaderProgramVariables::ParentsFieldId),
1046 _sfSelectedTechnique (),
1047 _sfStateVariables (UInt32(0)),
1048 _mfTechniques (),
1049 _mfTextures (),
1050 _sfGLId (GLenum(0))
1054 CgFXMaterialBase::CgFXMaterialBase(const CgFXMaterialBase &source) :
1055 Inherited(source),
1056 _sfTreatTechniquesAsVariants(source._sfTreatTechniquesAsVariants),
1057 _sfEffectFile (source._sfEffectFile ),
1058 _sfParameterValueSource (source._sfParameterValueSource ),
1059 _sfEffectString (source._sfEffectString ),
1060 _mfCompilerOptions (source._mfCompilerOptions ),
1061 _sfVariables (this,
1062 VariablesFieldId,
1063 ShaderProgramVariables::ParentsFieldId),
1064 _sfSelectedTechnique (source._sfSelectedTechnique ),
1065 _sfStateVariables (source._sfStateVariables ),
1066 _mfTechniques (),
1067 _mfTextures (),
1068 _sfGLId (source._sfGLId )
1073 /*-------------------------- destructors ----------------------------------*/
1075 CgFXMaterialBase::~CgFXMaterialBase(void)
1079 /*-------------------------------------------------------------------------*/
1080 /* Child linking */
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);
1099 return true;
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!"
1110 << std::endl;
1112 return false;
1115 return false;
1119 return Inherited::unlinkChild(pChild, childFieldId);
1122 void CgFXMaterialBase::onCreate(const CgFXMaterial *source)
1124 Inherited::onCreate(source);
1126 if(source != NULL)
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);
1141 ++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);
1153 ++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)));
1166 return returnValue;
1169 EditFieldHandlePtr CgFXMaterialBase::editHandleTreatTechniquesAsVariants(void)
1171 SFBool::EditHandlePtr returnValue(
1172 new SFBool::EditHandle(
1173 &_sfTreatTechniquesAsVariants,
1174 this->getType().getFieldDesc(TreatTechniquesAsVariantsFieldId),
1175 this));
1178 editSField(TreatTechniquesAsVariantsFieldMask);
1180 return returnValue;
1183 GetFieldHandlePtr CgFXMaterialBase::getHandleEffectFile (void) const
1185 SFString::GetHandlePtr returnValue(
1186 new SFString::GetHandle(
1187 &_sfEffectFile,
1188 this->getType().getFieldDesc(EffectFileFieldId),
1189 const_cast<CgFXMaterialBase *>(this)));
1191 return returnValue;
1194 EditFieldHandlePtr CgFXMaterialBase::editHandleEffectFile (void)
1196 SFString::EditHandlePtr returnValue(
1197 new SFString::EditHandle(
1198 &_sfEffectFile,
1199 this->getType().getFieldDesc(EffectFileFieldId),
1200 this));
1203 editSField(EffectFileFieldMask);
1205 return returnValue;
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)));
1216 return returnValue;
1219 EditFieldHandlePtr CgFXMaterialBase::editHandleParameterValueSource(void)
1221 SFUInt8::EditHandlePtr returnValue(
1222 new SFUInt8::EditHandle(
1223 &_sfParameterValueSource,
1224 this->getType().getFieldDesc(ParameterValueSourceFieldId),
1225 this));
1228 editSField(ParameterValueSourceFieldMask);
1230 return returnValue;
1233 GetFieldHandlePtr CgFXMaterialBase::getHandleEffectString (void) const
1235 SFString::GetHandlePtr returnValue(
1236 new SFString::GetHandle(
1237 &_sfEffectString,
1238 this->getType().getFieldDesc(EffectStringFieldId),
1239 const_cast<CgFXMaterialBase *>(this)));
1241 return returnValue;
1244 EditFieldHandlePtr CgFXMaterialBase::editHandleEffectString (void)
1246 SFString::EditHandlePtr returnValue(
1247 new SFString::EditHandle(
1248 &_sfEffectString,
1249 this->getType().getFieldDesc(EffectStringFieldId),
1250 this));
1253 editSField(EffectStringFieldMask);
1255 return returnValue;
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)));
1266 return returnValue;
1269 EditFieldHandlePtr CgFXMaterialBase::editHandleCompilerOptions(void)
1271 MFString::EditHandlePtr returnValue(
1272 new MFString::EditHandle(
1273 &_mfCompilerOptions,
1274 this->getType().getFieldDesc(CompilerOptionsFieldId),
1275 this));
1278 editMField(CompilerOptionsFieldMask, _mfCompilerOptions);
1280 return returnValue;
1283 GetFieldHandlePtr CgFXMaterialBase::getHandleVariables (void) const
1285 SFUnrecChildShaderProgramVariablesPtr::GetHandlePtr returnValue(
1286 new SFUnrecChildShaderProgramVariablesPtr::GetHandle(
1287 &_sfVariables,
1288 this->getType().getFieldDesc(VariablesFieldId),
1289 const_cast<CgFXMaterialBase *>(this)));
1291 return returnValue;
1294 EditFieldHandlePtr CgFXMaterialBase::editHandleVariables (void)
1296 SFUnrecChildShaderProgramVariablesPtr::EditHandlePtr returnValue(
1297 new SFUnrecChildShaderProgramVariablesPtr::EditHandle(
1298 &_sfVariables,
1299 this->getType().getFieldDesc(VariablesFieldId),
1300 this));
1302 returnValue->setSetMethod(
1303 boost::bind(&CgFXMaterial::setVariables,
1304 static_cast<CgFXMaterial *>(this), _1));
1306 editSField(VariablesFieldMask);
1308 return returnValue;
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)));
1319 return returnValue;
1322 EditFieldHandlePtr CgFXMaterialBase::editHandleSelectedTechnique(void)
1324 SFString::EditHandlePtr returnValue(
1325 new SFString::EditHandle(
1326 &_sfSelectedTechnique,
1327 this->getType().getFieldDesc(SelectedTechniqueFieldId),
1328 this));
1331 editSField(SelectedTechniqueFieldMask);
1333 return returnValue;
1336 GetFieldHandlePtr CgFXMaterialBase::getHandleStateVariables (void) const
1338 SFUInt32::GetHandlePtr returnValue(
1339 new SFUInt32::GetHandle(
1340 &_sfStateVariables,
1341 this->getType().getFieldDesc(StateVariablesFieldId),
1342 const_cast<CgFXMaterialBase *>(this)));
1344 return returnValue;
1347 EditFieldHandlePtr CgFXMaterialBase::editHandleStateVariables (void)
1349 SFUInt32::EditHandlePtr returnValue(
1350 new SFUInt32::EditHandle(
1351 &_sfStateVariables,
1352 this->getType().getFieldDesc(StateVariablesFieldId),
1353 this));
1356 editSField(StateVariablesFieldMask);
1358 return returnValue;
1361 GetFieldHandlePtr CgFXMaterialBase::getHandleTechniques (void) const
1363 MFUnrecCgFXTechniquePtr::GetHandlePtr returnValue(
1364 new MFUnrecCgFXTechniquePtr::GetHandle(
1365 &_mfTechniques,
1366 this->getType().getFieldDesc(TechniquesFieldId),
1367 const_cast<CgFXMaterialBase *>(this)));
1369 return returnValue;
1372 EditFieldHandlePtr CgFXMaterialBase::editHandleTechniques (void)
1374 MFUnrecCgFXTechniquePtr::EditHandlePtr returnValue(
1375 new MFUnrecCgFXTechniquePtr::EditHandle(
1376 &_mfTechniques,
1377 this->getType().getFieldDesc(TechniquesFieldId),
1378 this));
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);
1395 return returnValue;
1398 GetFieldHandlePtr CgFXMaterialBase::getHandleTextures (void) const
1400 MFUnrecTextureObjChunkPtr::GetHandlePtr returnValue(
1401 new MFUnrecTextureObjChunkPtr::GetHandle(
1402 &_mfTextures,
1403 this->getType().getFieldDesc(TexturesFieldId),
1404 const_cast<CgFXMaterialBase *>(this)));
1406 return returnValue;
1409 EditFieldHandlePtr CgFXMaterialBase::editHandleTextures (void)
1411 MFUnrecTextureObjChunkPtr::EditHandlePtr returnValue(
1412 new MFUnrecTextureObjChunkPtr::EditHandle(
1413 &_mfTextures,
1414 this->getType().getFieldDesc(TexturesFieldId),
1415 this));
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);
1432 return returnValue;
1435 GetFieldHandlePtr CgFXMaterialBase::getHandleGLId (void) const
1437 SFGLenum::GetHandlePtr returnValue(
1438 new SFGLenum::GetHandle(
1439 &_sfGLId,
1440 this->getType().getFieldDesc(GLIdFieldId),
1441 const_cast<CgFXMaterialBase *>(this)));
1443 return returnValue;
1446 EditFieldHandlePtr CgFXMaterialBase::editHandleGLId (void)
1448 SFGLenum::EditHandlePtr returnValue(
1449 new SFGLenum::EditHandle(
1450 &_sfGLId,
1451 this->getType().getFieldDesc(GLIdFieldId),
1452 this));
1455 editSField(GLIdFieldMask);
1457 return returnValue;
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),
1471 whichField,
1472 oOffsets,
1473 syncMode,
1474 uiSyncInfo);
1476 #endif
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));
1489 return returnValue;
1491 #endif
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);
1507 #endif
1509 #ifdef OSG_MT_CPTR_ASPECT
1510 _mfCompilerOptions.terminateShare(Thread::getCurrentAspect(),
1511 oOffsets);
1512 #endif
1516 OSG_END_NAMESPACE