7 #include <gls/headercheck.hpp>
8 #include <gls/errorcheck.hpp>
9 #include <gls/objects/object.hpp>
15 void gen_buffers( GLsizei size, GLuint* name ) { glGenBuffers( size, name ); }
16 void delete_buffers( GLsizei size,
const GLuint* name ) { glDeleteBuffers( size, name ); }
26 template<GLenum Target = GL_ARRAY_BUFFER, GLenum Usage = GL_DYNAMIC_DRAW>
36 return m_object.name();
61 check_gl_error( glBindBuffer( Target, m_object.name() ) );
72 check_gl_error( glBindBuffer( Target, 0 ) );
88 void bind_range( GLuint index, GLintptr offset, T range_size ) {
89 check_gl_error( glBindBufferRange( Target, index, m_object.name(), offset,
static_cast<GLsizeiptr
>( range_size ) ) );
112 void data( T data_size,
const GLvoid* data_ptr ) {
113 assert( data_size >= 0 );
114 m_size =
static_cast<GLsizeiptr
>( data_size );
117 check_gl_error( glBufferData( Target, m_size, data_ptr, Usage ) );
139 void sub_data( GLintptr offset, T data_size,
const GLvoid* data_ptr ) {
140 if( m_size < offset + static_cast<GLsizeiptr>( data_size ) ) {
143 new_buffer.
data( offset + static_cast<GLsizeiptr>( data_size ),
nullptr );
146 std::swap( *
this, new_buffer );
150 check_gl_error( glBufferSubData( Target, offset, static_cast<GLsizeiptr>( data_size ), data_ptr ) );
175 template<GLenum SourceTarget, GLenum SourceUsage,
typename V>
177 assert( data_size > 0 );
178 assert( source.
size() >= readoffset +
static_cast<GLsizeiptr
>( data_size ) );
180 if( m_size < writeoffset + static_cast<GLsizeiptr>( data_size ) ) {
183 new_buffer.
data( writeoffset + static_cast<GLsizeiptr>( data_size ),
nullptr );
189 std::swap( *
this, new_buffer );
192 check_gl_error( glBindBuffer( GL_COPY_READ_BUFFER, source.
name() ) );
193 check_gl_error( glBindBuffer( GL_COPY_WRITE_BUFFER,
name() ) );
195 check_gl_error( glCopyBufferSubData( GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, readoffset, writeoffset, static_cast<GLsizeiptr>( data_size ) ) );
197 check_gl_error( glBindBuffer( GL_COPY_READ_BUFFER, 0 ) );
198 check_gl_error( glBindBuffer( GL_COPY_WRITE_BUFFER, 0 ) );
213 assert( m_size >= offset + static_cast<GLsizeiptr>( data_size ) );
216 check_gl_error( glGetBufferSubData( Target, offset, static_cast<GLsizeiptr>( data_size ), data_ptr ) );
222 GLsizeiptr m_size = 0;
void sub_data(GLintptr offset, T data_size, const GLvoid *data_ptr)
Upload a data range.
Definition: buffer.hpp:139
static void unbind()
Unbind the current buffer from the target.
Definition: buffer.hpp:71
void data(T data_size, const GLvoid *data_ptr)
Allocate storage and upload data.
Definition: buffer.hpp:112
Class encapsulating an OpenGL buffer object.
Definition: buffer.hpp:27
GLuint name() const
Retrieve the OpenGL name of this buffer.
Definition: buffer.hpp:35
void bind()
Bind this buffer to its target.
Definition: buffer.hpp:60
void get_sub_data(GLintptr offset, T data_size, GLvoid *data_ptr)
Read back data from the buffer.
Definition: buffer.hpp:212
void bind_range(GLuint index, GLintptr offset, T range_size)
Bind a range to an indexed target.
Definition: buffer.hpp:88
GLsizeiptr size() const
Retrieve the size of buffer.
Definition: buffer.hpp:49
Definition: buffer.hpp:12
void copy_sub_data(const buffer< SourceTarget, SourceUsage > &source, GLintptr readoffset, GLintptr writeoffset, V data_size)
Copy a data range from another buffer into this one.
Definition: buffer.hpp:176