OpenGL ES 2.0和iOS中的默认FrameBuffer [英] OpenGL ES 2.0 and default FrameBuffer in iOS

查看:327
本文介绍了OpenGL ES 2.0和iOS中的默认FrameBuffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对FrameBuffers有点困惑. 当前,为了在屏幕上绘画,我使用此代码为GL_COLOR_ATTACHMENT0生成了带有Renderbuffer的帧缓冲区.

I'm a bit confused about FrameBuffers. Currently, to draw on screen, I generate a framebuffer with a Renderbuffer for the GL_COLOR_ATTACHMENT0 using this code.

-(void)initializeBuffers{

    //Build the main FrameBuffer
    glGenFramebuffers(1, &frameBuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);

    //Build the color Buffer
    glGenRenderbuffers(1, &colorBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);

    //setup the color buffer with the EAGLLayer (it automatically defines width and height of the buffer)
    [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:EAGLLayer];
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &bufferWidth);
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &bufferHeight);

    //Attach the colorbuffer to the framebuffer
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);

    //Check the Framebuffer status
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

    NSAssert(status == GL_FRAMEBUFFER_COMPLETE, ERROR_FRAMEBUFFER_FAIL);

}

然后使用

[context presentRenderbuffer:GL_RENDERBUFFER];

阅读

Reading this question, I saw the comment of Arttu Peltonen who says:

默认情况下,默认帧缓冲区是渲染到的位置,您没有 做任何事情来做到这一点.可以使用帧缓冲对象 渲染为,有些人称其为屏幕外渲染". 如果这样做,最终会导致图像带有纹理,而不是 默认的帧缓冲区(在屏幕上显示).您可以复制 从该纹理到默认帧缓冲区(屏幕上)的图像,即 通常使用blitting完成(但仅在OpenGL ES 3.0中可用). 但是,如果您只想在屏幕上显示图像,则可能 首先不会使用FBO.

Default framebuffer is where you render to by default, you don't have to do anything to get that. Framebuffer objects are what you can render to instead, and that's called "off-screen rendering" by some. If you do that, you end up with your image in a texture instead of the default framebuffer (that gets displayed on-screen). You can copy the image from that texture to the default framebuffer (on-screen), that's usually done with blitting (but it's only available in OpenGL ES 3.0). But if you only wanted to show the image on-screen, you probably wouldn't use a FBO in the first place.

所以我想知道我的方法是否仅用于屏幕外渲染. 在那种情况下,我该怎么做才能在默认缓冲区上渲染? (请注意,我不想使用GLKView ...)

So I wonder if my method is just to be used for off-screen rendering. And in that case, what I have to do to render on the default buffer?! (Note, I don't want to use a GLKView...)

推荐答案

OpenGL ES规范提供了两种帧缓冲区:窗口系统提供的帧缓冲区对象.默认的帧缓冲区是窗口系统提供的那种.但是规范不要求存在窗口系统提供的帧缓冲区或默认的帧缓冲区.

The OpenGL ES spec provides for two kinds of framebuffers: window-system-provided and framebuffer objects. The default framebuffer would be the window-system-provided kind. But the spec doesn't require that window-system-provided framebuffers or a default framebuffer exist.

在iOS中,没有窗口系统提供的帧缓冲区,也没有默认的帧缓冲区-所有绘制都是通过帧缓冲区对象完成的.若要渲染到屏幕,请创建一个渲染缓冲区,该缓冲区的存储来自CAEAGLLayer对象(或者使用代表您创建的对象,如使用GLKView类时一样).这正是您的代码正在做的事情.

In iOS, there are no window-system-provided framebuffers, and no default framebuffer -- all drawing is done with framebuffer objects. To render to the screen, you create a renderbuffer whose storage comes from a CAEAGLLayer object (or you use one that's created on your behalf, as when using the GLKView class). That's exactly what your code is doing.

要执行屏幕外渲染,请创建一个渲染缓冲区,然后调用glRenderbufferStorage为其分配存储空间.所述存储与CAEAGLLayer不关联,因此渲染缓冲区无法(直接)显示在屏幕上. (它也不是纹理-将纹理设置为渲染目标的工作方式有所不同-只是屏幕外缓冲区.)

To do offscreen rendering, you create a renderbuffer and call glRenderbufferStorage to allocate storage for it. Said storage is not associated with a CAEAGLLayer, so that renderbuffer can't be (directly) presented on the screen. (It's not a texture either -- setting up a texture as a render target works differently -- it's just an offscreen buffer.)

Apple的 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆