我是否可以在OpenGL 2.1的多个共享上下文中同时从同一缓冲区对象进行渲染?

杰斯特雷克

在Apple的文档中,我读到以下内容:

  • 1- “共享上下文共享在初始化共享之前和之后创建的所有纹理对象,显示列表,顶点程序,片段程序和缓冲区对象。”
  • 2 —“位于不同线程上的上下文可以共享对象资源。例如,一个线程中的一个上下文修改纹理,第二线程中的第二个上下文修改同一纹理是可以接受的。提供共享对象处理Apple API提供的保护可自动防止线程错误。”

因此,我希望能够一次创建缓冲区对象,然后使用它们在多个上下文中同时渲染。但是,如果这样做,我的NVIDIA GeForce GT 650M会崩溃,并且回溯如下:

Crashed Thread:        10  Dispatch queue: com.apple.root.default-qos
Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
…
Thread 10 Crashed:: Dispatch queue: com.apple.root.default-qos
0  GLEngine  0x00007fff924111d7 gleLookupHashObject + 51
1  GLEngine  0x00007fff925019a9 gleBindBufferObject + 52
2  GLEngine  0x00007fff9243c035 glBindBuffer_Exec + 127

我已经在https://gist.github.com/jlstrecker/9df10ef177c2a49bae3e中发布了完整的代码顶部是#define SHARE_BUFFERS-注释掉就可以了,但没有注释就崩溃了。

我不想讨论是否应该使用OpenGL 2.1,这是我正在连接的其他软件的要求。我也不想讨论是否应该使用GLUT-我的示例代码仅使用了它,因为它已包含在Mac中,并且没有任何外部依赖关系。我也不希望获得有关性能/优化的反馈。

我只想知道是否可以在多个上下文中同时从单个共享缓冲区对象进行渲染,如果可以,为什么我的代码崩溃了。

我们还遇到了“ gleLookupHashObject”崩溃问题,并做了一个小巧的假货(非常类似于您的假货),并在“事件”中发布给Apple支持。经过调查,Apple DTS工程师返回了以下信息,并引用:

“引起我注意的是,在主线程和绑定位置数据的辅助线程上都调用了glFlush()。这确实会引入问题,尽管有些微妙,但实际上确实表明我们对线程和GL施加了约束上下文没有得到充分尊重。在这一点上,您应该进一步调查您的实现以确保避免这种情况,或者更好的是,使用显式同步机制(例如我们为GCD提供的功能)扩展您的实现。”

因此,如果遇到此崩溃,您将需要在应用程序端进行显式同步(在驱动程序端进行修复)。

Apple官方文档中与“ OpenGL,上下文和线程”相关的摘要摘要:

[0] Section: "Use Multiple OpenGL Contexts"
If your application has multiple scenes that can be rendered in parallel, you can use a context for each scene you need to render. Create one context for each scene and assign each context to an operation or task. Because each task has its own context, all can submit rendering commands in parallel.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html#//apple_ref/doc/uid/TP40001987-CH409-SW6

[1] Section: Guidelines for Threading OpenGL Applications
(a) Use only one thread per context. OpenGL commands for a specific context are not thread safe. You should never have more than one thread accessing a single context simultaneously.
(b) Contexts that are on different threads can share object resources. For example, it is acceptable for one context in one thread to modify a texture, and a second context in a second thread to modify the same texture. The shared object handling provided by the Apple APIs automatically protects against thread errors. And, your application is following the "one thread per context" guideline.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html

[2] OpenGL Restricts Each Context to a Single Thread
Each thread in an OS X process has a single current OpenGL rendering context. Every time your application calls an OpenGL function, OpenGL implicitly looks up the context associated with the current thread and modifies the state or objects associated with that context.
OpenGL is not reentrant. If you modify the same context from multiple threads simultaneously, the results are unpredictable. Your application might crash or it might render improperly. If for some reason you decide to set more than one thread to target the same context, then you must synchronize threads by placing a mutex around all OpenGL calls to the context, such as gl* and CGL*. OpenGL commands that blockâsuch as fence commandsâdo not synchronize threads.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

DDD,在有限的上下文中让多个聚合根共享同一身份是否可以

在 2 个 OpenGL 上下文之间共享纹理

在OpenGL中,一个着色程序是否可以在一次绘制调用中同时渲染到FBO和默认的帧缓冲区?

OpenGL统一缓冲区对象(数组)彼此跳过Vec2

我想在Jinja2的Ansible上下文中包含另一个Jinja2模板

在上下文切换期间是否存储了IO缓冲区?

WebApi 2-多个同时上下文中的授权,REST状态管理

是否可以在DirectX DC /缓冲区上使用opengl进行绘制?

在同一上下文中使用Spring Boot 2 OAuth Client和Resourceserver

Opengl和opencl在单个共享上下文中只能使用1个内核

SDL2 SDL_CreateRenderer降级了OpenGL上下文,可以防止吗?

在同一个上下文中,“ inline”和“ noexcept”是否多余?

给定ggplot2对象,我可以检测轴是否离散吗?

是否有一个 SQL 语句可以让我看到匹配 2 个不同表的结果?

写入OpenGL多个渲染缓冲区失败

是否可以在AngularFire2中进行多次查询,或者我可以更改数据客户端?

OpenGL可以与其他版本共享上下文

为什么我的上下文中有一个空对象?

是否可以在GWT UiBinder上下文中引用枚举

我可以从消息上下文中获得什么其他对象

如何检查我的EC2是否可以访问同一帐户中的s3存储桶?

是否有与OpenGL的像素缓冲区对象等效的Vulkan?

CUDA-是否可以同时在多个内核上处理单个像素缓冲区数据(数组)?

NetLogo:在乌龟上下文中,是否可以使用某种语法代替“ crt 1”?

我可以设置openGL缓冲区以使其工作与OBJ文件类似的原理吗?

多个隔离的OpenGL上下文是否会影响性能

我是否需要在Maya 2017中定义OpenGL上下文?

我是否需要分别为每个opengl上下文加载函数?

Raspberry Pi上的SDL2无法创建渲染器:“已创建OpenGL上下文”