HEIC as texture source

Hi Kind Folks,

I have a simple texture load function which does fine when the source is a jpeg/jpg, but fails if the content is HEIC. I wandered around a bit on the web and found some fairly complicated ways to convert heic content into jpeg using various CI manipulations/routines and other stuff and quickly got lost and overwhelmed (of course)

Is there a “correct” way to do this so that my texture loader will load an heic image?

I use the “correct” qualifier because, I’m an old school coder (I mean, we’re talking the end of the IBM 029 era), so I did devise a really ugly (and simple) hack that works, but it’s rather embarrassing (still amazed my grad school were using those things)

Thanks in advance, and apologies if this is a really dumb question.

My loader code is as follows:

static func loadTexture(fileName: String) -> MTLTexture? {
    let loader = MTKTextureLoader(device: Renderer.Device)
    let texture: MTLTexture?
    var url:URL
    url = URL(fileURLWithPath: fileName)
    let loaderOptions : [MTKTextureLoader.Option: Any] =
                        [.origin:MTKTextureLoader.Origin.bottomLeft,
                         .generateMipmaps: false]
    var ok:Bool
    ok = ((try? url.checkResourceIsReachable()) != nil)
    texture = try? loader.newTexture(URL:url,options:loaderOptions)
}
1 Like