OpenGL SuperSampling抗锯齿?

时间:2014-03-06 14:48:02

标签: opengl glx motif

在办公室,我们正在使用旧的GLX / Motif软件,该软件使用OpenGL的AccumulationBuffer实现抗锯齿以保存图像。 我们的问题是Apple从其所有驱动程序中删除了AccumulationBuffer(从OS X 10.7.5开始),而某些Linux驱动程序(如Intel HDxxxx)也不支持它。

然后我想更新软件的抗锯齿代码,使其与大多数实际操作系统和GPU兼容,但保持生成的图像像以前一样漂亮(因为我们需要它们用于科学出版物)。 / p>

SuperSampling似乎是最古老,质量最好的抗锯齿方法,但我找不到任何不使用AccumulationBuffer的SSAA示例。使用OpenGL / GLX实现SuperSampling有不同的方法吗?

1 个答案:

答案 0 :(得分:3)

您可以使用FBO实现最有可能与累积缓冲区一起使用的相同类型的抗锯齿。除了使用纹理/渲染缓冲区作为“累积缓冲区”之外,该过程几乎相同。您可以使用两个FBO进行处理,也可以更改单个渲染FBO的附加渲染目标。

在使用两个FBO的伪代码中,流程看起来大致如下:

create renderbuffer rbA
create fboA (will be used for accumulation)
bind fboA
attach rbA to fboA
clear

create texture texB
create fboB (will be used for rendering)
attach texB to fboB
(create and attach a renderbuffer for the depth buffer)

loop over jitter offsets
    bind fboB
    clear
    render scene, with jitter offset applied

    bind fboA
    bind texB for texturing
    set blend function GL_CONSTANT_ALPHA, GL_ONE
    set blend color 0.0, 0.0, 0.0, 1.0 / #passes
    enable blending
    render screen size quad with simple texture sampling shader
    disable blending
end loop

bind fboA as read_framebuffer
bind default framebuffer as draw framebuffer
blit framebuffer

也可以进行全超级采样。正如Andon在上面的评论中建议的那样,你创建一个FBO,其渲染目标是每个维度中窗口大小的倍数,最后对你的窗口做一个缩小的blit。整个过程往往很慢并且使用大量内存,即使只有2倍。