From 64404e9de3a564de088980905b22a42ada3f4b1b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 31 Mar 2021 17:34:39 +0100 Subject: [PATCH] Added osg::DrawMeshTasks implementaton. --- examples/osgmeshshader/osgmeshshader.cpp | 41 ++----------- include/osg/DrawMeshTasks | 57 +++++++++++++++++++ src/osg/CMakeLists.txt | 2 + src/osg/DrawMeshTasks.cpp | 52 +++++++++++++++++ src/osg/GLExtensions.cpp | 6 -- .../serializers/osg/DrawMeshTasks.cpp | 13 +++++ 6 files changed, 129 insertions(+), 42 deletions(-) create mode 100644 include/osg/DrawMeshTasks create mode 100644 src/osg/DrawMeshTasks.cpp create mode 100644 src/osgWrappers/serializers/osg/DrawMeshTasks.cpp diff --git a/examples/osgmeshshader/osgmeshshader.cpp b/examples/osgmeshshader/osgmeshshader.cpp index 2619c5243..de4188048 100644 --- a/examples/osgmeshshader/osgmeshshader.cpp +++ b/examples/osgmeshshader/osgmeshshader.cpp @@ -10,49 +10,16 @@ #include #include +#include #include #include #include #include #include #include +#include #include - -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(); - if (extensions->isMeshShaderSupported && extensions->glDrawMeshTasksNV) - { - extensions->glDrawMeshTasksNV(first, count); - } - else - { - OSG_NOTICE<<"glDrawMeshTasksNV not supported. "<addShader( vShader.get() ); program->addShader( fShader.get() ); - osg::ref_ptr drawMesh = new DrawMeshTasks(0, 1); + osg::ref_ptr drawMesh = new osg::DrawMeshTasks(0, 1); drawMesh->getOrCreateStateSet()->setAttribute( program.get() ); + osgDB::writeNodeFile(*drawMesh, "test.osgt"); + osgViewer::Viewer viewer(arguments); viewer.setSceneData( drawMesh ); diff --git a/include/osg/DrawMeshTasks b/include/osg/DrawMeshTasks new file mode 100644 index 000000000..6e946fc24 --- /dev/null +++ b/include/osg/DrawMeshTasks @@ -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 +#include +#include + +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 diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 9deed7af9..4a4d0a842 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -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 diff --git a/src/osg/DrawMeshTasks.cpp b/src/osg/DrawMeshTasks.cpp new file mode 100644 index 000000000..982cfcaa4 --- /dev/null +++ b/src/osg/DrawMeshTasks.cpp @@ -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 + +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(); + if (extensions->isMeshShaderSupported && extensions->glDrawMeshTasksNV) + { + extensions->glDrawMeshTasksNV(_first, _count); + } + else + { + OSG_NOTICE<<"glDrawMeshTasksNV not supported. "<