I am working on an app that uses 2D textures to create animated kaleidoscopes. It starts out displaying to an NSOpenGLView. I am adding an option to switch to full-screen mode.
I would prefer to use the OS 10.5 approach to full screen so I can support 10.5, but I think I would face the same issue if I was using the approach described in the docs under "Creating a Full-Screen Application in Mac OS X v10.6".
The NSOpenGLContext init method initWithFormat:shareContext: takes an optional pointer to "Another OpenGL graphics context whose texture namespace and display lists you want to share with the receiver".
The code I'm using to create the full screen OpenGL context is straightforward:
NSOpenGLPixelFormatAttribute myAttributes[] = // Pixel Format Attributes for the FullScreen NSOpenGLContext
{
NSOpenGLPFAFullScreen, // specify full-screen OpenGL context
NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), // specify main display
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute) 32,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute) 0,
NSOpenGLPFAStencilSize, 0,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
0
};
NSOpenGLPixelFormat *myPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:myAttributes]; // Create FullScreen NSOpenGLContext with these attributes
NSOpenGLContext *fullScreenContext = [[NSOpenGLContext alloc] initWithFormat:myPixelFormat shareContext: myContext]; // Create an NSOpenGLContext with the FullScreen pixel format.
However, it doesn't seem to work.
My app only uses one texture, so I started out not using glGenTextures and glBindTexture. Instead I just used the single current texture for the context.
I tried changing my code to create a named texture with glGenTextures, in the hopes that I could bind the named texture after switching to the full-screen context, but no dice. Both approaches give the same result - the texture does not work in the full screen context.
I don't get any errors, but drawing with a texture doesn't do anything.
I am forced to recreate my texture each time I switch to full-screen mode. This is bad because the textures are potentially very large (depending on how big an image the user loads, up to the max texture size.) That forces me to load two copies of a very large object into VRAM. Worse, I have to do byte-swizzling in some cases to get the byte order correct. That takes several seconds on a large texture, which makes for a "pregnant pause" when entering full-screen mode.
Is there some trick I'm missing to sharing textures between an NSOpenGLView and a full screen OpenGL context?