fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Shader / Base / OSGShaderProgramBase.cpp
blob9e8bf2893c95da7bb00cfae5df3f7cf58851afb1
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 ShaderProgram!
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"
64 #include "OSGGL.h" // ShaderType default header
65 #include "OSGChangedFunctorMFields.h" // DestroyedFunctors default header
67 #include "OSGShaderProgramVariables.h" // Variables Class
68 #include "OSGFieldContainer.h" // Parents Class
70 #include "OSGShaderProgramBase.h"
71 #include "OSGShaderProgram.h"
73 #include <boost/bind.hpp>
75 OSG_BEGIN_NAMESPACE
77 /***************************************************************************\
78 * Description *
79 \***************************************************************************/
81 /*! \class OSG::ShaderProgram
85 /***************************************************************************\
86 * Field Documentation *
87 \***************************************************************************/
89 /*! \var GLenum ShaderProgramBase::_sfShaderType
93 /*! \var std::string ShaderProgramBase::_sfProgram
97 /*! \var std::string ShaderProgramBase::_sfDefines
101 /*! \var UInt32 ShaderProgramBase::_sfGLId
105 /*! \var ShaderProgramVariables * ShaderProgramBase::_sfVariables
106 fragment program object
109 /*! \var std::string ShaderProgramBase::_mfFeedbackVaryings
113 /*! \var ShaderParameter ShaderProgramBase::_mfParameter
117 /*! \var ShaderAttribute ShaderProgramBase::_mfAttributes
121 /*! \var bool ShaderProgramBase::_sfCgFrontEnd
125 /*! \var bool ShaderProgramBase::_sfPointSize
126 Flag to set whether the shader can change the point size.
129 /*! \var FieldContainer * ShaderProgramBase::_mfParents
133 /*! \var ChangedFunctorCallback ShaderProgramBase::_mfDestroyedFunctors
138 /***************************************************************************\
139 * FieldType/FieldTrait Instantiation *
140 \***************************************************************************/
142 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
143 PointerType FieldTraits<ShaderProgram *, nsOSG>::_type(
144 "ShaderProgramPtr",
145 "FieldContainerPtr",
146 ShaderProgram::getClassType(),
147 nsOSG);
148 #endif
150 OSG_FIELDTRAITS_GETTYPE_NS(ShaderProgram *, nsOSG)
152 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
153 ShaderProgram *,
154 nsOSG)
156 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
157 ShaderProgram *,
158 nsOSG)
160 /***************************************************************************\
161 * Field Description *
162 \***************************************************************************/
164 void ShaderProgramBase::classDescInserter(TypeObject &oType)
166 FieldDescriptionBase *pDesc = NULL;
169 pDesc = new SFGLenum::Description(
170 SFGLenum::getClassType(),
171 "shaderType",
173 ShaderTypeFieldId, ShaderTypeFieldMask,
174 false,
175 (Field::SFDefaultFlags | Field::FStdAccess),
176 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleShaderType),
177 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleShaderType));
179 oType.addInitialDesc(pDesc);
181 pDesc = new SFString::Description(
182 SFString::getClassType(),
183 "program",
185 ProgramFieldId, ProgramFieldMask,
186 false,
187 (Field::SFDefaultFlags | Field::FStdAccess),
188 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleProgram),
189 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleProgram));
191 oType.addInitialDesc(pDesc);
193 pDesc = new SFString::Description(
194 SFString::getClassType(),
195 "defines",
197 DefinesFieldId, DefinesFieldMask,
198 false,
199 (Field::SFDefaultFlags | Field::FStdAccess),
200 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleDefines),
201 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleDefines));
203 oType.addInitialDesc(pDesc);
205 pDesc = new SFUInt32::Description(
206 SFUInt32::getClassType(),
207 "GLId",
209 GLIdFieldId, GLIdFieldMask,
210 true,
211 (Field::FClusterLocal),
212 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleGLId),
213 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleGLId));
215 oType.addInitialDesc(pDesc);
217 pDesc = new SFUnrecChildShaderProgramVariablesPtr::Description(
218 SFUnrecChildShaderProgramVariablesPtr::getClassType(),
219 "variables",
220 "fragment program object\n",
221 VariablesFieldId, VariablesFieldMask,
222 false,
223 (Field::SFDefaultFlags | Field::FStdAccess),
224 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleVariables),
225 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleVariables));
227 oType.addInitialDesc(pDesc);
229 pDesc = new MFString::Description(
230 MFString::getClassType(),
231 "feedbackVaryings",
233 FeedbackVaryingsFieldId, FeedbackVaryingsFieldMask,
234 false,
235 (Field::MFDefaultFlags | Field::FStdAccess),
236 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleFeedbackVaryings),
237 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleFeedbackVaryings));
239 oType.addInitialDesc(pDesc);
241 pDesc = new MFShaderParameter::Description(
242 MFShaderParameter::getClassType(),
243 "parameter",
245 ParameterFieldId, ParameterFieldMask,
246 false,
247 (Field::MFDefaultFlags | Field::FStdAccess),
248 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleParameter),
249 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleParameter));
251 oType.addInitialDesc(pDesc);
253 pDesc = new MFShaderAttribute::Description(
254 MFShaderAttribute::getClassType(),
255 "attributes",
257 AttributesFieldId, AttributesFieldMask,
258 false,
259 (Field::MFDefaultFlags | Field::FStdAccess),
260 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleAttributes),
261 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleAttributes));
263 oType.addInitialDesc(pDesc);
265 pDesc = new SFBool::Description(
266 SFBool::getClassType(),
267 "cgFrontEnd",
269 CgFrontEndFieldId, CgFrontEndFieldMask,
270 false,
271 (Field::SFDefaultFlags | Field::FStdAccess),
272 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandleCgFrontEnd),
273 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandleCgFrontEnd));
275 oType.addInitialDesc(pDesc);
277 pDesc = new SFBool::Description(
278 SFBool::getClassType(),
279 "pointSize",
280 "Flag to set whether the shader can change the point size.\n",
281 PointSizeFieldId, PointSizeFieldMask,
282 false,
283 (Field::SFDefaultFlags | Field::FStdAccess),
284 static_cast<FieldEditMethodSig>(&ShaderProgram::editHandlePointSize),
285 static_cast<FieldGetMethodSig >(&ShaderProgram::getHandlePointSize));
287 oType.addInitialDesc(pDesc);
289 pDesc = new MFParentFieldContainerPtr::Description(
290 MFParentFieldContainerPtr::getClassType(),
291 "parents",
293 ParentsFieldId, ParentsFieldMask,
294 true,
295 (Field::FClusterLocal),
296 static_cast <FieldEditMethodSig>(&ShaderProgram::invalidEditField),
297 static_cast <FieldGetMethodSig >(&ShaderProgram::invalidGetField));
299 oType.addInitialDesc(pDesc);
301 pDesc = new MFChangedFunctorCallback::Description(
302 MFChangedFunctorCallback::getClassType(),
303 "destroyedFunctors",
305 DestroyedFunctorsFieldId, DestroyedFunctorsFieldMask,
306 true,
307 (Field::FClusterLocal),
308 static_cast <FieldEditMethodSig>(&ShaderProgram::invalidEditField),
309 static_cast <FieldGetMethodSig >(&ShaderProgram::invalidGetField));
311 oType.addInitialDesc(pDesc);
315 ShaderProgramBase::TypeObject ShaderProgramBase::_type(
316 ShaderProgramBase::getClassname(),
317 Inherited::getClassname(),
318 "NULL",
319 nsOSG, //Namespace
320 reinterpret_cast<PrototypeCreateF>(&ShaderProgramBase::createEmptyLocal),
321 reinterpret_cast<InitContainerF>(&ShaderProgram::initMethod),
322 reinterpret_cast<ExitContainerF>(&ShaderProgram::exitMethod),
323 reinterpret_cast<InitalInsertDescFunc>(
324 reinterpret_cast<void *>(&ShaderProgram::classDescInserter)),
325 false,
327 "<?xml version=\"1.0\"?>\n"
328 "\n"
329 "<FieldContainer\n"
330 " name=\"ShaderProgram\"\n"
331 " parent=\"FieldContainer\"\n"
332 " library=\"System\"\n"
333 " structure=\"concrete\"\n"
334 " pointerfieldtypes=\"both\"\n"
335 " systemcomponent=\"true\"\n"
336 " parentsystemcomponent=\"true\"\n"
337 " decoratable=\"false\"\n"
338 " useLocalIncludes=\"false\"\n"
339 " docGroupBase=\"GrpSystemShader\"\n"
340 " >\n"
341 "\n"
342 " <Field\n"
343 " name=\"shaderType\"\n"
344 " type=\"GLenum\"\n"
345 " cardinality=\"single\"\n"
346 " visibility=\"external\"\n"
347 " defaultValue=\"GL_NONE\"\n"
348 " defaultHeader=\"&quot;OSGGL.h&quot;\"\n"
349 " access=\"public\"\n"
350 " >\n"
351 " </Field>\n"
352 "\n"
353 " <Field\n"
354 " name=\"program\"\n"
355 " type=\"std::string\"\n"
356 " cardinality=\"single\"\n"
357 " visibility=\"external\"\n"
358 " access=\"public\"\n"
359 " >\n"
360 " </Field>\n"
361 "\n"
362 " <Field\n"
363 " name=\"defines\"\n"
364 " type=\"std::string\"\n"
365 " cardinality=\"single\"\n"
366 " visibility=\"external\"\n"
367 " access=\"public\"\n"
368 " >\n"
369 " </Field>\n"
370 "\n"
371 " <Field\n"
372 " name=\"GLId\"\n"
373 " type=\"UInt32\"\n"
374 " cardinality=\"single\"\n"
375 " visibility=\"internal\"\n"
376 " access=\"public\"\n"
377 " defaultValue=\"0\"\n"
378 " fieldFlags=\"FClusterLocal\"\n"
379 " >\n"
380 " </Field>\n"
381 "\n"
382 " <Field\n"
383 " name=\"variables\"\n"
384 " type=\"ShaderProgramVariables\"\n"
385 " cardinality=\"single\"\n"
386 " visibility=\"external\"\n"
387 " access=\"public\"\n"
388 " category=\"childpointer\"\n"
389 " childParentType=\"FieldContainer\"\n"
390 " linkParentField=\"Parents\"\n"
391 " >\n"
392 " fragment program object\n"
393 " </Field>\n"
394 "\n"
395 " <Field\n"
396 " name=\"feedbackVaryings\"\n"
397 " type=\"std::string\"\n"
398 " cardinality=\"multi\"\n"
399 " visibility=\"external\"\n"
400 " access=\"public\"\n"
401 " >\n"
402 " </Field>\n"
403 " \n"
404 " <Field\n"
405 " name=\"parameter\"\n"
406 " type=\"ShaderParameter\"\n"
407 " cardinality=\"multi\"\n"
408 " visibility=\"external\"\n"
409 " access=\"public\"\n"
410 " >\n"
411 " </Field>\n"
412 "\n"
413 " <Field\n"
414 " name=\"attributes\"\n"
415 " type=\"ShaderAttribute\"\n"
416 " cardinality=\"multi\"\n"
417 " visibility=\"external\"\n"
418 " access=\"public\"\n"
419 " >\n"
420 " </Field>\n"
421 "\n"
422 " <Field\n"
423 " name=\"cgFrontEnd\"\n"
424 " type=\"bool\"\n"
425 " cardinality=\"single\"\n"
426 " visibility=\"external\"\n"
427 " defaultValue=\"false\"\n"
428 " access=\"public\"\n"
429 " >\n"
430 " </Field>\n"
431 "\n"
432 " <Field\n"
433 " name=\"pointSize\"\n"
434 " type=\"bool\"\n"
435 " cardinality=\"single\"\n"
436 " visibility=\"external\"\n"
437 " defaultValue=\"false\"\n"
438 " access=\"public\"\n"
439 " >\n"
440 " Flag to set whether the shader can change the point size.\n"
441 " </Field>\n"
442 "\n"
443 " <Field\n"
444 " name=\"parents\"\n"
445 " type=\"FieldContainer\"\n"
446 " cardinality=\"multi\"\n"
447 " visibility=\"internal\"\n"
448 " access=\"none\"\n"
449 " category=\"parentpointer\"\n"
450 " fieldFlags=\"FClusterLocal\"\n"
451 " >\n"
452 " </Field>\n"
453 "\n"
454 " <Field\n"
455 " name=\"destroyedFunctors\"\n"
456 " type=\"ChangedFunctorCallback\"\n"
457 " cardinality=\"multi\"\n"
458 " visibility=\"internal\"\n"
459 " access=\"none\"\n"
460 " defaultHeader=\"OSGChangedFunctorMFields.h\"\n"
461 " fieldFlags=\"FClusterLocal\"\n"
462 " >\n"
463 " </Field>\n"
464 "\n"
465 "</FieldContainer>\n",
469 /*------------------------------ get -----------------------------------*/
471 FieldContainerType &ShaderProgramBase::getType(void)
473 return _type;
476 const FieldContainerType &ShaderProgramBase::getType(void) const
478 return _type;
481 UInt32 ShaderProgramBase::getContainerSize(void) const
483 return sizeof(ShaderProgram);
486 /*------------------------- decorator get ------------------------------*/
489 SFGLenum *ShaderProgramBase::editSFShaderType(void)
491 editSField(ShaderTypeFieldMask);
493 return &_sfShaderType;
496 const SFGLenum *ShaderProgramBase::getSFShaderType(void) const
498 return &_sfShaderType;
502 SFString *ShaderProgramBase::editSFProgram(void)
504 editSField(ProgramFieldMask);
506 return &_sfProgram;
509 const SFString *ShaderProgramBase::getSFProgram(void) const
511 return &_sfProgram;
515 SFString *ShaderProgramBase::editSFDefines(void)
517 editSField(DefinesFieldMask);
519 return &_sfDefines;
522 const SFString *ShaderProgramBase::getSFDefines(void) const
524 return &_sfDefines;
528 SFUInt32 *ShaderProgramBase::editSFGLId(void)
530 editSField(GLIdFieldMask);
532 return &_sfGLId;
535 const SFUInt32 *ShaderProgramBase::getSFGLId(void) const
537 return &_sfGLId;
541 //! Get the ShaderProgram::_sfVariables field.
542 const SFUnrecChildShaderProgramVariablesPtr *ShaderProgramBase::getSFVariables(void) const
544 return &_sfVariables;
547 SFUnrecChildShaderProgramVariablesPtr *ShaderProgramBase::editSFVariables (void)
549 editSField(VariablesFieldMask);
551 return &_sfVariables;
554 //! Get the value of the ShaderProgram::_sfVariables field.
555 ShaderProgramVariables * ShaderProgramBase::getVariables(void) const
557 return _sfVariables.getValue();
560 //! Set the value of the ShaderProgram::_sfVariables field.
561 void ShaderProgramBase::setVariables(ShaderProgramVariables * const value)
563 editSField(VariablesFieldMask);
565 _sfVariables.setValue(value);
569 MFString *ShaderProgramBase::editMFFeedbackVaryings(void)
571 editMField(FeedbackVaryingsFieldMask, _mfFeedbackVaryings);
573 return &_mfFeedbackVaryings;
576 const MFString *ShaderProgramBase::getMFFeedbackVaryings(void) const
578 return &_mfFeedbackVaryings;
582 MFShaderParameter *ShaderProgramBase::editMFParameter(void)
584 editMField(ParameterFieldMask, _mfParameter);
586 return &_mfParameter;
589 const MFShaderParameter *ShaderProgramBase::getMFParameter(void) const
591 return &_mfParameter;
595 MFShaderAttribute *ShaderProgramBase::editMFAttributes(void)
597 editMField(AttributesFieldMask, _mfAttributes);
599 return &_mfAttributes;
602 const MFShaderAttribute *ShaderProgramBase::getMFAttributes(void) const
604 return &_mfAttributes;
608 SFBool *ShaderProgramBase::editSFCgFrontEnd(void)
610 editSField(CgFrontEndFieldMask);
612 return &_sfCgFrontEnd;
615 const SFBool *ShaderProgramBase::getSFCgFrontEnd(void) const
617 return &_sfCgFrontEnd;
621 SFBool *ShaderProgramBase::editSFPointSize(void)
623 editSField(PointSizeFieldMask);
625 return &_sfPointSize;
628 const SFBool *ShaderProgramBase::getSFPointSize(void) const
630 return &_sfPointSize;
640 /*------------------------------ access -----------------------------------*/
642 SizeT ShaderProgramBase::getBinSize(ConstFieldMaskArg whichField)
644 SizeT returnValue = Inherited::getBinSize(whichField);
646 if(FieldBits::NoField != (ShaderTypeFieldMask & whichField))
648 returnValue += _sfShaderType.getBinSize();
650 if(FieldBits::NoField != (ProgramFieldMask & whichField))
652 returnValue += _sfProgram.getBinSize();
654 if(FieldBits::NoField != (DefinesFieldMask & whichField))
656 returnValue += _sfDefines.getBinSize();
658 if(FieldBits::NoField != (GLIdFieldMask & whichField))
660 returnValue += _sfGLId.getBinSize();
662 if(FieldBits::NoField != (VariablesFieldMask & whichField))
664 returnValue += _sfVariables.getBinSize();
666 if(FieldBits::NoField != (FeedbackVaryingsFieldMask & whichField))
668 returnValue += _mfFeedbackVaryings.getBinSize();
670 if(FieldBits::NoField != (ParameterFieldMask & whichField))
672 returnValue += _mfParameter.getBinSize();
674 if(FieldBits::NoField != (AttributesFieldMask & whichField))
676 returnValue += _mfAttributes.getBinSize();
678 if(FieldBits::NoField != (CgFrontEndFieldMask & whichField))
680 returnValue += _sfCgFrontEnd.getBinSize();
682 if(FieldBits::NoField != (PointSizeFieldMask & whichField))
684 returnValue += _sfPointSize.getBinSize();
686 if(FieldBits::NoField != (ParentsFieldMask & whichField))
688 returnValue += _mfParents.getBinSize();
690 if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
692 returnValue += _mfDestroyedFunctors.getBinSize();
695 return returnValue;
698 void ShaderProgramBase::copyToBin(BinaryDataHandler &pMem,
699 ConstFieldMaskArg whichField)
701 Inherited::copyToBin(pMem, whichField);
703 if(FieldBits::NoField != (ShaderTypeFieldMask & whichField))
705 _sfShaderType.copyToBin(pMem);
707 if(FieldBits::NoField != (ProgramFieldMask & whichField))
709 _sfProgram.copyToBin(pMem);
711 if(FieldBits::NoField != (DefinesFieldMask & whichField))
713 _sfDefines.copyToBin(pMem);
715 if(FieldBits::NoField != (GLIdFieldMask & whichField))
717 _sfGLId.copyToBin(pMem);
719 if(FieldBits::NoField != (VariablesFieldMask & whichField))
721 _sfVariables.copyToBin(pMem);
723 if(FieldBits::NoField != (FeedbackVaryingsFieldMask & whichField))
725 _mfFeedbackVaryings.copyToBin(pMem);
727 if(FieldBits::NoField != (ParameterFieldMask & whichField))
729 _mfParameter.copyToBin(pMem);
731 if(FieldBits::NoField != (AttributesFieldMask & whichField))
733 _mfAttributes.copyToBin(pMem);
735 if(FieldBits::NoField != (CgFrontEndFieldMask & whichField))
737 _sfCgFrontEnd.copyToBin(pMem);
739 if(FieldBits::NoField != (PointSizeFieldMask & whichField))
741 _sfPointSize.copyToBin(pMem);
743 if(FieldBits::NoField != (ParentsFieldMask & whichField))
745 _mfParents.copyToBin(pMem);
747 if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
749 _mfDestroyedFunctors.copyToBin(pMem);
753 void ShaderProgramBase::copyFromBin(BinaryDataHandler &pMem,
754 ConstFieldMaskArg whichField)
756 Inherited::copyFromBin(pMem, whichField);
758 if(FieldBits::NoField != (ShaderTypeFieldMask & whichField))
760 editSField(ShaderTypeFieldMask);
761 _sfShaderType.copyFromBin(pMem);
763 if(FieldBits::NoField != (ProgramFieldMask & whichField))
765 editSField(ProgramFieldMask);
766 _sfProgram.copyFromBin(pMem);
768 if(FieldBits::NoField != (DefinesFieldMask & whichField))
770 editSField(DefinesFieldMask);
771 _sfDefines.copyFromBin(pMem);
773 if(FieldBits::NoField != (GLIdFieldMask & whichField))
775 editSField(GLIdFieldMask);
776 _sfGLId.copyFromBin(pMem);
778 if(FieldBits::NoField != (VariablesFieldMask & whichField))
780 editSField(VariablesFieldMask);
781 _sfVariables.copyFromBin(pMem);
783 if(FieldBits::NoField != (FeedbackVaryingsFieldMask & whichField))
785 editMField(FeedbackVaryingsFieldMask, _mfFeedbackVaryings);
786 _mfFeedbackVaryings.copyFromBin(pMem);
788 if(FieldBits::NoField != (ParameterFieldMask & whichField))
790 editMField(ParameterFieldMask, _mfParameter);
791 _mfParameter.copyFromBin(pMem);
793 if(FieldBits::NoField != (AttributesFieldMask & whichField))
795 editMField(AttributesFieldMask, _mfAttributes);
796 _mfAttributes.copyFromBin(pMem);
798 if(FieldBits::NoField != (CgFrontEndFieldMask & whichField))
800 editSField(CgFrontEndFieldMask);
801 _sfCgFrontEnd.copyFromBin(pMem);
803 if(FieldBits::NoField != (PointSizeFieldMask & whichField))
805 editSField(PointSizeFieldMask);
806 _sfPointSize.copyFromBin(pMem);
808 if(FieldBits::NoField != (ParentsFieldMask & whichField))
810 editMField(ParentsFieldMask, _mfParents);
811 _mfParents.copyFromBin(pMem);
813 if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
815 editMField(DestroyedFunctorsFieldMask, _mfDestroyedFunctors);
816 _mfDestroyedFunctors.copyFromBin(pMem);
820 //! create a new instance of the class
821 ShaderProgramTransitPtr ShaderProgramBase::createLocal(BitVector bFlags)
823 ShaderProgramTransitPtr fc;
825 if(getClassType().getPrototype() != NULL)
827 FieldContainerTransitPtr tmpPtr =
828 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
830 fc = dynamic_pointer_cast<ShaderProgram>(tmpPtr);
833 return fc;
836 //! create a new instance of the class, copy the container flags
837 ShaderProgramTransitPtr ShaderProgramBase::createDependent(BitVector bFlags)
839 ShaderProgramTransitPtr fc;
841 if(getClassType().getPrototype() != NULL)
843 FieldContainerTransitPtr tmpPtr =
844 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
846 fc = dynamic_pointer_cast<ShaderProgram>(tmpPtr);
849 return fc;
852 //! create a new instance of the class
853 ShaderProgramTransitPtr ShaderProgramBase::create(void)
855 ShaderProgramTransitPtr fc;
857 if(getClassType().getPrototype() != NULL)
859 FieldContainerTransitPtr tmpPtr =
860 getClassType().getPrototype()-> shallowCopy();
862 fc = dynamic_pointer_cast<ShaderProgram>(tmpPtr);
865 return fc;
868 ShaderProgram *ShaderProgramBase::createEmptyLocal(BitVector bFlags)
870 ShaderProgram *returnValue;
872 newPtr<ShaderProgram>(returnValue, bFlags);
874 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
876 return returnValue;
879 //! create an empty new instance of the class, do not copy the prototype
880 ShaderProgram *ShaderProgramBase::createEmpty(void)
882 ShaderProgram *returnValue;
884 newPtr<ShaderProgram>(returnValue, Thread::getCurrentLocalFlags());
886 returnValue->_pFieldFlags->_bNamespaceMask &=
887 ~Thread::getCurrentLocalFlags();
889 return returnValue;
893 FieldContainerTransitPtr ShaderProgramBase::shallowCopyLocal(
894 BitVector bFlags) const
896 ShaderProgram *tmpPtr;
898 newPtr(tmpPtr, dynamic_cast<const ShaderProgram *>(this), bFlags);
900 FieldContainerTransitPtr returnValue(tmpPtr);
902 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
904 return returnValue;
907 FieldContainerTransitPtr ShaderProgramBase::shallowCopyDependent(
908 BitVector bFlags) const
910 ShaderProgram *tmpPtr;
912 newPtr(tmpPtr, dynamic_cast<const ShaderProgram *>(this), ~bFlags);
914 FieldContainerTransitPtr returnValue(tmpPtr);
916 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
918 return returnValue;
921 FieldContainerTransitPtr ShaderProgramBase::shallowCopy(void) const
923 ShaderProgram *tmpPtr;
925 newPtr(tmpPtr,
926 dynamic_cast<const ShaderProgram *>(this),
927 Thread::getCurrentLocalFlags());
929 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
931 FieldContainerTransitPtr returnValue(tmpPtr);
933 return returnValue;
939 /*------------------------- constructors ----------------------------------*/
941 ShaderProgramBase::ShaderProgramBase(void) :
942 Inherited(),
943 _sfShaderType (GLenum(GL_NONE)),
944 _sfProgram (),
945 _sfDefines (),
946 _sfGLId (UInt32(0)),
947 _sfVariables (this,
948 VariablesFieldId,
949 ShaderProgramVariables::ParentsFieldId),
950 _mfFeedbackVaryings (),
951 _mfParameter (),
952 _mfAttributes (),
953 _sfCgFrontEnd (bool(false)),
954 _sfPointSize (bool(false)),
955 _mfParents (),
956 _mfDestroyedFunctors ()
960 ShaderProgramBase::ShaderProgramBase(const ShaderProgramBase &source) :
961 Inherited(source),
962 _sfShaderType (source._sfShaderType ),
963 _sfProgram (source._sfProgram ),
964 _sfDefines (source._sfDefines ),
965 _sfGLId (source._sfGLId ),
966 _sfVariables (this,
967 VariablesFieldId,
968 ShaderProgramVariables::ParentsFieldId),
969 _mfFeedbackVaryings (source._mfFeedbackVaryings ),
970 _mfParameter (source._mfParameter ),
971 _mfAttributes (source._mfAttributes ),
972 _sfCgFrontEnd (source._sfCgFrontEnd ),
973 _sfPointSize (source._sfPointSize ),
974 _mfParents (),
975 _mfDestroyedFunctors (source._mfDestroyedFunctors )
980 /*-------------------------- destructors ----------------------------------*/
982 ShaderProgramBase::~ShaderProgramBase(void)
985 /*-------------------------------------------------------------------------*/
986 /* Parent linking */
988 bool ShaderProgramBase::linkParent(
989 FieldContainer * const pParent,
990 UInt16 const childFieldId,
991 UInt16 const parentFieldId )
993 if(parentFieldId == ParentsFieldId)
995 FieldContainer * pTypedParent =
996 dynamic_cast< FieldContainer * >(pParent);
998 if(pTypedParent != NULL)
1000 editMField(ParentsFieldMask, _mfParents);
1002 _mfParents.push_back(pTypedParent, childFieldId);
1004 return true;
1007 return false;
1010 return Inherited::linkParent(pParent, childFieldId, parentFieldId);
1013 bool ShaderProgramBase::unlinkParent(
1014 FieldContainer * const pParent,
1015 UInt16 const parentFieldId)
1017 if(parentFieldId == ParentsFieldId)
1019 FieldContainer * pTypedParent =
1020 dynamic_cast< FieldContainer * >(pParent);
1022 if(pTypedParent != NULL)
1024 Int32 iParentIdx = _mfParents.findIndex(pTypedParent);
1026 if(iParentIdx != -1)
1028 editMField(ParentsFieldMask, _mfParents);
1030 _mfParents.erase(iParentIdx);
1032 return true;
1035 SWARNING << "Child ([" << this
1036 << "] id [" << this->getId()
1037 << "] type [" << this->getType().getCName()
1038 << "] parentFieldId [" << parentFieldId
1039 << "]) - Parent ([" << pParent
1040 << "] id [" << pParent->getId()
1041 << "] type [" << pParent->getType().getCName()
1042 << "]): link inconsistent!"
1043 << std::endl;
1045 return false;
1048 return false;
1051 return Inherited::unlinkParent(pParent, parentFieldId);
1055 /*-------------------------------------------------------------------------*/
1056 /* Child linking */
1058 bool ShaderProgramBase::unlinkChild(
1059 FieldContainer * const pChild,
1060 UInt16 const childFieldId)
1062 if(childFieldId == VariablesFieldId)
1064 ShaderProgramVariables * pTypedChild =
1065 dynamic_cast<ShaderProgramVariables *>(pChild);
1067 if(pTypedChild != NULL)
1069 if(_sfVariables.getValue() == pTypedChild)
1071 editSField(VariablesFieldMask);
1073 _sfVariables.setValue(NULL);
1075 return true;
1078 SWARNING << "Parent ([" << this
1079 << "] id [" << this->getId()
1080 << "] type [" << this->getType().getCName()
1081 << "] childFieldId [" << childFieldId
1082 << "]) - Child ([" << pChild
1083 << "] id [" << pChild->getId()
1084 << "] type [" << pChild->getType().getCName()
1085 << "]): link inconsistent!"
1086 << std::endl;
1088 return false;
1091 return false;
1095 return Inherited::unlinkChild(pChild, childFieldId);
1098 void ShaderProgramBase::onCreate(const ShaderProgram *source)
1100 Inherited::onCreate(source);
1102 if(source != NULL)
1104 ShaderProgram *pThis = static_cast<ShaderProgram *>(this);
1106 pThis->setVariables(source->getVariables());
1110 GetFieldHandlePtr ShaderProgramBase::getHandleShaderType (void) const
1112 SFGLenum::GetHandlePtr returnValue(
1113 new SFGLenum::GetHandle(
1114 &_sfShaderType,
1115 this->getType().getFieldDesc(ShaderTypeFieldId),
1116 const_cast<ShaderProgramBase *>(this)));
1118 return returnValue;
1121 EditFieldHandlePtr ShaderProgramBase::editHandleShaderType (void)
1123 SFGLenum::EditHandlePtr returnValue(
1124 new SFGLenum::EditHandle(
1125 &_sfShaderType,
1126 this->getType().getFieldDesc(ShaderTypeFieldId),
1127 this));
1130 editSField(ShaderTypeFieldMask);
1132 return returnValue;
1135 GetFieldHandlePtr ShaderProgramBase::getHandleProgram (void) const
1137 SFString::GetHandlePtr returnValue(
1138 new SFString::GetHandle(
1139 &_sfProgram,
1140 this->getType().getFieldDesc(ProgramFieldId),
1141 const_cast<ShaderProgramBase *>(this)));
1143 return returnValue;
1146 EditFieldHandlePtr ShaderProgramBase::editHandleProgram (void)
1148 SFString::EditHandlePtr returnValue(
1149 new SFString::EditHandle(
1150 &_sfProgram,
1151 this->getType().getFieldDesc(ProgramFieldId),
1152 this));
1155 editSField(ProgramFieldMask);
1157 return returnValue;
1160 GetFieldHandlePtr ShaderProgramBase::getHandleDefines (void) const
1162 SFString::GetHandlePtr returnValue(
1163 new SFString::GetHandle(
1164 &_sfDefines,
1165 this->getType().getFieldDesc(DefinesFieldId),
1166 const_cast<ShaderProgramBase *>(this)));
1168 return returnValue;
1171 EditFieldHandlePtr ShaderProgramBase::editHandleDefines (void)
1173 SFString::EditHandlePtr returnValue(
1174 new SFString::EditHandle(
1175 &_sfDefines,
1176 this->getType().getFieldDesc(DefinesFieldId),
1177 this));
1180 editSField(DefinesFieldMask);
1182 return returnValue;
1185 GetFieldHandlePtr ShaderProgramBase::getHandleGLId (void) const
1187 SFUInt32::GetHandlePtr returnValue(
1188 new SFUInt32::GetHandle(
1189 &_sfGLId,
1190 this->getType().getFieldDesc(GLIdFieldId),
1191 const_cast<ShaderProgramBase *>(this)));
1193 return returnValue;
1196 EditFieldHandlePtr ShaderProgramBase::editHandleGLId (void)
1198 SFUInt32::EditHandlePtr returnValue(
1199 new SFUInt32::EditHandle(
1200 &_sfGLId,
1201 this->getType().getFieldDesc(GLIdFieldId),
1202 this));
1205 editSField(GLIdFieldMask);
1207 return returnValue;
1210 GetFieldHandlePtr ShaderProgramBase::getHandleVariables (void) const
1212 SFUnrecChildShaderProgramVariablesPtr::GetHandlePtr returnValue(
1213 new SFUnrecChildShaderProgramVariablesPtr::GetHandle(
1214 &_sfVariables,
1215 this->getType().getFieldDesc(VariablesFieldId),
1216 const_cast<ShaderProgramBase *>(this)));
1218 return returnValue;
1221 EditFieldHandlePtr ShaderProgramBase::editHandleVariables (void)
1223 SFUnrecChildShaderProgramVariablesPtr::EditHandlePtr returnValue(
1224 new SFUnrecChildShaderProgramVariablesPtr::EditHandle(
1225 &_sfVariables,
1226 this->getType().getFieldDesc(VariablesFieldId),
1227 this));
1229 returnValue->setSetMethod(
1230 boost::bind(&ShaderProgram::setVariables,
1231 static_cast<ShaderProgram *>(this), _1));
1233 editSField(VariablesFieldMask);
1235 return returnValue;
1238 GetFieldHandlePtr ShaderProgramBase::getHandleFeedbackVaryings (void) const
1240 MFString::GetHandlePtr returnValue(
1241 new MFString::GetHandle(
1242 &_mfFeedbackVaryings,
1243 this->getType().getFieldDesc(FeedbackVaryingsFieldId),
1244 const_cast<ShaderProgramBase *>(this)));
1246 return returnValue;
1249 EditFieldHandlePtr ShaderProgramBase::editHandleFeedbackVaryings(void)
1251 MFString::EditHandlePtr returnValue(
1252 new MFString::EditHandle(
1253 &_mfFeedbackVaryings,
1254 this->getType().getFieldDesc(FeedbackVaryingsFieldId),
1255 this));
1258 editMField(FeedbackVaryingsFieldMask, _mfFeedbackVaryings);
1260 return returnValue;
1263 GetFieldHandlePtr ShaderProgramBase::getHandleParameter (void) const
1265 MFShaderParameter::GetHandlePtr returnValue(
1266 new MFShaderParameter::GetHandle(
1267 &_mfParameter,
1268 this->getType().getFieldDesc(ParameterFieldId),
1269 const_cast<ShaderProgramBase *>(this)));
1271 return returnValue;
1274 EditFieldHandlePtr ShaderProgramBase::editHandleParameter (void)
1276 MFShaderParameter::EditHandlePtr returnValue(
1277 new MFShaderParameter::EditHandle(
1278 &_mfParameter,
1279 this->getType().getFieldDesc(ParameterFieldId),
1280 this));
1283 editMField(ParameterFieldMask, _mfParameter);
1285 return returnValue;
1288 GetFieldHandlePtr ShaderProgramBase::getHandleAttributes (void) const
1290 MFShaderAttribute::GetHandlePtr returnValue(
1291 new MFShaderAttribute::GetHandle(
1292 &_mfAttributes,
1293 this->getType().getFieldDesc(AttributesFieldId),
1294 const_cast<ShaderProgramBase *>(this)));
1296 return returnValue;
1299 EditFieldHandlePtr ShaderProgramBase::editHandleAttributes (void)
1301 MFShaderAttribute::EditHandlePtr returnValue(
1302 new MFShaderAttribute::EditHandle(
1303 &_mfAttributes,
1304 this->getType().getFieldDesc(AttributesFieldId),
1305 this));
1308 editMField(AttributesFieldMask, _mfAttributes);
1310 return returnValue;
1313 GetFieldHandlePtr ShaderProgramBase::getHandleCgFrontEnd (void) const
1315 SFBool::GetHandlePtr returnValue(
1316 new SFBool::GetHandle(
1317 &_sfCgFrontEnd,
1318 this->getType().getFieldDesc(CgFrontEndFieldId),
1319 const_cast<ShaderProgramBase *>(this)));
1321 return returnValue;
1324 EditFieldHandlePtr ShaderProgramBase::editHandleCgFrontEnd (void)
1326 SFBool::EditHandlePtr returnValue(
1327 new SFBool::EditHandle(
1328 &_sfCgFrontEnd,
1329 this->getType().getFieldDesc(CgFrontEndFieldId),
1330 this));
1333 editSField(CgFrontEndFieldMask);
1335 return returnValue;
1338 GetFieldHandlePtr ShaderProgramBase::getHandlePointSize (void) const
1340 SFBool::GetHandlePtr returnValue(
1341 new SFBool::GetHandle(
1342 &_sfPointSize,
1343 this->getType().getFieldDesc(PointSizeFieldId),
1344 const_cast<ShaderProgramBase *>(this)));
1346 return returnValue;
1349 EditFieldHandlePtr ShaderProgramBase::editHandlePointSize (void)
1351 SFBool::EditHandlePtr returnValue(
1352 new SFBool::EditHandle(
1353 &_sfPointSize,
1354 this->getType().getFieldDesc(PointSizeFieldId),
1355 this));
1358 editSField(PointSizeFieldMask);
1360 return returnValue;
1363 GetFieldHandlePtr ShaderProgramBase::getHandleParents (void) const
1365 MFParentFieldContainerPtr::GetHandlePtr returnValue;
1367 return returnValue;
1370 EditFieldHandlePtr ShaderProgramBase::editHandleParents (void)
1372 EditFieldHandlePtr returnValue;
1374 return returnValue;
1377 GetFieldHandlePtr ShaderProgramBase::getHandleDestroyedFunctors (void) const
1379 MFChangedFunctorCallback::GetHandlePtr returnValue;
1381 return returnValue;
1384 EditFieldHandlePtr ShaderProgramBase::editHandleDestroyedFunctors(void)
1386 EditFieldHandlePtr returnValue;
1388 return returnValue;
1392 #ifdef OSG_MT_CPTR_ASPECT
1393 void ShaderProgramBase::execSyncV( FieldContainer &oFrom,
1394 ConstFieldMaskArg whichField,
1395 AspectOffsetStore &oOffsets,
1396 ConstFieldMaskArg syncMode,
1397 const UInt32 uiSyncInfo)
1399 ShaderProgram *pThis = static_cast<ShaderProgram *>(this);
1401 pThis->execSync(static_cast<ShaderProgram *>(&oFrom),
1402 whichField,
1403 oOffsets,
1404 syncMode,
1405 uiSyncInfo);
1407 #endif
1410 #ifdef OSG_MT_CPTR_ASPECT
1411 FieldContainer *ShaderProgramBase::createAspectCopy(
1412 const FieldContainer *pRefAspect) const
1414 ShaderProgram *returnValue;
1416 newAspectCopy(returnValue,
1417 dynamic_cast<const ShaderProgram *>(pRefAspect),
1418 dynamic_cast<const ShaderProgram *>(this));
1420 return returnValue;
1422 #endif
1424 void ShaderProgramBase::resolveLinks(void)
1426 Inherited::resolveLinks();
1428 static_cast<ShaderProgram *>(this)->setVariables(NULL);
1430 #ifdef OSG_MT_CPTR_ASPECT
1431 AspectOffsetStore oOffsets;
1433 _pAspectStore->fillOffsetArray(oOffsets, this);
1434 #endif
1436 #ifdef OSG_MT_CPTR_ASPECT
1437 _mfFeedbackVaryings.terminateShare(Thread::getCurrentAspect(),
1438 oOffsets);
1439 #endif
1440 #ifdef OSG_MT_CPTR_ASPECT
1441 _mfParameter.terminateShare(Thread::getCurrentAspect(),
1442 oOffsets);
1443 #endif
1444 #ifdef OSG_MT_CPTR_ASPECT
1445 _mfAttributes.terminateShare(Thread::getCurrentAspect(),
1446 oOffsets);
1447 #endif
1448 #ifdef OSG_MT_CPTR_ASPECT
1449 _mfDestroyedFunctors.terminateShare(Thread::getCurrentAspect(),
1450 oOffsets);
1451 #endif
1455 OSG_END_NAMESPACE