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
|
/* Asset Management */
#pragma once
#include <gfx/core.h>
#include <stddef.h>
typedef struct Gfx Gfx;
typedef struct Model Model;
typedef struct ShaderProgram ShaderProgram;
typedef struct Texture Texture;
/// Describes where the asset comes from.
typedef enum AssetOrigin {
AssetFromMemory,
AssetFromFile,
} AssetOrigin;
/// Describes a texture's colour space.
typedef enum TextureColourSpace {
sRGB, // The most likely default.
LinearColourSpace,
} TextureColourSpace;
/// Describes a command to load a texture.
typedef struct LoadTextureCmd {
AssetOrigin origin;
enum { LoadTexture, LoadCubemap } type;
TextureColourSpace colour_space;
TextureFiltering filtering;
TextureWrapping wrap;
bool mipmaps;
union {
// A single texture.
struct {
union {
struct {
mstring filepath;
};
struct {
const void* data;
size_t size_bytes;
};
};
} texture;
// Cubemap texture.
struct {
union {
struct {
mstring filepath_pos_x;
mstring filepath_neg_x;
mstring filepath_pos_y;
mstring filepath_neg_y;
mstring filepath_pos_z;
mstring filepath_neg_z;
} filepaths;
struct {
const void* data_pos_x;
const void* data_neg_x;
const void* data_pos_y;
const void* data_neg_y;
const void* data_pos_z;
const void* data_neg_z;
} buffers;
};
} cubemap;
} data;
} LoadTextureCmd;
/// Describes a command to load a model.
///
/// |shader| is an optional shader program assigned to the loaded model objects.
/// If no shader is given, a Cook-Torrance shader based on the object's
/// characteristics (presence of normals, tangents, etc) is assigned.
typedef struct LoadModelCmd {
AssetOrigin origin;
union {
struct {
mstring filepath;
};
struct {
const void* data;
size_t size_bytes;
};
};
ShaderProgram* shader;
} LoadModelCmd;
/// Load a model.
///
/// For animated models, this function returns a (shallow) clone of the model
/// that is safe to mutate. For static models, this returns the original model
/// in the cache.
///
/// Currently only supports the GLTF format.
Model* gfx_load_model(Gfx*, const LoadModelCmd*);
/// Load a texture.
const Texture* gfx_load_texture(Gfx*, const LoadTextureCmd*);
|