Creating an Objective-C Pixel Buffer

I want to create an NSOpenGLPixelBuffer for off-screen rendering. At the moment, I can’t even initialize it. Here is the code:

NSOpenGLPixelFormatAttribute attribs[] = {
    NSOpenGLPFAPixelBuffer,
    NSOpenGLPFANoRecovery,
    NSOpenGLPFAAccelerated,
    NSOpenGLPFADepthSize, 24,
    (NSOpenGLPixelFormatAttribute) 0
};

NSOpenGLPixelFormat* format = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs] autorelease];
NSOpenGLPixelBuffer* pixBuf = [[NSOpenGLPixelBuffer alloc]
                               initWithTextureTarget: GL_TEXTURE_2D
                               textureInternalFormat: GL_RGBA
                               textureMaxMipMapLevel: 0
                               pixelsWide: 32
                               pixelsHigh: 32];

NSLog(@"pbuf address: %p", pixBuf);

I tried to mess with the pixel format and width, height, but nothing works. I repeatedly get nil for pixBuf. I am using Xcode 9 on macOS 10.13. He says NSOpenGLPixelBuffer is deprecated, but it should still work, right?

+6
source share
2 answers

NSOpenGLPixelBufferwas deprecated with OS X Lion , which itself dates back to 2011 . No wonder what you get nil.

, Apple :

, , NSOpenGLPixelBuffer . IOSurface GL- .

, , .

+5

, . GL_TEXTURE_2D GL_TEXTURE_RECTANGLE_EXT.

// Create an OpenGL pixel buffer
pixBuf = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_RECTANGLE_EXT textureInternalFormat:GL_RGBA textureMaxMipMapLevel:0 pixelsWide:32 pixelsHigh:32];
NULL_ERROR_EXIT(pixBuf, "Unable to create NSOpenGLPixelBuffer");
+2

All Articles