add ComputeDispatch class

revoke glDispatch in PCProgram::useProgram
update example
This commit is contained in:
Julien Valentin
2017-11-28 17:30:04 +01:00
parent 117045170d
commit bf1b4ec2bb
6 changed files with 100 additions and 8 deletions

View File

@@ -20,7 +20,7 @@
// This example can work only if GL version is 4.3 or greater
#include <osg/Texture2D>
#include <osg/Geometry>
#include <osg/ComputeDispatch>
#include <osg/Geode>
#include <osgDB/ReadFile>
#include <osgGA/StateSetManipulator>
@@ -57,14 +57,12 @@ int main( int argc, char** argv )
// 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
osg::ref_ptr<osg::Program> computeProg = new osg::Program;
computeProg->setComputeGroups( 512/16, 512/16, 1 );
computeProg->addShader( new osg::Shader(osg::Shader::COMPUTE, computeSrc) );
// Create a node for outputting to the texture.
// It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then.
// TODO: maybe we can have a custom drawable which also will implement glMemoryBarrier?
osg::ref_ptr<osg::Node> sourceNode = osgDB::readRefNodeFile("axes.osgt");
if ( !sourceNode ) sourceNode = new osg::Node;
osg::ref_ptr<osg::Node> sourceNode = new osg::ComputeDispatch(512/16, 512/16, 1 );
sourceNode->setDataVariance( osg::Object::DYNAMIC );
sourceNode->getOrCreateStateSet()->setAttributeAndModes( computeProg.get() );
sourceNode->getOrCreateStateSet()->addUniform( new osg::Uniform("targetTex", (int)0) );