简体   繁体   English

SFML 2.5.1 - 不支持几何着色器,Ubuntu 22.04,NVIDIA GeForce RTX Mobile

[英]SFML 2.5.1 - Geometry shaders are not supported, Ubuntu 22.04, NVIDIA GeForce RTX Mobile

After changing the operating system, I could no longer use the SFML geometry shader and always got the following error:换操作系统后,无法再使用SFML几何着色器,总是报如下错误:

Failed to create a shader: your system doesn't support geometry shaders 
(you should test Shader::isGeometryAvailable() before trying to use geometry shader

Oddly enough, the isAvailable() function, which checks if the system supports shaders at all, returned true and got me thinking that my system really doesn't support geometry shaders.奇怪的是,用于检查系统是否完全支持着色器的isAvailable() function 返回true ,让我认为我的系统确实不支持几何着色器。

Although I knew that my system supports this kind of shaders.虽然我知道我的系统支持这种着色器。 To prove this, one can type the command glxinfo and search for some kind of geometry shader.为了证明这一点,可以键入命令glxinfo并搜索某种几何着色器。 If the command is not recognized, you can install it with:如果无法识别该命令,您可以使用以下命令安装它:

$ sudo apt-get install mesa-utils

Finally, when I grep the information for something like "geometry", I get the following output.最后,当我 grep 诸如“几何”之类的信息时,我得到以下 output。

$ glxinfo | grep geometry
GL_EXT_float_blend, GL_EXT_frag_depth, GL_EXT_geometry_point_size, 
GL_EXT_geometry_shader, GL_EXT_gpu_shader5, GL_EXT_map_buffer_range, 
GL_OES_geometry_point_size, GL_OES_geometry_shader,

Here you can see that the geometry shader is indeed supported by my system and there is no driver error or something not installed, as my Ubuntu drivers are already all up to date:在这里你可以看到我的系统确实支持几何着色器并且没有驱动程序错误或未安装的东西,因为我的 Ubuntu 驱动程序已经全部是最新的:

$ ubuntu-drivers autoinstall
All the available drivers are already installed.

So it must indeed be an SFML 2.5.1 problem, since other people such as.所以它一定确实是一个 SFML 2.5.1 问题,因为其他人如。 @mabel have stumbled over this problem. @mabel 偶然发现了这个问题。

The final workaround I found out was indeed a bug or rather an upward compatibility issue with SFML 2.5.1.我发现的最终解决方法确实是一个错误,或者更确切地说是与 SFML 2.5.1 的向上兼容性问题。 As stated above glxinfo only returned the geometry shader GL_EXT_gpu_shader5 .如上所述, glxinfo仅返回几何着色器GL_EXT_gpu_shader5

The version is importatnt then since in the SFML Shader Code in the file located in src/SFML/Graphics/Shader.cpp it can be observed the follwogin code snippet:版本很重要,因为在位于src/SFML/Graphics/Shader.cpp的文件中的 SFML 着色器代码中,可以观察到以下代码片段:

bool Shader::isGeometryAvailable()
{
    std::lock_guard lock(isAvailableMutex);

    static bool checked   = false;
    static bool available = false;

    if (!checked)
    {
        checked = true;

        TransientContextLock contextLock;

        // Make sure that extensions are initialized
        sf::priv::ensureExtensionsInit();

        available = isAvailable() && (GLEXT_geometry_shader4 || GLEXT_GL_VERSION_3_2);
    }

    return available;
}

Here you can clearly see that only the macro of GLEXT_geometry_shader4 and GLEXT_GL_VERSION_3_2 is checked.这里可以清楚的看到,只勾选了GLEXT_geometry_shader4GLEXT_GL_VERSION_3_2的宏。 Therefore, the geometry shader version I used is not checked at all and the function eventually returns false , leading to the exit of the program in the following code snippet:因此,根本没有检查我使用的几何着色器版本, function 最终返回false ,导致程序在以下代码片段中退出:

// Make sure we can use geometry shaders
if (geometryShaderCode && !isGeometryAvailable())
{
  err() << "Failed to create a shader: your system doesn't support geometry shaders "
        << "(you should test Shader::isGeometryAvailable() before trying to use geometry shaders)" << std::endl;
  return false;
}

Finally I removed the last part of the line wich checks if the geometry shader is available, resulting in:最后,我删除了检查几何着色器是否可用的行的最后一部分,结果是:

available = isAvailable();

Attention!注意力! This is just a workaround I just found and want to share with you.这只是我刚刚发现并想与您分享的解决方法。 It's not an unversal solution and can get you into trouble if your system really doesn't support geometry shaders.这不是一个通用的解决方案,如果您的系统真的不支持几何着色器,它可能会给您带来麻烦。

After changing this line of code, I recreated SFML for myself using CMake. So the very normal procedure:更改这行代码后,我使用 CMake 为自己重新创建了 SFML。所以非常正常的过程:

$ cmake -S . -B build/ -D CMAKE_BUILD_TYPE=Release
$ cmake --build build/
$ sudo cmake --install build/

Then it was finally possible to link the SFML libraries to my executable without getting the mentioned error.然后终于可以将 SFML 库链接到我的可执行文件而不会出现上述错误。 For further use, this should be an update to make systems using only GL_EXT_gpu_shader5 compatible with SFML.为了进一步使用,这应该是一个更新,使仅使用GL_EXT_gpu_shader5的系统与 SFML 兼容。

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

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