Opengl es 使用透明EagleView的fps大幅下降

Opengl es 使用透明EagleView的fps大幅下降,opengl-es,cocos2d-iphone,transparency,eaglview,pixelformat,Opengl Es,Cocos2d Iphone,Transparency,Eaglview,Pixelformat,我有一个Cocos2d项目,我希望整个应用程序有一个稳定的背景。在其委托的applicationdFinishLaunching方法中,我替换了以下行: 我已将glView的像素格式从kEAGLColorFormatRGB565更改为kEAGLColorFormatRGBA8。当我进行更改时,glView变得透明,我可以看穿它,但fps急剧下降。如果我不做这样的改变,视图就不会变得透明,但我看不到fps的大幅下降。我说的是fps的显著下降,从59.0-60.0降到35.0-42.0左右 我在上面

我有一个Cocos2d项目,我希望整个应用程序有一个稳定的背景。在其委托的
applicationdFinishLaunching
方法中,我替换了以下行:

我已将glView的像素格式从
kEAGLColorFormatRGB565
更改为
kEAGLColorFormatRGBA8
。当我进行更改时,glView变得透明,我可以看穿它,但fps急剧下降。如果我不做这样的改变,视图就不会变得透明,但我看不到fps的大幅下降。我说的是fps的显著下降,从59.0-60.0降到35.0-42.0左右

我在上面addSubview行的正下方使用此代码,以使视图透明:

director.openGLView.opaque = NO;
整个ApplicationIDFinishLaunching方法如下所示:

- (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]];
}
为此:

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

无论何时添加透明的alpha通道,OpenGL引擎都必须执行某种形式(尽管是默认)的alpha混合。这是在非RGBA(即RGB 565)情况下不必做的每像素数学。任何时候,只要你增加引擎帧速率所需的数学运算,它就会下降。

这是意料之中的。RGBA8888帧缓冲区使用两倍的内存,GPU需要执行更多工作才能渲染到此帧缓冲区。这就是为什么RGB565是默认格式。

实际上,它更多的是增加的数学,而不是增加的内存。正是添加的alpha混合使帧速率下降。换句话说,这不是渲染到更大的帧缓冲区,而是它在命中帧缓冲区之前必须进行的数学运算,虽然我想你是对的,它还必须为每个像素向帧缓冲区增加2个额外字节:-)也完全同意这是可以预期的,Lol有没有其他方法可以让EagleView透明而不改变那行代码?@Stephen-这取决于你真正想做什么。可能存在这样一种情况,即EAGLView可以在后面而不是前面(您当前的操作方式),这将允许EAGLView不透明。我假设你的背后有某种东西,你希望通过它来展示。如果你让后面的东西变成前面的东西,反之亦然,那么可能会有选择!除此之外,不是真的,如果你需要通过另一个东西来展示,你需要允许透明度和混合。您可以更改混合模式。@Stephen-如果您知道您将只使用100%透明或100%不透明,您可以将混合模式修改为更简单(而不是更重的数学)的混合模式。它仍然允许透明,但本质上可以更简单地打开或关闭。我知道在我写的一个应用程序中,我有一个更简单的功能,由50%的分数触发。试试这里:没有理由不能,你可能意识到在切换上下文时有一个时间延迟,但在你想要/需要的地方提高帧速率可能是值得的。我可能会在appDelegate中编写一个自定义例程来切换模式,然后让其他子类调用它。换句话说,让代表做它应该做的事情并管理EGL。
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);