7 #include <gls/headercheck.hpp>
8 #include <gls/errorcheck.hpp>
9 #include <gls/objects/object.hpp>
10 #include <gls/objects/buffer.hpp>
16 void gen_vertex_arrays( GLsizei size, GLuint* name ) { glGenVertexArrays( size, name ); }
17 void delete_vertex_arrays( GLsizei size,
const GLuint* name ) { glDeleteVertexArrays( size, name ); }
33 return m_object.name();
41 check_gl_error( glBindVertexArray( m_object.name() ) );
49 check_gl_error( glBindVertexArray( 0 ) );
71 template<GLenum BufferType,
typename T,
typename U>
75 if( attribute_location < 0 ) {
79 bind_attribute( static_cast<GLuint>( attribute_location ), the_buffer, size, type, normalized, stride, offset );
100 template<GLenum BufferType,
typename T,
typename U>
103 check_gl_error( glBindBuffer( GL_ARRAY_BUFFER, the_buffer.
name() ) );
104 check_gl_error( glEnableVertexAttribArray( attribute_location ) );
105 check_gl_error( glVertexAttribPointer( attribute_location, size, type, normalized, static_cast<GLsizei>( stride ), reinterpret_cast<const GLvoid*>( offset ) ) );
106 check_gl_error( glBindBuffer( GL_ARRAY_BUFFER, 0 ) );
108 check_gl_error( glDisableVertexAttribArray( attribute_location ) );
125 if( attribute_location < 0 ) {
144 check_gl_error( glDisableVertexAttribArray( static_cast<GLuint>( attribute_location ) ) );
164 auto max_vertex_attributes = GLint();
166 check_gl_error( glGetIntegerv( GL_MAX_VERTEX_ATTRIBS, &max_vertex_attributes ) );
170 for( GLuint index = 0; index < static_cast<GLuint>( max_vertex_attributes ); ++index ) {
171 check_gl_error( glDisableVertexAttribArray( index ) );
188 template<GLenum BufferType>
191 check_gl_error( glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, the_buffer.
name() ) );
193 check_gl_error( glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ) );
204 check_gl_error( glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ) );
GLint get_attribute_location(const std::string &attribute_name) const
Get the location of an attribute.
Definition: program.hpp:154
Class encapsulating an OpenGL program object.
Definition: program.hpp:36
void bind_index_buffer(const buffer< BufferType > &the_buffer)
Bind an index buffer to this vertex array.
Definition: vertexarray.hpp:189
void unbind_index_buffer()
Unbind the index buffer from this vertex array.
Definition: vertexarray.hpp:202
Class encapsulating an OpenGL buffer object.
Definition: buffer.hpp:27
Class encapsulating an OpenGL vertex array object.
Definition: vertexarray.hpp:24
static void unbind()
Unbind the currently bound vertex array.
Definition: vertexarray.hpp:48
GLuint name() const
Retrieve the OpenGL name of this buffer.
Definition: buffer.hpp:35
void bind_attribute(GLuint attribute_location, const buffer< BufferType > &the_buffer, GLint size, GLenum type, GLboolean normalized, T stride, U offset)
Bind a shader attribute to a buffer source.
Definition: vertexarray.hpp:101
GLuint name() const
Retrieve the OpenGL name of this vertex array.
Definition: vertexarray.hpp:32
void clear_attribute_bindings()
Clear all attribute bindings.
Definition: vertexarray.hpp:163
void bind_attribute(const program &the_program, const std::string &attribute_name, const buffer< BufferType > &the_buffer, GLint size, GLenum type, GLboolean normalized, T stride, U offset)
Bind a shader attribute to a buffer source.
Definition: vertexarray.hpp:72
Definition: buffer.hpp:12
void bind()
Bind this vertex array.
Definition: vertexarray.hpp:40
void unbind_attribute(const program &the_program, const std::string &attribute_name)
Unbind a shader attribute.
Definition: vertexarray.hpp:122
void unbind_attribute(GLuint attribute_location)
Unbind a shader attribute.
Definition: vertexarray.hpp:142