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. 构造一个纹理,校验尺寸和缓冲长度。
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. 从借用的像素切片构造一个纹理。
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 都采样到相同颜色。
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn pixels(&self) -> &[ColorRgba8]
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. 采样并转换为线性光。
Trait Implementations§
impl StructuralPartialEq for Texture
Auto Trait Implementations§
impl Freeze for Texture
impl RefUnwindSafe for Texture
impl Send for Texture
impl Sync for Texture
impl Unpin for Texture
impl UnsafeUnpin for Texture
impl UnwindSafe for Texture
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more