Skip to content

Commit dac017f

Browse files
authored
add size property to texture view (#117)
Co-authored-by: Almar Klein <[email protected]>
1 parent 6a0fd30 commit dac017f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

wgpu/backends/rs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ def create_view(
12141214
)
12151215
id = _lib.wgpu_texture_create_view(self._internal, struct)
12161216

1217-
return base.GPUTextureView(label, id, self._device, self)
1217+
return base.GPUTextureView(label, id, self._device, self, self.texture_size)
12181218

12191219
# wgpu.help('texturedestroy', dev=True)
12201220
def destroy(self):
@@ -1811,19 +1811,20 @@ def __enter__(self):
18111811
# Get the current texture view, and make sure it is presented when done
18121812
self._create_native_swap_chain_if_needed()
18131813
sc_output = _lib.wgpu_swap_chain_get_next_texture(self._internal)
1814-
if sc_output.status == _lib.WGPUSwapChainStatus_Good:
1814+
status, view_id = sc_output.status, sc_output.view_id
1815+
if status == _lib.WGPUSwapChainStatus_Good:
18151816
pass
1816-
elif sc_output.status == _lib.WGPUSwapChainStatus_Suboptimal: # no-cover
1817+
elif status == _lib.WGPUSwapChainStatus_Suboptimal: # no-cover
18171818
if not getattr(self, "_warned_swap_chain_suboptimal", False):
18181819
logger.warning(f"Swap chain status of {self} is suboptimal")
18191820
self._warned_swap_chain_suboptimal = True
18201821
else: # no-cover
1821-
status = sc_output.status
18221822
status_str = swap_chain_status_map.get(status, "")
18231823
raise RuntimeError(
18241824
f"Swap chain status is not good: {status_str} ({status})"
18251825
)
1826-
return base.GPUTextureView("swap_chain", sc_output.view_id, self._device, None)
1826+
size = self._surface_size[0], self._surface_size[1], 1
1827+
return base.GPUTextureView("swap_chain", view_id, self._device, None, size)
18271828

18281829
def __exit__(self, type, value, tb):
18291830
# Present the current texture

wgpu/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,16 @@ class GPUTextureView(GPUObject):
824824
Create a texture view using :func:`GPUTexture.create_view`.
825825
"""
826826

827-
def __init__(self, label, internal, device, texture):
827+
def __init__(self, label, internal, device, texture, size):
828828
super().__init__(label, internal, device)
829829
self._texture = texture
830+
self._size = size
831+
832+
@property
833+
def size(self):
834+
""" The texture size (as a 3-tuple).
835+
"""
836+
return self._size
830837

831838
@property
832839
def texture(self):

0 commit comments

Comments
 (0)