-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhell_pack.h
More file actions
146 lines (121 loc) · 3.7 KB
/
Copy pathhell_pack.h
File metadata and controls
146 lines (121 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef __HELL_PACK_H__
#define __HELL_PACK_H__
#include "core_types.h"
#include "hp_error.h"
#include "hp_mesh.h"
#include "hp_material.h"
#include <span>
#include "range_utils.h"
constexpr u32 HELLPACK_VERSION = 1;
constexpr u64 HELLPACK_MAGIC =
( u64( 'H' ) ) |
( u64( 'E' ) << 8 ) |
( u64( 'L' ) << 16 ) |
( u64( 'L' ) << 24 ) |
( u64( 'P' ) << 32 ) |
( u64( 'A' ) << 40 ) |
( u64( 'C' ) << 48 ) |
( u64( 'K' ) << 56 );
constexpr char HELLPACK_MESH_DIR[] = "Mesh/";
// TODO: how to enforce these are dds ?
constexpr char HELLPACK_TEX_DIR[] = "Tex/";
enum hellpack_entry_t : u32
{
LEVEL = 0,
MESH,
TEXTURE,
COUNT
};
struct hellpack_data_ref
{
u64 offsetInBytes : 32;
u64 sizeInBytes : 32;
};
struct hellpack_file_header
{
u64 magic;
u64 fileSizeBytes;
u32 version;
u32 entriesCount; // TODO: enforce an explicit ordering on the entires, rn they're as in the struct
hellpack_entry_t type;
};
struct hellpack_level
{
typed_view<world_node> nodes;
typed_view<material_desc> materials;
};
struct float3;
using index_t = u8;
struct hellpack_mesh_asset
{
typed_view<packed_vtx> vertices;
typed_view<index_t> triangles;
typed_view<meshlet> meshlets;
float3 aabbMin;
float3 aabbMax;
};
struct hellpack_texture_asset
{
byte_view ddsData;
};
template<typename HPK_T>
HPK_T HpkReadBinaryBlob( std::span<const u8> blob )
{
HP_ASSERT( std::size( blob ) >= sizeof( hellpack_file_header ) );
const u8* base = std::data( blob );
const u64 sizeInBytes = std::size( blob );
const hellpack_file_header& h = ( const hellpack_file_header& ) ( *base );
HP_ASSERT( HELLPACK_MAGIC == h.magic );
HP_ASSERT( HELLPACK_VERSION == h.version );
HP_ASSERT( h.fileSizeBytes == sizeInBytes );
HP_ASSERT( h.entriesCount > 0 );
u64 entryTableOffsetInBytes = AlignUp( sizeof( h ), alignof( hellpack_data_ref ) );
std::span<const hellpack_data_ref> entryTable = { ( const hellpack_data_ref* ) ( base + entryTableOffsetInBytes ), h.entriesCount };
if constexpr( std::is_same_v<HPK_T, hellpack_level> )
{
HP_ASSERT( hellpack_entry_t::LEVEL == h.type );
HP_ASSERT( 2 == h.entriesCount );
return hellpack_level{
.nodes = {
( const world_node* ) ( base + entryTable[ 0 ].offsetInBytes ),
( u32 ) ( entryTable[ 0 ].sizeInBytes / sizeof( world_node ) )
},
.materials = {
( const material_desc* ) ( base + entryTable[ 1 ].offsetInBytes ),
( u32 ) ( entryTable[ 1 ].sizeInBytes / sizeof( material_desc ) )
}
};
}
else if constexpr( std::is_same_v<HPK_T, hellpack_mesh_asset> )
{
HP_ASSERT( hellpack_entry_t::MESH == h.type );
HP_ASSERT( 4 == h.entriesCount );
return hellpack_mesh_asset{
.vertices = {
( const packed_vtx* ) ( base + entryTable[ 0 ].offsetInBytes ),
( u32 ) ( entryTable[ 0 ].sizeInBytes / sizeof( packed_vtx ) )
},
.triangles = {
( const u8* ) ( base + entryTable[ 1 ].offsetInBytes ),
( u32 ) entryTable[ 1 ].sizeInBytes
},
.meshlets = {
( const meshlet* ) ( base + entryTable[ 2 ].offsetInBytes ),
( u32 ) ( entryTable[ 2 ].sizeInBytes / sizeof( meshlet ) )
},
.aabbMin = *( const float3* ) ( base + entryTable[ 3 ].offsetInBytes ),
.aabbMax = *( const float3* ) ( base + entryTable[ 3 ].offsetInBytes + sizeof( float3 ) )
};
}
else if constexpr( std::is_same_v<HPK_T, hellpack_texture_asset> )
{
static_assert( false, "hellpack_texture_asset is currently unsupported use dds directly" );
HP_ASSERT( hellpack_entry_t::TEXTURE == h.type );
HP_ASSERT( 1 == h.entriesCount );
return hellpack_texture_asset{
.ddsData = { base + entryTable[ 0 ].offsetInBytes, ( u32 ) entryTable[ 0 ].sizeInBytes }
};
}
else static_assert( false, "Unsupported HPK_T" );
}
#endif // !__HELL_PACK_H__