MTLRenderPassColorAttachmentDescriptor.clearColor does not respect alpha value
<p>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:</p>

<p>I'm setting the NSView's background color to a clear color:</p>

<pre><code>layer?.backgroundColor = NSColor.clearColor().CGColor
</code></pre>

<p>I have verified that this view in fact renders clear over the other view (rendering nothing in drawRect).</p>

<p>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.</p>

<pre><code>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()
        }
    }
</code></pre>

<p>Any suggestions on how to get the texture cleared with a transparent color before rendering any content into it?</p>

<p>Thank you.</p>

<p><a href="https://i.stack.imgur.com/x0tOW.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/x0tOW.jpg" alt="enter image description here"></a></p>

<p><strong>UPDATE:</strong> I seem to have answered my own question, and am updating this post with it so others can find this useful. </p>

<p>The trick seems to be to set the layer to be transparent. </p>

<pre><code>class MetalView: MTKView {
    required init(coder: NSCoder) {
        super.init(coder: coder)

        layer?.opaque = false
    }
}
</code></pre>