What does my choice of GLFW_SAMPLES actually do?

老子叫甜甜 提交于 2019-12-01 03:16:26

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!