change the design of BufferIndexBinding to work with BufferData instead of BufferObject
allow convenient BufferData abstraction + serialization of BufferIndexBinding
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
* Copyright (C) 2010 Tim Moore
|
||||
* Copyright (C) 2012 David Callu
|
||||
* Copyright (C) 2017 Julien Valentin
|
||||
*
|
||||
* 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
|
||||
@@ -40,53 +41,67 @@ class OSG_EXPORT BufferIndexBinding : public StateAttribute
|
||||
{
|
||||
protected:
|
||||
BufferIndexBinding(GLenum target, GLuint index);
|
||||
BufferIndexBinding(GLenum target, GLuint index, BufferObject* bo, GLintptr offset,
|
||||
GLsizeiptr size);
|
||||
BufferIndexBinding(GLenum target, GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
||||
BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
public:
|
||||
// The member value is part of the key to this state attribute in
|
||||
// the State class. Using the index target, we can separately
|
||||
// track the bindings for many different index targets.
|
||||
virtual unsigned getMember() const { return static_cast<unsigned int>(_index); }
|
||||
|
||||
GLenum getTarget() const { return _target; }
|
||||
///enable arbitrary BufferBinding (user is responsible for _target mismatch with bufferdata
|
||||
/// what can be done is setting wrong _target and use the one of bd if not subclassed
|
||||
void setTarget(GLenum t){_target=t;}
|
||||
|
||||
/** Set the renderbuffer index of the BlendEquationi. */
|
||||
void setIndex(unsigned int index);
|
||||
inline void setBufferData(BufferData *bufferdata) {
|
||||
if (_bufferData.valid())
|
||||
{
|
||||
_bufferData->removeClient(this);
|
||||
}
|
||||
|
||||
_bufferData=bufferdata;
|
||||
|
||||
if (_bufferData.valid())
|
||||
{
|
||||
if(!_bufferData->getBufferObject())
|
||||
_bufferData->setBufferObject(new VertexBufferObject());
|
||||
if(_size==0)
|
||||
_size=_bufferData->getTotalDataSize();
|
||||
}
|
||||
}
|
||||
/** Get the buffer data to be bound.
|
||||
*/
|
||||
inline const BufferData* getBufferData() const { return _bufferData.get(); }
|
||||
inline BufferData* getBufferData(){ return _bufferData.get(); }
|
||||
|
||||
/** Get the index target.
|
||||
*/
|
||||
unsigned int getIndex() const { return _index; }
|
||||
|
||||
/** Set the buffer object that will be bound to the index target.
|
||||
inline GLuint getIndex() const { return _index; }
|
||||
/** Set the index target. (and update parents StateSets)
|
||||
*/
|
||||
void setBufferObject(BufferObject *bo) { _bufferObject = bo; }
|
||||
void setIndex(GLuint index);
|
||||
|
||||
/** Get the buffer object to be bound.
|
||||
*/
|
||||
const BufferObject* getBufferObject() const { return _bufferObject.get(); }
|
||||
BufferObject* getBufferObject(){ return _bufferObject.get(); }
|
||||
|
||||
/** Set the starting offset into the buffer object for data for
|
||||
/** Set the starting offset into the buffer data for
|
||||
the indexed target. Note: the required alignment on the offset
|
||||
may be quite large (e.g., 256 bytes on NVidia 8600M). This
|
||||
should be checked with glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT...).
|
||||
*/
|
||||
void setOffset(GLintptr offset) { _offset = offset; }
|
||||
GLintptr getOffset() const { return _offset; }
|
||||
inline void setOffset(GLintptr offset) { _offset = offset; }
|
||||
inline GLintptr getOffset() const { return _offset; }
|
||||
|
||||
/** Set the size of data for the indexed target.
|
||||
/** Set the size override of bufferdata binded for the indexed target.
|
||||
*/
|
||||
void setSize(GLsizeiptr size) { _size = size; }
|
||||
GLsizeiptr getSize() const { return _size; }
|
||||
inline void setSize(GLsizeiptr size) { _size = size; }
|
||||
inline GLsizeiptr getSize() const { return _size; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
protected:
|
||||
virtual ~BufferIndexBinding();
|
||||
const GLenum _target;
|
||||
/*const*/ GLenum _target;
|
||||
ref_ptr<BufferData> _bufferData;
|
||||
GLuint _index;
|
||||
ref_ptr<BufferObject> _bufferObject;
|
||||
GLintptr _offset;
|
||||
GLsizeiptr _size;
|
||||
};
|
||||
@@ -100,21 +115,20 @@ class OSG_EXPORT UniformBufferBinding : public BufferIndexBinding
|
||||
UniformBufferBinding(GLuint index);
|
||||
/** Create a binding for a uniform buffer index target.
|
||||
* @param index the index target
|
||||
* @param bo associated buffer object
|
||||
* @param offset offset into buffer object
|
||||
* @param size size of data in buffer object
|
||||
* @param bd associated buffer data
|
||||
* @param offset offset into buffer data
|
||||
* @param size size of data in buffer data
|
||||
*/
|
||||
UniformBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
|
||||
UniformBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
||||
UniformBufferBinding(const UniformBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
META_StateAttribute(osg, UniformBufferBinding, UNIFORMBUFFERBINDING);
|
||||
|
||||
virtual int compare(const StateAttribute& bb) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(UniformBufferBinding, bb)
|
||||
|
||||
COMPARE_StateAttribute_Parameter(_target)
|
||||
COMPARE_StateAttribute_Parameter(_index)
|
||||
COMPARE_StateAttribute_Parameter(_bufferObject)
|
||||
COMPARE_StateAttribute_Parameter(_bufferData)
|
||||
COMPARE_StateAttribute_Parameter(_offset)
|
||||
COMPARE_StateAttribute_Parameter(_size)
|
||||
return 0;
|
||||
@@ -127,17 +141,16 @@ class OSG_EXPORT TransformFeedbackBufferBinding : public BufferIndexBinding
|
||||
{
|
||||
public:
|
||||
TransformFeedbackBufferBinding(GLuint index = 0);
|
||||
TransformFeedbackBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
|
||||
TransformFeedbackBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
||||
TransformFeedbackBufferBinding(const TransformFeedbackBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
META_StateAttribute(osg, TransformFeedbackBufferBinding, TRANSFORMFEEDBACKBUFFERBINDING);
|
||||
|
||||
virtual int compare(const StateAttribute& bb) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(TransformFeedbackBufferBinding, bb)
|
||||
|
||||
COMPARE_StateAttribute_Parameter(_target)
|
||||
COMPARE_StateAttribute_Parameter(_index)
|
||||
COMPARE_StateAttribute_Parameter(_bufferObject)
|
||||
COMPARE_StateAttribute_Parameter(_bufferData)
|
||||
COMPARE_StateAttribute_Parameter(_offset)
|
||||
COMPARE_StateAttribute_Parameter(_size)
|
||||
return 0;
|
||||
@@ -152,11 +165,11 @@ class OSG_EXPORT AtomicCounterBufferBinding : public BufferIndexBinding
|
||||
AtomicCounterBufferBinding(GLuint index=0);
|
||||
/** Create a binding for a atomic counter buffer index target.
|
||||
* @param index the index target
|
||||
* @param bo associated buffer object
|
||||
* @param offset offset into buffer object
|
||||
* @param size size of data in buffer object
|
||||
* @param bd associated buffer data
|
||||
* @param offset offset into buffer data
|
||||
* @param size size of data in buffer data
|
||||
*/
|
||||
AtomicCounterBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
|
||||
AtomicCounterBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
||||
AtomicCounterBufferBinding(const AtomicCounterBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
META_StateAttribute(osg, AtomicCounterBufferBinding, ATOMICCOUNTERBUFFERBINDING);
|
||||
|
||||
@@ -165,10 +178,9 @@ class OSG_EXPORT AtomicCounterBufferBinding : public BufferIndexBinding
|
||||
virtual int compare(const StateAttribute& bb) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(AtomicCounterBufferBinding, bb)
|
||||
|
||||
COMPARE_StateAttribute_Parameter(_target)
|
||||
COMPARE_StateAttribute_Parameter(_index)
|
||||
COMPARE_StateAttribute_Parameter(_bufferObject)
|
||||
COMPARE_StateAttribute_Parameter(_bufferData)
|
||||
COMPARE_StateAttribute_Parameter(_offset)
|
||||
COMPARE_StateAttribute_Parameter(_size)
|
||||
return 0;
|
||||
@@ -181,11 +193,11 @@ class OSG_EXPORT ShaderStorageBufferBinding : public BufferIndexBinding
|
||||
ShaderStorageBufferBinding(GLuint index=0);
|
||||
/** Create a binding for a shader storage buffer index target.
|
||||
* @param index the index target
|
||||
* @param bo associated buffer object
|
||||
* @param offset offset into buffer object
|
||||
* @param size size of data in buffer object
|
||||
* @param bd associated buffer data
|
||||
* @param offset offset into buffer data
|
||||
* @param size size of data in buffer data
|
||||
*/
|
||||
ShaderStorageBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
|
||||
ShaderStorageBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
||||
ShaderStorageBufferBinding(const ShaderStorageBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
META_StateAttribute(osg, ShaderStorageBufferBinding, SHADERSTORAGEBUFFERBINDING);
|
||||
|
||||
@@ -194,31 +206,32 @@ class OSG_EXPORT ShaderStorageBufferBinding : public BufferIndexBinding
|
||||
COMPARE_StateAttribute_Types(ShaderStorageBufferBinding, bb)
|
||||
COMPARE_StateAttribute_Parameter(_target)
|
||||
COMPARE_StateAttribute_Parameter(_index)
|
||||
COMPARE_StateAttribute_Parameter(_bufferObject)
|
||||
COMPARE_StateAttribute_Parameter(_bufferData)
|
||||
COMPARE_StateAttribute_Parameter(_offset)
|
||||
COMPARE_StateAttribute_Parameter(_size)
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class OSG_EXPORT DrawIndirectBufferBinding : public BufferIndexBinding
|
||||
{
|
||||
public:
|
||||
DrawIndirectBufferBinding();
|
||||
/** Create a binding for a uniform buffer index target.
|
||||
* @param bo associated buffer object
|
||||
/** Create a binding for a draw indirect buffer target.
|
||||
* @param bd associated buffer data
|
||||
*/
|
||||
DrawIndirectBufferBinding( BufferObject* bo);
|
||||
void apply(State& state) const;
|
||||
DrawIndirectBufferBinding( BufferData* bd);
|
||||
DrawIndirectBufferBinding(const DrawIndirectBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, DrawIndirectBufferBinding, INDIRECTDRAWBUFFERBINDING);
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
virtual int compare(const StateAttribute& bb) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(DrawIndirectBufferBinding, bb)
|
||||
COMPARE_StateAttribute_Parameter(_target)
|
||||
COMPARE_StateAttribute_Parameter(_bufferObject)
|
||||
COMPARE_StateAttribute_Parameter(_bufferData)
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user