

This means we are either hard-coding or saving some amount of data for a nearly meaningless task. The first is that we need to cache the layout of the vertex buffer to enable and disable the right attributes before drawing. There are several reasons why we might not like this code very much.

GlDrawElements( GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0 ) GlVertexAttribPointer( ATTRIBUTE_LOCATION_NORMALS, 3, GL_FLOAT, GL_FALSE, 32, 20 ) GlEnableVertexAttribArray( ATTRIBUTE_LOCATION_NORMALS ) GlVertexAttribPointer( ATTRIBUTE_LOCATION_TEXTUREUV, 2, GL_FLOAT, GL_FALSE, 32, 12 ) GlEnableVertexAttribArray( ATTRIBUTE_LOCATION_TEXTUREUV ) GlVertexAttribPointer( ATTRIBUTE_LOCATION_POSITIONS, 3, GL_FLOAT, GL_FALSE, 32, 0 ) GlEnableVertexAttribArray( ATTRIBUTE_LOCATION_POSITIONS ) GlBindBuffer( GL_ARRAY_BUFFER, vertex_buffer_object ) Bind shader program, uniforms and textures Therefore, a draw call might look like this: const GLuint ATTRIBUTE_LOCATION_POSITIONS = 0 Ĭonst GLuint ATTRIBUTE_LOCATION_TEXTUREUV = 1 Ĭonst GLuint ATTRIBUTE_LOCATION_NORMALS = 2 To do that, you need to bind the vertex buffer, enable the generic vertex attribute, and use glVertexAttribPointer to describe the layout of the buffer. positions, normals, UVs) to the corresponding vertex shader attributes. Binding the vertex bufferīefore drawing onto the screen, you need to bind your vertex data (e.g. In this post, we’ll show another useful technique that will help you produce increased performance and cleaner code when drawing objects. Previously, we showed how you can use vertex layout qualifiers to increase the performance and determinism of your OpenGL application.
