的实例
我试图创建一个Framebuffer来显示我的iOS应用程序中的3D模型,但是当Framebuffer被创建时,renderbufferStorage返回false。我的代码是基于glcamerariapple的示例代码。
创建帧缓冲区的代码如下:- (void)createFramebuffer
{
if (_context && !defaultFramebuffer) {
[EAGLContext setCurrentContext:_context];
// Create default framebuffer object
glGenFramebuffers(1, &defaultFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
// Create colour renderbuffer and allocate backing store
glGenRenderbuffers(1, &colorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
// Allocate the renderbuffer's storage (shared with the drawable object)
CAEAGLLayer *layer = (CAEAGLLayer*)self.glkView.layer;
BOOL success = [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
if(!success) {
NSLog(@"Error rendering buffer storage");
}
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, layer.bounds.size.width, layer.bounds.size.height);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);
// Create the depth render buffer and allocate storage
glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, framebufferWidth, framebufferHeight);
// Attach colour and depth render buffers to the frame buffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
}
}
任何帮助都将不胜感激。
我也在努力解决这个问题,并找到了一个适合我的解决方案。我用的是
var openGLView = OpenGLView()
和"renderbufferStorage"返回false。在我把它改成
之后var openGLView: OpenGLView!
我得到"renderbufferStorage"返回true
你不能在iOS中使用标准的renderbufferStorage。你必须使用一个对象这个对象是EAGLContext