[ACCEPTED]-How to get OpenGL version using Javascript?-webgl
The short answer is, you can't. You can 32 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));
But at 31 the moment they are required to return similar 30 values on all implementations of WebGL. For 29 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
Respectively.
The 28 reason they are supposed to return these 27 specific values is for privacy reasons. If 26 you could find out the vendor of someone's 25 GPU then you could use that as more information 24 to identify them. (see https://panopticlick.eff.org/ for examples of 23 using browser info to uniquely identify 22 a specific machine.)
Apple has even pointed 21 out that if you knew the vendor and model 20 number of the GPU then you could for example 19 know if someone recently bought a MacPro 18 since MacPro's have a GPU that is available 17 no where else. So for example you could 16 target ads at them. "Hey, I see based 15 on your GPU you have an $7000 computer. How'd 14 you like this expensive vacation package?"
Google 13 has decided on the other hand they don't 12 see that as a problem and so they've decided 11 to turn on a WebGL extension what was originally 10 supposed to be privileged (meaning only available 9 by special enabling for things like testing). That 8 extension is the WEBGL_debug_renderer_info
extension (http://www.khronos.org/registry/webgl/extensions/WEBGL_debug_renderer_info/)
To use it 7 first you have to check if it's available, then 6 if it is, you can get the actual vendor 5 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 4 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));
}
note: Checked recently 2017-Aug-1 This 3 is available in Firefox 54, Safari 10.1.2, Chrome 2 59 so I guess the other browsers have decided 1 it was important to expose
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.