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