X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=476079474aae4201fcf752a056b3cd6d86b207fe;hb=74b2136d5b41b18e2eec698f1fd11b503aa1100a;hp=5608becf70fb90c4621c8d0556cd23a477bffbf0;hpb=0ff2713a286a77fa3e3538f5a76b0bf60525eb5b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index 5608bec..4760794 100644 --- a/model.h +++ b/model.h @@ -310,7 +310,10 @@ static void mdl_load_array_file_buffer( mdl_context *mdl, mdl_array *arr, if( l != 1 ) mdl_load_fatal_corrupt( mdl ); } else { - assert( stride >= arr->item_size ); + vg_warn( "Applying alignment fixup to array @%p [%u -> %u] x %u\n", + buffer, arr->item_size, stride, arr->item_count ); + if( stride < arr->item_size ) + vg_fatal_error( "not safe\n" ); for( u32 i=0; iitem_count; i++ ){ u64 l = fread( buffer+i*stride, arr->item_size, 1, mdl->file ); @@ -323,7 +326,10 @@ static void mdl_load_array_file_buffer( mdl_context *mdl, mdl_array *arr, static void mdl_load_array_file( mdl_context *mdl, mdl_array_ptr *ptr, mdl_array *arr, void *lin_alloc, u32 stride ) { - assert( stride >= arr->item_size ); + if( stride < arr->item_size ){ + vg_error( "Structure max: %u. Got: %u\n", stride, arr->item_size ); + vg_fatal_error( "not safe\n" ); + } if( arr->item_count ){ u32 size = stride*arr->item_count; @@ -602,8 +608,8 @@ static void async_mdl_load_glmesh( void *payload, u32 size ) job->indices, job->indice_count ); } -static void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh ) -{ +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" ); @@ -629,6 +635,16 @@ static void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh ) mdl_load_array_file_buffer( mdl, arr_indices, job->indices, sizeof(mdl_indice) ); + if( fixup_table ){ + for( u32 i=0; ivertex_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) * --------------------------------------------------------- @@ -663,7 +679,7 @@ static void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh ) /* 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 ); + mdl_async_load_glmesh( mdl, &mdl->mesh, NULL ); for( u32 i=0; itextures ); i ++ ){ vg_linear_clear( vg_mem.scratch );