使用OpenGLCompatibility创建CVPixelBufferRef

时间:2012-10-19 14:16:54

标签: objective-c ios ios5 opengl-es

我正在尝试创建一个CVPixelBuffer来在其中分配一个位图并将其绑定到IOS 5下的OpenGL纹理,但我遇到了一些问题。我可以生成像素缓冲区,但IOSurface始终为null,因此我不能将它与CVOpenGLESTextureCacheCreateTextureFromImage一起使用。由于我没有使用相机或视频,而是自生成的位图,我无法使用CVSampleBufferRef从中获取像素缓冲区。

如果你们中的一些人知道如何解决这个问题,我会告诉你我的代码。

CVPixelBufferRef renderTarget = nil;
CFDictionaryRef empty; // empty value for attr value.
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault, // our empty IOSurface properties dictionary
                           NULL,
                           NULL,
                           0,
                           &kCFTypeDictionaryKeyCallBacks,
                           &kCFTypeDictionaryValueCallBacks);
attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                  2,
                                  &kCFTypeDictionaryKeyCallBacks,
                                  &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(attrs,
                     kCVPixelBufferIOSurfacePropertiesKey,
                     empty);
CFDictionarySetValue(attrs, kCVPixelBufferOpenGLCompatibilityKey, [NSNumber numberWithBool:YES]);

CVReturn err = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, tmpSize.width, tmpSize.height, kCVPixelFormatType_32ARGB, imageData, tmpSize.width*4, 0, 0, attrs, &renderTarget);

如果我转储新的PixelBufferRef,我得到:

1 : <CFString 0x3e43024c [0x3f8f8650]>{contents = "OpenGLCompatibility"} = <CFBoolean 0x3f8f8a10 [0x3f8f8650]>{value = true}
2 : <CFString 0x3e43026c [0x3f8f8650]>{contents = "IOSurfaceProperties"} = <CFBasicHash 0xa655750 [0x3f8f8650]>{type = immutable dict, count = 0,
entries =>
}

}

如果我尝试将它与TextureCache一起使用,我得到-6683错误(kCVReturnPixelBufferNotOpenGLCompatible),这样:

CVOpenGLESTextureCacheCreateTextureFromImage (
                                              kCFAllocatorDefault,
                                              self.eagViewController.textureCache,
                                              renderTarget,
                                              nil, // texture attributes
                                              GL_TEXTURE_2D,
                                              GL_RGBA, // opengl format
                                              tmpSize.width,
                                              tmpSize.height,
                                              GL_BGRA, // native iOS format 
                                              GL_UNSIGNED_BYTE,
                                              0,
                                              &renderTextureTemp);

0 个答案:

没有答案