createShader

View sourcecreateShader(gl: WebGLRenderingContext, src: string, type: number): WebGLShader

Creates a WebGL shader, submits its source, and requests compilation.

The helper calls WebGLRenderingContext#createShader with the supplied ShaderStage, asserts that WebGL returned a shader, uploads src with WebGLRenderingContext#shaderSource, and requests compilation with WebGLRenderingContext#compileShader. It returns the shader object without checking whether compilation succeeded; inspect that status separately with the WebGL API or validateShader.

Examples

import { ShaderStage } from '@wimaengine/render-core'
import { createShader } from '@wimaengine/render-webgl'

// `gl` is an existing WebGLRenderingContext.
const vertexShader = createShader(
  gl,
  'void main() { gl_Position = vec4(0.0); }',
  ShaderStage.Vertex
)

Parameters

NameDescriptionDefault
gl

WebGL context that owns the shader.

—
src

Shader-language source to upload.

—
type

Shader stage from ShaderStage.

—

Throws

If gl.createShader() returns null or undefined.

Returns

The allocated shader after source upload and compilation is requested.