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
|
#pragma once
#include <cglm/cglm.h>
#include "cglm/types.h"
#include "glad.h"
#include "utils.h"
struct quad_s {
vec2 vertices[WAYC_QUAD_NVERTS];
u32 indices[WAYC_QUAD_NINDICES];
};
static inline void wayc_quad_init(quad_s* quad, f32 left, f32 top, f32 right,
f32 bottom) {
wayc_notnull(quad);
/*
0 ---- 1
| |
| |
3 ---- 2
*/
// Vertices (CCW order)
WAYC_X(quad->vertices[0]) = left;
WAYC_Y(quad->vertices[0]) = top;
WAYC_X(quad->vertices[1]) = right;
WAYC_Y(quad->vertices[1]) = top;
WAYC_X(quad->vertices[2]) = right;
WAYC_Y(quad->vertices[2]) = bottom;
WAYC_X(quad->vertices[3]) = left;
WAYC_Y(quad->vertices[3]) = bottom;
/*
Triangles (CCW):
0 1 2
0 2 3
*/
quad->indices[0] = 0;
quad->indices[1] = 1;
quad->indices[2] = 2;
quad->indices[3] = 0;
quad->indices[4] = 2;
quad->indices[5] = 3;
}
// TODO: review all structs and use types
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);
enum buffer_type_e {
BUFFER_TYPE_VERTEX = GL_ARRAY_BUFFER,
BUFFER_TYPE_INDEX = GL_ELEMENT_ARRAY_BUFFER,
};
typedef u32 buffer_t;
bool wayc_buffer_init(buffer_t* buffer, usize size);
bool wayc_buffer_set(buffer_t buffer, usize offset, usize size, const u8* data);
void wayc_buffer_use(buffer_t buffer, buffer_type_e type);
void wayc_buffer_deinit(buffer_t* buffer);
|