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/attachshader/index.html | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/zh-cn/web/api/webglrenderingcontext/attachshader/index.html (limited to 'files/zh-cn/web/api/webglrenderingcontext/attachshader') diff --git a/files/zh-cn/web/api/webglrenderingcontext/attachshader/index.html b/files/zh-cn/web/api/webglrenderingcontext/attachshader/index.html new file mode 100644 index 0000000000..c91262824e --- /dev/null +++ b/files/zh-cn/web/api/webglrenderingcontext/attachshader/index.html @@ -0,0 +1,95 @@ +--- +title: WebGLRenderingContext.attachShader() +slug: Web/API/WebGLRenderingContext/attachShader +translation_of: Web/API/WebGLRenderingContext/attachShader +--- +
{{APIRef("WebGL")}}
+ +

WebGL API  的 WebGLRenderingContext.attachShader() 方法负责往 {{domxref("WebGLProgram")}} 添加一个片段或者顶点着色器。

+ +

语法

+ +
void gl.attachShader(program, shader);
+
+ +

参数

+ +
+
program
+
一个 {{domxref("WebGLProgram")}} 对象
+
shader
+
一个类型为片段或者顶点的 {{domxref("WebGLShader")}}
+
+ +

示例

+ +

以下代码为 {{domxref("WebGLProgram")}} 添加一个预先定义好的着色器。

+ +
var program = gl.createProgram();
+
+// 添加一个预先定义的着色器
+gl.attachShader(program, vertexShader);
+gl.attachShader(program, fragmentShader);
+
+gl.linkProgram(program);
+
+if ( !gl.getProgramParameter( program, gl.LINK_STATUS) ) {
+  var info = gl.getProgramInfoLog(program);
+  throw "Could not compile WebGL program. \n\n" + info;
+}
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
规范状态注释
{{SpecName('WebGL', "#5.14.9", "attachShader")}}{{Spec2('WebGL')}}Initial definition.
{{SpecName('OpenGL ES 2.0', "glAttachShader.xml", "glAttachShader")}}{{Spec2('OpenGL ES 2.0')}}OpenGL man page.
+ +

浏览器兼容性

+ + + +

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

+ +

相关资料

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