objective-c - 创建像素缓冲区 Objective-C

标签 objective-c xcode macos opengl

我想创建一个 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/

相关文章:

python - 无法在 Mac 上保存带有德语字母的 .py 文件

ios - 支持 iOS 库中的特定设备方向 - 一处更改

objective-c - 如何处理 Int 和 CGFloat 之间的操作?

Android 到 iOS - gradle 与 podfile

xcode - iOS OpenGL 游戏,两个 GLKViews/GLKViewControllers

objective-c - NSOperationQueue 出现非常奇怪的错误

iphone - 将 UINavigationBar 的外观设置重置为默认值

iphone - IOS - cellForRowAtIndexPath 跳过行

ios - Swift:协议(protocol):捕获类型之间的兼容性

macos - 如何在 Mac OS X 上的 Emacs 中编写波浪号 (~) 字符?