gpt4 book ai didi

ios - glFramebufferTexture2D 使用 EAGLContext 返回无效状态的其他原因?

转载 作者:行者123 更新时间:2023-11-30 12:28:04 28 4
gpt4 key购买 nike

Khronos 的一般 OpenGL-ES 2.0 文档似乎不完整,至少在 iOS 实现方面 https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glFramebufferTexture2D.xml

我已验证没有满足任何 GL_INVALID_OPERATION 条件,但这就是我要返回的状态。

此操作有时会成功完成,但通常会由于某种原因而出错。

在我将帧缓冲区连接到纹理的这个函数中失败了

  func fullColorFrameBuffer(_ fbo:GLuint, rbo:GLuint, texture:GLuint, size:CGSize) -> GLuint
{
print("full color framebuffer fbo:\(fbo) rbo:\(rbo) texture:\(texture) size:\(size)")
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), fbo)
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), rbo)

glRenderbufferStorage(GLenum(GL_RENDERBUFFER), GLenum(GL_RGBA8_OES), GLsizei(size.width), GLsizei(size.height))
glFramebufferRenderbuffer(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_RENDERBUFFER), rbo)

self.assertNoGLError()

glActiveTexture(GLenum(GL_TEXTURE0))
glBindTexture(GLenum(GL_TEXTURE_2D), fbo)

self.assertNoGLError()

glTexParameteri(GLenum(GL_TEXTURE_2D), GLenum(GL_TEXTURE_WRAP_S), GL_CLAMP_TO_EDGE);
glTexParameteri(GLenum(GL_TEXTURE_2D), GLenum(GL_TEXTURE_WRAP_T), GL_CLAMP_TO_EDGE);
glTexParameteri(GLenum(GL_TEXTURE_2D), GLenum(GL_TEXTURE_MIN_FILTER), GL_LINEAR);
glTexParameteri(GLenum(GL_TEXTURE_2D), GLenum(GL_TEXTURE_MAG_FILTER), GL_LINEAR);

self.assertNoGLError()

glTexImage2D(GLenum(GL_TEXTURE_2D), 0, GLint(GL_RGBA), GLsizei(size.width), GLsizei(size.height), 0, GLenum(GL_RGBA), GLenum(GL_UNSIGNED_BYTE), nil)

self.assertNoGLError()

glFramebufferTexture2D(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_TEXTURE_2D), texture, 0)

self.assertNoGLError()

let status = glCheckFramebufferStatus(GLenum(GL_FRAMEBUFFER))

if status != GLenum(GL_FRAMEBUFFER_COMPLETE)
{
NSLog("failed to make complete framebuffer object %x", status)
}

self.assertNoGLError()

return status
}

我在这里创建句柄:

 fileprivate func createBuffers()
{
glEnableVertexAttribArray(GLenum(LCAttributes.vertex.rawValue))
glVertexAttribPointer(GLenum(LCAttributes.vertex.rawValue), 2, GLenum(GL_FLOAT), 0, GLsizei(2 * MemoryLayout<GLfloat>.size), nil)

glEnableVertexAttribArray(GLenum(LCAttributes.texCoord.rawValue))
glVertexAttribPointer(GLenum(LCAttributes.texCoord.rawValue), 2, GLenum(GL_FLOAT), 0, GLsizei(2 * MemoryLayout<GLfloat>.size), nil)

glGenFramebuffers(1, &framebufferHandle)
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebufferHandle)

glGenRenderbuffers(1, &renderbufferHandle)
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), renderbufferHandle)

glGenTextures(1, &targetTexture)


print("createBuffers fbo:\(framebufferHandle) rbo:\(renderbufferHandle) texture:\(targetTexture)")
}

简单地说; iOS 上此函数返回 GL_INVALID_OPERATION 的任何其他已知原因是什么?或者,这个 bug 的调查要点是什么?我已经验证我位于正确的线程上,并且使用了相同的 EAGLContext。我已验证 View 已正确设置。

最佳答案

已经有一段时间了,但我在 iOS 上也遇到了类似的问题。 IIRC,它与 RenderBuffer 存储格式有关。试试这个:

    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, GLsizei(size.width), GLsizei(size.height));
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);

如果这不起作用,请告诉我,我将发布整个 RTT 创建函数。

关于ios - glFramebufferTexture2D 使用 EAGLContext 返回无效状态的其他原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43926322/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com