Search code examples
iosopengl-esmetal

Trade-offs between RGBA and BGRA formats for Metal textures


I am developing an iOS application using Metal and have the choice of using either RGBA or BGRA for texture formats. The application will be:

  • Rendering into textures
  • Drawing textures on screen
  • Generating UIImages from textures
  • Initialising textures from UIImages

Are there any performance trade-offs for choosing RGBA over BGRA? The latter two points lead me to RGBA, but I also notice that MTKTextureLoader defaults to BGRA textures. I was unable to find any application notes addressing difference between RGBA and BRGA in Metal.


Solution

  • BGRA is the default and most optimal format for textures and image data on iOS devices. While RGBA is supported, use of RGBA format can result in real performance issues when reading RGBA textures with UIImage and CoreGraphics because these layers can silently reorder the bytes for each pixel (this hurts performance for every pixel). BGRA native data can be copied via memcpy() on the device.