What does my choice of GLFW_SAMPLES actually do?

前端 未结 1 514
夕颜
夕颜 2021-01-02 01:32

What does setting this variable do? For instance, if I set it to 4, what does that mean?

I read a description on glfw.org (see here: GLFW Window Guide) under the \"

相关标签:
1条回答
  • 2021-01-02 01:44

    What does setting this variable do? For instance, if I set it to 4, what does that mean?

    GLFW_SAMPLES is used to enable multisampling. So glfwWindowHint(GLFW_SAMPLES, 4) is a way to enable 4x MSAA in your application.

    4x MSAA means that each pixel of the window's buffer consists of 4 subsamples, which means that each pixel consists of 4 pixels so to speak. Thus a buffer with the size of 200x100 pixels would actually be 800x400 pixels.


    If you were to create an additional framebuffer that is 4 times bigger than the screen. Then using it as a texture sampler with GL_LINEAR as the filter, would basically achieve the same result. Note that this is only the case for 4x MSAA, as GL_LINEAR only takes 4 samples closest to the pixel in question.

    When it comes to anti-aliasing, then using MSAA is a really effective but expensive solution. If you want a very clean and good looking result, then it's definitely the way to go. 4x MSAA is usually chosen as there's a good balance between quality and performance using it.

    The cheaper alternative in terms of performance is to use FXAA. Which is done as a post-processing step and usually comes at no cost. The difference is that MSAA renders at a bigger size and downsamples to to the wanted size, not loosing any quality. Where as FXAA simply averages the pixels as is, basically bluring the image. FXAA usually gives a really decent result.

    Also your driver will most likely enables it by default. But if it doesn't then use glEnable(GL_MULTISAMPLE).


    Lastly if you haven't already, then I highly recommend reading LearnOpenGL's Anti-Aliasing tutorial. It gives a really in-depth explanation of all of this.

    0 讨论(0)
提交回复
热议问题