创建像素缓冲区Objective-C

alD*_*blo 6 opengl macos xcode objective-c

我想为屏幕外渲染创建一个NSOpenGLPixelBuffer.现在,我甚至无法初始化它.这是代码:

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);
Run Code Online (Sandbox Code Playgroud)

我试图摆弄像素格式和宽度,高度,但似乎没有任何作用.我一再为pixBuf得到零.我在MacOS 10.13上使用Xcode 9.它说NSOpenGLPixelBuffer已被弃用,但它应该仍然有效,对吗?

hid*_*kgb 5

NSOpenGLPixelBuffer自OS X Lion以来一直被弃用,它本身可以追溯到2011年.难怪你得到了nil.

在这里,Apple提出了一种绘制纹理的新方法:

最后请注意,应该将NSOpenGLPixelBuffer类的全部内容视为已弃用.将IOSurfaceGL framebuffer对象结合使用作为替换.

请参阅此示例以了解它是如何需要的.