View Full Version : How to get the current renderer?

Duncan Champney
03-26-2008, 02:47 PM
My app use an NSOpenGLView for drawing.

I want to query the current renderer associated with my OpenGL view so that I can figure out how much total VRAM it has, and how much is available.

I can get to the CGLContextObj, for my OpenGL view, but then how do I find the current renderer? It looks like you find the rendered by display ID, but how do I get the display ID for my NSOpenGLView? I'm going around and around in circles with the documentation, trying to figure this out.

03-28-2008, 04:42 AM
Check this old sample code (http://developer.apple.com/samplecode/CocoaGL/listing7.html) to see how to get a list of all renderers on a display with CGLQueryRendererInfo. You need to pass in a display mask made with CGDisplayIDToOpenGLDisplayMask.

You can get the CGDisplayID corresponding to an NSView via NSScreen (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSScreen_Class/Reference/Reference.html#//apple_ref/doc/uid/20000333-24488):
[[[[[myview window] screen] deviceDescription] objectForKey:@"NSScreenNumber"] longValue]

Also, take a peek at /System/Library/Frameworks/OpenGL.framework/Headers/CGLTypes.h.
If you have a context, you can get the current renderer by ID like this:
CGLGetParameter(ctx, kCGLCPCurrentRendererID, &theID);

So then match kCGLRPRendererID with CGLQueryRendererInfo(), and look at kCGLRPVideoMemory.

As for "how much is available"... VRAM is virtualized. kCGLRPTextureMemory gives you a value which is roughly (kCGLRPVideoMemory - amount_the_framebuffer_is_using). After that, it's all "available", you're just sharing it will all the other apps running. Just like RAM.