equivalent formats across CoreVideo, Metal, and OpenGL

Following the document and demo

mixing_metal_and_opengl_rendering_in_a_view

section "Select a Compatible Pixel Format" only show MTLPixelFormatBGRA8Unorm as followed.

if I want to use MTLPixelFormatRGBA8Unorm, how can I find the cvpixelformat and gl format which match MTLPixelFormatRGBA8Unorm??

Thanks in advance.

// Table of equivalent formats across CoreVideo, Metal, and OpenGL
static const AAPLTextureFormatInfo AAPLInteropFormatTable[] =
{
  // Core Video Pixel Format,        Metal Pixel Format,      GL internalformat, GL format,  GL type
  { kCVPixelFormatType_32BGRA,       MTLPixelFormatBGRA8Unorm,   GL_RGBA,      GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV },
#if TARGET_IOS
  { kCVPixelFormatType_32BGRA,       MTLPixelFormatBGRA8Unorm_sRGB, GL_RGBA,      GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV },
#else
  { kCVPixelFormatType_ARGB2101010LEPacked, MTLPixelFormatBGR10A2Unorm,  GL_RGB10_A2,    GL_BGRA,   GL_UNSIGNED_INT_2_10_10_10_REV },
  { kCVPixelFormatType_32BGRA,       MTLPixelFormatBGRA8Unorm_sRGB, GL_SRGB8_ALPHA8,  GL_BGRA,   GL_UNSIGNED_INT_8_8_8_8_REV },
  { kCVPixelFormatType_64RGBAHalf,     MTLPixelFormatRGBA16Float,   GL_RGBA,      GL_RGBA,   GL_HALF_FLOAT },
#endif
};

 // Core Video Pixel Format,        Metal Pixel Format,      GL internalformat, GL format,  GL type   { kCVPixelFormatType_32RGBA,       MTLPixelFormatRGBA8Unorm,   GL_RGBA,      GL_RGBA, GL_UNSIGNED_BYTE },

is it OK ??

CVPixelBufferCreate with. kCVPixelFormatType_32RGBA will fail on IOS 14.2 iphone XR

Core Video Pixel Format,        Metal Pixel Format,       GL internalformat, GL format,  GL type   kCVPixelFormatType_32BGRA. MTLPixelFormat'RGBA'8Unorm. GL_RGBA. GL_RGBA. GL_UNSIGNED_BYTE

it's ok ?? Just CVPixelFormat is BGRA

Looking at the table in your example, first row seems to be the only option for MTLPixelFormatBGRA8Unorm.

So equivalent Core Video Pixel Format would be: kCVPixelFormatType_32BGRA.

I'll have to handle similar issue in the next few days. I'll let you know how it turn out. Also please let me know how it worked out for you.

Is there a specific format you would like to find a mapping for. There is no document describing this and some formats can be expressed in each API but there is no 1:1 mapping. For instance, compressed or YCbCr formats usually need additional properties. There are also some properties of some formats, such as colorspace and chroma subsampling, that apply in one API which can only be partially expressed in other APIs.

equivalent formats across CoreVideo, Metal, and OpenGL
 
 
Q