Question

In my code I have a wrapper class for an object backed by two buffer objects and a vertex array object. I generate them using this in the constructor (slightly simplified):

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &ibo);
glGenBuffers(1, &vbo);
printf("Ind buffers %d %d %d\n", vao, ibo, vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);

The printf gives this on the first few creations on the main thread.

Ind buffers 1 1 2
Ind buffers 3 4 5
Ind buffers 4 6 7
Ind buffers 5 8 9
Ind buffers 6 10 11
Ind buffers 7 12 13

There's a single non-indexed one in between that takes VAO #2 and buffer #3. This looks OK to me. Each array object gets two unique buffers attached to it.

I use this code later on as well for loading background resources (rather, generating them). The threads for this each have their own context created using glfwCreateContext and sharing resources with the main window. When these resources are first created, this output comes:

Ind buffers 1 14 15
Ind buffers 1 16 17
Ind buffers 1 18 19
Ind buffers 1 20 24
Ind buffers 1 21 23
Ind buffers 1 22 25
Ind buffers 1 26 27
Ind buffers 1 28 29
Ind buffers 2 30 31
Ind buffers 2 32 33
Ind buffers 2 34 35
Ind buffers 2 36 37
Ind buffers 2 39 40
Ind buffers 2 38 41
Ind buffers 2 42 43
Ind buffers 2 44 45

Very quickly after this, VAO #1 is used to draw 9 times using varying amounts of vertices and inevitably something segfaults.

My question is, is this a bug or am I doing something clearly wrong? I'm testing this on a Linux Ubuntu running Dell laptop with an Nvidia card.

Was it helpful?

Solution

OpenGL specification explicitly disallows sharing of VAO objects.

But VBOs are still shared. You just need lightweight VAO in every thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top