3

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

Community
  • 1
  • 1
rano
  • 5,616
  • 4
  • 40
  • 66

3 Answers3

13

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.

Mike
  • 146
  • 2
  • it appears that you are right Mike, giving some values multiple of 32 it is rendered correctly. Where in the docs is it written? – rano Nov 29 '10 at 22:36
  • 2
    It is said in this document http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/OpenGLESPlatforms/OpenGLESPlatforms.html under the `Release Notes and Best Practices for the PowerVR SGX` paragraph – rano Nov 30 '10 at 07:22
  • I guess they changed that again for iOS >= 6.0, since the iPhone 5 has a screen height of 1136, which divided by 32 gives 35.5... – Nicolas Miari Aug 23 '13 at 02:46
  • And what can I do for Iphone 5? My 3d model doesn`t appear on iPhone 5, but it appears on Iphone 4. I have to put the height at 1152? – ruff1991 Aug 28 '13 at 11:40
2

Is this in the Simulator? If so, then that is a known bug in the iOS 4.2 Simulator. This bug does not impact the devices themselves.

Frogblast
  • 1,671
  • 10
  • 9
1

How are you setting up your OpenGL-hosting layer and the view that it backs? When I try the OpenGL ES sample applications that I have here and here, both run just fine on the 4.2 Simulator, as well as the device.

Perhaps you could compare the initialization used in those examples with your own and see if there is something that you might be missing in the setup process.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • I had a comparative look at the Cube code and my EAGLView implementation and the difference I found is that I destroy the buffers before creating new ones in `layoutSubViews` whereas only one gets created in `resizeFromLayer:` later called in `layoutSubViews` in the cube example. If I comment the destroy line the view gets not rendered as I make it grow. – rano Nov 27 '10 at 10:39
  • Ah the other difference is that I use a depthbuffer but I guess it does not matter. – rano Nov 27 '10 at 10:39
  • @rano - Now that you point it out, I do something similar when resizing the OpenGL-hosting view in my Molecules application (source at http://www.sunsetlakesoftware.com/molecules, if I can get the site to come back up) and I'm seeing the same display artifact in the Simulator. On the device, it works fine. I'll file a bug report. – Brad Larson Nov 28 '10 at 00:09
  • thank you Brad, I still had not the the time to test on a real device (I'm waiting for a friend of mine who owns an iPhone ^^) and listening this from a developer I admire really reassures me – rano Nov 28 '10 at 08:25
  • one more hint I found, Brad: If I create the view giving the max size (320x480) it appears from the start, so I guess it is related in some way to the dimensions of the view – rano Nov 28 '10 at 14:09