createProgramFromSrc

View sourcecreateProgramFromSrc(gl: WebGL2RenderingContext, vertex: string, fragment: string, attributemap: Readonly<Map<string, MeshAttribute>>): WebGLProgram

Compiles vertex and fragment source, then creates a linked WebGL program.

The helper passes gl.VERTEX_SHADER and gl.FRAGMENT_SHADER to createShader; these are the WebGL values represented by the vertex and fragment entries of ShaderStage. It then delegates to createProgram, so attribute locations come from the supplied MeshAttribute descriptors in attributemap.

Shader compilation and program linking are requested, but their status is not checked here. Use validateShader and validateProgram when diagnostics are needed. The helper also does not make the program current or delete the temporary shader objects.

Examples

const program = createProgramFromSrc(gl, vertexSource, fragmentSource, attributes)
validateProgram(gl, program)

Parameters

NameDescriptionDefault
gl

Context used to compile and link.

—
vertex

Vertex-shader source.

—
fragment

Fragment-shader source.

—
attributemap

Attribute descriptors, normally the AttributeMap resource.

—

Throws

If shader or program allocation returns a falsy value.

Returns

The program returned by createProgram.