我想创建一个 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);
我试图摆弄像素格式和宽度、高度,但似乎没有任何效果。对于 pixBuf,我反复得到 nil。我在 MacOS 10.13 上使用 Xcode 9。它说 NSOpenGLPixelBuffer 已被弃用,但它应该仍然有效,对吧?
最佳答案
NSOpenGLPixelBuffer
已为 deprecated since OS X Lion ,它本身dates back to 2011 .难怪你会得到 nil
。
Here , Apple 提出了一种绘制纹理的新方法:
Finally note that the entirety of the NSOpenGLPixelBuffer class should be considered deprecated. Use IOSurface in conjunction with GL framebuffer objects as a replacement.
参见 this example了解它需要如何。
关于objective-c - 创建像素缓冲区 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47118628/