首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GLKView集可绘制属性

GLKView集可绘制属性
EN

Stack Overflow用户
提问于 2012-02-22 21:28:38
回答 5查看 4.7K关注 0票数 31

我正在尝试移植一个使用GLKit的苹果GLPaint示例。使用UIView,可以返回视图的CAEAGLLayer并将drawableProperties设置为包含kEAGLDrawablePropertyRetainedBacking。这具有在呈现渲染缓冲区后保留可绘制内容的效果,正如预期的那样。删除此属性会导致在绘图调用后闪烁,部分可绘制内容似乎被绘制到不同的缓冲区。

问题是,这正是我在GLKView中遇到的问题,但似乎没有一种方法来设置可绘制属性。返回CAEAGLLayer并设置属性没有任何效果,并且我没有看到GLKView的任何相关属性来设置保留的支持。

还有没有其他人遇到过这个问题,或者有解决方案?

EN

回答 5

Stack Overflow用户

发布于 2012-12-03 21:41:32

如果您想在GLKView中获取kEAGLDrawablePropertyRetainedBacking,请将以下类别添加到您的项目中。

代码语言:javascript
复制
@interface CAEAGLLayer (Retained)

@end 

@implementation CAEAGLLayer (Retained)

- (NSDictionary*) drawableProperties
{
    return @{kEAGLDrawablePropertyRetainedBacking : @(YES)};
}

@end

在由GLKView维护的CAEAGLLayer上设置drawableProperties不起作用,因为GLKView在绑定其可绘制内容并生成其呈现存储时会覆盖这些属性。使用此方法会强制GLKView改为使用您的类别返回的drawableProperties。

票数 8
EN

Stack Overflow用户

发布于 2012-12-13 07:38:24

Simeon的答案是有效的,但是改变了应用程序中所有基于EAGL的视图的行为。我有一些视图需要强制支持,而另一些视图则不需要,所以我想出了一个稍微不同的解决方案,通过创建GLKView和CEAGLLayer的子类,如下所示:

代码语言:javascript
复制
@interface RetainedEAGLLayer : CAEAGLLayer
@end

@implementation RetainedEAGLLayer
- (void)setDrawableProperties:(NSDictionary *)drawableProperties {
    // Copy the dictionary and add/modify the retained property
    NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] initWithCapacity:drawableProperties.count + 1];
    [drawableProperties enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
        // Copy all keys except the retained backing
        if (![key isKindOfClass:[NSString class]]
        || ![(NSString *)key isEqualToString:kEAGLDrawablePropertyRetainedBacking])
            [mutableDictionary setObject:object forKey:key];
    }];
    // Add the retained backing setting
    [mutableDictionary setObject:@(YES) forKey:kEAGLDrawablePropertyRetainedBacking];
    // Continue
    [super setDrawableProperties:mutableDictionary];
    [mutableDictionary release];
}
@end

还有这个

代码语言:javascript
复制
@interface RetainedGLKView : GLKView
@end

@implementation RetainedGLKView
+ (Class)layerClass {
    return [RetainedEAGLLayer class];
}
@end

现在,对于那些我想强制保留支持的视图,我可以只使用RetainedGLKView而不是GLKView。

票数 7
EN

Stack Overflow用户

发布于 2012-08-01 22:00:20

我不确定这是否可以工作,但下面是我们的一些代码:

代码语言:javascript
复制
GLKView * const view = (GLKView *)self.view;  
view.context = self.context;
view.delegate = self;
view.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.drawableMultisample = GLKViewDrawableMultisampleNone;
self.preferredFramesPerSecond = 30;

[EAGLContext setCurrentContext:self.context];
CAEAGLLayer * const eaglLayer = (CAEAGLLayer*) view.layer;
eaglLayer.opaque = YES;

您应该能够访问eaglLayer.drawableProperties。希望这能让你设置你想要的参数。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9395743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档