MTLClearColor not working

Hi,


I'm trying to set a background colour for my metal scene. I'm using:


descriptor.colorAttachments[0].clearColor = MTLClearColorMake(Double(newColourComponenets.r), Double(newColourComponenets.g), Double(newColourComponenets.b), 1.0)


Construction of a background colour using MTLClearColor(r:g:b:) gives the same outcome.


When I set


descriptor.colorAttachments[0].loadAction = .load


then the background colour is rendered, but changing it to .clear means I just get a black background.


I note from here that there is a circumstance when the background colour is ignored, but due to poor writing, I can't fathom when that is. Does anyone know....?

Accepted Reply

Found the answer:


the MTLClearColor has to be set before the makeCommandBuffer() and makeRenderCommandEncoder(description:) is called.

Replies

Found the answer:


the MTLClearColor has to be set before the makeCommandBuffer() and makeRenderCommandEncoder(description:) is called.