如何解决 GLSL 1.5 版本和 3.0 ES 版本之间的兼容性问题

3

我最近重新开始着手一个旧的个人项目(我上次最后一次工作是在2年前),这个项目使用GLSL着色器。该项目使用了许多像这样的着色器文件:

Original Answer翻译成"最初的回答"

#version 150

in vec3 color;

out vec4 out_Color;

void main(void){

    out_Color = vec4(color,1.0);

}

使用该文件运行程序时,我遇到了以下错误:

"Original Answer" 翻译成 "最初的回答"

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

我假设在过去的两年里我更新了PC的某些驱动程序,GLSL版本1.5不再受支持。我已尝试使用以下标题中的任何其他版本,每个版本都会报告不同的错误,按照上述支持版本的顺序报告如下:

#version 110:


"最初的回答"
0:3(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL 1.10
0:5(1): error: `out' qualifier in declaration of `out_Color' only valid for function parameters in GLSL 1.10

#version 120:

0:3(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL 1.20
0:5(1): error: `out' qualifier in declaration of `out_Color' only valid for function parameters in GLSL 1.20

#version 130:

0:1(1): error: `in' qualifier in declaration of `position' only valid for function parameters in GLSL 1.10
0:2(1): error: `in' qualifier in declaration of `textureCoordinates' only valid for function parameters in GLSL 1.10
0:4(1): error: `out' qualifier in declaration of `passTextureCoordinates' only valid for function parameters in GLSL 1.10

#版本100:

最初的回答
0:3(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL ES 1.00
0:3(1): error: No precision specified in this scope for type `vec3'
0:5(1): error: `out' qualifier in declaration of `out_Color' only valid for function parameters in GLSL ES 1.00
0:5(1): error: No precision specified in this scope for type `vec4'

#version 300 es:

0:3(1): error: No precision specified in this scope for type `vec3'
0:5(1): error: No precision specified in this scope for type `vec4'

最初的回答:假设不能或不是正确的解决方案只是回到1.5版本,那么现在我需要将我的着色器文件转换成以上某个版本并修复错误。所以这就是我的问题:这样做是正确的方法吗?我真的需要改变GLSL版本,如果是这样的话,哪个版本最好使用?我需要同时更改Java代码吗?或者改变GLSL的版本对我的Java LWJGL代码没有任何影响?
抱歉如果这是一个初学者的问题,而且我可能完全错了,正如我所提到的,我刚回到这个项目。以下是一些关于我当前安装的信息:
glxinfo | grep OpenGL
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile 
OpenGL core profile version string: 3.3 (Core Profile) Mesa 13.0.6
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:
OpenGL version string: 3.0 Mesa 13.0.6
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 13.0.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:

I'm working on debian:

Distributor ID: Debian
Description:    Debian GNU/Linux 9.13 (stretch)
Release:    9.13
Codename:   stretch

我添加了下面的代码以查找项目使用的LWJGL和OpenGL版本:

我添加了下面的代码以查找项目使用的LWJGL和OpenGL版本:

System.out.println("[DEBUG]: OS name " + System.getProperty("os.name"));
System.out.println("[DEBUG]: OS version " + System.getProperty("os.version"));
System.out.println("[DEBUG]: LWJGL version " + org.lwjgl.Sys.getVersion());
System.out.println("[DEBUG]: OpenGL version " + glGetString(GL_VERSION));

最初的回答是:

它的输出为:

[DEBUG]: OS name Linux
[DEBUG]: OS version 4.9.0-4-amd64
[DEBUG]: LWJGL version 3.0.0a
[DEBUG]: OpenGL version 3.0 Mesa 13.0.6

1
你创建了哪个OpenGL上下文?是哪个版本,哪个配置文件?你尝试使用Core Profile了吗?我几乎可以肯定没有任何图形卡支持3.0 ES而不支持150。 - BDL
你是对的,150(OpenGL 3.2)不支持。但是330(OpenGL 3.3)在核心配置文件中是被支持的。根据给定的着色器代码,它应该完全兼容OpenGL 3.3。 - BDL
我已经在问题中添加了LWJGL的版本。我假设我需要更新我的LWJGL版本才能使用OpenGL 3.3,对吗?如果是这样,据我所知,有很多方法已被替换和功能已更改,然后需要在我的Java代码中进行修复... - BRHSM
我相信这归结于调用这些函数: glfwCreateWindow()glfwMakeContextCurrent(window);glfwShowWindow(window); 对于第一个函数,我在此省略了参数,以便阅读,但它只是像高度、宽度和标题之类的东西。在我看来,这个过程中没有任何与核心配置文件有关的内容。如果我提供的信息不正确,请谅解,因为我已经两年没看到这段代码了... 如果您愿意,您也可以在这里查看代码:https://github.com/BRHSM/LWJGL_Engine 它非常杂乱无章,我也想修复它... - BRHSM
你的窗口提示不起作用。它们必须在调用glCreateWindow之前被调用。另外请注意,调试上下文仅适用于OpenGL 4.3及以上版本。我建议您请求主版本3,次版本3,并使用GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE); - BDL
显示剩余4条评论
1个回答

3
你的GPU支持兼容性配置下的OpenGL 3.0或核心配置下的OpenGL 3.3。所请求的版本150(OpenGL 3.2)不受支持。
你的着色器似乎与OpenGL 3.3核心配置兼容,因此我建议使用以下设置:
GLFW.glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
GLFW.glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);

请注意,在调用glCreateWindow之前,必须设置这些窗口提示。

在核心中不要忘记绑定VAO,否则无法绘制。 - genpfault

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接