WebGLRenderingContext.attachShader()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

La méthode WebGLRenderingContext.attachShader() de l'API WebGL attache un WebGLShader de fragment ou de sommet à un WebGLProgram.

Syntaxe

js
void gl.attachShader(programme, shader);

Paramètres

programme

Un WebGLProgram.

shader

Un WebGLShader de fragment ou de sommet.

Exemples

Le code suivant attache des shaders pré-existants à un WebGLProgram.

js
var programme = gl.createProgram();

// Attacher des shaders pré-existants
gl.attachShader(programme, shaderDeSommet);
gl.attachShader(programme, shaderDeFragment);

gl.linkProgram(programme);

if (!gl.getProgramParameter(programme, gl.LINK_STATUS)) {
  var info = gl.getProgramInfoLog(programme);
  throw "Impossible de compiler le program WebGL. \n\n" + info;
}

Spécifications

Specification
WebGL Specification
# 5.14.9

Compatibilité des navigateurs

Voir aussi