Add files
This commit is contained in:
commit
77bde04db3
97 changed files with 10327 additions and 0 deletions
22
src/graphics/graphics-library/compiling/create-shader.ts
Normal file
22
src/graphics/graphics-library/compiling/create-shader.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
export const createShader = (
|
||||
gl: WebGL2RenderingContext,
|
||||
type: GLenum,
|
||||
source: string,
|
||||
substitutions: { [name: string]: string }
|
||||
): WebGLShader => {
|
||||
source = source.replace(/{(.+)}/gm, (_, name: string): string => {
|
||||
const value = substitutions[name];
|
||||
return Number.isInteger(value) ? `${value}.0` : value;
|
||||
});
|
||||
|
||||
const shader = gl.createShader(type);
|
||||
|
||||
if (!shader) {
|
||||
throw new Error('Could not create shader');
|
||||
}
|
||||
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
|
||||
return shader;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue