diff --git a/examples/osggpucull/osggpucull.cpp b/examples/osggpucull/osggpucull.cpp index 194a9a946..0c00bbef3 100644 --- a/examples/osggpucull/osggpucull.cpp +++ b/examples/osggpucull/osggpucull.cpp @@ -189,7 +189,7 @@ struct IndirectTarget } void endRegister(unsigned int index, unsigned int rowsPerInstance, GLenum pixelFormat, GLenum type, GLint internalFormat, bool useMultiDrawArraysIndirect ) { - osg::VertexBufferObject * indirectCommandbuffer=new osg::VertexBufferObject(); + osg::DrawIndirectBufferObject * indirectCommandbuffer = new osg::DrawIndirectBufferObject(); indirectCommandbuffer->setUsage(GL_DYNAMIC_DRAW); indirectCommands->setBufferObject(indirectCommandbuffer); diff --git a/include/osg/BufferObject b/include/osg/BufferObject index c542e4121..37ae19a55 100644 --- a/include/osg/BufferObject +++ b/include/osg/BufferObject @@ -635,6 +635,28 @@ class OSG_EXPORT ElementBufferObject : public BufferObject virtual ~ElementBufferObject(); }; +class OSG_EXPORT DrawIndirectBufferObject : public BufferObject +{ + public: + + DrawIndirectBufferObject(); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + DrawIndirectBufferObject(const DrawIndirectBufferObject& vbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY); + + META_Object(osg,DrawIndirectBufferObject); + + unsigned int addArray(osg::Array* array); + void removeArray(osg::Array* array); + + void setArray(unsigned int i, Array* array); + Array* getArray(unsigned int i); + const Array* getArray(unsigned int i) const; + + protected: + virtual ~DrawIndirectBufferObject(); +}; + class Image; class OSG_EXPORT PixelBufferObject : public BufferObject { diff --git a/include/osg/PrimitiveSetIndirect b/include/osg/PrimitiveSetIndirect index d8771a781..6c8567c83 100644 --- a/include/osg/PrimitiveSetIndirect +++ b/include/osg/PrimitiveSetIndirect @@ -148,7 +148,7 @@ public: inline void setIndirectCommandArray(IndirectCommandDrawElements*idc) { _indirectCommandArray = idc; if(!_indirectCommandArray->getBufferObject()) - _indirectCommandArray->setBufferObject(new osg::VertexBufferObject()); + _indirectCommandArray->setBufferObject(new osg::DrawIndirectBufferObject()); } /// get command array of this indirect primitive set inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray; } @@ -656,7 +656,7 @@ public: inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc) { _indirectCommandArray = idc; if(!_indirectCommandArray->getBufferObject()) - _indirectCommandArray->setBufferObject(new osg::VertexBufferObject()); + _indirectCommandArray->setBufferObject(new osg::DrawIndirectBufferObject()); } inline const IndirectCommandDrawArrays* getIndirectCommandArray() const { return _indirectCommandArray; diff --git a/include/osg/State b/include/osg/State index 28a2880c4..2d363105f 100644 --- a/include/osg/State +++ b/include/osg/State @@ -600,7 +600,7 @@ class OSG_EXPORT State : public Referenced } else if (ibo != _currentDIBO) { - _glBindBuffer(GL_DRAW_INDIRECT_BUFFER, ibo->getGLObjectID()); + ibo->bindBuffer(); _currentDIBO = ibo; } } diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index 9e2199911..46fa4e869 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -1358,6 +1358,50 @@ const DrawElements* ElementBufferObject::getDrawElements(unsigned int i) const return dynamic_cast(getBufferData(i)); } +////////////////////////////////////////////////////////////////////////////////// +// +// DrawIndirectBufferObject +// +DrawIndirectBufferObject::DrawIndirectBufferObject() +{ + setTarget(GL_DRAW_INDIRECT_BUFFER); + setUsage(GL_STATIC_DRAW_ARB); +// setUsage(GL_STREAM_DRAW_ARB); +} + +DrawIndirectBufferObject::DrawIndirectBufferObject(const DrawIndirectBufferObject& vbo,const CopyOp& copyop): + BufferObject(vbo,copyop) +{ +} + +DrawIndirectBufferObject::~DrawIndirectBufferObject() +{ +} + +unsigned int DrawIndirectBufferObject::addArray(osg::Array* array) +{ + return addBufferData(array); +} + +void DrawIndirectBufferObject::removeArray(osg::Array* array) +{ + removeBufferData(array); +} + +void DrawIndirectBufferObject::setArray(unsigned int i, Array* array) +{ + setBufferData(i,array); +} + +Array* DrawIndirectBufferObject::getArray(unsigned int i) +{ + return dynamic_cast(getBufferData(i)); +} + +const Array* DrawIndirectBufferObject::getArray(unsigned int i) const +{ + return dynamic_cast(getBufferData(i)); +} ////////////////////////////////////////////////////////////////////////////////// //