如何使用 MTKTextureLoader newTextureWithContentsOfURL 的选项?

问题描述 投票:0回答:1

我正在尝试使用 MetalKit

newTextureWithContentsOfURL
为牛创建纹理。

MTKTextureLoader *texture_loader = [[MTKTextureLoader alloc] initWithDevice:device];
NSURL *cow_image = [[NSBundle mainBundle] URLForResource:@"spot_texture" withExtension:@"png"];
NSError *error;
diffuse_texture = [texture_loader newTextureWithContentsOfURL:cow_image options:nil error:&error];

这是样本牛(上)和我的牛(下)的样子。

Sample cow

My cow

我不知道这是什么原因,但我认为这些选项可能会有所帮助。

How to set this option using

NSDictionary
?

objective-c macos metal metalkit mtktextureloader
1个回答
1
投票

基于这个Objective-C Literals

MTKTextureLoader *texture_loader = [[MTKTextureLoader alloc] initWithDevice:device];
NSURL *cow_image = [[NSBundle mainBundle] URLForResource:@"spot_texture" 
withExtension:@"png"];
NSError *error;
diffuse_texture = [texture_loader newTextureWithContentsOfURL:cow_image options:@{ MTKTextureLoaderOptionSRGB : @true, MTKTextureLoaderOptionOrigin : @true} 
error:&error];
© www.soinside.com 2019 - 2024. All rights reserved.