WebGLRenderingContext: depthFunc() method

Note: This feature is available in Web Workers.

The WebGLRenderingContext.depthFunc() method of the WebGL API specifies a function that compares incoming pixel depth to the current depth buffer value.

Syntax

js
depthFunc(func)

Parameters

func

A GLenum specifying the depth comparison function, which sets the conditions under which the pixel will be drawn. The default value is gl.LESS. Possible values are:

Return value

None (undefined).

Examples

The depth testing is disabled by default. To enable or disable depth testing, use the enable() and disable() methods with the argument gl.DEPTH_TEST.

js
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.NEVER);

To check the current depth function, query the DEPTH_FUNC constant.

js
gl.getParameter(gl.DEPTH_FUNC) === gl.NEVER;
// true

Specifications

See also