透明EAGLEView的fps大幅下降

时间:2013-01-28 22:36:38

标签: opengl-es cocos2d-iphone transparency eaglview pixelformat

我有一个Cocos2d项目,我想要在整个应用程序中保持不变的背景。在其委托的applicationDidFinishLaunching方法中,我已替换了该行:

我已将glView的pixelFormat从kEAGLColorFormatRGB565更改为kEAGLColorFormatRGBA8。当我做出这个改变时,glView变得透明,我可以看透它,但fps急剧下降。如果我没有做出改变,那么视图就不会变得透明,但我看不到fps的大幅下降。我说的是fps大幅下降,从59.0-60.0到大约35.0-42.0。

我在上面的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]];
}

有关为何发生这种情况的任何想法?如果需要,我可以提供更多代码。

我忘了提到我做的另一个代码更改。在CCDirector.m setGLDefaultValues中,我改变了这一行:

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

对此:

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

2 个答案:

答案 0 :(得分:1)

无论何时添加具有透明度的Alpha通道,OpenGL引擎都必须执行某种形式(尽管是默认的)alpha混合。这是在非RGBA(即RGB 565)情况下不必进行的每像素数学运算。无论什么时候你加入引擎所需的数学运算速率都会下降。

答案 1 :(得分:1)

这是可以预料的。 RGBA8888帧缓冲器使用两倍的内存,GPU需要执行更多工作才能渲染到此帧缓冲区。这就是RGB565是默认格式的原因。