Mac 上的 OpenGL 操作
这实际上是架构问题或“它是如何工作的”问题,而不是需要解决的问题。
Apple 文档声称 CGL 是用于管理 OpenGL 上下文的最低级别 api,但缺乏允许将上下文连接到窗口的功能。 不过,AGL 和 Cocoa 可以毫无问题地将上下文绑定到窗口,所以问题是 - 如果它们是基于 CGL 构建的,它们如何做到这一点?
最明显的方法似乎是他们使用 CGL 渲染到屏幕外内存,然后能够以某种方式进行合成。如果是这样,那是怎么发生的呢?
This is really architecture question or 'how does it work' question than a problem to solve.
Apple documentation claims that CGL is lowest level api for managing OpenGL contexts, yet is lacks functionality that allows to connect a context to a window.
AGL and Cocoa can bind a context to a window without a problem though, so the question is - how do they do that if they are built upon CGL?
The obvious way appears to be that they use CGL to render to offscreen memory and are then capable of compositing this somehow. If this is so, how does that happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个私有函数 CGLSetSurface 将属于窗口一部分的表面连接到使用 CGLCreateContext 创建的 GL 上下文。 AGL 和 Cocoa 都在内部使用这个函数。
There is a private function CGLSetSurface that connects a surface that is part of a window to a GL context created with CGLCreateContext. Both AGL and Cocoa use this function internally.
完整示例:
Complete example:
从那以后我就没有再提过这个问题,这就是我能够从中得出的结论:
网上流传的未记录的 api 似乎是所有这些中的一个缺失块 - 我能够在不返回错误的情况下使用 CGLSetSurface ,但它最终并没有做那么多事情。显然还需要做一些其他事情才能使一切在如此低的水平上运行。
总而言之,似乎没有一种明智的方法可以通过
CGL
控制一切。处理所有事情的方法显然就像其他人正在做的那样 - 通过 Cocoa 类(使用 CGL 处理除附加到窗口之外的所有内容,但在那之后就可以了)。I didn't revisit the question ever since, this is what I was able to make out of it:
The undocumented api's that float around the net appear to be a missing block from all that - I was able to
CGLSetSurface
without it returning an error, however it didn't do all that much in the end. Apparently there is some other stuff that needs to be done to make everything work on such a low level.In all, there doesn't appear to be a sane way to control everything through
CGL
. The way to handle everything is like everyone else is doing apparently - throughCocoa classes
(using CGL for all the stuff other then attaching to window is fine though after that point).