首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每秒EAGLView透明帧数

每秒EAGLView透明帧数
EN

Stack Overflow用户
提问于 2012-01-05 11:48:14
回答 1查看 876关注 0票数 2

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

代码语言:javascript
复制
[viewController setView:glView];

使用

代码语言:javascript
复制
[[viewController view] addSubview:glView];

因为我已经在RootViewController的视图的initWithNib中添加了子视图,如果用glView替换视图,这些更改就会丢失。

我还将glView的pixelFormat从kEAGLColorFormatRGB565更改为kEAGLColorFormatRGBA8。当我做这个改变时,glView变得透明,我可以透过它看到它,但fps急剧下降。如果我不做更改,视图不会变得透明,但我看不到fps的巨大下降。我说的是fps的显著下降,从59.0-60.0下降到35.0-42.0。

我在上面的addSubview代码行下面使用了这段代码,以使视图透明:

代码语言:javascript
复制
glClearColor(0, 0, 0, 0);
director.openGLView.backgroundColor = [UIColor clearColor];
director.openGLView.opaque = NO;

最后两行是罪魁祸首;将它们注释掉(两行,而不仅仅是一行)会导致fps大幅下降,而注释掉glClearColor行对fps没有影响。

整个applicationDidFinishLaunching方法如下所示:

代码语言:javascript
复制
- (void) applicationDidFinishLaunching:(UIApplication*)application {
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    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 
                   depthFormat:0
                       ];

    // attach the openglView to the director
    [director setOpenGLView:glView];

    if(![director enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

    #if GAME_AUTOROTATION == kGameAutorotationUIViewController
        [director setDeviceOrientation:kCCDeviceOrientationPortrait];
    #else
        [director setDeviceOrientation:kCCDeviceOrientationPortrait];
    #endif

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

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

    //***make glView transparent***
    glClearColor(0, 0, 0, 0);
    director.openGLView.backgroundColor = [UIColor clearColor];
    director.openGLView.opaque = NO;

    // make the View Controller a child of the main window
    [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:[MainMenu scene]];
}

你知道为什么会发生这样的事情吗?我可以提供更多的代码,如果需要。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-06 01:00:28

如果你在第一代或第二代设备上测试,帧率的下降是意料之中的。你对此无能为力。这些设备有严重的填充速率限制,透明的32位GL视图对设备的要求太高了。

如果这种情况发生在第三代甚至第四代设备上,那么一定是出了什么问题,但我无法开始判断是什么。

如果您是在模拟器上测试性能,请不要这样做,因为这是不相关的。

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

https://stackoverflow.com/questions/8737403

复制
相关文章

相似问题

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