gpt4 book ai didi

ios - OpenGLES 帧缓冲区问题

转载 作者:行者123 更新时间:2023-11-28 20:35:24 27 4
gpt4 key购买 nike

一直在涉足 OpenGLES 并取得了不同程度的成功。我当前的问题是尝试加载 .obj 文件。我找到了一个很棒的 GLOBJLoader我已经在我当前的项目中实现了,但还没有完全实现。

这是我的代码

- (void)createFramebuffer
{

glGenFramebuffersOES(1, &viewFrameBuffer);
NSLog(@"Check 1");
[self checkFrameBuffer];
glGenRenderbuffersOES(1, &viewRenderBuffer);
NSLog(@"Check 2");
[self checkFrameBuffer];

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFrameBuffer);
NSLog(@"Check 3");
[self checkFrameBuffer];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderBuffer);
NSLog(@"Check 4");
[self checkFrameBuffer];
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
NSLog(@"Check 5");
[self checkFrameBuffer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewFrameBuffer);
NSLog(@"Check 6");
[self checkFrameBuffer];

GLint wide = 320;
GLint high = 480;

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &wide);
NSLog(@"Check 7");
[self checkFrameBuffer];
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &high);
NSLog(@"Check 8");
[self checkFrameBuffer];

if(USE_DEPTH_BUFFER)
{
glGenRenderbuffersOES(1, &depthRenderBuffer);
NSLog(@"Check 9");
[self checkFrameBuffer];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderBuffer);
NSLog(@"Check 10");
[self checkFrameBuffer];
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, glWidth, glHeight);
NSLog(@"Check 11");
[self checkFrameBuffer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderBuffer);
NSLog(@"Check 12");
[self checkFrameBuffer];
}
}

-(void)checkFrameBuffer
{
GLuint returned = (glCheckFramebufferStatus(GL_FRAMEBUFFER_OES));

if(returned != GL_FRAMEBUFFER_COMPLETE_OES)
{
NSLog(@"Error code: %x -->", returned);
switch (returned) {
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES:
NSLog(@"Incomplete: Dimensions");
break;

case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES:
NSLog(@"Incomplete: Formats");
break;

case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES:
NSLog(@"Incomplete: Missing Attachment");
break;

case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES:
NSLog(@"Incomplete: Attachment");
break;

default:
NSLog(@"Complete");
break;
}
}
}

createFrameBuffer() 方法显然是创建帧缓冲区,checkFrameBuffer() 只是帮助调试并在我执行的每一步后输出帧缓冲区的状态。

我从这里得到的输出是:

  1. 检查 1
  2. 错误代码:8cdd -->
  3. 完成
  4. 勾选 2
  5. 错误代码:8cdd -->
  6. 完成
  7. 勾选 3
  8. 错误代码:8cd7 -->
  9. 不完整:缺少附件
  10. 检查 4
  11. 错误代码:8cd7 -->
  12. 不完整:缺少附件
  13. 勾选 5
  14. 错误代码:8cd7 -->
  15. 不完整:缺少附件
  16. 勾选 6
  17. 错误代码:8cd6 -->
  18. 不完整:附件
  19. 勾选 7
  20. 错误代码:8cd6 -->
  21. 不完整:附件
  22. 检查 8
  23. 错误代码:8cd6 -->
  24. 不完整:附件
  25. 勾选 9
  26. 错误代码:8cd6 -->
  27. 不完整:附件
  28. 检查 10
  29. 错误代码:8cd6 -->
  30. 不完整:附件
  31. 勾选 11
  32. 错误代码:8cd6 -->
  33. 不完整:附件
  34. 勾选 12
  35. 错误代码:8cd6 -->
  36. 不完整:附件

这些问题使它无法正常工作,我完全感到困惑。应该说我对OpenGL不是很了解,我只是把东西拼在一起,边学边学,但我确实跑过了Jeff Lamarche's "OpenGLES From the Ground Up"所以知道少量。

我们将不胜感激任何帮助,如果您需要更多信息,请随时提出!

谢谢,

马特

最佳答案

您是否在此之前的某个时刻使用以下设置您的上下文:

[EAGLContext setCurrentContext:context];

在附加所有内容之前,不要费心检查帧缓冲区状态。只有这样,它才会注册为完整。

以下是我用于设置 OpenGL ES 1.1(给定 OES 后缀,我在您的代码中看到)带有深度缓冲区的帧缓冲区的代码:

    [EAGLContext setCurrentContext:context];

glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:glLayer];
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);

glGenRenderbuffersOES(1, &viewDepthBuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewDepthBuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, viewDepthBuffer);

if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
return;
}

我突然想到的一个区别是,您在 glFramebufferRenderbufferOES() 中输入帧缓冲区而不是渲染缓冲区。那可能是您问题的根源。此外,您明确设置了以像素为单位的 FBO 大小,而不是从 View 层获取该大小,我不知道您是否想这样做。

关于ios - OpenGLES 帧缓冲区问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10721496/

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