Created
August 7, 2013 22:25
-
-
Save mousebird/6179433 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set up the vertex array (note this can only be done on the main thread) | |
- (void)makeVertexArray | |
{ | |
// Create a vertex array object and set up its internal state | |
glGenVertexArraysOES(1, &_vertexArray); | |
glBindVertexArrayOES(_vertexArray); | |
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); | |
// Normally you'd have to do this each time | |
// Vertex arrays encapsulate this for you | |
glEnableVertexAttribArray(GLKVertexAttribPosition); | |
glVertexAttribPointer(GLKVertexAttribPosition, 3, | |
GL_FLOAT, GL_FALSE, | |
_vertexSize, BUFFER_OFFSET(0)); | |
glEnableVertexAttribArray(GLKVertexAttribNormal); | |
glVertexAttribPointer(GLKVertexAttribNormal, 3, | |
GL_FLOAT, GL_FALSE, | |
_vertexSize, BUFFER_OFFSET(12)); | |
if (_hasTextureCoords) | |
{ | |
glEnableVertexAttribArray(GLKVertexAttribTexCoord0); | |
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, | |
GL_FLOAT, GL_FALSE, | |
_vertexSize, BUFFER_OFFSET(24)); | |
} | |
glBindVertexArrayOES(0); | |
glBindBuffer(GL_ARRAY_BUFFER, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment