问题缘由:

在WSL2 Ubuntu20.04中使用sudo add-apt-repository ppa:kisak/kisak-mesasudo apt update && sudo apt upgrade更新OpenGL,更新前后OpenGL依然是1.4版本:OpenGL version string: 1.4 (2.1 Mesa 10.5.4),而最新版的OpenGL实际可以达到4.2版本:OpenGL version string: 4.2 (Compatibility Profile) Mesa 22.1.1 - kisak-mesa PPA

最原始的问题是在ROS2中运行rviz出现下面的错误:

[ERROR] [1654302833.739499814] [rviz2]: rviz::RenderSystem: error creating render window: InvalidParametersException: Window with name 'OgreWindow(0)' already exists in GLRenderSystem::_createRenderWindow at /tmp/binarydeb/ros-foxy-rviz-ogre-vendor-8.2.6/obj-x86_64-linux-gnu/ogre-v1.12.1-prefix/src/ogre-v1.12.1/RenderSystems/GL/src/OgreGLRenderSystem.cpp (line 1061)
[ERROR] [1654302833.739520104] [rviz2]: Unable to create the rendering window after 100 tries

经了解,这个问题产生的原因是OpenGL版本太低,使用glxinfo -B查看显示OpenGL版本为1.4

问题梳理及解决:

OpenGL有四种不同的渲染方式,分别是直接软件渲染、直接硬件渲染、间接软件渲染、间接硬件渲染。其中直接硬件渲染方式的效率最高,其次是间接硬件渲染,这部分的内容可以参阅How to tell whether your setup is good,里面简要的介绍了这四种方式的好坏。

现在打开WSL2 Ubuntu终端,输入glxinfo -B,这条命令会告诉你关于OpenGL的相关信息,我电脑上最初的输出如下:

name of display: localhost:10.0
display: localhost:10  screen: 0
direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
OpenGL vendor string: Mesa Project
OpenGL renderer string: Software Rasterizer
OpenGL version string: 1.4 (2.1 Mesa 10.5.4)

direct rendering: No表示采用的是间接渲染,OpenGL renderer string: Software Rasterizer表示OpenGL的渲染方式是软件渲染。这种方式效率最低。

这和我们的问题有什么关系呢?你可以运行LIBGL_ALWAYS_INDIRECT=0将渲染方式由间接改为直接,再运行glxinfo -B,你会发现输出结果和之前完全不一样:

$ LIBGL_ALWAYS_INDIRECT=0
$ glxinfo -B
name of display: localhost:12.0
display: localhost:12  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):Vendor: Microsoft Corporation (0xffffffff)Device: D3D12 (NVIDIA GeForce MX450) (0xffffffff)Version: 22.0.1Accelerated: yesVideo memory: 10011MBUnified memory: noPreferred profile: core (0x1)Max core profile version: 3.3Max compat profile version: 3.3Max GLES1 profile version: 1.1Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce MX450)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 22.0.1
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 3.3 (Compatibility Profile) Mesa 22.0.1
OpenGL shading language version string: 3.30
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 22.0.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

这时direct rendering: Yes表示采用直接渲染,同时OpenGL renderer string: D3D12 (NVIDIA GeForce MX450)表示采用硬件渲染。更重要的是,OpenGL的版本OpenGL version string: 3.3 (Compatibility Profile) Mesa 22.0.1,在这个过程中我只修改了OpenGL的渲染方式:由间接到直接。

我猜测这个结果的原因是OpenGL采用不同的渲染方式时,会采用不同的软件库。

如果你需要进一步的升级OpenGL,比如升级到4.2版本,则可以尝试如下命令:

sudo add-apt-repository ppa:kisak/kisak-mesa
sudo apt update && sudo apt upgrade

更新后再次使用glxinfo -B,输出结果如下:

name of display: localhost:10.0
display: localhost:10  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):Vendor: Microsoft Corporation (0xffffffff)Device: D3D12 (NVIDIA GeForce MX450) (0xffffffff)Version: 22.1.1Accelerated: yesVideo memory: 10011MBUnified memory: noPreferred profile: core (0x1)Max core profile version: 4.2Max compat profile version: 4.2Max GLES1 profile version: 1.1Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce MX450)
OpenGL core profile version string: 4.2 (Core Profile) Mesa 22.1.1 - kisak-mesa PPA
OpenGL core profile shading language version string: 4.20
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.2 (Compatibility Profile) Mesa 22.1.1 - kisak-mesa PPA
OpenGL shading language version string: 4.20
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 22.1.1 - kisak-mesa PPA
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

在这个过程中我有一个地方没有搞懂,LIBGL_ALWAYS_SOFTWARE变量是用来干嘛的,我将其设置为0或1后再执行glxinfo -B,输出结果没什么变化。
参考链接:
Github上相关的issue

在WSL2中开启OpenGL直接渲染以及升级OpenGL相关推荐

  1. viewpager初始化fragment没有绘制_NDK OpenGL ES渲染系列 之 绘制三角形

    前言 新的知识学习都是循序渐进的,从基础到复杂.前面OpenGL ES概念 已经介绍了OpenGL ES的相关概念,这篇文章开始我们就正式开始OpenGL ES渲染系列第一站---绘制三角形.绘制三角 ...

  2. C#中使用OpenGL(API)创建OpenGL渲染环境

    在C#中调用1.1版本的OpenGL函数,但是光有OpenGL函数还不能绘制图形,就像一个画家,他即使拥有绘画的技巧,还有画笔和颜料,如果没有画布,他也没有地方画画.有了画布,画家还需要画板把画布支起 ...

  3. 基于Surface的视频编解码与OpenGL ES渲染

    http://blog.csdn.net/gh_home/article/details/52399959 1. 概述 这篇文章所做的事情是这样的:  1. 从一个.mp4文件中解码视频流到surfa ...

  4. OpenGL基础渲染

    基础图形管线 客户端-服务器 着色器 创建坐标系 使用存储着色器 存储着色器的分类 将点连接起来 点和线 单独的三角形 一个简单的批次容器 不希望出现的图形 多边形偏移 裁剪 混合 多重采样 基础图形 ...

  5. Android OpenGL+Camera2渲染(3) —— 大眼,贴纸功能实现

    Android OpenGL+Camera2渲染(1) -- OpenGL简单介绍 Android OpenGL+Camera2渲染(2) -- OpenGL实现Camera2图像预览 Android ...

  6. Android硬件加速(二)-RenderThread与OpenGL GPU渲染

    Android4.0之后,系统默认开启硬件加速来渲染视图,之前,理解Android硬件加速的小白文简单的讲述了硬件加速的简单模型,不过主要针对前半阶段,并没怎么说是如何使用OpenGL.GPU处理数据 ...

  7. OpenGL文字渲染

    一.简介 由于OpenGL本身并没有定义如何渲染文字到屏幕,也没有用于表示文字的基本图形,我们必须自己定义一套全新的方式才能让OpenGL来绘制文字.目前一些技术包括:通过GL_LINES来绘制字形. ...

  8. OpenGL渲染模型 || 3. opengl 将模型成渲染图片

    前言 最近项目中需要使用到OpenGL对3D模型进行渲染. 已有数据为: 带纹理的3D模型 模型上的关键点.   需要实现的功能: 读取和保存 带纹理的3D模型.读取模型的关键点 对模型进行渲染,保存 ...

  9. Android OpenGL+Camera2渲染(2) —— OpenGL实现Camera2图像预览

    Android OpenGL+Camera2渲染(1) -- OpenGL简单介绍 Android OpenGL+Camera2渲染(2) -- OpenGL实现Camera2图像预览 Android ...

最新文章

  1. 2021-04-06 符号执行是啥?
  2. Tomcat8中的并发ConcurrentDateFormat的实现
  3. Linux:几个重要的文件处理命令
  4. 简述C语言的标准发展,简述C语言的发展历史
  5. onenote组织知识体系_我们的家人教给我们有关组织生活的知识
  6. python 读取jpg文件是yuv_Python读取YUV文件,并显示的方法
  7. selenium API
  8. 人工智能与人的职业发展
  9. Intellij IDEA 看源码必备的技能!
  10. c#怎么拟合函数得到参数_c#怎么拟合函数得到参数_最小二乘法拟合任意次曲线(C#)...
  11. 关于Spring Cloud Config服务器介绍
  12. Spring JdbcTemplate 模板剖析 之 常用 增删改查
  13. Segment Routing MPLS介绍
  14. win10怎么用记事本打开html文件,Win10系统怎么打开记事本
  15. 如何实现一个高速文件下载器
  16. linux 解压war到root_解压war包的解压软件 war包可以用解压工具解开吗
  17. PPT计算机辅助教学,教学ppt课件制作的几点心得
  18. 对于提高团队开会效率的看法
  19. firefox os android,若能同时使用Android应用,那么你可以接受Firefox OS手机了吗?
  20. python输出到文件里

热门文章

  1. 小米9pro textView不设置颜色不显示_小米万象息屏2.0内测开启,新增小组件功能和新息屏...
  2. 论文翻译:2020_DCCRN: Deep Complex Convolution Recurrent Network for Phase-Aware Speech Enhancement...
  3. 【计算机毕业设计】基于JSP的房产中介系统的设计与实现
  4. 崮云湖街道:“钉钉子”精神破译发展密码
  5. 报错remove Directory not empty
  6. 更改CAD的绘图单位及精度怎么操作??
  7. 超简单利用java实现猜数字大小游戏2
  8. WordPress 3.9'Smith'发布:包括许多新功能{InfoGraphic}
  9. EDA技术的概念及范畴
  10. XMind 8 Pro 3.7.8 最受欢迎思维导图