2010-11-30 01:43:27 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
|
|
* Copyright (C) 2010 Tim Moore
|
2012-03-29 17:43:12 +08:00
|
|
|
* Copyright (C) 2012 David Callu
|
2017-08-24 05:42:12 +08:00
|
|
|
* Copyright (C) 2017 Julien Valentin
|
2010-11-30 01:43:27 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2010-11-30 01:43:27 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2010-11-30 01:43:27 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-11-30 01:43:27 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_BUFFERINDEXBINDING
|
|
|
|
#define OSG_BUFFERINDEXBINDING 1
|
2010-11-30 16:12:06 +08:00
|
|
|
|
2012-03-29 17:43:12 +08:00
|
|
|
#include <osg/Array>
|
2010-11-30 01:43:27 +08:00
|
|
|
#include <osg/Export>
|
|
|
|
#include <osg/BufferObject>
|
|
|
|
#include <osg/StateAttribute>
|
|
|
|
|
2010-11-30 16:12:06 +08:00
|
|
|
#ifndef GL_TRANSFORM_FEEDBACK_BUFFER
|
|
|
|
#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E
|
|
|
|
#endif
|
|
|
|
|
2012-03-29 17:43:12 +08:00
|
|
|
|
2010-11-30 01:43:27 +08:00
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
class State;
|
|
|
|
|
|
|
|
/** Encapsulate binding buffer objects to index targets. This
|
|
|
|
* specifically supports the uniform buffer and transform feedback
|
|
|
|
* targets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Common implementation superclass
|
|
|
|
class OSG_EXPORT BufferIndexBinding : public StateAttribute
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
BufferIndexBinding(GLenum target, GLuint index);
|
2017-08-24 05:42:12 +08:00
|
|
|
BufferIndexBinding(GLenum target, GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
2010-11-30 01:43:27 +08:00
|
|
|
BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
public:
|
|
|
|
// The member value is part of the key to this state attribute in
|
2015-04-13 18:43:56 +08:00
|
|
|
// the State class. Using the index target, we can separately
|
2010-11-30 01:43:27 +08:00
|
|
|
// track the bindings for many different index targets.
|
|
|
|
virtual unsigned getMember() const { return static_cast<unsigned int>(_index); }
|
|
|
|
GLenum getTarget() const { return _target; }
|
2017-08-24 05:42:12 +08:00
|
|
|
///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;}
|
|
|
|
|
|
|
|
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(); }
|
2016-06-25 19:24:19 +08:00
|
|
|
|
2010-11-30 01:43:27 +08:00
|
|
|
/** Get the index target.
|
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
inline GLuint getIndex() const { return _index; }
|
|
|
|
/** Set the index target. (and update parents StateSets)
|
2010-11-30 01:43:27 +08:00
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
void setIndex(GLuint index);
|
2016-06-25 19:24:19 +08:00
|
|
|
|
|
|
|
|
2017-08-24 05:42:12 +08:00
|
|
|
/** Set the starting offset into the buffer data for
|
2010-11-30 01:43:27 +08:00
|
|
|
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...).
|
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
inline void setOffset(GLintptr offset) { _offset = offset; }
|
|
|
|
inline GLintptr getOffset() const { return _offset; }
|
2016-06-25 19:24:19 +08:00
|
|
|
|
2017-08-24 05:42:12 +08:00
|
|
|
/** Set the size override of bufferdata binded for the indexed target.
|
2010-11-30 01:43:27 +08:00
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
inline void setSize(GLsizeiptr size) { _size = size; }
|
|
|
|
inline GLsizeiptr getSize() const { return _size; }
|
2016-06-25 19:24:19 +08:00
|
|
|
|
2010-11-30 01:43:27 +08:00
|
|
|
virtual void apply(State& state) const;
|
2016-06-16 02:05:35 +08:00
|
|
|
|
2010-11-30 01:43:27 +08:00
|
|
|
protected:
|
|
|
|
virtual ~BufferIndexBinding();
|
2017-08-24 05:42:12 +08:00
|
|
|
/*const*/ GLenum _target;
|
|
|
|
ref_ptr<BufferData> _bufferData;
|
2016-06-25 19:24:19 +08:00
|
|
|
GLuint _index;
|
2010-11-30 01:43:27 +08:00
|
|
|
GLintptr _offset;
|
|
|
|
GLsizeiptr _size;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** StateAttribute for binding a uniform buffer index target.
|
|
|
|
*/
|
|
|
|
class OSG_EXPORT UniformBufferBinding : public BufferIndexBinding
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UniformBufferBinding();
|
|
|
|
UniformBufferBinding(GLuint index);
|
|
|
|
/** Create a binding for a uniform buffer index target.
|
|
|
|
* @param index the index target
|
2017-08-24 05:42:12 +08:00
|
|
|
* @param bd associated buffer data
|
|
|
|
* @param offset offset into buffer data
|
|
|
|
* @param size size of data in buffer data
|
2010-11-30 01:43:27 +08:00
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
UniformBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
2010-11-30 01:43:27 +08:00
|
|
|
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)
|
2017-08-24 05:42:12 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_bufferData)
|
2010-11-30 01:43:27 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_offset)
|
|
|
|
COMPARE_StateAttribute_Parameter(_size)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** StateAttribute for binding a transform feedback index target.
|
|
|
|
*/
|
|
|
|
class OSG_EXPORT TransformFeedbackBufferBinding : public BufferIndexBinding
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TransformFeedbackBufferBinding(GLuint index = 0);
|
2017-08-24 05:42:12 +08:00
|
|
|
TransformFeedbackBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
2010-11-30 01:43:27 +08:00
|
|
|
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)
|
2017-08-24 05:42:12 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_bufferData)
|
2010-11-30 01:43:27 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_offset)
|
|
|
|
COMPARE_StateAttribute_Parameter(_size)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2012-03-29 17:43:12 +08:00
|
|
|
|
|
|
|
/** StateAttribute for binding a atomic counter buffer index target.
|
|
|
|
*/
|
|
|
|
class OSG_EXPORT AtomicCounterBufferBinding : public BufferIndexBinding
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AtomicCounterBufferBinding(GLuint index=0);
|
|
|
|
/** Create a binding for a atomic counter buffer index target.
|
|
|
|
* @param index the index target
|
2017-08-24 05:42:12 +08:00
|
|
|
* @param bd associated buffer data
|
|
|
|
* @param offset offset into buffer data
|
|
|
|
* @param size size of data in buffer data
|
2012-03-29 17:43:12 +08:00
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
AtomicCounterBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
2012-03-29 17:43:12 +08:00
|
|
|
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)
|
2017-08-24 05:42:12 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_bufferData)
|
2012-03-29 17:43:12 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_offset)
|
|
|
|
COMPARE_StateAttribute_Parameter(_size)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-10 20:23:04 +08:00
|
|
|
class OSG_EXPORT ShaderStorageBufferBinding : public BufferIndexBinding
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ShaderStorageBufferBinding(GLuint index=0);
|
|
|
|
/** Create a binding for a shader storage buffer index target.
|
|
|
|
* @param index the index target
|
2017-08-24 05:42:12 +08:00
|
|
|
* @param bd associated buffer data
|
|
|
|
* @param offset offset into buffer data
|
|
|
|
* @param size size of data in buffer data
|
2014-12-10 20:23:04 +08:00
|
|
|
*/
|
2017-08-24 05:42:12 +08:00
|
|
|
ShaderStorageBufferBinding(GLuint index, BufferData* bd, GLintptr offset=0, GLsizeiptr size=0);
|
2014-12-10 20:23:04 +08:00
|
|
|
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)
|
2017-08-24 05:42:12 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_bufferData)
|
2014-12-10 20:23:04 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_offset)
|
|
|
|
COMPARE_StateAttribute_Parameter(_size)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-29 17:43:12 +08:00
|
|
|
} // namespace osg
|
2010-11-30 01:43:27 +08:00
|
|
|
|
|
|
|
#endif
|