【问题标题】:MetalKit - How to use the option of (MTKTextureLoader method) newTextureWithContentsOfURL?MetalKit - 如何使用(MTKTextureLoader 方法)newTextureWithContentsOfURL 的选项?
【发布时间】:2018-12-20 06:36:23
【问题描述】:

我正在尝试使用 MetalKit api 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

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

如何使用 NSDictionary 设置这个选项?

【问题讨论】:

  • 我使用 NSDictionary *dict = [NSDictionary dictionaryWithObject:@(YES) forKey:MTKTextureLoaderOptionOrigin];它可以工作,但我仍然不知道这段代码是什么意思。
  • 我很惊讶这行得通。这是要使用的正确选项名称,但通常您会提供原始值之一,例如 MTKTextureLoaderOriginFlippedVertically,而不是 NSNumber

标签: objective-c macos metal metalkit


【解决方案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];

【讨论】:

    猜你喜欢
    • 2020-02-11
    • 2020-07-12
    • 2018-09-08
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多