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
|
#include "rendering.h"
#include <glad.h>
#include "utils.h"
bool wayc_image_init(texture_t* texture, image_type_e type,
image_format_e format, u32 width, u32 height) {
bool success = false;
glGenTextures(1, texture);
wayc_defer_cond(glDeleteTextures(1, texture), success, true);
glBindTexture(type, *texture);
switch (type) {
case IMAGE_TYPE_2D:
glTexStorage2D(type, 1, format, width, height);
break;
default:
return success;
}
glBindTexture(type, 0);
success = true;
return success;
}
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, const u8* data) {
glBindTexture(type, texture);
switch (type) {
case IMAGE_TYPE_2D:
glTexSubImage2D(type, 0, offset[0], offset[1], width, height, format,
data_type, data);
break;
default:
return false;
}
return true;
}
void wayc_image_use(texture_t texture, image_type_e type, u32 slot) {
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(type, texture);
}
void wayc_image_deinit(texture_t* texture) { glDeleteTextures(1, texture); }
bool wayc_sampler_init(sampler_t* sampler, sample_filter_e filter,
sample_wrap_e wrap) {
glGenSamplers(1, sampler);
if (*sampler == 0) return false;
glSamplerParameteri(*sampler, GL_TEXTURE_MIN_FILTER, filter);
glSamplerParameteri(*sampler, GL_TEXTURE_MAG_FILTER, filter);
glSamplerParameteri(*sampler, GL_TEXTURE_WRAP_S, wrap);
glSamplerParameteri(*sampler, GL_TEXTURE_WRAP_T, wrap);
return true;
}
void wayc_sampler_use(sampler_t sampler, u32 slot) {
glActiveTexture(GL_TEXTURE0 + slot);
glBindSampler(slot, sampler);
}
void wayc_sampler_deinit(sampler_t* sampler) { glDeleteSamplers(1, sampler); }
bool wayc_atlas_init(atlas_t* atlas, image_format_e format, u32 width,
u32 height) {
return wayc_image_init(atlas, IMAGE_TYPE_2D, format, width, height);
}
void wayc_atlas_deinit(atlas_t* atlas) { wayc_image_deinit(atlas); }
|