+VG_STATIC void mesh_free( glmesh *mesh )
+{
+ if( mesh->loaded )
+ {
+ glDeleteVertexArrays( 1, &mesh->vao );
+ glDeleteBuffers( 1, &mesh->ebo );
+ glDeleteBuffers( 1, &mesh->vbo );
+ mesh->loaded = 0;
+ }
+}
+
+VG_STATIC void mdl_load_fatal_corrupt( mdl_context *mdl )
+{
+ fclose( mdl->file );
+ vg_file_print_invalid( mdl->file );
+ vg_fatal_exit_loop( "Corrupt model" );
+}
+
+/*
+ * Model implementation
+ *
+ * TODO.
+ *
+ * you have two api options for loading a model, first, the easy way:
+ * mdl_load ...
+ * will put the entire model straight into the linear_alloc
+ *
+ * or, to target different allocators:
+ *
+ * mdl_open
+ * mdl_load_metadata
+ * mdl_load_vertex_data
+ * mdl_load_indice_data
+ * mdl_close
+ *
+ * these should ideally be called in quick succession to limit stalls.
+ */
+
+/*
+ * if calling mdl_open, and the file does not exist, the game will fatal quit
+ */
+VG_STATIC void mdl_open( mdl_context *mdl, const char *path )
+{
+ memset( mdl, 0, sizeof( mdl_context ) );
+ mdl->file = fopen( path, "rb" );
+
+ if( !mdl->file )
+ {
+ vg_error( "mdl_open('%s'): %s\n", path, strerror(errno) );
+ vg_fatal_exit_loop( "see above for details" );
+ }
+
+ u64 l = fread( &mdl->info, sizeof(mdl_file_header), 1, mdl->file );
+ if( l != 1 )
+ mdl_load_fatal_corrupt( mdl );
+}
+