2017-07-27 02:25:41 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*
|
|
|
|
* osg/PrimitiveSetIndirect
|
|
|
|
* Author: Julien Valentin 2016-2017
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_INDIRECTPRIMITIVESET
|
|
|
|
#define OSG_INDIRECTPRIMITIVESET 1
|
|
|
|
|
|
|
|
#include <osg/PrimitiveSet>
|
|
|
|
|
|
|
|
|
|
|
|
namespace osg {
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
///common interface for IndirectCommandDrawArrayss
|
|
|
|
class OSG_EXPORT IndirectCommandDrawArrays: public BufferData
|
|
|
|
{
|
|
|
|
public:
|
2017-07-28 20:30:36 +08:00
|
|
|
IndirectCommandDrawArrays() : BufferData() { setBufferObject(new DrawIndirectBufferObject()); }
|
|
|
|
|
|
|
|
IndirectCommandDrawArrays(const IndirectCommandDrawArrays& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/) :
|
|
|
|
BufferData(copy, copyop) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-08-03 03:50:25 +08:00
|
|
|
virtual unsigned int getTotalDataSize() const { return getNumElements()*getElementSize(); }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual unsigned int & count(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & instanceCount(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & first(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & baseInstance(const unsigned int&index)=0;
|
|
|
|
|
|
|
|
virtual unsigned int getElementSize() const = 0;
|
|
|
|
virtual unsigned int getNumElements() const = 0;
|
2017-08-06 00:03:27 +08:00
|
|
|
virtual void reserveElements(const unsigned int) = 0;
|
|
|
|
virtual void resizeElements(const unsigned int) = 0;
|
2017-07-27 02:25:41 +08:00
|
|
|
};
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
class OSG_EXPORT IndirectCommandDrawElements: public BufferData
|
|
|
|
{
|
|
|
|
public:
|
2017-07-28 20:30:36 +08:00
|
|
|
IndirectCommandDrawElements() : BufferData() { setBufferObject(new DrawIndirectBufferObject()); }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
IndirectCommandDrawElements(const IndirectCommandDrawElements& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/)
|
2017-07-28 20:30:36 +08:00
|
|
|
: BufferData(copy, copyop) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-08-03 03:50:25 +08:00
|
|
|
virtual unsigned int getTotalDataSize() const { return getNumElements()*getElementSize(); }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual unsigned int & count(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & instanceCount(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & firstIndex(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & baseVertex(const unsigned int&index)=0;
|
|
|
|
virtual unsigned int & baseInstance(const unsigned int&index)=0;
|
|
|
|
|
|
|
|
virtual unsigned int getElementSize()const = 0;
|
|
|
|
virtual unsigned int getNumElements() const = 0;
|
2017-08-06 00:03:27 +08:00
|
|
|
virtual void reserveElements(const unsigned int) = 0;
|
|
|
|
virtual void resizeElements(const unsigned int) = 0;
|
2017-07-27 02:25:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// DrawArraysCommand
|
2017-07-28 20:30:36 +08:00
|
|
|
struct DrawArraysIndirectCommand
|
|
|
|
{
|
|
|
|
DrawArraysIndirectCommand(unsigned int pcount = 0, unsigned int pinstanceCount = 0, unsigned int pfirst = 0, unsigned int pbaseInstance = 0) :
|
|
|
|
count(pcount), instanceCount(pinstanceCount), first(pfirst), baseInstance(pbaseInstance) {}
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
unsigned int count;
|
|
|
|
unsigned int instanceCount;
|
|
|
|
unsigned int first;
|
|
|
|
unsigned int baseInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// default implementation of IndirectCommandDrawArrays
|
|
|
|
/// DefaultIndirectCommandDrawArrays to be hosted on GPU
|
2017-08-25 20:55:25 +08:00
|
|
|
class DefaultIndirectCommandDrawArrays: public IndirectCommandDrawArrays, public MixinVector<DrawArraysIndirectCommand>
|
2017-07-27 02:25:41 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
META_Object(osg,DefaultIndirectCommandDrawArrays)
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DefaultIndirectCommandDrawArrays() : IndirectCommandDrawArrays(), MixinVector<DrawArraysIndirectCommand>() {}
|
|
|
|
DefaultIndirectCommandDrawArrays(const DefaultIndirectCommandDrawArrays& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/) :
|
|
|
|
IndirectCommandDrawArrays(copy, copyop),MixinVector<DrawArraysIndirectCommand>() {}
|
|
|
|
|
|
|
|
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
|
|
|
|
virtual unsigned int getElementSize()const { return 16u; };
|
2017-08-03 03:50:25 +08:00
|
|
|
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(size()); }
|
2017-08-06 00:03:27 +08:00
|
|
|
virtual void reserveElements(const unsigned int n) {reserve(n);}
|
|
|
|
virtual void resizeElements(const unsigned int n) {resize(n);}
|
2017-08-03 03:50:25 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual unsigned int & count(const unsigned int&index) { return at(index).count; }
|
|
|
|
virtual unsigned int & instanceCount(const unsigned int&index) { return at(index).instanceCount; }
|
|
|
|
virtual unsigned int & first(const unsigned int&index) { return at(index).first; }
|
|
|
|
virtual unsigned int & baseInstance(const unsigned int&index) { return at(index).baseInstance; }
|
2017-08-03 03:50:25 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// default implementation of IndirectCommandDrawElements
|
|
|
|
/// DrawElementsCommand
|
2017-07-28 20:30:36 +08:00
|
|
|
struct DrawElementsIndirectCommand
|
|
|
|
{
|
|
|
|
DrawElementsIndirectCommand(unsigned int pcount = 0, unsigned int pinstanceCount = 0, unsigned int pfirstIndex = 0, unsigned int pbaseVertex = 0, unsigned int pbaseInstance = 0) :
|
|
|
|
count(pcount), instanceCount(pinstanceCount), firstIndex(pfirstIndex), baseVertex(pbaseVertex), baseInstance(pbaseInstance) {}
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
unsigned int count;
|
|
|
|
unsigned int instanceCount;
|
|
|
|
unsigned int firstIndex;
|
|
|
|
unsigned int baseVertex;
|
|
|
|
unsigned int baseInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// vector of DrawElementsCommand to be hosted on GPU
|
2017-08-25 20:55:25 +08:00
|
|
|
class DefaultIndirectCommandDrawElements: public IndirectCommandDrawElements, public MixinVector<DrawElementsIndirectCommand>
|
2017-07-27 02:25:41 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
META_Object(osg,DefaultIndirectCommandDrawElements)
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DefaultIndirectCommandDrawElements() : IndirectCommandDrawElements(), MixinVector<DrawElementsIndirectCommand>() {}
|
|
|
|
|
|
|
|
DefaultIndirectCommandDrawElements(const DefaultIndirectCommandDrawElements& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/) :
|
|
|
|
IndirectCommandDrawElements(copy, copyop), MixinVector<DrawElementsIndirectCommand>() {}
|
|
|
|
|
|
|
|
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
|
2017-08-03 03:50:25 +08:00
|
|
|
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(size()); }
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual unsigned int getElementSize()const { return 20u; };
|
2017-08-06 00:03:27 +08:00
|
|
|
virtual void reserveElements(const unsigned int n) {reserve(n);}
|
|
|
|
virtual void resizeElements(const unsigned int n) {resize(n);}
|
2017-08-03 03:50:25 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual unsigned int & count(const unsigned int&index) { return at(index).count; }
|
|
|
|
virtual unsigned int & instanceCount(const unsigned int&index) { return at(index).instanceCount; }
|
|
|
|
virtual unsigned int & firstIndex(const unsigned int&index) { return at(index).firstIndex; }
|
|
|
|
virtual unsigned int & baseVertex(const unsigned int&index) { return at(index).baseVertex; }
|
|
|
|
virtual unsigned int & baseInstance(const unsigned int&index) { return at(index).baseInstance; }
|
2017-08-03 03:50:25 +08:00
|
|
|
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The DrawElementsIndirect base PrimitiveSet
|
|
|
|
///
|
|
|
|
class OSG_EXPORT DrawElementsIndirect : public DrawElements
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawElementsIndirect(Type primType=PrimitiveType, GLenum mode = 0,unsigned int firstCommand = 0, GLsizei stride = 0) :
|
|
|
|
DrawElements(primType,mode, 0),_firstCommand(firstCommand),_stride(stride) { setIndirectCommandArray(new DefaultIndirectCommandDrawElements()); }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawElementsIndirect(const DrawElementsIndirect& rhs,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
|
|
|
DrawElements(rhs,copyop),_firstCommand(rhs._firstCommand), _stride(rhs._stride) { _indirectCommandArray=(DefaultIndirectCommandDrawElements*)copyop(rhs._indirectCommandArray.get()); }
|
2017-07-27 07:08:37 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// set command array of this indirect primitive set
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setIndirectCommandArray(IndirectCommandDrawElements*idc)
|
|
|
|
{
|
2017-07-27 07:08:37 +08:00
|
|
|
_indirectCommandArray = idc;
|
2017-07-27 18:27:55 +08:00
|
|
|
//ensure bo of idc is of the correct type
|
|
|
|
if(!dynamic_cast<DrawIndirectBufferObject* >(_indirectCommandArray->getBufferObject()))
|
|
|
|
_indirectCommandArray->setBufferObject(new DrawIndirectBufferObject());
|
2017-07-27 02:25:41 +08:00
|
|
|
}
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// get command array of this indirect primitive set
|
2017-10-19 18:57:53 +08:00
|
|
|
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray.get(); }
|
|
|
|
inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _indirectCommandArray.get(); }
|
2017-07-27 07:08:37 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
///Further methods are for advanced DI when you plan to use your own IndirectCommandElement (stride)
|
|
|
|
///or if you want to draw a particular command index of the IndirectCommandElement(FirstCommandToDraw)
|
|
|
|
|
|
|
|
/// set offset of the first command to draw in the IndirectCommandDrawArrays
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setFirstCommandToDraw( unsigned int i) { _firstCommand = i; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// get offset of the first command in the IndirectCommandDrawArrays
|
2017-07-28 20:30:36 +08:00
|
|
|
inline unsigned int getFirstCommandToDraw() const { return _firstCommand; }
|
2017-07-27 07:08:37 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// stride (to set if you use custom CommandArray)
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setStride( GLsizei i) { _stride=i; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// stride (to set if you use custom CommandArray)
|
2017-07-28 20:30:36 +08:00
|
|
|
inline GLsizei getStride() const { return _stride; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual unsigned int getNumPrimitives() const=0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~DrawElementsIndirect() {}
|
|
|
|
|
|
|
|
unsigned int _firstCommand;
|
|
|
|
GLsizei _stride;
|
2017-07-27 07:08:37 +08:00
|
|
|
ref_ptr<IndirectCommandDrawElements> _indirectCommandArray;
|
2017-07-27 02:25:41 +08:00
|
|
|
};
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The DrawElementsIndirectUByte PrimitiveSet
|
|
|
|
///
|
|
|
|
class OSG_EXPORT DrawElementsIndirectUByte : public DrawElementsIndirect, public VectorGLubyte
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef VectorGLubyte vector_type;
|
|
|
|
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirectUByte(GLenum mode = 0/*,unsigned int firstCommand = 0, GLsizei stride = 0*/) :
|
|
|
|
DrawElementsIndirect(DrawElementsUByteIndirectPrimitiveType,mode) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawElementsIndirectUByte(const DrawElementsIndirectUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
DrawElementsIndirect(array,copyop),
|
|
|
|
vector_type(array) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
* \param ptr Pointer to a GLubyte to copy index data from.
|
|
|
|
*/
|
|
|
|
DrawElementsIndirectUByte(GLenum mode, unsigned int no, const GLubyte* ptr) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUByteIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(ptr,ptr+no) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
*/
|
|
|
|
DrawElementsIndirectUByte(GLenum mode, unsigned int no) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUByteIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(no) {}
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual Object* cloneType() const { return new DrawElementsIndirectUByte(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsIndirectUByte(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsIndirectUByte*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "DrawElementsIndirectUByte"; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
|
|
|
|
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(size()); }
|
|
|
|
virtual bool supportsBufferObject() const { return false; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
|
|
|
|
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual void offsetIndices(int offset);
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual GLenum getDataType() { return GL_UNSIGNED_BYTE; }
|
|
|
|
|
|
|
|
virtual void resizeElements(unsigned int numIndices) { resize(numIndices); }
|
|
|
|
virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); }
|
|
|
|
|
|
|
|
virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; }
|
|
|
|
virtual unsigned int getElement(unsigned int i) { return (*this)[i]; }
|
|
|
|
|
|
|
|
virtual void addElement(unsigned int v) { push_back(GLubyte(v)); }
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual unsigned int getNumPrimitives() const;
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~DrawElementsIndirectUByte();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The DrawElementsIndirectUShort PrimitiveSet
|
|
|
|
///
|
|
|
|
class OSG_EXPORT DrawElementsIndirectUShort : public DrawElementsIndirect, public VectorGLushort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef VectorGLushort vector_type;
|
|
|
|
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirectUShort(GLenum mode = 0/*,unsigned int firstCommand = 0, GLsizei stride = 0*/) :
|
|
|
|
DrawElementsIndirect(DrawElementsUShortIndirectPrimitiveType,mode) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawElementsIndirectUShort(const DrawElementsIndirectUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
DrawElementsIndirect(array,copyop),
|
|
|
|
vector_type(array) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
* \param ptr Pointer to a GLushort to copy index data from.
|
|
|
|
*/
|
|
|
|
DrawElementsIndirectUShort(GLenum mode, unsigned int no, const GLushort* ptr) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUShortIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(ptr,ptr+no) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
*/
|
|
|
|
DrawElementsIndirectUShort(GLenum mode, unsigned int no) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUShortIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(no) {}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
DrawElementsIndirectUShort(GLenum mode, InputIterator first,InputIterator last) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUShortIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(first,last) {}
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual Object* cloneType() const { return new DrawElementsIndirectUShort(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsIndirectUShort(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsIndirectUShort*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "DrawElementsIndirectUShort"; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
|
|
|
|
virtual unsigned int getTotalDataSize() const { return 2u*static_cast<unsigned int>(size()); }
|
|
|
|
virtual bool supportsBufferObject() const { return false; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
|
|
|
|
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual void offsetIndices(int offset);
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual GLenum getDataType() { return GL_UNSIGNED_SHORT; }
|
|
|
|
virtual void resizeElements(unsigned int numIndices) { resize(numIndices); }
|
|
|
|
virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); }
|
|
|
|
|
|
|
|
virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; }
|
|
|
|
virtual unsigned int getElement(unsigned int i) { return (*this)[i]; }
|
|
|
|
|
|
|
|
virtual void addElement(unsigned int v) { push_back(GLushort(v)); }
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual unsigned int getNumPrimitives() const;
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~DrawElementsIndirectUShort();
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The DrawElementsIndirectUInt PrimitiveSet
|
|
|
|
///
|
|
|
|
class OSG_EXPORT DrawElementsIndirectUInt : public DrawElementsIndirect, public VectorGLuint
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef VectorGLuint vector_type;
|
|
|
|
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirectUInt(GLenum mode = 0/*,unsigned int firstCommand = 0, GLsizei stride = 0*/) :
|
|
|
|
DrawElementsIndirect(DrawElementsUIntIndirectPrimitiveType,mode) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawElementsIndirectUInt(const DrawElementsIndirectUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
DrawElementsIndirect(array,copyop),
|
|
|
|
vector_type(array) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
|
|
|
*/
|
|
|
|
DrawElementsIndirectUInt(GLenum mode, unsigned int no, const GLuint* ptr) :
|
|
|
|
DrawElementsIndirect(DrawElementsUIntIndirectPrimitiveType,mode),
|
|
|
|
vector_type(ptr,ptr+no) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
*/
|
|
|
|
DrawElementsIndirectUInt(GLenum mode, unsigned int no) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUIntIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(no) {}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
DrawElementsIndirectUInt(GLenum mode, InputIterator first,InputIterator last) :
|
2017-08-03 03:50:25 +08:00
|
|
|
DrawElementsIndirect(DrawElementsUIntIndirectPrimitiveType,mode),
|
2017-07-27 02:25:41 +08:00
|
|
|
vector_type(first,last) {}
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual Object* cloneType() const { return new DrawElementsIndirectUInt(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsIndirectUInt(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsIndirectUInt*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "DrawElementsIndirectUInt"; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
|
|
|
|
virtual unsigned int getTotalDataSize() const { return 4u*static_cast<unsigned int>(size()); }
|
|
|
|
virtual bool supportsBufferObject() const { return false; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
|
|
|
|
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual void offsetIndices(int offset);
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual GLenum getDataType() { return GL_UNSIGNED_INT; }
|
|
|
|
virtual void resizeElements(unsigned int numIndices) { resize(numIndices); }
|
|
|
|
virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); }
|
|
|
|
virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; }
|
|
|
|
virtual unsigned int getElement(unsigned int i) { return (*this)[i]; }
|
|
|
|
virtual void addElement(unsigned int v) { push_back(GLuint(v)); }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~DrawElementsIndirectUInt();
|
|
|
|
};
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The MultiDrawElementsIndirect PrimitiveSets
|
|
|
|
///
|
|
|
|
class OSG_EXPORT MultiDrawElementsIndirectUShort : public DrawElementsIndirectUShort
|
|
|
|
{
|
|
|
|
public:
|
2017-08-03 03:50:25 +08:00
|
|
|
MultiDrawElementsIndirectUShort(GLenum mode = 0/*,unsigned int firstCommand = 0, GLsizei stride = 0*/) :
|
|
|
|
DrawElementsIndirectUShort(mode),_count(0) { _primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType)); }
|
2017-07-28 20:30:36 +08:00
|
|
|
|
|
|
|
MultiDrawElementsIndirectUShort(const MultiDrawElementsIndirectUShort& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
DrawElementsIndirectUShort(mdi,copyop),_count(mdi._count) {}
|
2017-08-03 03:50:25 +08:00
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
|
|
|
*/
|
|
|
|
MultiDrawElementsIndirectUShort(GLenum mode, unsigned int no, const GLushort* ptr) :
|
|
|
|
DrawElementsIndirectUShort(mode,no,ptr)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
*/
|
|
|
|
MultiDrawElementsIndirectUShort(GLenum mode, unsigned int no) :
|
|
|
|
DrawElementsIndirectUShort(mode,no)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
MultiDrawElementsIndirectUShort(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
DrawElementsIndirectUShort(mode,first,last)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
2017-07-28 20:30:36 +08:00
|
|
|
|
|
|
|
virtual osg::Object* cloneType() const { return new MultiDrawElementsIndirectUShort(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawElementsIndirectUShort(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const MultiDrawElementsIndirectUShort*>(obj)!=NULL; }
|
|
|
|
virtual const char* className() const { return "MultiDrawElementsIndirectUShort"; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
|
|
|
|
|
|
|
///if you want to draw a subset of the IndirectCommandElement(FirstCommandToDraw,NumCommandsToDraw)
|
|
|
|
|
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setNumCommandsToDraw( unsigned int i) { _count=i; }
|
2017-07-27 02:25:41 +08:00
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline unsigned int getNumCommandsToDraw()const { return _count; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
unsigned int _count;
|
|
|
|
virtual ~MultiDrawElementsIndirectUShort();
|
|
|
|
};
|
|
|
|
|
|
|
|
class OSG_EXPORT MultiDrawElementsIndirectUByte : public DrawElementsIndirectUByte
|
|
|
|
{
|
|
|
|
public:
|
2017-08-03 03:50:25 +08:00
|
|
|
MultiDrawElementsIndirectUByte(GLenum mode = 0) :
|
|
|
|
DrawElementsIndirectUByte(mode),_count(0) { _primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType)); }
|
2017-07-28 20:30:36 +08:00
|
|
|
|
|
|
|
MultiDrawElementsIndirectUByte(const MultiDrawElementsIndirectUByte& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
DrawElementsIndirectUByte(mdi,copyop),_count(mdi._count) {}
|
2017-08-03 03:50:25 +08:00
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
|
|
|
*/
|
|
|
|
MultiDrawElementsIndirectUByte(GLenum mode, unsigned int no, const GLubyte* ptr) :
|
|
|
|
DrawElementsIndirectUByte(mode,no,ptr)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
*/
|
|
|
|
MultiDrawElementsIndirectUByte(GLenum mode, unsigned int no) :
|
|
|
|
DrawElementsIndirectUByte(mode,no)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
MultiDrawElementsIndirectUByte(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
DrawElementsIndirectUByte(mode,first,last)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
2017-07-28 20:30:36 +08:00
|
|
|
|
|
|
|
virtual osg::Object* cloneType() const { return new MultiDrawElementsIndirectUByte(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawElementsIndirectUByte(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const MultiDrawElementsIndirectUByte*>(obj)!=NULL; }
|
|
|
|
virtual const char* className() const { return "MultiDrawElementsIndirectUByte"; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setNumCommandsToDraw( unsigned int i) { _count=i; }
|
2017-07-27 02:25:41 +08:00
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline unsigned int getNumCommandsToDraw()const { return _count; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
unsigned int _count;
|
|
|
|
virtual ~MultiDrawElementsIndirectUByte();
|
|
|
|
};
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
class OSG_EXPORT MultiDrawElementsIndirectUInt : public DrawElementsIndirectUInt
|
|
|
|
{
|
|
|
|
public:
|
2017-08-03 03:50:25 +08:00
|
|
|
MultiDrawElementsIndirectUInt(GLenum mode = 0) :
|
|
|
|
DrawElementsIndirectUInt(mode),_count(0) { _primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType)); }
|
2017-07-28 20:30:36 +08:00
|
|
|
|
|
|
|
MultiDrawElementsIndirectUInt(const MultiDrawElementsIndirectUInt& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
DrawElementsIndirectUInt(mdi,copyop),_count(mdi._count) {}
|
2017-08-03 03:50:25 +08:00
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
|
|
|
*/
|
|
|
|
MultiDrawElementsIndirectUInt(GLenum mode, unsigned int no, const GLuint* ptr) :
|
|
|
|
DrawElementsIndirectUInt(mode,no,ptr)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
|
|
|
* \param no Number of intended elements. This will be the size of the underlying vector.
|
|
|
|
*/
|
|
|
|
MultiDrawElementsIndirectUInt(GLenum mode, unsigned int no) :
|
|
|
|
DrawElementsIndirectUInt(mode,no)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
MultiDrawElementsIndirectUInt(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
DrawElementsIndirectUInt(mode,first,last)
|
|
|
|
{_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
2017-07-28 20:30:36 +08:00
|
|
|
|
|
|
|
virtual osg::Object* cloneType() const { return new MultiDrawElementsIndirectUInt(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawElementsIndirectUInt(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const MultiDrawElementsIndirectUInt*>(obj)!=NULL; }
|
|
|
|
virtual const char* className() const { return "MultiDrawElementsIndirectUInt"; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setNumCommandsToDraw( unsigned int i) { _count=i; }
|
2017-07-27 02:25:41 +08:00
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline unsigned int getNumCommandsToDraw()const { return _count; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
unsigned int _count;
|
|
|
|
virtual ~MultiDrawElementsIndirectUInt();
|
|
|
|
};
|
2017-07-28 20:30:36 +08:00
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The MultiDrawArraysIndirect PrimitiveSet
|
|
|
|
///
|
|
|
|
class OSG_EXPORT DrawArraysIndirect : public osg::PrimitiveSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawArraysIndirect(GLenum mode=0, unsigned int firstcommand = 0, GLsizei stride = 0) :
|
2017-07-27 02:25:41 +08:00
|
|
|
osg::PrimitiveSet(Type(DrawArraysIndirectPrimitiveType), mode),
|
2017-07-28 20:30:36 +08:00
|
|
|
_firstCommand(firstcommand), _stride(stride) { setIndirectCommandArray(new DefaultIndirectCommandDrawArrays); }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
DrawArraysIndirect(const DrawArraysIndirect& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
2017-07-27 02:25:41 +08:00
|
|
|
osg::PrimitiveSet(dal,copyop),
|
|
|
|
_firstCommand(dal._firstCommand),
|
|
|
|
_stride(dal._stride),
|
2017-07-28 20:30:36 +08:00
|
|
|
_indirectCommandArray((DefaultIndirectCommandDrawArrays*)copyop( dal._indirectCommandArray.get())) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new DrawArraysIndirect(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new DrawArraysIndirect(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const DrawArraysIndirect*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "DrawArraysIndirect"; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
|
|
|
|
virtual unsigned int getNumIndices() const;
|
|
|
|
virtual unsigned int index(unsigned int pos) const;
|
|
|
|
virtual void offsetIndices(int offset);
|
|
|
|
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
|
|
|
|
2017-07-27 05:36:55 +08:00
|
|
|
/// stride (to set if you use custom CommandArray)
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setStride( GLsizei i) { _stride=i; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// stride (to set if you use custom CommandArray)
|
2017-07-28 20:30:36 +08:00
|
|
|
inline GLsizei getStride()const { return _stride; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// set offset of the first command in the IndirectCommandDrawArrays
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setFirstCommandToDraw( unsigned int i) { _firstCommand=i; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
/// get offset of the first command in the IndirectCommandDrawArrays
|
2017-07-28 20:30:36 +08:00
|
|
|
inline unsigned int getFirstCommandToDraw() const { return _firstCommand; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc)
|
|
|
|
{
|
2017-07-27 07:08:37 +08:00
|
|
|
_indirectCommandArray = idc;
|
2017-07-27 18:27:55 +08:00
|
|
|
//ensure bo of idc is of the correct type
|
|
|
|
if(!dynamic_cast<DrawIndirectBufferObject* >(_indirectCommandArray->getBufferObject()))
|
|
|
|
_indirectCommandArray->setBufferObject(new DrawIndirectBufferObject());
|
2017-07-27 02:25:41 +08:00
|
|
|
}
|
2017-10-19 18:57:53 +08:00
|
|
|
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const { return _indirectCommandArray.get(); }
|
|
|
|
inline IndirectCommandDrawArrays* getIndirectCommandArray() { return _indirectCommandArray.get(); }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
unsigned int _firstCommand;
|
|
|
|
GLsizei _stride;
|
2017-07-27 07:08:37 +08:00
|
|
|
ref_ptr<IndirectCommandDrawArrays> _indirectCommandArray;
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// \brief The MultiDrawArraysIndirect PrimitiveSet
|
|
|
|
///
|
|
|
|
class OSG_EXPORT MultiDrawArraysIndirect : public DrawArraysIndirect
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
MultiDrawArraysIndirect(GLenum mode=0, unsigned int firstcommand = 0, unsigned int count = 0, GLsizei stride = 0) :
|
|
|
|
osg::DrawArraysIndirect(mode, firstcommand, stride), _count(count) { _primitiveType=Type(MultiDrawArraysIndirectPrimitiveType); }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
MultiDrawArraysIndirect(const MultiDrawArraysIndirect& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
|
|
|
osg::DrawArraysIndirect(dal,copyop), _count(dal._count) {}
|
2017-07-27 02:25:41 +08:00
|
|
|
|
2017-07-28 20:30:36 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new MultiDrawArraysIndirect(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawArraysIndirect(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const MultiDrawArraysIndirect*>(obj)!=NULL; }
|
|
|
|
virtual const char* className() const { return "MultiDrawArraysIndirect"; }
|
2017-07-27 02:25:41 +08:00
|
|
|
|
|
|
|
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
|
|
|
|
|
|
|
virtual void accept(PrimitiveFunctor& functor) const;
|
|
|
|
virtual void accept(PrimitiveIndexFunctor& functor) const;
|
|
|
|
|
|
|
|
virtual unsigned int getNumIndices() const;
|
|
|
|
virtual unsigned int index(unsigned int pos) const;
|
|
|
|
virtual void offsetIndices(int offset);
|
|
|
|
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
|
|
|
|
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline void setNumCommandsToDraw( unsigned int i) { _count=i; }
|
2017-07-27 02:25:41 +08:00
|
|
|
/// count of Indirect Command to execute
|
2017-07-28 20:30:36 +08:00
|
|
|
inline unsigned int getNumCommandsToDraw()const { return _count; }
|
|
|
|
|
2017-07-27 02:25:41 +08:00
|
|
|
protected:
|
|
|
|
unsigned int _count;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|