#[repr(C)]pub struct MTKTextureLoader { /* private fields */ }
MTKTextureLoader
only.Expand description
Load Metal textures from files with the device specified at initialization
See also Apple’s documentation
Implementations§
Source§impl MTKTextureLoader
impl MTKTextureLoader
Sourcepub unsafe fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>
pub unsafe fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>
Metal device with which to create Metal textures
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithDevice(
this: Allocated<Self>,
device: &ProtocolObject<dyn MTLDevice>,
) -> Retained<Self>
pub unsafe fn initWithDevice( this: Allocated<Self>, device: &ProtocolObject<dyn MTLDevice>, ) -> Retained<Self>
Initialize the loader
Parameter device
: Metal device with which to create Metal textures
Sourcepub unsafe fn newTextureWithContentsOfURL_options_completionHandler(
&self,
url: &NSURL,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderCallback,
)
Available on crate feature block2
only.
pub unsafe fn newTextureWithContentsOfURL_options_completionHandler( &self, url: &NSURL, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderCallback, )
block2
only.Asynchronously create a Metal texture and load image data from the file at URL
Parameter URL
: Location of image file from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter completionHandler
: Block called when the texture has been loaded and fully initialized
Sourcepub unsafe fn newTextureWithName_scaleFactor_bundle_options_completionHandler(
&self,
name: &NSString,
scale_factor: CGFloat,
bundle: Option<&NSBundle>,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderCallback,
)
Available on crate features block2
and objc2-core-foundation
only.
pub unsafe fn newTextureWithName_scaleFactor_bundle_options_completionHandler( &self, name: &NSString, scale_factor: CGFloat, bundle: Option<&NSBundle>, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderCallback, )
block2
and objc2-core-foundation
only.Asynchronously create a Metal texture and load image data from a given texture or image asset name
Parameter name
: A texture or image asset name
Parameter scaleFactor
: scale factor of the texture to retrieve from the asset catalog. Typically the
value retrieved from -[UIView contentScale] or -[NSWindow backingScaleFactor].
Parameter bundle
: Resource bundle in which the asset is located. Main bundle used if nil.
Parameter options
: Dictonary of MTKTextureLoaderOptions. The following options are ignormed when used
to load a texture asset but can be used when creating a texture from an image asset:
MTKTextureLoaderOptionGenerateMipmaps
MTKTextureLoaderOptionSRGB
MTKTextureLoaderOptionCubeFromVerticalTexture
MTKTextureLoaderOptionOrigin
Parameter completionHandler
: Block called when texture has been loaded and fully initialized
Uses texture data from version of the texture from the texture set in the asset catalog which mathces the device’s traits. This method attempts to load a texture asset with thw name iven. If a texture asset with the name given does not exist, it will attempt to create a texture from an image asset with the given name
Sourcepub unsafe fn newTexturesWithContentsOfURLs_options_completionHandler(
&self,
ur_ls: &NSArray<NSURL>,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderArrayCallback,
)
Available on crate feature block2
only.
pub unsafe fn newTexturesWithContentsOfURLs_options_completionHandler( &self, ur_ls: &NSArray<NSURL>, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderArrayCallback, )
block2
only.Asynchronously create an array of Metal textures and load image data from the files at URLs
Parameter URLs
: Locations of image files from which to create the textures
Parameter options
: Dictonary of MTKTextureLoaderOptions, which will be used for every texture loaded
Parameter completionHandler
: Block called when all of the textures have been loaded and fully initialized. The array of MTLTextures will be the same length and in the same order as the requested array of paths. If an error occurs while loading a texture, the corresponding array index will contain NSNull. The NSError will be null if all of the textures are loaded successfully, or will correspond to one of the textures which failed to load.
Sourcepub unsafe fn newTexturesWithNames_scaleFactor_bundle_options_completionHandler(
&self,
names: &NSArray<NSString>,
scale_factor: CGFloat,
bundle: Option<&NSBundle>,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderArrayCallback,
)
Available on crate features block2
and objc2-core-foundation
only.
pub unsafe fn newTexturesWithNames_scaleFactor_bundle_options_completionHandler( &self, names: &NSArray<NSString>, scale_factor: CGFloat, bundle: Option<&NSBundle>, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderArrayCallback, )
block2
and objc2-core-foundation
only.Asynchronously create Metal textures and load image data from a given texture or image asset names
Parameter names
: An array texture or image asset names. If an error occurs while loading a texture,
the corresponding index in the returned array contain [NSNull null]
Parameter scaleFactor
: scale factor of the texture to retrieve from the asset catalog. Typically the
value retrieved from -[UIView contentScale] or -[NSWindow backingScaleFactor].
Parameter bundle
: Resource bundle in which the assets are located. Main bundle used if nil.
Parameter options
: Dictonary of MTKTextureLoaderOptions. The following options are ignormed when used
to load a texture asset but can be used when creating a texture from an image asset
MTKTextureLoaderOptionGenerateMipmaps
MTKTextureLoaderOptionSRGB
MTKTextureLoaderOptionCubeFromVerticalTexture
MTKTextureLoaderOptionOrigin
Parameter completionHandler
: Block called when all of the textures have been loaded and fully
initialized. The NSError will be null if all of the textures are loaded
successfully, or will correspond to one of the textures which failed to
load.
Uses texture data from version of the texture from the texture set in the asset catalog which mathces the device’s traits. This method attempts to load a texture asset with each name iven. If a texture asset with the name given does not exist, it will attempt to create a texture from an image asset with the given name.
Sourcepub unsafe fn newTextureWithData_options_completionHandler(
&self,
data: &NSData,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderCallback,
)
Available on crate feature block2
only.
pub unsafe fn newTextureWithData_options_completionHandler( &self, data: &NSData, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderCallback, )
block2
only.Asynchronously create a Metal texture and load image data from the NSData object provided
Parameter data
: NSData object containing image file data from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter completionHandler
: Block called when texture has been loaded and fully initialized
Sourcepub unsafe fn newTextureWithCGImage_options_completionHandler(
&self,
cg_image: &CGImage,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderCallback,
)
Available on crate features block2
and objc2-core-graphics
only.
pub unsafe fn newTextureWithCGImage_options_completionHandler( &self, cg_image: &CGImage, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderCallback, )
block2
and objc2-core-graphics
only.Asynchronously create a Metal texture and load image data from the given CGImageRef
Parameter cgImage
: CGImageRef containing image data from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter completionHandler
: Block called when texture has been loaded and fully initialized
Sourcepub unsafe fn newTextureWithMDLTexture_options_completionHandler(
&self,
texture: &MDLTexture,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
completion_handler: MTKTextureLoaderCallback,
)
Available on crate features block2
and objc2-model-io
only.
pub unsafe fn newTextureWithMDLTexture_options_completionHandler( &self, texture: &MDLTexture, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, completion_handler: MTKTextureLoaderCallback, )
block2
and objc2-model-io
only.Asynchronously create a Metal texture and load image data from the given MDLTexture
Parameter texture
: MDLTexture containing image data from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter completionHandler
: Block called when texture has been loaded and fully initialized
Sourcepub unsafe fn newTextureWithContentsOfURL_options_error(
&self,
url: &NSURL,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
pub unsafe fn newTextureWithContentsOfURL_options_error( &self, url: &NSURL, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, ) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
Synchronously create a Metal texture and load image data from the file at URL
Returns: The Metal texture. nil if an error occured
Parameter URL
: Location of image file from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter error
: Pointer to an autoreleased NSError object which will be set if an error occurred
Sourcepub unsafe fn newTextureWithData_options_error(
&self,
data: &NSData,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
pub unsafe fn newTextureWithData_options_error( &self, data: &NSData, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, ) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
Synchronously create a Metal texture and load image data from the NSData object provided
Returns: The Metal texture. nil if an error occured
Parameter data
: NSData object containing image file data from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter error
: Pointer to an autoreleased NSError object which will be set if an error occurred
Sourcepub unsafe fn newTextureWithCGImage_options_error(
&self,
cg_image: &CGImage,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
Available on crate feature objc2-core-graphics
only.
pub unsafe fn newTextureWithCGImage_options_error( &self, cg_image: &CGImage, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, ) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
objc2-core-graphics
only.Synchronously create a Metal texture and load image data from the given CGImageRef
Returns: The Metal texture. nil if an error occured
Parameter cgImage
: CGImageRef containing image data from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter error
: Pointer to an autoreleased NSError object which will be set if an error occurred
Sourcepub unsafe fn newTextureWithMDLTexture_options_error(
&self,
texture: &MDLTexture,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
Available on crate feature objc2-model-io
only.
pub unsafe fn newTextureWithMDLTexture_options_error( &self, texture: &MDLTexture, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, ) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
objc2-model-io
only.Synchronously create a Metal texture and load image data from the given MDLTexture
Returns: The Metal texture. nil if an error occured
Parameter texture
: MDLTexture containing image data from which to create the texture
Parameter options
: Dictonary of MTKTextureLoaderOptions
Parameter error
: Pointer to an autoreleased NSError object which will be set if an error occurred
Sourcepub unsafe fn newTextureWithName_scaleFactor_bundle_options_error(
&self,
name: &NSString,
scale_factor: CGFloat,
bundle: Option<&NSBundle>,
options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>,
) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
Available on crate feature objc2-core-foundation
only.
pub unsafe fn newTextureWithName_scaleFactor_bundle_options_error( &self, name: &NSString, scale_factor: CGFloat, bundle: Option<&NSBundle>, options: Option<&NSDictionary<MTKTextureLoaderOption, AnyObject>>, ) -> Result<Retained<ProtocolObject<dyn MTLTexture>>, Retained<NSError>>
objc2-core-foundation
only.Synchronously create a Metal texture with texture data from a given texture or image asset name
Returns: The Metal texture. nil if an error occured
Parameter names
: An array of texture asset names
Parameter scaleFactor
: scale factor of the texture to retrieve from the asset catalog. Typically the
value retrieved from -[UIView contentScale] or -[NSWindow backingScaleFactor].
Parameter bundle
: Resource bundle in which the asset is located. Main bundle used if nil.
Parameter options
: Dictonary of MTKTextureLoaderOptions. The following options are ignormed when used
to load a texture asset but can be used when creating a texture from an image asset
MTKTextureLoaderOptionGenerateMipmaps
MTKTextureLoaderOptionSRGB
MTKTextureLoaderOptionCubeFromVerticalTexture
MTKTextureLoaderOptionOrigins
Uses texture data from version of the texture from the texture set in the asset catalog which mathces the device’s traits. This method attempts to load a texture asset with the name given. If a texture asset with the name given does not exist, it will attempt to create a texture from an image asset with the given name.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T
.
This is the reference-variant. Use Retained::downcast
if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString
.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString
to a NSMutableString
,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass:
for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject
.
§Panics
This works internally by calling isKindOfClass:
. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject
and
NSProxy
implement this method.
§Examples
Cast an NSString
back and forth from NSObject
.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();
Try (and fail) to cast an NSObject
to an NSString
.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());
Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();
This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}
Trait Implementations§
Source§impl AsRef<AnyObject> for MTKTextureLoader
impl AsRef<AnyObject> for MTKTextureLoader
Source§impl AsRef<MTKTextureLoader> for MTKTextureLoader
impl AsRef<MTKTextureLoader> for MTKTextureLoader
Source§impl AsRef<NSObject> for MTKTextureLoader
impl AsRef<NSObject> for MTKTextureLoader
Source§impl Borrow<AnyObject> for MTKTextureLoader
impl Borrow<AnyObject> for MTKTextureLoader
Source§impl Borrow<NSObject> for MTKTextureLoader
impl Borrow<NSObject> for MTKTextureLoader
Source§impl ClassType for MTKTextureLoader
impl ClassType for MTKTextureLoader
Source§const NAME: &'static str = "MTKTextureLoader"
const NAME: &'static str = "MTKTextureLoader"
Source§type ThreadKind = <<MTKTextureLoader as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<MTKTextureLoader as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for MTKTextureLoader
impl Debug for MTKTextureLoader
Source§impl Deref for MTKTextureLoader
impl Deref for MTKTextureLoader
Source§impl Hash for MTKTextureLoader
impl Hash for MTKTextureLoader
Source§impl Message for MTKTextureLoader
impl Message for MTKTextureLoader
Source§impl NSObjectProtocol for MTKTextureLoader
impl NSObjectProtocol for MTKTextureLoader
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref