不支持 GLSL 着色器版本 4.30

GLSL shader version 4.30 not supported

我的笔记本电脑中有一块 Intel HD4400 显卡。当我 运行 glxinfo | grep "OpenGL",我得到

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.0.0-rc5
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 18.0.0-rc5
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 18.0.0-rc5
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
OpenGL ES profile extensions:

这应该意味着我的显卡可以支持GLSL 4.30版本吧?但是,我的着色器编译失败并显示以下消息

error: GLSL 4.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, 3.00 ES, and 3.10 ES

在我的代码中,我使用以下语句将上下文配置文件设置为核心

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)

之后我将上下文主要版本和次要版本分别设置为 4 和 3。

有什么想法吗?我在 Ubuntu 18.04。我认为可能是图形驱动程序不是最新的,但如果它们不是最新的,那么 glxinfo 是否仍会告诉我支持 4.50 版?似乎 Ubuntu 已经安装了最新的 Intel 图形驱动程序,我不想冒险安装可能会损坏我的显示器的图形驱动程序。

附加信息:

我 运行 在另一台机器上使用了这段代码 ,它运行良好(而且我很确定那台机器不支持 GL 4.3 兼容)。因此,我不认为这是我创建上下文的方式。这是我设置个人资料上下文版本的代码:

void set_gl_attribs()
{   
    if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE))
    {
        cout << "Could not set core profile" << endl;
    }
    if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4))
    {
        cout << "Could not set GL major version" << endl;
    }
    if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3))
    {
        cout << "Could not set GL minor version" << endl;
    }
}

这是其中我调用代码之前我调用任何其他SDL或 OpenGL 函数):

SDL_Init(SDL_INIT_EVERYTHING);

window = SDL_CreateWindow("Sphere", 100, 100, width, height, SDL_WINDOW_OPENGL);
gl_context = SDL_GL_CreateContext(window);
//SDL_HideWindow(window);

set_gl_attribs();  // where I set the context, as shown above
SDL_GL_SetSwapInterval(1);

glewExperimental = GL_TRUE;
GLuint glew_return = glewInit();

设置代码不正确。您必须在创建上下文之前选择一个核心配置文件上下文,在上下文存在后更改配置文件为时已晚并且不会起作用。此外,根据 SDL2 文档,必须在通过 SDL_CreateWindow.

创建 window 之前对 SDL_GL_SetAttribute 进行所有调用

将所有调用移至 SDL_GL_SetAtrribute,以便它们在 SDL_CreateWindow 之前。

这个不正确的代码似乎在其他机器上工作的原因是因为不同的驱动程序提供不同版本的 OpenGL,具体取决于您是否要求兼容性或代码配置文件上下文。

  • Mesa 将只提供 3.0 的兼容性上下文,

  • macOS 将仅提供 2.1 用于兼容性上下文,

  • Windows 上的 NVidia 和 AMD 驱动程序将提供它们支持的最新版本。