06f36bb75f65cda2110930eea995daefae561067
[carveJwlIkooP6JGAAIwe30JlM.git] / scene.h
1 #pragma once
2 #include "vg/vg_bvh.h"
3 #include "common.h"
4 #include "model.h"
5
6 typedef struct scene_context scene_context;
7 typedef struct scene_vert scene_vert;
8
9 #pragma pack(push,1)
10
11 /* 32 byte vertexs, we don't care about the normals too much,
12 * maybe possible to bring down uv to i16s too */
13 struct scene_vert
14 {
15 v3f co; /* 3*32 */
16 v2f uv; /* 2*32 */
17 i8 norm[4]; /* 4*8 */
18 u16 flags; /* only for the cpu. its junk on the gpu */
19 u16 unused[3];
20 };
21
22 #pragma pack(pop)
23
24 /*
25 * 1. this should probably be a CONTEXT based approach unlike this mess.
26 * take a bit of the mdl_context ideas and redo this header. its messed up
27 * pretty bad right now.
28 */
29
30 struct scene_context
31 {
32 scene_vert *arrvertices;
33 u32 *arrindices;
34
35 u32 vertex_count, indice_count,
36 max_vertices, max_indices;
37
38 boxf bbx;
39 mdl_submesh submesh;
40 };
41
42 extern bh_system bh_system_scene;
43 bh_tree *scene_bh_create( void *lin_alloc, scene_context *s );
44 int scene_raycast( scene_context *s, bh_tree *bh,
45 v3f co, v3f dir, ray_hit *hit, u16 ignore );
46 vg_async_item *scene_alloc_async( scene_context *scene, glmesh *mesh,
47 u32 max_vertices, u32 max_indices );
48 void scene_copy_slice( scene_context *ctx, mdl_submesh *sm );
49 void scene_push_vert( scene_context *ctx, scene_vert *v );
50 void scene_vert_pack_norm( scene_vert *vert, v3f norm, f32 blend );
51 void scene_push_tri( scene_context *ctx, u32 tri[3] );
52 void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl,
53 mdl_submesh *sm, m4x3f transform );
54 void scene_set_vertex_flags( scene_context *ctx,
55 u32 start, u32 count, u16 flags );
56 void scene_supply_buffer( scene_context *ctx, void *buffer );
57 void scene_init( scene_context *ctx, u32 max_vertices, u32 max_indices );
58 u32 scene_mem_required( scene_context *ctx );
59 void async_scene_upload( void *payload, u32 size );
60 void scene_upload_async( scene_context *ctx, glmesh *mesh );