From a6069c3226a42d6ef29348b9e3ddd8adb5e147fd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Nov 2017 14:22:31 +0000 Subject: [PATCH] Introduced Drawable::CreateVertexArrayStateCallback to enable customization of how VertexArrayState objects. Added public accessors to the Drawable::VertexArrayStateList. --- include/osg/ComputeDispatch | 4 +-- include/osg/Drawable | 50 ++++++++++++++++++++++++++++-- include/osg/Geometry | 2 +- include/osgParticle/ParticleSystem | 2 +- include/osgTerrain/GeometryPool | 2 +- include/osgText/TextBase | 2 +- src/osg/Drawable.cpp | 6 ++-- src/osg/Geometry.cpp | 2 +- src/osgParticle/ParticleSystem.cpp | 2 +- src/osgTerrain/GeometryPool.cpp | 2 +- src/osgText/TextBase.cpp | 2 +- 11 files changed, 62 insertions(+), 14 deletions(-) diff --git a/include/osg/ComputeDispatch b/include/osg/ComputeDispatch index 411d8de32..5e0ac6ffe 100644 --- a/include/osg/ComputeDispatch +++ b/include/osg/ComputeDispatch @@ -34,9 +34,9 @@ namespace osg{ META_Node(osg, ComputeDispatch); - virtual void compileGLObjects(RenderInfo& renderInfo) const {} + virtual void compileGLObjects(RenderInfo&) const {} - virtual VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const { return 0; } + virtual VertexArrayState* createVertexArrayStateImplememtation(RenderInfo&) const { return 0; } virtual void drawImplementation(RenderInfo& renderInfo) const; diff --git a/include/osg/Drawable b/include/osg/Drawable index acae9d2c3..9547659f5 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -278,7 +278,53 @@ class OSG_EXPORT Drawable : public Node */ virtual void compileGLObjects(RenderInfo& renderInfo) const; - virtual VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const; + + /** Callback class for overriding the default Drawable::createCreateVertexArrayStateImplementation().*/ + struct CreateVertexArrayStateCallback : public virtual osg::Object + { + CreateVertexArrayStateCallback() {} + + CreateVertexArrayStateCallback(const CreateVertexArrayStateCallback& rhs,const CopyOp& copyop): + Object(rhs, copyop) {} + + META_Object(osg, CreateVertexArrayStateCallback); + + /** do customized createVertexArrayState .*/ + virtual osg::VertexArrayState* createVertexArrayStateImplementation(osg::RenderInfo& renderInfo, const osg::Drawable* drawable) const + { + return drawable->createVertexArrayStateImplementation(renderInfo); + } + }; + + + /** Set the callback to override the default Drawable::createCreateVertexArrayStateImplementation().*/ + void setCreateVertexArrayStateCallback(CreateVertexArrayStateCallback* cb) { _createVertexArrayStateCallback = cb; } + + /** Get the callback that overrides the default Drawable::createCreateVertexArrayStateImplementation().*/ + CreateVertexArrayStateCallback* getCreateVertexArrayStateCallback() { return _createVertexArrayStateCallback.get(); } + + /** Get the const callback that overrides the default Drawable::createCreateVertexArrayStateImplementation().*/ + const CreateVertexArrayStateCallback* getCreateVertexArrayStateCallback() const { return _createVertexArrayStateCallback.get(); } + + + /** Craeate tje VertexArrayState object used to track vertex array and vertex array object state. This method will be called automatically during rendering setup so users should not call this themselves.*/ + inline VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const + { + if (_createVertexArrayStateCallback.valid()) return _createVertexArrayStateCallback->createVertexArrayStateImplementation(renderInfo, this); + else return createVertexArrayStateImplementation(renderInfo); + } + + /** Implementaion of Craeate tje VertexArrayState object.*/ + virtual VertexArrayState* createVertexArrayStateImplementation(RenderInfo& renderInfo) const; + + typedef buffered_object< osg::ref_ptr > VertexArrayStateList; + + void setVertexArrayStateList(VertexArrayStateList& vasl) { _vertexArrayStateList = vasl; } + + VertexArrayStateList& getVertexArrayStateList() { return _vertexArrayStateList; } + + const VertexArrayStateList& getVertexArrayStateList() const { return _vertexArrayStateList; } + /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/ @@ -491,10 +537,10 @@ class OSG_EXPORT Drawable : public Node typedef osg::buffered_value GLObjectList; mutable GLObjectList _globjList; - typedef buffered_object< osg::ref_ptr > VertexArrayStateList; mutable VertexArrayStateList _vertexArrayStateList; ref_ptr _drawCallback; + ref_ptr _createVertexArrayStateCallback; }; #ifdef INLINE_DRAWABLE_DRAW diff --git a/include/osg/Geometry b/include/osg/Geometry index dd1094859..1fb8caea3 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -233,7 +233,7 @@ class OSG_EXPORT Geometry : public Drawable bool _containsDeprecatedData; - virtual VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const; + virtual VertexArrayState* createVertexArrayStateImplementation(RenderInfo& renderInfo) const; public: diff --git a/include/osgParticle/ParticleSystem b/include/osgParticle/ParticleSystem index 4348cb075..099549501 100644 --- a/include/osgParticle/ParticleSystem +++ b/include/osgParticle/ParticleSystem @@ -265,7 +265,7 @@ namespace osgParticle * for all graphics contexts. */ virtual void releaseGLObjects(osg::State* state=0) const; - virtual osg::VertexArrayState* createVertexArrayState(osg::RenderInfo& renderInfo) const; + virtual osg::VertexArrayState* createVertexArrayStateImplemenation(osg::RenderInfo& renderInfo) const; void adjustEstimatedMaxNumOfParticles(int delta) { _estimatedMaxNumOfParticles += delta; } diff --git a/include/osgTerrain/GeometryPool b/include/osgTerrain/GeometryPool index bb8e1e34b..06fec359a 100644 --- a/include/osgTerrain/GeometryPool +++ b/include/osgTerrain/GeometryPool @@ -66,7 +66,7 @@ class OSGTERRAIN_EXPORT SharedGeometry : public osg::Drawable const VertexToHeightFieldMapping& getVertexToHeightFieldMapping() const { return _vertexToHeightFieldMapping; } - osg::VertexArrayState* createVertexArrayState(osg::RenderInfo& renderInfo) const; + osg::VertexArrayState* createVertexArrayStateImplemenation(osg::RenderInfo& renderInfo) const; void compileGLObjects(osg::RenderInfo& renderInfo) const; diff --git a/include/osgText/TextBase b/include/osgText/TextBase index f262a0593..a674e3bd4 100644 --- a/include/osgText/TextBase +++ b/include/osgText/TextBase @@ -295,7 +295,7 @@ protected: void initArraysAndBuffers(); - osg::VertexArrayState* createVertexArrayState(osg::RenderInfo& renderInfo) const; + osg::VertexArrayState* createVertexArrayStateImplementation(osg::RenderInfo& renderInfo) const; void positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength); String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last); diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 857e4546d..f82df9df0 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -249,7 +249,8 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): _supportsVertexBufferObjects(drawable._supportsVertexBufferObjects), _useVertexBufferObjects(drawable._useVertexBufferObjects), _useVertexArrayObject(drawable._useVertexArrayObject), - _drawCallback(drawable._drawCallback) + _drawCallback(drawable._drawCallback), + _createVertexArrayStateCallback(drawable._createVertexArrayStateCallback) { setStateSet(copyop(drawable._stateset.get())); } @@ -696,8 +697,9 @@ void Drawable::draw(RenderInfo& renderInfo) const #endif -VertexArrayState* Drawable::createVertexArrayState(RenderInfo& renderInfo) const +VertexArrayState* Drawable::createVertexArrayStateImplementation(RenderInfo& renderInfo) const { + OSG_NOTICE<<"VertexArrayState* Drawable::createVertexArrayStateImplementation(RenderInfo& renderInfo) const "<assignAllDispatchers(); return vos; diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index aff29211b..30b1bd9b9 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -720,7 +720,7 @@ void Geometry::releaseGLObjects(State* state) const } -VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo) const +VertexArrayState* Geometry::createVertexArrayStateImplementation(RenderInfo& renderInfo) const { State& state = *renderInfo.getState(); diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index c20bef1d5..fc9fec13f 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -657,7 +657,7 @@ void osgParticle::ParticleSystem::releaseGLObjects(osg::State* state) const } } -osg::VertexArrayState* osgParticle::ParticleSystem::createVertexArrayState(osg::RenderInfo& renderInfo) const +osg::VertexArrayState* osgParticle::ParticleSystem::createVertexArrayStateImplemenation(osg::RenderInfo& renderInfo) const { osg::State& state = *renderInfo.getState(); diff --git a/src/osgTerrain/GeometryPool.cpp b/src/osgTerrain/GeometryPool.cpp index c69781f44..760579440 100644 --- a/src/osgTerrain/GeometryPool.cpp +++ b/src/osgTerrain/GeometryPool.cpp @@ -796,7 +796,7 @@ SharedGeometry::~SharedGeometry() { } -osg::VertexArrayState* SharedGeometry::createVertexArrayState(osg::RenderInfo& renderInfo) const +osg::VertexArrayState* SharedGeometry::createVertexArrayStateImplemenation(osg::RenderInfo& renderInfo) const { osg::State& state = *renderInfo.getState(); diff --git a/src/osgText/TextBase.cpp b/src/osgText/TextBase.cpp index 6fbf2e5ba..3d9534903 100644 --- a/src/osgText/TextBase.cpp +++ b/src/osgText/TextBase.cpp @@ -109,7 +109,7 @@ void TextBase::initArraysAndBuffers() _texcoords->setBufferObject(_vbo.get()); } -osg::VertexArrayState* TextBase::createVertexArrayState(osg::RenderInfo& renderInfo) const +osg::VertexArrayState* TextBase::createVertexArrayStateImplementation(osg::RenderInfo& renderInfo) const { State& state = *renderInfo.getState();