diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-14 21:05:53 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-14 21:05:53 +0000 |
commit | 9925f734681d1f0dd8f30576a0c4cebfa4339190 (patch) | |
tree | d37ad22ae3a4b0b15aa951740a60b70189d3687f /third_party | |
parent | 2bb61dc4a36fc8522b12d0d67e2a1a2076cd0ecc (diff) | |
download | chromium_src-9925f734681d1f0dd8f30576a0c4cebfa4339190.zip chromium_src-9925f734681d1f0dd8f30576a0c4cebfa4339190.tar.gz chromium_src-9925f734681d1f0dd8f30576a0c4cebfa4339190.tar.bz2 |
Modified texture cubemap example to use VBOs instead of client-side vertex arrays.
BUG=26099
TEST-none
Review URL: http://codereview.chromium.org/552001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c b/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c index 691801f..5eb13a6 100644 --- a/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c +++ b/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c @@ -31,17 +31,14 @@ typedef struct GLuint textureId; // Vertex data - int numIndices; - GLfloat *vertices; - GLfloat *normals; - GLuint *indices; - + int numIndices; + GLuint vboIds[3]; } UserData; /// // Create a simple cubemap with a 1x1 face with a different // color for each face -GLuint CreateSimpleTextureCubemap( ) +static GLuint CreateSimpleTextureCubemap( ) { GLuint textureId; // Six 1x1 RGB faces @@ -106,6 +103,11 @@ GLuint CreateSimpleTextureCubemap( ) int Init ( ESContext *esContext ) { UserData *userData = esContext->userData; + int numSlices = 20; + int numVertices = ( (numSlices / 2) + 1 ) * ( numSlices + 1 ); + GLfloat *vertices = NULL; + GLfloat *normals = NULL; + GLushort *indices = NULL; GLbyte vShaderStr[] = "attribute vec4 a_position; \n" "attribute vec3 a_normal; \n" @@ -139,9 +141,24 @@ int Init ( ESContext *esContext ) userData->textureId = CreateSimpleTextureCubemap (); // Generate the vertex data - userData->numIndices = esGenSphere ( 20, 0.75f, &userData->vertices, &userData->normals, - NULL, &userData->indices ); - + userData->numIndices = esGenSphere ( numSlices, 0.75f, &vertices, &normals, + NULL, &indices ); + glGenBuffers( 3, userData->vboIds ); + // Load vertex positions + glBindBuffer ( GL_ARRAY_BUFFER, userData->vboIds[0] ); + glBufferData ( GL_ARRAY_BUFFER, 3 * numVertices * sizeof(GLfloat), + vertices, GL_STATIC_DRAW ); + // Load vertex normals + glBindBuffer ( GL_ARRAY_BUFFER, userData->vboIds[1] ); + glBufferData ( GL_ARRAY_BUFFER, 3 * numVertices * sizeof(GLfloat), + normals, GL_STATIC_DRAW ); + // Load vertex indices + glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->vboIds[2] ); + glBufferData ( GL_ELEMENT_ARRAY_BUFFER, userData->numIndices * sizeof(GLushort), + indices, GL_STATIC_DRAW ); + if ( vertices != NULL ) free ( vertices ); + if ( normals != NULL ) free ( normals ); + if ( indices != NULL ) free ( indices ); glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); return TRUE; @@ -169,10 +186,10 @@ void Draw ( ESContext *esContext ) // Load the vertex position glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT, - GL_FALSE, 0, userData->vertices ); + GL_FALSE, 0, 0 ); // Load the normal glVertexAttribPointer ( userData->normalLoc, 3, GL_FLOAT, - GL_FALSE, 0, userData->normals ); + GL_FALSE, 0, 0 ); glEnableVertexAttribArray ( userData->positionLoc ); glEnableVertexAttribArray ( userData->normalLoc ); @@ -185,7 +202,7 @@ void Draw ( ESContext *esContext ) glUniform1i ( userData->samplerLoc, 0 ); glDrawElements ( GL_TRIANGLES, userData->numIndices, - GL_UNSIGNED_INT, userData->indices ); + GL_UNSIGNED_SHORT, 0 ); eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); } @@ -203,8 +220,8 @@ void ShutDown ( ESContext *esContext ) // Delete program object glDeleteProgram ( userData->programObject ); - free ( userData->vertices ); - free ( userData->normals ); + // Delete vertex buffer objects + glDeleteBuffers ( 3, userData->vboIds ); } |