WebGLRenderingContext.getContextAttributes()
getContextAttributes方法返回一个WebGLContextAttributes对象,包含实际的上下文参数。如果上下文丢失可能返回null。
语法
gl.getContextAttributes();
返回值
返回一个WebGLContextAttributes对象,包含实际的上下文参数。如果上下文丢失可能返回null。
例子
给到<canvas>元素
<canvas id="canvas"></canvas>
给到WebGL上下文
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
gl.getContextAttributes();
getContextAttributes方法返回一个对象,可描述此上下文设置的属性,例如:
{
alpha: true,
antialias: true,
depth: true,
failIfMajorPerformanceCaveat: false,
premultipliedAlpha: true,
preserveDrawingBuffer: false,
stencil: false
}
上下文属性可以在创建它时使用HTMLCanvasElement.getContext()办法对其设置
canvas.getContext("webgl",
{ antialias: false,
depth: false });
更多各个属性的详细信息,参见getContext
规范
浏览器兼容
Desktop:Chrome 9、 Firefox 4.0 、 Internet Explorer 11 、Opera 12、Safari 5.1;
Mobile: Android (Yes)、 Chrome for Android 25、 Firefox Mobile 4.0、 IE Mobile (Yes)、 Opera Mobile 12、 Safari Mobile 8.1