Merge remote-tracking branch 'upstream/master' into MDI7

This commit is contained in:
Julien Valentin
2017-08-24 11:26:23 +02:00
108 changed files with 2569 additions and 415 deletions

View File

@@ -36,17 +36,13 @@
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osg/BufferTemplate>
#include <osg/PrimitiveSetIndirect>
#include "ShapeToGeometry.h"
#include "AggregateGeometryVisitor.h"
#if 0
#include "DrawIndirectPrimitiveSet.h"
#else
#include <osg/PrimitiveSetIndirect>
#endif
#include "GpuCullShaders.h"
// each instance type may have max 8 LODs ( if you change
// this value, don't forget to change it in vertex shaders accordingly )
const unsigned int OSGGPUCULL_MAXIMUM_LOD_NUMBER = 8;
@@ -180,17 +176,20 @@ struct IndirectTarget
IndirectTarget()
: maxTargetQuantity(0)
{
indirectCommands = new osg::DefaultIndirectCommandDrawArrays;
indirectCommands->getBufferObject()->setUsage(GL_DYNAMIC_DRAW);
indirectCommands = new osg::DrawArraysIndirectCommandArray ;
}
IndirectTarget( AggregateGeometryVisitor* agv, osg::Program* program )
: geometryAggregator(agv), drawProgram(program), maxTargetQuantity(0)
{
indirectCommands = new osg::DefaultIndirectCommandDrawArrays;
indirectCommands->getBufferObject()->setUsage(GL_DYNAMIC_DRAW);
indirectCommands = new osg::DrawArraysIndirectCommandArray;
}
void endRegister(unsigned int index, unsigned int rowsPerInstance, GLenum pixelFormat, GLenum type, GLint internalFormat, bool useMultiDrawArraysIndirect )
{
osg::DrawIndirectBufferObject * indirectCommandbuffer=new osg::DrawIndirectBufferObject();
indirectCommandbuffer->setUsage(GL_DYNAMIC_DRAW);
indirectCommands->setBufferObject(indirectCommandbuffer);
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommands);
indirectCommandTextureBuffer->setInternalFormat( GL_R32I );
indirectCommandTextureBuffer->bindToImageUnit(index, osg::Texture::READ_WRITE);
@@ -200,27 +199,28 @@ struct IndirectTarget
// add proper primitivesets to geometryAggregators
if( !useMultiDrawArraysIndirect ) // use glDrawArraysIndirect()
{
std::vector<osg::DrawArraysIndirect*> newPrimitiveSets;
std::vector<DrawArraysIndirect*> newPrimitiveSets;
for(unsigned int j=0;j<indirectCommands->size(); ++j){
osg::DrawArraysIndirect *ipr=new osg::DrawArraysIndirect( GL_TRIANGLES, j );
ipr->setIndirectCommandArray( indirectCommands);
newPrimitiveSets.push_back(ipr);
}
for(unsigned int j=0;j<indirectCommands->size(); ++j)
newPrimitiveSets.push_back( new DrawArraysIndirect( GL_TRIANGLES, j*sizeof( osg::DrawArraysIndirectCommand ), indirectCommands ) );
geometryAggregator->getAggregatedGeometry()->removePrimitiveSet(0,geometryAggregator->getAggregatedGeometry()->getNumPrimitiveSets() );
for(unsigned int j=0;j<indirectCommands->size(); ++j)
geometryAggregator->getAggregatedGeometry()->addPrimitiveSet( newPrimitiveSets[j] );
/*DrawIndirectBufferBinding should be deprecated
///attach a DrawIndirect buffer binding to the stateset for non builtin primset DrawArraysIndirect
osg::ref_ptr<osg::DrawIndirectBufferBinding> bb=new osg::DrawIndirectBufferBinding();
bb->setBufferObject(indirectCommandbuffer );
geometryAggregator->getAggregatedGeometry()->getOrCreateStateSet()->setAttribute(bb );*/
}
else // use glMultiDrawArraysIndirect()
{
osg::MultiDrawArraysIndirect *ipr=new osg::MultiDrawArraysIndirect( GL_TRIANGLES );
ipr->setIndirectCommandArray( indirectCommands );
osg::MultiDrawArraysIndirect * mdi=new osg::MultiDrawArraysIndirect(GL_TRIANGLES);
mdi->setIndirectCommandArray(indirectCommands);
geometryAggregator->getAggregatedGeometry()->removePrimitiveSet(0,geometryAggregator->getAggregatedGeometry()->getNumPrimitiveSets() );
geometryAggregator->getAggregatedGeometry()->addPrimitiveSet( ipr );
geometryAggregator->getAggregatedGeometry()->addPrimitiveSet(mdi );
}
geometryAggregator->getAggregatedGeometry()->setUseDisplayList(false);
@@ -266,7 +266,7 @@ struct IndirectTarget
stateset->setAttributeAndModes( drawProgram.get(), osg::StateAttribute::ON );
}
osg::ref_ptr< osg::DefaultIndirectCommandDrawArrays > indirectCommands;
osg::ref_ptr< osg::DrawArraysIndirectCommandArray > indirectCommands;
osg::ref_ptr<osg::TextureBuffer> indirectCommandTextureBuffer;
osg::ref_ptr< AggregateGeometryVisitor > geometryAggregator;
osg::ref_ptr<osg::Program> drawProgram;
@@ -286,7 +286,7 @@ struct GPUCullData
instanceTypesUBO = new osg::UniformBufferObject;
// instanceTypesUBO->setUsage( GL_STREAM_DRAW );
instanceTypes->setBufferObject( instanceTypesUBO.get() );
instanceTypesUBB = new osg::UniformBufferBinding(1, instanceTypesUBO.get(), 0, 0);
instanceTypesUBB = new osg::UniformBufferBinding(1, instanceTypes.get(), 0, 0);
}
void setUseMultiDrawArraysIndirect( bool value )
@@ -316,7 +316,7 @@ struct GPUCullData
// AggregateGeometryVisitor creates single osg::Geometry from all objects used by specific indirect target
AggregateGeometryVisitor::AddObjectResult aoResult = target->second.geometryAggregator->addObject( node , typeID, lodNumber );
// Information about first vertex and a number of vertices is stored for later primitiveset creation
target->second.indirectCommands->push_back( osg::DrawArraysIndirectCommand( aoResult.count,1, aoResult.first ) );
target->second.indirectCommands->push_back( osg::DrawArraysIndirectCommand( aoResult.count,1,aoResult.first ) );
osg::ComputeBoundsVisitor cbv;
node->accept(cbv);
@@ -725,9 +725,9 @@ struct ResetTexturesCallback : public osg::StateSet::Callback
osg::TextureBuffer* tex = dynamic_cast<osg::TextureBuffer*>( stateset->getTextureAttribute(*it,osg::StateAttribute::TEXTURE) );
if(tex==NULL)
continue;
osg::BufferData* img =const_cast<osg::BufferData*>(tex->getBufferData());
if(img!=NULL)
img->dirty();
osg::BufferData* drawcmds = tex->getBufferData();
if(drawcmds!=NULL)
drawcmds->dirty();
}
for(it=texUnitsDirtyParams.begin(), eit=texUnitsDirtyParams.end(); it!=eit; ++it)
{