+static void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh,
+ u32 *fixup_table ){
+ mdl_array *arr_vertices = mdl_find_array( mdl, "mdl_vert" );
+ mdl_array *arr_indices = mdl_find_array( mdl, "mdl_indice" );
+
+ if( arr_vertices && arr_indices ){
+ u32 size_verts = vg_align8(sizeof(mdl_vert)*arr_vertices->item_count),
+ size_indices = vg_align8(sizeof(mdl_indice)*arr_indices->item_count),
+ size_hdr = vg_align8(sizeof(struct payload_glmesh_load)),
+ total = size_hdr + size_verts + size_indices;
+
+ vg_async_item *call = vg_async_alloc( total );
+ struct payload_glmesh_load *job = call->payload;
+
+ u8 *payload = call->payload;
+
+ job->mesh = mesh;
+ job->verts = (void*)(payload + size_hdr);
+ job->indices = (void*)(payload + size_hdr + size_verts);
+ job->vertex_count = arr_vertices->item_count;
+ job->indice_count = arr_indices->item_count;
+
+ mdl_load_array_file_buffer( mdl, arr_vertices,
+ job->verts, sizeof(mdl_vert) );
+ mdl_load_array_file_buffer( mdl, arr_indices, job->indices,
+ sizeof(mdl_indice) );
+
+ if( fixup_table ){
+ for( u32 i=0; i<job->vertex_count; i ++ ){
+ mdl_vert *vert = &job->verts[i];
+
+ for( u32 j=0; j<4; j++ ){
+ vert->groups[j] = fixup_table[vert->groups[j]];
+ }
+ }
+ }
+
+ /*
+ * Unpack the indices (if there are meshes)
+ * ---------------------------------------------------------
+ */
+
+ if( mdl_arrcount( &mdl->submeshs ) ){
+ mdl_submesh *sm = mdl_arritm( &mdl->submeshs, 0 );
+ u32 offset = sm->vertex_count;
+
+ for( u32 i=1; i<mdl_arrcount( &mdl->submeshs ); i++ ){
+ mdl_submesh *sm = mdl_arritm( &mdl->submeshs, i );
+ u32 *indices = job->indices + sm->indice_start;
+
+ for( u32 j=0; j<sm->indice_count; j++ )
+ indices[j] += offset;
+
+ offset += sm->vertex_count;
+ }
+ }
+
+ /*
+ * Dispatch
+ * -------------------------
+ */
+
+ vg_async_dispatch( call, async_mdl_load_glmesh );
+ }
+ else{
+ vg_fatal_error( "no vertex/indice data\n" );
+ }
+}
+
+/* uploads the glmesh, and textures. everything is saved into the mdl_context */
+static void mdl_async_full_load_std( mdl_context *mdl ){
+ mdl_async_load_glmesh( mdl, &mdl->mesh, NULL );
+
+ for( u32 i=0; i<mdl_arrcount( &mdl->textures ); i ++ ){
+ vg_linear_clear( vg_mem.scratch );
+ mdl_texture *tex = mdl_arritm( &mdl->textures, i );
+
+ void *data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size );
+ mdl_fread_pack_file( mdl, &tex->file, data );
+
+ vg_tex2d_load_qoi_async( data, tex->file.pack_size,
+ VG_TEX2D_CLAMP|VG_TEX2D_NEAREST, &tex->glname );
+ }
+}
+