Merge branch 'ComputeDispatch' of https://github.com/mp3butcher/OpenSceneGraph into mp3butcher-ComputeDispatch

This commit is contained in:
Robert Osfield
2017-11-29 09:30:56 +00:00
9 changed files with 117 additions and 77 deletions

View File

@@ -10,7 +10,7 @@
#include <osg/StateAttributeCallback>
#include <osg/Texture2D>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/ComputeDispatch>
#include <osgDB/ReadFile>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
@@ -167,6 +167,7 @@ class ComputeNode : public osg::PositionAttitudeTransform
public:
osg::ref_ptr<osg::ComputeDispatch> _computeDispatch;
osg::ref_ptr<osg::Program> _computeProgram;
osg::ref_ptr<osg::Shader> _computeShader; //compute and write position data in SSBO
@@ -204,6 +205,8 @@ public:
_vertexShaderSourcePath = "shaders/osgssboVertexShader.vs";
_geometryShaderSourcePath = "shaders/osgssboGeometryShader.gs";
_fragmentShaderSourcePath = "shaders/osgssboFragmentShader.fs";
_computeDispatch=new osg::ComputeDispatch();
addChild(_computeDispatch);
}
};
@@ -622,7 +625,7 @@ void ComputeNode::initComputingSetup()
{
_computeProgram = new osg::Program;
_computeProgram->setComputeGroups((NUM_ELEMENTS_X / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_X / WORK_GROUP_SIZE), (NUM_ELEMENTS_Y / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_Y / WORK_GROUP_SIZE), 1);
_computeDispatch->setComputeGroups((NUM_ELEMENTS_X / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_X / WORK_GROUP_SIZE), (NUM_ELEMENTS_Y / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_Y / WORK_GROUP_SIZE), 1);
_computeShader = osgDB::readRefShaderFile(osg::Shader::COMPUTE, _computeShaderSourcePath);
_computeProgram->addShader(_computeShader.get());

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) );