medfall

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

commit 29ad0b79026ad18dd6e2c491f8c6b4ea6f164854
parent 19c3c7a202e545b3222a69d4ea10cf77a4536abe
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Nov 30 20:50:40 +0200

Don't delete vertex/index buffers until we delete the mesh

This should fix garbage rendering on AMD GPUs

Diffstat:
bsp.cc | 3---
bsp_renderer.cc | 4----
immediate.cc | 3---
renderer.cc | 29+++++++++++++++++++++++------
renderer.h | 10+++++++---
skybox.cc | 3---
6 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/bsp.cc b/bsp.cc @@ -449,8 +449,5 @@ extern "C" GAME_FRAME( game_frame ) { renderer_draw_mesh( mesh, render_state2 ); renderer_delete_mesh( mesh ); - renderer_delete_vb( mesh_config.positions ); - renderer_delete_vb( mesh_config.colours ); - renderer_delete_ib( mesh_config.indices ); renderer_delete_texture( texture ); } diff --git a/bsp_renderer.cc b/bsp_renderer.cc @@ -103,10 +103,6 @@ void bspr_init( BSPRenderer * bspr, MemoryArena * arena, const BSP * bsp ) { config.num_vertices = num_indices; bspr->meshes[ l ] = renderer_new_mesh( config ); - - renderer_delete_vb( config.positions ); - renderer_delete_vb( config.colours ); - renderer_delete_ib( config.indices ); } } diff --git a/immediate.cc b/immediate.cc @@ -237,11 +237,8 @@ void immediate_render( const ImmediateContext * ctx, const RenderState & render_ } Mesh mesh = renderer_new_mesh( mesh_config ); - renderer_draw_mesh( mesh, render_state ); - renderer_delete_mesh( mesh ); - renderer_delete_vb( vb ); } void immediate_clear( ImmediateContext * ctx ) { diff --git a/renderer.cc b/renderer.cc @@ -7,11 +7,10 @@ STATIC_ASSERT( SAME_TYPE( VB, GLuint ) ); STATIC_ASSERT( SAME_TYPE( UB, GLuint ) ); -STATIC_ASSERT( SAME_TYPE( VAO, GLuint ) ); STATIC_ASSERT( SAME_TYPE( Shader, GLuint ) ); STATIC_ASSERT( SAME_TYPE( Texture, GLuint ) ); STATIC_ASSERT( SAME_TYPE( TextureBuffer, GLuint ) ); -STATIC_ASSERT( SAME_TYPE( u32, GLuint ) ); // for indexed rendering +STATIC_ASSERT( SAME_TYPE( u32, GLuint ) ); static const GLuint ATTR_POSITION = 0; static const GLuint ATTR_NORMAL = 1; @@ -404,15 +403,33 @@ Mesh renderer_new_mesh( MeshConfig config ) { glBindVertexArray( 0 ); - Mesh mesh; - mesh.vao = vao; + Mesh mesh = { }; mesh.num_vertices = config.num_vertices; mesh.primitive_type = config.primitive_type; - mesh.indexed = config.indices != 0; + mesh.vao = vao; + if( config.unified_buffer == 0 ) { + mesh.positions = config.positions; + mesh.normals = config.normals; + mesh.tex_coords0 = config.tex_coords0; + mesh.tex_coords1 = config.tex_coords1; + mesh.colours = config.colours; + } + else { + mesh.positions = config.unified_buffer; + } + mesh.indices = config.indices; + return mesh; } void renderer_delete_mesh( const Mesh & mesh ) { + if( mesh.positions ) renderer_delete_vb( mesh.positions ); + if( mesh.normals ) renderer_delete_vb( mesh.normals ); + if( mesh.tex_coords0 ) renderer_delete_vb( mesh.tex_coords0 ); + if( mesh.tex_coords1 ) renderer_delete_vb( mesh.tex_coords1 ); + if( mesh.colours ) renderer_delete_vb( mesh.colours ); + if( mesh.indices ) renderer_delete_ib( mesh.indices ); + glDeleteVertexArrays( 1, &mesh.vao ); } @@ -487,7 +504,7 @@ void renderer_draw_mesh( const Mesh & mesh, RenderState state ) { // TODO: missing a bunch of stuff here GLenum primitive = primitivetype_to_glenum( mesh.primitive_type ); - if( mesh.indexed ) { + if( mesh.indices != 0 ) { glDrawElements( primitive, mesh.num_vertices, GL_UNSIGNED_INT, 0 ); } else { diff --git a/renderer.h b/renderer.h @@ -12,7 +12,6 @@ typedef u32 VB; typedef u32 IB; typedef u32 UB; -typedef u32 VAO; typedef u32 Shader; typedef u32 Texture; typedef u32 TextureBuffer; @@ -80,9 +79,14 @@ enum PrimitiveType { struct Mesh { u32 num_vertices; - VAO vao; PrimitiveType primitive_type; - bool indexed; + u32 vao; + VB positions; + VB normals; + VB tex_coords0; + VB tex_coords1; + VB colours; + IB indices; }; struct MeshConfig { diff --git a/skybox.cc b/skybox.cc @@ -69,9 +69,6 @@ void skybox_init( Skybox * skybox ) { skybox->mesh = renderer_new_mesh( mesh_config ); skybox->vertex_uniforms = renderer_new_ub(); skybox->fragment_uniforms = renderer_new_ub(); - - renderer_delete_vb( vb ); - renderer_delete_ib( ib ); } struct VSData {