绘制渲染缓冲区对象的内容 [英] Draw the contents of the render buffer Object

查看:94
本文介绍了绘制渲染缓冲区对象的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不太了解渲染缓冲区对象的操作.例如,如果要显示渲染缓冲区中的内容,是否必须将渲染渲染为纹理?

Do not quite understand the operation render buffer object. For example if I want to show what is in the render buffer, I must necessarily do the render to texture?

    GLuint fbo,color_rbo,depth_rbo;

    glGenFramebuffers(1,&fbo);
    glBindFramebuffer(GL_FRAMEBUFFER,fbo);

    glGenRenderbuffersEXT(1, &color_rb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, color_rb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, 256, 256);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_RENDERBUFFER_EXT, color_rb);

    glGenRenderbuffersEXT(1, &depth_rb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 256, 256);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, depth_rb);

    if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)!=GL_FRAMEBUFFER_COMPLETE_EXT)return 1;

    glBindFramebuffer(GL_FRAMEBUFFER,0);

    //main loop    

    //This does not work :-(
    glBindFramebuffer(GL_FRAMEBUFFER,fbo);
    glClearColor(0.0,0.0,0.0,1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawCube();
    glBindFramebuffer(GL_FRAMEBUFFER,0);

有什么主意吗?

推荐答案

当您使用FBO而不是默认帧缓冲区(这是FBO的要点)时,您将看不到任何东西.

You are not going to see anything when you draw to an FBO instead of the default framebuffer, that is part of the point of FBOs.

  1. 将渲染缓冲区拆分为另一个帧缓冲区(在这种情况下,默认后备缓冲区可能为GL_BACK)

绘制到纹理附件中,然后如果要查看结果,则绘制纹理映射的基元(例如三角形/四边形).

Draw into a texture attachment and then draw texture-mapped primitives (e.g. triangles / quad) if you want to see the results.

由于2的含义不言自明,因此我将更详细地解释选项1:

/* We are going to blit into the window (default framebuffer)                     */
glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0);
glDrawBuffer      (GL_BACK);              /* Use backbuffer as color dst.         */

/* Read from your FBO */
glBindFramebuffer (GL_READ_FRAMEBUFFER, fbo);
glReadBuffer      (GL_COLOR_ATTACHMENT0); /* Use Color Attachment 0 as color src. */

/* Copy the color and depth buffer from your FBO to the default framebuffer       */
glBlitFramebuffer (0,0, width,height,
                   0,0, width,height,
                   GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
                   GL_NEAREST);

有两件事在这里值得一提:

首先,从一个帧缓冲区到另一个帧缓冲区的过渡通常比绘制两个填充整个视口的纹理三角形要慢得多. 第二,当您拉伸深度或模板图像时,不能使用线性过滤...但是如果您采用纹理映射方法,则可以使用线性过滤(这仅在源缓冲区和目标缓冲区的分辨率不同时才有意义)在发条时).

There are a couple of things worth mentioning here:

First, blitting from one framebuffer to another is often measurably slower than drawing two textured triangles that fill the entire viewport. Second, you cannot use linear filtering when you blit a depth or stencil image... but you can if you take the texture mapping approach (this only truly matters if the resolution of your source and destination buffers differ when blitting).

总体而言,绘制带纹理的图元是更灵活的解决方案.如果需要进行多样本抗锯齿"功能,则"blitting"最为有用,因为您必须在着色器中实现该功能,否则在 之后添加了多样本纹理化.一些较旧的硬件/驱动程序支持FBO,但不支持多样本颜色(需要DX10硬件)或深度(需要DX10.1硬件)纹理.

Overall, drawing a textured primitive is the more flexible solution. Blitting is most useful if you need to do Multisample Anti-Aliasing, because you would have to implement that in a shader otherwise and multisample texturing was added after Framebuffer Objects; some older hardware/drivers support FBOs but not multisample color (requires DX10 hardware) or depth (requires DX10.1 hardware) textures.

这篇关于绘制渲染缓冲区对象的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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