题前科普
eglfs是Qt的一个平台插件,使Qt程序可以利用opengl es画图而无需窗口系统. 这种方式是在支持gpu的嵌入式设备主要采用的方式. 一般需要gpu厂商提供egl和gles驱动模块.
Qt可以利用eglfs插件实现直接画图(全屏),或者在有窗口管理系统(如wayland合成器weston或Qtwayland合成器)时,通过窗口画图.前者只能全屏显示一个程序,后者可以实现多进程应用
OpenGL ES (OpenGL for Embedded Systems) 是 OpenGL 三维图形 API 的子集,针对手机、PDA和游戏主机等嵌入式设备而设计。
关于这篇文章我在raspberryPi3 上做了实践
首先环境:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
Linux ubuntu 3.13.0-153-generic #203-Ubuntu SMP Thu Jun 14 08:54:48 UTC 2018 i686 i686 i686 GNU/Linux
raspberryPi3
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch
Linux once 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l GNU/Linux
这里的raspbian 版本跟官方的版本不一样官方的是jessie.但是不对于所用的知识点不大要紧。
按着官方的步骤一步一步的走。
[on RPi]sudo raspi-config 调整配置为the console ,将GPU Memory 该为256Mb
[on RPi] 选择rip-update;
[on RPi] reboot
[on RPi] 1.sudo nano /etc/apt/sources.list 将里面的关于deb-src 的注释掉
2. sudo apt-get update
sudo apt-get build-dep qt4-x11
sudo apt-get build-dep libqt5gui5
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0
[on RPi] sudo mkdir /usr/local/qt5pi ;sudo chown pi:pi /usr/local/qt5pi
现在回顾上面的关于树莓派的准备工作;首先注意下工作环境;
其次在树莓派上配置层上电启动后为终端模式,将GPU 内存设为最大,因为我们要跑个3d OpenGL ;
同时更新树莓派让更改的生效。然后安装好一些运行测试openGL 的库
在创建个qt5pi 为之后同步我们PC机,交叉编译的Qt源码的安装文件
【on host PC】mkdir ~/raspi ;cd ~/raspi ;git clone https://github.com/raspberrypi/tools
【on host PC】mkdir sysroot sysroot/usr sysroot/opt
rsync -avz pi@raspberrypi.local:/lib sysroot
rsync -avz pi@raspberrypi.local:/usr/include sysroot/usr
rsync -avz pi@raspberrypi.local:/usr/lib sysroot/usr
rsync -avz pi@raspberrypi.local:/opt/vc sysroot/opt
raspberrypi.local 为树莓派的ip
【on host PC】wget https://raw.githubusercontent.com/riscv/riscv-poky/priv-1.10/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
【on host PC】git clone git://code.qt.io/qt/qtbase.git -b <qt-version> ; cd qtbase
./configure -release -opengl es2 -device <rpi-version> -device-option CROSS_COMPILE=~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- -sysroot ~/raspi/sysroot -opensource -confirm-license -make libs -prefix /usr/local/qt5pi -extprefix ~/raspi/qt5pi -hostprefix ~/raspi/qt5 -v
这里<qt-version> 我的为v5.9.1 版本;也可去http://download.qt.io/archive/qt/ 下载
<rpi-version> linux-rasp-pi3-g++ 这个主要是这路径下qt-everywhere-opensource-src-5.9.1/qtbase/mkspecs/devices/linux-rasp-pi3-g++$的qmake.conf
还需要加-no-use-gold-linker(For higher Qt version (like 5.9.1) you may also need to add)
如果配置这步成功啦就
make &&make install
在此回顾下前面的pc 机所做的:
1,首先我们去把交叉编译工具下载下来,为编译raspberry 平台的Qt源码和应用做准备;
交叉编译工具要与我们的编译raspberry镜像的一致,不然在configure会出错,
一般用最新的交叉编译和最新的raspberry就一致的
2,然后我们做个文件同步工作,就是把树莓派上的/lib;/usr/include;/usr/lib/;/opt/vc这几个目录的文件搬到PC的sysroot下
其实这里的sysroot 这个文件具体的作用(我只能意会,懂得给我说下)在配置的时候也用到啦。
我的理解是模拟出raspberry的环境,因为我们编译时qt和qt应用可能依赖于树莓派的环境和库。
就像我们在pc上编译qt源码一样,只不过pc 上不要sysroot啦
3,自己看py脚本吧,这个我也没看哈哈照着做
4,说下这configure 配置的参数选项
-release 发行版 -opengl es2 支持openGL api类型为es2 -device <rpi-version> 这个就是生成qmake的配置信息
-device-option CROSS_COMPILE= 交叉编译路径
如果configure 这步出错;唯一的思路是去看config.log ,查错;在解决好后,把config.cache 删啦(这玩意太可恶啦);再重新配置
【on host PC】rsync -avz qt5pi pi@raspberrypi.local:/usr/local
【on host PC】cd qtbase/examples/opengl/qopenglwidget
~/raspi/qt5/bin/qmake
make; scp qopenglwidget pi@raspberrypi.local:/home/pi
这里就把我们安装的qt5pi 同步到之前我们在树莓派mkdir的/usr/local/qt5pi 同步啦
然后在把我们的测试app程序编译出来 放到树莓派上去运行测试
接下来的比较烦;在树莓派上运行去找所需要的库;设置QT 环境变量
这里没有必要看官方文档;我这里给出思路去解决
主要用的是ldd 这个工具来添加,复制,所需要的库到目的路径;
主要是将/opt/vc/lib 的not found 的库做个ln 到/usr/lib/arm-linux-gnueabihf/下;
这里解决的办法有点多也可以添加个环境变量吧/opt/vc/lib 加入到LD_LIBRARY_PATH 里
大概就是这样的拉。