1

私はCocos2dプロジェクトを持っており、アプリ全体で一定のバックグラウンドが必要です。そのデリゲートのapplicationDidFinishLaunching方法で、私は次の行を置き換えました:

glViewのpixelFormatをからkEAGLColorFormatRGB565に変更しましたkEAGLColorFormatRGBA8。その変更を行うと、glViewは透明になり、透けて見えますが、fpsは劇的に低下します。その変更を行わないと、ビューは透明になりませんが、fpsの大幅な低下は見られません。59.0〜60.0から約35.0〜42.0へのfpsの大幅な低下について話しています。

ビューを透明にするために、上のaddSubview行のすぐ下にあるこのコードを使用しています。

director.openGLView.opaque = NO;

applicationDidFinishLaunchingメソッド全体は次のようになります。

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Try to use CADisplayLink director
    // if it fails (SDK < 3.1) use the default director
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];


    CCDirector *director = [CCDirector sharedDirector];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

    //
    // Create the EAGLView manually
    //  1. Create a RGB565 format. Alternative: RGBA8
    //  2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
    //
    //
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGBA8    // kEAGLColorFormatRGBA8
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

    // attach the openglView to the director
    [director setOpenGLView:glView];
    glView.opaque = NO;
//  // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if( ! [director enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

    //
    // VERY IMPORTANT:
    // If the rotation is going to be controlled by a UIViewController
    // then the device orientation should be "Portrait".
    //
    // IMPORTANT:
    // By default, this template only supports Landscape orientations.
    // Edit the RootViewController.m file to edit the supported orientations.
    //
#if GAME_AUTOROTATION == kGameAutorotationUIViewController 
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:YES];


    // make the OpenGLView a child of the view controller
    [viewController setView:glView];

    //Required in iOS6, recommended in 4 and 5
    [window setRootViewController:viewController];

    // make the View Controller a child of the main window, needed for iOS 4 and 5
    [window addSubview: viewController.view];

    [window makeKeyAndVisible];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];


    // Removes the startup flicker
    [self removeStartupFlicker];

    // Run the intro Scene
    [[CCDirector sharedDirector] runWithScene: [Intro scene]];
}

なぜこれが起こっているのかについてのアイデアはありますか?必要に応じて、より多くのコードを提供できます。

私が行ったもう1つのコード変更について言及するのを忘れました。CCDirector.msetGLDefaultValuesで、この行を次のように変更しました。

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

これに:

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
4

2 に答える 2

1

透明度のあるアルファチャネルを追加するときはいつでも、OpenGLエンジンは何らかの形式(デフォルトではありますが)のアルファブレンディングを実行する必要があります。これは、RGBA以外(つまりRGB 565)の場合に行う必要がなかったピクセルあたりの計算です。エンジンに必要な計算を追加すると、フレームレートが低下します。

于 2013-01-28T22:46:39.820 に答える
1

これは予想されることです。RGBA8888フレームバッファは2倍のメモリを使用し、GPUはこのフレームバッファにレンダリングするためにより多くの作業を実行する必要があります。これが、RGB565がデフォルトのフォーマットである理由です。

于 2013-01-28T22:46:47.303 に答える