glFlush() vs [[self openGLContext]lushBuffer] vs glFinish vs glSwapAPPLE vs aglSwapBuffers
使用 NSOpenGLView 时有几个类似的 OpenGL 操作:
glFlush()
[[self openGLContext]lushBuffer]
glFinish()
- glSwapAPPLE
- aglSwapBuffers
何时应该这些都可以使用吗?
在示例应用程序中,Apple 使用 glFlush()
,后跟 [[self openGLContext]lushBuffer]
。为什么他们同时使用这两个?
如果我使用双缓冲 Cocoa NSOpenGLView,正确的方法是什么?
There are several similar OpenGL operations when working with an NSOpenGLView:
glFlush()
[[self openGLContext] flushBuffer]
glFinish()
- glSwapAPPLE
- aglSwapBuffers
When should each of these be used?
In a sample application, Apple uses glFlush()
, followed by [[self openGLContext] flushBuffer]
. Why do they use both of these?
What would be the right approach, if I am using a double-buffered Cocoa NSOpenGLView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确的方法是调用
[[self openGLContext]flushBuffer]
。The correct approach is just calling
[[self openGLContext] flushBuffer]
.您是否看过这个?它解释了何时使用 glFlush() 和 glFinish()。两者都是控制命令执行和同步的 OpenGL 函数。通常,您在进行多线程渲染时会希望使用这些函数,否则就没有任何需要。
glSwapAPPLE() 和 aglSwapBuffers() 是 Apple 提供的扩展,用于将后台缓冲区的内容显示到屏幕上(在 Windows 上为 wglSwapBuffers())。您应该使用其中之一,但不能同时使用两者,因为它们实际上做同样的事情。我会坚持使用 AGL 方法,因为它类似于 WGL、EGL 等。
从外观上看,
[[self openGLContext]lushBuffer]
可能是 glFlush() 的客观 C 包装器。我无法想象它还能做任何其他事情。Have you looked at this? It explains when to use glFlush() and glFinish(). Both are OpenGL functions that control execution and synchronizing of commands. Generally you would want to use these functions when doing multi-threaded rendering otherwise there shouldn't be any need.
glSwapAPPLE() and aglSwapBuffers() are extensions provided by Apple to display the contents of the backbuffer to screen (on Windows it's wglSwapBuffers()). You should use either one but not both as they really do the same thing. I would stick to the AGL method as it's analogous to WGL, EGL, etc..
[[self openGLContext] flushBuffer]
is probably an objective C wrapper to glFlush() from the looks of it. I can't imagine it doing anything else.当心!
[[self openGLContext]lushBuffer]
不仅仅是gFlush()
的 Objective-C 包装器。此函数(Apple 文档) 仅当您在像素格式中设置双缓冲区时才有效,例如否则你必须使用
glFlush();
我花了很长时间才看到 NSOpenGLContext 类参考。Be careful!
[[self openGLContext] flushBuffer]
is not just an Objective-C wrapper forgFlush()
. This function (- (void)flushBuffer
in the Apple Documentation) works only if you set double buffer in your pixel format likeOtherwise you have to use
glFlush();
It took me a long time until I saw the essential line in the NSOpenGLContext Class Reference.