【发布时间】:2018-06-09 05:53:54
【问题描述】:
我正在尝试在没有 GPU 的 Linux 服务器上导出使用 WebGL 渲染的图像。为此,我使用的是无头 Chrome,但导出的图像是黑色的(example exported image、taking a screenshot of page shows its just canvas that is black)。我希望有人帮助我弄清楚为什么会发生这种情况。
要导出图像,我将图像渲染到画布中,通过canvas.toDataURL('image/jpeg') 导出数据,然后将数据发布到服务器。我使用 Pixi.js 进行渲染,如果我使用画布渲染器,那么一切都可以在服务器上运行;这是 WebGL 渲染不起作用。值得注意的是,WebGL 渲染在 Macbook 上的 Chrome 63 中运行良好。
为了控制 Chrome,我使用了Puppeteer。我所做的只是打开一个页面,等待一秒钟,然后再次关闭它:
puppeteer
.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
})
.then(browser => {
return browser.newPage().then(page => {
return page
.goto(url)
.then(() => page.waitFor(1000))
.then(() => browser.close())
.catch(err => console.error('Failed', err));
});
})
这些是 puppeteer 传递给 Chrome 的参数:
[
'--disable-background-networking',
'--disable-background-timer-throttling',
'--disable-client-side-phishing-detection',
'--disable-default-apps',
'--disable-extensions',
'--disable-hang-monitor',
'--disable-popup-blocking',
'--disable-prompt-on-repost',
'--disable-sync',
'--disable-translate',
'--metrics-recording-only',
'--no-first-run',
'--remote-debugging-port=0',
'--safebrowsing-disable-auto-update',
'--enable-automation',
'--password-store=basic',
'--use-mock-keychain',
'--user-data-dir=/tmp/puppeteer_dev_profile-GhEAXZ',
'--headless',
'--disable-gpu',
'--hide-scrollbars',
'--mute-audio',
'--no-sandbox',
'--disable-setuid-sandbox'
]
swiftshader author said in June headless WebGL rendering is possible 似乎是confirmed by this Chromium issue,所以我想我错过了一些东西。有没有人知道我做错了什么?
我尝试过的几件事:
- Not passing in --disable-gpu
-
--use-gl=swiftshader-webgl,--use-gl=swiftshader,--use-gl=osmesa - 全屏截图看看它是否只是画布。整个屏幕都是黑色的。
版本
- Chrome:linux-515411
- 傀儡师:0.13.0
- 节点:8.2.1
- Linux:CentOS 7
这是我需要在我的服务器上安装才能运行 chrome (Source)
yum install cups-libs dbus-glib libXrandr libXcursor libXinerama cairo cairo-gobject pango ffmpeg
rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/atk-2.22.0-3.el7.x86_64.rpm
rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/at-spi2-atk-2.22.0-2.el7.x86_64.rpm
rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/at-spi2-core-2.22.0-1.el7.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/g/GConf2-3.2.6-7.fc20.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libXScrnSaver-1.2.2-6.fc20.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libxkbcommon-0.3.1-1.fc20.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libwayland-client-1.2.0-3.fc20.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libwayland-cursor-1.2.0-3.fc20.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/g/gtk3-3.10.4-1.fc20.x86_64.rpm
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/16/Fedora/x86_64/os/Packages/gdk-pixbuf2-2.24.0-1.fc16.x86_64.rpm
【问题讨论】:
-
你能提供更多关于你的硬件配置的细节吗? AFAIK,WebGL 确实需要 GPU。许多(大多数?)最近的计算机确实包含英特尔“集成图形”形式的 GPU,如果您不过度推动它们,这对于 3D 渲染来说绰绰有余,但是没有 GPU 访问权限的 VM 将是一个问题。 ..
-
我们的服务器没有 GPU。有很多文档表明它是可能的:“SwiftShader 是基于 CPU 的高性能 OpenGL ES 实现”(github.com/google/swiftshader)blog.chromium.org/2016/06/…。添加 Swiftshader bugs.chromium.org/p/chromium/issues/detail?id=630728 的 Chromium 问题。 Chromium 文档讨论 GPU 不可用时的软件合成器chromium.org/developers/design-documents/…
-
你真的安装了 Swiftshader 吗?在您的帖子中没有看到任何关于此的内容?另外,你有办法捕获 Chrome 的控制台吗?
-
将 --disable-gpu 传递给我的 chrome 选项允许我呈现一个 html 画布饼图。非常感谢您的提示!
-
我运行的服务(无浏览器)似乎没有 WebGL 的问题(除了速度慢,但这完全取决于您分配的资源)。你可以看一个例子here。
标签: javascript google-chrome webgl pixi.js puppeteer