Ok, so let’s see.
So I have the object below and it crashes after 31 vertices are added, works fine up until that point. Not sure if I hit the buffer limit for my video card or I am missing something else.
So to cover my bases and be able to move on. Should the GPU buffer be used to create cube boxes then adjust them using the geometry shader or is there some thing I can adjust to fix my issue and add more vertices/objects.
Basically, I don’t know when to use the GPU buffer and when to stick to cpu processing.
Side note, let’s say you are using the buffer for every object - creating multiple indices and such(and my issue isn’t buffer size). Should you also use the gpu buffer for simple flat surfaces or should more simple items be done cpu side then sent to the gpu?
GLfloat vertices[] = {
//pos //color //texture
//back top
0.0f, 1.4f, 0.0f, 0.0f, 0.8f, 0.8f, 0.0f, 0.0f,//0
-0.1f, 1.4f, 0.005f, 0.8f, 0.0f, 0.8f, 0.0f, 0.0f,
-0.5f, 0.03f, 0.38f, 0.8f, 0.8f, 0.0f, 0.0f, 0.0f,
-0.45f, 0.0f, 0.35f, 0.8f, 0.8f, 0.0f, 0.0f, 0.0f,
-0.25f, 0.03f, 0.75f, 0.8f, 0.0f, 0.8f, 0.0f, 0.0f,
-0.25f, 0.03f, 0.7f, 0.0f, 0.8f, 0.8f, 0.0f, 0.0f,//5
-0.25f, 0.02f, 0.7f, 0.0f, 0.8f, 0.8f, 0.0f, 0.0f,
-0.25f, 0.02f, 0.75f, 0.8f, 0.0f, 0.8f, 0.0f, 0.0f,
0.25f, 0.02f, 0.7f, 0.8f, 0.8f, 0.0f, 0.0f, 0.0f,
0.25f, 0.02f, 0.75f, 0.8f, 0.8f, 0.0f, 0.0f, 0.0f,
0.25f, 0.03f, 0.75f, 0.8f, 0.0f, 0.8f, 0.0f, 0.0f,//10
0.25f, 0.03f, 0.7f, 0.0f, 0.8f, 0.8f, 0.0f, 0.0f,
0.5f, 0.03f, 0.38f, 0.0f, 0.8f, 0.8f, 0.0f, 0.0f,
0.45f, 0.0f, 0.35f, 0.8f, 0.0f, 0.8f, 0.0f, 0.0f,
0.1f, 1.4f, 0.005f, 0.8f, 0.8f, 0.0f, 0.0f, 0.0f,
//back bottom
-0.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f, 0.8f, 0.0f, 1.0f,//35
0.7f, 0.0f, 0.0f, 0.8f, 0.8f, 0.8f, 0.0f, 0.0f,
*/
};
GLuint indices[] = {
0, 1, 2,
2, 3, 0,
3, 2, 4,
4, 5, 3,
5, 4, 6,
6, 7, 5,
7, 6, 8,
8, 9, 7,
9, 8, 10,
10, 11, 9,
11, 10, 12,
12, 13, 11,
13, 12, 14,
14, 0, 13,
4, 2, 15,
15, 16, 4,
16, 15, 3,
3, 17, 16,
3, 17, 5,
17, 16, 18,
18, 19, 17,
19, 18, 20,
20, 21, 19,
21, 20, 22,
22, 23, 21,
23, 22, 24,
24, 22, 13,
13, 22, 11,
24, 23, 10,
23, 24, 12,
1, 0, 25,
25, 0, 26,
2, 1, 25,
25, 26, 2,
3, 26, 15,
26, 3, 27,
27, 28, 26,
28, 27, 29,
28, 29, 0,
30, 27, 26,
26, 30, 15,
30, 15, 28,
28, 15, 3,
//0, 31, 14,
//0, 31, 32,
};
GLuint VBO, EBO;
glGenVertexArrays(0 , &VAO[0]);
glGenBuffers(0 , &VBO);
glGenBuffers(0 , &EBO);
glBindVertexArray(VAO[0]);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
printf("////%i/////", sizeof(indices));
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(GLfloat), (GLvoid*)(3*sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(GLfloat), (GLvoid*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(2);
glBindVertexArray(0);
...........
glBindVertexArray(VAO[0]);
int size;
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
glDrawElements(GL_TRIANGLES, size/sizeof(GLuint), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
I’ll add in subData later if needed for multiple objects.
Thanks.