adapt examples for new BindImageTexture
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
// This example can work only if GL version is 4.3 or greater
|
||||
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/BindImageTexture>
|
||||
#include <osg/ComputeDispatch>
|
||||
#include <osg/Geode>
|
||||
#include <osgDB/ReadFile>
|
||||
@@ -52,7 +53,9 @@ int main( int argc, char** argv )
|
||||
tex2D->setInternalFormat( GL_R32F );
|
||||
tex2D->setSourceFormat( GL_RED );
|
||||
tex2D->setSourceType( GL_FLOAT );
|
||||
tex2D->bindToImageUnit( 0, osg::Texture::WRITE_ONLY ); // So we can use 'image2D' in the compute shader
|
||||
// So we can use 'image2D' in the compute shader
|
||||
osg::ref_ptr<osg::BindImageTexture> imagbinding = new osg::BindImageTexture(0, tex2D, osg::BindImageTexture::WRITE_ONLY, GL_R32F);
|
||||
|
||||
|
||||
// The compute shader can't work with other kinds of shaders
|
||||
// It also requires the work group numbers. Setting them to 0 will disable the compute shader
|
||||
@@ -75,7 +78,7 @@ int main( int argc, char** argv )
|
||||
quad->addDrawable( geom );
|
||||
quad->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
|
||||
quad->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex2D.get() );
|
||||
|
||||
quad->getOrCreateStateSet()->setAttributeAndModes(imagbinding.get());
|
||||
// Create the scene graph and start the viewer
|
||||
osg::ref_ptr<osg::Group> scene = new osg::Group;
|
||||
scene->addChild( sourceNode );
|
||||
|
||||
@@ -151,6 +151,7 @@
|
||||
#include <osg/Image>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TextureBuffer>
|
||||
#include <osg/BindImageTexture>
|
||||
#include <osg/BufferIndexBinding>
|
||||
#include <osg/ComputeBoundsVisitor>
|
||||
#include <osg/LightSource>
|
||||
@@ -321,9 +322,9 @@ struct IndirectTarget
|
||||
{
|
||||
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommands.get());
|
||||
indirectCommandTextureBuffer->setInternalFormat( GL_R32I );
|
||||
indirectCommandTextureBuffer->bindToImageUnit(index, osg::Texture::READ_WRITE);
|
||||
indirectCommandTextureBuffer->setUnRefImageDataAfterApply(false);
|
||||
|
||||
indirectCommandImageBinding=new osg::BindImageTexture(index, indirectCommandTextureBuffer, osg::BindImageTexture::READ_WRITE, GL_R32I);
|
||||
|
||||
// add proper primitivesets to geometryAggregators
|
||||
if( !useMultiDrawArraysIndirect ) // use glDrawArraysIndirect()
|
||||
@@ -365,7 +366,8 @@ struct IndirectTarget
|
||||
|
||||
instanceTarget = new osg::TextureBuffer(instanceTargetImage);
|
||||
instanceTarget->setInternalFormat( internalFormat );
|
||||
instanceTarget->bindToImageUnit(OSGGPUCULL_MAXIMUM_INDIRECT_TARGET_NUMBER+index, osg::Texture::READ_WRITE);
|
||||
|
||||
instanceTargetimagebinding = new osg::BindImageTexture(OSGGPUCULL_MAXIMUM_INDIRECT_TARGET_NUMBER+index, instanceTarget, osg::BindImageTexture::READ_WRITE, internalFormat);
|
||||
|
||||
}
|
||||
|
||||
@@ -374,6 +376,7 @@ struct IndirectTarget
|
||||
std::string uniformName = uniformNamePrefix + char( '0' + index );
|
||||
osg::Uniform* uniform = new osg::Uniform(uniformName.c_str(), (int)index );
|
||||
stateset->addUniform( uniform );
|
||||
stateset->setAttribute(indirectCommandImageBinding);
|
||||
stateset->setTextureAttribute( index, indirectCommandTextureBuffer.get() );
|
||||
|
||||
|
||||
@@ -389,6 +392,8 @@ struct IndirectTarget
|
||||
|
||||
osg::Uniform* uniform = new osg::Uniform(uniformName.c_str(), (int)(OSGGPUCULL_MAXIMUM_INDIRECT_TARGET_NUMBER+index) );
|
||||
stateset->addUniform( uniform );
|
||||
|
||||
stateset->setAttribute(instanceTargetimagebinding);
|
||||
stateset->setTextureAttribute( OSGGPUCULL_MAXIMUM_INDIRECT_TARGET_NUMBER+index, instanceTarget.get() );
|
||||
}
|
||||
|
||||
@@ -400,9 +405,11 @@ struct IndirectTarget
|
||||
|
||||
osg::ref_ptr< osg::DefaultIndirectCommandDrawArrays > indirectCommands;
|
||||
osg::ref_ptr<osg::TextureBuffer> indirectCommandTextureBuffer;
|
||||
osg::ref_ptr<osg::BindImageTexture> indirectCommandImageBinding;
|
||||
osg::ref_ptr< AggregateGeometryVisitor > geometryAggregator;
|
||||
osg::ref_ptr<osg::Program> drawProgram;
|
||||
osg::ref_ptr< osg::TextureBuffer > instanceTarget;
|
||||
osg::ref_ptr<osg::BindImageTexture> instanceTargetimagebinding;
|
||||
unsigned int maxTargetQuantity;
|
||||
};
|
||||
|
||||
@@ -1713,4 +1720,3 @@ int main( int argc, char **argv )
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user