Program - noobgl/noobgl GitHub Wiki

The program is the core of the rendering process, it must be feeded with shaders, attributes and uniforms to finaly perform a rendering onto the canvas.

Import

import { Program } from "noobgl";

Constructor

new Program(context);
  • context the WebGL2 context of a canvas.

Properties

.context the context the program use to process and render.

.instance the native program instance initiated with the context.

.shader the shader currently attached to the program (default null).

.drawLength the amount of indices of the vertex array attribute.

.drawSize the size of each element in the vertex array attribute.

Methods

.enable(...WebGL2Constants)

Enable specific WebGL capabilities for this context.

  • ...WebGL2Constants a list of WebGL capabilities (more info here)
    • BLEND
    • CULL_FACE
    • DEPTH_TEST
    • DITHER
    • POLYGON_OFFSET_FILL
    • SAMPLE_ALPHA_TO_COVERAGE
    • SAMPLE_COVERAGE
    • SCISSOR_TEST
    • STENCIL_TEST
    • RASTERIZER_DISCARD

.attachShader(shader)

Attach vertex & fragment shaders to the program.

  • shader an instance of Shader

.detachShader()

Detach the current vertex & fragment shaders from the program.


.setAttribute(name, data, size, type)

Enable, define and feed the shader's attribute with data.

  • name the name of the attribute in the shader.
  • data the array of data to provide to the attribute.
    • ArrayBuffer
    • SharedArrayBuffer
    • ArrayBufferView
  • size the size of the buffer object's data store.
  • type a WebGL constant specifying the binding point
    • ARRAY_BUFFER
    • ELEMENT_ARRAY_BUFFER
    • COPY_READ_BUFFER
    • COPY_WRITE_BUFFER
    • TRANSFORM_FEEDBACK_BUFFER
    • UNIFORM_BUFFER
    • PIXEL_PACK_BUFFER
    • PIXEL_UNPACK_BUFFER

.setVertexAttribute(name, data, size)

Enable, define and feed the shader's vertex attribute with data.

  • name the name of attribute in the shader.
  • data the array of data to provide to the attribute.
    • ArrayBuffer
    • SharedArrayBuffer
    • ArrayBufferView
  • size the size of the buffer object's data store.

.setUniform(name, type, ...values)

Feed the shader's uniform with data.

  • name the name of the uniform in the shader.
  • type the type of data that the uniform stores, it can be i for integers or f for floats.
  • ...values a list of values (from 1 to 4).

.setUniformMatrix(name, matrix, transpose)

Feed the shader's matrix uniform with data.

  • name the name of the uniform in the shader.
  • matrix a Float32Array representing the matrix2, matrix3 or matrix4.
  • transpose a Boolean defining whether or not the matrix must be transposed (default false).

.link()

Link the program to the WebGL context and validate the link status. If an error occurs, it delete the program.


.use()

Set this program to be used by the WebGL context.


.render(mode, offset, length)

Renders the current program and its shaders onto the canvas.

  • mode the drawing mode to use to render the program (default TRIANGLES).
    • POINTS
    • LINE_STRIP
    • LINE_LOOP
    • LINES
    • TRIANGLE_STRIP
    • TRIANGLE_FAN
    • TRIANGLES
  • offset the starting index in the vertex array (default 0).
  • length the number of indices to render from the vertex array (default, all the vertex array).

.delete()

Delete the program.