MCPcopy Create free account
hub / github.com/PavelDoGreat/WebGL-Fluid-Simulation / Material

Class Material

script.js:351–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351class Material {
352 constructor (vertexShader, fragmentShaderSource) {
353 this.vertexShader = vertexShader;
354 this.fragmentShaderSource = fragmentShaderSource;
355 this.programs = [];
356 this.activeProgram = null;
357 this.uniforms = [];
358 }
359
360 setKeywords (keywords) {
361 let hash = 0;
362 for (let i = 0; i < keywords.length; i++)
363 hash += hashCode(keywords[i]);
364
365 let program = this.programs[hash];
366 if (program == null)
367 {
368 let fragmentShader = compileShader(gl.FRAGMENT_SHADER, this.fragmentShaderSource, keywords);
369 program = createProgram(this.vertexShader, fragmentShader);
370 this.programs[hash] = program;
371 }
372
373 if (program == this.activeProgram) return;
374
375 this.uniforms = getUniforms(program);
376 this.activeProgram = program;
377 }
378
379 bind () {
380 gl.useProgram(this.activeProgram);
381 }
382}
383
384class Program {
385 constructor (vertexShader, fragmentShader) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected