Merge pull request #277 from mp3butcher/MDI2
PrimitiveSetIndirect cleanup + serializers
This commit is contained in:
@@ -206,7 +206,7 @@ struct IndirectTarget
|
||||
|
||||
for(unsigned int j=0;j<indirectCommands->size(); ++j){
|
||||
osg::DrawArraysIndirect *ipr=new osg::DrawArraysIndirect( GL_TRIANGLES, j );
|
||||
ipr->setIndirectCommandDrawArrays( indirectCommands);
|
||||
ipr->setIndirectCommandArray( indirectCommands);
|
||||
newPrimitiveSets.push_back(ipr);
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ struct IndirectTarget
|
||||
else // use glMultiDrawArraysIndirect()
|
||||
{
|
||||
osg::MultiDrawArraysIndirect *ipr=new osg::MultiDrawArraysIndirect( GL_TRIANGLES );
|
||||
ipr->setIndirectCommandDrawArrays( indirectCommands );
|
||||
ipr->setIndirectCommandArray( indirectCommands );
|
||||
geometryAggregator->getAggregatedGeometry()->removePrimitiveSet(0,geometryAggregator->getAggregatedGeometry()->getNumPrimitiveSets() );
|
||||
geometryAggregator->getAggregatedGeometry()->addPrimitiveSet( ipr );
|
||||
}
|
||||
|
||||
@@ -201,29 +201,6 @@ class OSG_EXPORT ShaderStorageBufferBinding : public BufferIndexBinding
|
||||
}
|
||||
};
|
||||
|
||||
class OSG_EXPORT DrawIndirectBufferBinding : public BufferIndexBinding
|
||||
{
|
||||
public:
|
||||
DrawIndirectBufferBinding();
|
||||
/** Create a binding for a uniform buffer index target.
|
||||
* @param bo associated buffer object
|
||||
*/
|
||||
DrawIndirectBufferBinding( BufferObject* bo);
|
||||
void apply(State& state) const;
|
||||
DrawIndirectBufferBinding(const DrawIndirectBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, DrawIndirectBufferBinding, INDIRECTDRAWBUFFERBINDING);
|
||||
|
||||
virtual int compare(const StateAttribute& bb) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(DrawIndirectBufferBinding, bb)
|
||||
COMPARE_StateAttribute_Parameter(_target)
|
||||
COMPARE_StateAttribute_Parameter(_bufferObject)
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace osg
|
||||
|
||||
#endif
|
||||
|
||||
@@ -137,39 +137,37 @@ 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){setIndirectCommandDrawArrays(new DefaultIndirectCommandDrawElements());}
|
||||
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());
|
||||
_indirectCommandArray=(DefaultIndirectCommandDrawElements*)copyop(rhs._indirectCommandArray.get());
|
||||
}
|
||||
|
||||
/// set command array of this indirect primitive set
|
||||
inline void setIndirectCommandDrawArrays(IndirectCommandDrawElements*idc) {
|
||||
_IndirectCommandDrawArrays = idc;
|
||||
if(!_IndirectCommandDrawArrays->getBufferObject())
|
||||
_IndirectCommandDrawArrays->setBufferObject(new osg::VertexBufferObject());
|
||||
inline void setIndirectCommandArray(IndirectCommandDrawElements*idc) {
|
||||
_indirectCommandArray = idc;
|
||||
if(!_indirectCommandArray->getBufferObject())
|
||||
_indirectCommandArray->setBufferObject(new osg::VertexBufferObject());
|
||||
}
|
||||
/// get command array of this indirect primitive set
|
||||
inline IndirectCommandDrawElements* getIndirectCommandDrawArrays()const {
|
||||
return _IndirectCommandDrawArrays;
|
||||
}
|
||||
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray; }
|
||||
inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _indirectCommandArray; }
|
||||
|
||||
///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;
|
||||
}
|
||||
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 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 {
|
||||
inline GLsizei getStride() const {
|
||||
return _stride;
|
||||
}
|
||||
virtual unsigned int getNumPrimitives() const=0;
|
||||
@@ -179,7 +177,7 @@ protected:
|
||||
|
||||
unsigned int _firstCommand;
|
||||
GLsizei _stride;
|
||||
ref_ptr<IndirectCommandDrawElements> _IndirectCommandDrawArrays;
|
||||
ref_ptr<IndirectCommandDrawElements> _indirectCommandArray;
|
||||
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -491,7 +489,18 @@ public:
|
||||
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;
|
||||
@@ -519,6 +528,18 @@ public:
|
||||
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;
|
||||
@@ -542,7 +563,18 @@ public:
|
||||
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;
|
||||
@@ -568,13 +600,13 @@ public:
|
||||
|
||||
DrawArraysIndirect(GLenum mode=0, unsigned int firstcommand = 0, GLsizei stride = 0):
|
||||
osg::PrimitiveSet(Type(DrawArraysIndirectPrimitiveType), mode),
|
||||
_firstCommand(firstcommand), _stride(stride) {setIndirectCommandDrawArrays(new DefaultIndirectCommandDrawArrays);}
|
||||
_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()))
|
||||
_indirectCommandArray((DefaultIndirectCommandDrawArrays*)copyop( dal._indirectCommandArray.get()))
|
||||
{}
|
||||
|
||||
virtual osg::Object* cloneType() const {
|
||||
@@ -604,8 +636,8 @@ public:
|
||||
|
||||
virtual unsigned int getNumPrimitives() const;
|
||||
|
||||
/// stride (to set if you use custom CommandArray)
|
||||
inline void setStride( GLsizei i) {
|
||||
/// stride (to set if you use custom CommandArray)
|
||||
inline void setStride( GLsizei i) {
|
||||
_stride=i;
|
||||
}
|
||||
/// stride (to set if you use custom CommandArray)
|
||||
@@ -613,28 +645,31 @@ public:
|
||||
return _stride;
|
||||
}
|
||||
/// set offset of the first command in the IndirectCommandDrawArrays
|
||||
inline void setFirstCommand( unsigned int i) {
|
||||
inline void setFirstCommandToDraw( unsigned int i) {
|
||||
_firstCommand=i;
|
||||
}
|
||||
/// get offset of the first command in the IndirectCommandDrawArrays
|
||||
inline unsigned int getFirstCommand()const {
|
||||
inline unsigned int getFirstCommandToDraw() const {
|
||||
return _firstCommand;
|
||||
}
|
||||
|
||||
inline void setIndirectCommandDrawArrays(IndirectCommandDrawArrays*idc) {
|
||||
_IndirectCommandDrawArrays = idc;
|
||||
if(!_IndirectCommandDrawArrays->getBufferObject())
|
||||
_IndirectCommandDrawArrays->setBufferObject(new osg::VertexBufferObject());
|
||||
inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc) {
|
||||
_indirectCommandArray = idc;
|
||||
if(!_indirectCommandArray->getBufferObject())
|
||||
_indirectCommandArray->setBufferObject(new osg::VertexBufferObject());
|
||||
}
|
||||
inline IndirectCommandDrawArrays* getIndirectCommandDrawArrays()const {
|
||||
return _IndirectCommandDrawArrays;
|
||||
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const {
|
||||
return _indirectCommandArray;
|
||||
}
|
||||
inline IndirectCommandDrawArrays* getIndirectCommandArray(){
|
||||
return _indirectCommandArray;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _firstCommand;
|
||||
GLsizei _stride;
|
||||
ref_ptr<IndirectCommandDrawArrays> _IndirectCommandDrawArrays;
|
||||
ref_ptr<IndirectCommandDrawArrays> _indirectCommandArray;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -18,10 +18,6 @@
|
||||
|
||||
#include <string.h> // for memcpy
|
||||
|
||||
#ifndef GL_DRAW_INDIRECT_BUFFER
|
||||
#define GL_DRAW_INDIRECT_BUFFER 0x8F3F
|
||||
#endif
|
||||
|
||||
namespace osg {
|
||||
|
||||
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index)
|
||||
@@ -172,37 +168,4 @@ ShaderStorageBufferBinding::ShaderStorageBufferBinding(const ShaderStorageBuffer
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DrawIndirectBufferBinding::DrawIndirectBufferBinding( )
|
||||
: BufferIndexBinding(GL_DRAW_INDIRECT_BUFFER, 0)
|
||||
{
|
||||
}
|
||||
void DrawIndirectBufferBinding::apply(State& state) const
|
||||
{
|
||||
if (_bufferObject.valid())
|
||||
{
|
||||
GLBufferObject* glObject
|
||||
= _bufferObject->getOrCreateGLBufferObject(state.getContextID());
|
||||
if (!glObject->_extensions->isUniformBufferObjectSupported)
|
||||
return;
|
||||
// if (glObject->isDirty()) glObject->compileBuffer();
|
||||
glObject->_extensions->glBindBuffer (_target, glObject->getGLObjectID());
|
||||
}
|
||||
}
|
||||
DrawIndirectBufferBinding::DrawIndirectBufferBinding( BufferObject* bo)
|
||||
: BufferIndexBinding(GL_DRAW_INDIRECT_BUFFER, 0, bo, 0, 0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DrawIndirectBufferBinding::DrawIndirectBufferBinding(const DrawIndirectBufferBinding& rhs,
|
||||
const CopyOp& copyop)
|
||||
: BufferIndexBinding(rhs, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace osg
|
||||
|
||||
@@ -20,16 +20,19 @@
|
||||
#include <osg/Notify>
|
||||
#include <assert.h>
|
||||
|
||||
/// TODO: add base vertex feature to PrimitiveFunctor and PrimitiveIndexFunctor
|
||||
//#define PRIMFUNCTORBASEVERTEX 1
|
||||
|
||||
using namespace osg;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DrawElementsIndirect
|
||||
//
|
||||
template<class T> inline
|
||||
unsigned int getNumPrimitivesDI( const T&_this)
|
||||
template<class T>
|
||||
inline unsigned int getNumPrimitivesDI( const T&_this )
|
||||
{
|
||||
unsigned int offset= _this.getFirstCommandToDraw();
|
||||
IndirectCommandDrawElements *cmd=_this.getIndirectCommandDrawArrays();
|
||||
IndirectCommandDrawElements *cmd=const_cast<IndirectCommandDrawElements *>(_this.getIndirectCommandArray());
|
||||
unsigned int total=0;
|
||||
switch(_this.getMode())
|
||||
{
|
||||
@@ -60,7 +63,7 @@ unsigned int DrawElementsIndirectUByte::getNumPrimitives() const{return getNumPr
|
||||
unsigned int DrawElementsIndirectUShort::getNumPrimitives() const{return getNumPrimitivesDI<DrawElementsIndirectUShort>(*this);}
|
||||
|
||||
void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const
|
||||
{ GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
|
||||
GLenum mode = _mode;
|
||||
@@ -76,8 +79,8 @@ void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) c
|
||||
state.bindElementBufferObject(ebo);
|
||||
|
||||
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_INT,
|
||||
(const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex()) //command array adress
|
||||
+_firstCommand* _IndirectCommandDrawArrays->getElementSize())// runtime offset computaion can be sizeof(*_IndirectCommandDrawArrays->begin())
|
||||
(const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex()) //command array adress
|
||||
+_firstCommand* _indirectCommandArray->getElementSize())// runtime offset computaion can be sizeof(*_indirectCommandArray->begin())
|
||||
);
|
||||
|
||||
}
|
||||
@@ -97,24 +100,28 @@ void DrawElementsIndirectUInt::offsetIndices(int offset)
|
||||
}
|
||||
void DrawElementsIndirectUInt::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() && cmd)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)]
|
||||
_IndirectCommandDrawArrays->baseVertex(_firstCommand));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
// TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
if (!empty())
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
|
||||
&(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
|
||||
,_indirectCommandArray->baseVertex(_firstCommand));
|
||||
#endif
|
||||
}
|
||||
|
||||
void DrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() && cmd)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)]
|
||||
_IndirectCommandDrawArrays->baseVertex(_firstCommand));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
// TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
if (!empty())
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
|
||||
&(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
|
||||
,_indirectCommandArray->baseVertex(_firstCommand));
|
||||
#endif
|
||||
|
||||
}
|
||||
void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const
|
||||
{ GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
|
||||
GLenum mode = _mode;
|
||||
@@ -129,8 +136,8 @@ void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects)
|
||||
|
||||
state.bindElementBufferObject(ebo);
|
||||
|
||||
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_BYTE, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())
|
||||
+_firstCommand* _IndirectCommandDrawArrays->getElementSize()));
|
||||
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_BYTE, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())
|
||||
+_firstCommand* _indirectCommandArray->getElementSize()));
|
||||
|
||||
}
|
||||
DrawElementsIndirectUByte::~DrawElementsIndirectUByte()
|
||||
@@ -148,24 +155,27 @@ void DrawElementsIndirectUByte::offsetIndices(int offset)
|
||||
}
|
||||
void DrawElementsIndirectUByte::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() && cmd)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)]
|
||||
_IndirectCommandDrawArrays->baseVertex(_firstCommand));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
// TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
if (!empty())
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
|
||||
&(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
|
||||
,_indirectCommandArray->baseVertex(_firstCommand));
|
||||
#endif
|
||||
}
|
||||
|
||||
void DrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() && cmd)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)]
|
||||
_IndirectCommandDrawArrays->baseVertex(_firstCommand));
|
||||
*/
|
||||
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
// TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
if (!empty())
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
|
||||
&(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
|
||||
,_indirectCommandArray->baseVertex(_firstCommand));
|
||||
#endif
|
||||
}
|
||||
void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const
|
||||
{ GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
|
||||
GLenum mode = _mode;
|
||||
@@ -180,8 +190,8 @@ void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects)
|
||||
|
||||
state.bindElementBufferObject(ebo);
|
||||
|
||||
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())
|
||||
+_firstCommand* _IndirectCommandDrawArrays->getElementSize()));
|
||||
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())
|
||||
+_firstCommand* _indirectCommandArray->getElementSize()));
|
||||
|
||||
}
|
||||
DrawElementsIndirectUShort::~DrawElementsIndirectUShort()
|
||||
@@ -199,20 +209,24 @@ void DrawElementsIndirectUShort::offsetIndices(int offset)
|
||||
}
|
||||
void DrawElementsIndirectUShort::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() && cmd)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)]
|
||||
_IndirectCommandDrawArrays->baseVertex(_firstCommand));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
// TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
if (!empty())
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
|
||||
&(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
|
||||
,_indirectCommandArray->baseVertex(_firstCommand));
|
||||
#endif
|
||||
}
|
||||
|
||||
void DrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() && cmd)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)]
|
||||
_IndirectCommandDrawArrays->baseVertex(_firstCommand));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
// TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
if (!empty())
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
|
||||
&(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
|
||||
,_indirectCommandArray->baseVertex(_firstCommand));
|
||||
#endif
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -221,22 +235,22 @@ void DrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const
|
||||
//
|
||||
template<class T> inline
|
||||
unsigned int getNumPrimitivesMDI( const T&_this)
|
||||
{ IndirectCommandDrawElements *_IndirectCommandDrawArrays=_this.getIndirectCommandDrawArrays();
|
||||
{ IndirectCommandDrawElements *_indirectCommandArray=const_cast<IndirectCommandDrawElements *>(_this.getIndirectCommandArray());
|
||||
unsigned int total=0;
|
||||
switch(_this.getMode())
|
||||
{
|
||||
case(PrimitiveSet::POINTS):
|
||||
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i);
|
||||
for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
|
||||
total+=_indirectCommandArray->count(i);
|
||||
case(PrimitiveSet::LINES):
|
||||
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i)/2;
|
||||
for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
|
||||
total+=_indirectCommandArray->count(i)/2;
|
||||
case(PrimitiveSet::TRIANGLES):
|
||||
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i)/3;
|
||||
for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
|
||||
total+=_indirectCommandArray->count(i)/3;
|
||||
case(PrimitiveSet::QUADS):
|
||||
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i)/4;
|
||||
for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
|
||||
total+=_indirectCommandArray->count(i)/4;
|
||||
case(PrimitiveSet::LINE_STRIP):
|
||||
case(PrimitiveSet::LINE_LOOP):
|
||||
case(PrimitiveSet::TRIANGLE_STRIP):
|
||||
@@ -245,7 +259,7 @@ unsigned int getNumPrimitivesMDI( const T&_this)
|
||||
case(PrimitiveSet::PATCHES):
|
||||
case(PrimitiveSet::POLYGON):
|
||||
{
|
||||
unsigned int primcount = _IndirectCommandDrawArrays->getNumElements();
|
||||
unsigned int primcount = _indirectCommandArray->getNumElements();
|
||||
return primcount;
|
||||
}
|
||||
}
|
||||
@@ -266,7 +280,7 @@ MultiDrawElementsIndirectUByte::~MultiDrawElementsIndirectUByte()
|
||||
}
|
||||
void MultiDrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
GLenum mode = _mode;
|
||||
@@ -282,30 +296,34 @@ void MultiDrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObje
|
||||
|
||||
state.bindElementBufferObject(ebo);
|
||||
|
||||
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_BYTE, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())),_IndirectCommandDrawArrays->getNumElements(), _stride);
|
||||
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_BYTE, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())),_indirectCommandArray->getNumElements(), _stride);
|
||||
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUByte::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() )
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)],
|
||||
_IndirectCommandDrawArrays->baseVertex(i));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
//TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
if (!empty() )
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(i),
|
||||
&(*this)[_indirectCommandArray->firstIndex(i)]
|
||||
,_indirectCommandArray->baseVertex(i));
|
||||
#endif
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() )
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)],
|
||||
_IndirectCommandDrawArrays->baseVertex(i));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
//TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
if (!empty() )
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(i),
|
||||
&(*this)[_indirectCommandArray->firstIndex(i)]
|
||||
,_indirectCommandArray->baseVertex(i));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -321,7 +339,7 @@ MultiDrawElementsIndirectUShort::~MultiDrawElementsIndirectUShort()
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const
|
||||
{ GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
|
||||
GLenum mode = _mode;
|
||||
@@ -336,31 +354,35 @@ void MultiDrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObj
|
||||
|
||||
state.bindElementBufferObject(ebo);
|
||||
|
||||
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())),
|
||||
_count>0?_count:_IndirectCommandDrawArrays->getNumElements(),_stride);
|
||||
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())),
|
||||
_count>0?_count:_indirectCommandArray->getNumElements(),_stride);
|
||||
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUShort::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() )
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)],
|
||||
_IndirectCommandDrawArrays->baseVertex(i));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
//TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
if (!empty() )
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(i),
|
||||
&(*this)[_indirectCommandArray->firstIndex(i)]
|
||||
,_indirectCommandArray->baseVertex(i));
|
||||
#endif
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() )
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)],
|
||||
_IndirectCommandDrawArrays->baseVertex(i));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
//TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
if (!empty() )
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(i),
|
||||
&(*this)[_indirectCommandArray->firstIndex(i)]
|
||||
,_indirectCommandArray->baseVertex(i));
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -374,7 +396,7 @@ MultiDrawElementsIndirectUInt::~MultiDrawElementsIndirectUInt()
|
||||
|
||||
void MultiDrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
GLenum mode = _mode;
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
@@ -389,32 +411,35 @@ void MultiDrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjec
|
||||
|
||||
state.bindElementBufferObject(ebo);
|
||||
|
||||
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_INT, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())),
|
||||
_count>0?_count:_IndirectCommandDrawArrays->getNumElements(), _stride);
|
||||
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_INT, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())),
|
||||
_count>0?_count:_indirectCommandArray->getNumElements(), _stride);
|
||||
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUInt::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() )
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)],
|
||||
_IndirectCommandDrawArrays->baseVertex(i));
|
||||
*/
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
//TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
if (!empty() )
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(i),
|
||||
&(*this)[_indirectCommandArray->firstIndex(i)]
|
||||
,_indirectCommandArray->baseVertex(i));
|
||||
#endif
|
||||
}
|
||||
|
||||
void MultiDrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
/* if (!empty() )
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i),
|
||||
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)],
|
||||
_IndirectCommandDrawArrays->baseVertex(i));
|
||||
*/
|
||||
|
||||
#ifdef PRIMFUNCTORBASEVERTEX
|
||||
//TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
if (!empty() )
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
functor.drawElements(_mode,_indirectCommandArray->count(i),
|
||||
&(*this)[_indirectCommandArray->firstIndex(i)]
|
||||
,_indirectCommandArray->baseVertex(i));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -424,39 +449,39 @@ void MultiDrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
|
||||
//
|
||||
void DrawArraysIndirect::draw(osg::State& state, bool) const
|
||||
{
|
||||
GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
|
||||
GLExtensions* ext = state.get<GLExtensions>();
|
||||
|
||||
ext->glDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())
|
||||
+_firstCommand* _IndirectCommandDrawArrays->getElementSize()));
|
||||
ext->glDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())
|
||||
+_firstCommand* _indirectCommandArray->getElementSize()));
|
||||
|
||||
}
|
||||
|
||||
void DrawArraysIndirect::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
functor.drawArrays(_mode, _IndirectCommandDrawArrays->first(_firstCommand), _IndirectCommandDrawArrays->count(_firstCommand));
|
||||
functor.drawArrays(_mode, _indirectCommandArray->first(_firstCommand), _indirectCommandArray->count(_firstCommand));
|
||||
}
|
||||
|
||||
void DrawArraysIndirect::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
functor.drawArrays(_mode, _IndirectCommandDrawArrays->first(_firstCommand), _IndirectCommandDrawArrays->count(_firstCommand));
|
||||
functor.drawArrays(_mode, _indirectCommandArray->first(_firstCommand), _indirectCommandArray->count(_firstCommand));
|
||||
}
|
||||
|
||||
unsigned int DrawArraysIndirect::getNumIndices() const
|
||||
{
|
||||
return _IndirectCommandDrawArrays->count(_firstCommand);
|
||||
return _indirectCommandArray->count(_firstCommand);
|
||||
}
|
||||
|
||||
unsigned int DrawArraysIndirect::index(unsigned int pos) const
|
||||
{
|
||||
return _IndirectCommandDrawArrays->first(_firstCommand)+ pos;
|
||||
return _indirectCommandArray->first(_firstCommand)+ pos;
|
||||
}
|
||||
|
||||
void DrawArraysIndirect::offsetIndices(int offset)
|
||||
{
|
||||
_IndirectCommandDrawArrays->first(_firstCommand)+= offset;
|
||||
_indirectCommandArray->first(_firstCommand)+= offset;
|
||||
}
|
||||
|
||||
unsigned int DrawArraysIndirect::getNumPrimitives() const
|
||||
@@ -464,13 +489,13 @@ unsigned int DrawArraysIndirect::getNumPrimitives() const
|
||||
switch(_mode)
|
||||
{
|
||||
case(POINTS):
|
||||
return _IndirectCommandDrawArrays->count(_firstCommand);
|
||||
return _indirectCommandArray->count(_firstCommand);
|
||||
case(LINES):
|
||||
return _IndirectCommandDrawArrays->count(_firstCommand)/2;
|
||||
return _indirectCommandArray->count(_firstCommand)/2;
|
||||
case(TRIANGLES):
|
||||
return _IndirectCommandDrawArrays->count(_firstCommand)/3;
|
||||
return _indirectCommandArray->count(_firstCommand)/3;
|
||||
case(QUADS):
|
||||
return _IndirectCommandDrawArrays->count(_firstCommand)/4;
|
||||
return _indirectCommandArray->count(_firstCommand)/4;
|
||||
case(LINE_STRIP):
|
||||
case(LINE_LOOP):
|
||||
case(TRIANGLE_STRIP):
|
||||
@@ -491,31 +516,31 @@ unsigned int DrawArraysIndirect::getNumPrimitives() const
|
||||
//
|
||||
void MultiDrawArraysIndirect::draw(osg::State& state, bool) const
|
||||
{
|
||||
GLBufferObject* dibo = _IndirectCommandDrawArrays->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
|
||||
|
||||
GLExtensions* ext = state.get<GLExtensions>();
|
||||
|
||||
ext->glMultiDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())+_firstCommand*_IndirectCommandDrawArrays->getElementSize()),
|
||||
_count>0?_count:_IndirectCommandDrawArrays->getNumElements(), _stride);
|
||||
ext->glMultiDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())+_firstCommand*_indirectCommandArray->getElementSize()),
|
||||
_count>0?_count:_indirectCommandArray->getNumElements(), _stride);
|
||||
|
||||
}
|
||||
|
||||
void MultiDrawArraysIndirect::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
{
|
||||
functor.drawArrays(_mode, _IndirectCommandDrawArrays->first(i), _IndirectCommandDrawArrays->count(i));
|
||||
functor.drawArrays(_mode, _indirectCommandArray->first(i), _indirectCommandArray->count(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MultiDrawArraysIndirect::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
{
|
||||
functor.drawArrays(_mode, _IndirectCommandDrawArrays->first(i), _IndirectCommandDrawArrays->count(i));
|
||||
functor.drawArrays(_mode, _indirectCommandArray->first(i), _indirectCommandArray->count(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,51 +548,51 @@ unsigned int MultiDrawArraysIndirect::getNumIndices() const
|
||||
{
|
||||
unsigned int total=0;
|
||||
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
total+= _IndirectCommandDrawArrays->count(i);
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
total+= _indirectCommandArray->count(i);
|
||||
return total;
|
||||
}
|
||||
|
||||
unsigned int MultiDrawArraysIndirect::index(unsigned int pos) const
|
||||
{
|
||||
/* unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
unsigned int i = 0, maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
for(i=_firstCommand; i<maxindex;++i)
|
||||
{
|
||||
unsigned int count = _IndirectCommandDrawArrays->count(i);
|
||||
unsigned int count = _indirectCommandArray->count(i);
|
||||
if (pos<count) break;
|
||||
pos -= count;
|
||||
}
|
||||
return _IndirectCommandDrawArrays->first(maxindex-1) + pos;*/
|
||||
return pos;//???
|
||||
if (i>=maxindex) return 0;
|
||||
return _indirectCommandArray->first(maxindex-1) + pos;
|
||||
|
||||
}
|
||||
|
||||
void MultiDrawArraysIndirect::offsetIndices(int offset)
|
||||
{
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
_IndirectCommandDrawArrays->first(i) += offset;
|
||||
unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
_indirectCommandArray->first(i) += offset;
|
||||
}
|
||||
|
||||
unsigned int MultiDrawArraysIndirect::getNumPrimitives() const
|
||||
{
|
||||
unsigned int total=0;unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand;
|
||||
unsigned int total=0;unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
|
||||
|
||||
switch(_mode)
|
||||
{
|
||||
case(POINTS):
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i);
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
total+=_indirectCommandArray->count(i);
|
||||
case(LINES):
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i)/2;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
total+=_indirectCommandArray->count(i)/2;
|
||||
case(TRIANGLES):
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i)/3;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
total+=_indirectCommandArray->count(i)/3;
|
||||
case(QUADS):
|
||||
for(unsigned int i=_firstCommand; i<maxindex;i++)
|
||||
total+=_IndirectCommandDrawArrays->count(i)/4;
|
||||
for(unsigned int i = _firstCommand; i<maxindex; ++i)
|
||||
total+=_indirectCommandArray->count(i)/4;
|
||||
case(LINE_STRIP):
|
||||
case(LINE_LOOP):
|
||||
case(TRIANGLE_STRIP):
|
||||
@@ -576,7 +601,7 @@ unsigned int MultiDrawArraysIndirect::getNumPrimitives() const
|
||||
case(PATCHES):
|
||||
case(POLYGON):
|
||||
{
|
||||
unsigned int primcount = _IndirectCommandDrawArrays->getNumElements();
|
||||
unsigned int primcount = _indirectCommandArray->getNumElements();
|
||||
return primcount;
|
||||
}
|
||||
}
|
||||
|
||||
188
src/osgWrappers/serializers/osg/PrimitiveSetIndirect.cpp
Normal file
188
src/osgWrappers/serializers/osg/PrimitiveSetIndirect.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
#include <osg/PrimitiveSetIndirect>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
namespace DACommandsArrays {
|
||||
REGISTER_OBJECT_WRAPPER( IndirectCommandDrawArrays,
|
||||
0,
|
||||
osg::IndirectCommandDrawArrays,
|
||||
"osg::Object osg::BufferData osg::IndirectCommandDrawArrays" )
|
||||
{
|
||||
{
|
||||
UPDATE_TO_VERSION_SCOPED( 147 )
|
||||
ADDED_ASSOCIATE("osg::BufferData")
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace DECommandsArrays {
|
||||
REGISTER_OBJECT_WRAPPER( IndirectCommandDrawElements,
|
||||
0,
|
||||
osg::IndirectCommandDrawElements,
|
||||
"osg::Object osg::BufferData osg::IndirectCommandDrawElements" )
|
||||
{
|
||||
{
|
||||
UPDATE_TO_VERSION_SCOPED( 147 )
|
||||
ADDED_ASSOCIATE("osg::BufferData")
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace DefaultDACommandsArrays {
|
||||
|
||||
|
||||
static bool checkDACommands( const osg::DefaultIndirectCommandDrawArrays& node )
|
||||
{
|
||||
return node.size()>0;
|
||||
}
|
||||
|
||||
static bool readDACommands( osgDB::InputStream& is, osg::DefaultIndirectCommandDrawArrays& node )
|
||||
{
|
||||
unsigned int elmt, size = 0; is >> size >> is.BEGIN_BRACKET;
|
||||
node.resize(size);
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
is >>elmt; node.count(i) = elmt;
|
||||
is >>elmt; node.instanceCount(i) = elmt;
|
||||
is >>elmt; node.first(i) = elmt;
|
||||
is >>elmt; node.baseInstance(i) = elmt;
|
||||
}
|
||||
is >> is.END_BRACKET;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool writeDACommands( osgDB::OutputStream& os, const osg::DefaultIndirectCommandDrawArrays& node )
|
||||
{
|
||||
unsigned int size = node.getNumElements();
|
||||
osg::DefaultIndirectCommandDrawArrays& nonconstnode =const_cast<osg::DefaultIndirectCommandDrawArrays&>(node);
|
||||
os << size << os.BEGIN_BRACKET << std::endl;
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
os << nonconstnode.count(i);
|
||||
os << nonconstnode.instanceCount(i);
|
||||
os << nonconstnode.first(i);
|
||||
os << nonconstnode.baseInstance(i);
|
||||
}
|
||||
os << os.END_BRACKET << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgDefaultIndirectCommandDrawArrays,
|
||||
new osg::DefaultIndirectCommandDrawArrays,
|
||||
osg::DefaultIndirectCommandDrawArrays,
|
||||
"osg::Object osg::BufferData osg::IndirectCommandDrawArrays osg::DefaultIndirectCommandDrawArrays" )
|
||||
{
|
||||
ADD_USER_SERIALIZER(DACommands);
|
||||
}
|
||||
}
|
||||
namespace DefaultDECommandsArrays {
|
||||
|
||||
static bool checkDECommands( const osg::DefaultIndirectCommandDrawElements& node )
|
||||
{
|
||||
return node.size()>0;
|
||||
}
|
||||
|
||||
static bool readDECommands( osgDB::InputStream& is, osg::DefaultIndirectCommandDrawElements& node )
|
||||
{
|
||||
unsigned int elmt, size = 0; is >> size >> is.BEGIN_BRACKET;
|
||||
node.resize(size);
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
is >>elmt; node.count(i) = elmt;
|
||||
is >>elmt; node.instanceCount(i) = elmt;
|
||||
is >>elmt; node.firstIndex(i) = elmt;
|
||||
is >>elmt; node.baseVertex(i) = elmt;
|
||||
is >>elmt; node.baseInstance(i) = elmt;
|
||||
}
|
||||
is >> is.END_BRACKET;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool writeDECommands( osgDB::OutputStream& os, const osg::DefaultIndirectCommandDrawElements& node )
|
||||
{
|
||||
unsigned int size = node.getNumElements();
|
||||
osg::DefaultIndirectCommandDrawElements& nonconstnode =const_cast<osg::DefaultIndirectCommandDrawElements&>(node);
|
||||
os << size << os.BEGIN_BRACKET << std::endl;
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
os << nonconstnode.count(i);
|
||||
os << nonconstnode.instanceCount(i);
|
||||
os << nonconstnode.firstIndex(i);
|
||||
os << nonconstnode.baseVertex(i);
|
||||
os << nonconstnode.baseInstance(i);
|
||||
}
|
||||
os << os.END_BRACKET << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgDefaultIndirectCommandDrawElements,
|
||||
new osg::DefaultIndirectCommandDrawElements,
|
||||
osg::DefaultIndirectCommandDrawElements,
|
||||
"osg::Object osg::BufferData osg::IndirectCommandDrawElements osg::DefaultIndirectCommandDrawElements" )
|
||||
{
|
||||
{
|
||||
UPDATE_TO_VERSION_SCOPED( 147 )
|
||||
ADDED_ASSOCIATE("osg::BufferData")
|
||||
}
|
||||
ADD_USER_SERIALIZER(DECommands);
|
||||
}
|
||||
}
|
||||
namespace DrawArraysIndirectWrapper {
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( DrawArraysIndirect,
|
||||
new osg::DrawArraysIndirect,
|
||||
osg::DrawArraysIndirect,
|
||||
"osg::Object osg::BufferData osg::PrimitiveSet osg::DrawArraysIndirect" )
|
||||
{
|
||||
ADD_OBJECT_SERIALIZER( IndirectCommandArray, osg::IndirectCommandDrawArrays ,new osg::DefaultIndirectCommandDrawArrays());
|
||||
ADD_UINT_SERIALIZER( FirstCommandToDraw, 0);
|
||||
ADD_INT_SERIALIZER( Stride, 0);
|
||||
}
|
||||
|
||||
}
|
||||
namespace MultiDrawArraysIndirectWrapper {
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( MultiDrawArraysIndirect,
|
||||
new osg::MultiDrawArraysIndirect,
|
||||
osg::MultiDrawArraysIndirect,
|
||||
"osg::Object osg::BufferData osg::PrimitiveSet osg::DrawArraysIndirect osg::MultiDrawArraysIndirect" )
|
||||
{
|
||||
ADD_UINT_SERIALIZER( NumCommandsToDraw, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace DrawElementsIndirectWrapper {
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( DrawElementsIndirect,
|
||||
0,
|
||||
osg::DrawElementsIndirect,
|
||||
"osg::Object osg::BufferData osg::PrimitiveSet osg::DrawElementsIndirect" )
|
||||
{
|
||||
ADD_OBJECT_SERIALIZER( IndirectCommandArray, osg::IndirectCommandDrawElements, new osg::DefaultIndirectCommandDrawElements());
|
||||
ADD_UINT_SERIALIZER( FirstCommandToDraw, 0);
|
||||
ADD_INT_SERIALIZER( Stride, 0);
|
||||
}
|
||||
|
||||
}
|
||||
#define INDIRECTDRAW_ELEMENTS_WRAPPER( DRAWELEMENTS, ELEMENTTYPE ) \
|
||||
namespace Wrapper##DRAWELEMENTS { \
|
||||
REGISTER_OBJECT_WRAPPER( DRAWELEMENTS, new osg::DRAWELEMENTS, osg::DRAWELEMENTS, "osg::Object osg::BufferData osg::PrimitiveSet osg::IndirectDrawElements osg::"#DRAWELEMENTS) \
|
||||
{ \
|
||||
ADD_ISAVECTOR_SERIALIZER( vector, osgDB::BaseSerializer::ELEMENTTYPE, 4 ); \
|
||||
} \
|
||||
}\
|
||||
namespace WrapperMulti##DRAWELEMENTS { \
|
||||
REGISTER_OBJECT_WRAPPER( Multi##DRAWELEMENTS, new osg::Multi##DRAWELEMENTS, osg::Multi##DRAWELEMENTS, "osg::Object osg::BufferData osg::PrimitiveSet osg::IndirectDrawElements osg::"#DRAWELEMENTS" osg::Multi"#DRAWELEMENTS) \
|
||||
{ \
|
||||
ADD_UINT_SERIALIZER( NumCommandsToDraw, 0);\
|
||||
} \
|
||||
}\
|
||||
|
||||
|
||||
INDIRECTDRAW_ELEMENTS_WRAPPER( DrawElementsIndirectUByte, RW_UCHAR )
|
||||
INDIRECTDRAW_ELEMENTS_WRAPPER( DrawElementsIndirectUShort, RW_USHORT )
|
||||
INDIRECTDRAW_ELEMENTS_WRAPPER( DrawElementsIndirectUInt, RW_UINT )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user