Added osg::MultiDrawMeshTasksIndirectCount class to wrap glMultiDrawMeshTasksIndirectCountNV call.

This commit is contained in:
Robert Osfield 2021-04-01 08:45:42 +01:00
parent 27a664a4e3
commit 4599a86bc9
5 changed files with 152 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <osg/DrawMeshTasks>
#include <osg/DrawMeshTasksIndirect>
#include <osg/MultiDrawMeshTasksIndirect>
#include <osg/MultiDrawMeshTasksIndirectCount>
#include <osgUtil/Optimizer>
int main( int argc, char** argv )
@ -63,8 +64,9 @@ 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.
// group->addChild( new osg::MultiDrawMeshTasksIndirect(0, 0, 0) ); // will require a buffer to be bound.
// group->addChild( new osg::MultiDrawMeshTasksIndirectCount(0, 0, 0, 0) ); // will require a buffer to be bound.
osgDB::writeNodeFile(*group, "test.osgt");

View File

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

View File

@ -76,6 +76,7 @@ SET(TARGET_H
${HEADER_PATH}/DrawMeshTasks
${HEADER_PATH}/DrawMeshTasksIndirect
${HEADER_PATH}/MultiDrawMeshTasksIndirect
${HEADER_PATH}/MultiDrawMeshTasksIndirectCount
${HEADER_PATH}/DrawPixels
${HEADER_PATH}/Endian
${HEADER_PATH}/Export
@ -295,6 +296,7 @@ SET(TARGET_SRC
DrawMeshTasks.cpp
DrawMeshTasksIndirect.cpp
MultiDrawMeshTasksIndirect.cpp
MultiDrawMeshTasksIndirectCount.cpp
DrawPixels.cpp
dxtctool.cpp
dxtctool.h

View File

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

View File

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