Domanda

Ho un progetto in 3D basato sul exemple EAGLView da Apple.

Ho un bug molto Stange con il contesto (credo), mio ??contesto è creare utilizzando:

  

[contesto renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: (CAEAGLLayer *) self.layer];

Sulla init visualizzare il 3D è un lavoro, e il layout di visualizzazione secondaria, il mio framebuffer è distruggere un creare di nuovo. Ma in alcuni casi, il framebuffer non viene a creare. Ho ricerca con il debugger ho trovare il problema diventerà dal contesto "creazione":

- (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;
}

Non capisco il motivo per cui di lavoro o no. Quando ho questo problema, mi rivolgo il mio iphone per la forza per eseguire layoutSubview, ed è il lavoro. è molto strano.

Quali sono i motivi per il contesto non crea in seconda ed è ok subito dopo.

È stato utile?

Soluzione

Non hai postato il codice che mostra come in realtà si è creato il contesto, basta usarlo. La vostra creazione contesto dovrebbe essere simile a questo

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

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

E se il contesto è 0 (che media zero) allora avrete rilevato prima mano.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top