2011-11-19 45 views
0

我需要创建类型GL_TEXTURE_RECTANGLE_EXT的OpenGL的质感,让我可以使用如何将CVImageBufferRef转换为一个OpenGL纹理

outputImageProviderFromTextureWithPixelFormat:pixelsWide:pixelsHigh:name:flipped:releaseCallback:releaseContext:colorSpace:shouldColorMatch 

,但我无法弄清楚如何我CVImageBufferRef转换为OpenGL纹理。我相信我只是没有找到正确的东西。我如何将CVImageBufferRef转换为OpenGL纹理?

当我尝试:

CVImageBufferRef imageBuffer = CVBufferRetain(mCurrentImageBuffer); 

    GLuint     texture = CVOpenGLTextureGetName(imageBuffer); 


    id provider= [context outputImageProviderFromTextureWithPixelFormat:QCPlugInPixelFormatARGB8 
                  pixelsWide:CVPixelBufferGetWidth(imageBuffer) 
                  pixelsHigh:CVPixelBufferGetHeight(imageBuffer) 
                    name:texture 
                   flipped:NO 
                 releaseCallback:_TextureReleaseCallback 
                 releaseContext:NULL 
                  colorSpace:CVImageBufferGetColorSpace(imageBuffer) 
                 shouldColorMatch:YES]; 

它告诉我, '名称' 不能为空。我认为这是因为我的imageBuffer是一个像素缓冲区,而不是OpenGL纹理。我怎样才能从我的像素缓冲区创建一个OpenGL纹理?

回答

0

CoreVideo框架中可能存在一些特殊的快速路径,但您始终可以获取原始支持数据并将其提供给glTexImage2D。这里有一个answered question,它涵盖了获取原始数据。

编辑:

挖多一点,看来你也许可以简单地通过使用CVOpenGLTextureGetTargetCVOpenGLTextureGetName使用已经与CVImageBufferRef相关的OpenGL纹理。这些操作在CVOpenGLTextureRef类型,这是typedef'd CVImageBufferRef

+0

我试过使用CVOpenGLTextureGetName(imageBuffer),它似乎返回null。我得到了'2011-11-20 12:23:52.607 Quartz Composer [18612:407] *** EXCEPTION IGNORED: - [CaptureWithDevice outputImageProviderFromTextureWithPixelFormat:pixelsWide:pixelsHigh:name:flipped:releaseCallback:releaseContext:colorSpace:sh​​ouldColorMatch:]:Argument当我运行它时,“name”不能为空' – Adam

+0

在阅读你提到的另一个线程之后,我认为它返回null的原因是因为我的imageBuffer不是OpenGL缓冲区。所以,我仍然需要从像素缓冲区转换一个开放的GL纹理。 – Adam

+0

啊,我明白了。那么你可以尝试原始数据路线。不幸的是,我没有做很多CoreVideo的工作。 – James