Added osg::MultiDrawMeshTasksIndirect class

This commit is contained in:
Robert Osfield 2021-03-31 18:36:45 +01:00
parent 874c9ac691
commit 27a664a4e3
7 changed files with 145 additions and 1 deletions

View File

@ -19,6 +19,7 @@
#include <osg/Shader> #include <osg/Shader>
#include <osg/DrawMeshTasks> #include <osg/DrawMeshTasks>
#include <osg/DrawMeshTasksIndirect> #include <osg/DrawMeshTasksIndirect>
#include <osg/MultiDrawMeshTasksIndirect>
#include <osgUtil/Optimizer> #include <osgUtil/Optimizer>
int main( int argc, char** argv ) int main( int argc, char** argv )
@ -62,7 +63,7 @@ int main( int argc, char** argv )
group->getOrCreateStateSet()->setAttribute( program.get() ); group->getOrCreateStateSet()->setAttribute( program.get() );
group->addChild( new osg::DrawMeshTasks(0, 1) ); group->addChild( new osg::DrawMeshTasks(0, 1) );
// group->addChild( new osg::MultiDrawMeshTasksIndirect(0, 0, 0) ); // will require a buffer to be bound.
// group->addChild( new osg::DrawMeshTasksIndirect(0) ); // will require a buffer to be bound. // group->addChild( new osg::DrawMeshTasksIndirect(0) ); // will require a buffer to be bound.
osgDB::writeNodeFile(*group, "test.osgt"); osgDB::writeNodeFile(*group, "test.osgt");

View File

@ -0,0 +1,59 @@
/* -*-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_MULTIDRAWMESHTASKSINDIRECT
#define OSG_MULTIDRAWMESHTASKSINDIRECT 1
#include <osg/Drawable>
namespace osg {
/** MultiDrawMeshTasksIndirect is an osg::Drawable subclass which encapsulates glMultiDrawMeshTasksIndirectNV.*/
class OSG_EXPORT MultiDrawMeshTasksIndirect : public Drawable
{
public:
MultiDrawMeshTasksIndirect();
MultiDrawMeshTasksIndirect(GLintptr offset, GLsizei drawCount, GLsizei stride);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
MultiDrawMeshTasksIndirect(const MultiDrawMeshTasksIndirect& drawimage,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, MultiDrawMeshTasksIndirect);
void setOffset(GLintptr offset) { _offset = offset; }
GLintptr getOffset() const { return _offset; }
void setDrawCount(GLsizei count) { _drawCount = count; }
GLsizei getDrawCount() const { return _drawCount; }
void setStride(GLsizei stride) { _stride = stride; }
GLsizei getStride() const { return _stride; }
virtual void drawImplementation(RenderInfo& renderInfo) const;
protected:
MultiDrawMeshTasksIndirect& operator = (const MultiDrawMeshTasksIndirect&) { return *this;}
virtual ~MultiDrawMeshTasksIndirect();
GLintptr _offset;
GLsizei _drawCount;
GLsizei _stride;
};
}
#endif

View File

@ -75,6 +75,7 @@ SET(TARGET_H
${HEADER_PATH}/Drawable ${HEADER_PATH}/Drawable
${HEADER_PATH}/DrawMeshTasks ${HEADER_PATH}/DrawMeshTasks
${HEADER_PATH}/DrawMeshTasksIndirect ${HEADER_PATH}/DrawMeshTasksIndirect
${HEADER_PATH}/MultiDrawMeshTasksIndirect
${HEADER_PATH}/DrawPixels ${HEADER_PATH}/DrawPixels
${HEADER_PATH}/Endian ${HEADER_PATH}/Endian
${HEADER_PATH}/Export ${HEADER_PATH}/Export
@ -293,6 +294,7 @@ SET(TARGET_SRC
Drawable.cpp Drawable.cpp
DrawMeshTasks.cpp DrawMeshTasks.cpp
DrawMeshTasksIndirect.cpp DrawMeshTasksIndirect.cpp
MultiDrawMeshTasksIndirect.cpp
DrawPixels.cpp DrawPixels.cpp
dxtctool.cpp dxtctool.cpp
dxtctool.h dxtctool.h

View File

@ -26,6 +26,8 @@ DrawMeshTasks::DrawMeshTasks(GLuint first, GLuint count):
_first(first), _first(first),
_count(count) _count(count)
{ {
// turn off display lists as they are inappropriate
setSupportsDisplayList(false);
} }
DrawMeshTasks::DrawMeshTasks(const DrawMeshTasks& dmt,const CopyOp& copyop): DrawMeshTasks::DrawMeshTasks(const DrawMeshTasks& dmt,const CopyOp& copyop):

View File

@ -24,6 +24,8 @@ DrawMeshTasksIndirect::DrawMeshTasksIndirect() :
DrawMeshTasksIndirect::DrawMeshTasksIndirect(GLintptr offset): DrawMeshTasksIndirect::DrawMeshTasksIndirect(GLintptr offset):
_offset(offset) _offset(offset)
{ {
// turn off display lists as they are inappropriate
setSupportsDisplayList(false);
} }
DrawMeshTasksIndirect::DrawMeshTasksIndirect(const DrawMeshTasksIndirect& dmt,const CopyOp& copyop): DrawMeshTasksIndirect::DrawMeshTasksIndirect(const DrawMeshTasksIndirect& dmt,const CopyOp& copyop):

View File

@ -0,0 +1,59 @@
/* -*-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/MultiDrawMeshTasksIndirect>
using namespace osg;
MultiDrawMeshTasksIndirect::MultiDrawMeshTasksIndirect() :
_offset(0),
_drawCount(0),
_stride(0)
{
// turn off display lists as they are inappropriate
setSupportsDisplayList(false);
}
MultiDrawMeshTasksIndirect::MultiDrawMeshTasksIndirect(GLintptr offset, GLsizei drawCount, GLsizei stride):
_offset(offset),
_drawCount(drawCount),
_stride(stride)
{
// turn off display lists as they are inappropriate
setSupportsDisplayList(false);
}
MultiDrawMeshTasksIndirect::MultiDrawMeshTasksIndirect(const MultiDrawMeshTasksIndirect& dmt,const CopyOp& copyop):
Drawable(dmt, copyop),
_offset(dmt._offset),
_drawCount(dmt._drawCount),
_stride(dmt._stride)
{
}
MultiDrawMeshTasksIndirect::~MultiDrawMeshTasksIndirect()
{
}
void MultiDrawMeshTasksIndirect::drawImplementation(RenderInfo& renderInfo) const
{
const GLExtensions* extensions = renderInfo.getState()->get<GLExtensions>();
if (extensions->isMeshShaderSupported && extensions->glMultiDrawMeshTasksIndirectNV)
{
extensions->glMultiDrawMeshTasksIndirectNV(_offset, _drawCount, _stride);
}
else
{
OSG_NOTICE<<"glMultiDrawMeshTasksIndirectNV not supported. "<<std::endl;
}
}

View File

@ -0,0 +1,19 @@
#include <osg/MultiDrawMeshTasksIndirect>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( MultiDrawMeshTasksIndirect,
new osg::MultiDrawMeshTasksIndirect,
osg::MultiDrawMeshTasksIndirect,
"osg::Object osg::Node osg::Drawable osg::MultiDrawMeshTasksIndirect" )
{
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLintptr >( \
"Offset", 0, &MyClass::getOffset, &MyClass::setOffset), osgDB::BaseSerializer::RW_INT );
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLsizei >( \
"DrawCount", 0, &MyClass::getDrawCount, &MyClass::setDrawCount), osgDB::BaseSerializer::RW_INT );
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLsizei>( \
"Stride", 0, &MyClass::getStride, &MyClass::setStride), osgDB::BaseSerializer::RW_INT );
}