warp.Texture#
- class warp.Texture(*args, **kwargs)[source]#
Unified texture class for hardware-accelerated sampling on GPU and software sampling on CPU.
This class handles both 2D and 3D textures. The dimensionality is determined automatically from the input data shape, or can be set explicitly via the
dimsparameter or by using theTexture2DorTexture3Dsubclasses.Textures provide hardware-accelerated filtering and addressing for regularly-gridded data on CUDA devices. On CPU, software-based filtering and addressing is used. Supports bilinear/trilinear interpolation and various addressing modes (wrap, clamp, mirror, border).
Supports uint8, uint16, and float32 data types. Integer textures are read as normalized floats in the [0, 1] range.
- Class Constants:
ADDRESS_WRAP (int): Wrap coordinates (tile the texture) = 0 ADDRESS_CLAMP (int): Clamp coordinates to [0, 1] = 1 ADDRESS_MIRROR (int): Mirror coordinates at boundaries = 2 ADDRESS_BORDER (int): Return 0 for coordinates outside [0, 1] = 3 FILTER_POINT (int): Nearest-neighbor filtering = 0 FILTER_LINEAR (int): Bilinear/trilinear filtering = 1
Example:
import warp as wp import numpy as np # Create a 2D texture data_2d = np.random.rand(256, 256).astype(np.float32) tex2d = wp.Texture(data_2d, device="cuda:0") # Create a 3D texture data_3d = np.random.rand(64, 64, 64).astype(np.float32) tex3d = wp.Texture(data_3d, device="cuda:0")
- __init__(
- data=None,
- width=0,
- height=0,
- depth=0,
- num_channels=1,
- dtype=np.float32,
- filter_mode=1,
- address_mode=None,
- address_mode_u=None,
- address_mode_v=None,
- address_mode_w=None,
- normalized_coords=True,
- device=None,
- dims=None,
Create a texture.
- Parameters:
data (ndarray | array | None) – Initial texture data as a numpy array or warp array. For 2D: shape (height, width), (height, width, 2), or (height, width, 4). For 3D: shape (depth, height, width), (depth, height, width, 2), or (depth, height, width, 4). Supported dtypes: uint8, uint16, float32.
width (int) – Texture width (required if data is None).
height (int) – Texture height (required if data is None).
depth (int) – Texture depth (required if data is None for 3D textures).
num_channels (int) – Number of channels (1, 2, or 4). Only used if data is None. Default is 1.
dtype – Data type (uint8, uint16, or float32). Only used if data is None; when data is provided, dtype is inferred from the data. Default is float32.
filter_mode (int) – Filtering mode - FILTER_POINT (0) or FILTER_LINEAR (1). Default is LINEAR.
address_mode (int | tuple[int, ...] | None) – Address mode for all axes - ADDRESS_WRAP (0), ADDRESS_CLAMP (1), ADDRESS_MIRROR (2), or ADDRESS_BORDER (3). Can be a single int or tuple.
address_mode_u (int | None) – Per-axis address mode for U. Overrides address_mode if specified.
address_mode_v (int | None) – Per-axis address mode for V. Overrides address_mode if specified.
address_mode_w (int | None) – Per-axis address mode for W (3D only). Overrides address_mode if specified.
normalized_coords (bool) – If True (default), coordinates are in [0, 1] range. If False, coordinates are in texel space.
device – Device to create the texture on (CPU or CUDA).
dims (int | None) – Explicit dimensionality (2 or 3). If None, auto-detected from data.
Methods
__init__([data, width, height, depth, ...])Create a texture.
Attributes
Address mode for U axis.
Address mode for V axis.
Address mode for W axis (3D only).
Texture depth in pixels (1 for 2D textures).
Texture dimensionality (2 or 3).
Data type of the texture.
Texture height in pixels.
Texture handle ID (for advanced use).
Whether texture uses normalized coordinates.
Number of channels.
Texture width in pixels.
- ADDRESS_WRAP = 0#
- ADDRESS_CLAMP = 1#
- ADDRESS_MIRROR = 2#
- ADDRESS_BORDER = 3#
- FILTER_POINT = 0#
- FILTER_LINEAR = 1#