globjects  1.0.0.000000000000
Strict OpenGL objects wrapper.
Buffer.h
Go to the documentation of this file.
1
2#pragma once
3
4#include <vector>
5#include <array>
6
7#include <glbinding/gl/types.h>
8
9#include <globjects/globjects_api.h>
10#include <globjects/Object.h>
11
12
13namespace globjects
14{
15
16
35class GLOBJECTS_API Buffer : public Object
36{
37public:
39 {
40 DirectStateAccessARB
41 , DirectStateAccessEXT
42 , Legacy
43 };
44
46
52 static void setWorkingTarget(gl::GLenum target);
53
54public:
58
64 static Buffer * fromId(gl::GLuint id);
65
69 virtual void accept(ObjectVisitor & visitor) override;
70
75 void bind(gl::GLenum target) const;
76
80 static void unbind(gl::GLenum target);
81
86 static void unbind(gl::GLenum target, gl::GLuint index);
87
95 void setData(gl::GLsizeiptr size, const gl::GLvoid * data, gl::GLenum usage);
96
99 template <typename T>
100 void setData(const T & data, gl::GLenum usage);
101
104 template <typename T>
105 void setData(const std::vector<T> & data, gl::GLenum usage);
106
109 template <typename T, std::size_t Count>
110 void setData(const std::array<T, Count> & data, gl::GLenum usage);
111
119 void setSubData(gl::GLintptr offset, gl::GLsizeiptr size, const gl::GLvoid* data = nullptr);
120
123 template <typename T>
124 void setSubData(const T & data, gl::GLintptr offset = 0);
125
128 template <typename T>
129 void setSubData(const std::vector<T> & data, gl::GLintptr offset = 0);
130
133 template <typename T, std::size_t Count>
134 void setSubData(const std::array<T, Count> & data, gl::GLintptr offset = 0);
135
142 void setStorage(gl::GLsizeiptr size, const gl::GLvoid * data, gl::BufferStorageMask flags);
143
146 template <typename T>
147 void setStorage(const T & data, gl::BufferStorageMask flags);
148
151 template <typename T>
152 void setStorage(const std::vector<T> & data, gl::BufferStorageMask flags);
153
156 template <typename T, std::size_t Count>
157 void setStorage(const std::array<T, Count> & data, gl::BufferStorageMask flags);
158
165 gl::GLint getParameter(gl::GLenum pname) const;
166
173 gl::GLint64 getParameter64(gl::GLenum pname) const;
174
178 const void * map() const;
179
184 void * map(gl::GLenum access);
185
194 void * mapRange(gl::GLintptr offset, gl::GLsizeiptr length, gl::BufferAccessMask access);
195
199 bool unmap() const;
200
206 void flushMappedRange(gl::GLintptr offset, gl::GLsizeiptr length);
207
211 void bindBase(gl::GLenum target, gl::GLuint index) const;
212
216 void bindRange(gl::GLenum target, gl::GLuint index, gl::GLintptr offset, gl::GLsizeiptr size) const;
217
224 void copySubData(Buffer * buffer, gl::GLintptr readOffset, gl::GLintptr writeOffset, gl::GLsizeiptr size) const;
225
228 void copySubData(Buffer * buffer, gl::GLsizeiptr size) const;
229
236 void copyData(Buffer * buffer, gl::GLsizeiptr size, gl::GLenum usage) const;
237
243 void clearData(gl::GLenum internalformat, gl::GLenum format, gl::GLenum type, const void * data = nullptr);
244
250 void clearSubData(gl::GLenum internalformat, gl::GLintptr offset, gl::GLsizeiptr size, gl::GLenum format, gl::GLenum type, const void * data = nullptr);
251
252 const void * getPointer() const;
253 void * getPointer();
254 const void * getPointer(gl::GLenum pname) const;
255 void * getPointer(gl::GLenum pname);
256
264 void getSubData(gl::GLintptr offset, gl::GLsizeiptr size, void * data) const;
265
268 template <typename T>
269 std::vector<T> getSubData(gl::GLsizeiptr count, gl::GLintptr offset = 0) const;
270
273 template <typename T, std::size_t Count>
274 std::array<T, Count> getSubData(gl::GLintptr offset = 0) const;
275
279 void invalidateData() const;
280
286 void invalidateSubData(gl::GLintptr offset, gl::GLsizeiptr length) const;
287
288 virtual gl::GLenum objectType() const override;
289
290protected:
294 Buffer(IDResource * resource);
295
299 virtual ~Buffer();
300};
301
302
303} // namespace globjects
304
305
306#include <globjects/Buffer.inl>
Wrapper for OpenGL buffer objects.
Definition: Buffer.h:36
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 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:39
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.
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...
Buffer(IDResource *resource)
Creates a buffer with an external id.
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 * mapRange(gl::GLintptr offset, gl::GLsizeiptr length, gl::BufferAccessMask access)
Wraps the OpenGL function glMapBufferRange. Maps only a range of the buffers memory.
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.
virtual void accept(ObjectVisitor &visitor) override
Implements the visitor pattern.
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
Superclass of all wrapped OpenGL objects.
Definition: Object.h:27
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:30
Contains all the classes that wrap OpenGL functionality.