我通过以下方式创建上下文:
new sf::Window(sf::VideoMode(800, 600), "OpenGL",
sf::Style::Default,
sf::ContextSettings(24, 8, 0, 3, 3, sf::ContextSettings::Core)));
我正在通过 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);
}
``
#version 330 core
in vec4 fragColor;
out vec4 outColor;
void main()
{
outColor = fragColor;
}
我收到错误字符串:
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.
但我有 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:
所以我应该可以使用 GLSL 3.30。
最佳答案
在着色器中指定统一位置的功能不是 OpenGL 3.3 版或 GLSL 3.30 版的一部分。它只是 GL 4.3 或 GLSL 4.30 的核心功能。指定顶点着色器输入和片段着色器输出位置的能力是 3.30,但统一位置不是。
显式统一位置规范实际上并不需要特殊硬件;这纯粹是一个接口(interface)的东西。因此,pre-4.x 硬件可以实现它。但是,如果您的硬件仅限于 GL 3.3,那么很有可能硬件太旧以至于 IHV 停止使用新的 OpenGL 功能对其进行更新。所以即使它可以支持它,该功能也是在 IHV 停止更新硬件后出现的。
虽然 NVIDIA 已将其部分 3.3 版硬件的最新非硬件功能保持在最新状态,但英特尔或 AMD 却并非如此。因此,即使您的 NVIDIA 3.x GPU 可以运行,Intel 或 AMD 的 3.x GPU 也可能无法运行。
在您的例子中,“Juniper”指的是 Radeon 67xx 系列。这些是 GL 4.x 部分。但是,您使用的是开源驱动程序而不是 AMD 的实际 Linux 驱动程序,因此您只能从中获得 3.3。
最好提高您所需的 OpenGL 版本以匹配您的着色器。但是,如果您希望将其保留为 3.30 着色器并将其用作扩展(因为您使用的是开源驱动程序而不是 AMD 的驱动程序),您将需要 extension declaration在 #version
声明下方:
#extension GL_ARB_explicit_uniform_location : require
关于c++ - 编译着色器 GLSL 3.30 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38144148/