Loading...
Searching...
No Matches
Buffer.h
Go to the documentation of this file.
#pragma once
#include <vector>
#include <array>
#include <glbinding/gl/types.h>
#include <globjects/globjects_api.h>
#include <globjects/Object.h>
namespace globjects
{
class GLOBJECTS_API Buffer : public Object
{
public:
enum class BindlessImplementation
{
DirectStateAccessARB
, DirectStateAccessEXT
, Legacy
};
static void hintBindlessImplementation(BindlessImplementation impl);
static void setWorkingTarget(gl::GLenum target);
public:
Buffer();
static Buffer * fromId(gl::GLuint id);
virtual void accept(ObjectVisitor & visitor) override;
void bind(gl::GLenum target) const;
static void unbind(gl::GLenum target);
static void unbind(gl::GLenum target, gl::GLuint index);
void setData(gl::GLsizeiptr size, const gl::GLvoid * data, gl::GLenum usage);
template <typename T>
void setData(const T & data, gl::GLenum usage);
template <typename T>
void setData(const std::vector<T> & data, gl::GLenum usage);
template <typename T, std::size_t Count>
void setData(const std::array<T, Count> & data, gl::GLenum usage);
void setSubData(gl::GLintptr offset, gl::GLsizeiptr size, const gl::GLvoid* data = nullptr);
template <typename T>
void setSubData(const T & data, gl::GLintptr offset = 0);
template <typename T>
void setSubData(const std::vector<T> & data, gl::GLintptr offset = 0);
template <typename T, std::size_t Count>
void setSubData(const std::array<T, Count> & data, gl::GLintptr offset = 0);
void setStorage(gl::GLsizeiptr size, const gl::GLvoid * data, gl::BufferStorageMask flags);
template <typename T>
void setStorage(const T & data, gl::BufferStorageMask flags);
template <typename T>
void setStorage(const std::vector<T> & data, gl::BufferStorageMask flags);
template <typename T, std::size_t Count>
void setStorage(const std::array<T, Count> & data, gl::BufferStorageMask flags);
gl::GLint getParameter(gl::GLenum pname) const;
gl::GLint64 getParameter64(gl::GLenum pname) const;
const void * map() const;
void * map(gl::GLenum access);
void * mapRange(gl::GLintptr offset, gl::GLsizeiptr length, gl::BufferAccessMask access);
bool unmap() const;
void flushMappedRange(gl::GLintptr offset, gl::GLsizeiptr length);
void bindBase(gl::GLenum target, gl::GLuint index) const;
void bindRange(gl::GLenum target, gl::GLuint index, gl::GLintptr offset, gl::GLsizeiptr size) const;
void copySubData(Buffer * buffer, gl::GLintptr readOffset, gl::GLintptr writeOffset, gl::GLsizeiptr size) const;
void copySubData(Buffer * buffer, gl::GLsizeiptr size) const;
void copyData(Buffer * buffer, gl::GLsizeiptr size, gl::GLenum usage) const;
void clearData(gl::GLenum internalformat, gl::GLenum format, gl::GLenum type, const void * data = nullptr);
void clearSubData(gl::GLenum internalformat, gl::GLintptr offset, gl::GLsizeiptr size, gl::GLenum format, gl::GLenum type, const void * data = nullptr);
const void * getPointer() const;
void * getPointer();
const void * getPointer(gl::GLenum pname) const;
void * getPointer(gl::GLenum pname);
void getSubData(gl::GLintptr offset, gl::GLsizeiptr size, void * data) const;
template <typename T>
std::vector<T> getSubData(gl::GLsizeiptr count, gl::GLintptr offset = 0) const;
template <typename T, std::size_t Count>
std::array<T, Count> getSubData(gl::GLintptr offset = 0) const;
void invalidateData() const;
void invalidateSubData(gl::GLintptr offset, gl::GLsizeiptr length) const;
virtual gl::GLenum objectType() const override;
protected:
Buffer(IDResource * resource);
virtual ~Buffer();
};
} // namespace globjects
#include <globjects/Buffer.inl>
Object.h
globjects::Buffer
Wrapper for OpenGL buffer objects.
Definition Buffer.h:36
globjects::Buffer::invalidateSubData
void invalidateSubData(gl::GLintptr offset, gl::GLsizeiptr length) const
Wraps the OpenGL function gl::glInvalidateBufferSubData.
globjects::Buffer::getSubData
std::vector< T > getSubData(gl::GLsizeiptr count, gl::GLintptr offset=0) const
Convenience method to simplify getting of data in form of an std::vector.
globjects::Buffer::setSubData
void setSubData(const std::vector< T > &data, gl::GLintptr offset=0)
Convenience method to simplify passing of data in form of an std::vector.
globjects::Buffer::hintBindlessImplementation
static void hintBindlessImplementation(BindlessImplementation impl)
globjects::Buffer::getParameter64
gl::GLint64 getParameter64(gl::GLenum pname) const
Wraps the OpenGL function gl::glGetBufferParameter for 64 bit data types. Queries OpenGL for internal...
globjects::Buffer::getParameter
gl::GLint getParameter(gl::GLenum pname) const
Wraps the OpenGL function gl::glGetBufferParameter. Queries OpenGL for internal state of the buffer.
globjects::Buffer::~Buffer
virtual ~Buffer()
globjects::Buffer::setStorage
void setStorage(const std::array< T, Count > &data, gl::BufferStorageMask flags)
Convenience method to simplify passing of data in form of an std::array.
globjects::Buffer::setData
void setData(gl::GLsizeiptr size, const gl::GLvoid *data, gl::GLenum usage)
Wraps the OpenGL function glBufferData. Creates video memory for the buffer.
globjects::Buffer::setData
void setData(const std::vector< T > &data, gl::GLenum usage)
Convenience method to simplify passing of data in form of an std::vector.
globjects::Buffer::invalidateData
void invalidateData() const
Wraps the OpenGL function gl::glInvalidateBufferData.
globjects::Buffer::getSubData
void getSubData(gl::GLintptr offset, gl::GLsizeiptr size, void *data) const
Wraps the OpenGL function glGetBufferSubData. Retrieves the contents of the buffers data store.
globjects::Buffer::BindlessImplementation
BindlessImplementation
Definition Buffer.h:39
globjects::Buffer::setWorkingTarget
static void setWorkingTarget(gl::GLenum target)
Sets the target that is used for binding buffers to call state changing OpenGL functions....
globjects::Buffer::setSubData
void setSubData(gl::GLintptr offset, gl::GLsizeiptr size, const gl::GLvoid *data=nullptr)
Wraps the OpenGL function glBufferSubData. Writes data only to a defined area of the memory.
globjects::Buffer::unbind
static void unbind(gl::GLenum target)
Unbinds a specific target, i.e. binds a 0 id to the target.
globjects::Buffer::bindBase
void bindBase(gl::GLenum target, gl::GLuint index) const
Wraps the OpenGL function gl::glBindBufferBase.
globjects::Buffer::getPointer
void * getPointer(gl::GLenum pname)
globjects::Buffer::unmap
bool unmap() const
Wraps the OpenGL function glUnmapBuffer.
globjects::Buffer::flushMappedRange
void flushMappedRange(gl::GLintptr offset, gl::GLsizeiptr length)
Wraps the OpenGL function glFlushMappedBufferRange.
globjects::Buffer::map
const void * map() const
Maps the Buffer's memory read only.
globjects::Buffer::bind
void bind(gl::GLenum target) const
Binds the buffer to target.
globjects::Buffer::bindRange
void bindRange(gl::GLenum target, gl::GLuint index, gl::GLintptr offset, gl::GLsizeiptr size) const
Wraps the OpenGL function gl::glBindBufferRange.
globjects::Buffer::copyData
void copyData(Buffer *buffer, gl::GLsizeiptr size, gl::GLenum usage) const
Creates new uninitialized memory to fit size (using usage), then copies the contents of buffer to thi...
globjects::Buffer::Buffer
Buffer(IDResource *resource)
Creates a buffer with an external id.
globjects::Buffer::copySubData
void copySubData(Buffer *buffer, gl::GLsizeiptr size) const
Convenience method. Both readOffset and writeOffset are 0.
globjects::Buffer::copySubData
void copySubData(Buffer *buffer, gl::GLintptr readOffset, gl::GLintptr writeOffset, gl::GLsizeiptr size) const
Wraps the OpenGL function glCopyBufferSubData.
globjects::Buffer::setStorage
void setStorage(const std::vector< T > &data, gl::BufferStorageMask flags)
Convenience method to simplify passing of data in form of an std::vector.
globjects::Buffer::clearSubData
void clearSubData(gl::GLenum internalformat, gl::GLintptr offset, gl::GLsizeiptr size, gl::GLenum format, gl::GLenum type, const void *data=nullptr)
Wraps the OpenGL function gl::glClearBufferSubData.
globjects::Buffer::map
void * map(gl::GLenum access)
Maps the Buffer's memory using the internal target.
globjects::Buffer::getPointer
void * getPointer()
globjects::Buffer::getPointer
const void * getPointer() const
globjects::Buffer::mapRange
void * mapRange(gl::GLintptr offset, gl::GLsizeiptr length, gl::BufferAccessMask access)
Wraps the OpenGL function glMapBufferRange. Maps only a range of the buffers memory.
globjects::Buffer::setStorage
void setStorage(const T &data, gl::BufferStorageMask flags)
Convenience method to simplify passing of data in form of a POD struct.
globjects::Buffer::setStorage
void setStorage(gl::GLsizeiptr size, const gl::GLvoid *data, gl::BufferStorageMask flags)
Wraps the OpenGL function glBufferStorage.
globjects::Buffer::Buffer
Buffer()
Creates a new OpenGL buffer object.
globjects::Buffer::accept
virtual void accept(ObjectVisitor &visitor) override
Implements the visitor pattern.
globjects::Buffer::unbind
static void unbind(gl::GLenum target, gl::GLuint index)
Unbinds the buffer bound to the target and index.
globjects::Buffer::clearData
void clearData(gl::GLenum internalformat, gl::GLenum format, gl::GLenum type, const void *data=nullptr)
Wraps the OpenGL function gl::glClearBufferData. Clears the Buffer's data by filling it with the valu...
globjects::Buffer::setSubData
void setSubData(const std::array< T, Count > &data, gl::GLintptr offset=0)
Convenience method to simplify passing of data in form of an std::array.
globjects::Buffer::setData
void setData(const T &data, gl::GLenum usage)
Convenience method to simplify passing of data in form of a POD struct.
globjects::Buffer::getPointer
const void * getPointer(gl::GLenum pname) const
globjects::Buffer::setSubData
void setSubData(const T &data, gl::GLintptr offset=0)
Convenience method to simplify passing of data in form of a POD struct.
globjects::Buffer::setData
void setData(const std::array< T, Count > &data, gl::GLenum usage)
Convenience method to simplify passing of data in form of an std::array.
globjects::Buffer::getSubData
std::array< T, Count > getSubData(gl::GLintptr offset=0) const
Convenience method to simplify getting of data in form of an std::array.
globjects::Buffer::fromId
static Buffer * fromId(gl::GLuint id)
Creates a buffer with an external id. This object does not own the associated OpenGL object and will ...
globjects::Buffer::objectType
virtual gl::GLenum objectType() const override
globjects::Object
Superclass of all wrapped OpenGL objects.
Definition Object.h:27
globjects::ObjectVisitor
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition ObjectVisitor.h:30
globjects
Contains all the classes that wrap OpenGL functionality.