31

GLKitを使用するためにApplesGLPaintの例を移植しようとしています。UIViewを使用すると、ビューのCAEAGLLayerを返し、drawablePropertiesをkEAGLDrawablePropertyRetainedBackingを含むように設定できます。これには、予想どおり、レンダリングバッファを提示した後、ドローアブルコンテンツを保持する効果があります。このプロパティを削除すると、描画呼び出し後にちらつきが発生し、描画可能なコンテンツの一部が別のバッファに描画されているように見えます。

問題は、これがまさに現在GLKViewで発生している問題ですが、描画可能なプロパティを設定する方法がないようです。CAEAGLLayerを返してプロパティを設定しても効果はなく、保持されたバッキングを設定するためのGLKViewの関連するプロパティが表示されません。

他の誰かがこれに遭遇したか、解決策を持っていますか?

4

5 に答える 5

8

GLKView で kEAGLDrawablePropertyRetainedBacking を取得する場合は、次のカテゴリをプロジェクトに追加します。

@interface CAEAGLLayer (Retained)

@end 

@implementation CAEAGLLayer (Retained)

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

@end

GLKView によって維持される CAEAGLLayer に drawableProperties を設定しても機能しません。これは、GLKView がドローアブルをバインドしてレンダリング ストレージを生成するときに、これらのプロパティを上書きするためです。このメソッドを使用すると、代わりに GLKView がカテゴリの返された drawableProperties を使用するようになります。

于 2012-12-03T13:41:31.603 に答える
7

Simeon の答えは機能しますが、アプリケーション内のすべての EAGL ベースのビューの動作が変わります。バッキングを強制する必要があるビューとそうでないビューがあるため、次のように GLKView と CEAGLLayer のサブクラスを作成することで、わずかに異なるソリューションを思い付きました。

@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

この

@interface RetainedGLKView : GLKView
@end

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

これで、保持されたバッキングを強制したいビューに対して、GLKView の代わりに RetainedGLKView を使用できるようになりました。

于 2012-12-12T23:38:23.647 に答える
2

これが機能するかどうかはわかりませんが、次のコードがあります。

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。うまくいけば、それはあなたがあなたが望むパラメータを設定することを可能にします。

于 2012-08-01T14:00:19.893 に答える
1

GLKView 実装ファイルで:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    if ((self = [super initWithCoder:aDecoder]))
    {
        _eaglLayer = (CAEAGLLayer *)self.layer;

        _eaglLayer.opaque = TRUE;
        _eaglLayer.drawableProperties = @{ kEAGLDrawablePropertyRetainedBacking : [NSNumber numberWithBool:NO],
                                           kEAGLDrawablePropertyColorFormat     : kEAGLColorFormatRGBA8};

    }
    return self;
}

どうやって物事をこれほど複雑にしているのか、私にはわかりません。こんな感じで、これだけ。

于 2016-05-01T23:52:56.487 に答える
-2

こんにちはこれを試してみてください

GLKView * const view = (GLKView *)self.view;  
view.context = self.context;
view.delegate = self;
view.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.drawableMultisample = GLKViewDrawableMultisampleNone;
self.preferredFramesPerSecond = 10;

[EAGLContext setCurrentContext:self.context];
CAEAGLLayer * const eaglLayer = (CAEAGLLayer*) view.layer;
于 2012-08-17T06:24:16.043 に答える