730 lines
28 KiB
C++
730 lines
28 KiB
C++
/* -*-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 {
|
|
///common interface for IndirectCommandDrawArrayss
|
|
class OSG_EXPORT IndirectCommandDrawArrays: public BufferData
|
|
{
|
|
public:
|
|
IndirectCommandDrawArrays():BufferData(){}
|
|
IndirectCommandDrawArrays(const IndirectCommandDrawArrays& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/)
|
|
:BufferData(copy, copyop){ }
|
|
|
|
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;
|
|
};
|
|
class OSG_EXPORT IndirectCommandDrawElements: public BufferData
|
|
{
|
|
public:
|
|
IndirectCommandDrawElements():BufferData(){}
|
|
IndirectCommandDrawElements(const IndirectCommandDrawElements& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/)
|
|
:BufferData(copy, copyop){}
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// DrawArraysCommand
|
|
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){};
|
|
unsigned int count;
|
|
unsigned int instanceCount;
|
|
unsigned int first;
|
|
unsigned int baseInstance;
|
|
};
|
|
|
|
/// default implementation of IndirectCommandDrawArrays
|
|
/// DefaultIndirectCommandDrawArrays to be hosted on GPU
|
|
class OSG_EXPORT DefaultIndirectCommandDrawArrays: public IndirectCommandDrawArrays, public MixinVector<DrawArraysIndirectCommand>
|
|
{
|
|
public:
|
|
META_Object(osg,DefaultIndirectCommandDrawArrays)
|
|
|
|
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 getTotalDataSize() const {
|
|
return 16u*static_cast<unsigned int>(size());
|
|
}
|
|
virtual unsigned int getElementSize()const {return 16u;};
|
|
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;}
|
|
virtual unsigned int getNumElements() const {return static_cast<unsigned int>(size());}
|
|
};
|
|
|
|
|
|
/// default implementation of IndirectCommandDrawElements
|
|
/// DrawElementsCommand
|
|
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){};
|
|
unsigned int count;
|
|
unsigned int instanceCount;
|
|
unsigned int firstIndex;
|
|
unsigned int baseVertex;
|
|
unsigned int baseInstance;
|
|
};
|
|
|
|
/// vector of DrawElementsCommand to be hosted on GPU
|
|
class OSG_EXPORT DefaultIndirectCommandDrawElements: public IndirectCommandDrawElements, public MixinVector<DrawElementsIndirectCommand>
|
|
{
|
|
public:
|
|
META_Object(osg,DefaultIndirectCommandDrawElements)
|
|
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();
|
|
}
|
|
virtual unsigned int getTotalDataSize() const {
|
|
return 20u*static_cast<unsigned int>(size());
|
|
}
|
|
|
|
virtual unsigned int getElementSize()const {return 20u;};
|
|
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;}
|
|
virtual unsigned int getNumElements() const {return static_cast<unsigned int>(size());}
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The DrawElementsIndirect base PrimitiveSet
|
|
///
|
|
class OSG_EXPORT DrawElementsIndirect : public DrawElements
|
|
{
|
|
public:
|
|
|
|
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());}
|
|
|
|
DrawElementsIndirect(const DrawElementsIndirect& rhs,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
DrawElements(rhs,copyop),_firstCommand(rhs._firstCommand), _stride(rhs._stride) {
|
|
_IndirectCommandDrawArrays=(DefaultIndirectCommandDrawElements*)copyop(rhs._IndirectCommandDrawArrays.get());
|
|
}
|
|
/// set command array of this indirect primitive set
|
|
inline void setIndirectCommandArray(IndirectCommandDrawElements*idc) {
|
|
_IndirectCommandDrawArrays = idc;
|
|
if(!_IndirectCommandDrawArrays->getBufferObject())
|
|
_IndirectCommandDrawArrays->setBufferObject(new osg::VertexBufferObject());
|
|
}
|
|
/// get command array of this indirect primitive set
|
|
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _IndirectCommandDrawArrays; }
|
|
inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _IndirectCommandDrawArrays; }
|
|
///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
|
|
inline void setFirstCommandToDraw( unsigned int i) { _firstCommand = i; }
|
|
/// get offset of the first command in the IndirectCommandDrawArrays
|
|
inline unsigned int getFirstCommandToDraw() const { return _firstCommand; }
|
|
/// stride (to set if you use custom CommandArray)
|
|
inline void setStride( GLsizei i) {
|
|
_stride=i;
|
|
}
|
|
/// stride (to set if you use custom CommandArray)
|
|
inline GLsizei getStride() const {
|
|
return _stride;
|
|
}
|
|
virtual unsigned int getNumPrimitives() const=0;
|
|
|
|
protected:
|
|
virtual ~DrawElementsIndirect() {}
|
|
|
|
unsigned int _firstCommand;
|
|
GLsizei _stride;
|
|
ref_ptr<IndirectCommandDrawElements> _IndirectCommandDrawArrays;
|
|
|
|
};
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The DrawElementsIndirectUByte PrimitiveSet
|
|
///
|
|
class OSG_EXPORT DrawElementsIndirectUByte : public DrawElementsIndirect, public VectorGLubyte
|
|
{
|
|
public:
|
|
|
|
typedef VectorGLubyte vector_type;
|
|
|
|
DrawElementsIndirectUByte(GLenum mode = 0,unsigned int firstCommand = 0, GLsizei stride = 0):
|
|
DrawElementsIndirect(DrawElementsUByteIndirectPrimitiveType,mode,firstCommand,stride) {}
|
|
|
|
DrawElementsIndirectUByte(const DrawElementsIndirectUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
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) :
|
|
DrawElementsIndirect(MultiDrawElementsUByteIndirectPrimitiveType,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.
|
|
*/
|
|
DrawElementsIndirectUByte(GLenum mode, unsigned int no) :
|
|
DrawElementsIndirect(MultiDrawElementsUByteIndirectPrimitiveType,mode),
|
|
vector_type(no) {}
|
|
|
|
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";
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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 {
|
|
return static_cast<unsigned int>(size());
|
|
}
|
|
virtual unsigned int index(unsigned int pos) const {
|
|
return (*this)[pos];
|
|
}
|
|
virtual void offsetIndices(int offset);
|
|
|
|
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));
|
|
}
|
|
virtual unsigned int getNumPrimitives() const;
|
|
protected:
|
|
|
|
virtual ~DrawElementsIndirectUByte();
|
|
};
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The DrawElementsIndirectUShort PrimitiveSet
|
|
///
|
|
class OSG_EXPORT DrawElementsIndirectUShort : public DrawElementsIndirect, public VectorGLushort
|
|
{
|
|
public:
|
|
|
|
typedef VectorGLushort vector_type;
|
|
|
|
DrawElementsIndirectUShort(GLenum mode = 0,unsigned int firstCommand = 0, GLsizei stride = 0):
|
|
DrawElementsIndirect(DrawElementsUShortIndirectPrimitiveType,mode,firstCommand,stride) {}
|
|
|
|
DrawElementsIndirectUShort(const DrawElementsIndirectUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
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) :
|
|
DrawElementsIndirect(MultiDrawElementsUShortIndirectPrimitiveType,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.
|
|
*/
|
|
DrawElementsIndirectUShort(GLenum mode, unsigned int no) :
|
|
DrawElementsIndirect(MultiDrawElementsUShortIndirectPrimitiveType,mode),
|
|
vector_type(no) {}
|
|
|
|
template <class InputIterator>
|
|
DrawElementsIndirectUShort(GLenum mode, InputIterator first,InputIterator last) :
|
|
DrawElementsIndirect(MultiDrawElementsUShortIndirectPrimitiveType,mode),
|
|
vector_type(first,last) {}
|
|
|
|
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";
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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 {
|
|
return static_cast<unsigned int>(size());
|
|
}
|
|
virtual unsigned int index(unsigned int pos) const {
|
|
return (*this)[pos];
|
|
}
|
|
virtual void offsetIndices(int offset);
|
|
|
|
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));
|
|
}
|
|
virtual unsigned int getNumPrimitives() const;
|
|
protected:
|
|
|
|
virtual ~DrawElementsIndirectUShort();
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The DrawElementsIndirectUInt PrimitiveSet
|
|
///
|
|
class OSG_EXPORT DrawElementsIndirectUInt : public DrawElementsIndirect, public VectorGLuint
|
|
{
|
|
public:
|
|
|
|
typedef VectorGLuint vector_type;
|
|
|
|
DrawElementsIndirectUInt(GLenum mode = 0,unsigned int firstCommand = 0, GLsizei stride = 0):
|
|
DrawElementsIndirect(DrawElementsUIntIndirectPrimitiveType,mode,firstCommand,stride) {}
|
|
|
|
DrawElementsIndirectUInt(const DrawElementsIndirectUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
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) :
|
|
DrawElementsIndirect(MultiDrawElementsUIntIndirectPrimitiveType,mode),
|
|
vector_type(no) {}
|
|
|
|
template <class InputIterator>
|
|
DrawElementsIndirectUInt(GLenum mode, InputIterator first,InputIterator last) :
|
|
DrawElementsIndirect(MultiDrawElementsUIntIndirectPrimitiveType,mode),
|
|
vector_type(first,last) {}
|
|
|
|
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";
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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 {
|
|
return static_cast<unsigned int>(size());
|
|
}
|
|
virtual unsigned int index(unsigned int pos) const {
|
|
return (*this)[pos];
|
|
}
|
|
virtual void offsetIndices(int offset);
|
|
|
|
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));
|
|
}
|
|
|
|
virtual unsigned int getNumPrimitives() const;
|
|
protected:
|
|
|
|
virtual ~DrawElementsIndirectUInt();
|
|
};
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The MultiDrawElementsIndirect PrimitiveSets
|
|
///
|
|
class OSG_EXPORT MultiDrawElementsIndirectUShort : public DrawElementsIndirectUShort
|
|
{
|
|
public:
|
|
MultiDrawElementsIndirectUShort(GLenum mode = 0,unsigned int firstCommand = 0,unsigned int commandcount = 0, GLsizei stride = 0):
|
|
DrawElementsIndirectUShort(mode,firstCommand,stride),_count(commandcount){_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
|
MultiDrawElementsIndirectUShort(const MultiDrawElementsIndirectUShort& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
DrawElementsIndirectUShort(mdi,copyop),_count(mdi._count) {}
|
|
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";
|
|
}
|
|
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
|
|
inline void setNumCommandsToDraw( unsigned int i) {
|
|
_count=i;
|
|
}
|
|
/// count of Indirect Command to execute
|
|
inline unsigned int getNumCommandsToDraw()const {
|
|
return _count;
|
|
}
|
|
protected:
|
|
unsigned int _count;
|
|
virtual ~MultiDrawElementsIndirectUShort();
|
|
};
|
|
|
|
class OSG_EXPORT MultiDrawElementsIndirectUByte : public DrawElementsIndirectUByte
|
|
{
|
|
public:
|
|
MultiDrawElementsIndirectUByte(GLenum mode = 0,unsigned int firstCommand = 0,unsigned int commandcount = 0, GLsizei stride = 0):
|
|
DrawElementsIndirectUByte(mode,firstCommand,stride),_count(commandcount){_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
|
MultiDrawElementsIndirectUByte(const MultiDrawElementsIndirectUByte& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
DrawElementsIndirectUByte(mdi,copyop),_count(mdi._count) {}
|
|
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";
|
|
}
|
|
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;
|
|
/// count of Indirect Command to execute
|
|
inline void setNumCommandsToDraw( unsigned int i) {
|
|
_count=i;
|
|
}
|
|
/// count of Indirect Command to execute
|
|
inline unsigned int getNumCommandsToDraw()const {
|
|
return _count;
|
|
}
|
|
protected:
|
|
unsigned int _count;
|
|
virtual ~MultiDrawElementsIndirectUByte();
|
|
};
|
|
class OSG_EXPORT MultiDrawElementsIndirectUInt : public DrawElementsIndirectUInt
|
|
{
|
|
public:
|
|
MultiDrawElementsIndirectUInt(GLenum mode = 0,unsigned int firstCommand = 0,unsigned int commandcount = 0, GLsizei stride = 0):
|
|
DrawElementsIndirectUInt(mode,firstCommand,stride),_count(commandcount){_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
|
MultiDrawElementsIndirectUInt(const MultiDrawElementsIndirectUInt& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
DrawElementsIndirectUInt(mdi,copyop),_count(mdi._count) {}
|
|
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";
|
|
}
|
|
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;
|
|
/// count of Indirect Command to execute
|
|
inline void setNumCommandsToDraw( unsigned int i) {
|
|
_count=i;
|
|
}
|
|
/// count of Indirect Command to execute
|
|
inline unsigned int getNumCommandsToDraw()const {
|
|
return _count;
|
|
}
|
|
protected:
|
|
unsigned int _count;
|
|
virtual ~MultiDrawElementsIndirectUInt();
|
|
};
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The MultiDrawArraysIndirect PrimitiveSet
|
|
///
|
|
class OSG_EXPORT DrawArraysIndirect : public osg::PrimitiveSet
|
|
{
|
|
public:
|
|
|
|
DrawArraysIndirect(GLenum mode=0, unsigned int firstcommand = 0, GLsizei stride = 0):
|
|
osg::PrimitiveSet(Type(DrawArraysIndirectPrimitiveType), mode),
|
|
_firstCommand(firstcommand), _stride(stride) {setIndirectCommandArray(new DefaultIndirectCommandDrawArrays);}
|
|
|
|
DrawArraysIndirect(const DrawArraysIndirect& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
osg::PrimitiveSet(dal,copyop),
|
|
_firstCommand(dal._firstCommand),
|
|
_stride(dal._stride),
|
|
_IndirectCommandDrawArrays((DefaultIndirectCommandDrawArrays*)copyop( dal._IndirectCommandDrawArrays.get()))
|
|
{}
|
|
|
|
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";
|
|
}
|
|
|
|
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;
|
|
|
|
/// stride (to set if you use custom CommandArray)
|
|
inline void setStride( GLsizei i) {
|
|
_stride=i;
|
|
}
|
|
/// stride (to set if you use custom CommandArray)
|
|
inline GLsizei getStride()const {
|
|
return _stride;
|
|
}
|
|
/// set offset of the first command in the IndirectCommandDrawArrays
|
|
inline void setFirstCommandToDraw( unsigned int i) {
|
|
_firstCommand=i;
|
|
}
|
|
/// get offset of the first command in the IndirectCommandDrawArrays
|
|
inline unsigned int getFirstCommandToDraw() const {
|
|
return _firstCommand;
|
|
}
|
|
|
|
inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc) {
|
|
_IndirectCommandDrawArrays = idc;
|
|
if(!_IndirectCommandDrawArrays->getBufferObject())
|
|
_IndirectCommandDrawArrays->setBufferObject(new osg::VertexBufferObject());
|
|
}
|
|
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const {
|
|
return _IndirectCommandDrawArrays;
|
|
}
|
|
inline IndirectCommandDrawArrays* getIndirectCommandArray(){
|
|
return _IndirectCommandDrawArrays;
|
|
}
|
|
|
|
protected:
|
|
|
|
unsigned int _firstCommand;
|
|
GLsizei _stride;
|
|
ref_ptr<IndirectCommandDrawArrays> _IndirectCommandDrawArrays;
|
|
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
/// \brief The MultiDrawArraysIndirect PrimitiveSet
|
|
///
|
|
class OSG_EXPORT MultiDrawArraysIndirect : public DrawArraysIndirect
|
|
{
|
|
public:
|
|
|
|
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);}
|
|
|
|
MultiDrawArraysIndirect(const MultiDrawArraysIndirect& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
osg::DrawArraysIndirect(dal,copyop), _count(dal._count)
|
|
{}
|
|
|
|
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";
|
|
}
|
|
|
|
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
|
|
inline void setNumCommandsToDraw( unsigned int i) {
|
|
_count=i;
|
|
}
|
|
/// count of Indirect Command to execute
|
|
inline unsigned int getNumCommandsToDraw()const {
|
|
return _count;
|
|
}
|
|
protected:
|
|
unsigned int _count;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
|
|