2010-04-03 21 views
7

He estado luchando con esto desde hace un tiempo, y este código falla, para mí, con razones desconocidas. Estoy creando un FBO, vinculando una textura, y luego el primer glDrawArrays() se bloquea con un "EXC_BAD_ACCESS" en mi simulador de iPhone.La creación de OpenGL ES 2.0 FBO falla con el error desconocido

Aquí está el código que utilizo para crear el OBF (y obligar a la textura y ...)

glGenFramebuffers(1, &lastFrameBuffer); 
glGenRenderbuffers(1, &lastFrameDepthBuffer); 
glGenTextures(1, &lastFrameTexture); 

glBindTexture(GL_TEXTURE1, lastFrameTexture); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 768, 1029, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, NULL); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

//Bind/alloc depthbuf 
glBindRenderbuffer(GL_RENDERBUFFER, lastFrameDepthBuffer); 
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 768, 1029); 

glBindFramebuffer(GL_FRAMEBUFFER, lastFrameBuffer); 

//binding the texture to the FBO :D 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lastFrameTexture, 0); 

// attach the renderbuffer to depth attachment point 
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, lastFrameDepthBuffer); 

[self checkFramebufferStatus]; 

Como se puede ver este participa en un objeto, checkFrameBufferStatus se ve así:

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); 
switch(status) 
{ 
    case GL_FRAMEBUFFER_COMPLETE: 
    JNLogString(@"Framebuffer complete."); 
    return TRUE; 

    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 
    JNLogString(@"[ERROR] Framebuffer incomplete: Attachment is NOT complete."); 
    return false; 

    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 
    JNLogString(@"[ERROR] Framebuffer incomplete: No image is attached to FBO."); 
    return false; 

    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 
    JNLogString(@"[ERROR] Framebuffer incomplete: Attached images have different dimensions."); 
    return false; 

    case GL_FRAMEBUFFER_UNSUPPORTED: 
    JNLogString(@"[ERROR] Unsupported by FBO implementation."); 
    return false; 

    default: 
    JNLogString(@"[ERROR] Unknown error."); 
    return false; 

JNLogString es sólo un NSLog, y en este caso me da:

2010-04-03 02:46:54.854 Bubbleeh[6634:207] ES2Renderer.m:372 [ERROR] Unknown error. 

Cuando lo llamo t derecha aquí.

Por lo tanto, falla, y el diagnóstico me dice que hay un error desconocido y estoy atascado. Básicamente copié el código de la Guía de programación de OpenGL ES 2.0 ...

¿Qué estoy haciendo mal?

+0

genpfault: Pareces haber corrompido un poco el cuerpo. Por favor, arreglalo. Gracias por adelantado. – Nick

Respuesta

3
 glBindTexture(GL_TEXTURE1, lastFrameTexture); 

eso no está permitido, yo estaba tratando de obligar a la textura a una unidad (GL_TEXTURE1), sino que debe ser realizado por glActiveTexture(), no por glBindTexture(), que quiere saber el tipo de la textura (GL_TEXTURE_2D, GL_TEXTURE_3D, etc.) no la unidad de textura. Para poder hacer una textura en la unidad de textura 1 ahora tengo el siguiente código que creo que es correcto:

//Bind 2D Texture lastFrameTexture to texture unit 1 
glActiveTexture(GL_TEXTURE1); 
glBindTexture(GL_TEXTURE_2D, lastFrameTexture); 
1

Pruebe usar glGetError después de cada llamada GL. Especialmente el glTexImage2D.

+0

Gracias, eso ayudó mucho. – Nick

0

Si utiliza XCode, Añadir punto de interrupción de errores de OpenGL en "punto de interrupción Navigator" ([+] -> [Agregar Punto de interrupción de OpenGL ES Error]). Entonces todos los problemas de OpenGL se mostrarán en línea, donde aparece el problema.

Cuestiones relacionadas