Skip to content

Commit

Permalink
webgl helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fromtheeast710 committed Sep 28, 2024
1 parent 66a662a commit 40e1e9e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib/scripts/webgl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function compileShader(gl, type, src) {
const shader = gl.createShader(type)!;
gl.shaderSource(shader, src);
gl.compileShader(shader);

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
console.error("Shader failed to compile: " + gl.getShaderInfoLog(shader));

return shader;
}

export function createProgram(gl, vertexShader, fragmentShader) {
const program = gl.createProgram();

gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);

if (!gl.getProgramParameter(program, gl.LINK_STATUS))
console.error("Program failed to link: " + gl.getProgramInfoLog(program));

return program;
}

0 comments on commit 40e1e9e

Please sign in to comment.