medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 9dd2ac6640be35aa387a3275ae9f058f1a37f1d5
parent 01928c4ae4d034ee513698a006d9da4f451f86c0
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Sep 16 17:45:41 +0100

Use the GPU for BTT rendering

Diffstat:
btt.cc | 2+-
gpubtt.cc | 17+++++++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/btt.cc b/btt.cc @@ -302,7 +302,7 @@ extern "C" GAME_FRAME( game_frame ) { glUseProgram( state->test_shader ); glUniformMatrix4fv( state->test_un_VP, 1, GL_FALSE, glm::value_ptr( VP ) ); glUniform3fv( state->test_un_sun, 1, glm::value_ptr( sun ) ); - state->hm.render(); + gpubtt_render( &state->gpubtt ); glUseProgram( 0 ); immediate_init( &imm, triangles, array_count( triangles ) ); diff --git a/gpubtt.cc b/gpubtt.cc @@ -24,9 +24,9 @@ static void gpubtt_build( ) { const glm::vec3 offset( ohm->x_offset, ohm->y_offset, 0.0f ); - const glm::vec3 v0( ohm->hm.point( v0.x, v0.y ) + offset ); - const glm::vec3 v1( ohm->hm.point( v1.x, v1.y ) + offset ); - const glm::vec3 v2( ohm->hm.point( v2.x, v2.y ) + offset ); + const glm::vec3 v0( ohm->hm.point( iv0.x, iv0.y ) + offset ); + const glm::vec3 v1( ohm->hm.point( iv1.x, iv1.y ) + offset ); + const glm::vec3 v2( ohm->hm.point( iv2.x, iv2.y ) + offset ); if( btt->left ) { const glm::ivec2 mid = ( iv0 + iv2 ) / 2; @@ -35,9 +35,10 @@ static void gpubtt_build( gpubtt_build( verts, i, ohm, btt->right, iv2, mid, iv1 ); } else { - verts[ *i++ ] = v0; - verts[ *i++ ] = v1; - verts[ *i++ ] = v2; + verts[ *i + 0 ] = v0; + verts[ *i + 1 ] = v1; + verts[ *i + 2 ] = v2; + *i += 3; } } @@ -62,7 +63,7 @@ void gpubtt_init( glGenBuffers( 1, &gpubtt->vbo_verts ); glBindBuffer( GL_ARRAY_BUFFER, gpubtt->vbo_verts ); - glBufferData( GL_ARRAY_BUFFER, num_leaves * sizeof( GLfloat ) * 3, verts, GL_STATIC_DRAW ); + glBufferData( GL_ARRAY_BUFFER, i * 3 * sizeof( GLfloat ), verts, GL_STATIC_DRAW ); glEnableVertexAttribArray( at_position ); glVertexAttribPointer( at_position, 3, GL_FLOAT, GL_FALSE, 0, 0 ); @@ -80,6 +81,6 @@ void gpubtt_destroy( GPUBTT * const gpubtt ) { void gpubtt_render( const GPUBTT * const gpubtt ) { glBindVertexArray( gpubtt->vao ); - glDrawElements( GL_TRIANGLES, gpubtt->num_verts, GL_UNSIGNED_INT, 0 ); + glDrawArrays( GL_TRIANGLES, 0, gpubtt->num_verts * 3 ); glBindVertexArray( 0 ); }