代码之家  ›  专栏  ›  技术社区  ›  Nick

OpenGL ES 2.0 FBO创建出现未知错误

  •  7
  • Nick  · 技术社区  · 16 年前

    我已经为此挣扎了一段时间,而这段代码崩溃了,对我来说,未知的原因。我正在创建一个FBO,绑定一个纹理,然后第一个glDrawArrays()在我的iPhone模拟器上崩溃为“EXC\u BAD\u ACCESS”。

    下面是我用来创建FBO(以及绑定纹理和…)的代码

    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];
    

    如您所见,它参与了一个对象,checkFrameBufferStatus如下所示:

    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;
    

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

    当我叫它的时候。

    所以,它崩溃了,诊断告诉我有一个未知的错误,我有点卡住了。我基本上是从OpenGLES2.0编程指南中复制的代码。。。

    我做错什么了?

    3 回复  |  直到 15 年前
        1
  •  3
  •   Nick    16 年前
            glBindTexture(GL_TEXTURE1, lastFrameTexture);
    

    这是不允许的,我试图将纹理绑定到单元1(GL\u TEXTURE1),但这应该由glActiveTexture()完成,而不是由glBindTexture()完成,glBindTexture()希望知道纹理的类型(GL\u texture\u 2D、GL\u texture\u 3D等),而不是纹理单元。要在纹理单元1中放置纹理,我现在有以下我认为正确的代码:

    //Bind 2D Texture lastFrameTexture to texture unit 1
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, lastFrameTexture);
    
        2
  •  1
  •   epatel    16 年前

    尝试使用 glGetError 每次总帐呼叫后。特别是 glTexImage2D .

        3
  •  0
  •   George    12 年前

    如果使用XCode,请在“断点导航器”中为OpenGL错误添加断点([+]->[添加OpenGL ES错误断点)。然后所有的OpenGL问题都会在线显示,问题出现的地方。