--- title: WebGLRenderingContext.polygonOffset() slug: Web/API/WebGLRenderingContext/polygonOffset translation_of: Web/API/WebGLRenderingContext/polygonOffset original_slug: Web/API/WebGLRenderingContext/多边形偏移(polygonOffset) ---
The WebGLRenderingContext.polygonOffset()
method of the WebGL API specifies the scale factors and units to calculate depth values.
The offset is added before the depth test is performed and before the value is written into the depth buffer.
void gl.polygonOffset(factor, units);
None.
The polygon offset fill is disabled by default. To enable or disable polygon offset fill, use the {{domxref("WebGLRenderingContext.enable", "enable()")}} and {{domxref("WebGLRenderingContext.disable", "disable()")}} methods with the argument gl.POLYGON_OFFSET_FILL
.
gl.enable(gl.POLYGON_OFFSET_FILL); gl.polygonOffset(2, 3);
想要查看当前多边形偏移的 factor 或 units, 查询 POLYGON_OFFSET_FACTOR
和POLYGON_OFFSET_UNITS
的内容即可.
gl.getParameter(gl.POLYGON_OFFSET_FACTOR); // 2 gl.getParameter(gl.POLYGON_OFFSET_UNITS); // 3
Specification | Status | Comment |
---|---|---|
{{SpecName('WebGL', "#5.14.3", "polygonOffset")}} | {{Spec2('WebGL')}} | Initial definition. |
{{SpecName('OpenGL ES 2.0', "glPolygonOffset.xml", "glPolygonOffset")}} | {{Spec2('OpenGL ES 2.0')}} | Man page of the OpenGL API. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("api.WebGLRenderingContext.polygonOffset")}}