本文介绍了在iOS中创建RGB CVOpenGLESTexture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iOS中创建 3通道 CVOpenGLESTexture.

通过为CVOpenGLESTextureCacheCreateTextureFromImage()中的formatinternalFormat分别在CVPixelBufferCreate()GL_LUMINANCE中指定kCVPixelFormatType_OneComponent8,可以成功创建单通道纹理.

类似地,通过为CVOpenGLESTextureCacheCreateTextureFromImage()中的formatinternalFormat分别在CVPixelBufferCreate()GL_RGBA中指​​定kCVPixelFormatType_32BGRA,可以成功创建 4通道 RGBA纹理. /p>

我需要创建具有可访问像素的 3通道,24位,RGB(或BGR)纹理.
我似乎找不到正确的参数(或其组合)到CVPixelBufferCreate()CVOpenGLESTextureCacheCreateTextureFromImage(),不会导致它们中的任何一个失败.

其他信息
我的设备上CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes()所支持的FOURCC格式类型已报告 :
32 24 16L5655551L5552vuy2vufyuvsyuvf40 L008 L0102C08r408v408y408y416 BGRA b64ab48rb32ab16gR10kv308v216v210v410r4flgrb4rgg4bgg4gbr4420v420f411v411f422v422f444v444fy420f420a2vyL00hL00f2C0h2C0fRGhARGfAw30rw40aw40mx420x422x444x44pxf20xf22xf44xf4px22pxf2pb3a8.

有趣的是,其中一些值未在CVPixelBuffer.h中定义.

当我将kCVPixelFormatType_24RGB(24 == 0x18)传递给CVPixelBufferCreate()时,它会成功,但随后CVOpenGLESTextureCacheCreateTextureFromImage()会失败,并显示错误代码-6683 :kCVReturnPixelBufferNotOpenGLCompatible.

解决方案

尽管我很乐意被证明是错误的,并向我展示了如何做到这一点,但我还是很高兴.

我在此处(再次回答自己),可以列出设备上支持的所有fourCC缓冲区格式,以及与每个此类fourCC格式关联的一堆格式属性.

与此问题相关的标志是:

  • kCVPixelFormatOpenGLESCompatibility
  • kCVPixelFormatContainsAlpha:应为false;否则为false.
  • kCVPixelFormatContainsRGB:注意:仅受__IPHONE_8_0支持,但并非严格必要;
  • 使用调试器,我发现了另一个有用的键:CFSTR("IOSurfaceOpenGLESTextureCompatibility"),它将验证OpenGL ES纹理支持直接像素访问,而无需(较慢的)glReadPixels()glTexImage2D().

不幸的是,使用这些标志,似乎目前没有这样的RGB/BGR支持的格式.

I am trying to create a 3-channel CVOpenGLESTexture in iOS.

I can successfully create a single-channel texture by specifying kCVPixelFormatType_OneComponent8 in CVPixelBufferCreate() and GL_LUMINANCE for both format and internalFormat in CVOpenGLESTextureCacheCreateTextureFromImage().

Similarly, I can successfully create a 4-channel RGBA texture by specifying kCVPixelFormatType_32BGRA in CVPixelBufferCreate() and GL_RGBA for both format and internalFormat in CVOpenGLESTextureCacheCreateTextureFromImage().

I need to create 3-channel, 24-bit, RGB (or BGR) texture with accessible pixels.
I cannot seem to find the correct parameters (or combination thereof) to CVPixelBufferCreate() and CVOpenGLESTextureCacheCreateTextureFromImage() that will not cause either of them to fail.

Additional Info
The supported FOURCC format types reported by CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes() on my device:
32, 24, 16, L565, 5551, L555, 2vuy, 2vuf, yuvs, yuvf, 40, L008, L010, 2C08, r408, v408, y408, y416, BGRA, b64a, b48r, b32a, b16g, R10k, v308, v216, v210, v410, r4fl, grb4, rgg4, bgg4, gbr4, 420v, 420f, 411v, 411f, 422v, 422f, 444v, 444f, y420, f420, a2vy, L00h, L00f, 2C0h, 2C0f, RGhA, RGfA, w30r, w40a, w40m, x420, x422, x444, x44p, xf20, xf22, xf44, xf4p, x22p, xf2p, b3a8.

Interestingly, some of these values are not defined in CVPixelBuffer.h.

When I pass kCVPixelFormatType_24RGB (24 == 0x18) to CVPixelBufferCreate() it succeeds, but then CVOpenGLESTextureCacheCreateTextureFromImage() fails with error code -6683:kCVReturnPixelBufferNotOpenGLCompatible.

解决方案

Answering myself, though I will be happy to be proved wrong and shown how to do this.

As I show here (answering myself yet again) it is possible to list all the fourCC buffer formats supported on the device, and a bunch of format attributes associated with each such fourCC format.

The flags pertinent to this question are:

  • kCVPixelFormatOpenGLESCompatibility
  • kCVPixelFormatContainsAlpha : Should be false;
  • kCVPixelFormatContainsRGB : Note: supported only from __IPHONE_8_0, but not strictly necessary;
  • Using the debugger, I found another helpful key: CFSTR("IOSurfaceOpenGLESTextureCompatibility") which will verify that the OpenGL ES texture supports direct pixel access with no need for (the slower) glReadPixels() and glTexImage2D().

Unfortunately, using these flags, it seems that there is currently no such RGB/BGR supported format.

这篇关于在iOS中创建RGB CVOpenGLESTexture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:41