-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.c
49 lines (43 loc) · 1.02 KB
/
buffer.c
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
#include <stdio.h>
#include <string.h>
#include <glisy/gl.h>
#include <glisy/buffer.h>
void
glisy_buffer_init(glisy_buffer *buffer, GLuint target) {
if (!buffer) return;
if (target == 0) target = GL_ARRAY_BUFFER;
buffer->handle = 0;
buffer->target = target;
}
void
glisy_buffer_bind(glisy_buffer *buffer) {
if (!buffer) return;
glGenBuffers(1, &buffer->handle);
glBindBuffer(buffer->target, buffer->handle);
}
void
glisy_buffer_unbind(glisy_buffer *buffer) {
if (!buffer) return;
glBindBuffer(buffer->target, 0);
}
void
glisy_buffer_dispose(glisy_buffer *buffer) {
if (!buffer) return;
glDeleteBuffers(1, &buffer->handle);
buffer->handle = 0;
}
void
glisy_buffer_update(glisy_buffer *buffer, GLuint usage) {
if (!buffer) return;
glBufferData(buffer->target,
buffer->size,
buffer->data,
usage);
}
void
glisy_buffer_source(glisy_buffer *buffer, GLsizei size, GLvoid *data) {
if (!buffer) return;
if (!data) return;
buffer->size = size;
buffer->data = data;
}