问题描述
我的.Net Winforms应用程序在我的主窗口中创建了三个OpenGL渲染上下文,然后允许用户弹出其他窗口,其中每个窗口还有两个渲染上下文(使用拆分器).在第26个渲染上下文左右,事情开始变得非常缓慢.无需花费几毫秒来渲染帧,新的渲染上下文只需5到10秒.它仍然有效,只是速度很慢! OpenGL不会返回任何错误(glGetError).
My .Net Winforms application creates three OpenGL rendering contexts in my main window, and then allows the user to popup other windows where each window has two more rendering contexts (using a splitter). At around the 26th rendering context, things start to go REALLY slow. Instead of taking a few milliseconds to render a frame, the new rendering context takes between 5 and 10 seconds. It still works, just REALLY SLOW! And OpenGL does NOT return any errors (glGetError).
其他窗口工作正常.经过一定数量后,只是新的渲染上下文放慢了速度.如果我关闭了这些窗口,一切都很好-直到我重新打开足够的窗口以通过限制.每个渲染上下文都有自己的线程,并且每个线程都使用一个简单的着色器.当我上传纹理时,速度变慢似乎发生了.但是纹理的大小对我可以创建多少个上下文没有影响,OpenGL窗口的大小也没有影响.
The other windows work fine. Just the new rendering contexts after a certain number slow down. If I close those windows, everything is fine -- until I reopen enough windows to pass the limit. Each rendering context has its own thread, and each one uses a simple shader. The slow down appears to happen when I upload a texture. But the size of the texture has no effect on how many contexts I can create, nor does the size of the OpenGL window.
我在nVidia卡上运行,并在具有不同内存量和不同驱动程序版本的不同GPU上看到了这一点.这是怎么回事?一个应用程序可以创建多少个渲染上下文有一些限制?
I'm running on nVidia cards and see this on different GPU's with different amounts of memory and different driver versions. What's the deal? Is there some limit to how many rendering contexts an application can create?
其他任何人是否都拥有同时包含很多渲染上下文的应用程序?
Does anyone else have an application with LOTS of rendering contexts going at the same time?
推荐答案
正如内森·基德(Nathan Kidd)正确说的那样,限制是特定于实现的,而您所能做的就是在通用硬件上运行一些测试.
As Nathan Kidd correctly said, the limit is implementation-specific, and all you can do is to run some tests on common hardware.
在今天的部门会议上,我感到无聊,所以我试图拼凑一些创建OpenGL上下文并尝试渲染的代码.我尝试了在有无纹理,有无前向兼容OpenGL上下文的情况下进行渲染.
I was bored at today's department meeting, so i tried to piece together a bit of code which creates OpenGL contexts and tries some rendering. I tried rendering with and without textures, with and without forward-compatible OpenGL context.
事实证明,GeForce卡的限制相当高(甚至没有限制).对于台式机Quadro,限制了128个可以正确重绘的上下文,该程序可以创建128个以上的上下文,且没有错误,但是窗口中包含垃圾.
It turned out that the limit is pretty high for GeForce cards (maybe even no limit). For desktop Quadro, there was limit of 128 contexts that were able to repaint correctly, the program was able to create 128 more contexts with no errors, but the windows contained rubbish.
在ATi Radeon 6950上更加有趣,在那里重新绘制在#105窗口处停止,并且创建渲染上下文#200失败.
It was even more interesting on ATi Radeon 6950, there the redrawing stopped at window #105, and creating rendering context #200 failed.
如果您想尝试一下,可以在这里找到该程序: Max OpenGL Contexts测试(有完整的源代码+ win32二进制文件).
If you want to try for yourself, the program can be found here: Max OpenGL Contexts test (there is full source code + win32 binaries).
就是这样.一条建议-尽可能避免使用多个上下文.在多个监视器上运行的应用程序中可以理解多个上下文,但是单个监视器上的应用程序应该求助于单个上下文.上下文切换很慢.这还不是全部. OpenGL窗口与另一个窗口重叠的应用程序需要硬件剪切区域.在GeForce上有一个硬件裁剪区域,在Quadro上有八个或更多(与游戏相反,CAD应用程序通常使用与OpenGL窗口重叠的窗口和菜单).如果需要更多区域,渲染又要依靠软件了-同样,拥有大量OpenGL窗口(上下文)并不是一个好主意.
That's the result. One piece of advice - avoid using multiple contexts where possible. Multiple contexts can be understood in application running at mulitple monitors, but applications on a single monitor should resort to a single context. Context switching is slow. And that's not all. Applications where OpenGL windows are overlapped by another windows require hardware clipping regions. There is one hardware clipping region on GeForce, eight or more on Quadro (CAD applications often use windows and menus that overlap OpenGL window, in contrast with games). In case more regions are needed, rendering falls back to software - so again - having lots of OpenGL windows (contexts) is not a very good idea.
这篇关于您可以同时创建多少个OpenGL渲染上下文是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!