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

发布于 2024-08-27 08:56:26 字数 2416 浏览 5 评论 0原文

我已经为此苦苦挣扎了一段时间,对我来说,这段代码崩溃的原因未知。我正在创建一个 FBO,绑定一个纹理,然后第一个 glDrawArrays() 在我的 iPhone 模拟器上崩溃并显示“EXC_BAD_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;

JNLogString 只是一个 NSLog,在这种情况下,它给了我:

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

当我就在那里称呼它。

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

我做错了什么?

I've been struggling with this for a while now, and this code crashes with, to me, unknown reasons. I'm creating an FBO, binding a texture, and then the very first glDrawArrays() crashes with a "EXC_BAD_ACCESS" on my iPhone Simulator.

Here's the code I use to create the FBO (and bind texture and...)

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

As you can see this takes part in an object, checkFrameBufferStatus looks like this:

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 is just an NSLog, and in this case it gives me:

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

When I call it right there.

So, it crashes, and diagnostic tells me there's an unknown error and I'm kinda stuck. I basically copied the code from the OpenGL ES 2.0 Programming Guide...

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

欢你一世 2024-09-03 08:56:26
        glBindTexture(GL_TEXTURE1, lastFrameTexture);

这是不允许的,我试图将纹理绑定到单元一(GL_TEXTURE1),但这应该由 glActiveTexture() 完成,而不是由 glBindTexture() 完成,glBindTexture() 想要知道纹理的类型(GL_TEXTURE_2D、GL_TEXTURE_3D 等)。 )不是纹理单元。为了将纹理放置在纹理单元 1 中,我现在拥有以下我认为正确的代码:

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

That's not allowed, I was trying to bind the texture to unit one (GL_TEXTURE1), but that should be done by glActiveTexture(), not by glBindTexture(), which wants to know the type of the texture (GL_TEXTURE_2D, GL_TEXTURE_3D, etc.) not the texture unit. To place a texture in texture unit 1 I now have the following code which I think is correct:

//Bind 2D Texture lastFrameTexture to texture unit 1
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, lastFrameTexture);
稀香 2024-09-03 08:56:26

尝试在每次 GL 调用后使用 glGetError。特别是glTexImage2D

Try using glGetError after each GL call. Specially the glTexImage2D.

无人问我粥可暖 2024-09-03 08:56:26

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

If you use XCode, add breakpoint for OpenGL errors in "Breakpoint Navigator" ([+] -> [Add OpenGL ES Error Breakpoint]). Then all OpenGL problems will be showed on line, where problem appear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文