more cleaning up
This commit is contained in:
parent
2c7d72a699
commit
560398fefb
110 changed files with 931 additions and 2645 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
|
||||
import { appConfig } from '../../config';
|
||||
import { clamp } from '../../utils/clamp';
|
||||
import {
|
||||
createCachedFloat32BufferWrite,
|
||||
writeFloat32BufferIfChanged,
|
||||
|
|
@ -25,7 +24,6 @@ export class BrushPipeline {
|
|||
|
||||
private readonly bindGroupLayout: GPUBindGroupLayout;
|
||||
private readonly bindGroup: GPUBindGroup;
|
||||
private readonly pipeline: GPURenderPipeline;
|
||||
private readonly multiTargetPipeline: GPURenderPipeline;
|
||||
private readonly uniforms: GPUBuffer;
|
||||
private readonly uniformValues = new Float32Array(BrushPipeline.UNIFORM_COUNT);
|
||||
|
|
@ -39,7 +37,6 @@ export class BrushPipeline {
|
|||
BrushPipeline.ATTRIBUTES_PER_LINE_SEGMENT
|
||||
);
|
||||
|
||||
private linePoints: Array<vec2> = [];
|
||||
private lineSegments: Array<LineSegment> = [];
|
||||
private actualSegments: Array<LineSegment> = [];
|
||||
|
||||
|
|
@ -59,7 +56,6 @@ export class BrushPipeline {
|
|||
});
|
||||
|
||||
const shaderModule = smartCompile(device, CommonState.shaderCode, shader);
|
||||
this.pipeline = this.createPipeline(shaderModule, 'fragment', 1);
|
||||
this.multiTargetPipeline = this.createPipeline(shaderModule, 'fragmentMrt', 2);
|
||||
|
||||
this.uniforms = this.device.createBuffer({
|
||||
|
|
@ -80,12 +76,6 @@ export class BrushPipeline {
|
|||
});
|
||||
}
|
||||
|
||||
public addSwipe(position: vec2) {
|
||||
const previousPosition = this.linePoints[this.linePoints.length - 1] ?? position;
|
||||
this.addSwipeSegment(previousPosition, position);
|
||||
this.linePoints.push(vec2.clone(position));
|
||||
}
|
||||
|
||||
public addSwipeSegment(from: vec2, to: vec2) {
|
||||
this.lineSegments.push({
|
||||
from: vec2.clone(from),
|
||||
|
|
@ -94,7 +84,6 @@ export class BrushPipeline {
|
|||
}
|
||||
|
||||
public clearSwipes() {
|
||||
this.linePoints.length = 0;
|
||||
this.lineSegments.length = 0;
|
||||
this.actualSegments.length = 0;
|
||||
}
|
||||
|
|
@ -103,8 +92,7 @@ export class BrushPipeline {
|
|||
brushSize,
|
||||
brushSizeVariation,
|
||||
selectedColorIndex,
|
||||
isErasing,
|
||||
}: BrushSettings & { selectedColorIndex: number; isErasing: boolean }) {
|
||||
}: BrushSettings & { selectedColorIndex: number }) {
|
||||
const brushRadius = brushSize / 2;
|
||||
const brushRadiusVariation = Math.floor(brushRadius * brushSizeVariation);
|
||||
const brushFeather = Math.max(1, brushRadius * BrushPipeline.FEATHER_RADIUS_RATIO);
|
||||
|
|
@ -115,10 +103,10 @@ export class BrushPipeline {
|
|||
this.uniformValues[1] = brushRadiusVariation;
|
||||
this.uniformValues[2] = 0;
|
||||
this.uniformValues[3] = 0;
|
||||
this.uniformValues[4] = !isErasing && selectedColorIndex === 0 ? 1 : 0;
|
||||
this.uniformValues[5] = !isErasing && selectedColorIndex === 1 ? 1 : 0;
|
||||
this.uniformValues[6] = !isErasing && selectedColorIndex === 2 ? 1 : 0;
|
||||
this.uniformValues[7] = isErasing ? 0 : 1;
|
||||
this.uniformValues[4] = selectedColorIndex === 0 ? 1 : 0;
|
||||
this.uniformValues[5] = selectedColorIndex === 1 ? 1 : 0;
|
||||
this.uniformValues[6] = selectedColorIndex === 2 ? 1 : 0;
|
||||
this.uniformValues[7] = 1;
|
||||
writeFloat32BufferIfChanged(
|
||||
this.device,
|
||||
this.uniforms,
|
||||
|
|
@ -264,10 +252,6 @@ export class BrushPipeline {
|
|||
return offset;
|
||||
}
|
||||
|
||||
public execute(commandEncoder: GPUCommandEncoder, trailMapOut: GPUTextureView): void {
|
||||
this.executeWithPipeline(commandEncoder, this.pipeline, [trailMapOut]);
|
||||
}
|
||||
|
||||
public executeMultiTarget(
|
||||
commandEncoder: GPUCommandEncoder,
|
||||
sourceMapOut: GPUTextureView,
|
||||
|
|
@ -392,6 +376,6 @@ export class BrushPipeline {
|
|||
}
|
||||
|
||||
private get lineCount() {
|
||||
return clamp(this.actualSegments.length, 0, BrushPipeline.MAX_LINE_COUNT);
|
||||
return this.actualSegments.length;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue