BufferIndexBinding
Go to the documentation of this file.
/* -*-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
* (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_BUFFERINDEXBINDING
#define OSG_BUFFERINDEXBINDING 1
#include <osg/Array>
#include <osg/Export>
#include <osg/BufferObject>
#include <osg/StateAttribute>
#ifndef GL_TRANSFORM_FEEDBACK_BUFFER
#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E
#endif
namespace osg {
class State;
// Common implementation superclass
class OSG_EXPORT BufferIndexBinding : public StateAttribute
{
protected:
BufferIndexBinding(GLenum target, GLuint index);
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; }
void setTarget(GLenum t){_target=t;}
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();
}
}
inline const BufferData* getBufferData() const { return _bufferData.get(); }
inline BufferData* getBufferData(){ return _bufferData.get(); }
inline GLuint getIndex() const { return _index; }
void setIndex(GLuint index);
inline void setOffset(GLintptr offset) { _offset = offset; }
inline GLintptr getOffset() const { return _offset; }
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;
ref_ptr<BufferData> _bufferData;
GLuint _index;
GLintptr _offset;
GLsizeiptr _size;
};
class OSG_EXPORT UniformBufferBinding : public BufferIndexBinding
{
public:
UniformBufferBinding();
UniformBufferBinding(GLuint index);
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(_bufferData)
COMPARE_StateAttribute_Parameter(_offset)
COMPARE_StateAttribute_Parameter(_size)
return 0;
}
};
class OSG_EXPORT TransformFeedbackBufferBinding : public BufferIndexBinding
{
public:
TransformFeedbackBufferBinding(GLuint index = 0);
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(_bufferData)
COMPARE_StateAttribute_Parameter(_offset)
COMPARE_StateAttribute_Parameter(_size)
return 0;
}
};
class OSG_EXPORT AtomicCounterBufferBinding : public BufferIndexBinding
{
public:
AtomicCounterBufferBinding(GLuint index=0);
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);
void readData(osg::State & state, osg::UIntArray & uintArray) const;
virtual int compare(const StateAttribute& bb) const
{
COMPARE_StateAttribute_Types(AtomicCounterBufferBinding, bb)
COMPARE_StateAttribute_Parameter(_target)
COMPARE_StateAttribute_Parameter(_index)
COMPARE_StateAttribute_Parameter(_bufferData)
COMPARE_StateAttribute_Parameter(_offset)
COMPARE_StateAttribute_Parameter(_size)
return 0;
}
};
class OSG_EXPORT ShaderStorageBufferBinding : public BufferIndexBinding
{
public:
ShaderStorageBufferBinding(GLuint index=0);
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);
virtual int compare(const StateAttribute& bb) const
{
COMPARE_StateAttribute_Types(ShaderStorageBufferBinding, bb)
COMPARE_StateAttribute_Parameter(_target)
COMPARE_StateAttribute_Parameter(_index)
COMPARE_StateAttribute_Parameter(_bufferData)
COMPARE_StateAttribute_Parameter(_offset)
COMPARE_StateAttribute_Parameter(_size)
return 0;
}
};
} // namespace osg
#endif
Array
BufferObject
StateAttribute
COMPARE_StateAttribute_Parameter
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
COMPARE_StateAttribute_Types
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
osg::AtomicCounterBufferBinding::readData
void readData(osg::State &state, osg::UIntArray &uintArray) const
osg::AtomicCounterBufferBinding::AtomicCounterBufferBinding
AtomicCounterBufferBinding(const AtomicCounterBufferBinding &rhs, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::AtomicCounterBufferBinding::AtomicCounterBufferBinding
AtomicCounterBufferBinding(GLuint index, BufferData *bd, GLintptr offset=0, GLsizeiptr size=0)
osg::AtomicCounterBufferBinding::AtomicCounterBufferBinding
AtomicCounterBufferBinding(GLuint index=0)
osg::AtomicCounterBufferBinding::compare
virtual int compare(const StateAttribute &bb) const
Definition BufferIndexBinding:178
osg::AtomicCounterBufferBinding::META_StateAttribute
META_StateAttribute(osg, AtomicCounterBufferBinding, ATOMICCOUNTERBUFFERBINDING)
osg::BufferData
Definition BufferObject:495
osg::BufferIndexBinding::setTarget
void setTarget(GLenum t)
Definition BufferIndexBinding:54
osg::BufferIndexBinding::getBufferData
BufferData * getBufferData()
Definition BufferIndexBinding:75
osg::BufferIndexBinding::_target
GLenum _target
Definition BufferIndexBinding:102
osg::BufferIndexBinding::getTarget
GLenum getTarget() const
Definition BufferIndexBinding:51
osg::BufferIndexBinding::getSize
GLsizeiptr getSize() const
Definition BufferIndexBinding:96
osg::BufferIndexBinding::setIndex
void setIndex(GLuint index)
osg::BufferIndexBinding::getOffset
GLintptr getOffset() const
Definition BufferIndexBinding:91
osg::BufferIndexBinding::getBufferData
const BufferData * getBufferData() const
Definition BufferIndexBinding:74
osg::BufferIndexBinding::setOffset
void setOffset(GLintptr offset)
Definition BufferIndexBinding:90
osg::BufferIndexBinding::getIndex
GLuint getIndex() const
Definition BufferIndexBinding:79
osg::BufferIndexBinding::_bufferData
ref_ptr< BufferData > _bufferData
Definition BufferIndexBinding:103
osg::BufferIndexBinding::apply
virtual void apply(State &state) const
osg::BufferIndexBinding::getMember
virtual unsigned getMember() const
Definition BufferIndexBinding:50
osg::BufferIndexBinding::BufferIndexBinding
BufferIndexBinding(GLenum target, GLuint index)
osg::BufferIndexBinding::_index
GLuint _index
Definition BufferIndexBinding:104
osg::BufferIndexBinding::_offset
GLintptr _offset
Definition BufferIndexBinding:105
osg::BufferIndexBinding::setBufferData
void setBufferData(BufferData *bufferdata)
Definition BufferIndexBinding:56
osg::BufferIndexBinding::BufferIndexBinding
BufferIndexBinding(GLenum target, GLuint index, BufferData *bd, GLintptr offset=0, GLsizeiptr size=0)
osg::BufferIndexBinding::BufferIndexBinding
BufferIndexBinding(const BufferIndexBinding &rhs, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::BufferIndexBinding::setSize
void setSize(GLsizeiptr size)
Definition BufferIndexBinding:95
osg::BufferIndexBinding::~BufferIndexBinding
virtual ~BufferIndexBinding()
osg::BufferIndexBinding::_size
GLsizeiptr _size
Definition BufferIndexBinding:106
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::ShaderStorageBufferBinding::ShaderStorageBufferBinding
ShaderStorageBufferBinding(GLuint index=0)
osg::ShaderStorageBufferBinding::META_StateAttribute
META_StateAttribute(osg, ShaderStorageBufferBinding, SHADERSTORAGEBUFFERBINDING)
osg::ShaderStorageBufferBinding::ShaderStorageBufferBinding
ShaderStorageBufferBinding(const ShaderStorageBufferBinding &rhs, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::ShaderStorageBufferBinding::ShaderStorageBufferBinding
ShaderStorageBufferBinding(GLuint index, BufferData *bd, GLintptr offset=0, GLsizeiptr size=0)
osg::ShaderStorageBufferBinding::compare
virtual int compare(const StateAttribute &bb) const
Definition BufferIndexBinding:204
osg::StateAttribute
Definition StateAttribute:77
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::ATOMICCOUNTERBUFFERBINDING
@ ATOMICCOUNTERBUFFERBINDING
Definition StateAttribute:195
osg::StateAttribute::SHADERSTORAGEBUFFERBINDING
@ SHADERSTORAGEBUFFERBINDING
Definition StateAttribute:203
osg::StateAttribute::UNIFORMBUFFERBINDING
@ UNIFORMBUFFERBINDING
Definition StateAttribute:192
osg::StateAttribute::TRANSFORMFEEDBACKBUFFERBINDING
@ TRANSFORMFEEDBACKBUFFERBINDING
Definition StateAttribute:193
osg::State
Definition State:80
osg::TransformFeedbackBufferBinding::TransformFeedbackBufferBinding
TransformFeedbackBufferBinding(const TransformFeedbackBufferBinding &rhs, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::TransformFeedbackBufferBinding::compare
virtual int compare(const StateAttribute &bb) const
Definition BufferIndexBinding:148
osg::TransformFeedbackBufferBinding::META_StateAttribute
META_StateAttribute(osg, TransformFeedbackBufferBinding, TRANSFORMFEEDBACKBUFFERBINDING)
osg::TransformFeedbackBufferBinding::TransformFeedbackBufferBinding
TransformFeedbackBufferBinding(GLuint index, BufferData *bd, GLintptr offset=0, GLsizeiptr size=0)
osg::TransformFeedbackBufferBinding::TransformFeedbackBufferBinding
TransformFeedbackBufferBinding(GLuint index=0)
osg::UniformBufferBinding::compare
virtual int compare(const StateAttribute &bb) const
Definition BufferIndexBinding:126
osg::UniformBufferBinding::META_StateAttribute
META_StateAttribute(osg, UniformBufferBinding, UNIFORMBUFFERBINDING)
osg::UniformBufferBinding::UniformBufferBinding
UniformBufferBinding(const UniformBufferBinding &rhs, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::UniformBufferBinding::UniformBufferBinding
UniformBufferBinding()
osg::UniformBufferBinding::UniformBufferBinding
UniformBufferBinding(GLuint index)
osg::UniformBufferBinding::UniformBufferBinding
UniformBufferBinding(GLuint index, BufferData *bd, GLintptr offset=0, GLsizeiptr size=0)
osg::VertexBufferObject
Definition BufferObject:599
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::UIntArray
TemplateIndexArray< GLuint, Array::UIntArrayType, 1, GL_UNSIGNED_INT > UIntArray
Definition Array:419
osg::GLintptr
ptrdiff_t GLintptr
Definition GLDefines:692
osg::GLsizeiptr
ptrdiff_t GLsizeiptr
Definition GLDefines:691
Export
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39