I want to create an NSOpenGLPixelBuffer for offscreen rendering. For now, I'm even unable to init it. Here's 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've tried to fiddle with pixel format and width, height but nothing seems to work. I repeatedly get nil for the pixBuf. I'm using Xcode 9 on MacOS 10.13. It says the NSOpenGLPixelBuffer is deprecated but it should still work, right?
NSOpenGLPixelBuffer
has been deprecated since OS X Lion, which itself dates back to 2011. No wonder you`re getting nil
.
Here, Apple propose a new approach to drawing into textures:
Finally note that the entirety of the NSOpenGLPixelBuffer class should be considered deprecated. Use IOSurface in conjunction with GL framebuffer objects as a replacement.
See this example to get a grasp of how it needs to be.
Might be help following code. you replace GL_TEXTURE_2D to this 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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With