gpt4 book ai didi

ios - 无法使用 glGenFramebuffers 生成帧缓冲区

转载 作者:行者123 更新时间:2023-11-29 11:06:57 32 4
gpt4 key购买 nike

glGenFramebuffers 不分配帧缓冲区对象!我无法让这个小程序运行。

代码:

/* ----- AppDelegate.h ----- */
#import <UIKit/UIKit.h>

#import "GLView.h"

@interface AppDelegate : NSObject <UIApplicationDelegate>{
@private
UIWindow *window;
GLView *view;
}

@end

/* ----- AppDelegate.h ----- */

#import "AppDelegate.h"

@implementation AppDelegate

- (void)dealloc
{
[view release];
[window release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect frame = [[UIScreen mainScreen] bounds];

window = [[UIWindow alloc] initWithFrame:frame];
view = [[GLView alloc] initWithFrame:frame];

[window addSubview:view];
[window makeKeyAndVisible];
return YES;
}

@end

/* ----- GLView.h ----- */

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>

@interface GLView : UIView{
@private
EAGLContext* context;
GLuint color_render_buffer;
GLuint depth_render_buffer;
GLuint frame_buffer;
}

-(void)render:(CADisplayLink*)displayLink;

@end

/* ----- GLView.mm ----- */

#import "GLView.h"

@implementation GLView

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)self.layer;
eaglLayer.opaque = YES;

context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if(!context && ![EAGLContext setCurrentContext:context]){
[self release];
return nil;
}

int width = (int)frame.size.width;
int height = (int)frame.size.height;

glGenFramebuffers(1, &frame_buffer);
glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer);
if(glIsFramebuffer(frame_buffer) == GL_FALSE){
//NSLog(@"%i", frame_buffer);
NSLog(@"frame_buffer is GL_FALSE!");
}

glGenRenderbuffers(1, &color_render_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, color_render_buffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer];

if(glIsRenderbuffer(color_render_buffer) == GL_FALSE){
NSLog(@"%i", color_render_buffer);
NSLog(@"color_render_buffer is GL_FALSE");
}

glGenRenderbuffers(1, &depth_render_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, depth_render_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);

if(glIsRenderbuffer(depth_render_buffer) == GL_FALSE){
NSLog(@"depth_render_buffer is GL_FALSE");
}


glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_render_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_render_buffer);

if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
#ifdef DEBUG_LOG
NSLog(@"Framebuffer is not complete!");
exit(1);
#endif
}

[[CADisplayLink displayLinkWithTarget:self selector:@selector(render:)] addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
return self;
}

+(Class)layerClass{
return [CAEAGLLayer class];
}

-(void)dealloc{
if([EAGLContext currentContext] == context){
[EAGLContext setCurrentContext:nil];
}

[context release];
[super dealloc];
}

-(void)render:(CADisplayLink*)displayLink{
/* Rendering */

[context presentRenderbuffer:GL_RENDERBUFFER];
}

@end

我总是收到“frame_buffer is GL_FALSE!”打印到控制台... frame_buffer 始终为 0(窗口系统默认帧缓冲区)是否有任何设置需要添加到 plist?还是我遗漏了什么?

请帮忙。

最佳答案

你永远不会调用 setCurrentContext: when context != nil.
变化:

if(!context && ![EAGLContext setCurrentContext:context]){

收件人:

if(!context || ![EAGLContext setCurrentContext:context]){

关于ios - 无法使用 glGenFramebuffers 生成帧缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13189700/

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