简体   繁体   English

C ++ OpenGL着色版本错误 - 不支持GLSL x [Ubuntu 16.04]

[英]C++ OpenGL shading version error - GLSL x is not supported [Ubuntu 16.04]

I am currently working on a project using OpenGL on Ubuntu 16.04 and have run into a major issue. 我目前正在研究在Ubuntu 16.04上使用OpenGL的项目,并遇到了一个重大问题。 At this point I have no idea what to do as it feels like I have tried everything in order to fix this. 在这一点上,我不知道该怎么做,因为感觉我已经尝试了一切以解决这个问题。

For some reason my shader just won't compile and returns the following error: 由于某种原因,我的着色器不会编译并返回以下错误:

Failed to compile vertex shader!
0:1(10): error: GLSL 4.50 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, 3.00 ES, 3.10 ES, and 3.20 ES`

I have adjusted the version in the shader file without any luck. 我已经调整了着色器文件中的版本而没有任何运气。 #version 450 core etc. but I keep getting the same result. #version 450 core等但我一直得到相同的结果。

For reference, here is the output of sudo glxinfo | grep "OpenGL" 作为参考,这里是sudo glxinfo | grep "OpenGL"的输出 sudo glxinfo | grep "OpenGL" : sudo glxinfo | grep "OpenGL"

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 13.1.0-devel
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 13.1.0-devel
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 13.1.0-devel
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

The output from glxinfo shows OpenGL core 4.5 is installed, so why is this not supported? glxinfo的输出显示安装了OpenGL核心4.5,为什么不支持这个?

I have also tried to find the current version of OpenGL used in the project: std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; 我还试图找到项目中使用的当前版本的OpenGL: std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; which results in a blank return. 这导致空白回报。

I have spent 10 hours on this single issue until now, so any help is appreciated! 到目前为止,我已经在这个问题上花了10个小时,所以任何帮助都表示赞赏!

Edit: Is there a way to force the project/Ubuntu to use OpenGL and not GLSL by ie removing GLSL completely (this part)? 编辑:有没有办法迫使项目/ Ubuntu使用OpenGL而不是GLSL,即完全删除GLSL(这一部分)?

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 13.1.0-devel
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

For anyone else experiencing the same issues, this was the solution that worked for me: 对于遇到相同问题的其他人来说,这是对我有用的解决方案:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Seems like you're not explicitly asking for a core profile context. 好像你没有明确要求核心配置文件上下文。 Your glxinfo output shows, that compatibility profile contexts (there were no "compatibility" profiles before OpenGL-3.0, but that's a moot point for this) are not supported: 您的glxinfo输出显示,不支持兼容性配置文件上下文(在OpenGL-3.0之前没有“兼容性”配置文件,但这是一个有争议的点):

This is telling you that in core profile up to v4.5 is supported: 这告诉您在核心配置文件中支持v4.5:

OpenGL core profile version string: 4.5 (Core Profile) Mesa 13.1.0-devel
OpenGL core profile shading language version string: 4.50
OpenGL core profile profile mask: core profile

… and this does tell you, that the highest version that's not explicitly marked core is going to be OpenGL-3.0: ...这确实告诉你,未明确标记为核心的最高版本将是OpenGL-3.0:

OpenGL version string: 3.0 Mesa 13.1.0-devel
OpenGL shading language version string: 1.30

So either request a core profile or accept that you're stuck to GL-3.0 and below. 因此要么请求核心配置文件,要么接受您坚持使用GL-3.0及以下版本。


Just for comparison, here's how it looks for an OpenGL implementation (NVidia) that does support OpenGL-4.x even outside a core profile: 仅仅为了比较,下面是它如何寻找支持OpenGL-4.x的OpenGL实现(NVidia),甚至在核心配置文件之外:

OpenGL core profile version string: 4.4.0 NVIDIA 367.27
OpenGL core profile shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.5.0 NVIDIA 367.27
OpenGL shading language version string: 4.50 NVIDIA

If you intend to use 4.5 capabilities you need a core profile and that is supported on your system according to this output line 如果您打算使用4.5功能,则需要核心配置文件,并且系统会根据此输出行支持该配置文件

OpenGL core profile version string: 4.5 (Core Profile) Mesa 13.1.0-devel

The other output line 另一条输出线

OpenGL version string: 3.0 Mesa 13.1.0-devel

does not mean that you have two different openGL drivers but that you can afford OpenGL 3.0 tops without core profile. 并不意味着你有两个不同的openGL驱动程序,但你可以买得起没有核心配置文件的OpenGL 3.0 tops。

In order to use the core profile capabilities make sure to enable it as well as compiling your shaders with the correct preprocessor directive 为了使用核心配置文件功能,请确保启用它以及使用正确的预处理器指令编译着色器

// Example using glut for context initialization
glutInitContextVersion(4, 5);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutInit(&argc, argv);

// Shaders
#version 450
...

Try next code in your shader: 在着色器中尝试下一个代码:

"#version 320 es “#version 320 es

precision mediump float; 精密介质浮子;

...your code " ......你的代码“

GLSL is the shader language used by OpenGL although the two version numbers don't always match. GLSL是OpenGL使用的着色器语言,尽管两个版本号并不总是匹配。 From your ourput, it looks like you are using the on Chip Intel GPU. 从您的输出,看起来您正在使用片上Intel GPU。 The driver for this chip qorks through Mesa which as far as I know does not support OpenGL 4 yet. 这个芯片的驱动程序是通过Mesa进行的,据我所知,它还不支持OpenGL 4。

If you have a Nvidia card, you can install the proprietary NVidia driver which does support the latest version of OpenGL. 如果您有Nvidia卡,则可以安装支持最新OpenGL版本的专有NVidia驱动程序。 Otherwise you will need to modify your shaders to use an older version of the language. 否则,您需要修改着色器以使用该语言的旧版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM