Merge pull request #278 from mp3butcher/MDI2

Mdi
This commit is contained in:
OpenSceneGraph git repository
2017-07-28 08:46:30 +01:00
committed by GitHub
7 changed files with 107 additions and 18 deletions

View File

@@ -181,18 +181,16 @@ struct IndirectTarget
: maxTargetQuantity(0)
{
indirectCommands = new osg::DefaultIndirectCommandDrawArrays;
indirectCommands->getBufferObject()->setUsage(GL_DYNAMIC_DRAW);
}
IndirectTarget( AggregateGeometryVisitor* agv, osg::Program* program )
: geometryAggregator(agv), drawProgram(program), maxTargetQuantity(0)
{
indirectCommands = new osg::DefaultIndirectCommandDrawArrays;
indirectCommands->getBufferObject()->setUsage(GL_DYNAMIC_DRAW);
}
void endRegister(unsigned int index, unsigned int rowsPerInstance, GLenum pixelFormat, GLenum type, GLint internalFormat, bool useMultiDrawArraysIndirect )
{
osg::VertexBufferObject * indirectCommandbuffer=new osg::VertexBufferObject();
indirectCommandbuffer->setUsage(GL_DYNAMIC_DRAW);
indirectCommands->setBufferObject(indirectCommandbuffer);
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommands);
indirectCommandTextureBuffer->setInternalFormat( GL_R32I );
indirectCommandTextureBuffer->bindToImageUnit(index, osg::Texture::READ_WRITE);

View File

@@ -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
{

View File

@@ -25,7 +25,7 @@ namespace osg {
class OSG_EXPORT IndirectCommandDrawArrays: public BufferData
{
public:
IndirectCommandDrawArrays():BufferData(){}
IndirectCommandDrawArrays():BufferData(){setBufferObject(new DrawIndirectBufferObject());}
IndirectCommandDrawArrays(const IndirectCommandDrawArrays& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/)
:BufferData(copy, copyop){ }
@@ -40,7 +40,7 @@ public:
class OSG_EXPORT IndirectCommandDrawElements: public BufferData
{
public:
IndirectCommandDrawElements():BufferData(){}
IndirectCommandDrawElements():BufferData(){setBufferObject(new DrawIndirectBufferObject());}
IndirectCommandDrawElements(const IndirectCommandDrawElements& copy,const CopyOp& copyop/*=CopyOp::SHALLOW_COPY*/)
:BufferData(copy, copyop){}
@@ -147,8 +147,9 @@ public:
/// set command array of this indirect primitive set
inline void setIndirectCommandArray(IndirectCommandDrawElements*idc) {
_indirectCommandArray = idc;
if(!_indirectCommandArray->getBufferObject())
_indirectCommandArray->setBufferObject(new osg::VertexBufferObject());
//ensure bo of idc is of the correct type
if(!dynamic_cast<DrawIndirectBufferObject* >(_indirectCommandArray->getBufferObject()))
_indirectCommandArray->setBufferObject(new DrawIndirectBufferObject());
}
/// get command array of this indirect primitive set
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray; }
@@ -655,8 +656,9 @@ public:
inline void setIndirectCommandArray(IndirectCommandDrawArrays*idc) {
_indirectCommandArray = idc;
if(!_indirectCommandArray->getBufferObject())
_indirectCommandArray->setBufferObject(new osg::VertexBufferObject());
//ensure bo of idc is of the correct type
if(!dynamic_cast<DrawIndirectBufferObject* >(_indirectCommandArray->getBufferObject()))
_indirectCommandArray->setBufferObject(new DrawIndirectBufferObject());
}
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const {
return _indirectCommandArray;

View File

@@ -591,6 +591,27 @@ class OSG_EXPORT State : public Referenced
}
inline void bindDrawIndirectBufferObject(osg::GLBufferObject* ibo)
{
if (ibo->isDirty())
{
ibo->compileBuffer();
_currentDIBO = ibo;
}
else if (ibo != _currentDIBO)
{
ibo->bindBuffer();
_currentDIBO = ibo;
}
}
inline void unbindDrawIndirectBufferObject()
{
if (!_currentDIBO) return;
_glBindBuffer(GL_DRAW_INDIRECT_BUFFER,0);
_currentDIBO = 0;
}
void setCurrentVertexArrayObject(GLuint vao) { _currentVAO = vao; }
GLuint getCurrentVertexArrayObject() const { return _currentVAO; }
@@ -1259,6 +1280,7 @@ class OSG_EXPORT State : public Referenced
unsigned int _currentActiveTextureUnit;
unsigned int _currentClientActiveTextureUnit;
GLBufferObject* _currentPBO;
GLBufferObject* _currentDIBO;
GLuint _currentVAO;

View File

@@ -1358,6 +1358,50 @@ const DrawElements* ElementBufferObject::getDrawElements(unsigned int i) const
return dynamic_cast<const DrawElements*>(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<osg::Array*>(getBufferData(i));
}
const Array* DrawIndirectBufferObject::getArray(unsigned int i) const
{
return dynamic_cast<const osg::Array*>(getBufferData(i));
}
//////////////////////////////////////////////////////////////////////////////////
//

View File

@@ -64,7 +64,7 @@ unsigned int DrawElementsIndirectUShort::getNumPrimitives() const{return getNumP
void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@@ -122,7 +122,7 @@ void DrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
}
void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@@ -176,7 +176,7 @@ void DrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const
}
void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@@ -282,7 +282,7 @@ void MultiDrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObje
{
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
@@ -340,7 +340,7 @@ MultiDrawElementsIndirectUShort::~MultiDrawElementsIndirectUShort()
void MultiDrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@@ -397,7 +397,7 @@ MultiDrawElementsIndirectUInt::~MultiDrawElementsIndirectUInt()
void MultiDrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const
{
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
@@ -450,7 +450,7 @@ void MultiDrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
void DrawArraysIndirect::draw(osg::State& state, bool) const
{
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLExtensions* ext = state.get<GLExtensions>();
@@ -517,7 +517,7 @@ unsigned int DrawArraysIndirect::getNumPrimitives() const
void MultiDrawArraysIndirect::draw(osg::State& state, bool) const
{
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID());
state.bindDrawIndirectBufferObject(dibo);
GLExtensions* ext = state.get<GLExtensions>();

View File

@@ -89,6 +89,7 @@ State::State():
_currentClientActiveTextureUnit=0;
_currentPBO = 0;
_currentDIBO = 0;
_currentVAO = 0;
_isSecondaryColorSupported = false;