I wanna draw a pixel buffer directly on the screen with the Metal API.
in OpenGL I can use glDrawPixels
how to do it in Metal?
I wanna draw a pixel buffer directly on the screen with the Metal API.
in OpenGL I can use glDrawPixels
how to do it in Metal?
What's your use case?
Without more information it's difficult to say, but it sounds like you might want to use a MTLBlitCommandEncoder to copy the data from some buffer to the drawable texture.
It should achieve a similar effect. But if it doesn't, please provide more information.
lets say I have a picture in a pixel buffer(RGBA). just wanna display it on the screen as raw data.
in OpenGL i can just draw it directly on the screen by calling glDrawPixels.
So my question is: can I do it the "same way" in Metal OR do I have to draw it on a texture and display it by drawing to triangles(to make a quad)?
the last way is not a such good idea for my engine :(
So it sounds like your use case is simple enough to just a MTLBlitCommandEncoder, as [@Matt Cox](https://developer.apple.com/forums/profile/Matt Cox) suggested. You'd need to get the data into a Metal buffer first and then you can use the copyFromBuffer method to fill the drawable texture with data you filled from that buffer.
Note, that In OpenGL you don't need to copy the data into a buffer first to use glDrawPixels. So if that's a concern, there are some tricks you can use to avoid that copy.
Yes, it is very important that the routine is fast. I calculate the image first (streaming data, like a video decoder) and than need the fastest way to "flip" it on the screen.
I found this: [https://stackoverflow.com/questions/64267791/present-a-pixel-buffer-to-a-mtkview)
Is this the fastest way, or is the solution with the texture better?
I'm very interested in this tricks, but please provide C++ code.
OK, I'm going to use
func copy(from: any MTLBuffer, sourceOffset: Int, sourceBytesPerRow: Int, sourceBytesPerImage: Int, sourceSize: MTLSize, to: any MTLTexture, destinationSlice: Int, destinationLevel: Int, destinationOrigin: MTLOrigin)
@Graphics and Games Engineer: how not to copy my data in the MTLBuffer every frame?
I am using newBufferWithBytesNoCopy(...) now, but I get an Access Violation :( the pointer I pass is 6404804 so it is aligned
ideas?
sorry :)
I'm using posix_memalign() now and it works perfectly,
thx