From 27a664a4e3fa74922e9c478392962fa8e0bf8c57 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 31 Mar 2021 18:36:45 +0100 Subject: [PATCH] Added osg::MultiDrawMeshTasksIndirect class --- examples/osgmeshshader/osgmeshshader.cpp | 3 +- include/osg/MultiDrawMeshTasksIndirect | 59 +++++++++++++++++++ src/osg/CMakeLists.txt | 2 + src/osg/DrawMeshTasks.cpp | 2 + src/osg/DrawMeshTasksIndirect.cpp | 2 + src/osg/MultiDrawMeshTasksIndirect.cpp | 59 +++++++++++++++++++ .../osg/MultiDrawMeshTasksIndirect.cpp | 19 ++++++ 7 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 include/osg/MultiDrawMeshTasksIndirect create mode 100644 src/osg/MultiDrawMeshTasksIndirect.cpp create mode 100644 src/osgWrappers/serializers/osg/MultiDrawMeshTasksIndirect.cpp diff --git a/examples/osgmeshshader/osgmeshshader.cpp b/examples/osgmeshshader/osgmeshshader.cpp index 1b5426614..86d0ca795 100644 --- a/examples/osgmeshshader/osgmeshshader.cpp +++ b/examples/osgmeshshader/osgmeshshader.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include int main( int argc, char** argv ) @@ -62,7 +63,7 @@ int main( int argc, char** argv ) group->getOrCreateStateSet()->setAttribute( program.get() ); 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. osgDB::writeNodeFile(*group, "test.osgt"); diff --git a/include/osg/MultiDrawMeshTasksIndirect b/include/osg/MultiDrawMeshTasksIndirect new file mode 100644 index 000000000..bb9d0e522 --- /dev/null +++ b/include/osg/MultiDrawMeshTasksIndirect @@ -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 + +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 diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 7c6cad484..ced55d877 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -75,6 +75,7 @@ SET(TARGET_H ${HEADER_PATH}/Drawable ${HEADER_PATH}/DrawMeshTasks ${HEADER_PATH}/DrawMeshTasksIndirect + ${HEADER_PATH}/MultiDrawMeshTasksIndirect ${HEADER_PATH}/DrawPixels ${HEADER_PATH}/Endian ${HEADER_PATH}/Export @@ -293,6 +294,7 @@ SET(TARGET_SRC Drawable.cpp DrawMeshTasks.cpp DrawMeshTasksIndirect.cpp + MultiDrawMeshTasksIndirect.cpp DrawPixels.cpp dxtctool.cpp dxtctool.h diff --git a/src/osg/DrawMeshTasks.cpp b/src/osg/DrawMeshTasks.cpp index e35ff5bb9..4c08c201e 100644 --- a/src/osg/DrawMeshTasks.cpp +++ b/src/osg/DrawMeshTasks.cpp @@ -26,6 +26,8 @@ DrawMeshTasks::DrawMeshTasks(GLuint first, GLuint count): _first(first), _count(count) { + // turn off display lists as they are inappropriate + setSupportsDisplayList(false); } DrawMeshTasks::DrawMeshTasks(const DrawMeshTasks& dmt,const CopyOp& copyop): diff --git a/src/osg/DrawMeshTasksIndirect.cpp b/src/osg/DrawMeshTasksIndirect.cpp index 5428f779c..afc51eb3e 100644 --- a/src/osg/DrawMeshTasksIndirect.cpp +++ b/src/osg/DrawMeshTasksIndirect.cpp @@ -24,6 +24,8 @@ DrawMeshTasksIndirect::DrawMeshTasksIndirect() : DrawMeshTasksIndirect::DrawMeshTasksIndirect(GLintptr offset): _offset(offset) { + // turn off display lists as they are inappropriate + setSupportsDisplayList(false); } DrawMeshTasksIndirect::DrawMeshTasksIndirect(const DrawMeshTasksIndirect& dmt,const CopyOp& copyop): diff --git a/src/osg/MultiDrawMeshTasksIndirect.cpp b/src/osg/MultiDrawMeshTasksIndirect.cpp new file mode 100644 index 000000000..850aaeaef --- /dev/null +++ b/src/osg/MultiDrawMeshTasksIndirect.cpp @@ -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 + +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(); + if (extensions->isMeshShaderSupported && extensions->glMultiDrawMeshTasksIndirectNV) + { + extensions->glMultiDrawMeshTasksIndirectNV(_offset, _drawCount, _stride); + } + else + { + OSG_NOTICE<<"glMultiDrawMeshTasksIndirectNV not supported. "< +#include +#include +#include + +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 ); +}