Added osg::DrawMeshTasks implementaton.

This commit is contained in:
Robert Osfield 2021-03-31 17:34:39 +01:00
parent 0612b03eab
commit 64404e9de3
6 changed files with 129 additions and 42 deletions

View File

@ -10,49 +10,16 @@
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osg/GraphicsContext>
#include <osg/Camera>
#include <osg/Viewport>
#include <osg/StateSet>
#include <osg/Program>
#include <osg/Shader>
#include <osg/DrawMeshTasks>
#include <osgUtil/Optimizer>
class DrawMeshTasks : public osg::Drawable
{
public:
DrawMeshTasks() :
first(0),
count(0)
{
}
DrawMeshTasks(GLuint in_first, GLuint in_count) :
first(in_first),
count(in_count)
{
}
GLuint first;
GLuint count;
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
{
const osg::GLExtensions* extensions = renderInfo.getState()->get<osg::GLExtensions>();
if (extensions->isMeshShaderSupported && extensions->glDrawMeshTasksNV)
{
extensions->glDrawMeshTasksNV(first, count);
}
else
{
OSG_NOTICE<<"glDrawMeshTasksNV not supported. "<<std::endl;
}
}
};
int main( int argc, char** argv )
{
osg::ArgumentParser arguments( &argc, argv );
@ -90,9 +57,11 @@ int main( int argc, char** argv )
program->addShader( vShader.get() );
program->addShader( fShader.get() );
osg::ref_ptr<osg::Node> drawMesh = new DrawMeshTasks(0, 1);
osg::ref_ptr<osg::Node> drawMesh = new osg::DrawMeshTasks(0, 1);
drawMesh->getOrCreateStateSet()->setAttribute( program.get() );
osgDB::writeNodeFile(*drawMesh, "test.osgt");
osgViewer::Viewer viewer(arguments);
viewer.setSceneData( drawMesh );

57
include/osg/DrawMeshTasks Normal file
View File

@ -0,0 +1,57 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_DRAWPIXELS
#define OSG_DRAWPIXELS 1
#include <osg/Drawable>
#include <osg/Vec3>
#include <osg/Image>
namespace osg {
/** DrawMeshTasks is an osg::Drawable subclass which encapsulates glDrawMeshTasksNV.*/
class OSG_EXPORT DrawMeshTasks : public Drawable
{
public:
DrawMeshTasks();
DrawMeshTasks(GLuint first, GLuint count);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
DrawMeshTasks(const DrawMeshTasks& drawimage,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, DrawMeshTasks);
void setFirst(GLuint first) { _first = first; }
GLuint getFirst() const { return _first; }
void setCount(GLuint count) { _count = count; }
GLuint getCount() const { return _count; }
virtual void drawImplementation(RenderInfo& renderInfo) const;
protected:
DrawMeshTasks& operator = (const DrawMeshTasks&) { return *this;}
virtual ~DrawMeshTasks();
GLuint _first;
GLuint _count;
};
}
#endif

View File

@ -73,6 +73,7 @@ SET(TARGET_H
${HEADER_PATH}/DepthRangeIndexed
${HEADER_PATH}/DisplaySettings
${HEADER_PATH}/Drawable
${HEADER_PATH}/DrawMeshTasks
${HEADER_PATH}/DrawPixels
${HEADER_PATH}/Endian
${HEADER_PATH}/Export
@ -289,6 +290,7 @@ SET(TARGET_SRC
DepthRangeIndexed.cpp
DisplaySettings.cpp
Drawable.cpp
DrawMeshTasks.cpp
DrawPixels.cpp
dxtctool.cpp
dxtctool.h

52
src/osg/DrawMeshTasks.cpp Normal file
View File

@ -0,0 +1,52 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osg/DrawMeshTasks>
using namespace osg;
DrawMeshTasks::DrawMeshTasks()
{
// turn off display lists as they are inappropriate
setSupportsDisplayList(false);
}
DrawMeshTasks::DrawMeshTasks(GLuint first, GLuint count):
_first(first),
_count(count)
{
}
DrawMeshTasks::DrawMeshTasks(const DrawMeshTasks& dmt,const CopyOp& copyop):
Drawable(dmt, copyop),
_first(dmt._first),
_count(dmt._count)
{
}
DrawMeshTasks::~DrawMeshTasks()
{
}
void DrawMeshTasks::drawImplementation(RenderInfo& renderInfo) const
{
const GLExtensions* extensions = renderInfo.getState()->get<GLExtensions>();
if (extensions->isMeshShaderSupported && extensions->glDrawMeshTasksNV)
{
extensions->glDrawMeshTasksNV(_first, _count);
}
else
{
OSG_NOTICE<<"glDrawMeshTasksNV not supported. "<<std::endl;
}
}

View File

@ -1331,12 +1331,6 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
osg::setGLExtensionFuncPtr(glDrawMeshTasksIndirectNV, "glDrawMeshTasksIndirectNV", validContext);
osg::setGLExtensionFuncPtr(glMultiDrawMeshTasksIndirectNV, "glMultiDrawMeshTasksIndirectNV", validContext);
osg::setGLExtensionFuncPtr(glMultiDrawMeshTasksIndirectCountNV, "glMultiDrawMeshTasksIndirectCountNV", validContext);
OSG_NOTICE<<"isMeshShaderSupported = "<<isMeshShaderSupported<<std::endl;
OSG_NOTICE<<"glDrawMeshTasksNV = "<<(void*)(glDrawMeshTasksNV)<<std::endl;
OSG_NOTICE<<"glDrawMeshTasksIndirectNV = "<<(void*)(glDrawMeshTasksIndirectNV)<<std::endl;
OSG_NOTICE<<"glMultiDrawMeshTasksIndirectNV = "<<(void*)(glMultiDrawMeshTasksIndirectNV)<<std::endl;
OSG_NOTICE<<"glMultiDrawMeshTasksIndirectCountNV = "<<(void*)(glMultiDrawMeshTasksIndirectCountNV)<<std::endl;
}
GLExtensions::~GLExtensions()

View File

@ -0,0 +1,13 @@
#include <osg/DrawMeshTasks>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( DrawMeshTasks,
new osg::DrawMeshTasks,
osg::DrawMeshTasks,
"osg::Object osg::Node osg::Drawable osg::DrawMeshTasks" )
{
ADD_UINT_SERIALIZER( First, 0 );
ADD_UINT_SERIALIZER( Count, 0 );
}