I am new to Metal and am trying to add a metal view on top of another NSView. Within the metal view (MTKView) i want to render a triangle, over clear (transparent) background. However, the background of the MTKView is always a solid color. Here is what i have tried:
I'm setting the NSView's background color to a clear color:
layer?.backgroundColor = NSColor.clearColor().CGColor
I have verified that this view in fact renders clear over the other view (rendering nothing in drawRect).
If i start rendering my triangle in drawRect, it is always over a solid background. I was able to change the background color RGB values, bot not A. It's always solid color.
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
...
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
rpd.colorAttachments[0].loadAction = .Clear
rpd.colorAttachments[0].clearColor = MTLClearColorMake(1, 0, 0, 0.5)
...
command_buffer.presentDrawable(drawable)
command_buffer.commit()
}
}
Any suggestions on how to get the texture cleared with a transparent color before rendering any content into it?
Thank you.