为什么我的 EAGLVIew 在 iOS 4.2 中不再呈现? [英] Why is my EAGLVIew not rendering anymore in iOS 4.2?

查看:19
本文介绍了为什么我的 EAGLVIew 在 iOS 4.2 中不再呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 iOS SDK 4.2 我在我的应用程序中遇到了一些不当行为(另一个被问到 这里).我要请你帮忙的一个关于 OpenGL 视图(EAGLView 子类)的问题,它不再呈现我放入的 3d 模型.

Upgrading to the iOS SDK 4.2 I'm experiencing several misbehaviors in my application (another one is asked here). The one I'm gonna ask your help for concerns an OpenGL view (an EAGLView subclass) that renders no more the 3d model I'm putting in.

视图已分配,它似乎可以识别手势,但其内容不可见(我已检查它是关于视图而不是错位通过为背景着色来建模:它不通过 glClearColor()) 着色它.

The view is allocated and it appears to recognize the gestures but its content is not visible (I've checked that it's about the view and not the misplacing of the model by coloring the background: it does not color it through glClearColor()).

当我双击它时,它会调整大小(它会全屏,在此之前它是一个小 UIVIew)调用这个方法:

When I double tap it it shall resize (it goes fullscreen, before this it is a little UIVIew) calling this method:

- (void)animateToGrow{
    DNSLog(@"grow");
    grow = YES;
    oldFrame = self.frame;
    oldCenter = self.center;

    [UIView beginAnimations:@"MoveAndStrech" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];

    self.frame = CGRectMake(0, 0, WIDTH, HEIGHT); 
    self.center = CGPointMake(CENTER_X, CENTER_Y);
    [UIView commitAnimations];
    [self setupGLPerspectiveNear:0.1 far:1000];
}

然后神奇地模型出现了,甚至背景也被着色了.

and magically the model appears, and even the background gets colored.

我有一个方法可以调整它的大小,让它回到之前的帧和中心位置,当它被调用时,视图再次变为 'empty'.

I have a method that resizes it and make it back to its previous frame and center position and when it gets called the view becomes 'empty' again.

之前有什么建议吗?(如果需要,我可以发布更多代码)

Prior to Any suggestion? (I can post more code if needed)

更新这发生在模拟器上(目前无法在设备上测试).如果这是一个公认的错误,有没有人参考 Apple 文档?

UPDATE This is happening on the simulator (cannot test on a device at the moment). If this is an acknowledged bug, has anyone a reference from Apple docs?

更新 2我使用的是 OpenGL ES 1.1 而不是 2.0.

UPDATE 2 I'm using OpenGL ES 1.1 and not 2.0.

这是我在 EAGLView 的 layoutSubViews 中所做的:

Here is what I do in EAGLView's layoutSubViews :

- (void)layoutSubviews 
{
    [EAGLContext setCurrentContext:_context];
    [self destroyFramebuffer];
    [self createFramebuffer];
    [self drawView];
}

这是我的 createFramebuffer

- (BOOL)createFramebuffer
{
    glGenFramebuffersOES(1, &_viewFramebuffer);
    glGenRenderbuffersOES(1, &_viewRenderbuffer);
    
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
    [_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _viewRenderbuffer);
    
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &_backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &_backingHeight);
    
    if (_useDepthBuffer) 
    {
        glGenRenderbuffersOES(1, &_depthRenderbuffer);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, _depthRenderbuffer);
        glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, _backingWidth, _backingHeight);
        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, _depthRenderbuffer);
    }
    
    if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) 
    {
        NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
        return NO;
    }
    
    return YES;
}

更新 3

如果我创建视图并为其提供全屏帧 (320x480),它会显示正确渲染.在某种程度上它与视图尺寸有关

If I create the view giving it the fullscreen frame (320x480) It appears rendered correctly. In some way It is related to the view dimensions

推荐答案

我花了很长时间才找到这个.根本没有很好的记录,但它在苹果文档中.在 os 4.2 及更高版本上,您需要 EAGLview 大小在两个维度上都为 32 像素的倍数才能正常工作.

It took me forever to find this out. Not well documented at all, but it's in the apple docs. On os 4.2 and higher, you need the EAGLview size to be a multiple of 32 pixels in both dimensions for it to work.

这篇关于为什么我的 EAGLVIew 在 iOS 4.2 中不再呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆