diff --git a/include/osg/PrimitiveSet b/include/osg/PrimitiveSet index 5948a8650..c96a95327 100644 --- a/include/osg/PrimitiveSet +++ b/include/osg/PrimitiveSet @@ -374,6 +374,7 @@ class DrawElements : public PrimitiveSet /** Get the const ElementBufferObject. If no EBO is assigned returns NULL*/ inline const osg::ElementBufferObject* getElementBufferObject() const { return dynamic_cast(_bufferObject.get()); } + virtual void resizeElements(unsigned int numIndices) = 0; virtual void reserveElements(unsigned int numIndices) = 0; virtual void setElement(unsigned int, unsigned int) = 0; virtual unsigned int getElement(unsigned int) = 0; @@ -430,6 +431,7 @@ class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } virtual void offsetIndices(int offset); + virtual void resizeElements(unsigned int numIndices) { resize(numIndices); } virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } @@ -492,6 +494,7 @@ class OSG_EXPORT DrawElementsUShort : public DrawElements, public VectorGLushort virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } virtual void offsetIndices(int offset); + virtual void resizeElements(unsigned int numIndices) { resize(numIndices); } virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } @@ -554,6 +557,7 @@ class OSG_EXPORT DrawElementsUInt : public DrawElements, public VectorGLuint virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } virtual void offsetIndices(int offset); + virtual void resizeElements(unsigned int numIndices) { resize(numIndices); } virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } diff --git a/src/osgWrappers/serializers/osg/Array.cpp b/src/osgWrappers/serializers/osg/Array.cpp index aa884f824..83920f8c7 100644 --- a/src/osgWrappers/serializers/osg/Array.cpp +++ b/src/osgWrappers/serializers/osg/Array.cpp @@ -111,7 +111,7 @@ REGISTER_OBJECT_WRAPPER( Array, } #define ARRAY_WRAPPERS( ARRAY ) \ - namespace Wrappers##ARRAY { REGISTER_OBJECT_WRAPPER( ARRAY, new osg::ARRAY, osg::ARRAY, "osg::Object osg::Array "#ARRAY ) {} } + namespace Wrappers##ARRAY { REGISTER_OBJECT_WRAPPER( ARRAY, new osg::ARRAY, osg::ARRAY, "osg::Object osg::Array osg::"#ARRAY ) {} } ARRAY_WRAPPERS(FloatArray) ARRAY_WRAPPERS(Vec2Array) diff --git a/src/osgWrappers/serializers/osg/PrimitiveSet.cpp b/src/osgWrappers/serializers/osg/PrimitiveSet.cpp new file mode 100644 index 000000000..d0b55b8b5 --- /dev/null +++ b/src/osgWrappers/serializers/osg/PrimitiveSet.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include + +namespace PrimitiveSetWrapper { + +REGISTER_OBJECT_WRAPPER( PrimitiveSet, + 0, + osg::PrimitiveSet, + "osg::Object osg::PrimitiveSet" ) +{ + + BEGIN_ENUM_SERIALIZER_NO_SET( Type, PrimitiveType ); + ADD_ENUM_VALUE( PrimitiveType ); + ADD_ENUM_VALUE( DrawArraysPrimitiveType ); + ADD_ENUM_VALUE( DrawArrayLengthsPrimitiveType ); + ADD_ENUM_VALUE( DrawElementsUBytePrimitiveType ); + ADD_ENUM_VALUE( DrawElementsUShortPrimitiveType ); + ADD_ENUM_VALUE( DrawElementsUIntPrimitiveType ); + END_ENUM_SERIALIZER(); + + ADD_GLENUM_SERIALIZER( Mode, GLenum, GL_NONE ); + + ADD_UINT_SERIALIZER_NO_SET( TotalDataSize, 0); + ADD_UINT_SERIALIZER_NO_SET( NumPrimitives, 0); + + wrapper->addSerializer( + new osgDB::PropByValSerializer< osg::PrimitiveSet, bool > ("supportsBufferObject", false, &osg::PrimitiveSet::supportsBufferObject, 0, osgDB::BaseSerializer::RW_BOOL ) + ); +} + +} + +namespace DrawArraysWrapper { + +REGISTER_OBJECT_WRAPPER( DrawArrays, + new osg::DrawArrays, + osg::DrawArrays, + "osg::Object osg::PrimitiveSet osg::DrawArrays" ) +{ + ADD_GLINT_SERIALIZER( First, 0); + ADD_GLINT_SERIALIZER( Count, 0); +} + +} + +namespace DrawElementsWrapper { + +struct ResizeDrawElements : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + { + if (inputParameters.empty()) return false; + + osg::Object* indexObject = inputParameters[0].get(); + + unsigned int index = 0; + osg::DoubleValueObject* dvo = dynamic_cast(indexObject); + if (dvo) index = static_cast(dvo->getValue()); + else + { + osg::UIntValueObject* uivo = dynamic_cast(indexObject); + if (uivo) index = uivo->getValue(); + } + osg::DrawElements* de = reinterpret_cast(objectPtr); + de->resizeElements(index); + + return true; + } +}; + + +REGISTER_OBJECT_WRAPPER( DrawElements, + 0, + osg::DrawElements, + "osg::Object osg::PrimitiveSet osg::DrawElements" ) +{ + ADD_METHOD_OBJECT( "resizeElements", ResizeDrawElements ); +} + +} + +#define DRAW_ELEMENTS_WRAPPER( DRAWELEMENTS ) \ + namespace Wrapper##DRAWELEMENTS { REGISTER_OBJECT_WRAPPER( DRAWELEMENTS, new osg::DRAWELEMENTS, osg::DRAWELEMENTS, "osg::Object osg::PrimitiveSet osg::DrawElements "#DRAWELEMENTS) {} } + +DRAW_ELEMENTS_WRAPPER( DrawElementsUByte ) +DRAW_ELEMENTS_WRAPPER( DrawElementsUShort ) +DRAW_ELEMENTS_WRAPPER( DrawElementsUInt )