简体   繁体   English

EAGLContext在openGLES 1 iPhone OS上不起作用

[英]EAGLContext not work on openGLES 1 iphone os

I have a 3D project based on the EAGLView exemple from Apple. 我有一个基于Apple EAGLView示例的3D项目。

I have a very stange bug with the context ( I think ), my context is create by using : 我的上下文有一个非常糟糕的错误(我认为),我的上下文是通过使用以下命令创建的:

[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer]; [上下文renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];

On init the 3D view it's work, and on layout subview, my frameBuffer is destroy an create again. 在初始化3D视图时它起作用,在布局子视图中,我的frameBuffer再次破坏了创建。 But in some case, the framebuffer is not create. 但是在某些情况下,不会创建帧缓冲区。 I have search with the debugger I have find the problem become from the context "creation": 我用调试器进行搜索,发现问题来自上下文“创建”:

- (BOOL)createFramebuffer
{
    NSLog(@"[EAGLVIEW] create framebuffer");

    glGenFramebuffersOES(1, &viewFramebuffer);
    glGenRenderbuffersOES(1, &viewRenderbuffer);

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);


    //////// HERE, some time the context is 0 /////////
    [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);


    // On génère le tampon de profondeur -- bah oui, on fait de la 3D
    glGenRenderbuffersOES(1, &depthRenderbuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    // On paramètre le tampon :
    // - avec les dimensions que l'on veut
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
    //glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES, backingWidth, backingHeight);
    // - avec la profondeur que l'on veut
    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;
}

I don't understand why it's work or not. 我不明白为什么要这么做。 When i have this bug, i turn my iphone for force to execute layoutSubview, and it's work. 当我遇到此错误时,我将iPhone拨开以强制执行layoutSubview,并且它可以正常工作。 it's very strange. 这很奇怪。

what are the reason for the context not create at second and it's ok just after. 是什么原因导致上下文无法在第二个创建,然后就可以了。

You have not posted the code showing how you actually created the context, just using it. 您尚未发布仅显示使用上下文的代码来显示如何实际创建上下文。 Your context creation should look something like this 您的上下文创建应如下所示

context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

if (!context || ![EAGLContext setCurrentContext:context])
    return false;

And if the context is 0 (which mean nil) then you will have detected it before hand. 如果上下文为0(表示零),那么您将在手之前检测到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM