Fix brush on mobile

This commit is contained in:
Andras Schmelczer 2023-05-20 10:04:29 +01:00
commit a7b14b9fbb
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -36,7 +36,7 @@ export default class GameLoop {
private readonly canvas: HTMLCanvasElement, private readonly canvas: HTMLCanvasElement,
private readonly device: GPUDevice private readonly device: GPUDevice
) { ) {
const context = this.canvas.getContext('webgpu') as any; const context = this.canvas.getContext('webgpu') as any as GPUCanvasContext;
context.configure({ context.configure({
device: this.device, device: this.device,
format: navigator.gpu.getPreferredCanvasFormat(), format: navigator.gpu.getPreferredCanvasFormat(),
@ -82,15 +82,17 @@ export default class GameLoop {
return; return;
} }
this.brushPipeline.addSwipe( const position = vec2.fromValues(
vec2.fromValues(event.clientX, this.canvas.height - event.clientY) event.clientX * this.devicePixelRatio,
this.canvas.height - event.clientY * this.devicePixelRatio
); );
this.brushPipeline.addSwipe(position);
} }
private resize() { private resize() {
const devicePixelRatio = window.devicePixelRatio || 1; const devicePixelRatio = window.devicePixelRatio || 1;
this.canvas.width = this.canvas.clientWidth * devicePixelRatio; this.canvas.width = this.canvas.clientWidth * this.devicePixelRatio;
this.canvas.height = this.canvas.clientHeight * devicePixelRatio; this.canvas.height = this.canvas.clientHeight * this.devicePixelRatio;
} }
private async render(time: DOMHighResTimeStamp) { private async render(time: DOMHighResTimeStamp) {
@ -167,4 +169,8 @@ export default class GameLoop {
private get canvasSize(): vec2 { private get canvasSize(): vec2 {
return vec2.fromValues(this.canvas.width, this.canvas.height); return vec2.fromValues(this.canvas.width, this.canvas.height);
} }
private get devicePixelRatio(): number {
return window.devicePixelRatio || 1;
}
} }