CVOpenGLESTexture方法类型的官方文档在哪里?

Poc*_*chi 8 xcode opengl-es ios ios5

我试过谷歌和stackoverflow但我似乎无法找到以CVOpenGLESTexture开头的函数的官方文档.我可以看到它们来自核心视频,我知道它们是在iOS 5上添加的,但搜索文档并没有给我任何东西.

我正在寻找有关参数的信息,他们做什么,如何使用它们等,就像在其他苹果框架中一样.

到目前为止我所能做的就是命令点击它来查看信息,但这感觉非常奇怪.或者有没有办法添加它,以便它可以显示在xcode右侧的快速帮助?

如果这是一个愚蠢的问题,谢谢,对不起.

PD:核心视频参考指南似乎也没有解释这些.

Bra*_*son 16

不幸的是,这些新功能确实没有任何文档.您现在要找到的最好的是在CVOpenGLESTextureCache.h头文件中,您将看到函数参数的基本描述:

/*!
    @function   CVOpenGLESTextureCacheCreate
    @abstract   Creates a new Texture Cache.
    @param      allocator The CFAllocatorRef to use for allocating the cache.  May be NULL.
    @param      cacheAttributes A CFDictionaryRef containing the attributes of the cache itself.   May be NULL.
    @param      eaglContext The OpenGLES 2.0 context into which the texture objects will be created.  OpenGLES 1.x contexts are not supported.
    @param      textureAttributes A CFDictionaryRef containing the attributes to be used for creating the CVOpenGLESTexture objects.  May be NULL.
    @param      cacheOut   The newly created texture cache will be placed here
    @result     Returns kCVReturnSuccess on success
*/
CV_EXPORT CVReturn CVOpenGLESTextureCacheCreate(
                    CFAllocatorRef allocator,
                    CFDictionaryRef cacheAttributes,
                    void *eaglContext,
                    CFDictionaryRef textureAttributes,
                    CVOpenGLESTextureCacheRef *cacheOut) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
Run Code Online (Sandbox Code Playgroud)

更难的元素是属性字典,遗憾的是,您需要找到示例才能正确使用这些函数.Apple有GLCameraRippleRosyWriter示例,展示了如何使用BGRA和YUV输入颜色格式的快速纹理上传路径.Apple还在WWDC上提供了ChromaKey示例(可能仍然可以与视频一起访问),演示了如何使用这些纹理缓存从OpenGL ES纹理中提取信息.

我刚刚在我的GPUImage框架中使用了这种快速纹理上传(源代码可以在该链接中获得),所以我将列出我能够解析的内容.首先,我使用以下代码创建纹理缓存:

CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)[[GPUImageOpenGLESContext sharedImageProcessingOpenGLESContext] context], NULL, &coreVideoTextureCache);
if (err) 
{
    NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate %d");
}
Run Code Online (Sandbox Code Playgroud)

所引用的上下文是为OpenGL ES 2.0配置的EAGLContext.

我使用它来保存视频内存中iOS设备相机的视频帧,我使用以下代码执行此操作:

CVPixelBufferLockBaseAddress(cameraFrame, 0);

CVOpenGLESTextureRef texture = NULL;
CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, coreVideoTextureCache, cameraFrame, NULL, GL_TEXTURE_2D, GL_RGBA, bufferWidth, bufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0, &texture);

if (!texture || err) {
    NSLog(@"CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err);  
    return;
}

outputTexture = CVOpenGLESTextureGetName(texture);
glBindTexture(GL_TEXTURE_2D, outputTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Do processing work on the texture data here

CVPixelBufferUnlockBaseAddress(cameraFrame, 0);

CVOpenGLESTextureCacheFlush(coreVideoTextureCache, 0);
CFRelease(texture);
outputTexture = 0;
Run Code Online (Sandbox Code Playgroud)

这将从纹理缓存创建一个新的CVOpenGLESTextureRef,表示OpenGL ES纹理.此纹理基于相机传入的CVImageBufferRef.然后从CVOpenGLESTextureRef中检索该纹理并为其设置适当的参数(这在我的处理中似乎是必要的).最后,当我完成时,我会对纹理进行处理并进行清理.

这种快速上传过程对iOS设备产生了真正的影响.在iPhone 4S上上传和处理单个640x480视频帧的时间从9.0毫秒到1.8毫秒.

听说这也是相反的,这可能允许glReadPixels()在某些情况下更换,但我还没试过.