globjects  2.0.0.630135941c42
Strict OpenGL objects wrapper.
Loading...
Searching...
No Matches
Buffer.h
Go to the documentation of this file.
1
2#pragma once
3
4
5#include <vector>
6#include <array>
7
8#include <glbinding/gl/types.h>
9
10#include <globjects/globjects_api.h>
11#include <globjects/Object.h>
13
14
15namespace globjects
16{
17
18
37class GLOBJECTS_API Buffer : public Object, public Instantiator<Buffer>
38{
39public:
41 {
42 Legacy
43 , DirectStateAccessEXT
44 , DirectStateAccessARB
45 };
46
48
54 static void setWorkingTarget(gl::GLenum target);
55
56
57public:
61
65 virtual ~Buffer();
66
72 static Buffer * fromId(gl::GLuint id);
73
78 void bind(gl::GLenum target) const;
79
83 static void unbind(gl::GLenum target);
84
89 static void unbind(gl::GLenum target, gl::GLuint index);
90
98 void setData(gl::GLsizeiptr size, const gl::GLvoid * data, gl::GLenum usage);
99
102 template <typename T>
103 void setData(const T & data, gl::GLenum usage);
104
107 template <typename T>
108 void setData(const std::vector<T> & data, gl::GLenum usage);
109
112 template <typename T, std::size_t Count>
113 void setData(const std::array<T, Count> & data, gl::GLenum usage);
114
122 void setSubData(gl::GLintptr offset, gl::GLsizeiptr size, const gl::GLvoid* data = nullptr);
123
126 template <typename T>
127 void setSubData(const T & data, gl::GLintptr offset = 0);
128
131 template <typename T>
132 void setSubData(const std::vector<T> & data, gl::GLintptr offset = 0);
133
136 template <typename T, std::size_t Count>
137 void setSubData(const std::array<T, Count> & data, gl::GLintptr offset = 0);
138
145 void setStorage(gl::GLsizeiptr size, const gl::GLvoid * data, gl::BufferStorageMask flags);
146
149 template <typename T>
150 void setStorage(const T & data, gl::BufferStorageMask flags);
151
154 template <typename T>
155 void setStorage(const std::vector<T> & data, gl::BufferStorageMask flags);
156
159 template <typename T, std::size_t Count>
160 void setStorage(const std::array<T, Count> & data, gl::BufferStorageMask flags);
161
168 gl::GLint getParameter(gl::GLenum pname) const;
169
176 gl::GLint64 getParameter64(gl::GLenum pname) const;
177
181 const void * map() const;
182
187 void * map(gl::GLenum access);
188
197 void * mapRange(gl::GLintptr offset, gl::GLsizeiptr length, gl::MapBufferAccessMask access);
198
202 bool unmap() const;
203
209 void flushMappedRange(gl::GLintptr offset, gl::GLsizeiptr length);
210
214 void bindBase(gl::GLenum target, gl::GLuint index) const;
215
219 void bindRange(gl::GLenum target, gl::GLuint index, gl::GLintptr offset, gl::GLsizeiptr size) const;
220
227 void copySubData(Buffer * buffer, gl::GLintptr readOffset, gl::GLintptr writeOffset, gl::GLsizeiptr size) const;
228
231 void copySubData(Buffer * buffer, gl::GLsizeiptr size) const;
232
239 void copyData(Buffer * buffer, gl::GLsizeiptr size, gl::GLenum usage) const;
240
246 void clearData(gl::GLenum internalformat, gl::GLenum format, gl::GLenum type, const void * data = nullptr);
247
253 void clearSubData(gl::GLenum internalformat, gl::GLintptr offset, gl::GLsizeiptr size, gl::GLenum format, gl::GLenum type, const void * data = nullptr);
254
255 const void * getPointer() const;
256 void * getPointer();
257 const void * getPointer(gl::GLenum pname) const;
258 void * getPointer(gl::GLenum pname);
259
267 void getSubData(gl::GLintptr offset, gl::GLsizeiptr size, void * data) const;
268
271 template <typename T>
272 std::vector<T> getSubData(gl::GLsizeiptr count, gl::GLintptr offset = 0) const;
273
276 template <typename T, std::size_t Count>
277 std::array<T, Count> getSubData(gl::GLintptr offset = 0) const;
278
282 void invalidateData() const;
283
289 void invalidateSubData(gl::GLintptr offset, gl::GLsizeiptr length) const;
290
291 virtual gl::GLenum objectType() const override;
292
293
294protected:
298 Buffer(std::unique_ptr<IDResource> && resource);
299};
300
301
302} // namespace globjects
303
304
305#include <globjects/Buffer.inl>
Wrapper for OpenGL buffer objects.
Definition Buffer.h:38
void invalidateSubData(gl::GLintptr offset, gl::GLsizeiptr length) const
Wraps the OpenGL function gl::glInvalidateBufferSubData.
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.
void setSubData(const std::vector< T > &data, gl::GLintptr offset=0)
Convenience method to simplify passing of data in form of an std::vector.
static void hintBindlessImplementation(BindlessImplementation impl)
gl::GLint64 getParameter64(gl::GLenum pname) const
Wraps the OpenGL function gl::glGetBufferParameter for 64 bit data types. Queries OpenGL for internal...
gl::GLint getParameter(gl::GLenum pname) const
Wraps the OpenGL function gl::glGetBufferParameter. Queries OpenGL for internal state of the buffer.
void setStorage(const std::array< T, Count > &data, gl::BufferStorageMask flags)
Convenience method to simplify passing of data in form of an std::array.
void * mapRange(gl::GLintptr offset, gl::GLsizeiptr length, gl::MapBufferAccessMask access)
Wraps the OpenGL function glMapBufferRange. Maps only a range of the buffers memory.
void setData(gl::GLsizeiptr size, const gl::GLvoid *data, gl::GLenum usage)
Wraps the OpenGL function glBufferData. Creates video memory for the buffer.
void setData(const std::vector< T > &data, gl::GLenum usage)
Convenience method to simplify passing of data in form of an std::vector.
void invalidateData() const
Wraps the OpenGL function gl::glInvalidateBufferData.
void getSubData(gl::GLintptr offset, gl::GLsizeiptr size, void *data) const
Wraps the OpenGL function glGetBufferSubData. Retrieves the contents of the buffers data store.
BindlessImplementation
Definition Buffer.h:41
static void setWorkingTarget(gl::GLenum target)
Sets the target that is used for binding buffers to call state changing OpenGL functions....
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.
static void unbind(gl::GLenum target)
Unbinds a specific target, i.e. binds a 0 id to the target.
void bindBase(gl::GLenum target, gl::GLuint index) const
Wraps the OpenGL function gl::glBindBufferBase.
void * getPointer(gl::GLenum pname)
bool unmap() const
Wraps the OpenGL function glUnmapBuffer.
void flushMappedRange(gl::GLintptr offset, gl::GLsizeiptr length)
Wraps the OpenGL function glFlushMappedBufferRange.
Buffer(std::unique_ptr< IDResource > &&resource)
Creates a buffer with an external id.
const void * map() const
Maps the Buffer's memory read only.
void bind(gl::GLenum target) const
Binds the buffer to target.
void bindRange(gl::GLenum target, gl::GLuint index, gl::GLintptr offset, gl::GLsizeiptr size) const
Wraps the OpenGL function gl::glBindBufferRange.
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...
void copySubData(Buffer *buffer, gl::GLsizeiptr size) const
Convenience method. Both readOffset and writeOffset are 0.
void copySubData(Buffer *buffer, gl::GLintptr readOffset, gl::GLintptr writeOffset, gl::GLsizeiptr size) const
Wraps the OpenGL function glCopyBufferSubData.
void setStorage(const std::vector< T > &data, gl::BufferStorageMask flags)
Convenience method to simplify passing of data in form of an std::vector.
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.
void * map(gl::GLenum access)
Maps the Buffer's memory using the internal target.
const void * getPointer() const
void setStorage(const T &data, gl::BufferStorageMask flags)
Convenience method to simplify passing of data in form of a POD struct.
void setStorage(gl::GLsizeiptr size, const gl::GLvoid *data, gl::BufferStorageMask flags)
Wraps the OpenGL function glBufferStorage.
Buffer()
Creates a new OpenGL buffer object.
static void unbind(gl::GLenum target, gl::GLuint index)
Unbinds the buffer bound to the target and index.
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...
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.
void setData(const T &data, gl::GLenum usage)
Convenience method to simplify passing of data in form of a POD struct.
const void * getPointer(gl::GLenum pname) const
void setSubData(const T &data, gl::GLintptr offset=0)
Convenience method to simplify passing of data in form of a POD struct.
void setData(const std::array< T, Count > &data, gl::GLenum usage)
Convenience method to simplify passing of data in form of an std::array.
std::array< T, Count > getSubData(gl::GLintptr offset=0) const
Convenience method to simplify getting of data in form of an std::array.
static Buffer * fromId(gl::GLuint id)
Creates a buffer with an external id. This object does not own the associated OpenGL object and will ...
virtual gl::GLenum objectType() const override
CRTP for creating objects similar to std::make_unique.
Definition Instantiator.h:22
Superclass of all wrapped OpenGL objects.
Definition Object.h:28
Contains all the classes that wrap OpenGL functionality.