1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Introduced a shorthand for setting up array attributes.

This commit is contained in:
Thomas Harte 2016-05-10 19:11:48 -04:00
parent 257420b0f7
commit 47ae402f7e
3 changed files with 18 additions and 15 deletions

View File

@ -426,21 +426,8 @@ void OpenGLOutputBuilder::prepare_output_vertex_array()
{
glBindVertexArray(output_vertex_array);
glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer);
const GLsizei vertexStride = OutputVertexSize;
size_t offset = 0;
const char *attributes[] = {"horizontal", "vertical", nullptr};
const char **attribute = attributes;
while(*attribute)
{
GLint attributeLocation = output_shader_program->get_attrib_location(*attribute);
glEnableVertexAttribArray((GLuint)attributeLocation);
glVertexAttribPointer((GLuint)attributeLocation, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)offset);
glVertexAttribDivisor((GLuint)attributeLocation, 1);
offset += 4;
attribute++;
}
output_shader_program->enable_vertex_attribute_with_pointer("horizontal", 2, GL_UNSIGNED_SHORT, GL_FALSE, OutputVertexSize, (void *)OutputVertexOffsetOfHorizontal, 1);
output_shader_program->enable_vertex_attribute_with_pointer("vertical", 2, GL_UNSIGNED_SHORT, GL_FALSE, OutputVertexSize, (void *)OutputVertexOffsetOfVertical, 1);
}
}

View File

@ -112,3 +112,11 @@ GLint Shader::get_uniform_location(const GLchar *name)
{
return glGetUniformLocation(_shader_program, name);
}
void Shader::enable_vertex_attribute_with_pointer(const char *name, GLint size, GLenum type, GLboolean normalised, GLsizei stride, const GLvoid *pointer, GLuint divisor)
{
GLint location = get_attrib_location(name);
glEnableVertexAttribArray((GLuint)location);
glVertexAttribPointer((GLuint)location, size, type, normalised, stride, pointer);
glVertexAttribDivisor((GLuint)location, divisor);
}

View File

@ -66,6 +66,14 @@ public:
*/
GLint get_uniform_location(const GLchar *name);
/*!
Shorthand for an appropriate sequence of:
* @c get_attrib_location;
* @c glEnableVertexAttribArray;
* @c glVertexAttribPointer;
* @c glVertexAttribDivisor.
*/
void enable_vertex_attribute_with_pointer(const char *name, GLint size, GLenum type, GLboolean normalised, GLsizei stride, const GLvoid *pointer, GLuint divisor);
private:
GLuint compile_shader(const char *source, GLenum type);