Refactor
This commit is contained in:
parent
25caf2fd5f
commit
9c64392e01
3 changed files with 16 additions and 13 deletions
|
|
@ -14,7 +14,7 @@ export abstract class FrameBuffer {
|
|||
|
||||
constructor(protected readonly gl: UniversalRenderingContext) {}
|
||||
|
||||
public bindAndClear(inputTextures: Array<Texture>) {
|
||||
public bindAndClear(inputTextures: Array<Texture> = []) {
|
||||
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.frameBuffer);
|
||||
|
||||
inputTextures.forEach((t) => t.bind());
|
||||
|
|
|
|||
|
|
@ -17,13 +17,11 @@ type ShaderWithSource = WebGLShader & { source: string };
|
|||
|
||||
/** @internal */
|
||||
export class ParallelCompiler {
|
||||
private extension?: any;
|
||||
private gl: UniversalRenderingContext;
|
||||
private parallelCompileExtension?: any;
|
||||
private programs: Array<CompilingProgram> = [];
|
||||
|
||||
public constructor(gl: UniversalRenderingContext) {
|
||||
this.gl = gl;
|
||||
this.extension = tryEnableExtension(gl, 'KHR_parallel_shader_compile');
|
||||
public constructor(private readonly gl: UniversalRenderingContext) {
|
||||
this.parallelCompileExtension = tryEnableExtension(gl, 'KHR_parallel_shader_compile');
|
||||
}
|
||||
|
||||
public createProgram(
|
||||
|
|
@ -105,8 +103,11 @@ export class ParallelCompiler {
|
|||
|
||||
this.programs.forEach((p) => {
|
||||
if (
|
||||
!this.extension ||
|
||||
this.gl.getProgramParameter(p.program, this.extension.COMPLETION_STATUS_KHR)
|
||||
!this.parallelCompileExtension ||
|
||||
this.gl.getProgramParameter(
|
||||
p.program,
|
||||
this.parallelCompileExtension.COMPLETION_STATUS_KHR
|
||||
)
|
||||
) {
|
||||
this.checkProgram(p);
|
||||
done.push(p);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { ReadonlyVec2 } from 'gl-matrix';
|
||||
import { DefaultFrameBuffer } from '../../graphics-library/frame-buffer/default-frame-buffer';
|
||||
import { ParallelCompiler } from '../../graphics-library/parallel-compiler';
|
||||
import { FragmentShaderOnlyProgram } from '../../graphics-library/program/fragment-shader-only-program';
|
||||
import { getUniversalRenderingContext } from '../../graphics-library/universal-rendering-context';
|
||||
|
|
@ -18,16 +19,15 @@ import randomVertex from '../shaders/random-vs.glsl';
|
|||
* @param ignoreWebGL2 Ignore WebGL2, even when it's available
|
||||
*/
|
||||
export const renderNoise = async (
|
||||
textureSize: vec2,
|
||||
textureSize: ReadonlyVec2,
|
||||
scale: number,
|
||||
amplitude: number,
|
||||
ignoreWebGL2 = false
|
||||
): Promise<HTMLCanvasElement> => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = textureSize.x;
|
||||
canvas.height = textureSize.y;
|
||||
|
||||
const gl = getUniversalRenderingContext(canvas, ignoreWebGL2);
|
||||
|
||||
const frameBuffer = new DefaultFrameBuffer(gl, textureSize);
|
||||
const program = new FragmentShaderOnlyProgram(gl);
|
||||
const compiler = new ParallelCompiler(gl);
|
||||
|
||||
|
|
@ -39,11 +39,13 @@ export const renderNoise = async (
|
|||
await compiler.compilePrograms();
|
||||
await programPromise;
|
||||
|
||||
frameBuffer.bindAndClear();
|
||||
program.draw({
|
||||
scale,
|
||||
amplitude,
|
||||
});
|
||||
|
||||
frameBuffer.destroy();
|
||||
program.destroy();
|
||||
|
||||
return canvas;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue