Skip to main content

Texture

Struct Texture 

Source
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

Source

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.

Source

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.

Source

pub fn solid(color: ColorRgba8) -> Self

Build a 1×1 solid-color texture: any UV samples the same color. 构建一个 1×1 纯色纹理:任何 UV 都采样到相同颜色。

Source

pub fn width(&self) -> u32

Texture width in pixels. 纹理宽度(像素)。

Source

pub fn height(&self) -> u32

Texture height in pixels. 纹理高度(像素)。

Source

pub fn pixels(&self) -> &[ColorRgba8]

The underlying pixel buffer, row-major. 底层像素缓冲,按行优先排列。

Source

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. 越界或非有限坐标会被环绕/截断,绝不会产生越界索引。

Source

pub fn sample_linear(&self, u: f32, v: f32) -> Rgb

Sample and convert to linear light. 采样并转换为线性光。

Trait Implementations§

Source§

impl Clone for Texture

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Texture

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Texture

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Texture

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.