问题描述
我正在尝试移植Apples GLPaint示例以使用GLKit。使用UIView,可以返回视图的CAEAGLLayer并将drawableProperties设置为包含kEAGLDrawablePropertyRetainedBacking。这具有在呈现渲染缓冲区之后保留可绘制内容的效果,如预期的那样。删除此属性会导致绘制调用后闪烁,部分可绘制内容似乎被绘制到不同的缓冲区。
I'm trying to port Apples GLPaint example to use GLKit. Using a UIView, its possible to return the CAEAGLLayer of the view and set the drawableProperties to include kEAGLDrawablePropertyRetainedBacking. This has the effect of retaining the drawable contents after presenting the render buffer, as expected. Removing this property results in flickering after the draw call with part of the drawable content seemingly being drawn to different buffers.
问题是这正是我现在遇到的问题在我的GLKView中,但似乎没有办法设置drawable属性。返回CAEAGLLayer并设置属性没有任何效果,我没有看到GLKView的任何相关属性来设置保留的支持。
The problem is this is exactly the issue I am now having in my GLKView, but there doesn't seem to be a way to set the drawable properties. Returning a CAEAGLLayer and setting the properties has no effect and I don't see any relevant properties of GLKView to set retained backing.
是否有其他人遇到过这个或有一个解决方案?
Has anybody else come across this or have a solution?
推荐答案
如果要在GLKView中获取kEAGLDrawablePropertyRetainedBacking,请将以下类别添加到项目中。
If you want to get kEAGLDrawablePropertyRetainedBacking in a GLKView, add the following category to your project.
@interface CAEAGLLayer (Retained)
@end
@implementation CAEAGLLayer (Retained)
- (NSDictionary*) drawableProperties
{
return @{kEAGLDrawablePropertyRetainedBacking : @(YES)};
}
@end
在CAEAGLLayer上设置drawableProperties由GLKView维护不起作用,因为GLKView在绑定其drawable并生成其渲染存储时会覆盖这些属性。使用此方法会强制GLKView使用您的类别返回的drawableProperties。
Setting the drawableProperties on the CAEAGLLayer maintained by the GLKView doesn't work because the GLKView overwrites those properties when it binds its drawable and generates its render storage. Using this method forces the GLKView to use your category's returned drawableProperties instead.
这篇关于GLKView设置drawable属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!