gpt4 book ai didi

c++ - 从非主线程加载的 VAO 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:33 32 4
gpt4 key购买 nike

在我的代码中,我有一个对象的包装类,该对象由两个缓冲区对象和一个顶点数组对象支持。我在构造函数中使用它生成它们(稍微简化):

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);

printf 在主线程的前几个创建时给出了这个。

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

中间有一个非索引的缓冲区,它占用 VAO #2 和缓冲区 #3。这对我来说没问题。每个数组对象都有两个唯一的缓冲区附加到它。

我稍后也会使用此代码来加载背景资源(而不是生成它们)。每个线程都有自己的上下文,使用 glfwCreateContext 创建并与主窗口共享资源。首次创建这些资源时,会出现以下输出:

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

在此之后很快,VAO #1 被用来绘制 9 次,使用不同数量的顶点和不可避免的一些段错误。

我的问题是,这是错误还是我做错了什么?我正在使用 Nvidia 卡运行戴尔笔记本电脑的 Linux Ubuntu 上对此进行测试。

最佳答案

OpenGL 规范明确禁止共享 VAO 对象。

但是 VBO 仍然是共享的。您只需要在每个线程中使用轻量级 VAO。

关于c++ - 从非主线程加载的 VAO 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18492878/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com