From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../webglrenderingcontext/bindtexture/index.html | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 files/zh-cn/web/api/webglrenderingcontext/bindtexture/index.html (limited to 'files/zh-cn/web/api/webglrenderingcontext/bindtexture') diff --git a/files/zh-cn/web/api/webglrenderingcontext/bindtexture/index.html b/files/zh-cn/web/api/webglrenderingcontext/bindtexture/index.html new file mode 100644 index 0000000000..2124e54091 --- /dev/null +++ b/files/zh-cn/web/api/webglrenderingcontext/bindtexture/index.html @@ -0,0 +1,117 @@ +--- +title: WebGLRenderingContext.bindTexture() +slug: Web/API/WebGLRenderingContext/bindTexture +tags: + - API + - Method + - Reference + - Textures + - WebGL + - WebGLRenderingContext +translation_of: Web/API/WebGLRenderingContext/bindTexture +--- +
{{APIRef("WebGL")}}
+ +

WebGL API 的 WebGLRenderingContext.bindTexture() 方法将给定的 {{domxref("WebGLTexture")}} 绑定到目标(绑定点)。

+ +

语法

+ +
void gl.bindTexture(target, texture);
+
+ +

参数

+ +
+
target
+
{{domxref("GLenum")}} 指定绑定点(目标)。 可能的值: +
    +
  • gl.TEXTURE_2D: 二维纹理。
  • +
  • gl.TEXTURE_CUBE_MAP: 立方体映射纹理。
  • +
  • 当使用 {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}} 时,可以使用以下值: +
      +
    • gl.TEXTURE_3D: 三维纹理.
    • +
    • gl.TEXTURE_2D_ARRAY: 二维数组纹理.
    • +
    +
  • +
+
+
texture
+
要绑定的 {{domxref("WebGLTexture")}} 对象。
+
+ +

返回值

+ +

无。

+ +

异常

+ +

如果目标不是 gl.TEXTURE_2D ,gl.TEXTURE_CUBE_MAP,gl.TEXTURE_3D 或 gl.TEXTURE_2D_ARRAY ,则会抛出 gl.INVALID_ENUM 错误。

+ +

示例

+ +

绑定纹理

+ +
var canvas = document.getElementById('canvas');
+var gl = canvas.getContext('webgl');
+var texture = gl.createTexture();
+
+gl.bindTexture(gl.TEXTURE_2D, texture);
+
+ +

获取当前绑定

+ +

要检查当前纹理绑定,请查询gl.TEXTURE_BINDING_2D或gl.TEXTURE_BINDING_CUBE_MAP常量。

+ +
gl.getParameter(gl.TEXTURE_BINDING_2D);
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('WebGL', "#5.14.8", "bindTexture")}}{{Spec2('WebGL')}}WebGL初始定义。
{{SpecName('OpenGL ES 2.0', "glBindTexture.xml", "glBindTexture")}}{{Spec2('OpenGL ES 2.0')}}OpenGL ES 2.0 API手册(类似).
{{SpecName('WebGL2', "#3.7.1", "bindTexture")}}{{Spec2('WebGL2')}}WebGL 2更新定义。
+ 增加: gl.TEXTURE_3D and gl.TEXTURE_2D_ARRAY
{{SpecName('OpenGL ES 3.0', "glBindTexture.xhtml", "glBindTexture")}}{{Spec2('OpenGL ES 3.0')}}OpenGL ES 3.0 API手册(类似)。
+ +

浏览器兼容性

+ + + +

{{Compat("api/WebGLRenderingContext", "WebGLRenderingContext.bindTexture")}}

+ +

另见

+ + + + -- cgit v1.2.3-54-g00ecf