X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=6ff0a857eaf9d036b1fa050511844ddeb0790fe3;hb=ca35eceae3abfcfb9ba266d6ea8e664bc06b0a3e;hp=664950fc0191b7bf6f9e7f95e3ce6d4cffd3bb25;hpb=02e5027d274fc66fecca0572d0998e2c562da7a7;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index 664950f..6ff0a85 100644 --- a/model.h +++ b/model.h @@ -1,13 +1,13 @@ /* - * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved */ #ifndef MODEL_H #define MODEL_H -#include "common.h" +#include "skaterift.h" -#define MDL_VERSION_NR 100 +#define MDL_VERSION_NR 101 enum mdl_shader { @@ -17,7 +17,8 @@ enum mdl_shader k_shader_standard_vertex_blend = 3, k_shader_water = 4, k_shader_invisible = 5, - k_shader_boundary = 6 + k_shader_boundary = 6, + k_shader_fxglow = 7 }; enum mdl_surface_prop @@ -36,7 +37,8 @@ enum material_flag k_material_flag_grow_grass = 0x00000004, k_material_flag_grindable = 0x00000008, k_material_flag_invisible = 0x00000010, - k_material_flag_boundary = 0x00000020 + k_material_flag_boundary = 0x00000020, + k_material_flag_preview_visibile = 0x00000040 }; #pragma pack(push,1) @@ -71,6 +73,14 @@ typedef struct mdl_texture mdl_texture; typedef struct mdl_array mdl_array; typedef struct mdl_header mdl_header; +typedef struct glmesh glmesh; +struct glmesh +{ + GLuint vao, vbo, ebo; + u32 indice_count; + u32 loaded; +}; + struct mdl_transform { v3f co, s; @@ -221,13 +231,11 @@ struct mdl_header mdl_array index; }; -struct mdl_context -{ +struct mdl_context{ FILE *file; mdl_header info; - struct mdl_array_ptr - { + struct mdl_array_ptr{ void *data; u32 count, stride; } @@ -249,11 +257,10 @@ struct mdl_context /* mesh buffers */ verts, indices; - u32 pack_base_offset; - - /* pack data */ - //pack; + + /* runtime */ + glmesh mesh; }; @@ -407,7 +414,7 @@ VG_STATIC void mdl_open( mdl_context *mdl, const char *path, void *lin_alloc ) if( l != 1 ) mdl_load_fatal_corrupt( mdl ); - if( mdl->info.version != MDL_VERSION_NR ){ + if( mdl->info.version < MDL_VERSION_NR ){ vg_warn( "For model: %s\n", path ); vg_warn( " version: %u (current: %u)\n", mdl->info.version, MDL_VERSION_NR ); @@ -444,22 +451,29 @@ VG_STATIC void mdl_transform_m4x3( mdl_transform *transform, m4x3f mtx ) VG_STATIC const char *mdl_pstr( mdl_context *mdl, u32 pstr ) { - return mdl_arritm( &mdl->strings, pstr ); + return ((char *)mdl_arritm( &mdl->strings, pstr )) + 4; +} + + +VG_STATIC int +mdl_pstreq( mdl_context *mdl, u32 pstr, const char *str, u32 djb2 ) +{ + u32 hash = *((u32 *)mdl_arritm( &mdl->strings, pstr )); + if( hash == djb2 ){ + if( !strcmp( str, mdl_pstr( mdl, pstr ))) return 1; + else return 0; + } + else return 0; } +#define MDL_CONST_PSTREQ( MDL, Q, CONSTSTR )\ + mdl_pstreq( MDL, Q, CONSTSTR, vg_strdjb2( CONSTSTR ) ) + /* * Simple mesh interface for OpenGL * ---------------------------------------------------------------------------- */ -typedef struct glmesh glmesh; -struct glmesh -{ - GLuint vao, vbo, ebo; - u32 indice_count; - u32 loaded; -}; - VG_STATIC void mesh_upload( glmesh *mesh, mdl_vert *verts, u32 vert_count, u32 *indices, u32 indice_count ) @@ -571,11 +585,11 @@ struct payload_glmesh_load{ VG_STATIC void async_mdl_load_glmesh( void *payload, u32 size ) { struct payload_glmesh_load *job = payload; - mesh_upload( job->mesh, job->verts, job->vertex_count, job->indices, job->indice_count ); } +/* TODO: Find out if this needs deprecating in favour of the new full loader */ VG_STATIC void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh ) { mdl_array *arr_vertices = mdl_find_array( mdl, "mdl_vert" ); @@ -632,5 +646,21 @@ VG_STATIC void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh ) vg_fatal_error( "no vertex/indice data\n" ); } } + +/* uploads the glmesh, and textures. everything is saved into the mdl_context */ +VG_STATIC void mdl_async_full_load_std( mdl_context *mdl ){ + mdl_async_load_glmesh( mdl, &mdl->mesh ); + + for( u32 i=0; itextures ); 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 ); + } +} #endif