Been pulling my hair out trying to figure out the current best path from AVFoundation videos to an openGLTexture, most of what I find is related to iOS, and I can\'t seem to mak
I'm starting on the same journey and know as much about OpenGL as I do about sheep farming, but did notice that your pbOptions doesn't contain kCVPixelBufferOpenGLCompatibilityKey
NSDictionary *pbOptions = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_422YpCbCr8], kCVPixelBufferPixelFormatTypeKey,
[NSDictionary dictionary], kCVPixelBufferIOSurfacePropertiesKey,
[NSNumber numberWithBool:YES], kCVPixelBufferOpenGLCompatibilityKey, nil];
I'm requesting the pixel buffer as kCVPixelFormatType_32BGRA rather than component and this works for me with local variables for _currentSurface (IOSurfaceRef), textureName (GLuint), _sourceWidth (int) and _sourceHeight (int)
IOSurfaceRef newSurface = CVPixelBufferGetIOSurface(pixelBuffer);
if (_currentSurface != newSurface) {
CGLContextObj cgl_ctx = (CGLContextObj)[[self openGLContext] CGLContextObj];
[[self openGLContext] makeCurrentContext];
IOSurfaceDecrementUseCount(_currentSurface);
_currentSurface = newSurface;
IOSurfaceIncrementUseCount(_currentSurface);
GLsizei texWidth = (int) IOSurfaceGetWidth(_currentSurface);
GLsizei texHeight = (int) IOSurfaceGetHeight(_currentSurface);
if (_sourceWidth == 0 && _sourceHeight == 0) {
// used during drawing of texture
_sourceWidth = texWidth;
_sourceHeight = texHeight;
}
if (!_textureName) {
GLuint name;
glGenTextures(1, &name);
_textureName = name;
}
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _textureName);
CGLTexImageIOSurface2D(cgl_ctx, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA, texWidth, texHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, self.currentSurface, 0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
}