changed: gcc8 base update
[opensg.git] / Source / Contrib / ComputeBase / ComputeShader / OSGComputeShaderAlgorithmBase.cpp
blob22f66c141781c1ce08be72a4ce967501811be64d
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 ComputeShaderAlgorithm!
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 "OSGTextureImageChunk.h" // TextureImages Class
66 #include "OSGChunkMaterial.h" // ChunkMaterial Class
67 #include "OSGComputeShaderChunk.h" // ComputeShader Class
69 #include "OSGComputeShaderAlgorithmBase.h"
70 #include "OSGComputeShaderAlgorithm.h"
72 #include <boost/bind.hpp>
74 OSG_BEGIN_NAMESPACE
76 /***************************************************************************\
77 * Description *
78 \***************************************************************************/
80 /*! \class OSG::ComputeShaderAlgorithm
81 This class allows the operation of a compute shader algorithm. It allows the specification of
82 shader buffers and textures to be used in the computation task and the details of the computational
83 space the compute shader operats on.
86 /***************************************************************************\
87 * Field Documentation *
88 \***************************************************************************/
90 /*! \var TextureImageChunk * ComputeShaderAlgorithmBase::_mfTextureImages
91 Texture images to be used for reading/writing in the compute shader.
92 The texture images uses the binding points starting from 0 and then
93 incrementing by 1.
96 /*! \var ChunkMaterial * ComputeShaderAlgorithmBase::_sfChunkMaterial
97 This chunk material allows the usage of texture images, uniform buffer objects
98 and shader storage buffer objects in the compute shader. Only these material
99 chunks are going to be respected, all other will simply omitted. A valid
100 chunk in the chunk material specifies the binding point to be used in the compute
101 shader.
104 /*! \var ComputeShaderChunk * ComputeShaderAlgorithmBase::_sfComputeShader
105 The compute shader abstracts the actual shader code and the variable specifications
106 used in the shader.
109 /*! \var Vec3i ComputeShaderAlgorithmBase::_sfDispatchConfig
110 The number of work groups, i.e. the work group count.
113 /*! \var Vec3i ComputeShaderAlgorithmBase::_sfWorkGroupSize
114 The size of the work groups, i.e. the local_size_var value of the layout specifier.
115 This does need the ARB_compute_variable_group_size GL extension to work.
118 /*! \var bool ComputeShaderAlgorithmBase::_sfUseMemoryBarrier
119 This flag toggles the usage of the memory barrier call after the operation of
120 the compute shader.
123 /*! \var bool ComputeShaderAlgorithmBase::_sfUseVariableWorkGroupSize
124 This flag enables the useage of the variable work group size dispatch API that
125 is specified in the ARB_compute_variable_group_size extension.
128 /*! \var GLenum ComputeShaderAlgorithmBase::_sfMemoryBarrier
129 This bitmask determines the behavior of the memory barrier that is issued after the
130 operation of the compute shader.
134 /***************************************************************************\
135 * FieldType/FieldTrait Instantiation *
136 \***************************************************************************/
138 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
139 PointerType FieldTraits<ComputeShaderAlgorithm *, nsOSG>::_type(
140 "ComputeShaderAlgorithmPtr",
141 "ComputeAlgorithmPtr",
142 ComputeShaderAlgorithm::getClassType(),
143 nsOSG);
144 #endif
146 OSG_FIELDTRAITS_GETTYPE_NS(ComputeShaderAlgorithm *, nsOSG)
148 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
149 ComputeShaderAlgorithm *,
150 nsOSG)
152 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
153 ComputeShaderAlgorithm *,
154 nsOSG)
156 /***************************************************************************\
157 * Field Description *
158 \***************************************************************************/
160 void ComputeShaderAlgorithmBase::classDescInserter(TypeObject &oType)
162 FieldDescriptionBase *pDesc = NULL;
165 pDesc = new MFUnrecTextureImageChunkPtr::Description(
166 MFUnrecTextureImageChunkPtr::getClassType(),
167 "textureImages",
168 "Texture images to be used for reading/writing in the compute shader.\n"
169 "The texture images uses the binding points starting from 0 and then \n"
170 "incrementing by 1.\n",
171 TextureImagesFieldId, TextureImagesFieldMask,
172 false,
173 (Field::MFDefaultFlags | Field::FStdAccess),
174 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleTextureImages),
175 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleTextureImages));
177 oType.addInitialDesc(pDesc);
179 pDesc = new SFUnrecChunkMaterialPtr::Description(
180 SFUnrecChunkMaterialPtr::getClassType(),
181 "chunkMaterial",
182 "This chunk material allows the usage of texture images, uniform buffer objects\n"
183 "and shader storage buffer objects in the compute shader. Only these material\n"
184 "chunks are going to be respected, all other will simply omitted. A valid\n"
185 "chunk in the chunk material specifies the binding point to be used in the compute\n"
186 "shader.\n",
187 ChunkMaterialFieldId, ChunkMaterialFieldMask,
188 false,
189 (Field::SFDefaultFlags | Field::FStdAccess),
190 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleChunkMaterial),
191 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleChunkMaterial));
193 oType.addInitialDesc(pDesc);
195 pDesc = new SFUnrecComputeShaderChunkPtr::Description(
196 SFUnrecComputeShaderChunkPtr::getClassType(),
197 "computeShader",
198 "The compute shader abstracts the actual shader code and the variable specifications\n"
199 "used in the shader.\n",
200 ComputeShaderFieldId, ComputeShaderFieldMask,
201 false,
202 (Field::SFDefaultFlags | Field::FStdAccess),
203 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleComputeShader),
204 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleComputeShader));
206 oType.addInitialDesc(pDesc);
208 pDesc = new SFVec3i::Description(
209 SFVec3i::getClassType(),
210 "dispatchConfig",
211 "The number of work groups, i.e. the work group count.\n",
212 DispatchConfigFieldId, DispatchConfigFieldMask,
213 false,
214 (Field::SFDefaultFlags | Field::FStdAccess),
215 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleDispatchConfig),
216 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleDispatchConfig));
218 oType.addInitialDesc(pDesc);
220 pDesc = new SFVec3i::Description(
221 SFVec3i::getClassType(),
222 "workGroupSize",
223 "The size of the work groups, i.e. the local_size_var value of the layout specifier.\n"
224 "This does need the ARB_compute_variable_group_size GL extension to work.\n",
225 WorkGroupSizeFieldId, WorkGroupSizeFieldMask,
226 false,
227 (Field::SFDefaultFlags | Field::FStdAccess),
228 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleWorkGroupSize),
229 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleWorkGroupSize));
231 oType.addInitialDesc(pDesc);
233 pDesc = new SFBool::Description(
234 SFBool::getClassType(),
235 "useMemoryBarrier",
236 "This flag toggles the usage of the memory barrier call after the operation of\n"
237 "the compute shader.\n",
238 UseMemoryBarrierFieldId, UseMemoryBarrierFieldMask,
239 false,
240 (Field::SFDefaultFlags | Field::FStdAccess),
241 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleUseMemoryBarrier),
242 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleUseMemoryBarrier));
244 oType.addInitialDesc(pDesc);
246 pDesc = new SFBool::Description(
247 SFBool::getClassType(),
248 "useVariableWorkGroupSize",
249 "This flag enables the useage of the variable work group size dispatch API that\n"
250 "is specified in the ARB_compute_variable_group_size extension.\n",
251 UseVariableWorkGroupSizeFieldId, UseVariableWorkGroupSizeFieldMask,
252 false,
253 (Field::SFDefaultFlags | Field::FStdAccess),
254 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleUseVariableWorkGroupSize),
255 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleUseVariableWorkGroupSize));
257 oType.addInitialDesc(pDesc);
259 pDesc = new SFGLenum::Description(
260 SFGLenum::getClassType(),
261 "memoryBarrier",
262 "This bitmask determines the behavior of the memory barrier that is issued after the\n"
263 "operation of the compute shader.\n",
264 MemoryBarrierFieldId, MemoryBarrierFieldMask,
265 false,
266 (Field::SFDefaultFlags | Field::FStdAccess),
267 static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleMemoryBarrier),
268 static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleMemoryBarrier));
270 oType.addInitialDesc(pDesc);
274 ComputeShaderAlgorithmBase::TypeObject ComputeShaderAlgorithmBase::_type(
275 ComputeShaderAlgorithmBase::getClassname(),
276 Inherited::getClassname(),
277 "NULL",
278 nsOSG, //Namespace
279 reinterpret_cast<PrototypeCreateF>(&ComputeShaderAlgorithmBase::createEmptyLocal),
280 reinterpret_cast<InitContainerF>(&ComputeShaderAlgorithm::initMethod),
281 reinterpret_cast<ExitContainerF>(&ComputeShaderAlgorithm::exitMethod),
282 reinterpret_cast<InitalInsertDescFunc>(
283 reinterpret_cast<void *>(&ComputeShaderAlgorithm::classDescInserter)),
284 false,
286 "<?xml version=\"1.0\"?>\n"
287 "\n"
288 "<FieldContainer\n"
289 "\tname=\"ComputeShaderAlgorithm\"\n"
290 "\tparent=\"ComputeAlgorithm\"\n"
291 "\tlibrary=\"ContribComputeBase\"\n"
292 "\tpointerfieldtypes=\"both\"\n"
293 "\tstructure=\"concrete\"\n"
294 "\tsystemcomponent=\"true\"\n"
295 "\tparentsystemcomponent=\"true\"\n"
296 "\tdecoratable=\"false\"\n"
297 "\tuseLocalIncludes=\"false\"\n"
298 " isNodeCore=\"false\"\n"
299 " >\n"
300 " This class allows the operation of a compute shader algorithm. It allows the specification of \n"
301 " shader buffers and textures to be used in the computation task and the details of the computational\n"
302 " space the compute shader operats on.\n"
303 " \n"
304 " <Field\n"
305 " name=\"textureImages\"\n"
306 " type=\"TextureImageChunk\"\n"
307 " category=\"pointer\"\n"
308 " cardinality=\"multi\"\n"
309 " visibility=\"external\"\n"
310 " access=\"public\"\n"
311 " >\n"
312 " Texture images to be used for reading/writing in the compute shader.\n"
313 " The texture images uses the binding points starting from 0 and then \n"
314 " incrementing by 1.\n"
315 " </Field>\n"
316 " <Field\n"
317 " name=\"chunkMaterial\"\n"
318 " type=\"ChunkMaterial\"\n"
319 " category=\"pointer\"\n"
320 " cardinality=\"single\"\n"
321 " visibility=\"external\"\n"
322 " access=\"public\"\n"
323 " >\n"
324 " This chunk material allows the usage of texture images, uniform buffer objects\n"
325 " and shader storage buffer objects in the compute shader. Only these material\n"
326 " chunks are going to be respected, all other will simply omitted. A valid\n"
327 " chunk in the chunk material specifies the binding point to be used in the compute\n"
328 " shader.\n"
329 " </Field>\n"
330 " <Field\n"
331 " name=\"computeShader\"\n"
332 " type=\"ComputeShaderChunk\"\n"
333 " category=\"pointer\"\n"
334 " cardinality=\"single\"\n"
335 " visibility=\"external\"\n"
336 " access=\"public\"\n"
337 " >\n"
338 " The compute shader abstracts the actual shader code and the variable specifications\n"
339 " used in the shader.\n"
340 " </Field>\n"
341 " <Field\n"
342 " name=\"dispatchConfig\"\n"
343 " type=\"Vec3i\"\n"
344 " cardinality=\"single\"\n"
345 " visibility=\"external\"\n"
346 " access=\"public\"\n"
347 " defaultValue=\"1, 0, 0\"\n"
348 " >\n"
349 " The number of work groups, i.e. the work group count.\n"
350 " </Field>\n"
351 "<Field\n"
352 " name=\"workGroupSize\"\n"
353 " type=\"Vec3i\"\n"
354 " cardinality=\"single\"\n"
355 " visibility=\"external\"\n"
356 " access=\"public\"\n"
357 " defaultValue=\"1, 1, 1\"\n"
358 " >\n"
359 " The size of the work groups, i.e. the local_size_var value of the layout specifier.\n"
360 " This does need the ARB_compute_variable_group_size GL extension to work.\n"
361 " </Field>\n"
362 "\n"
363 " <Field\n"
364 " name=\"useMemoryBarrier\"\n"
365 " type=\"bool\"\n"
366 " cardinality=\"single\"\n"
367 " visibility=\"external\"\n"
368 " access=\"public\"\n"
369 " defaultValue=\"false\"\n"
370 " >\n"
371 " This flag toggles the usage of the memory barrier call after the operation of\n"
372 " the compute shader.\n"
373 " </Field>\n"
374 "\n"
375 " <Field\n"
376 " name=\"useVariableWorkGroupSize\"\n"
377 " type=\"bool\"\n"
378 " cardinality=\"single\"\n"
379 " visibility=\"external\"\n"
380 " access=\"public\"\n"
381 " defaultValue=\"false\"\n"
382 " >\n"
383 " This flag enables the useage of the variable work group size dispatch API that\n"
384 " is specified in the ARB_compute_variable_group_size extension.\n"
385 " </Field>\n"
386 "\n"
387 " <Field\n"
388 " name=\"memoryBarrier\"\n"
389 " type=\"GLenum\"\n"
390 " cardinality=\"single\"\n"
391 " visibility=\"external\"\n"
392 " access=\"public\"\n"
393 " defaultValue=\"GL_SHADER_STORAGE_BARRIER_BIT\"\n"
394 " >\n"
395 " This bitmask determines the behavior of the memory barrier that is issued after the\n"
396 " operation of the compute shader.\n"
397 " </Field>\n"
398 "\n"
399 "</FieldContainer>\n",
400 "This class allows the operation of a compute shader algorithm. It allows the specification of \n"
401 "shader buffers and textures to be used in the computation task and the details of the computational\n"
402 "space the compute shader operats on.\n"
405 /*------------------------------ get -----------------------------------*/
407 FieldContainerType &ComputeShaderAlgorithmBase::getType(void)
409 return _type;
412 const FieldContainerType &ComputeShaderAlgorithmBase::getType(void) const
414 return _type;
417 UInt32 ComputeShaderAlgorithmBase::getContainerSize(void) const
419 return sizeof(ComputeShaderAlgorithm);
422 /*------------------------- decorator get ------------------------------*/
425 //! Get the ComputeShaderAlgorithm::_mfTextureImages field.
426 const MFUnrecTextureImageChunkPtr *ComputeShaderAlgorithmBase::getMFTextureImages(void) const
428 return &_mfTextureImages;
431 MFUnrecTextureImageChunkPtr *ComputeShaderAlgorithmBase::editMFTextureImages (void)
433 editMField(TextureImagesFieldMask, _mfTextureImages);
435 return &_mfTextureImages;
437 TextureImageChunk * ComputeShaderAlgorithmBase::getTextureImages(const UInt32 index) const
439 return _mfTextureImages[index];
442 //! Get the ComputeShaderAlgorithm::_sfChunkMaterial field.
443 const SFUnrecChunkMaterialPtr *ComputeShaderAlgorithmBase::getSFChunkMaterial(void) const
445 return &_sfChunkMaterial;
448 SFUnrecChunkMaterialPtr *ComputeShaderAlgorithmBase::editSFChunkMaterial (void)
450 editSField(ChunkMaterialFieldMask);
452 return &_sfChunkMaterial;
455 //! Get the value of the ComputeShaderAlgorithm::_sfChunkMaterial field.
456 ChunkMaterial * ComputeShaderAlgorithmBase::getChunkMaterial(void) const
458 return _sfChunkMaterial.getValue();
461 //! Set the value of the ComputeShaderAlgorithm::_sfChunkMaterial field.
462 void ComputeShaderAlgorithmBase::setChunkMaterial(ChunkMaterial * const value)
464 editSField(ChunkMaterialFieldMask);
466 _sfChunkMaterial.setValue(value);
470 //! Get the ComputeShaderAlgorithm::_sfComputeShader field.
471 const SFUnrecComputeShaderChunkPtr *ComputeShaderAlgorithmBase::getSFComputeShader(void) const
473 return &_sfComputeShader;
476 SFUnrecComputeShaderChunkPtr *ComputeShaderAlgorithmBase::editSFComputeShader (void)
478 editSField(ComputeShaderFieldMask);
480 return &_sfComputeShader;
483 //! Get the value of the ComputeShaderAlgorithm::_sfComputeShader field.
484 ComputeShaderChunk * ComputeShaderAlgorithmBase::getComputeShader(void) const
486 return _sfComputeShader.getValue();
489 //! Set the value of the ComputeShaderAlgorithm::_sfComputeShader field.
490 void ComputeShaderAlgorithmBase::setComputeShader(ComputeShaderChunk * const value)
492 editSField(ComputeShaderFieldMask);
494 _sfComputeShader.setValue(value);
498 SFVec3i *ComputeShaderAlgorithmBase::editSFDispatchConfig(void)
500 editSField(DispatchConfigFieldMask);
502 return &_sfDispatchConfig;
505 const SFVec3i *ComputeShaderAlgorithmBase::getSFDispatchConfig(void) const
507 return &_sfDispatchConfig;
511 SFVec3i *ComputeShaderAlgorithmBase::editSFWorkGroupSize(void)
513 editSField(WorkGroupSizeFieldMask);
515 return &_sfWorkGroupSize;
518 const SFVec3i *ComputeShaderAlgorithmBase::getSFWorkGroupSize(void) const
520 return &_sfWorkGroupSize;
524 SFBool *ComputeShaderAlgorithmBase::editSFUseMemoryBarrier(void)
526 editSField(UseMemoryBarrierFieldMask);
528 return &_sfUseMemoryBarrier;
531 const SFBool *ComputeShaderAlgorithmBase::getSFUseMemoryBarrier(void) const
533 return &_sfUseMemoryBarrier;
537 SFBool *ComputeShaderAlgorithmBase::editSFUseVariableWorkGroupSize(void)
539 editSField(UseVariableWorkGroupSizeFieldMask);
541 return &_sfUseVariableWorkGroupSize;
544 const SFBool *ComputeShaderAlgorithmBase::getSFUseVariableWorkGroupSize(void) const
546 return &_sfUseVariableWorkGroupSize;
550 SFGLenum *ComputeShaderAlgorithmBase::editSFMemoryBarrier(void)
552 editSField(MemoryBarrierFieldMask);
554 return &_sfMemoryBarrier;
557 const SFGLenum *ComputeShaderAlgorithmBase::getSFMemoryBarrier(void) const
559 return &_sfMemoryBarrier;
565 void ComputeShaderAlgorithmBase::pushToTextureImages(TextureImageChunk * const value)
567 editMField(TextureImagesFieldMask, _mfTextureImages);
569 _mfTextureImages.push_back(value);
572 void ComputeShaderAlgorithmBase::assignTextureImages(const MFUnrecTextureImageChunkPtr &value)
574 MFUnrecTextureImageChunkPtr::const_iterator elemIt =
575 value.begin();
576 MFUnrecTextureImageChunkPtr::const_iterator elemEnd =
577 value.end ();
579 static_cast<ComputeShaderAlgorithm *>(this)->clearTextureImages();
581 while(elemIt != elemEnd)
583 this->pushToTextureImages(*elemIt);
585 ++elemIt;
589 void ComputeShaderAlgorithmBase::removeFromTextureImages(UInt32 uiIndex)
591 if(uiIndex < _mfTextureImages.size())
593 editMField(TextureImagesFieldMask, _mfTextureImages);
595 _mfTextureImages.erase(uiIndex);
599 void ComputeShaderAlgorithmBase::removeObjFromTextureImages(TextureImageChunk * const value)
601 Int32 iElemIdx = _mfTextureImages.findIndex(value);
603 if(iElemIdx != -1)
605 editMField(TextureImagesFieldMask, _mfTextureImages);
607 _mfTextureImages.erase(iElemIdx);
610 void ComputeShaderAlgorithmBase::clearTextureImages(void)
612 editMField(TextureImagesFieldMask, _mfTextureImages);
615 _mfTextureImages.clear();
620 /*------------------------------ access -----------------------------------*/
622 SizeT ComputeShaderAlgorithmBase::getBinSize(ConstFieldMaskArg whichField)
624 SizeT returnValue = Inherited::getBinSize(whichField);
626 if(FieldBits::NoField != (TextureImagesFieldMask & whichField))
628 returnValue += _mfTextureImages.getBinSize();
630 if(FieldBits::NoField != (ChunkMaterialFieldMask & whichField))
632 returnValue += _sfChunkMaterial.getBinSize();
634 if(FieldBits::NoField != (ComputeShaderFieldMask & whichField))
636 returnValue += _sfComputeShader.getBinSize();
638 if(FieldBits::NoField != (DispatchConfigFieldMask & whichField))
640 returnValue += _sfDispatchConfig.getBinSize();
642 if(FieldBits::NoField != (WorkGroupSizeFieldMask & whichField))
644 returnValue += _sfWorkGroupSize.getBinSize();
646 if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField))
648 returnValue += _sfUseMemoryBarrier.getBinSize();
650 if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField))
652 returnValue += _sfUseVariableWorkGroupSize.getBinSize();
654 if(FieldBits::NoField != (MemoryBarrierFieldMask & whichField))
656 returnValue += _sfMemoryBarrier.getBinSize();
659 return returnValue;
662 void ComputeShaderAlgorithmBase::copyToBin(BinaryDataHandler &pMem,
663 ConstFieldMaskArg whichField)
665 Inherited::copyToBin(pMem, whichField);
667 if(FieldBits::NoField != (TextureImagesFieldMask & whichField))
669 _mfTextureImages.copyToBin(pMem);
671 if(FieldBits::NoField != (ChunkMaterialFieldMask & whichField))
673 _sfChunkMaterial.copyToBin(pMem);
675 if(FieldBits::NoField != (ComputeShaderFieldMask & whichField))
677 _sfComputeShader.copyToBin(pMem);
679 if(FieldBits::NoField != (DispatchConfigFieldMask & whichField))
681 _sfDispatchConfig.copyToBin(pMem);
683 if(FieldBits::NoField != (WorkGroupSizeFieldMask & whichField))
685 _sfWorkGroupSize.copyToBin(pMem);
687 if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField))
689 _sfUseMemoryBarrier.copyToBin(pMem);
691 if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField))
693 _sfUseVariableWorkGroupSize.copyToBin(pMem);
695 if(FieldBits::NoField != (MemoryBarrierFieldMask & whichField))
697 _sfMemoryBarrier.copyToBin(pMem);
701 void ComputeShaderAlgorithmBase::copyFromBin(BinaryDataHandler &pMem,
702 ConstFieldMaskArg whichField)
704 Inherited::copyFromBin(pMem, whichField);
706 if(FieldBits::NoField != (TextureImagesFieldMask & whichField))
708 editMField(TextureImagesFieldMask, _mfTextureImages);
709 _mfTextureImages.copyFromBin(pMem);
711 if(FieldBits::NoField != (ChunkMaterialFieldMask & whichField))
713 editSField(ChunkMaterialFieldMask);
714 _sfChunkMaterial.copyFromBin(pMem);
716 if(FieldBits::NoField != (ComputeShaderFieldMask & whichField))
718 editSField(ComputeShaderFieldMask);
719 _sfComputeShader.copyFromBin(pMem);
721 if(FieldBits::NoField != (DispatchConfigFieldMask & whichField))
723 editSField(DispatchConfigFieldMask);
724 _sfDispatchConfig.copyFromBin(pMem);
726 if(FieldBits::NoField != (WorkGroupSizeFieldMask & whichField))
728 editSField(WorkGroupSizeFieldMask);
729 _sfWorkGroupSize.copyFromBin(pMem);
731 if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField))
733 editSField(UseMemoryBarrierFieldMask);
734 _sfUseMemoryBarrier.copyFromBin(pMem);
736 if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField))
738 editSField(UseVariableWorkGroupSizeFieldMask);
739 _sfUseVariableWorkGroupSize.copyFromBin(pMem);
741 if(FieldBits::NoField != (MemoryBarrierFieldMask & whichField))
743 editSField(MemoryBarrierFieldMask);
744 _sfMemoryBarrier.copyFromBin(pMem);
748 //! create a new instance of the class
749 ComputeShaderAlgorithmTransitPtr ComputeShaderAlgorithmBase::createLocal(BitVector bFlags)
751 ComputeShaderAlgorithmTransitPtr fc;
753 if(getClassType().getPrototype() != NULL)
755 FieldContainerTransitPtr tmpPtr =
756 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
758 fc = dynamic_pointer_cast<ComputeShaderAlgorithm>(tmpPtr);
761 return fc;
764 //! create a new instance of the class, copy the container flags
765 ComputeShaderAlgorithmTransitPtr ComputeShaderAlgorithmBase::createDependent(BitVector bFlags)
767 ComputeShaderAlgorithmTransitPtr fc;
769 if(getClassType().getPrototype() != NULL)
771 FieldContainerTransitPtr tmpPtr =
772 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
774 fc = dynamic_pointer_cast<ComputeShaderAlgorithm>(tmpPtr);
777 return fc;
780 //! create a new instance of the class
781 ComputeShaderAlgorithmTransitPtr ComputeShaderAlgorithmBase::create(void)
783 ComputeShaderAlgorithmTransitPtr fc;
785 if(getClassType().getPrototype() != NULL)
787 FieldContainerTransitPtr tmpPtr =
788 getClassType().getPrototype()-> shallowCopy();
790 fc = dynamic_pointer_cast<ComputeShaderAlgorithm>(tmpPtr);
793 return fc;
796 ComputeShaderAlgorithm *ComputeShaderAlgorithmBase::createEmptyLocal(BitVector bFlags)
798 ComputeShaderAlgorithm *returnValue;
800 newPtr<ComputeShaderAlgorithm>(returnValue, bFlags);
802 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
804 return returnValue;
807 //! create an empty new instance of the class, do not copy the prototype
808 ComputeShaderAlgorithm *ComputeShaderAlgorithmBase::createEmpty(void)
810 ComputeShaderAlgorithm *returnValue;
812 newPtr<ComputeShaderAlgorithm>(returnValue, Thread::getCurrentLocalFlags());
814 returnValue->_pFieldFlags->_bNamespaceMask &=
815 ~Thread::getCurrentLocalFlags();
817 return returnValue;
821 FieldContainerTransitPtr ComputeShaderAlgorithmBase::shallowCopyLocal(
822 BitVector bFlags) const
824 ComputeShaderAlgorithm *tmpPtr;
826 newPtr(tmpPtr, dynamic_cast<const ComputeShaderAlgorithm *>(this), bFlags);
828 FieldContainerTransitPtr returnValue(tmpPtr);
830 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
832 return returnValue;
835 FieldContainerTransitPtr ComputeShaderAlgorithmBase::shallowCopyDependent(
836 BitVector bFlags) const
838 ComputeShaderAlgorithm *tmpPtr;
840 newPtr(tmpPtr, dynamic_cast<const ComputeShaderAlgorithm *>(this), ~bFlags);
842 FieldContainerTransitPtr returnValue(tmpPtr);
844 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
846 return returnValue;
849 FieldContainerTransitPtr ComputeShaderAlgorithmBase::shallowCopy(void) const
851 ComputeShaderAlgorithm *tmpPtr;
853 newPtr(tmpPtr,
854 dynamic_cast<const ComputeShaderAlgorithm *>(this),
855 Thread::getCurrentLocalFlags());
857 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
859 FieldContainerTransitPtr returnValue(tmpPtr);
861 return returnValue;
867 /*------------------------- constructors ----------------------------------*/
869 ComputeShaderAlgorithmBase::ComputeShaderAlgorithmBase(void) :
870 Inherited(),
871 _mfTextureImages (),
872 _sfChunkMaterial (NULL),
873 _sfComputeShader (NULL),
874 _sfDispatchConfig (Vec3i(1, 0, 0)),
875 _sfWorkGroupSize (Vec3i(1, 1, 1)),
876 _sfUseMemoryBarrier (bool(false)),
877 _sfUseVariableWorkGroupSize(bool(false)),
878 _sfMemoryBarrier (GLenum(GL_SHADER_STORAGE_BARRIER_BIT))
882 ComputeShaderAlgorithmBase::ComputeShaderAlgorithmBase(const ComputeShaderAlgorithmBase &source) :
883 Inherited(source),
884 _mfTextureImages (),
885 _sfChunkMaterial (NULL),
886 _sfComputeShader (NULL),
887 _sfDispatchConfig (source._sfDispatchConfig ),
888 _sfWorkGroupSize (source._sfWorkGroupSize ),
889 _sfUseMemoryBarrier (source._sfUseMemoryBarrier ),
890 _sfUseVariableWorkGroupSize(source._sfUseVariableWorkGroupSize),
891 _sfMemoryBarrier (source._sfMemoryBarrier )
896 /*-------------------------- destructors ----------------------------------*/
898 ComputeShaderAlgorithmBase::~ComputeShaderAlgorithmBase(void)
902 void ComputeShaderAlgorithmBase::onCreate(const ComputeShaderAlgorithm *source)
904 Inherited::onCreate(source);
906 if(source != NULL)
908 ComputeShaderAlgorithm *pThis = static_cast<ComputeShaderAlgorithm *>(this);
910 MFUnrecTextureImageChunkPtr::const_iterator TextureImagesIt =
911 source->_mfTextureImages.begin();
912 MFUnrecTextureImageChunkPtr::const_iterator TextureImagesEnd =
913 source->_mfTextureImages.end ();
915 while(TextureImagesIt != TextureImagesEnd)
917 pThis->pushToTextureImages(*TextureImagesIt);
919 ++TextureImagesIt;
922 pThis->setChunkMaterial(source->getChunkMaterial());
924 pThis->setComputeShader(source->getComputeShader());
928 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleTextureImages (void) const
930 MFUnrecTextureImageChunkPtr::GetHandlePtr returnValue(
931 new MFUnrecTextureImageChunkPtr::GetHandle(
932 &_mfTextureImages,
933 this->getType().getFieldDesc(TextureImagesFieldId),
934 const_cast<ComputeShaderAlgorithmBase *>(this)));
936 return returnValue;
939 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleTextureImages (void)
941 MFUnrecTextureImageChunkPtr::EditHandlePtr returnValue(
942 new MFUnrecTextureImageChunkPtr::EditHandle(
943 &_mfTextureImages,
944 this->getType().getFieldDesc(TextureImagesFieldId),
945 this));
947 returnValue->setAddMethod(
948 boost::bind(&ComputeShaderAlgorithm::pushToTextureImages,
949 static_cast<ComputeShaderAlgorithm *>(this), _1));
950 returnValue->setRemoveMethod(
951 boost::bind(&ComputeShaderAlgorithm::removeFromTextureImages,
952 static_cast<ComputeShaderAlgorithm *>(this), _1));
953 returnValue->setRemoveObjMethod(
954 boost::bind(&ComputeShaderAlgorithm::removeObjFromTextureImages,
955 static_cast<ComputeShaderAlgorithm *>(this), _1));
956 returnValue->setClearMethod(
957 boost::bind(&ComputeShaderAlgorithm::clearTextureImages,
958 static_cast<ComputeShaderAlgorithm *>(this)));
960 editMField(TextureImagesFieldMask, _mfTextureImages);
962 return returnValue;
965 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleChunkMaterial (void) const
967 SFUnrecChunkMaterialPtr::GetHandlePtr returnValue(
968 new SFUnrecChunkMaterialPtr::GetHandle(
969 &_sfChunkMaterial,
970 this->getType().getFieldDesc(ChunkMaterialFieldId),
971 const_cast<ComputeShaderAlgorithmBase *>(this)));
973 return returnValue;
976 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleChunkMaterial (void)
978 SFUnrecChunkMaterialPtr::EditHandlePtr returnValue(
979 new SFUnrecChunkMaterialPtr::EditHandle(
980 &_sfChunkMaterial,
981 this->getType().getFieldDesc(ChunkMaterialFieldId),
982 this));
984 returnValue->setSetMethod(
985 boost::bind(&ComputeShaderAlgorithm::setChunkMaterial,
986 static_cast<ComputeShaderAlgorithm *>(this), _1));
988 editSField(ChunkMaterialFieldMask);
990 return returnValue;
993 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleComputeShader (void) const
995 SFUnrecComputeShaderChunkPtr::GetHandlePtr returnValue(
996 new SFUnrecComputeShaderChunkPtr::GetHandle(
997 &_sfComputeShader,
998 this->getType().getFieldDesc(ComputeShaderFieldId),
999 const_cast<ComputeShaderAlgorithmBase *>(this)));
1001 return returnValue;
1004 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleComputeShader (void)
1006 SFUnrecComputeShaderChunkPtr::EditHandlePtr returnValue(
1007 new SFUnrecComputeShaderChunkPtr::EditHandle(
1008 &_sfComputeShader,
1009 this->getType().getFieldDesc(ComputeShaderFieldId),
1010 this));
1012 returnValue->setSetMethod(
1013 boost::bind(&ComputeShaderAlgorithm::setComputeShader,
1014 static_cast<ComputeShaderAlgorithm *>(this), _1));
1016 editSField(ComputeShaderFieldMask);
1018 return returnValue;
1021 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleDispatchConfig (void) const
1023 SFVec3i::GetHandlePtr returnValue(
1024 new SFVec3i::GetHandle(
1025 &_sfDispatchConfig,
1026 this->getType().getFieldDesc(DispatchConfigFieldId),
1027 const_cast<ComputeShaderAlgorithmBase *>(this)));
1029 return returnValue;
1032 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleDispatchConfig (void)
1034 SFVec3i::EditHandlePtr returnValue(
1035 new SFVec3i::EditHandle(
1036 &_sfDispatchConfig,
1037 this->getType().getFieldDesc(DispatchConfigFieldId),
1038 this));
1041 editSField(DispatchConfigFieldMask);
1043 return returnValue;
1046 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleWorkGroupSize (void) const
1048 SFVec3i::GetHandlePtr returnValue(
1049 new SFVec3i::GetHandle(
1050 &_sfWorkGroupSize,
1051 this->getType().getFieldDesc(WorkGroupSizeFieldId),
1052 const_cast<ComputeShaderAlgorithmBase *>(this)));
1054 return returnValue;
1057 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleWorkGroupSize (void)
1059 SFVec3i::EditHandlePtr returnValue(
1060 new SFVec3i::EditHandle(
1061 &_sfWorkGroupSize,
1062 this->getType().getFieldDesc(WorkGroupSizeFieldId),
1063 this));
1066 editSField(WorkGroupSizeFieldMask);
1068 return returnValue;
1071 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleUseMemoryBarrier (void) const
1073 SFBool::GetHandlePtr returnValue(
1074 new SFBool::GetHandle(
1075 &_sfUseMemoryBarrier,
1076 this->getType().getFieldDesc(UseMemoryBarrierFieldId),
1077 const_cast<ComputeShaderAlgorithmBase *>(this)));
1079 return returnValue;
1082 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleUseMemoryBarrier(void)
1084 SFBool::EditHandlePtr returnValue(
1085 new SFBool::EditHandle(
1086 &_sfUseMemoryBarrier,
1087 this->getType().getFieldDesc(UseMemoryBarrierFieldId),
1088 this));
1091 editSField(UseMemoryBarrierFieldMask);
1093 return returnValue;
1096 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleUseVariableWorkGroupSize (void) const
1098 SFBool::GetHandlePtr returnValue(
1099 new SFBool::GetHandle(
1100 &_sfUseVariableWorkGroupSize,
1101 this->getType().getFieldDesc(UseVariableWorkGroupSizeFieldId),
1102 const_cast<ComputeShaderAlgorithmBase *>(this)));
1104 return returnValue;
1107 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleUseVariableWorkGroupSize(void)
1109 SFBool::EditHandlePtr returnValue(
1110 new SFBool::EditHandle(
1111 &_sfUseVariableWorkGroupSize,
1112 this->getType().getFieldDesc(UseVariableWorkGroupSizeFieldId),
1113 this));
1116 editSField(UseVariableWorkGroupSizeFieldMask);
1118 return returnValue;
1121 GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleMemoryBarrier (void) const
1123 SFGLenum::GetHandlePtr returnValue(
1124 new SFGLenum::GetHandle(
1125 &_sfMemoryBarrier,
1126 this->getType().getFieldDesc(MemoryBarrierFieldId),
1127 const_cast<ComputeShaderAlgorithmBase *>(this)));
1129 return returnValue;
1132 EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleMemoryBarrier (void)
1134 SFGLenum::EditHandlePtr returnValue(
1135 new SFGLenum::EditHandle(
1136 &_sfMemoryBarrier,
1137 this->getType().getFieldDesc(MemoryBarrierFieldId),
1138 this));
1141 editSField(MemoryBarrierFieldMask);
1143 return returnValue;
1147 #ifdef OSG_MT_CPTR_ASPECT
1148 void ComputeShaderAlgorithmBase::execSyncV( FieldContainer &oFrom,
1149 ConstFieldMaskArg whichField,
1150 AspectOffsetStore &oOffsets,
1151 ConstFieldMaskArg syncMode,
1152 const UInt32 uiSyncInfo)
1154 ComputeShaderAlgorithm *pThis = static_cast<ComputeShaderAlgorithm *>(this);
1156 pThis->execSync(static_cast<ComputeShaderAlgorithm *>(&oFrom),
1157 whichField,
1158 oOffsets,
1159 syncMode,
1160 uiSyncInfo);
1162 #endif
1165 #ifdef OSG_MT_CPTR_ASPECT
1166 FieldContainer *ComputeShaderAlgorithmBase::createAspectCopy(
1167 const FieldContainer *pRefAspect) const
1169 ComputeShaderAlgorithm *returnValue;
1171 newAspectCopy(returnValue,
1172 dynamic_cast<const ComputeShaderAlgorithm *>(pRefAspect),
1173 dynamic_cast<const ComputeShaderAlgorithm *>(this));
1175 return returnValue;
1177 #endif
1179 void ComputeShaderAlgorithmBase::resolveLinks(void)
1181 Inherited::resolveLinks();
1183 static_cast<ComputeShaderAlgorithm *>(this)->clearTextureImages();
1185 static_cast<ComputeShaderAlgorithm *>(this)->setChunkMaterial(NULL);
1187 static_cast<ComputeShaderAlgorithm *>(this)->setComputeShader(NULL);
1193 OSG_END_NAMESPACE