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

查看:128
本文介绍了为什么我的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.

我有一个方法可以调整它的大小并使其恢复到之前的帧和中心位置,当它被调用时,视图变为'空'再次。

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)

UPDATE
这是在模拟器上发生的(无法在设备上测试时刻)。如果这是一个公认的错误,有没有人引用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?

UPDATE 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

推荐答案

我花了很长时间才发现这一点。根本没有完整记录,但它在苹果文档中。在操作系统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天全站免登陆