编译着色器 GLSL 3.30 时出错

pat*_*jos 0 c++ linux opengl

我通过以下方式创建上下文:

new sf::Window(sf::VideoMode(800, 600), "OpenGL",
                                             sf::Style::Default, 
                                             sf::ContextSettings(24, 8, 0, 3, 3, sf::ContextSettings::Core)));
Run Code Online (Sandbox Code Playgroud)

我正在通过 glLoadGen 为 OpenGL 3.3 Core Profile 加载扩展,一个扩展EXT_texture_compression_s3tc。当我编译着色器时:

#version 330 core

layout (location = 0) in vec3 vertPos;

layout (location = 5) uniform mat4 modelMat;
layout (location = 6) uniform mat4 viewMat;
layout (location = 7) uniform mat4 projectionMat;

out vec4 fragColor;

void main()
{
    gl_Position = projectionMat * viewMat * modelMat * vec4(vertPos, 1.0);
    fragColor = vec4(0.5, 0.5, 0.5, 1.0);
}
Run Code Online (Sandbox Code Playgroud)

``

#version 330 core

in vec4 fragColor;
out vec4 outColor;

void main()
{
    outColor = fragColor;
}
Run Code Online (Sandbox Code Playgroud)

我得到错误字符串:

ERROR: Shader compilation error at shader: "media/shaders/shader.vs.glsl"
0:7(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.
0:8(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.
0:9(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.
Run Code Online (Sandbox Code Playgroud)

但我有 OpenGL 3.3(所以 GLSL 3.30)。 glxinfo印刷:

Extended renderer info (GLX_MESA_query_renderer):
    Vendor: X.Org (0x1002)
    Device: AMD JUNIPER (DRM 2.43.0, LLVM 3.8.0) (0x68be)
    Version: 11.2.0
    Accelerated: yes
    Video memory: 512MB
    Unified memory: no
    Preferred profile: core (0x1)
    Max core profile version: 3.3
    Max compat profile version: 3.0
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.0
OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD JUNIPER (DRM 2.43.0, LLVM 3.8.0)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.0
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
Run Code Online (Sandbox Code Playgroud)

所以我应该可以使用 GLSL 3.30。

Nic*_*las 6

在着色器中指定统一位置的能力不是 OpenGL 3.3 版或 GLSL 3.30 版的一部分。它只是 GL 4.3 或 GLSL 4.30 的核心功能。指定顶点着色器输入和片段着色器输出位置的能力是 3.30,但统一位置不是。

明确的统一位置规范实际上并不需要特殊的硬件;这纯粹是一个界面问题。因此,4.x 之前的硬件可以实现它。但是,如果您的硬件仅限于 GL 3.3,则很有可能该硬件太旧以至于 IHV 停止使用新的 OpenGL 功能对其进行更新。因此,即使它可以支持它,该功能还是在 IHV 停止更新硬件后出现。

尽管 NVIDIA 已将其某些仅 3.3 版的硬件保持在最新的非硬件功能上,但英特尔或 AMD 却并非如此。因此,即使您有可以运行的 NVIDIA 3.x GPU,Intel 或 AMD 的 3.x GPU 也可能无法运行。

在您的情况下,“瞻博网络”指的是 Radeon 67xx 系列。这些是 GL 4.x 部分。但是,您使用的是开源驱动程序而不是 AMD 的实际 Linux 驱动程序,因此您只能从中获得 3.3。

最好提高您所需的 OpenGL 版本以匹配您的着色器。但是,如果您希望将其保留为 3.30 着色器并将其用作扩展(因为您使用的是开源驱动程序而不是 AMD 的驱动程序),则需要在声明下方添加扩展#version声明:

#extension GL_ARB_explicit_uniform_location : require
Run Code Online (Sandbox Code Playgroud)