How to List all OpenGL ES Compatible PixelBuffer Formats

天涯浪子 提交于 2019-12-11 16:16:52

问题


Is there a way to list all CVPixelBuffer formats for CVPixelBufferCreate() that will not generate error -6683: kCVReturnPixelBufferNotOpenGLCompatible when used with CVOpenGLESTextureCacheCreateTextureFromImage()?

This lists all the supported CVPixelBuffer formats for CVPixelBufferCreate(), but does not guarantee that CVOpenGLESTextureCacheCreateTextureFromImage() will not return the error above. I guess my desired list should be a subset of this one.


回答1:


Based on the answer from Adi Shavit above, here's a full code snippet (Objective-C) that you can use to print all the current OpenGL ES compatible pixel formats:

+ (void)load {
  @autoreleasepool {
    printf("Core Video Supported Pixel Format Types:\n");

    CFArrayRef pixelFormatDescriptionsArray = CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes(kCFAllocatorDefault);
    for (CFIndex i = 0; i < CFArrayGetCount(pixelFormatDescriptionsArray); i++) {
      CFNumberRef pixelFormatFourCC = (CFNumberRef)CFArrayGetValueAtIndex(pixelFormatDescriptionsArray, i);

      if (pixelFormatFourCC != NULL) {
        UInt32 value;

        CFNumberGetValue(pixelFormatFourCC, kCFNumberSInt32Type, &value);

        NSString * pixelFormat;
        if (value <= 0x28) {
          pixelFormat = [NSString stringWithFormat:@"Core Video Pixel Format Type 0x%02x", (unsigned int)value];
        } else {
          pixelFormat = [NSString stringWithFormat:@"Core Video Pixel Format Type (FourCC) %c%c%c%c", (char)(value >> 24), (char)(value >> 16), (char)(value >> 8), (char)value];
        }

        CFDictionaryRef desc =  CVPixelFormatDescriptionCreateWithPixelFormatType(kCFAllocatorDefault, (OSType)value);
        CFBooleanRef OpenGLESCompatibility = (CFBooleanRef)CFDictionaryGetValue(desc, kCVPixelFormatOpenGLESCompatibility);
        printf("%s: Compatible with OpenGL ES: %s\n", pixelFormat.UTF8String, (OpenGLESCompatibility != nil && CFBooleanGetValue(OpenGLESCompatibility)) ? "YES" : "NO");
      }
    }

    printf("End Core Video Supported Pixel Format Types.\n");
  }
}

You can put this snippet anywhere in a Objective-C category or class to print which pixel format are compatible and which aren't. For completeness purposes, here are all the pixel formats currently compatible with OpenGL ES as of iOS 10.2.1:

  • L565
  • 5551
  • L555
  • 2vuy
  • yuvs
  • yuvf
  • L008
  • L016
  • 2C08
  • 2C16
  • BGRA
  • 420v
  • 420f
  • 420e
  • 411v
  • 411f
  • 422v
  • 422f
  • 444v
  • 444f
  • L00h
  • L00f
  • 2C0h
  • 2C0f
  • RGhA
  • RGfA



回答2:


Answering myself... after further study of this link.
The function CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes() provides all the supported formats on a particular device (and OS). Once the fourCC value is found as shown in the link, you can use CVPixelFormatDescriptionCreateWithPixelFormatType() to get a dictionary with various fields describing each format.

This looks something like this:

UInt32 value;
CFNumberGetValue(pixelFormatFourCC, kCFNumberSInt32Type, &value);
auto desc =  CVPixelFormatDescriptionCreateWithPixelFormatType(kCFAllocatorDefault, (OSType)value);
auto OpenGLCompatibility = (CFBooleanRef)CFDictionaryGetValue(desc, kCVPixelFormatOpenGLCompatibility);
auto OpenGLESCompatibility = (CFBooleanRef)CFDictionaryGetValue(desc, kCVPixelFormatOpenGLESCompatibility);

If OpenGLESCompatibility is true then this format is OpenGL ES compatible.



来源:https://stackoverflow.com/questions/27149380/how-to-list-all-opengl-es-compatible-pixelbuffer-formats

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!