EN
Il contenuto non è disponibile nella lingua di destinazione, ma solo in inglese.

getShaderParameter method

Returns the value of the parameter associated with pname for a shader object.

IE11

 

Syntax

var retVal = WebGLRenderingContext.getShaderParameter(shader, pname);

Parameters

shader [in]

Type: WebGLShader

The shader object to query.

pname [in]

Type: Number

The parameter to look up. See below

Return value

Type: any

Value of pname. See below

Remarks

pnamereturned type
gl.SHADER_TYPENumber
gl.DELETE_STATUSBoolean
gl.COMPILE_STATUSBoolean

 

Examples

This example creates and compiles a shader. It uses getShaderParameter with gl.COMPILE_STATUS as the pname to see if the shader compiled successfully. For more info on this example, see Get started with WebGL.


// Loads a shader from a script tag
// Parameters:
//   WebGL context
//   id of script element containing the shader to load
function getShader(gl, id) {
  var shaderScript = document.getElementById(id);

  // error - element with supplied id couldn't be retrieved
  if (!shaderScript) {
    return null;
  }

  // If successful, build a string representing the shader source
  var str = "";
  var k = shaderScript.firstChild;
  while (k) {
    if (k.nodeType == 3) {
      str += k.textContent;
    }
    k = k.nextSibling;
  }

  var shader;

  // Create shaders based on the type we set
  //   note: these types are commonly used, but not required
  if (shaderScript.type == "x-shader/x-fragment") {
    shader = gl.createShader(gl.FRAGMENT_SHADER);
  } else if (shaderScript.type == "x-shader/x-vertex") {
    shader = gl.createShader(gl.VERTEX_SHADER);
  } else {
    return null;
  }

  gl.shaderSource(shader, str);
  gl.compileShader(shader);

  // Check the compile status, return an error if failed
  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
    console.log(gl.getShaderInfoLog(shader));
    return null;
  }

  return shader;
}



See also

WebGLRenderingContext
getShaderParameter

 

 

Mostra:
© 2014 Microsoft