files/en-us/web/api/webglrenderingcontext/bindtexture/index.md
{{APIRef("WebGL")}}{{AvailableInWorkers}}
The WebGLRenderingContext.bindTexture() method of the WebGL API binds a given
{{domxref("WebGLTexture")}} to a target (binding point).
bindTexture(target, texture)
target
: A {{domxref("WebGL_API/Types", "GLenum")}} specifying the binding point (target). Possible values:
gl.TEXTURE_2D
gl.TEXTURE_CUBE_MAP
When using a {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}}, the following values are available additionally:
gl.TEXTURE_3D
gl.TEXTURE_2D_ARRAY
texture
null is passed, the currently bound texture for the specified target is unbound.None ({{jsxref("undefined")}}).
A gl.INVALID_ENUM error is thrown if target is not
gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP,
gl.TEXTURE_3D, or gl.TEXTURE_2D_ARRAY.
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Unbind any texture currently bound to TEXTURE_2D
gl.bindTexture(gl.TEXTURE_2D, null);
To check the current texture binding, query the gl.TEXTURE_BINDING_2D or
gl.TEXTURE_BINDING_CUBE_MAP constants.
gl.getParameter(gl.TEXTURE_BINDING_2D);
{{Specifications}}
{{Compat}}