Skip to content

Commit 325d4ec

Browse files
committed
sharper rendering -> true devicePixelRatio
1 parent 434c87c commit 325d4ec

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

webgpu/canvas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ def update_html_canvas(self, html_canvas):
282282
"device": self.device.handle,
283283
"format": self.format,
284284
"alphaMode": "premultiplied",
285-
"sampleCount": self.multisample.count,
286285
"usage": TextureUsage.RENDER_ATTACHMENT | TextureUsage.COPY_DST,
287286
}
288287
)
@@ -366,8 +365,9 @@ def resize(self):
366365
if canvas is None:
367366
return
368367
rect = canvas.getBoundingClientRect()
369-
width = int(rect.width)
370-
height = int(rect.height)
368+
dpr = getattr(platform.js.window, 'devicePixelRatio', 1) or 1
369+
width = round(rect.width * dpr)
370+
height = round(rect.height * dpr)
371371

372372
if width == self.width and height == self.height:
373373
for func in self._on_resize_callbacks:

webgpu/jupyter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ def _draw_scene(scene: Scene, width, height, id_):
8787

8888
while html_canvas is None:
8989
html_canvas = platform.js.document.getElementById(f"{id_}canvas")
90-
html_canvas.width = width
91-
html_canvas.height = height
9290
gui_element = platform.js.document.getElementById(f"{id_}lilgui")
9391

9492
# Lazily initialize the WebGPU device the first time we draw.

webgpu/link/link.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ function serializeEvent(event) {
2727
let obj = Object.fromEntries(keys.map((k) => [k, event[k]]));
2828
if (event.x !== undefined) {
2929
let rect = event.target.getBoundingClientRect();
30-
obj.canvasX = event.x - Math.floor(rect.x);
31-
obj.canvasY = event.y - Math.floor(rect.y);
30+
let dpr = window.devicePixelRatio || 1;
31+
obj.canvasX = Math.round((event.x - rect.x) * dpr);
32+
obj.canvasY = Math.round((event.y - rect.y) * dpr);
3233
}
3334
return obj;
3435
}

0 commit comments

Comments
 (0)