gpt4 book ai didi

ios - 为什么向我的应用程序添加多重采样会在第一帧卡住屏幕?

转载 作者:行者123 更新时间:2023-11-29 03:21:08 27 4
gpt4 key购买 nike

我正在尝试将多重采样添加到我的应用程序中,但似乎我犯了一个错误,但我找不到我做错了什么。

这就是我设置帧缓冲区和渲染缓冲区的方式

- (void)setupBuffers {
glGenFramebuffers(1, &_framebuffer);
glGenRenderbuffers(1, &_renderbuffer);

glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);

[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer]; // I already set the current context to _context, and _eaglLayer is just self.layer

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _renderbuffer);

if (YES) { // note if I set this to no, my app properly displays (I don't even have to remove the code in my render method)
glGenFramebuffers(1, &_msaa_framebuffer);
glGenRenderbuffers(1, &_msaa_renderbuffer);

glBindFramebuffer(GL_FRAMEBUFFER, _msaa_framebuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _msaa_renderbuffer);

glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 2, GL_RGBA8_OES, [AppDelegate screenWidth], [AppDelegate screenHeight]); // yes, this is the proper width and height I tested it
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _msaa_renderbuffer);
}

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE) {
NSLog(@"Failed to make complete framebuffer object %x", status);
exit(1);
}
}

在我的 ViewController 上调用 viewDidLoad 后,我在我的 UIView 子类上调用方法 setupDisplayLink

- (void)setupDisplayLink {
CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)];
//displayLink.frameInterval = [[NSNumber numberWithInt:1] integerValue];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}

这调用了我的渲染方法,非常简单:

- (void)render:(CADisplayLink*)displayLink {
glBindRenderbuffer(GL_RENDERBUFFER, _msaa_framebuffer);

glViewport(0, 0, [AppDelegate screenWidth], [AppDelegate screenHeight]);
glClearColor(188.0f / 255.0f, 226.0f / 255.0f, 232.0f / 255.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

[[OpenGLViewController instance].menu draw:displayLink]; // drawing happens here

glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, _framebuffer);
glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, _msaa_framebuffer);

glResolveMultisampleFramebufferAPPLE();

glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, (GLenum[1]) { GL_COLOR_ATTACHMENT0 });

glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);

NSLog(@"%@", @"HI");
[_context presentRenderbuffer:GL_RENDERBUFFER];
}

它根本没有挂起(应用程序一直在控制台中打印“HI”,因为我在渲染方法中告诉它)。出于某种原因,当我为多重采样添加额外的帧缓冲区和渲染缓冲区时,只绘制了第一帧,我不知道为什么。它只是卡住在那个框架上。为什么我的应用程序只能使用 MSAA 绘制第一帧?

最佳答案

至少可以说,这并不奇怪。唯一一次将 _msaa_framebuffer 绑定(bind)为 DRAW 缓冲区是在初始化 FBO 后立即进行。

第一次调用 render (...) 时,将以下行绘制到您的 _msaa_framebuffer 中:

[[OpenGLViewController instance].menu draw:displayLink]; // drawing happens here

但是,稍后在 render (...) 中,您将绘制缓冲区设置为 _framebuffer 并且从那时起您再也不会更改它。

要解决您的问题,您所要做的就是记住在 render (...) 函数开头将 _msaa_framebuffer 绑定(bind)为绘制缓冲区:

- (void)render:(CADisplayLink*)displayLink {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, _msaa_framebuffer);

关于ios - 为什么向我的应用程序添加多重采样会在第一帧卡住屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21079204/

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