SenOGL  0.2
Library aiming to ease the use of OpenGL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Buffer Class Reference

OpenGL Buffer Object. More...

#include <Buffer.hpp>

Inheritance diagram for Buffer:
OpenGLObject IndexedBuffer UniformBuffer

Public Types

enum  Target : GLenum {
  Target::VertexAttributes = GL_ARRAY_BUFFER, Target::AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, Target::CopyRead = GL_COPY_READ_BUFFER, Target::CopyWrite = GL_COPY_WRITE_BUFFER,
  Target::IndirectDispatch = GL_DISPATCH_INDIRECT_BUFFER, Target::IndirectDraw = GL_DRAW_INDIRECT_BUFFER, Target::VertexIndices = GL_ELEMENT_ARRAY_BUFFER, Target::PixelPack = GL_PIXEL_PACK_BUFFER,
  Target::PixelUnpack = GL_PIXEL_UNPACK_BUFFER, Target::Query = GL_QUERY_BUFFER, Target::ShaderStorage = GL_SHADER_STORAGE_BUFFER, Target::Texture = GL_TEXTURE_BUFFER,
  Target::TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER, Target::Uniform = GL_UNIFORM_BUFFER
}
 Bind targets. More...
 
enum  Usage : GLenum {
  Usage::StaticDraw = GL_STATIC_DRAW, Usage::StaticRead = GL_STATIC_READ, Usage::StaticCopy = GL_STATIC_COPY, Usage::DynamicDraw = GL_DYNAMIC_DRAW,
  Usage::DynamicRead = GL_DYNAMIC_READ, Usage::DynamicCopy = GL_DYNAMIC_COPY, Usage::StreamDraw = GL_STREAM_DRAW, Usage::StreamRead = GL_STREAM_READ,
  Usage::StreamCopy = GL_STREAM_COPY
}
 Usage hint for mutable buffers. More...
 
enum  StorageUsage : GLbitfield {
  StorageUsage::Unspecified = 0, StorageUsage::DynamicStorageBit = GL_DYNAMIC_STORAGE_BIT, StorageUsage::MapReadBit = GL_MAP_READ_BIT, StorageUsage::MapWriteBit = GL_MAP_WRITE_BIT,
  StorageUsage::MapPersistentBit = GL_MAP_PERSISTENT_BIT, StorageUsage::MapCoherentBit = GL_MAP_COHERENT_BIT, StorageUsage::ClientStorageBit = GL_CLIENT_STORAGE_BIT
}
 Usage hint for immutable buffers. More...
 

Public Member Functions

 Buffer ()=default
 Default Constructor Avoid using this is favor of the 'typed' constructor when possible. More...
 
 Buffer (Target type, GLuint handle=0)
 Constructor specifying a buffer type. More...
 
 Buffer (const Buffer &)=default
 Copy constructor. More...
 
 Buffer (Buffer &&)=default
 Move constructor. More...
 
Bufferoperator= (const Buffer &)=default
 Assigment operator. More...
 
Bufferoperator= (Buffer &&)=default
 Move assignment operator. More...
 
virtual ~Buffer ()
 Destructor. More...
 
virtual void init () override
 Generates a new buffer name to manage. More...
 
void init (Target t)
 Generates a new buffer of type t. More...
 
virtual void cleanup () override
 Destroy managed buffer. More...
 
void bind () const
 Binds the buffer to its assigned target (type) More...
 
void bind (Target t) const
 Binds the buffer to arbitrary target (type) More...
 
void bind (GLuint bindingPoint, GLintptr offset=0, GLsizeiptr size=0) const
 Bind this buffer to the specified binding point in the OpenGL context. More...
 
void bind (Target target, GLuint bindingPoint, GLintptr offset=0, GLsizeiptr size=0) const
 Similar to bind(GLuint, GLintptr, GLsizeiptr) but allowing for another target than the type of the buffer. More...
 
void unbind () const
 Unbinds the buffer. More...
 
void data (const void *data, size_t size, Buffer::Usage usage) const
 glBufferData More...
 
void store (const void *data, size_t size, Buffer::StorageUsage flags) const
 glBufferStorage More...
 
void subData (size_t offset, size_t size, const void *data) const
 glBufferSubData​ More...
 
Target getType () const
 
void setType (Target t)
 If the type wasn't specified at creation, this should be called before any init() More...
 
- Public Member Functions inherited from OpenGLObject
 OpenGLObject ()
 
 OpenGLObject (GLuint handle)
 Constructs a instance managing an existing OpenGL Object. More...
 
 OpenGLObject (const OpenGLObject &)=default
 
 OpenGLObject (OpenGLObject &&)=default
 
OpenGLObjectoperator= (const OpenGLObject &)=default
 
OpenGLObjectoperator= (OpenGLObject &&)=default
 
virtual ~OpenGLObject ()
 
GLuint getName () const
 Returns OpenGL name of the object. More...
 
void setName (GLuint n)
 Sets the OpenGL name of the object managed by this instance /!\ Use with caution ! (assignment operator is probably what you're looking for) More...
 
virtual bool isValid () const
 Returns true if the object seems valid. More...
 
 operator bool () const
 Syntactic sugar for isValid(). More...
 

Static Public Member Functions

static void copySubData (Target srcType, Target dstType, GLuint srcOffset, GLuint dstOffset, GLuint size)
 glCopyBufferSubData More...
 
static void copySubData (const Buffer &src, const Buffer &dst, GLuint srcOffset, GLuint dstOffset, GLuint size)
 glCopyNamedBufferSubData More...
 

Protected Attributes

Target _type = Target::VertexAttributes
 Target of the Buffer. More...
 
- Protected Attributes inherited from OpenGLObject
GLuint _handle
 OpenGL name of the managed object. More...
 

Detailed Description

OpenGL Buffer Object.

Member Enumeration Documentation

enum Buffer::StorageUsage : GLbitfield
strong

Usage hint for immutable buffers.

Enumerator
Unspecified 
DynamicStorageBit 

The contents of the data store may be updated after creation through calls to glBufferSubData. If this bit is not set, the buffer content may not be directly updated by the client. The data argument may be used to specify the initial content of the buffer's data store regardless of the presence of the GL_DYNAMIC_STORAGE_BIT​. Regardless of the presence of this bit, buffers may always be updated with server-side calls such as glCopyBufferSubData​ and glClearBufferSubData​.

MapReadBit 

The data store may be mapped by the client for read access and a pointer in the client's address space obtained that may be read from.

MapWriteBit 

The data store may be mapped by the client for write access and a pointer in the client's address space obtained that may be written through.

MapPersistentBit 

The client may request that the server read from or write to the buffer while it is mapped. The client's pointer to the data store remains valid so long as the data store is mapped, even during execution of drawing or dispatch commands.

MapCoherentBit 

Shared access to buffers that are simultaneously mapped for client access and are used by the server will be coherent, so long as that mapping is performed using glMapBufferRange​. That is, data written to the store by either the client or server will be immediately visible to the other with no further action taken by the application. In particular,.

ClientStorageBit 

A hint that the buffer object's data should be stored in client memory. Assuming that such a distinction exists in the driver.

enum Buffer::Target : GLenum
strong

Bind targets.

Enumerator
VertexAttributes 

Vertex attributes (VBO)

AtomicCounter 

Atomic counter storage.

CopyRead 

Buffer copy source.

CopyWrite 

Buffer copy destination.

IndirectDispatch 

Indirect compute dispatch commands.

IndirectDraw 

Indirect command arguments.

VertexIndices 

Vertex array indices (IBO)

PixelPack 

Pixel read target.

PixelUnpack 

Texture data source.

Query 

Query result buffer.

ShaderStorage 

Read-write storage for shaders.

Texture 

Texture data buffer.

TransformFeedback 

Transform feedback buffer.

Uniform 

Uniform block storage (UBO)

enum Buffer::Usage : GLenum
strong

Usage hint for mutable buffers.

STATIC: The user will set the data once. DYNAMIC: The user will set the data occasionally. STREAM: The user will be changing the data after every use. Or almost every use.

DRAW: The user will be writing data to the buffer, but the user will not read it. READ: The user will not be writing data, but the user will be reading it back. COPY: The user will be neither writing nor reading the data.

Enumerator
StaticDraw 

GL_STATIC_DRAW.

StaticRead 

GL_STATIC_READ.

StaticCopy 

GL_STATIC_COPY.

DynamicDraw 

GL_DYNAMIC_DRAW.

DynamicRead 

GL_DYNAMIC_READ.

DynamicCopy 

GL_DYNAMIC_COPY.

StreamDraw 

GL_STREAM_DRAW.

StreamRead 

GL_STREAM_READ.

StreamCopy 

GL_STREAM_COPY.

Constructor & Destructor Documentation

Buffer::Buffer ( )
default

Default Constructor Avoid using this is favor of the 'typed' constructor when possible.

See also
Buffer(Target type, GLuint handle = 0)
Buffer::Buffer ( Target  type,
GLuint  handle = 0 
)

Constructor specifying a buffer type.

Parameters
typeTarget
handleRaw OpenGL name (Used to manage a existing object, call init() to generate a new one).
See also
Buffer::Target
init()
Buffer::Buffer ( const Buffer )
default

Copy constructor.

Buffer::Buffer ( Buffer &&  )
default

Move constructor.

Buffer::~Buffer ( )
virtual

Destructor.

Member Function Documentation

void Buffer::bind ( ) const

Binds the buffer to its assigned target (type)

See also
unbind()
void Buffer::bind ( Target  t) const

Binds the buffer to arbitrary target (type)

See also
unbind()
void Buffer::bind ( GLuint  bindingPoint,
GLintptr  offset = 0,
GLsizeiptr  size = 0 
) const

Bind this buffer to the specified binding point in the OpenGL context.

Buffer type must be AtomicCounter, TransformFeedback, Uniform or ShaderStorage.

Parameters
bindingPointBinding Point
offsetStarting offset in basic machine unit (optional, default: 0)
sizeAmount of data in machine unit to bind (optional, default: 0, means the entire buffer)
See also
glBindBufferBase, glBindBufferRange
void Buffer::bind ( Target  target,
GLuint  bindingPoint,
GLintptr  offset = 0,
GLsizeiptr  size = 0 
) const

Similar to bind(GLuint, GLintptr, GLsizeiptr) but allowing for another target than the type of the buffer.

Parameters
targetTarget of bind operation. Must be AtomicCounter, TransformFeedback, Uniform or ShaderStorage.
bindingPointBinding Point
offsetStarting offset in basic machine unit (optional, default: 0)
sizeAmount of data in machine unit to bind (optional, default: 0, means the entire buffer)
See also
bind(GLuint, GLintptr, GLsizeiptr)
void Buffer::cleanup ( )
overridevirtual

Destroy managed buffer.

Implements OpenGLObject.

void Buffer::copySubData ( Target  srcType,
Target  dstType,
GLuint  srcOffset,
GLuint  dstOffset,
GLuint  size 
)
inlinestatic

glCopyBufferSubData

Parameters
srcTypeSource buffer type
dstTypeDestination buffer type
srcOffsetSource offset (in basic machine unit)
dstOffsetSource offset (in basic machine unit)
sizeData size to copy (in basic machine unit)
void Buffer::copySubData ( const Buffer src,
const Buffer dst,
GLuint  srcOffset,
GLuint  dstOffset,
GLuint  size 
)
inlinestatic

glCopyNamedBufferSubData

Parameters
srcSource buffer
dstDestination buffer
srcOffsetSource offset (in basic machine unit)
dstOffsetSource offset (in basic machine unit)
sizeData size to copy (in basic machine unit)
void Buffer::data ( const void *  data,
size_t  size,
Buffer::Usage  usage 
) const

glBufferData

Target Buffer::getType ( ) const
inline
Returns
Target of the buffer
void Buffer::init ( )
overridevirtual

Generates a new buffer name to manage.

Implements OpenGLObject.

void Buffer::init ( Target  t)

Generates a new buffer of type t.

Parameters
tTarget of the new buffer
Buffer& Buffer::operator= ( const Buffer )
default

Assigment operator.

Buffer& Buffer::operator= ( Buffer &&  )
default

Move assignment operator.

void Buffer::setType ( Target  t)
inline

If the type wasn't specified at creation, this should be called before any init()

Parameters
tNew type of the buffer
See also
init()
void Buffer::store ( const void *  data,
size_t  size,
Buffer::StorageUsage  flags 
) const

glBufferStorage

void Buffer::subData ( size_t  offset,
size_t  size,
const void *  data 
) const

glBufferSubData​

void Buffer::unbind ( ) const

Unbinds the buffer.

See also
bind()

Member Data Documentation

Target Buffer::_type = Target::VertexAttributes
protected

Target of the Buffer.


The documentation for this class was generated from the following files: