This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vao_leak0.c
94 lines (75 loc) · 2.47 KB
/
vao_leak0.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
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
#define GL_GLEXT_PROTOTYPES 1
#include <GL/glcorearb.h>
#include <GLFW/glfw3.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
GLFWwindow* context;
int leak = 0;
leak = (argc > 1) && (strcmp(argv[1], "leak") == 0);
if (!glfwInit()) {
fprintf(stderr, "Unable to initialize\n");
return -1;
}
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
context = glfwCreateWindow(320, 240, "Main", NULL, NULL);
if (!context) {
fprintf(stderr, "Unable to create context\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(context);
{
GLuint aid;
GLuint vao;
fprintf(stderr, "Vendor: %s\n", glGetString(GL_VENDOR));
fprintf(stderr, "Version: %s\n", glGetString(GL_VERSION));
for (int count = 0; count < 10; ++count) {
fprintf(stderr, "Creating 100mb VBO\n");
glGenBuffers(1, &aid);
assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ARRAY_BUFFER, aid);
assert(glGetError() == GL_NO_ERROR);
glBufferData(GL_ARRAY_BUFFER, 100000000L, NULL, GL_STATIC_DRAW);
assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ARRAY_BUFFER, 0);
assert(glGetError() == GL_NO_ERROR);
fprintf(stderr, "Created VBO %d\n", aid);
fprintf(stderr, "Creating VAO\n");
glGenVertexArrays(1, &vao);
assert(glGetError() == GL_NO_ERROR);
glBindVertexArray(vao);
assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ARRAY_BUFFER, aid);
assert(glGetError() == GL_NO_ERROR);
glEnableVertexAttribArray(0);
assert(glGetError() == GL_NO_ERROR);
glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, 0, 0, (void*) 0L);
assert(glGetError() == GL_NO_ERROR);
glBindVertexArray(0);
assert(glGetError() == GL_NO_ERROR);
fprintf(stderr, "Created VAO %d and associated VBO %d\n", vao, aid);
fprintf(stderr, "Deleting VBO %d\n", aid);
glDeleteBuffers(1, &aid);
assert(glGetError() == GL_NO_ERROR);
if (!leak) {
fprintf(stderr, "Deleting VAO %d\n", vao);
glDeleteVertexArrays(1, &vao);
assert(glGetError() == GL_NO_ERROR);
} else {
fprintf(stderr, "Leaking VBO %d via VAO %d\n", aid, vao);
}
sleep(2L);
}
}
glfwMakeContextCurrent(NULL);
glfwTerminate();
return 0;
}