Introduced Drawable::CreateVertexArrayStateCallback to enable customization of how VertexArrayState objects.

Added public accessors to the Drawable::VertexArrayStateList.
This commit is contained in:
Robert Osfield 2017-11-29 14:22:31 +00:00
parent 03434b20cf
commit a6069c3226
11 changed files with 62 additions and 14 deletions

View File

@ -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;

View File

@ -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<VertexArrayState> > 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<GLuint> GLObjectList;
mutable GLObjectList _globjList;
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
mutable VertexArrayStateList _vertexArrayStateList;
ref_ptr<DrawCallback> _drawCallback;
ref_ptr<CreateVertexArrayStateCallback> _createVertexArrayStateCallback;
};
#ifdef INLINE_DRAWABLE_DRAW

View File

@ -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:

View File

@ -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; }

View File

@ -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;

View File

@ -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);

View File

@ -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 "<<this<<std::endl;
VertexArrayState* vos = new osg::VertexArrayState(renderInfo.getState());
vos->assignAllDispatchers();
return vos;

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();