PrevUpHomeNext

Buffers

#include <oglplus/buffer.hpp>

Common buffer operations

template <>
class ObjCommonOps<tag::Buffer>
 : public BufferName
{
public:
	typedef BufferTarget Target; 1
	typedef BufferIndexedTarget IndexedTarget;

	static BufferName Binding(BufferTarget target); 2
	static void Bind(BufferTarget target, BufferName buffer); 3

	static BufferName Binding(BufferIndexedTarget target, GLuint index); 4
	static void BindBase(
		BufferIndexedTarget target,
		GLuint index,
		BufferName buffer
	); 5
	static void BindRange(
		BufferIndexedTarget target,
		GLuint index,
		BufferName buffer,
		BufferSize offset,
		BufferSize size
	); 6

#if GL_VERSION_4_4 || GL_ARB_multi_bind
	static void BindBase(
		BufferIndexedTarget target,
		GLuint first,
		const Sequence<BufferName>& buffers
	); 7

	static void BindRange(
		BufferIndexedTarget target,
		GLuint first,
		const Sequence<BufferName>& buffers,
		const GLintptr* offsets,
		const GLsizeiptr* sizes
	); 8
#endif

1

Buffer bind targets.

2

Returns the buffer currently bound to the specified target.

3

Binds the specified buffer to the specified target.

4

Returns the current buffer bound to the specified indexed target.

5

Binds the specified buffer to the specified indexed target.

6

Bind a range starting at offset with length specified by size in a buffer to the specified indexed target.

7

Sequentially binds all buffers to indexed targets starting at first index.

8

Sequentially binds ranges (specified by offsets and sizes which must point to arrays of at least as much values as the buffers sequence) of all buffers to indexed targets starting at first index.

	void Bind(BufferTarget target) const; 1
	void Bind(BufferIndexedTarget target, GLuint index) const; 2
	void BindBase(BufferIndexedTarget target, GLuint index) const;

#if GL_VERSION_4_0 || GL_ARB_transform_feedback3
	void BindBaseUniform(UniformBufferBindingPoint index) const; 3
#endif

#if GL_VERSION_4_0 || GL_ARB_transform_feedback3
	void BindBaseTransformFeedback(TransformFeedbackBufferBindingPoint index) const 4
#endif

#if GL_VERSION_4_2 || GL_ARB_shader_atomic_counters
	void BindBaseAtomicCounter(AtomicCounterBufferBindingPoint index) const; 5
#endif

#if GL_VERSION_4_3 || GL_ARB_shader_storage_buffer_object
	void BindBaseShaderStorage(ShaderStorageBufferBindingPoint index) const; 6
#endif

	void BindRange(
		BufferIndexedTarget target,
		GLuint index,
		BufferSize offset,
		BufferSize size
	) const; 7

1

Binds this buffer to the specified target.

2

Binds this buffer to the specified indexed target.

3

Binds this buffer to the uniform buffer binding point with the specified index.

4

Binds this buffer to the transform feedback binding point with the specified index.

5

Binds this buffer to the atomic counter binding point with the specified index.

6

Binds this buffer to the shader storage binding point with the specified index.

7

Binds a range (specified by offset and size) of this buffer to the specified indexed target.

#if GL_VERSION_4_3 || GL_ARB_invalidate_subdata
	void InvalidateData(void); 1
	void InvalidateSubData(BufferSize offset, BufferSize size); 2
#endif
};

1

Invalidate all of this buffer's data. See glInvalidateBufferData.

2

Invalidate a subrange (specified by offset and size) of this buffer's data. See glInvalidateBufferSubData.

Operations with explicit selector

template <>
class ObjectOps<tag::ExplicitSel, tag::Buffer>
 : public ObjZeroOps<tag::ExplicitSel, tag::Buffer> 1
{
public:
	struct Property
	{
		typedef BufferUsage Usage;
		typedef BufferMapAccess MapAccess;
	};

	typedef BufferTypedMap<GLubyte> Map; 2

	static Boolean Mapped(BufferTarget target); 3

	static void Resize(
		BufferTarget target,
		BufferSize size,
		BufferUsage usage = BufferUsage::StaticDraw
	); 4

	static void RawData(
		BufferTarget target,
		BufferSize size,
		const GLvoid* data,
		BufferUsage usage = BufferUsage::StaticDraw
	); 5

	static void Data(
		BufferTarget target,
		const BufferData& data,
		BufferUsage usage = BufferUsage::StaticDraw
	); 6

	template <typename GLtype>
	static void Data(
		BufferTarget target,
		SizeType count,
		const GLtype* data,
		BufferUsage usage = BufferUsage::StaticDraw
	);

	static void SubData(
		BufferTarget target,
		BufferSize offset,
		const BufferData& data
	); 7

	template <typename GLtype>
	static void SubData(
		BufferTarget target,
		BufferSize offset,
		SizeType count,
		const GLtype* data
	);

#if GL_VERSION_3_1 || GL_ARB_copy_buffer
	static void CopySubData(
		BufferTarget readtarget,
		BufferTarget writetarget,
		BufferSize readoffset,
		BufferSize writeoffset,
		BufferSize size
	); 8
#endif

#if GL_VERSION_4_3
	template <typename GLtype>
	static void ClearData(
		BufferTarget target,
		PixelDataInternalFormat internal_format,
		PixelDataFormat format,
		const GLtype* value
	); 9

	template <typename GLtype>
	static void ClearSubData(
		BufferTarget target,
		PixelDataInternalFormat internal_format,
		BufferSize offset,
		BufferSize size,
		PixelDataFormat format,
		const GLtype* value
	); 10
#endif

#if GL_VERSION_4_4 || GL_ARB_buffer_storage
	static void Storage(
		BufferTarget target,
		const BufferData& data,
		Bitfield<BufferStorageBit> flags
	); 11
	static void Storage(
		BufferTarget target,
		BufferSize size,
		const void* data,
		Bitfield<BufferStorageBit> flags
	);

	static Boolean ImmutableStorage(BufferTarget target); 12

	static Bitfield<BufferStorageBit> StorageFlags(BufferTarget target); 13
#endif

1

Indirectly inherits from ObjCommonOps<tag::Buffer>.

2

Mapping of the buffer to the client address space.

3

Returns true if the buffer currently bound to the specified target is mapped. See glGetBufferParameter, GL_BUFFER_MAPPED.

4

Allocates or reallocates storage of a buffer currently bound to target to the specified size without uploading any data, taking usage as a hint. See glBufferData.

5

Uploads size bytes from the location pointed to by data to the buffer bound to the specified target, taking usage as a hint. See glBufferData.

6

Uploads the specified data to the buffer bound to the specified target taking usage as a hint. See glBufferData.

7

Uploads the specified data to a sub-range (starting at offset) of the buffer bound to the specified target. See glBufferSubData.

8

Copies a block of data of the specified size from a buffer bound to readtarget starting at readoffset to a buffer bound to writetarget starting at writeoffset. See glCopyBufferSubData.

9

Clears the whole buffer bound to target with the specified fixed value, in the specified format. See glClearBufferSubData.

10

Clears a sub-range (specified by offset and size) of a buffer bound to target with the specified fixed value, using the specified internal_format.

11

Creates a data store for buffer currently bound to target, and uploads the specified data. See glBufferStorage.

12

Returns true if the storage of the buffer currently bound to target is immutable. See glGetBufferParameter, GL_BUFFER_IMMUTABLE_STORAGE.

13

Returns the storage flags of a buffer currently bound to target. See glGetBufferParameter, GL_BUFFER_STORAGE_FLAGS.

	static SizeType Size(BufferTarget target); 1
	static BufferUsage Usage(BufferTarget target); 2
	static Bitfield<BufferMapAccess> Access(BufferTarget target); 3

#if GL_ARB_sparse_buffer
	static void PageCommitment(
		BufferTarget target,
		BufferSize offset,
		BufferSize size,
		Boolean commit
	); 4

	static SizeType PageSize(void); 5
#endif

#if GL_NV_shader_buffer_load
	static void MakeResident(BufferTarget target, AccessSpecifier access); 6
	static void MakeNonResident(BufferTarget target); 7
	static BufferGPUAddress GPUAddress(BufferTarget target); 8
#endif
};

1

Returns the size of a buffer currently bound to the specified target. See glGet, GL_BUFFER_SIZE.

2

Returns the usage hint of a buffer currently bound to the specified target. See glGet, GL_BUFFER_USAGE.

3

Returns the access bits of a buffer currently bound to the specified target. See glGet, GL_BUFFER_ACCESS.

4

Commits and de-commits regions (specified by offset and size) of sparse buffer currently bound to the specified target. See glBufferPageCommitmentARB.

5

Returns the implementation-dependent sparse buffer storage page size. See glGet, GL_SPARSE_BUFFER_PAGE_SIZE_ARB.

6

Makes buffer currently bound to target accessible to GLSL shaders. See glMakeBufferResidentNV

7

Makes buffer currently bound to target inaccessible to GLSL shaders. See glMakeBufferNonResidentNV

8

Returns the GPU address of the buffer currently bound to target. See glGetBufferParameter, GL_BUFFER_GPU_ADDRESS_NV.

Definition

typedef ObjectOps<tag::ExplicitSel, tag::Buffer>
	BufferOps;

typedef Object<BufferOps> Buffer;

typedef ObjectZero<ObjZeroOps<tag::ExplicitSel, tag::Buffer>>
	NoBuffer;

Syntax sugar operators

struct BufferTargetAndUsage { }; 1

BufferTargetAndUsage operator << (
	BufferTarget target,
	BufferUsage usage
); 2


struct BufferOpsAndIdxTgt { }; 3

BufferOpsAndIdxTgt operator << (
	const BufferOps& buffer,
	BufferIndexedTarget target
); 4


struct BufferTargetAndOffset { }; 5

BufferTargetAndOffset operator + (
	BufferTarget target,
	BufferSize offset
); 6

// Bind
BufferTarget operator << (
	const BufferOps& buf,
	BufferTarget target
); 7

const BufferOps& operator << (
	const BufferOpsAndIdxTgt& bat,
	GLuint index
); 8

BufferTarget operator << (
	BufferTarget target,
	const BufferData& data
); 9

BufferTarget operator << (
	BufferTargetAndUsage&& tau,
	const BufferData& data
); 10

BufferTarget operator << (
	BufferTargetAndOffset&& tao,
	const BufferData& data
); 11

1

Helper class for syntax sugar operators. Binds together the buffer target and usage hint.

2

Ties together a buffer target and usage hint.

3

Helper class for syntax sugar operators. Binds together a reference to a buffer and an indexed target.

4

Ties together a reference to a buffer and an indexed target.

5

Helper class for syntax sugar operators. Binds together a buffer target and offset value.

6

Ties together a buffer target and offset value.

7

Equivalent to buf.Bind(target).

8

Equivalent to BufferOps::BindBase(target, index).

9

Equivalent to BufferOps::Data(target, data).

10

Equivalent to BufferOps::Data(target, data, usage).

11

Equivalent to BufferOps::SubData(target, offset, data).

Target

#include <oglplus/buffer_target.hpp>

enum class BufferTarget : GLenum
{
	Array                 = GL_ARRAY_BUFFER,
	AtomicCounter         = GL_ATOMIC_COUNTER_BUFFER,
	CopyRead              = GL_COPY_READ_BUFFER,
	CopyWrite             = GL_COPY_WRITE_BUFFER,
	DispatchIndirect      = GL_DISPATCH_INDIRECT_BUFFER,
	DrawIndirect          = GL_DRAW_INDIRECT_BUFFER,
	ElementArray          = GL_ELEMENT_ARRAY_BUFFER,
	PixelPack             = GL_PIXEL_PACK_BUFFER,
	PixelUnpack           = GL_PIXEL_UNPACK_BUFFER,
	ShaderStorage         = GL_SHADER_STORAGE_BUFFER,
	Texture               = GL_TEXTURE_BUFFER,
	TransformFeedback     = GL_TRANSFORM_FEEDBACK_BUFFER,
	Uniform               = GL_UNIFORM_BUFFER,
	Query                 = GL_QUERY_BUFFER,
	Parameter             = GL_PARAMETER_BUFFER_ARB,
	ExternalVirtualMemory = GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
};

template <>
Range<BufferTarget> EnumValueRange<BufferTarget>(void);

StrCRef EnumValueName(BufferTarget);

Target to class

#if !OGLPLUS_NO_ENUM_VALUE_CLASSES
namespace enums {

template <typename Base, template<BufferTarget> class Transform>
class EnumToClass<Base, BufferTarget, Transform> 1
 : public Base
{
public:
	EnumToClass(void);
	EnumToClass(Base&& base);

	Transform<BufferTarget::Array>
		Array;
	Transform<BufferTarget::AtomicCounter>
		AtomicCounter;
	Transform<BufferTarget::CopyRead>
		CopyRead;
	Transform<BufferTarget::CopyWrite>
		CopyWrite;
	Transform<BufferTarget::DispatchIndirect>
		DispatchIndirect;
	Transform<BufferTarget::DrawIndirect>
		DrawIndirect;
	Transform<BufferTarget::ElementArray>
		ElementArray;
	Transform<BufferTarget::PixelPack>
		PixelPack;
	Transform<BufferTarget::PixelUnpack>
		PixelUnpack;
	Transform<BufferTarget::ShaderStorage>
		ShaderStorage;
	Transform<BufferTarget::Texture>
		Texture;
	Transform<BufferTarget::TransformFeedback>
		TransformFeedback;
	Transform<BufferTarget::Uniform>
		Uniform;
	Transform<BufferTarget::Query>
		Query;
	Transform<BufferTarget::Parameter>
		Parameter;
	Transform<BufferTarget::ExternalVirtualMemory>
		ExternalVirtualMemory;
};

} // namespace enums
#endif

1

Specialization of EnumToClass for the BufferTarget enumeration.

IndexedTarget

#include <oglplus/buffer_target.hpp>

enum class BufferIndexedTarget : GLenum
{
	AtomicCounter     = GL_ATOMIC_COUNTER_BUFFER,
	ShaderStorage     = GL_SHADER_STORAGE_BUFFER,
	TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER,
	Uniform           = GL_UNIFORM_BUFFER
};

template <>
Range<BufferIndexedTarget> EnumValueRange<BufferIndexedTarget>(void);

StrCRef EnumValueName(BufferIndexedTarget);

Indexed target to class

#if !OGLPLUS_NO_ENUM_VALUE_CLASSES
namespace enums {

template <typename Base, template<BufferIndexedTarget> class Transform>
class EnumToClass<Base, BufferIndexedTarget, Transform> 1
 : public Base
{
public:
	EnumToClass(void);
	EnumToClass(Base&& base);

	Transform<BufferIndexedTarget::AtomicCounter>
		AtomicCounter;
	Transform<BufferIndexedTarget::ShaderStorage>
		ShaderStorage;
	Transform<BufferIndexedTarget::TransformFeedback>
		TransformFeedback;
	Transform<BufferIndexedTarget::Uniform>
		Uniform;
};

} // namespace enums
#endif

1

Specialization of EnumToClass for the BufferIndexedTarget enumeration.

Indexed binding point numbers

#include <oglplus/buffer_binding.hpp>

#if GL_VERSION_4_0 || GL_ARB_transform_feedback3
class UniformBufferBindingPoint
 : public LimitedCount<GL_MAX_UNIFORM_BUFFER_BINDINGS>
{
public:
	UniformBufferBindingPoint(GLuint number); 1
};
#endif

#if GL_VERSION_4_0 || GL_ARB_transform_feedback3
class TransformFeedbackBufferBindingPoint
 : public LimitedCount<GL_MAX_TRANSFORM_FEEDBACK_BUFFERS>
{
public:
	TransformFeedbackBufferBindingPoint(GLuint number); 2
};
#endif

#if GL_VERSION_4_2 || GL_ARB_shader_atomic_counters
class AtomicCounterBufferBindingPoint
 : public LimitedCount<GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS>
{
public:
	AtomicCounterBufferBindingPoint(GLuint number); 3
};
#endif

#if GL_VERSION_4_3 || GL_ARB_shader_storage_buffer_object
class ShaderStorageBufferBindingPoint
 : public LimitedCount<GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS>
{
public:
	ShaderStorageBufferBindingPoint(GLuint number); 4
};
#endif

1

Throws LimitError if number is greater than the implementation-dependent maximum number of indexed uniform buffer binding points. See GL_MAX_UNIFORM_BUFFER_BINDINGS.

2

Throws LimitError if number is greater than the implementation-dependent maximum number of indexed transform feedback buffer binding points. See GL_MAX_TRANSFORM_FEEDBACK_BUFFERS.

3

Throws LimitError if number is greater than the implementation-dependent maximum number of indexed atomic counter buffer binding points. See GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS.

4

Throws LimitError if number is greater than the implementation-dependent maximum number of indexed shader storage buffer binding points. See GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS.

Usage

#include <oglplus/buffer_usage.hpp>

enum class BufferUsage : GLenum
{
	StreamDraw  = GL_STREAM_DRAW,
	StreamRead  = GL_STREAM_READ,
	StreamCopy  = GL_STREAM_COPY,
	StaticDraw  = GL_STATIC_DRAW,
	StaticRead  = GL_STATIC_READ,
	StaticCopy  = GL_STATIC_COPY,
	DynamicDraw = GL_DYNAMIC_DRAW,
	DynamicRead = GL_DYNAMIC_READ,
	DynamicCopy = GL_DYNAMIC_COPY
};

template <>
Range<BufferUsage> EnumValueRange<BufferUsage>(void);

StrCRef EnumValueName(BufferUsage);

Storage bits

#include <oglplus/buffer_storage_bit.hpp>

enum class BufferStorageBit : GLbitfield
{
	MapRead        = GL_MAP_READ_BIT,
	MapWrite       = GL_MAP_WRITE_BIT,
	MapPersistent  = GL_MAP_PERSISTENT_BIT,
	MapCoherent    = GL_MAP_COHERENT_BIT,
	DynamicStorage = GL_DYNAMIC_STORAGE_BIT,
	ClientStorage  = GL_CLIENT_STORAGE_BIT,
	SparseStorage  = GL_SPARSE_STORAGE_BIT_ARB
};

template <>
Range<BufferStorageBit> EnumValueRange<BufferStorageBit>(void);

StrCRef EnumValueName(BufferStorageBit);

Bitfield<BufferStorageBit> operator | (BufferStorageBit b1, BufferStorageBit b2);

Size

The BufferSize class is used to store GPU buffer sizes in units of machine byte. Instances of this class are mostly used as parameters to buffer-related functions specifying buffer data offset and size.

#include <oglplus/buffer_size.hpp>

class BufferSize
{
public:
	BufferSize(void); 1
	BufferSize(BigSizeType size); 2

	template <typename T>
	BufferSize(unsigned count, const T*); 3

	template <typename T, std::size_t N>
	BufferSize(const T (&)[N]); 4

	template <typename T, std::size_t N>
	BufferSize(const std::array<T, N>& array); 5

	template <typename T>
	BufferSize(const std::vector<T>& vector); 6

	operator BigSizeType (void) const 7
	noexcept;

	template <typename T>
	static BufferSize Of(unsigned count, const T* data = nullptr); 8

	template <typename T>
	BufferSize Add(unsigned count, const T* = nullptr) const; 9

	BufferSize Add(const BufferSize& buffer_size); const 10

	GLsizeiptr Get(void) const; 11
};

1

Constructs a zero size.

2

Constructs a BufferSize object from a value in bytes.

3

Constructs a BufferSize required to store count instances of T.

4

Constructs a BufferSize required to store N instances of T.

5

Constructs a BufferSize required to store elements in array.

6

Constructs a BufferSize required to store elements in vector.

7

Implicit conversion to the underlying BigSizeType.

8

Makes a new instance of BufferSize required to store count instances of T.

9

Returns a new BufferSize that is the sum of this and the size of count instances of T.

10

Returns a new BufferSize that is the sum of this and the specified buffer_size.

11

Returns the stored size in bytes.

The BufferTypedSize template class is a helper ancestor of BufferSize that is used to construct instances of BufferSize with fixed data type.

template <typename T>
class BufferTypedSize
 : public BufferSize
{
public:
	BufferTypedSize(void);
	BufferTypedSize(GLsizeiptr count); 1
};

1

Constructs a BufferSize required to store count instances of T.

Data

The BufferData class is used to store a pointer to and the size of a block of memory containing data to be uploaded to a GPU buffer. Instances of this class are mostly used as parameters to buffer-related functions specifying buffer data to be uploaded to the GPU's memory.

[Note] Note

This class does not do an internal deep copy of the data passed to the constructors. The original memory block must not be free'd while any instances of BufferData referencing it are in use.

#include <oglplus/buffer_data.hpp>

class BufferData
{
public:
	BufferData(BufferSize size, const GLvoid* data); 1

	/// Construction from @p count of instances of type @c T at @p data
	template <typename T>
	BufferData(SizeType count, const T* data); 2

	template <typename T, std::size_t N>
	BufferData(const T (&data)[N]); 3

	template <typename T, std::size_t N>
	BufferData(const std::array<T, N>& array); 4

	template <typename T>
	BufferData(const std::vector<T>& vector); 5
};

1

Constructs BufferData from a raw pointer to a data block and its size.

2

Constructs BufferData from a pointer to count instances of type T.

3

Constructs BufferData from an array of N elements of type T.

4

Constructs BufferData from an array.

5

Constructs BufferData from a vector.

GPU address

The BufferGPUAddress class encapsulates buffers GPU address value.

#include <oglplus/buffer_gpu_addr.hpp>

#if GL_NV_shader_buffer_load

class BufferGPUAddress
{
public:
	BufferGPUAddress(GLuint64EXT addr);
};

GLuint64EXT GetGLAddress(BufferGPUAddress bga); 1

#endif

1

Returns the underlying buffer address value.


PrevUpHomeNext