fix some errors during renaming and cleanup code

This commit is contained in:
mp3butcher 2017-07-27 01:08:37 +02:00
parent b26fa74e7e
commit 8742ad8da6
2 changed files with 187 additions and 159 deletions

View File

@ -141,17 +141,19 @@ public:
DrawElementsIndirect(const DrawElementsIndirect& rhs,const CopyOp& copyop=CopyOp::SHALLOW_COPY): DrawElementsIndirect(const DrawElementsIndirect& rhs,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
DrawElements(rhs,copyop),_firstCommand(rhs._firstCommand), _stride(rhs._stride) { 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 /// set command array of this indirect primitive set
inline void setIndirectCommandArray(IndirectCommandDrawElements*idc) { inline void setIndirectCommandArray(IndirectCommandDrawElements*idc) {
_IndirectCommandDrawArrays = idc; _indirectCommandArray = idc;
if(!_IndirectCommandDrawArrays->getBufferObject()) if(!_indirectCommandArray->getBufferObject())
_IndirectCommandDrawArrays->setBufferObject(new osg::VertexBufferObject()); _indirectCommandArray->setBufferObject(new osg::VertexBufferObject());
} }
/// get command array of this indirect primitive set /// get command array of this indirect primitive set
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _IndirectCommandDrawArrays; } inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray; }
inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _IndirectCommandDrawArrays; } inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _indirectCommandArray; }
///Further methods are for advanced DI when you plan to use your own IndirectCommandElement (stride) ///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) ///or if you want to draw a particular command index of the IndirectCommandElement(FirstCommandToDraw)
@ -159,6 +161,7 @@ public:
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 /// 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) /// stride (to set if you use custom CommandArray)
inline void setStride( GLsizei i) { inline void setStride( GLsizei i) {
_stride=i; _stride=i;
@ -174,7 +177,7 @@ protected:
unsigned int _firstCommand; unsigned int _firstCommand;
GLsizei _stride; GLsizei _stride;
ref_ptr<IndirectCommandDrawElements> _IndirectCommandDrawArrays; ref_ptr<IndirectCommandDrawElements> _indirectCommandArray;
}; };
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
@ -603,7 +606,7 @@ public:
osg::PrimitiveSet(dal,copyop), osg::PrimitiveSet(dal,copyop),
_firstCommand(dal._firstCommand), _firstCommand(dal._firstCommand),
_stride(dal._stride), _stride(dal._stride),
_IndirectCommandDrawArrays((DefaultIndirectCommandDrawArrays*)copyop( dal._IndirectCommandDrawArrays.get())) _indirectCommandArray((DefaultIndirectCommandDrawArrays*)copyop( dal._indirectCommandArray.get()))
{} {}
virtual osg::Object* cloneType() const { virtual osg::Object* cloneType() const {
@ -651,22 +654,22 @@ public:
} }
inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc) { inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc) {
_IndirectCommandDrawArrays = idc; _indirectCommandArray = idc;
if(!_IndirectCommandDrawArrays->getBufferObject()) if(!_indirectCommandArray->getBufferObject())
_IndirectCommandDrawArrays->setBufferObject(new osg::VertexBufferObject()); _indirectCommandArray->setBufferObject(new osg::VertexBufferObject());
} }
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const { inline const IndirectCommandDrawArrays* getIndirectCommandArray() const {
return _IndirectCommandDrawArrays; return _indirectCommandArray;
} }
inline IndirectCommandDrawArrays* getIndirectCommandArray(){ inline IndirectCommandDrawArrays* getIndirectCommandArray(){
return _IndirectCommandDrawArrays; return _indirectCommandArray;
} }
protected: protected:
unsigned int _firstCommand; unsigned int _firstCommand;
GLsizei _stride; GLsizei _stride;
ref_ptr<IndirectCommandDrawArrays> _IndirectCommandDrawArrays; ref_ptr<IndirectCommandDrawArrays> _indirectCommandArray;
}; };

View File

@ -20,13 +20,16 @@
#include <osg/Notify> #include <osg/Notify>
#include <assert.h> #include <assert.h>
/// TODO: add base vertex feature to PrimitiveFunctor and PrimitiveIndexFunctor
//#define PRIMFUNCTORBASEVERTEX 1
using namespace osg; using namespace osg;
//////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// DrawElementsIndirect // DrawElementsIndirect
// //
template<class T> inline template<class T>
unsigned int getNumPrimitivesDI( const T&_this) inline unsigned int getNumPrimitivesDI( const T&_this )
{ {
unsigned int offset= _this.getFirstCommandToDraw(); unsigned int offset= _this.getFirstCommandToDraw();
IndirectCommandDrawElements *cmd=const_cast<IndirectCommandDrawElements *>(_this.getIndirectCommandArray()); IndirectCommandDrawElements *cmd=const_cast<IndirectCommandDrawElements *>(_this.getIndirectCommandArray());
@ -60,7 +63,7 @@ unsigned int DrawElementsIndirectUByte::getNumPrimitives() const{return getNumPr
unsigned int DrawElementsIndirectUShort::getNumPrimitives() const{return getNumPrimitivesDI<DrawElementsIndirectUShort>(*this);} unsigned int DrawElementsIndirectUShort::getNumPrimitives() const{return getNumPrimitivesDI<DrawElementsIndirectUShort>(*this);}
void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLenum mode = _mode; GLenum mode = _mode;
@ -76,8 +79,8 @@ void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) c
state.bindElementBufferObject(ebo); state.bindElementBufferObject(ebo);
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_INT, state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_INT,
(const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex()) //command array adress (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex()) //command array adress
+_firstCommand* _IndirectCommandDrawArrays->getElementSize())// runtime offset computaion can be sizeof(*_IndirectCommandDrawArrays->begin()) +_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 void DrawElementsIndirectUInt::accept(PrimitiveFunctor& functor) const
{ {
/* if (!empty() && cmd) #ifdef PRIMFUNCTORBASEVERTEX
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand), // TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)] if (!empty())
_IndirectCommandDrawArrays->baseVertex(_firstCommand)); functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
*/ &(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
,_indirectCommandArray->baseVertex(_firstCommand));
#endif
} }
void DrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const void DrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
{ {
/* if (!empty() && cmd) #ifdef PRIMFUNCTORBASEVERTEX
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand), // TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)] if (!empty())
_IndirectCommandDrawArrays->baseVertex(_firstCommand)); functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
*/ &(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
,_indirectCommandArray->baseVertex(_firstCommand));
#endif
} }
void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLenum mode = _mode; GLenum mode = _mode;
@ -129,8 +136,8 @@ void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects)
state.bindElementBufferObject(ebo); state.bindElementBufferObject(ebo);
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_BYTE, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex()) state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_BYTE, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())
+_firstCommand* _IndirectCommandDrawArrays->getElementSize())); +_firstCommand* _indirectCommandArray->getElementSize()));
} }
DrawElementsIndirectUByte::~DrawElementsIndirectUByte() DrawElementsIndirectUByte::~DrawElementsIndirectUByte()
@ -148,24 +155,27 @@ void DrawElementsIndirectUByte::offsetIndices(int offset)
} }
void DrawElementsIndirectUByte::accept(PrimitiveFunctor& functor) const void DrawElementsIndirectUByte::accept(PrimitiveFunctor& functor) const
{ {
/* if (!empty() && cmd) #ifdef PRIMFUNCTORBASEVERTEX
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand), // TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)] if (!empty())
_IndirectCommandDrawArrays->baseVertex(_firstCommand)); functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
*/ &(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
,_indirectCommandArray->baseVertex(_firstCommand));
#endif
} }
void DrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const void DrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const
{ {
/* if (!empty() && cmd) #ifdef PRIMFUNCTORBASEVERTEX
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand), // TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)] if (!empty())
_IndirectCommandDrawArrays->baseVertex(_firstCommand)); functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
*/ &(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
,_indirectCommandArray->baseVertex(_firstCommand));
#endif
} }
void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLenum mode = _mode; GLenum mode = _mode;
@ -180,8 +190,8 @@ void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects)
state.bindElementBufferObject(ebo); state.bindElementBufferObject(ebo);
state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex()) state.get<GLExtensions>()-> glDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())
+_firstCommand* _IndirectCommandDrawArrays->getElementSize())); +_firstCommand* _indirectCommandArray->getElementSize()));
} }
DrawElementsIndirectUShort::~DrawElementsIndirectUShort() DrawElementsIndirectUShort::~DrawElementsIndirectUShort()
@ -199,20 +209,24 @@ void DrawElementsIndirectUShort::offsetIndices(int offset)
} }
void DrawElementsIndirectUShort::accept(PrimitiveFunctor& functor) const void DrawElementsIndirectUShort::accept(PrimitiveFunctor& functor) const
{ {
/* if (!empty() && cmd) #ifdef PRIMFUNCTORBASEVERTEX
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand), // TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)] if (!empty())
_IndirectCommandDrawArrays->baseVertex(_firstCommand)); functor.drawElements(_mode,_indirectCommandArray->count(_firstCommand),
*/ &(*this)[_indirectCommandArray->firstIndex(_firstCommand)]
,_indirectCommandArray->baseVertex(_firstCommand));
#endif
} }
void DrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const void DrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const
{ {
/* if (!empty() && cmd) #ifdef PRIMFUNCTORBASEVERTEX
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(_firstCommand), // TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
&(*this)[_IndirectCommandDrawArrays->firstIndex(_firstCommand)] if (!empty())
_IndirectCommandDrawArrays->baseVertex(_firstCommand)); 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 template<class T> inline
unsigned int getNumPrimitivesMDI( const T&_this) unsigned int getNumPrimitivesMDI( const T&_this)
{ IndirectCommandDrawElements *_IndirectCommandDrawArrays=const_cast<IndirectCommandDrawElements *>(_this.getIndirectCommandArray()); { IndirectCommandDrawElements *_indirectCommandArray=const_cast<IndirectCommandDrawElements *>(_this.getIndirectCommandArray());
unsigned int total=0; unsigned int total=0;
switch(_this.getMode()) switch(_this.getMode())
{ {
case(PrimitiveSet::POINTS): case(PrimitiveSet::POINTS):
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();++i) for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
total+=_IndirectCommandDrawArrays->count(i); total+=_indirectCommandArray->count(i);
case(PrimitiveSet::LINES): case(PrimitiveSet::LINES):
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();++i) for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
total+=_IndirectCommandDrawArrays->count(i)/2; total+=_indirectCommandArray->count(i)/2;
case(PrimitiveSet::TRIANGLES): case(PrimitiveSet::TRIANGLES):
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();++i) for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
total+=_IndirectCommandDrawArrays->count(i)/3; total+=_indirectCommandArray->count(i)/3;
case(PrimitiveSet::QUADS): case(PrimitiveSet::QUADS):
for(unsigned int i=0;i<_IndirectCommandDrawArrays->getNumElements();++i) for(unsigned int i=0;i<_indirectCommandArray->getNumElements();++i)
total+=_IndirectCommandDrawArrays->count(i)/4; total+=_indirectCommandArray->count(i)/4;
case(PrimitiveSet::LINE_STRIP): case(PrimitiveSet::LINE_STRIP):
case(PrimitiveSet::LINE_LOOP): case(PrimitiveSet::LINE_LOOP):
case(PrimitiveSet::TRIANGLE_STRIP): case(PrimitiveSet::TRIANGLE_STRIP):
@ -245,7 +259,7 @@ unsigned int getNumPrimitivesMDI( const T&_this)
case(PrimitiveSet::PATCHES): case(PrimitiveSet::PATCHES):
case(PrimitiveSet::POLYGON): case(PrimitiveSet::POLYGON):
{ {
unsigned int primcount = _IndirectCommandDrawArrays->getNumElements(); unsigned int primcount = _indirectCommandArray->getNumElements();
return primcount; return primcount;
} }
} }
@ -266,7 +280,7 @@ MultiDrawElementsIndirectUByte::~MultiDrawElementsIndirectUByte()
} }
void MultiDrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLenum mode = _mode; GLenum mode = _mode;
@ -282,30 +296,34 @@ void MultiDrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObje
state.bindElementBufferObject(ebo); 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 void MultiDrawElementsIndirectUByte::accept(PrimitiveFunctor& functor) const
{ {
/* if (!empty() ) #ifdef PRIMFUNCTORBASEVERTEX
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; //TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
for(unsigned int i=_firstCommand; i<maxindex;++i) unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i), if (!empty() )
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)], for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->baseVertex(i)); functor.drawElements(_mode,_indirectCommandArray->count(i),
*/ &(*this)[_indirectCommandArray->firstIndex(i)]
,_indirectCommandArray->baseVertex(i));
#endif
} }
void MultiDrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const void MultiDrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const
{ {
/* if (!empty() ) #ifdef PRIMFUNCTORBASEVERTEX
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; //TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
for(unsigned int i=_firstCommand; i<maxindex;++i) unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i), if (!empty() )
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)], for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->baseVertex(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 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLenum mode = _mode; GLenum mode = _mode;
@ -336,31 +354,35 @@ void MultiDrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObj
state.bindElementBufferObject(ebo); state.bindElementBufferObject(ebo);
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())), state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_SHORT, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())),
_count>0?_count:_IndirectCommandDrawArrays->getNumElements(),_stride); _count>0?_count:_indirectCommandArray->getNumElements(),_stride);
} }
void MultiDrawElementsIndirectUShort::accept(PrimitiveFunctor& functor) const void MultiDrawElementsIndirectUShort::accept(PrimitiveFunctor& functor) const
{ {
/* if (!empty() ) #ifdef PRIMFUNCTORBASEVERTEX
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; //TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
for(unsigned int i=_firstCommand; i<maxindex;++i) unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i), if (!empty() )
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)], for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->baseVertex(i)); functor.drawElements(_mode,_indirectCommandArray->count(i),
*/ &(*this)[_indirectCommandArray->firstIndex(i)]
,_indirectCommandArray->baseVertex(i));
#endif
} }
void MultiDrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const void MultiDrawElementsIndirectUShort::accept(PrimitiveIndexFunctor& functor) const
{ {
/* if (!empty() ) #ifdef PRIMFUNCTORBASEVERTEX
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; //TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
for(unsigned int i=_firstCommand; i<maxindex;++i) unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i), if (!empty() )
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)], for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->baseVertex(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 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@ -389,32 +411,35 @@ void MultiDrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjec
state.bindElementBufferObject(ebo); state.bindElementBufferObject(ebo);
state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_INT, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())), state.get<GLExtensions>()-> glMultiDrawElementsIndirect(mode, GL_UNSIGNED_INT, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())),
_count>0?_count:_IndirectCommandDrawArrays->getNumElements(), _stride); _count>0?_count:_indirectCommandArray->getNumElements(), _stride);
} }
void MultiDrawElementsIndirectUInt::accept(PrimitiveFunctor& functor) const void MultiDrawElementsIndirectUInt::accept(PrimitiveFunctor& functor) const
{ {
/* if (!empty() ) #ifdef PRIMFUNCTORBASEVERTEX
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; //TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
for(unsigned int i=_firstCommand; i<maxindex;++i) unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i), if (!empty() )
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)], for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->baseVertex(i)); functor.drawElements(_mode,_indirectCommandArray->count(i),
*/ &(*this)[_indirectCommandArray->firstIndex(i)]
,_indirectCommandArray->baseVertex(i));
#endif
} }
void MultiDrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const void MultiDrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
{ {
/* if (!empty() ) #ifdef PRIMFUNCTORBASEVERTEX
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; //TODO: add base vertex parameter in PrimitiveFunctor and PrimitiveIndexFunctor drawelements method
for(unsigned int i=_firstCommand; i<maxindex;++i) unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
functor.drawElements(_mode,_IndirectCommandDrawArrays->count(i), if (!empty() )
&(*this)[_IndirectCommandDrawArrays->firstIndex(i)], for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->baseVertex(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 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLExtensions* ext = state.get<GLExtensions>(); GLExtensions* ext = state.get<GLExtensions>();
ext->glDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex()) ext->glDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())
+_firstCommand* _IndirectCommandDrawArrays->getElementSize())); +_firstCommand* _indirectCommandArray->getElementSize()));
} }
void DrawArraysIndirect::accept(PrimitiveFunctor& functor) const 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 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 unsigned int DrawArraysIndirect::getNumIndices() const
{ {
return _IndirectCommandDrawArrays->count(_firstCommand); return _indirectCommandArray->count(_firstCommand);
} }
unsigned int DrawArraysIndirect::index(unsigned int pos) const unsigned int DrawArraysIndirect::index(unsigned int pos) const
{ {
return _IndirectCommandDrawArrays->first(_firstCommand)+ pos; return _indirectCommandArray->first(_firstCommand)+ pos;
} }
void DrawArraysIndirect::offsetIndices(int offset) void DrawArraysIndirect::offsetIndices(int offset)
{ {
_IndirectCommandDrawArrays->first(_firstCommand)+= offset; _indirectCommandArray->first(_firstCommand)+= offset;
} }
unsigned int DrawArraysIndirect::getNumPrimitives() const unsigned int DrawArraysIndirect::getNumPrimitives() const
@ -464,13 +489,13 @@ unsigned int DrawArraysIndirect::getNumPrimitives() const
switch(_mode) switch(_mode)
{ {
case(POINTS): case(POINTS):
return _IndirectCommandDrawArrays->count(_firstCommand); return _indirectCommandArray->count(_firstCommand);
case(LINES): case(LINES):
return _IndirectCommandDrawArrays->count(_firstCommand)/2; return _indirectCommandArray->count(_firstCommand)/2;
case(TRIANGLES): case(TRIANGLES):
return _IndirectCommandDrawArrays->count(_firstCommand)/3; return _indirectCommandArray->count(_firstCommand)/3;
case(QUADS): case(QUADS):
return _IndirectCommandDrawArrays->count(_firstCommand)/4; return _indirectCommandArray->count(_firstCommand)/4;
case(LINE_STRIP): case(LINE_STRIP):
case(LINE_LOOP): case(LINE_LOOP):
case(TRIANGLE_STRIP): case(TRIANGLE_STRIP):
@ -491,31 +516,31 @@ unsigned int DrawArraysIndirect::getNumPrimitives() const
// //
void MultiDrawArraysIndirect::draw(osg::State& state, bool) 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()); state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
GLExtensions* ext = state.get<GLExtensions>(); GLExtensions* ext = state.get<GLExtensions>();
ext->glMultiDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_IndirectCommandDrawArrays->getBufferIndex())+_firstCommand*_IndirectCommandDrawArrays->getElementSize()), ext->glMultiDrawArraysIndirect(_mode, (const GLvoid *)(dibo->getOffset(_indirectCommandArray->getBufferIndex())+_firstCommand*_indirectCommandArray->getElementSize()),
_count>0?_count:_IndirectCommandDrawArrays->getNumElements(), _stride); _count>0?_count:_indirectCommandArray->getNumElements(), _stride);
} }
void MultiDrawArraysIndirect::accept(PrimitiveFunctor& functor) const void MultiDrawArraysIndirect::accept(PrimitiveFunctor& functor) const
{ {
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
for(unsigned int i=_firstCommand; i<maxindex;++i) 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 void MultiDrawArraysIndirect::accept(PrimitiveIndexFunctor& functor) const
{ {
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
for(unsigned int i=_firstCommand; i<maxindex;++i) 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 total=0;
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
for(unsigned int i=_firstCommand; i<maxindex;++i) for(unsigned int i = _firstCommand; i<maxindex; ++i)
total+= _IndirectCommandDrawArrays->count(i); total+= _indirectCommandArray->count(i);
return total; return total;
} }
unsigned int MultiDrawArraysIndirect::index(unsigned int pos) const unsigned int MultiDrawArraysIndirect::index(unsigned int pos) const
{ {
/* unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; unsigned int i = 0, maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
for(unsigned int i=_firstCommand; i<maxindex;++i) for(i=_firstCommand; i<maxindex;++i)
{ {
unsigned int count = _IndirectCommandDrawArrays->count(i); unsigned int count = _indirectCommandArray->count(i);
if (pos<count) break; if (pos<count) break;
pos -= count; pos -= count;
} }
return _IndirectCommandDrawArrays->first(maxindex-1) + pos;*/ if (i>=maxindex) return 0;
return pos;//??? return _indirectCommandArray->first(maxindex-1) + pos;
} }
void MultiDrawArraysIndirect::offsetIndices(int offset) void MultiDrawArraysIndirect::offsetIndices(int offset)
{ {
unsigned int maxindex=_count>0?_firstCommand + _count : _IndirectCommandDrawArrays->getNumElements() - _firstCommand; unsigned int maxindex=_count>0?_firstCommand + _count : _indirectCommandArray->getNumElements() - _firstCommand;
for(unsigned int i=_firstCommand; i<maxindex;++i) for(unsigned int i = _firstCommand; i<maxindex; ++i)
_IndirectCommandDrawArrays->first(i) += offset; _indirectCommandArray->first(i) += offset;
} }
unsigned int MultiDrawArraysIndirect::getNumPrimitives() const 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) switch(_mode)
{ {
case(POINTS): case(POINTS):
for(unsigned int i=_firstCommand; i<maxindex;++i) for(unsigned int i = _firstCommand; i<maxindex; ++i)
total+=_IndirectCommandDrawArrays->count(i); total+=_indirectCommandArray->count(i);
case(LINES): case(LINES):
for(unsigned int i=_firstCommand; i<maxindex;++i) for(unsigned int i = _firstCommand; i<maxindex; ++i)
total+=_IndirectCommandDrawArrays->count(i)/2; total+=_indirectCommandArray->count(i)/2;
case(TRIANGLES): case(TRIANGLES):
for(unsigned int i=_firstCommand; i<maxindex;++i) for(unsigned int i = _firstCommand; i<maxindex; ++i)
total+=_IndirectCommandDrawArrays->count(i)/3; total+=_indirectCommandArray->count(i)/3;
case(QUADS): case(QUADS):
for(unsigned int i=_firstCommand; i<maxindex;++i) for(unsigned int i = _firstCommand; i<maxindex; ++i)
total+=_IndirectCommandDrawArrays->count(i)/4; total+=_indirectCommandArray->count(i)/4;
case(LINE_STRIP): case(LINE_STRIP):
case(LINE_LOOP): case(LINE_LOOP):
case(TRIANGLE_STRIP): case(TRIANGLE_STRIP):
@ -576,7 +601,7 @@ unsigned int MultiDrawArraysIndirect::getNumPrimitives() const
case(PATCHES): case(PATCHES):
case(POLYGON): case(POLYGON):
{ {
unsigned int primcount = _IndirectCommandDrawArrays->getNumElements(); unsigned int primcount = _indirectCommandArray->getNumElements();
return primcount; return primcount;
} }
} }