2
votes

Question is quite simple. On Windows you have BitBlt() to draw to the screen. On OS X you could normally use OpenGl but how do I draw the bitmap to the screen using Apples new Metal framework? I cant find anything valuable in Apples Metal references. I'm right now using Core Graphics for the drawing part but since my bitmap is updating all the time, I feel like I should move to Metal to reduce the overhead.

1
this is why we need "lacks minimal understanding" backtbodt
There is no reason you should have to use Metal to draw images. -[NSImage drawInRect:] will do just fine.tbodt
Isn't NSImage quite slow compared to Metal? What if I'm updating my bitmap 30 times a second? I asked for Metal because I want to use Metal.user148013
@user148013 how big is the image that you are updating 30 times a second?Fogmeister
500 x 800 pixels. But i could increase the size without problems. I just want to draw to the screen with litte overhead as possible.user148013

1 Answers

3
votes

The very short answer is this: First, you need to setup a standard rendering pipeline using Metal, which is a bit of work, if you don't know anything about the rendering pipeline (note: but this can be simplified by avoiding 3D stuff by rendering a quad with two triangles, just give xy coordinates for the vertices). There is a lot of sample code from Apple that shows how to setup a standard rendering pipeline, the simplest is maybe MetalImageProcessing, so you could strip that down (even though that uses a compute shader which is overcomplicated to draw in, you'd want to substitute it for standard vertex and fragment shaders).

Second, you need to learn how vertex and fragment shaders work and how to draw stuff with them, see shadertoy for this.

Just noticed the users last comment, if you have an array of bytes that represent an image then you can just make an MTLTexture out of that and render it to the screen, see Apple's example above but change the compute shader to standard vertex and fragments shaders for faster performance.