Class GLShader

a base GL Shader object

Constructors

  • Parameters

    • gl: WebGLRenderingContext

      the current WebGL rendering context

    • vertex: string

      a string containing the GLSL source code to set

    • fragment: string

      a string containing the GLSL source code to set

    • Optionalprecision: string

      float precision ('lowp', 'mediump' or 'highp').

    Returns GLShader

    https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders

    // create a basic shader
    let myShader = new me.GLShader(
    // WebGL rendering context
    gl,
    // vertex shader
    [
    "void main() {",
    " gl_Position = doMathToMakeClipspaceCoordinates;",
    "}"
    ].join("\n"),
    // fragment shader
    [
    "void main() {",
    " gl_FragColor = doMathToMakeAColor;",
    "}"
    ].join("\n")
    )
    // use the shader
    myShader.bind();

Properties

attributes: number[]

the location attributes of the shader

fragment: string

the fragment shader source code

gl: WebGLRenderingContext

the active gl rendering context

program: WebGLProgram

a reference to the shader program (once compiled)

uniforms: object

the uniforms of the shader

vertex: string

the vertex shader source code

Methods

  • returns the location of an attribute variable in this shader program

    Parameters

    • name: string

      the name of the attribute variable whose location to get.

    Returns number

    number indicating the location of the variable name if found. Returns -1 otherwise

  • Set the uniform to the given value

    Parameters

    • name: string

      the uniform name

    • value: object | Float32Array

      the value to assign to that uniform

    Returns void

    myShader.setUniform("uProjectionMatrix", this.projectionMatrix);
    
  • activate the given vertex attribute for this shader

    Parameters

    • gl: WebGLRenderingContext

      the current WebGL rendering context

    • attributes: object[]

      an array of vertex attributes

    • vertexByteSize: number

      the size of a single vertex in bytes

    Returns void