Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

iphone - Why is my EAGLVIew not rendering anymore in iOS 4.2?

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.

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()).

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 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 I'm using OpenGL ES 1.1 and not 2.0.

Here is what I do in EAGLView's layoutSubViews :

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

And this is my 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;
}

UPDATE 3

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...