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
|
#pragma once
#include <cglm/cglm.h>
#include "cglm/types.h"
#include "glad.h"
#include "utils.h"
enum image_type_e {
IMAGE_TYPE_2D = GL_TEXTURE_2D,
};
enum image_format_e {
IMAGE_FORMAT_RGBA = GL_RGBA,
IMAGE_FORMAT_RED = GL_RED,
};
enum image_data_type_e {
IMAGE_DATA_TYPE_UNSIGNED_BYTE = GL_UNSIGNED_BYTE,
};
enum {
IMAGE_FORMAT_RGBA_ALIGNMENT = 4,
IMAGE_FORMAT_RED_ALIGNMENT = 1,
};
typedef u32 texture_t;
bool wayc_image_init(texture_t* texture, image_type_e type,
image_format_e format, u32 width, u32 height);
bool wayc_image_upload(texture_t texture, ivec2 offset, u32 width, u32 height,
image_type_e type, image_format_e format,
image_data_type_e data_type, i32 alignment,
const u8* data);
void wayc_image_use(texture_t texture, u32 slot);
void wayc_image_deinit(texture_t* texture);
enum sample_filter_e {
SAMPLE_FILTER_NEAREST = GL_NEAREST,
SAMPLE_FILTER_LINEAR = GL_LINEAR,
};
enum sample_wrap_e {
SAMPLE_WRAP_CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
SAMPLE_WRAP_REPEAT = GL_REPEAT,
};
typedef u32 sampler_t;
bool wayc_sampler_init(sampler_t* sampler, sample_filter_e filter,
sample_wrap_e wrap);
void wayc_sampler_use(sampler_t sampler, u32 slot);
void wayc_sampler_deinit(sampler_t* sampler);
struct atlas_s {
texture_t texture;
sampler_t sampler;
u32 width, height;
image_format_e format;
};
bool wayc_atlas_init(atlas_s* atlas, image_format_e format, u32 width,
u32 height);
void wayc_atlas_use(atlas_s* atlas, u32 slot);
bool wayc_atlas_set(atlas_s* atlas, image_data_type_e data_type, ivec2 offset,
u32 width, u32 height, i32 alignment, const u8* data);
void wayc_atlas_deinit(atlas_s* atlas);
struct atlas_packer_s {
struct atlas_s* atlas;
u32 row_height;
ivec2 cursor;
};
#define WAYC_ATLAS_PACKER_INIT(atlas) \
atlas_packer_s { atlas, 0, {0, 0} }
bool wayc_atlas_packer_allocate(struct atlas_packer_s* packer, u32 width,
u32 height, ivec2 out);
|