fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Base / OSGUniformBufferObjStd140ChunkBase.cpp
blobf54d36207ae4457f3488cc67f7e71e76e0543177
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 UniformBufferObjStd140Chunk!
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"
66 #include "OSGUniformBufferObjStd140ChunkBase.h"
67 #include "OSGUniformBufferObjStd140Chunk.h"
69 #include <boost/bind.hpp>
71 OSG_BEGIN_NAMESPACE
73 /***************************************************************************\
74 * Description *
75 \***************************************************************************/
77 /*! \class OSG::UniformBufferObjStd140Chunk
78 See \ref PageSystemUniformBufferObjChunk for a description.
80 This chunk wraps the OpenGL uniform buffer object extension (ARB_uniform_buffer_object).
81 Basically, it holds a raw memory buffer and a buffer object binding point. The raw memory
82 buffer is expected to be provided by the chunk user in a OpenGL std140 compatible format.
83 Any shader binding an uniform block to the very same binding point is expected to respect
84 the corresponding block layout.
87 /***************************************************************************\
88 * Field Documentation *
89 \***************************************************************************/
91 /*! \var GLenum UniformBufferObjStd140ChunkBase::_sfGLId
92 The OpenGL object id for this uniform buffer object.
95 /*! \var GLenum UniformBufferObjStd140ChunkBase::_sfUsage
96 Specifies the expected usage pattern of the data store. The symbolic constant must be
97 GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY,
98 GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY,
99 GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.
102 /*! \var UInt8 UniformBufferObjStd140ChunkBase::_mfBuffer
103 The uniform buffer storage. The layout of this memory block is governed by the
104 shader uniform block layout according to OpenGL std140 specification.
108 /***************************************************************************\
109 * FieldType/FieldTrait Instantiation *
110 \***************************************************************************/
112 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
113 PointerType FieldTraits<UniformBufferObjStd140Chunk *, nsOSG>::_type(
114 "UniformBufferObjStd140ChunkPtr",
115 "UniformBufferObjBaseChunkPtr",
116 UniformBufferObjStd140Chunk::getClassType(),
117 nsOSG);
118 #endif
120 OSG_FIELDTRAITS_GETTYPE_NS(UniformBufferObjStd140Chunk *, nsOSG)
122 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
123 UniformBufferObjStd140Chunk *,
124 nsOSG)
126 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
127 UniformBufferObjStd140Chunk *,
128 nsOSG)
130 /***************************************************************************\
131 * Field Description *
132 \***************************************************************************/
134 void UniformBufferObjStd140ChunkBase::classDescInserter(TypeObject &oType)
136 FieldDescriptionBase *pDesc = NULL;
139 pDesc = new SFGLenum::Description(
140 SFGLenum::getClassType(),
141 "GLId",
142 "The OpenGL object id for this uniform buffer object.\n",
143 GLIdFieldId, GLIdFieldMask,
144 true,
145 (Field::FClusterLocal),
146 static_cast<FieldEditMethodSig>(&UniformBufferObjStd140Chunk::editHandleGLId),
147 static_cast<FieldGetMethodSig >(&UniformBufferObjStd140Chunk::getHandleGLId));
149 oType.addInitialDesc(pDesc);
151 pDesc = new SFGLenum::Description(
152 SFGLenum::getClassType(),
153 "usage",
154 "Specifies the expected usage pattern of the data store. The symbolic constant must be \n"
155 "GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, \n"
156 "GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, \n"
157 "GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.\n",
158 UsageFieldId, UsageFieldMask,
159 false,
160 (Field::SFDefaultFlags | Field::FStdAccess),
161 static_cast<FieldEditMethodSig>(&UniformBufferObjStd140Chunk::editHandleUsage),
162 static_cast<FieldGetMethodSig >(&UniformBufferObjStd140Chunk::getHandleUsage));
164 oType.addInitialDesc(pDesc);
166 pDesc = new MFUInt8::Description(
167 MFUInt8::getClassType(),
168 "buffer",
169 "The uniform buffer storage. The layout of this memory block is governed by the\n"
170 "shader uniform block layout according to OpenGL std140 specification.\n",
171 BufferFieldId, BufferFieldMask,
172 false,
173 (Field::MFDefaultFlags | Field::FStdAccess),
174 static_cast<FieldEditMethodSig>(&UniformBufferObjStd140Chunk::editHandleBuffer),
175 static_cast<FieldGetMethodSig >(&UniformBufferObjStd140Chunk::getHandleBuffer));
177 oType.addInitialDesc(pDesc);
181 UniformBufferObjStd140ChunkBase::TypeObject UniformBufferObjStd140ChunkBase::_type(
182 UniformBufferObjStd140ChunkBase::getClassname(),
183 Inherited::getClassname(),
184 "NULL",
185 nsOSG, //Namespace
186 reinterpret_cast<PrototypeCreateF>(&UniformBufferObjStd140ChunkBase::createEmptyLocal),
187 reinterpret_cast<InitContainerF>(&UniformBufferObjStd140Chunk::initMethod),
188 reinterpret_cast<ExitContainerF>(&UniformBufferObjStd140Chunk::exitMethod),
189 reinterpret_cast<InitalInsertDescFunc>(
190 reinterpret_cast<void *>(&UniformBufferObjStd140Chunk::classDescInserter)),
191 false,
193 "<?xml version=\"1.0\"?>\n"
194 "\n"
195 "<FieldContainer\n"
196 " name=\"UniformBufferObjStd140Chunk\"\n"
197 " parent=\"UniformBufferObjBaseChunk\"\n"
198 " library=\"System\"\n"
199 " pointerfieldtypes=\"both\"\n"
200 " structure=\"concrete\"\n"
201 " systemcomponent=\"true\"\n"
202 " parentsystemcomponent=\"true\"\n"
203 " decoratable=\"false\"\n"
204 " useLocalIncludes=\"false\"\n"
205 " docGroupBase=\"GrpSystemState\"\n"
206 " >\n"
207 " See \\ref PageSystemUniformBufferObjChunk for a description.\n"
208 "\n"
209 " This chunk wraps the OpenGL uniform buffer object extension (ARB_uniform_buffer_object). \n"
210 " Basically, it holds a raw memory buffer and a buffer object binding point. The raw memory \n"
211 " buffer is expected to be provided by the chunk user in a OpenGL std140 compatible format. \n"
212 " Any shader binding an uniform block to the very same binding point is expected to respect \n"
213 " the corresponding block layout.\n"
214 "\n"
215 " <Field\n"
216 " name=\"GLId\"\n"
217 " type=\"GLenum\"\n"
218 " cardinality=\"single\"\n"
219 " visibility=\"internal\"\n"
220 " access=\"public\"\n"
221 " defaultValue=\"0\"\n"
222 " fieldFlags=\"FClusterLocal\"\n"
223 "\t>\n"
224 " The OpenGL object id for this uniform buffer object.\n"
225 " </Field>\n"
226 " <Field\n"
227 " name=\"usage\"\n"
228 " type=\"GLenum\"\n"
229 " cardinality=\"single\"\n"
230 " visibility=\"external\"\n"
231 " access=\"public\"\n"
232 " defaultValue=\"GL_STATIC_DRAW\"\n"
233 " potential_values=\"GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, GL_DYNAMIC_COPY\"\n"
234 "\t>\n"
235 " Specifies the expected usage pattern of the data store. The symbolic constant must be \n"
236 " GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, \n"
237 " GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, \n"
238 " GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.\n"
239 " </Field>\n"
240 "<Field\n"
241 " name=\"buffer\"\n"
242 " type=\"UInt8\"\n"
243 " cardinality=\"multi\"\n"
244 " visibility=\"external\"\n"
245 " access=\"public\"\n"
246 "\t>\n"
247 "\tThe uniform buffer storage. The layout of this memory block is governed by the\n"
248 " shader uniform block layout according to OpenGL std140 specification.\n"
249 " </Field>\n"
250 "</FieldContainer>\n",
251 "See \\ref PageSystemUniformBufferObjChunk for a description.\n"
252 "\n"
253 "This chunk wraps the OpenGL uniform buffer object extension (ARB_uniform_buffer_object). \n"
254 "Basically, it holds a raw memory buffer and a buffer object binding point. The raw memory \n"
255 "buffer is expected to be provided by the chunk user in a OpenGL std140 compatible format. \n"
256 "Any shader binding an uniform block to the very same binding point is expected to respect \n"
257 "the corresponding block layout.\n"
260 /*------------------------------ get -----------------------------------*/
262 FieldContainerType &UniformBufferObjStd140ChunkBase::getType(void)
264 return _type;
267 const FieldContainerType &UniformBufferObjStd140ChunkBase::getType(void) const
269 return _type;
272 UInt32 UniformBufferObjStd140ChunkBase::getContainerSize(void) const
274 return sizeof(UniformBufferObjStd140Chunk);
277 /*------------------------- decorator get ------------------------------*/
280 SFGLenum *UniformBufferObjStd140ChunkBase::editSFGLId(void)
282 editSField(GLIdFieldMask);
284 return &_sfGLId;
287 const SFGLenum *UniformBufferObjStd140ChunkBase::getSFGLId(void) const
289 return &_sfGLId;
293 SFGLenum *UniformBufferObjStd140ChunkBase::editSFUsage(void)
295 editSField(UsageFieldMask);
297 return &_sfUsage;
300 const SFGLenum *UniformBufferObjStd140ChunkBase::getSFUsage(void) const
302 return &_sfUsage;
306 MFUInt8 *UniformBufferObjStd140ChunkBase::editMFBuffer(void)
308 editMField(BufferFieldMask, _mfBuffer);
310 return &_mfBuffer;
313 const MFUInt8 *UniformBufferObjStd140ChunkBase::getMFBuffer(void) const
315 return &_mfBuffer;
323 /*------------------------------ access -----------------------------------*/
325 SizeT UniformBufferObjStd140ChunkBase::getBinSize(ConstFieldMaskArg whichField)
327 SizeT returnValue = Inherited::getBinSize(whichField);
329 if(FieldBits::NoField != (GLIdFieldMask & whichField))
331 returnValue += _sfGLId.getBinSize();
333 if(FieldBits::NoField != (UsageFieldMask & whichField))
335 returnValue += _sfUsage.getBinSize();
337 if(FieldBits::NoField != (BufferFieldMask & whichField))
339 returnValue += _mfBuffer.getBinSize();
342 return returnValue;
345 void UniformBufferObjStd140ChunkBase::copyToBin(BinaryDataHandler &pMem,
346 ConstFieldMaskArg whichField)
348 Inherited::copyToBin(pMem, whichField);
350 if(FieldBits::NoField != (GLIdFieldMask & whichField))
352 _sfGLId.copyToBin(pMem);
354 if(FieldBits::NoField != (UsageFieldMask & whichField))
356 _sfUsage.copyToBin(pMem);
358 if(FieldBits::NoField != (BufferFieldMask & whichField))
360 _mfBuffer.copyToBin(pMem);
364 void UniformBufferObjStd140ChunkBase::copyFromBin(BinaryDataHandler &pMem,
365 ConstFieldMaskArg whichField)
367 Inherited::copyFromBin(pMem, whichField);
369 if(FieldBits::NoField != (GLIdFieldMask & whichField))
371 editSField(GLIdFieldMask);
372 _sfGLId.copyFromBin(pMem);
374 if(FieldBits::NoField != (UsageFieldMask & whichField))
376 editSField(UsageFieldMask);
377 _sfUsage.copyFromBin(pMem);
379 if(FieldBits::NoField != (BufferFieldMask & whichField))
381 editMField(BufferFieldMask, _mfBuffer);
382 _mfBuffer.copyFromBin(pMem);
386 //! create a new instance of the class
387 UniformBufferObjStd140ChunkTransitPtr UniformBufferObjStd140ChunkBase::createLocal(BitVector bFlags)
389 UniformBufferObjStd140ChunkTransitPtr fc;
391 if(getClassType().getPrototype() != NULL)
393 FieldContainerTransitPtr tmpPtr =
394 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
396 fc = dynamic_pointer_cast<UniformBufferObjStd140Chunk>(tmpPtr);
399 return fc;
402 //! create a new instance of the class, copy the container flags
403 UniformBufferObjStd140ChunkTransitPtr UniformBufferObjStd140ChunkBase::createDependent(BitVector bFlags)
405 UniformBufferObjStd140ChunkTransitPtr fc;
407 if(getClassType().getPrototype() != NULL)
409 FieldContainerTransitPtr tmpPtr =
410 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
412 fc = dynamic_pointer_cast<UniformBufferObjStd140Chunk>(tmpPtr);
415 return fc;
418 //! create a new instance of the class
419 UniformBufferObjStd140ChunkTransitPtr UniformBufferObjStd140ChunkBase::create(void)
421 UniformBufferObjStd140ChunkTransitPtr fc;
423 if(getClassType().getPrototype() != NULL)
425 FieldContainerTransitPtr tmpPtr =
426 getClassType().getPrototype()-> shallowCopy();
428 fc = dynamic_pointer_cast<UniformBufferObjStd140Chunk>(tmpPtr);
431 return fc;
434 UniformBufferObjStd140Chunk *UniformBufferObjStd140ChunkBase::createEmptyLocal(BitVector bFlags)
436 UniformBufferObjStd140Chunk *returnValue;
438 newPtr<UniformBufferObjStd140Chunk>(returnValue, bFlags);
440 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
442 return returnValue;
445 //! create an empty new instance of the class, do not copy the prototype
446 UniformBufferObjStd140Chunk *UniformBufferObjStd140ChunkBase::createEmpty(void)
448 UniformBufferObjStd140Chunk *returnValue;
450 newPtr<UniformBufferObjStd140Chunk>(returnValue, Thread::getCurrentLocalFlags());
452 returnValue->_pFieldFlags->_bNamespaceMask &=
453 ~Thread::getCurrentLocalFlags();
455 return returnValue;
459 FieldContainerTransitPtr UniformBufferObjStd140ChunkBase::shallowCopyLocal(
460 BitVector bFlags) const
462 UniformBufferObjStd140Chunk *tmpPtr;
464 newPtr(tmpPtr, dynamic_cast<const UniformBufferObjStd140Chunk *>(this), bFlags);
466 FieldContainerTransitPtr returnValue(tmpPtr);
468 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
470 return returnValue;
473 FieldContainerTransitPtr UniformBufferObjStd140ChunkBase::shallowCopyDependent(
474 BitVector bFlags) const
476 UniformBufferObjStd140Chunk *tmpPtr;
478 newPtr(tmpPtr, dynamic_cast<const UniformBufferObjStd140Chunk *>(this), ~bFlags);
480 FieldContainerTransitPtr returnValue(tmpPtr);
482 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
484 return returnValue;
487 FieldContainerTransitPtr UniformBufferObjStd140ChunkBase::shallowCopy(void) const
489 UniformBufferObjStd140Chunk *tmpPtr;
491 newPtr(tmpPtr,
492 dynamic_cast<const UniformBufferObjStd140Chunk *>(this),
493 Thread::getCurrentLocalFlags());
495 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
497 FieldContainerTransitPtr returnValue(tmpPtr);
499 return returnValue;
505 /*------------------------- constructors ----------------------------------*/
507 UniformBufferObjStd140ChunkBase::UniformBufferObjStd140ChunkBase(void) :
508 Inherited(),
509 _sfGLId (GLenum(0)),
510 _sfUsage (GLenum(GL_STATIC_DRAW)),
511 _mfBuffer ()
515 UniformBufferObjStd140ChunkBase::UniformBufferObjStd140ChunkBase(const UniformBufferObjStd140ChunkBase &source) :
516 Inherited(source),
517 _sfGLId (source._sfGLId ),
518 _sfUsage (source._sfUsage ),
519 _mfBuffer (source._mfBuffer )
524 /*-------------------------- destructors ----------------------------------*/
526 UniformBufferObjStd140ChunkBase::~UniformBufferObjStd140ChunkBase(void)
531 GetFieldHandlePtr UniformBufferObjStd140ChunkBase::getHandleGLId (void) const
533 SFGLenum::GetHandlePtr returnValue(
534 new SFGLenum::GetHandle(
535 &_sfGLId,
536 this->getType().getFieldDesc(GLIdFieldId),
537 const_cast<UniformBufferObjStd140ChunkBase *>(this)));
539 return returnValue;
542 EditFieldHandlePtr UniformBufferObjStd140ChunkBase::editHandleGLId (void)
544 SFGLenum::EditHandlePtr returnValue(
545 new SFGLenum::EditHandle(
546 &_sfGLId,
547 this->getType().getFieldDesc(GLIdFieldId),
548 this));
551 editSField(GLIdFieldMask);
553 return returnValue;
556 GetFieldHandlePtr UniformBufferObjStd140ChunkBase::getHandleUsage (void) const
558 SFGLenum::GetHandlePtr returnValue(
559 new SFGLenum::GetHandle(
560 &_sfUsage,
561 this->getType().getFieldDesc(UsageFieldId),
562 const_cast<UniformBufferObjStd140ChunkBase *>(this)));
564 return returnValue;
567 EditFieldHandlePtr UniformBufferObjStd140ChunkBase::editHandleUsage (void)
569 SFGLenum::EditHandlePtr returnValue(
570 new SFGLenum::EditHandle(
571 &_sfUsage,
572 this->getType().getFieldDesc(UsageFieldId),
573 this));
576 editSField(UsageFieldMask);
578 return returnValue;
581 GetFieldHandlePtr UniformBufferObjStd140ChunkBase::getHandleBuffer (void) const
583 MFUInt8::GetHandlePtr returnValue(
584 new MFUInt8::GetHandle(
585 &_mfBuffer,
586 this->getType().getFieldDesc(BufferFieldId),
587 const_cast<UniformBufferObjStd140ChunkBase *>(this)));
589 return returnValue;
592 EditFieldHandlePtr UniformBufferObjStd140ChunkBase::editHandleBuffer (void)
594 MFUInt8::EditHandlePtr returnValue(
595 new MFUInt8::EditHandle(
596 &_mfBuffer,
597 this->getType().getFieldDesc(BufferFieldId),
598 this));
601 editMField(BufferFieldMask, _mfBuffer);
603 return returnValue;
607 #ifdef OSG_MT_CPTR_ASPECT
608 void UniformBufferObjStd140ChunkBase::execSyncV( FieldContainer &oFrom,
609 ConstFieldMaskArg whichField,
610 AspectOffsetStore &oOffsets,
611 ConstFieldMaskArg syncMode,
612 const UInt32 uiSyncInfo)
614 UniformBufferObjStd140Chunk *pThis = static_cast<UniformBufferObjStd140Chunk *>(this);
616 pThis->execSync(static_cast<UniformBufferObjStd140Chunk *>(&oFrom),
617 whichField,
618 oOffsets,
619 syncMode,
620 uiSyncInfo);
622 #endif
625 #ifdef OSG_MT_CPTR_ASPECT
626 FieldContainer *UniformBufferObjStd140ChunkBase::createAspectCopy(
627 const FieldContainer *pRefAspect) const
629 UniformBufferObjStd140Chunk *returnValue;
631 newAspectCopy(returnValue,
632 dynamic_cast<const UniformBufferObjStd140Chunk *>(pRefAspect),
633 dynamic_cast<const UniformBufferObjStd140Chunk *>(this));
635 return returnValue;
637 #endif
639 void UniformBufferObjStd140ChunkBase::resolveLinks(void)
641 Inherited::resolveLinks();
643 #ifdef OSG_MT_CPTR_ASPECT
644 AspectOffsetStore oOffsets;
646 _pAspectStore->fillOffsetArray(oOffsets, this);
647 #endif
649 #ifdef OSG_MT_CPTR_ASPECT
650 _mfBuffer.terminateShare(Thread::getCurrentAspect(),
651 oOffsets);
652 #endif
656 OSG_END_NAMESPACE