如何在Metal中创建纯色纹理?

问题描述

我正在尝试使用基本的纹理加载器来创建单色纹理,但是失败了。这是示例所能达到的最小化。可能是什么问题?

为什么这可能会失败?

            NSError* texture_loader_error = nil;
            // default Metalkit texture loader
            _texture_loader = [[MTKTextureLoader alloc] initWithDevice:_device];
            
            NSDictionary* texture_loader_options = @{MTKTextureLoaderOptionGenerateMipmaps: @(NO),MTKTextureLoaderOptionSRGB: @(YES)};
            
            usize texture_index = 0;
            
            // load default textures
            {
                simd_float4 color_white = simd_make_float4(1.0,1.0,1.0);
                NSData* color_data_white = [[NSData alloc] initWithBytes:&color_white length:sizeof(color_white)];
                
                id<MTLTexture> texture = [_texture_loader newTextureWithData:color_data_white options: texture_loader_options error:&texture_loader_error];
                if (!texture) {
                    NSLog(@"Failed to create texture,error %@",error);
                } else {
                    texture_index += 1;
                }
                
            }

textureLoader是否希望数据采用png之类的通用格式,而不仅仅是字节?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)