资源初始化和 OpenGL 上下文
我们有一个 OpenGL 应用程序(使用 Ogre3d 和 SDL,而不是直接调用 OpenGL),我们试图在运行时更改分辨率。看来我们需要使用新的分辨率重新初始化 OpenGL 上下文,但在此过程中许多项目都被破坏了。在 Linux 上,它似乎可以工作一段时间,然后我们在屏幕上看到图形损坏。在 Windows 上,当我们下次尝试渲染帧时,它就会崩溃。我们在 Ogre 中强制重新加载纹理,如果我们只渲染纹理(无 3D 模型),那么这可以正常工作,但任何 3D 模型都会导致崩溃,并且在渲染它们之前重新加载没有任何效果。
以下是我们正在执行的 Ogre3d 调用的深入解释的链接:http://www.ogre3d.org/forums/viewtopic.php?f=2&t=62825
我们真正需要知道的是,重新初始化 Opengl 上下文时需要恢复哪些资源?
为什么调整 OpenGL 上下文会影响其他资源?这是 OpenGL 的工作方式,还是我们使用的库之一引入了这个问题?我们是否可以在不知情的情况下添加这个问题?
We have an OpenGL Application (using Ogre3d and SDL, not directly calling OpenGL) and we are trying to change the Resolution at runtime. It seems that we need to re-initialize our OpenGL context with the new Resolution but a number of items are breaking along the way. On Linux it seems to work for a while, then we get graphical corruption on screen. On Windows it simply crashes the next time we try to render a frame. We have forced the reloading of textures in Ogre, and if we rendering nothing but textures (no 3d models) then this works fine, but any 3d models cause a crash and reloading before rendering them has no effect.
Here is a link to an in depth explanation of Ogre3d calls we are doing: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=62825
All we really need to know is, When re-initializing an Opengl context what resources need to be restored?
Why does adjusting an OpenGL context affect other resources? Is it the way OpenGL works, or did one of the libraries we use introduce this issue? Could we have added this issue without knowing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您查看过此论坛帖子吗?
当改变分辨率时,SDL 似乎会破坏 OpenGL。在这种情况下,所有 GL 资源都会随上下文一起被销毁。
一种可能的解决方案是创建另一个“虚拟”GL 上下文,与“真实”GL 上下文共享资源,并通过 SDL 破坏“主”上下文来使其保持活动状态。这样你的大部分资源就应该能够存活下来。
请注意,有些资源无法共享,纹理和 VBO 可以,但 VAO 不能。
Did you have a look at this forum thread ?
SDL seems to destroy the OpenGL when changing resolution. In this case, all you GL resources are destroyed with the context.
One possible solution would be to create another 'dummy' GL context, sharing resources with you 'real' GL context, and to keep it alive with SDL destroys the 'main' context. This way most of your resources should survive.
Note that some resources can't be shared, textures and VBO are fine, but VAO can't.
在其表面代码建立后,SDL 添加了 OpenGL 支持。这就是为什么更改 SDL 窗口的大小具有破坏性。有人向您介绍了 OpenGL 上下文共享及其注意事项。不过,我可以通过不使用 SDL 创建 OpenGL 窗口来完全避免这个问题。您可以使用 SDL 提供的所有其他功能,而无需 SDL 管理的窗口,因此唯一需要更改的是输入事件处理以及窗口的创建方式。我会使用 GLFW 而不是 SDL,它与 SDL 一样要求您实现自己的事件处理循环,因此使用 GLFW 作为 OpenGL 窗口和上下文创建的直接替代品非常简单。
OpenGL support was added SDL after its surface code had been established. That's why changing the size of a SDL window is destructive. You were pointed to OpenGL context sharing and its caveats. However I'd avoid the problem alltogether by not using SDL for creating an OpenGL window. You can use all the other facilities SDL provides without a window managed by SDL, so the only thing that would change is input event processing and how the window's created. Instead of SDL I'd use GLFW, which like SDL requires you to implement your own event processing loop, so using GLFW as a drop-in replacement for OpenGL window and context creation is straightforward.