-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cpp
More file actions
55 lines (45 loc) · 1.62 KB
/
texture.cpp
File metadata and controls
55 lines (45 loc) · 1.62 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
#include <gl_layer/private/context.h>
namespace gl_layer {
void Context::glGenTextures(GLsizei count, GLuint* handles) {
for (GLsizei i = 0; i < count; ++i) {
textures.emplace(handles[i], Texture {
handles[i],
NO_TEXTURE_TARGET
});
}
}
void Context::glCreateTextures(GLenum target, GLsizei count, GLuint* handles) {
for (GLsizei i = 0; i < count; ++i) {
textures.emplace(handles[i], Texture {
handles[i],
static_cast<GLTextureTarget>(target)
});
}
}
void Context::glBindTexture(GLenum target, GLuint texture_handle) {
if (texture_handle == 0) {
// TODO: Discourage binding zero handle? (Suggest 1x1 texture to mark "invalid" instead).
return;
}
auto it = textures.find(texture_handle);
if (it == textures.end()) {
output_fmt("glBindTexture(target = %s, texture = %u): Invalid texture handle.", enum_str(target), texture_handle);
return;
}
Texture& texture = it->second;
// Target not set yet, this is the first time this texture is bound.
if (texture.target == NO_TEXTURE_TARGET) {
texture.target = static_cast<GLTextureTarget>(target);
}
if (target != texture.target) {
output_fmt("glBindTexture(target = %s, texture = %u): Invalid texture target (texture is already %s).", enum_str(target), texture_handle, enum_str(texture.target));
return;
}
bound_textures[texture.target] = texture_handle;
}
void Context::glDeleteTextures(GLsizei count, GLuint* handles) {
for (GLsizei i = 0; i < count; ++i) {
textures.erase(handles[i]);
}
}
}