Search code examples
objective-cswiftcolorsbackgroundmetal

change CAMetalLayer background color


My CAMetalLayer background color is black, even if i'm assigning new color as the backgroundColor property.

Am i missing something? Thanks!

Link to the original project :

https://github.com/audiokit/MetalParticles


Solution

  • This project takes a rather unconventional approach to clearing the drawable's texture each frame: it replaces the textures contents with an array of zeros that is the same size as the texture (width * height * 4). Subsequently, it encodes some compute work that actually draws the particles. This is almost certainly not the most efficient way to achieve this effect, but if you want to make the smallest change that could possibly work (as opposed to experimenting with making the code as efficient as possible), Just fill the blankBitmapRawData array with your desired clear color (near line 82 of ParticleLab.swift).