X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=02e85bcd835b59c3e2639dbf0076605271da9ce3;hb=b9dedb4dd2a1e94ae76a3986716ee3c57e568213;hp=59b75beeb797e89aab8356eeedc5002cc77fa079;hpb=c2d67378dd5c82de50b8fbbbe222ec6be2da4eee;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index 59b75be..02e85bc 100644 --- a/model.h +++ b/model.h @@ -21,6 +21,24 @@ typedef struct mdl_keyframe mdl_keyframe; #define MDL_SUBMESH_MAX 8000 #define MDL_STRING_LENGTH_MAX 64 +enum classtype +{ + k_classtype_none = 0, + k_classtype_gate = 1, + k_classtype_block = 2, + k_classtype_spawn = 3, + k_classtype_water = 4, + k_classtype_car_path = 5, + k_classtype_instance = 6, + k_classtype_capsule = 7, + k_classtype_route_node = 8, + k_classtype_route = 9, + k_classtype_bone = 10, + k_classtype_skeleton = 11, + k_classtype_skin = 12 +}; + + #pragma pack(push,1) struct mdl_vert @@ -182,13 +200,15 @@ struct glmesh { GLuint vao, vbo, ebo; u32 indice_count; + u32 loaded; }; -__attribute__((warn_unused_result)) -static int mesh_upload( glmesh *mesh, - mdl_vert *verts, u32 vert_count, - u32 *indices, u32 indice_count ) +static void mesh_upload( glmesh *mesh, + mdl_vert *verts, u32 vert_count, + u32 *indices, u32 indice_count ) { + //assert( mesh->loaded == 0 ); + glGenVertexArrays( 1, &mesh->vao ); glGenBuffers( 1, &mesh->vbo ); glGenBuffers( 1, &mesh->ebo ); @@ -233,13 +253,10 @@ static int mesh_upload( glmesh *mesh, stride, (void *)offsetof(mdl_vert, groups) ); glEnableVertexAttribArray( 5 ); - if( VG_CHECK_GL_ERR() ) - { - return 0; - } + VG_CHECK_GL_ERR(); mesh->indice_count = indice_count; - return 1; + mesh->loaded = 1; } static void mesh_bind( glmesh *mesh ) @@ -260,9 +277,12 @@ static void mesh_draw( glmesh *mesh ) static void mesh_free( glmesh *mesh ) { - glDeleteVertexArrays( 1, &mesh->vao ); - glDeleteBuffers( 1, &mesh->ebo ); - glDeleteBuffers( 1, &mesh->vbo ); + if( mesh->loaded ) + { + glDeleteVertexArrays( 1, &mesh->vao ); + glDeleteBuffers( 1, &mesh->ebo ); + glDeleteBuffers( 1, &mesh->vbo ); + } } @@ -286,7 +306,7 @@ static mdl_header *mdl_load( const char *path ) if( size < sizeof(mdl_header) ) { - free( header ); + vg_free( header ); vg_error( "Invalid file '%s' (too small for header)\n", path ); return NULL; } @@ -296,7 +316,7 @@ static mdl_header *mdl_load( const char *path ) vg_error( "Invalid file '%s'" "(wrong .file_length, %ub != real file size %ub)\n", path, header->file_length, size ); - free( header ); + vg_free( header ); return NULL; } @@ -347,7 +367,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->count > ri->max_count ) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer exceeds the maximum (%u/%u)\n", path, ri->desc, ri->count, ri->max_count ); return NULL; @@ -355,7 +375,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->offset >= header->file_length ) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer offset is out of range\n", path, ri->desc ); return NULL; @@ -363,7 +383,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->offset + ri->size*ri->count > header->file_length ) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer size is out of range\n", path, ri->desc ); return NULL; @@ -378,7 +398,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->offset >= rj->offset && (ri->offset+ri->size*ri->count < rj->offset+rj->size*rj->count)) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer overlaps '%s'\n", path, ri->desc, rj->desc ); return NULL; @@ -470,15 +490,13 @@ static void mdl_node_transform( mdl_node *pnode, m4x3f transform ) v3_copy( pnode->co, transform[3] ); } -__attribute__((warn_unused_result)) -static int mdl_unpack_submesh( mdl_header *mdl, glmesh *mesh, mdl_submesh *sm ) +static void mdl_unpack_submesh( mdl_header *mdl, glmesh *mesh, mdl_submesh *sm ) { - return mesh_upload( mesh, mdl_submesh_vertices( mdl, sm ), sm->vertex_count, - mdl_submesh_indices( mdl, sm ), sm->indice_count ); + mesh_upload( mesh, mdl_submesh_vertices( mdl, sm ), sm->vertex_count, + mdl_submesh_indices( mdl, sm ), sm->indice_count ); } -__attribute__((warn_unused_result)) -static int mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh ) +static void mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh ) { u32 offset = mdl_submesh_from_id( mdl, 0 )->vertex_count; @@ -496,8 +514,8 @@ static int mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh ) mdl_vert *vertex_base = mdl_baseptr( mdl, mdl->vertex_offset ); u32 *indice_base = mdl_baseptr( mdl, mdl->indice_offset ); - return mesh_upload( mesh, vertex_base, mdl->vertex_count, - indice_base, mdl->indice_count ); + mesh_upload( mesh, vertex_base, mdl->vertex_count, + indice_base, mdl->indice_count ); } static void mdl_draw_submesh( mdl_submesh *sm )