change the design of BufferIndexBinding to work with BufferData instead of BufferObject
allow convenient BufferData abstraction + serialization of BufferIndexBinding
This commit is contained in:
@@ -773,7 +773,7 @@ void ComputeNode::initComputingSetup()
|
||||
_dataArray->setBufferObject(_ssbo.get());
|
||||
|
||||
|
||||
_ssbb = new osg::ShaderStorageBufferBinding(0, _ssbo.get(), 0, blockSize);
|
||||
_ssbb = new osg::ShaderStorageBufferBinding(0, _dataArray, 0, blockSize);
|
||||
statesetComputation->setAttributeAndModes(_ssbb.get(), osg::StateAttribute::ON);
|
||||
|
||||
|
||||
|
||||
@@ -108,10 +108,10 @@ class ResetAtomicCounter : public osg::StateAttributeCallback
|
||||
osg::AtomicCounterBufferBinding * acbb = dynamic_cast<osg::AtomicCounterBufferBinding *>(sa);
|
||||
if (acbb)
|
||||
{
|
||||
osg::AtomicCounterBufferObject * acbo = dynamic_cast<osg::AtomicCounterBufferObject*>(acbb->getBufferObject());
|
||||
if (acbo && acbo->getBufferData(0))
|
||||
osg::BufferData * acbd = acbb->getBufferData();
|
||||
if (acbd)
|
||||
{
|
||||
acbo->getBufferData(0)->dirty();
|
||||
acbd->dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,10 +207,10 @@ int main(int argc, char** argv)
|
||||
acboBlue->setUsage(GL_STREAM_COPY);
|
||||
atomicCounterArrayBlue->setBufferObject(acboBlue.get());
|
||||
|
||||
osg::ref_ptr<osg::AtomicCounterBufferBinding> acbbRedAndGreen = new osg::AtomicCounterBufferBinding(0, acboRedAndGreen.get(), 0, sizeof(GLuint)*3);
|
||||
osg::ref_ptr<osg::AtomicCounterBufferBinding> acbbRedAndGreen = new osg::AtomicCounterBufferBinding(0, atomicCounterArrayRedAndGreen.get(), 0, sizeof(GLuint)*3);
|
||||
ss->setAttributeAndModes(acbbRedAndGreen.get());
|
||||
|
||||
osg::ref_ptr<osg::AtomicCounterBufferBinding> acbbBlue = new osg::AtomicCounterBufferBinding(2, acboBlue.get(), 0, sizeof(GLuint));
|
||||
osg::ref_ptr<osg::AtomicCounterBufferBinding> acbbBlue = new osg::AtomicCounterBufferBinding(2, atomicCounterArrayBlue.get(), 0, sizeof(GLuint));
|
||||
ss->setAttributeAndModes(acbbBlue.get());
|
||||
|
||||
acbbRedAndGreen->setUpdateCallback(new ResetAtomicCounter);
|
||||
|
||||
@@ -187,14 +187,14 @@ struct IndirectTarget
|
||||
}
|
||||
void endRegister(unsigned int index, unsigned int rowsPerInstance, GLenum pixelFormat, GLenum type, GLint internalFormat, bool useMultiDrawArraysIndirect )
|
||||
{
|
||||
osg::Image* indirectCommandImage = new osg::Image;
|
||||
indirectCommandImage->setImage( indirectCommands->getTotalDataSize()/sizeof(unsigned int), 1, 1, GL_R32I, GL_RED, GL_UNSIGNED_INT, (unsigned char*)indirectCommands->getDataPointer(), osg::Image::NO_DELETE );
|
||||
// osg::Image* indirectCommandImage = new osg::Image;
|
||||
//indirectCommandImage->setImage( indirectCommands->getTotalDataSize()/sizeof(unsigned int), 1, 1, GL_R32I, GL_RED, GL_UNSIGNED_INT, (unsigned char*)indirectCommands->getDataPointer(), osg::Image::NO_DELETE );
|
||||
|
||||
osg::VertexBufferObject * indirectCommandImagebuffer=new osg::VertexBufferObject();
|
||||
indirectCommandImagebuffer->setUsage(GL_DYNAMIC_DRAW);
|
||||
indirectCommandImage->setBufferObject(indirectCommandImagebuffer);
|
||||
indirectCommands->setBufferObject(indirectCommandImagebuffer);
|
||||
|
||||
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommandImage);
|
||||
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommands);
|
||||
indirectCommandTextureBuffer->setInternalFormat( GL_R32I );
|
||||
indirectCommandTextureBuffer->bindToImageUnit(index, osg::Texture::READ_WRITE);
|
||||
indirectCommandTextureBuffer->setUnRefImageDataAfterApply(false);
|
||||
@@ -222,9 +222,9 @@ struct IndirectTarget
|
||||
}
|
||||
|
||||
///attach a DrawIndirect buffer binding to the stateset
|
||||
osg::ref_ptr<osg::DrawIndirectBufferBinding> bb=new osg::DrawIndirectBufferBinding();
|
||||
bb->setBufferObject(indirectCommandImage->getBufferObject());
|
||||
geometryAggregator->getAggregatedGeometry()->getOrCreateStateSet()->setAttribute(bb );
|
||||
osg::ref_ptr<osg::DrawIndirectBufferBinding> bb=new osg::DrawIndirectBufferBinding(indirectCommands);
|
||||
|
||||
geometryAggregator->getAggregatedGeometry()->getOrCreateStateSet()->setAttributeAndModes(bb );
|
||||
geometryAggregator->getAggregatedGeometry()->setUseDisplayList(false);
|
||||
geometryAggregator->getAggregatedGeometry()->setUseVertexBufferObjects(true);
|
||||
|
||||
@@ -288,7 +288,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 )
|
||||
@@ -724,16 +724,16 @@ struct ResetTexturesCallback : public osg::StateSet::Callback
|
||||
std::vector<unsigned int>::iterator it,eit;
|
||||
for(it=texUnitsDirty.begin(), eit=texUnitsDirty.end(); it!=eit; ++it)
|
||||
{
|
||||
osg::Texture* tex = dynamic_cast<osg::Texture*>( stateset->getTextureAttribute(*it,osg::StateAttribute::TEXTURE) );
|
||||
osg::TextureBuffer* tex = dynamic_cast<osg::TextureBuffer*>( stateset->getTextureAttribute(*it,osg::StateAttribute::TEXTURE) );
|
||||
if(tex==NULL)
|
||||
continue;
|
||||
osg::Image* img = tex->getImage(0);
|
||||
osg::BufferData* img = const_cast<osg::BufferData*>(tex->getBufferData());
|
||||
if(img!=NULL)
|
||||
img->dirty();
|
||||
}
|
||||
for(it=texUnitsDirtyParams.begin(), eit=texUnitsDirtyParams.end(); it!=eit; ++it)
|
||||
{
|
||||
osg::Texture* tex = dynamic_cast<osg::Texture*>( stateset->getTextureAttribute(*it,osg::StateAttribute::TEXTURE) );
|
||||
osg::TextureBuffer* tex = dynamic_cast<osg::TextureBuffer*>( stateset->getTextureAttribute(*it,osg::StateAttribute::TEXTURE) );
|
||||
if(tex!=NULL)
|
||||
tex->dirtyTextureParameters();
|
||||
}
|
||||
|
||||
@@ -104,9 +104,7 @@ public:
|
||||
void operator() (StateAttribute* attr, NodeVisitor* nv)
|
||||
{
|
||||
UniformBufferBinding* ubb = static_cast<UniformBufferBinding*>(attr);
|
||||
UniformBufferObject* ubo
|
||||
= static_cast<UniformBufferObject*>(ubb->getBufferObject());
|
||||
FloatArray* array = static_cast<FloatArray*>(ubo->getBufferData(0));
|
||||
FloatArray* array = static_cast<FloatArray*>(ubb->getBufferData());
|
||||
double time = nv->getFrameStamp()->getSimulationTime();
|
||||
double frac = fmod(time, 1.0);
|
||||
Vec4f warmColor = (Vec4f(0.0, 0.0, 1.0 ,1) * frac
|
||||
@@ -165,7 +163,7 @@ int main(int argc, char** argv)
|
||||
group1->addChild(loadedModel.get());
|
||||
scene->addChild(group1);
|
||||
ref_ptr<UniformBufferBinding> ubb1
|
||||
= new UniformBufferBinding(0, ubo.get(), 0, blockSize);
|
||||
= new UniformBufferBinding(0, colorArray.get(), 0, blockSize);
|
||||
ss1->setAttributeAndModes(ubb1.get(), StateAttribute::ON);
|
||||
|
||||
ref_ptr<FloatArray> colorArray2
|
||||
@@ -180,7 +178,7 @@ int main(int argc, char** argv)
|
||||
group2->addChild(loadedModel.get());
|
||||
scene->addChild(group2);
|
||||
ref_ptr<UniformBufferBinding> ubb2
|
||||
= new UniformBufferBinding(0, ubo2.get(), 0, blockSize);
|
||||
= new UniformBufferBinding(0, colorArray2.get(), 0, blockSize);
|
||||
ss2->setAttributeAndModes(ubb2.get(), StateAttribute::ON);
|
||||
|
||||
ref_ptr<FloatArray> colorArray3
|
||||
@@ -195,7 +193,7 @@ int main(int argc, char** argv)
|
||||
group3->addChild(loadedModel.get());
|
||||
scene->addChild(group3);
|
||||
ref_ptr<UniformBufferBinding> ubb3
|
||||
= new UniformBufferBinding(0, ubo3.get(), 0, blockSize);
|
||||
= new UniformBufferBinding(0, colorArray3.get(), 0, blockSize);
|
||||
ubb3->setUpdateCallback(new UniformBufferCallback);
|
||||
ubb3->setDataVariance(Object::DYNAMIC);
|
||||
ss3->setAttributeAndModes(ubb3.get(), StateAttribute::ON);
|
||||
|
||||
Reference in New Issue
Block a user