AFrame 指定 WebGL 版本

AFrame specify WebGL version

AFrame 1.1.0 使用 THREE.js 123,现在默认使用 WebGL2。
一些 AFrame 组件还不能与 WebGL2 一起工作。如果我们可以将 AFrame 与 WebGL1 一起使用,那就太好了。 THREE.js 仍然支持 WebGL1 渲染。

创建渲染器时,您可以从中pass your own canvas and context to the constructor, instead of letting the engine create its own. So you could simply grab the <canvas> HTMLElement, request a WebGL1 context,并在初始化渲染器时使用它们:

var myCanvas = document.getElementById('myCanvas');
var gl = canvas.getContext('webgl');

var renderer = new WebGLRenderer({
    canvas: myCanvas,
    context: gl
});

根据 AFrame 的维护者的说法,目前 1.1.0 无法做到这一点。

AFrame 在 a-scene.js setupCanvas() 中创建了它自己的 canvas,所以你不能在已经设置了 webgl1 上下文的情况下传入一个。

我们最终为我们自己的 AFrame 版本打了补丁。您可以在此处查看使用 renderer 系统指定是否使用 WebGL2 与 WebGL1 的逻辑。

https://github.com/8thwall/8frame/commit/533c4304f20153834a85f60a19e161e61ce71ec6

即使有了补丁,webgl1 在着色器 GLSL 兼容性方面仍然存在问题。