createProgram

View sourcecreateProgram(gl: WebGLRenderingContext, vertex: WebGLShader, fragment: WebGLShader, attributemap: Readonly<Map<string, MeshAttribute>>): WebGLProgram

Creates and links a WebGL program with explicit vertex-attribute locations.

The helper calls WebGLRenderingContext#createProgram, asserts that WebGL returned a program, attaches vertex and fragment with WebGLRenderingContext#attachShader, then binds every MeshAttribute value in attributemap with WebGLRenderingContext#bindAttribLocation. Map keys are ignored; each descriptor’s MeshAttribute#id and MeshAttribute#name are passed to WebGL. It finishes with WebGLRenderingContext#linkProgram and returns the program. Attribute locations must therefore be supplied before linking.

This helper does not inspect LINK_STATUS, call validateProgram, or make the program current with WebGLRenderingContext#useProgram. A link failure still returns the program so callers can inspect it with WebGL or validateProgram.

Examples

import { MeshAttribute } from '@wimaengine/render-core'
import { AttributeMap, createProgram } from '@wimaengine/render-webgl'

const attributes = new AttributeMap()
attributes.set('position', new MeshAttribute('position', 0, gl.FLOAT, 3))
const program = createProgram(gl, vertexShader, fragmentShader, attributes)

Parameters

NameDescriptionDefault
gl——
vertex——
fragment——
attributemap

Attribute descriptors, normally the AttributeMap resource.

—

Throws

If WebGLRenderingContext#createProgram returns a falsy value.

Returns

The created program after the link operation.