From Wang Rui, "In the attached files I've added the Compute Shader support for OSG, as well as serializer updates and a new osgcomputeshaders example. My submission also include a setComputeGroups() function in Program for setting compute-shader work groups, and a bindToImageUnit() function in Texture for binding textures as image variables in shaders.

All code are tested on Windows 7 + NVIDIA GFX 570 with the latest GeForce 310.70 Driver (BETA), which could support OpenGL 4.3.

Compute shader information can be found at "http://www.opengl.org/registry/specs/ARB/compute_shader.txt"
"
This commit is contained in:
Robert Osfield
2013-01-25 11:54:03 +00:00
parent f6450a1123
commit 26a8f63212
16 changed files with 397 additions and 4 deletions

View File

@@ -137,7 +137,8 @@ void Program::ProgramBinary::assign(unsigned int size, const unsigned char* data
Program::Program() :
_geometryVerticesOut(1), _geometryInputType(GL_TRIANGLES),
_geometryOutputType(GL_TRIANGLE_STRIP),
_patchVertices(3)
_patchVertices(3),
_numGroupsX(0), _numGroupsY(0), _numGroupsZ(0)
{
}
@@ -167,6 +168,10 @@ Program::Program(const Program& rhs, const osg::CopyOp& copyop):
_geometryOutputType = rhs._geometryOutputType;
_patchVertices = rhs._patchVertices;
_numGroupsX = rhs._numGroupsX;
_numGroupsY = rhs._numGroupsY;
_numGroupsZ = rhs._numGroupsZ;
}
@@ -203,6 +208,15 @@ int Program::compare(const osg::StateAttribute& sa) const
if( _patchVertices < rhs._patchVertices ) return -1;
if( rhs._patchVertices < _patchVertices ) return 1;
if( _numGroupsX < rhs._numGroupsX ) return -1;
if( rhs._numGroupsX < _numGroupsX ) return 1;
if( _numGroupsY < rhs._numGroupsY ) return -1;
if( rhs._numGroupsY < _numGroupsY ) return 1;
if( _numGroupsZ < rhs._numGroupsZ ) return -1;
if( rhs._numGroupsZ < _numGroupsZ ) return 1;
ShaderList::const_iterator litr=_shaderList.begin();
ShaderList::const_iterator ritr=rhs._shaderList.begin();
@@ -397,6 +411,19 @@ GLint Program::getParameter( GLenum pname ) const
return 0;
}
void Program::setComputeGroups( GLint numGroupsX, GLint numGroupsY, GLint numGroupsZ )
{
_numGroupsX = numGroupsX;
_numGroupsY = numGroupsY;
_numGroupsZ = numGroupsZ;
}
void Program::getComputeGroups( GLint& numGroupsX, GLint& numGroupsY, GLint& numGroupsZ ) const
{
numGroupsX = _numGroupsX;
numGroupsY = _numGroupsY;
numGroupsZ = _numGroupsZ;
}
void Program::addBindAttribLocation( const std::string& name, GLuint index )
{
@@ -930,4 +957,8 @@ Program::ProgramBinary* Program::PerContextProgram::compileProgramBinary(osg::St
void Program::PerContextProgram::useProgram() const
{
_extensions->glUseProgram( _glProgramHandle );
if ( _program->_numGroupsX>0 && _program->_numGroupsY>0 && _program->_numGroupsZ>0 )
{
_extensions->glDispatchCompute( _program->_numGroupsX, _program->_numGroupsY, _program->_numGroupsZ );
}
}