有没有办法更改现有 GLFW window 的 MSAA 样本数?

Is there a way to change the number of MSAA samples of an existing GLFW window?

我目前正在使用 C++、OpenGL 和 GLFW 编写游戏。我想允许用户更改游戏用于抗锯齿的样本数量,因为使用旧系统的用户可能出于性能原因希望完全禁用抗锯齿。

问题是 GLFW_SAMPLES 是 window 创建提示,这意味着它在创建 window 时应用:

// Use 4 samples for antialiasing
glfwWindowHint(GLFW_SAMPLES, 4);

// The hint above is applied to the window that's created below
GLFWwindow* myWindow = glfwCreateWindow(widthInPix, heightInPix, title.c_str(), glfwGetPrimaryMonitor(), nullptr);

// Disable antialiasing
// This hint is not applied to the previously created window
glfwWindowHint(GLFW_SAMPLES, 4);

GLFW 文档不包含任何有关如何更改现有 window 样本数量的信息。过去有人遇到过这个问题吗?

不,您必须创建一个新的 window 并销毁旧的。最好共享两个上下文,这样 non-container objects 就不会在混乱中丢失。

或者,您可以创建多重采样纹理或渲染缓冲区,渲染到 FBO,然后将渲染数据 blit 到非多重采样 window。这样,您就可以完全控制样本的数量,并且可以轻松地随意销毁和重新创建此类图像。