Skip to main content

Texture

Struct Texture 

Source
pub struct Texture(/* private fields */);
Expand description

A texture resource that stores formatted image data.

C++ equivalent: MTL::Texture

Implementations§

Source§

impl Texture

Source

pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self>

Create a Texture from a raw pointer.

§Safety

The pointer must be a valid Metal texture object.

Source

pub fn as_raw(&self) -> *mut c_void

Get the raw pointer to the texture.

Source

pub fn texture_type(&self) -> TextureType

Get the texture type.

C++ equivalent: TextureType textureType() const

Source

pub fn pixel_format(&self) -> PixelFormat

Get the pixel format.

C++ equivalent: PixelFormat pixelFormat() const

Source

pub fn width(&self) -> UInteger

Get the width of the texture.

C++ equivalent: NS::UInteger width() const

Source

pub fn height(&self) -> UInteger

Get the height of the texture.

C++ equivalent: NS::UInteger height() const

Source

pub fn depth(&self) -> UInteger

Get the depth of the texture.

C++ equivalent: NS::UInteger depth() const

Source

pub fn mipmap_level_count(&self) -> UInteger

Get the number of mipmap levels.

C++ equivalent: NS::UInteger mipmapLevelCount() const

Source

pub fn sample_count(&self) -> UInteger

Get the sample count (for multisampled textures).

C++ equivalent: NS::UInteger sampleCount() const

Source

pub fn array_length(&self) -> UInteger

Get the array length (for texture arrays).

C++ equivalent: NS::UInteger arrayLength() const

Source

pub fn usage(&self) -> TextureUsage

Get the texture usage flags.

C++ equivalent: TextureUsage usage() const

Source

pub fn is_shareable(&self) -> bool

Check if this is a shareable texture.

C++ equivalent: bool isShareable() const

Source

pub fn is_framebuffer_only(&self) -> bool

Check if this is a framebuffer-only texture.

C++ equivalent: bool isFramebufferOnly() const

Source

pub fn first_mipmap_in_tail(&self) -> UInteger

Get the first mipmap level used in a texture view.

C++ equivalent: NS::UInteger firstMipmapInTail() const

Source

pub fn tail_size_in_bytes(&self) -> UInteger

Get the tail size in bytes for sparse textures.

C++ equivalent: NS::UInteger tailSizeInBytes() const

Source

pub fn is_sparse(&self) -> bool

Check if the tail is sparse.

C++ equivalent: bool isSparse() const

Source

pub fn gpu_resource_id(&self) -> ResourceID

Get the GPU resource ID for bindless access.

C++ equivalent: ResourceID gpuResourceID() const

Source

pub fn allow_gpu_optimized_contents(&self) -> bool

Check if texture allows GPU-optimized contents.

C++ equivalent: bool allowGPUOptimizedContents() const

Source

pub fn compression_type(&self) -> TextureCompressionType

Get the texture compression type.

C++ equivalent: TextureCompressionType compressionType() const

Source

pub fn swizzle(&self) -> TextureSwizzleChannels

Get the texture swizzle channels.

C++ equivalent: TextureSwizzleChannels swizzle() const

Source

pub fn parent_texture(&self) -> Option<Texture>

Get the parent texture (if this is a view).

C++ equivalent: Texture* parentTexture() const

Source

pub fn parent_relative_level(&self) -> UInteger

Get the parent relative level (for texture views).

C++ equivalent: NS::UInteger parentRelativeLevel() const

Source

pub fn parent_relative_slice(&self) -> UInteger

Get the parent relative slice (for texture views).

C++ equivalent: NS::UInteger parentRelativeSlice() const

Source

pub fn buffer(&self) -> Option<Buffer>

Get the buffer (if texture is backed by a buffer).

C++ equivalent: Buffer* buffer() const

Source

pub fn buffer_offset(&self) -> UInteger

Get the buffer offset (if texture is backed by a buffer).

C++ equivalent: NS::UInteger bufferOffset() const

Source

pub fn buffer_bytes_per_row(&self) -> UInteger

Get the buffer bytes per row (if texture is backed by a buffer).

C++ equivalent: NS::UInteger bufferBytesPerRow() const

Source

pub fn iosurface(&self) -> Option<*mut c_void>

Get the IOSurface backing this texture, if any.

C++ equivalent: IOSurfaceRef iosurface() const

Returns an opaque pointer to the IOSurfaceRef, or None if the texture is not backed by an IOSurface.

Source

pub fn iosurface_plane(&self) -> UInteger

Get the IOSurface plane index for this texture.

C++ equivalent: NS::UInteger iosurfacePlane() const

Source

pub fn sparse_texture_tier(&self) -> TextureSparseTier

Get the sparse texture tier for this texture.

C++ equivalent: TextureSparseTier sparseTextureTier() const

Source

pub fn remote_storage_texture(&self) -> Option<Texture>

Get the remote storage texture (for cross-process sharing).

C++ equivalent: Texture* remoteStorageTexture() const

Source

pub fn new_remote_texture_view_for_device( &self, device: &Device, ) -> Option<Texture>

Create a remote texture view for a different device.

C++ equivalent: Texture* newRemoteTextureViewForDevice(const Device*)

Source

pub fn new_texture_view_with_pixel_format( &self, pixel_format: PixelFormat, ) -> Option<Texture>

Create a texture view with a different pixel format.

C++ equivalent: Texture* newTextureView(PixelFormat)

Source

pub fn new_texture_view( &self, pixel_format: PixelFormat, texture_type: TextureType, level_range: Range, slice_range: Range, ) -> Option<Texture>

Create a texture view with different pixel format and texture type.

C++ equivalent: Texture* newTextureView(PixelFormat, TextureType, NS::Range levels, NS::Range slices)

Source

pub fn new_texture_view_with_swizzle( &self, pixel_format: PixelFormat, texture_type: TextureType, level_range: Range, slice_range: Range, swizzle: TextureSwizzleChannels, ) -> Option<Texture>

Create a texture view with swizzle.

C++ equivalent: Texture* newTextureView(PixelFormat, TextureType, NS::Range, NS::Range, TextureSwizzleChannels)

Source

pub fn new_shared_texture_handle(&self) -> Option<SharedTextureHandle>

Create a shared texture handle for cross-process sharing.

C++ equivalent: SharedTextureHandle* newSharedTextureHandle()

Source

pub fn new_texture_view_with_descriptor( &self, descriptor: &TextureViewDescriptor, ) -> Option<Texture>

Create a texture view with a descriptor.

C++ equivalent: Texture* newTextureView(const TextureViewDescriptor*)

Source

pub unsafe fn get_bytes( &self, pixel_bytes: *mut c_void, bytes_per_row: UInteger, bytes_per_image: UInteger, region: Region, mipmap_level: UInteger, slice: UInteger, )

Get texture data bytes (full version with slice).

C++ equivalent: void getBytes(void*, NS::UInteger, NS::UInteger, MTL::Region, NS::UInteger, NS::UInteger)

§Safety

The pixel_bytes pointer must be valid for writing the requested data.

Source

pub unsafe fn get_bytes_simple( &self, pixel_bytes: *mut c_void, bytes_per_row: UInteger, region: Region, mipmap_level: UInteger, )

Get texture data bytes (simple version for 2D textures).

C++ equivalent: void getBytes(void*, NS::UInteger, MTL::Region, NS::UInteger)

§Safety

The pixel_bytes pointer must be valid for writing the requested data.

Source

pub unsafe fn replace_region( &self, region: Region, mipmap_level: UInteger, slice: UInteger, pixel_bytes: *const c_void, bytes_per_row: UInteger, bytes_per_image: UInteger, )

Replace a region of the texture (full version with slice).

C++ equivalent: void replaceRegion(MTL::Region, NS::UInteger, NS::UInteger, const void*, NS::UInteger, NS::UInteger)

§Safety

The pixel_bytes pointer must be valid for reading the data to copy.

Source

pub unsafe fn replace_region_simple( &self, region: Region, mipmap_level: UInteger, pixel_bytes: *const c_void, bytes_per_row: UInteger, )

Replace a region of the texture (simple version for 2D textures).

C++ equivalent: void replaceRegion(MTL::Region, NS::UInteger, const void*, NS::UInteger)

§Safety

The pixel_bytes pointer must be valid for reading the data to copy.

Source

pub fn label(&self) -> Option<String>

Get the label for this texture.

C++ equivalent: NS::String* label() const

Source

pub fn set_label(&self, label: &str)

Set the label for this texture.

C++ equivalent: void setLabel(const NS::String*)

Source

pub fn device(&self) -> Device

Get the device that created this texture.

C++ equivalent: Device* device() const

Source

pub fn resource_options(&self) -> ResourceOptions

Get the resource options.

C++ equivalent: ResourceOptions resourceOptions() const

Source

pub fn allocated_size(&self) -> UInteger

Get the allocated size.

C++ equivalent: NS::UInteger allocatedSize() const

Trait Implementations§

Source§

impl Clone for Texture

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · 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 Drop for Texture

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Referencing for Texture

Source§

fn as_ptr(&self) -> *const c_void

Get the raw pointer to the Objective-C object.
Source§

fn as_mut_ptr(&self) -> *mut c_void

Get the raw mutable pointer to the Objective-C object.
Source§

fn retain(&self) -> Self
where Self: Clone,

Retain the object, incrementing its reference count. Read more
Source§

fn release(&self)

Release the object, decrementing its reference count. Read more
Source§

fn autorelease(&self) -> Self
where Self: Clone,

Autorelease the object. Read more
Source§

fn retain_count(&self) -> usize

Get the retain count of the object. Read more
Source§

impl Send for Texture

Source§

impl Sync 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.