NSOpenGLLayer 和多线程
我已经使用可可粉写了一个3D查看器。 OpenGL渲染是在创建其自己的Nsopenglcontext的单独线程中执行的。
如果没有图层处理,则在刷新时调用3D视图绘制方法,并且OpenGL线程可以进行刷新,并且所有内容都可以完美地工作……
现在,我必须使用可可层实现该应用程序。创建3D NSVIEW时,将创建NSopenglayer的子类并将其附加到视图上。该方法
(void)drawInOpenGLContext:NSOpenGLContext *)ctx
pixelFormat:(NSOpenGLPixelFormat *)pixelFormat
forLayerTime:(CFTimeInterval)timeInterval
displayTime:(const CVTimeStamp *)timeStamp;
是由可可(Cocoa)调用的,但是我无法使我的OpenGL线程呈现任何东西。
我曾尝试使用OpenGL上下文中传递给prawinopenglcontext在OpenGL线程中,我尝试
[layer setOpenGLContext:ctx]
在openGL线程中使用openGL线程进行A OpenGL上下文,依此类推,但没有任何可用。
I have written a 3D viewer using Cocoa. The OpenGL renderings are performed in a separate thread that creates its own NSOpenGLContext.
Without layer handling, the 3D view drawRect method is called on refresh, and the OpenGL thread does its refresh and every things works perfectly...
Now, I have to implement the application using Cocoa layers. When the 3D NSView is created, a subclass of NSOpenGLLayer is created and attached to the view. The method
(void)drawInOpenGLContext:NSOpenGLContext *)ctx
pixelFormat:(NSOpenGLPixelFormat *)pixelFormat
forLayerTime:(CFTimeInterval)timeInterval
displayTime:(const CVTimeStamp *)timeStamp;
is called by Cocoa, but I am unable to make my OpenGL thread render anything.
I had tried to use the OpenGL context passed to drawInOpenGLContext in the OpenGL thread, I have tried to do a
[layer setOpenGLContext:ctx]
in the OpenGL thread with the OpenGL context created in the thread, and so on, but nothing works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你记得在 NSView 上调用 setWantsLayer 吗?您需要从 NSView 中调用它,以使其成为层托管视图。请参阅 NSView setWantsLayer 的文档。
在我的 TestOpenGLLayer 类中,我只需定义 drawInOpenGLContext 函数。我向其中添加了 opeNGL 命令,视图正确渲染了该图层。我不必调用 [layer setContext]。
Did you remember to call setWantsLayer on your NSView? You need to call that from your NSView probably to make it a layer-hosted view. See the documentation for NSView setWantsLayer.
In my TestOpenGLLayer class, I only had to define the drawInOpenGLContext function. I added my opeNGL commands to it and the view rendered the layer properly. I did not have to call [layer setContext].