Skip to content

Commit 2465dc8

Browse files
authored
Imgui get up-to-date framebuffer size (#706)
* imgui get up-to-date framebuffer size * lint
1 parent 331d013 commit 2465dc8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

wgpu/utils/imgui/imgui_backend.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ def _update_vertex_buffer(self, draw_data: imgui.ImDrawData):
377377
)
378378

379379
def render(
380-
self, draw_data: imgui.ImDrawData, render_pass: wgpu.GPURenderPassEncoder
380+
self,
381+
draw_data: imgui.ImDrawData,
382+
render_pass: wgpu.GPURenderPassEncoder,
383+
psize: tuple,
381384
):
382385
"""
383386
Render the imgui draw data with the given render pass.
@@ -392,10 +395,7 @@ def render(
392395
if draw_data is None:
393396
return
394397

395-
display_width, display_height = draw_data.display_size
396-
fb_width = int(display_width * draw_data.framebuffer_scale.x)
397-
fb_height = int(display_height * draw_data.framebuffer_scale.y)
398-
398+
fb_width, fb_height = psize
399399
if fb_width <= 0 or fb_height <= 0 or draw_data.cmd_lists_count == 0:
400400
return
401401

wgpu/utils/imgui/imgui_renderer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def render(self):
149149
draw_data = self._update_gui_function()
150150

151151
pixel_ratio = self._canvas_context.canvas.get_pixel_ratio()
152+
psize = self._canvas_context.canvas.get_physical_size()
152153
self._backend.io.display_framebuffer_scale = (pixel_ratio, pixel_ratio)
153154

154155
command_encoder = self._backend._device.create_command_encoder()
@@ -164,7 +165,7 @@ def render(self):
164165
}
165166
],
166167
)
167-
self._backend.render(draw_data, render_pass)
168+
self._backend.render(draw_data, render_pass, psize)
168169
render_pass.end()
169170
self._backend._device.queue.submit([command_encoder.finish()])
170171

0 commit comments

Comments
 (0)