From b29c6287be9e97b83c2b96025abf1d87256212d6 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 1 Jul 2020 16:18:02 +0200 Subject: [PATCH] add size property to texture view --- wgpu/backends/rs.py | 11 ++++++----- wgpu/base.py | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/wgpu/backends/rs.py b/wgpu/backends/rs.py index 31965e0e..3ef1908f 100644 --- a/wgpu/backends/rs.py +++ b/wgpu/backends/rs.py @@ -1214,7 +1214,7 @@ def create_view( ) id = _lib.wgpu_texture_create_view(self._internal, struct) - return base.GPUTextureView(label, id, self._device, self) + return base.GPUTextureView(label, id, self._device, self, self.texture_size) # wgpu.help('texturedestroy', dev=True) def destroy(self): @@ -1811,19 +1811,20 @@ def __enter__(self): # Get the current texture view, and make sure it is presented when done self._create_native_swap_chain_if_needed() sc_output = _lib.wgpu_swap_chain_get_next_texture(self._internal) - if sc_output.status == _lib.WGPUSwapChainStatus_Good: + status, view_id = sc_output.status, sc_output.view_id + if status == _lib.WGPUSwapChainStatus_Good: pass - elif sc_output.status == _lib.WGPUSwapChainStatus_Suboptimal: # no-cover + elif status == _lib.WGPUSwapChainStatus_Suboptimal: # no-cover if not getattr(self, "_warned_swap_chain_suboptimal", False): logger.warning(f"Swap chain status of {self} is suboptimal") self._warned_swap_chain_suboptimal = True else: # no-cover - status = sc_output.status status_str = swap_chain_status_map.get(status, "") raise RuntimeError( f"Swap chain status is not good: {status_str} ({status})" ) - return base.GPUTextureView("swap_chain", sc_output.view_id, self._device, None) + size = self._surface_size[0], self._surface_size[1], 1 + return base.GPUTextureView("swap_chain", view_id, self._device, None, size) def __exit__(self, type, value, tb): # Present the current texture diff --git a/wgpu/base.py b/wgpu/base.py index ab52ff48..d7ca1ca4 100644 --- a/wgpu/base.py +++ b/wgpu/base.py @@ -824,9 +824,16 @@ class GPUTextureView(GPUObject): Create a texture view using :func:`GPUTexture.create_view`. """ - def __init__(self, label, internal, device, texture): + def __init__(self, label, internal, device, texture, size): super().__init__(label, internal, device) self._texture = texture + self._size = size + + @property + def size(self): + """ The texture size (as a 3-tuple). + """ + return self._size @property def texture(self):