pub struct Texture { /* private fields */ }Expand description
A 2D texture owning an RGBA8 pixel buffer, with nearest-neighbor wrap sampling. 一个拥有 RGBA8 像素缓冲的 2D 纹理,支持最近邻环绕采样。
Implementations§
Source§impl Texture
impl Texture
Sourcepub fn new(
width: u32,
height: u32,
pixels: Vec<ColorRgba8>,
) -> Result<Self, Error>
pub fn new( width: u32, height: u32, pixels: Vec<ColorRgba8>, ) -> Result<Self, Error>
Construct a texture, validating dimensions and buffer length. 构造一个纹理,校验尺寸和缓冲长度。
§Errors
尺寸为 0 或超过 MAX_TEXTURE_DIMENSION、像素数量与尺寸不符,或尺寸乘积溢出时返回相应错误。
Returns an error when a dimension is zero or exceeds MAX_TEXTURE_DIMENSION,
when the pixel count does not match the dimensions, or when the product overflows.
Sourcepub fn from_pixels(
width: u32,
height: u32,
pixels: &[ColorRgba8],
) -> Result<Self, Error>
pub fn from_pixels( width: u32, height: u32, pixels: &[ColorRgba8], ) -> Result<Self, Error>
Construct a texture from a borrowed pixel slice. 从借用的像素切片构造一个纹理。
§Errors
与 Texture::new 相同。
Same errors as Texture::new.
Sourcepub fn solid(color: ColorRgba8) -> Self
pub fn solid(color: ColorRgba8) -> Self
Build a 1×1 solid-color texture: any UV samples the same color. 构建一个 1×1 纯色纹理:任何 UV 都采样到相同颜色。
Sourcepub fn pixels(&self) -> &[ColorRgba8]
pub fn pixels(&self) -> &[ColorRgba8]
The underlying pixel buffer, row-major. 底层像素缓冲,按行优先排列。
Sourcepub fn sample(&self, u: f32, v: f32) -> ColorRgba8
pub fn sample(&self, u: f32, v: f32) -> ColorRgba8
Sample a texel with [0, 1)-wrapped nearest-neighbor addressing.
使用 [0, 1) 环绕的最近邻寻址采样一个纹素。
Out-of-range or non-finite coordinates are wrapped/clamped and never index out of bounds. 越界或非有限坐标会被环绕/截断,绝不会产生越界索引。
Sourcepub fn sample_linear(&self, u: f32, v: f32) -> Rgb
pub fn sample_linear(&self, u: f32, v: f32) -> Rgb
Sample and convert to linear light. 采样并转换为线性光。