diff --git a/examples/osgmeshshader/osgmeshshader.cpp b/examples/osgmeshshader/osgmeshshader.cpp index de4188048..1b5426614 100644 --- a/examples/osgmeshshader/osgmeshshader.cpp +++ b/examples/osgmeshshader/osgmeshshader.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include int main( int argc, char** argv ) @@ -57,14 +58,18 @@ int main( int argc, char** argv ) program->addShader( vShader.get() ); program->addShader( fShader.get() ); - osg::ref_ptr drawMesh = new osg::DrawMeshTasks(0, 1); - drawMesh->getOrCreateStateSet()->setAttribute( program.get() ); + osg::ref_ptr group = new osg::Group; + group->getOrCreateStateSet()->setAttribute( program.get() ); - osgDB::writeNodeFile(*drawMesh, "test.osgt"); + group->addChild( new osg::DrawMeshTasks(0, 1) ); + + // group->addChild( new osg::DrawMeshTasksIndirect(0) ); // will require a buffer to be bound. + + osgDB::writeNodeFile(*group, "test.osgt"); osgViewer::Viewer viewer(arguments); - viewer.setSceneData( drawMesh ); + viewer.setSceneData( group ); // for non GL3/GL4 and non GLES2 platforms we need enable the osg_ uniforms that the shaders will use, // you don't need thse two lines on GL3/GL4 and GLES2 specific builds as these will be enable by default. diff --git a/include/osg/DrawMeshTasks b/include/osg/DrawMeshTasks index 6e946fc24..4113b397a 100644 --- a/include/osg/DrawMeshTasks +++ b/include/osg/DrawMeshTasks @@ -11,12 +11,10 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSG_DRAWPIXELS -#define OSG_DRAWPIXELS 1 +#ifndef OSG_DRAWMESHTASKS +#define OSG_DRAWMESHTASKS 1 #include -#include -#include namespace osg { diff --git a/include/osg/DrawMeshTasksIndirect b/include/osg/DrawMeshTasksIndirect new file mode 100644 index 000000000..a85c0b538 --- /dev/null +++ b/include/osg/DrawMeshTasksIndirect @@ -0,0 +1,51 @@ +/* -*-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_DRAWMESHTASKSINDIRECT +#define OSG_DRAWMESHTASKSINDIRECT 1 + +#include + +namespace osg { + +/** DrawMeshTasksIndirect is an osg::Drawable subclass which encapsulates glDrawMeshTasksIndirectNV.*/ +class OSG_EXPORT DrawMeshTasksIndirect : public Drawable +{ + public: + + DrawMeshTasksIndirect(); + + DrawMeshTasksIndirect(GLintptr offset); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + DrawMeshTasksIndirect(const DrawMeshTasksIndirect& drawimage,const CopyOp& copyop=CopyOp::SHALLOW_COPY); + + META_Node(osg, DrawMeshTasksIndirect); + + void setOffset(GLintptr offset) { _offset = offset; } + GLintptr getOffset() const { return _offset; } + + virtual void drawImplementation(RenderInfo& renderInfo) const; + + protected: + + DrawMeshTasksIndirect& operator = (const DrawMeshTasksIndirect&) { return *this;} + + virtual ~DrawMeshTasksIndirect(); + + GLintptr _offset; +}; + +} + +#endif diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 4a4d0a842..7c6cad484 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -74,6 +74,7 @@ SET(TARGET_H ${HEADER_PATH}/DisplaySettings ${HEADER_PATH}/Drawable ${HEADER_PATH}/DrawMeshTasks + ${HEADER_PATH}/DrawMeshTasksIndirect ${HEADER_PATH}/DrawPixels ${HEADER_PATH}/Endian ${HEADER_PATH}/Export @@ -291,6 +292,7 @@ SET(TARGET_SRC DisplaySettings.cpp Drawable.cpp DrawMeshTasks.cpp + DrawMeshTasksIndirect.cpp DrawPixels.cpp dxtctool.cpp dxtctool.h diff --git a/src/osg/DrawMeshTasks.cpp b/src/osg/DrawMeshTasks.cpp index 982cfcaa4..e35ff5bb9 100644 --- a/src/osg/DrawMeshTasks.cpp +++ b/src/osg/DrawMeshTasks.cpp @@ -14,7 +14,9 @@ using namespace osg; -DrawMeshTasks::DrawMeshTasks() +DrawMeshTasks::DrawMeshTasks(): + _first(0), + _count(0) { // turn off display lists as they are inappropriate setSupportsDisplayList(false); diff --git a/src/osg/DrawMeshTasksIndirect.cpp b/src/osg/DrawMeshTasksIndirect.cpp new file mode 100644 index 000000000..5428f779c --- /dev/null +++ b/src/osg/DrawMeshTasksIndirect.cpp @@ -0,0 +1,51 @@ +/* -*-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; + +DrawMeshTasksIndirect::DrawMeshTasksIndirect() : + _offset(0) +{ + // turn off display lists as they are inappropriate + setSupportsDisplayList(false); +} + +DrawMeshTasksIndirect::DrawMeshTasksIndirect(GLintptr offset): + _offset(offset) +{ +} + +DrawMeshTasksIndirect::DrawMeshTasksIndirect(const DrawMeshTasksIndirect& dmt,const CopyOp& copyop): + Drawable(dmt, copyop), + _offset(dmt._offset) +{ +} + +DrawMeshTasksIndirect::~DrawMeshTasksIndirect() +{ +} + +void DrawMeshTasksIndirect::drawImplementation(RenderInfo& renderInfo) const +{ + const GLExtensions* extensions = renderInfo.getState()->get(); + if (extensions->isMeshShaderSupported && extensions->glDrawMeshTasksIndirectNV) + { + extensions->glDrawMeshTasksIndirectNV(_offset); + } + else + { + OSG_NOTICE<<"glDrawMeshTasksIndirectNV not supported. "< +#include +#include +#include + +REGISTER_OBJECT_WRAPPER( DrawMeshTasksIndirect, + new osg::DrawMeshTasksIndirect, + osg::DrawMeshTasksIndirect, + "osg::Object osg::Node osg::Drawable osg::DrawMeshTasksIndirect" ) +{ + wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLintptr >( \ + "Offset", 0, &MyClass::getOffset, &MyClass::setOffset), osgDB::BaseSerializer::RW_INT ); +}