没有累积缓冲区的OpenGL抗锯齿 [英] OpenGL antialiasing without the accumulation buffer

查看:94
本文介绍了没有累积缓冲区的OpenGL抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NVIDIA卡上,我可以使用累积缓冲区执行全屏抗锯齿,如下所示:

On an NVIDIA card I can perform full scene anti-aliasing using the accumulation buffer something like this:

if(m_antialias)
{
    glClear(GL_ACCUM_BUFFER_BIT);
    for(int j = 0; j < antialiasing; j++)
    {
        accPerspective(m_camera.FieldOfView(), // Vertical field of view in degrees.
            aspectratio, // The aspect ratio.
            20., // Near clipping
            1000.,
            JITTER[antialiasing][j].X(), JITTER[antialiasing][j].Y(),
            0.0, 0.0, 1.0);

        m_camera.gluLookAt();

        ActualDraw();

        glAccum(GL_ACCUM, float(1.0 / antialiasing));

        glDrawBuffer(GL_FRONT);
        glAccum(GL_RETURN, float(antialiasing) / (j + 1));
        glDrawBuffer(GL_BACK);
    }

    glAccum(GL_RETURN, 1.0);
}

在ATI卡上,未实现累积缓冲区,每个人都说您现在可以使用着色器语言来实现.当然,问题在于GLSL对于OpenGL初学者来说是一个很高的入门门槛.

On ATI cards the accumulation buffer is not implemented, and everyone says that you can do that in shader language now. The problem with that, of course, is that GLSL is a pretty high barrier to entry for an OpenGL beginner.

谁能指出我的一些东西,这些东西将向我展示如何以ATI卡可以做到的方式进行全屏抗锯齿,并且让新手可以理解?

Can anyone point me to something that will show me how to do whole-scene anti-aliasing in a way that ATI cards can do, and that a newbie can understand?

推荐答案

为什么无论是否有累积缓冲区,您都将以这种方式进行抗锯齿?只需使用多重采样;它不是免费的,但是比您做的便宜得多.

Why would you ever do antialiasing this way, regardless of whether you have accumulation buffers or not? Just use multisampling; it's not free, but it's much cheaper than what you're doing.

首先,您必须创建一个具有多重采样缓冲区的上下文.这意味着您需要使用 WGL/GLX_ARB_multisample ,这意味着在Windows上,则需要进行两阶段上下文创建.您应该要求像素格式为1 *_SAMPLE_BUFFERS_ARB和一些*_SAMPLES_ARB.样本数量越大,抗锯齿效果越好(也越慢).您可以使用wglGetPixelFormatAttribfvglXGetConfig来获取最大样本数.

First, you have to create a context with a multisampled buffer. That means you need to use WGL/GLX_ARB_multisample, which means that on Windows, you need to do two-stage context creation. You should request a pixel format with 1 *_SAMPLE_BUFFERS_ARB and some number of *_SAMPLES_ARB. The larger the number of samples, the better the antialiasing (also the slower). You can get the maximum number of samples with wglGetPixelFormatAttribfv or glXGetConfig.

成功创建具有多样本帧缓冲区的上下文后,将正常渲染,但有一个例外:在设置代码中调用glEnable(GL_MULTISAMPLE).这将激活多采样渲染.

Once you have successfully created a context with a multisample framebuffer, you render as normal, with one exception: call glEnable(GL_MULTISAMPLE) in your setup code. This will activate multisampled rendering.

这就是您所需要的.

或者,如果您使用的是GL 3.x,或者可以访问 ARB_framebuffer_object ,可以跳过上下文内容,并创建一个多采样的帧缓冲区.您的深度缓冲区和颜色缓冲区必须全部具有相同数量的样本.我建议针对这些使用使用渲染缓冲区,因为您仍在使用固定功能(并且您可以不能从固定功能管道中的多样本纹理中提取纹理.

Alternatively, if you're using GL 3.x or have access to ARB_framebuffer_object, you can skip the context stuff and create a multisampled framebuffer. Your depth buffer and color buffer(s) must all have the same number of samples. I would suggest using renderbuffers for these, since you're still using fixed-function (and you can't texture from a multisample texture in the fixed-function pipeline).

您可以为颜色和深度创建多采样渲染缓冲区(它们必须具有相同数量的采样).您将它们设置在FBO中,然后渲染到它们中(当然使用glEnable(GL_MULTISAMPLE)).完成后,您可以使用 glBlitFramebuffer 将多样本帧缓冲区后缓冲区(不应进行多重采样).

You create multisampled renderbuffers for color and depth (they must have the same number of samples). You set them up in an FBO, and render into them (with glEnable(GL_MULTISAMPLE), of course). When you're done, you then use glBlitFramebuffer to blit from your multisample framebuffer into the back-buffer (which shouldn't be multisampled).

当然,问题在于GLSL对于OpenGL初学者来说是一个很高的入门门槛.

The problem with that, of course, is that GLSL is a pretty high barrier to entry for an OpenGL beginner.

说谁?向着色器学习的初学者没有错.的确,以我的经验来看,这样的初学者经常学习更好,因为他们了解更有效的事情的细节.

Says who? There is nothing wrong with a beginner learning from shaders. Indeed, in my experience, such beginners often learn better, because they understand the details of what's going on more effectively.

这篇关于没有累积缓冲区的OpenGL抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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