pygfx.resources.Texture¶
- class pygfx.resources.Texture(data=None, *, dim, size=None, format=None, colorspace='srgb', generate_mipmaps=False)¶
Bases:
Resource
Texture object containing structured 1D, 2D or 3D data.
Can be used to represent e.g. image data or colormaps. Can also serve as a render target (for the renderer). Supports texture stacks, cube textures, and mipmapping.
- Parameters:
data – array, optional Array data of any type that supports the buffer-protocol, (e.g. a bytes or numpy array). If None, nbytes and size must be provided. The dtype must be compatible with the rendering backend.
dim – int The dimensionality of the array (1, 2 or 3).
size – tuple, [3] The extent
(width, height, depth)
of the array. If None, it is derived from dim and the shape of the data. The texture can also represent a stack of images by setting dim=2 and depth > 1, or a cube image by setting dim=2 and depth==6.format – str A format string describing the texture layout. If None, this is derived from the data. This must be a pygfx format specifier, e.g. “3xf4”, but can also be a format specific to the render backend (e.g. from
wgpu.TextureFormat
).colorspace – str If this data is used as color, it is interpreted to be in this colorspace. Can be “srgb” or “physical”. Default “srgb”.
generate_mipmaps – bool If True, automatically generates mipmaps when transferring data to the GPU.
- property rev¶
An integer that is increased when update_range() is called.
- property dim¶
The dimensionality of the texture (1, 2, or 3).
- property data¶
The data for this texture. Can be None if the data only exists on the GPU.
Note: the data is the same reference that was given to instantiate this object, but this may change.
- property mem¶
The data for this buffer as a memoryview. Can be None if the data only exists on the GPU.
- property nbytes¶
Get the number of bytes in the texture.
- property size¶
The size of the texture as (width, height, depth). (always a 3-tuple, regardless of the dimension).
- property format¶
The texture format as a string. Usually a pygfx format specifier (e.g. u2 for scalar uint16, or 3xf4 for RGB float32), but can also be a overridden to a backend-specific format.
- property colorspace¶
If this data is used as color, it is interpreted to be in this colorspace. Can be “srgb” or “physical”. Default “srgb”.
- property generate_mipmaps¶
Whether to automatically generate mipmaps when uploading to the GPU.
- update_range(offset, size)¶
Mark a certain range of the data for upload to the GPU. The offset and (sub) size should be (width, height, depth) tuples. Numpy users beware that an arrays shape is (height, width)!
Examples¶
Transform Control without Matrix Updating
Simulating grass with point sprites
Image with another image overlaid
Volume and Volume Slice Rendering