如何使用Javascript获取OpenGL版本? [英] How to get OpenGL version using Javascript?

查看:601
本文介绍了如何使用Javascript获取OpenGL版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让浏览器返回opengl版本字符串?

Is there any way to let the browser returns the opengl version string?

我知道浏览器没有执行opengl,这就是为什么在代码中,着色器被写为字符串,不会导致javascript语法错误,

I know that opengl is not executed by the browser, this is why in the code, the shaders are written as string to not make javascript syntax errors,

因此,如果浏览器可以与GPU交互,那么必须有一些代码返回一个字符串控制台而不是着色器?

So, if the browser can interract with the GPU, then there must be some code that returns a string to the console instead of shaders?

推荐答案

简短的回答是,你做不到。您可以要求标准的GL版本。

The short answer is, you can't. You can ask for the standard GL versions.

const gl = document.createElement("canvas").getContext("webgl");
console.log(gl.getParameter(gl.VERSION));
console.log(gl.getParameter(gl.SHADING_LANGUAGE_VERSION));
console.log(gl.getParameter(gl.VENDOR));

但目前他们需要在WebGL的所有实现上返回类似的值。例如,在我的机器上,他们返回

But at the moment they are required to return similar values on all implementations of WebGL. For example on my machine they return

WebGL 1.0 (OpenGL ES 2.0 Chromium) 
WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium) 
WebKit 

分别为。

他们应该返回这些特定值的原因是出于隐私原因。如果您能找到某人GPU的供应商,那么您可以将其用作更多信息来识别它们。 (有关使用浏览器信息唯一标识特定内容的示例,请参阅 https://panopticlick.eff.org/ 机器。)

The reason they are supposed to return these specific values is for privacy reasons. If you could find out the vendor of someone's GPU then you could use that as more information to identify them. (see https://panopticlick.eff.org/ for examples of using browser info to uniquely identify a specific machine.)

Apple甚至指出,如果您知道GPU的供应商和型号,那么您可以知道是否有人最近购买了MacPro以来的MacPro一个没有其他地方可用的GPU。例如,您可以定位广告。 嘿,我看到你的GPU上有7000美元的电脑。你觉得这个昂贵的度假套餐怎么样?

Apple has even pointed out that if you knew the vendor and model number of the GPU then you could for example know if someone recently bought a MacPro since MacPro's have a GPU that is available no where else. So for example you could target ads at them. "Hey, I see based on your GPU you have an $7000 computer. How'd you like this expensive vacation package?"

谷歌已决定另一方面我们认为这是一个问题所以他们决定打开原本应该是特权的WebGL扩展(这意味着只能通过特殊的启用来测试)。该扩展名是 WEBGL_debug_renderer_info 扩展名( http://www.khronos.org/registry/webgl/extensions/WEBGL_debug_renderer_info/

Google has decided on the other hand they don't see that as a problem and so they've decided to turn on a WebGL extension what was originally supposed to be privileged (meaning only available by special enabling for things like testing). That extension is the WEBGL_debug_renderer_info extension (http://www.khronos.org/registry/webgl/extensions/WEBGL_debug_renderer_info/)

首先使用它,你必须检查它是否可用,如果是,则可以获得实际的供应商和渲染器。

To use it first you have to check if it's available, then if it is, you can get the actual vendor and renderer.

// try to get the extensions
const ext = gl.getExtension("WEBGL_debug_renderer_info");

// if the extension exists, find out the info.
if (ext) {
  console.log(gl.getParameter(ext.UNMASKED_VENDOR_WEBGL));
  console.log(gl.getParameter(ext.UNMASKED_RENDERER_WEBGL));
}

当我在我的机器上运行时,我得到了

When I run that on my machine I get

NVIDIA Corporation
NVIDIA GeForce GT 650M OpenGL Engine 

const gl = document.createElement("canvas").getContext("webgl");
// try to get the extensions
const ext = gl.getExtension("WEBGL_debug_renderer_info");

// if the extension exists, find out the info.
if (ext) {
  console.log(gl.getParameter(ext.UNMASKED_VENDOR_WEBGL));
  console.log(gl.getParameter(ext.UNMASKED_RENDERER_WEBGL));
}

注意:最近检查2017年8月1日这在Firefox 54,Safari 10.1.2,Chrome 59中可用,所以我猜其他浏览器已经决定公开

note: Checked recently 2017-Aug-1 This is available in Firefox 54, Safari 10.1.2, Chrome 59 so I guess the other browsers have decided it was important to expose

这篇关于如何使用Javascript获取OpenGL版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆