Add shader prep utils
This commit is contained in:
parent
006377b31a
commit
929421ba6d
31
src/shaders.ts
Normal file
31
src/shaders.ts
Normal file
@ -0,0 +1,31 @@
|
||||
export function loadShader(gl: WebGLRenderingContext, type: GLenum, source: string) {
|
||||
const shader = gl.createShader(type);
|
||||
if (!shader) {
|
||||
throw new Error("WebGL fails to create shader for given type");
|
||||
}
|
||||
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
|
||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||
const compileError = gl.getShaderInfoLog(shader);
|
||||
throw new Error("Error when compiling shader: " + compileError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function loadProgram(gl: WebGLRenderingContext, vertexShader: WebGLShader, fragmentShader: WebGLShader) {
|
||||
const program = gl.createProgram();
|
||||
if (!program) {
|
||||
throw new Error("WebGL fails to create program");
|
||||
}
|
||||
|
||||
gl.attachShader(program, vertexShader);
|
||||
gl.attachShader(program, fragmentShader);
|
||||
gl.linkProgram(program);
|
||||
|
||||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
||||
const linkError = gl.getProgramInfoLog(program);
|
||||
throw new Error("Error when linking program: " + linkError);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user