X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=scene.h;h=d8fac1ad524a05672feabee916237ddfbeac8acf;hb=1fd91b77f23ce1593037e01b9abb62859545b400;hp=b54587aadf1a1064019bedf7882fd0140eb6b4f7;hpb=ab34e6bf232cb0c890d8b02c5d21449c20b938e6;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/scene.h b/scene.h index b54587a..d8fac1a 100644 --- a/scene.h +++ b/scene.h @@ -41,7 +41,7 @@ struct scene_context mdl_submesh submesh; }; -VG_STATIC u32 scene_mem_required( scene_context *ctx ) +static u32 scene_mem_required( scene_context *ctx ) { u32 vertex_length = vg_align8(ctx->max_vertices * sizeof(scene_vert)), index_length = vg_align8(ctx->max_indices * sizeof(u32)); @@ -49,7 +49,7 @@ VG_STATIC u32 scene_mem_required( scene_context *ctx ) return vertex_length + index_length; } -VG_STATIC +static void scene_init( scene_context *ctx, u32 max_vertices, u32 max_indices ) { ctx->vertex_count = 0; @@ -73,8 +73,7 @@ void scene_supply_buffer( scene_context *ctx, void *buffer ) ctx->arrindices = (u32*)(((u8*)buffer) + vertex_length); } -VG_STATIC void scene_vert_pack_norm( scene_vert *vert, v3f norm ) -{ +static void scene_vert_pack_norm( scene_vert *vert, v3f norm, f32 blend ){ v3f n; v3_muls( norm, 127.0f, n ); v3_minv( n, (v3f){ 127.0f, 127.0f, 127.0f }, n ); @@ -82,13 +81,13 @@ VG_STATIC void scene_vert_pack_norm( scene_vert *vert, v3f norm ) vert->norm[0] = n[0]; vert->norm[1] = n[1]; vert->norm[2] = n[2]; - vert->norm[3] = 0; /* free byte :D */ + vert->norm[3] = blend * 127.0f; } /* * Append a model into the scene with a given transform */ -VG_STATIC void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl, +static void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl, mdl_submesh *sm, m4x3f transform ) { if( ctx->vertex_count + sm->vertex_count > ctx->max_vertices ){ @@ -129,7 +128,7 @@ VG_STATIC void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl, v3f normal; m3x3_mulv( normal_matrix, src->norm, normal ); - scene_vert_pack_norm( pvert, normal ); + scene_vert_pack_norm( pvert, normal, src->colour[0]*(1.0f/255.0f) ); v2_copy( src->uv, pvert->uv ); } @@ -166,7 +165,7 @@ VG_STATIC void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl, /* * One by one adders for simplified access (mostly procedural stuff) */ -VG_STATIC void scene_push_tri( scene_context *ctx, u32 tri[3] ) +static void scene_push_tri( scene_context *ctx, u32 tri[3] ) { if( ctx->indice_count + 3 > ctx->max_indices ) vg_fatal_error( "Scene indice buffer overflow (%u exceeds %u)\n", @@ -181,7 +180,7 @@ VG_STATIC void scene_push_tri( scene_context *ctx, u32 tri[3] ) ctx->indice_count += 3; } -VG_STATIC void scene_push_vert( scene_context *ctx, scene_vert *v ) +static void scene_push_vert( scene_context *ctx, scene_vert *v ) { if( ctx->vertex_count + 1 > ctx->max_vertices ) vg_fatal_error( "Scene vertex buffer overflow (%u exceeds %u)\n", @@ -193,7 +192,7 @@ VG_STATIC void scene_push_vert( scene_context *ctx, scene_vert *v ) ctx->vertex_count ++; } -VG_STATIC void scene_copy_slice( scene_context *ctx, mdl_submesh *sm ) +static void scene_copy_slice( scene_context *ctx, mdl_submesh *sm ) { sm->indice_start = ctx->submesh.indice_start; sm->indice_count = ctx->indice_count - sm->indice_start; @@ -205,7 +204,7 @@ VG_STATIC void scene_copy_slice( scene_context *ctx, mdl_submesh *sm ) ctx->submesh.vertex_start = ctx->vertex_count; } -VG_STATIC void scene_set_vertex_flags( scene_context *ctx, +static void scene_set_vertex_flags( scene_context *ctx, u32 start, u32 count, u16 flags ){ for( u32 i=0; iarrvertices[ start + i ].flags = flags; @@ -216,7 +215,7 @@ struct scene_upload_info{ glmesh *mesh; }; -VG_STATIC void async_scene_upload( void *payload, u32 size ) +static void async_scene_upload( void *payload, u32 size ) { struct scene_upload_info *info = payload; @@ -265,7 +264,7 @@ VG_STATIC void async_scene_upload( void *payload, u32 size ) vg_info( " verts:%u\n", ctx->vertex_count ); } -VG_STATIC void scene_upload_async( scene_context *ctx, glmesh *mesh ) +static void scene_upload_async( scene_context *ctx, glmesh *mesh ) { vg_async_item *call = vg_async_alloc( sizeof(struct scene_upload_info) ); @@ -276,7 +275,7 @@ VG_STATIC void scene_upload_async( scene_context *ctx, glmesh *mesh ) vg_async_dispatch( call, async_scene_upload ); } -VG_STATIC +static vg_async_item *scene_alloc_async( scene_context *scene, glmesh *mesh, u32 max_vertices, u32 max_indices ) { @@ -302,7 +301,7 @@ vg_async_item *scene_alloc_async( scene_context *scene, glmesh *mesh, * BVH implementation */ -VG_STATIC void scene_bh_expand_bound( void *user, boxf bound, u32 item_index ) +static void scene_bh_expand_bound( void *user, boxf bound, u32 item_index ) { scene_context *s = user; scene_vert *pa = &s->arrvertices[ s->arrindices[item_index*3+0] ], @@ -314,7 +313,7 @@ VG_STATIC void scene_bh_expand_bound( void *user, boxf bound, u32 item_index ) box_addpt( bound, pc->co ); } -VG_STATIC float scene_bh_centroid( void *user, u32 item_index, int axis ) +static float scene_bh_centroid( void *user, u32 item_index, int axis ) { scene_context *s = user; scene_vert *pa = &s->arrvertices[ s->arrindices[item_index*3+0] ], @@ -337,7 +336,7 @@ VG_STATIC float scene_bh_centroid( void *user, u32 item_index, int axis ) #endif } -VG_STATIC void scene_bh_swap( void *user, u32 ia, u32 ib ) +static void scene_bh_swap( void *user, u32 ia, u32 ib ) { scene_context *s = user; @@ -358,7 +357,7 @@ VG_STATIC void scene_bh_swap( void *user, u32 ia, u32 ib ) tj[2] = temp[2]; } -VG_STATIC void scene_bh_debug( void *user, u32 item_index ) +static void scene_bh_debug( void *user, u32 item_index ) { scene_context *s = user; u32 idx = item_index*3; @@ -371,7 +370,7 @@ VG_STATIC void scene_bh_debug( void *user, u32 item_index ) vg_line( pc->co, pa->co, 0xff0000ff ); } -VG_STATIC void scene_bh_closest( void *user, u32 index, v3f point, v3f closest ) +static void scene_bh_closest( void *user, u32 index, v3f point, v3f closest ) { scene_context *s = user; @@ -383,19 +382,20 @@ VG_STATIC void scene_bh_closest( void *user, u32 index, v3f point, v3f closest ) closest_on_triangle_1( point, positions, closest ); } -VG_STATIC bh_system bh_system_scene = +static bh_system bh_system_scene = { .expand_bound = scene_bh_expand_bound, .item_centroid = scene_bh_centroid, .item_closest = scene_bh_closest, .item_swap = scene_bh_swap, .item_debug = scene_bh_debug, + .system_type = 0x1 }; /* * An extra step is added onto the end to calculate the hit normal */ -VG_STATIC int scene_raycast( scene_context *s, bh_tree *bh, +static int scene_raycast( scene_context *s, bh_tree *bh, v3f co, v3f dir, ray_hit *hit, u16 ignore ) { hit->tri = NULL; @@ -414,7 +414,7 @@ VG_STATIC int scene_raycast( scene_context *s, bh_tree *bh, v3_copy( s->arrvertices[tri[i]].co, vs[i] ); f32 t; - if( ray_tri( vs, co, dir, &t ) ){ + if( ray_tri( vs, co, dir, &t, 0 ) ){ if( t < hit->dist ){ hit->dist = t; hit->tri = tri; @@ -439,7 +439,7 @@ VG_STATIC int scene_raycast( scene_context *s, bh_tree *bh, return hit->tri?1:0; } -VG_STATIC bh_tree *scene_bh_create( void *lin_alloc, scene_context *s ) +static bh_tree *scene_bh_create( void *lin_alloc, scene_context *s ) { u32 triangle_count = s->indice_count / 3; return bh_create( lin_alloc, &bh_system_scene, s, triangle_count, 2 );