diff --git a/examples/osgcomputeshaders/osgcomputeshaders.cpp b/examples/osgcomputeshaders/osgcomputeshaders.cpp index 7d87a7472..73265b522 100644 --- a/examples/osgcomputeshaders/osgcomputeshaders.cpp +++ b/examples/osgcomputeshaders/osgcomputeshaders.cpp @@ -20,6 +20,7 @@ // This example can work only if GL version is 4.3 or greater #include +#include #include #include #include @@ -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 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 scene = new osg::Group; scene->addChild( sourceNode ); diff --git a/examples/osggpucull/osggpucull.cpp b/examples/osggpucull/osggpucull.cpp index 7b8bd8a1d..ddf045f83 100644 --- a/examples/osggpucull/osggpucull.cpp +++ b/examples/osggpucull/osggpucull.cpp @@ -151,6 +151,7 @@ #include #include #include +#include #include #include #include @@ -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 indirectCommandTextureBuffer; + osg::ref_ptr indirectCommandImageBinding; osg::ref_ptr< AggregateGeometryVisitor > geometryAggregator; osg::ref_ptr drawProgram; osg::ref_ptr< osg::TextureBuffer > instanceTarget; + osg::ref_ptr instanceTargetimagebinding; unsigned int maxTargetQuantity; }; @@ -1713,4 +1720,3 @@ int main( int argc, char **argv ) return viewer.run(); } -