We've got a chunk of code that draws to an NSImage (text with a nice looking background), then converts it to an NSBitmapImageRep for use as a texture (originally OpenGL, now Metal). It's worked without issue for years on thousands of customer machines.
Psuedocode:
image = [[NSImage alloc] initWithSize:size];
[image lockFocus];
//Do drawing
bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect];
[image unlockFocus];
//Generate texture using [bitmap bitmapData];
Now we have a customer with a brand new MacBook running macOS 10.15, and the texture is getting corrupted. We've tracked it down to the NSBitmapImageRep being created with floating point samples.
I've also noticed that initWithFocusedViewRect is now deprecated. I've attempted to use [image CGImageForProposedRect] and then create the NSBitmapImageRep from the CGImage, but that has the same problem with floating point samples.
So my questions are:
- Is it possible to convert the NSBitmapImageRep to the format we need it in (8-bit integer samples, 32bpp)?
- Or, if I use one of the NSBitmapImageRep initializers that allow me to specify the format I want, how do I get the data into it from an NSImage?
- Or, is there another way to go about doing this?