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);