iphone – GLKView给出’无法完成帧缓冲对象8cd6’错误

我试图将GLKView添加到滚动视图但没有成功.

目前,我的绘图代码只是将背景颜色设置为红色,但在它实现之前,它会抛出错误“Failed to make framebuffer object 8cd6”错误.我已经设法通过将OpenGL绘制到标准的UIView中来完成同样的工作,但是只要将其切换为GLKView,它就会抛出错误.

这是我在AppDelegate.m中初始化滚动视图的方式:

ScrollView *scroll = [[ScrollView alloc] init];
[[self window] setRootViewController:scroll];

然后在我的ScrollView.m本身中有以下内容:

CGRect screenRect;

float screenWidth = 1920;   
float screenHeight = 1280;

UIScrollView *scrollView;
GLKView *glkView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self)
    {
        // Custom initialization
    }

    return self;
}

-(void)loadView
{
    // initialise the view's size parameters
    screenRect.size.width = screenWidth;
    screenRect.size.height = screenHeight;

    // init the scrollview with the new screen rect
    scrollView = [[UIScrollView alloc] initWithFrame:screenRect];

    // set the delegate as itself
    [scrollView setDelegate:self];

    // make the scrollview our main view
    [self setView:scrollView];

    // now create the GLKView and context
    EAGLContext * context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    glkView = [[GLKView alloc] initWithFrame:screenRect];
    glkView.context = context;
    glkView.delegate = self;

    // add the GLKView to the scrollView
    [scrollView addSubview:glkView];

    /* old code, which works fine */
    // OpenGLView openGLView = [[OpenGLView alloc] initWithFrame: screenRect];    
    // openGLView.delegate = self;
    // openGLView.opaque = NO;    
    // [scrollView addSubview:openGLView];
    /* end of old code */

    // and finally tell the scrollview the size of it's content
    [scrollView setContentSize:screenRect.size];
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    // ** THROWS THE ERROR BEFORE HERE ** //
    // set the background colour to red
    glClearColor(1.0, 0.0, 0.0, 1.0);

    // and now clear it    
    glClear(GL_COLOR_BUFFER_BIT);
}

这个代码导致这种情况发生的原因是什么?

最佳答案 在从主线程实例化视图时,我会发生此错误.

FWIW,错误消息中的8cd6是GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT的OpenGL错误代码,这意味着没有完全配置OpenGL帧缓冲区.

点赞