Hello, is there a way to directly draw to a Metal texture that a shader (in a separate, custom library) can manipulate?
Peter Tran
10/15/2024, 2:58 PM
By 'draw' I mean
DrawScope
draw calls.
In Android I can do this:
Copy code
val androidSurface: android.view.Surface = getHWSurfaceFromSomewher()
val androidCanvas = surface.lockHardwareCanvas()
val canvas = Canvas(androidCanvas)
CanvasDrawScope().draw(
canvas = canvas
) {
//DrawScope draw calls
}
surface.unlockCanvasAndPost(androidCanvas)
// drawing has been rendered to texture
Peter Tran
10/15/2024, 3:00 PM
For iOS it seems like I could do something like:
Copy code
val tex = device!!.newTextureWithDescriptor(texDescriptor)
//what is this???
val texturePtr
val renderTarget = BackendRenderTarget.makeMetal(width, height, texturePtr)
val skiaSurface = Surface.makeFromBackendRenderTarget(rt = renderTarget)
val composeCanvas = skiaSurface?.canvas?.asComposeCanvas()
But I do not know what to pass in for
texturePtr
to
BackendRenderTarget.makeMetal
.
Peter Tran
10/15/2024, 3:07 PM
I know I could render to a bitmap using
Canvas(bitmap)
, and then copy the pixels to a texture. But the extra copy seems less than ideal vs letting the skia backend draw directly to the texture.
Thoughts?