|
Q: How do I select a hardware accelerated renderer and prevent it from falling into the software renderer?A: The Mac OS X implementation of OpenGL allows an application to gracefully switch to a software renderer as a failure recovery system when the hardware resources are not sufficient for a given operation. While most applications will benefit from this recovery there are certain applications that might want to disable this feature. Performance driven applications, like games, need to stay in hardware accelerated renderers to achieve and maintain an acceptable frame rate. A simple way to select a hardware accelerated renderer without the choice of software fallback is by selecting the following pixel format attributes: For CGL:
For AGL:
For NSOpenGL:
Note: Disabling the software renderer fallback will result in no rendering until the state that caused the fallback changes to a state the hardware can render. Using the * Listing 1: Creating a Pixel Format Object with Accelerated and NoRecovery attributes. - initWithFrame:(NSRect)frameRect { NSOpenGLPixelFormatAttribute attrs[] = { NSOpenGLPFANoRecovery, NSOpenGLPFAColorSize, 24, NSOpenGLPFADepthSize, 16, NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated, 0 }; long rendererID; NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; // Report the renderer ID that this pixel format binds to // CGLRenderers.h contains a list of known renderers and their corresponding RendererID codes. // Also at http://developer.apple.com/documentation/GraphicsImaging/Reference/CGL_OpenGL/ [pixelFormat getValues:&rendererID forAttribute:NSOpenGLPFARendererID forVirtualScreen:0]; NSLog(@"NSOpenGLView pixelFormat RendererID = %08x", (unsigned)rendererID); self = [super initWithFrame:frameRect pixelFormat:pixelFormat]; return self; } The Techniques for Choosing Attributes section of the OpenGL Programming Guide for Mac OS X provides additional information on this subject. Determining if your current drawing state will execute in the GPUCGL provides two parameters for checking whether the system is using the GPU for processing: IMPORTANT: Although you can perform these queries at any time, keep in mind that such queries force an internal state validation, which can impact performance. For best performance, do not use these queries inside your drawing loop. Listing 2: Using CGL to check whether the GPU is processing vertices and fragments. BOOL gpuProcessing; GLint fragmentGPUProcessing, vertexGPUProcessing; CGLGetParameter (CGLGetCurrentContext(), kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); CGLGetParameter(CGLGetCurrentContext(), kCGLCPGPUVertexProcessing, &vertexGPUProcessing); gpuProcessing = (fragmentGPUProcessing && vertexGPUProcessing) ? YES : NO; The above listing will set Note: Some hardware, like the Intel GMA 950, does not have built-in vertex processing. These renderers will always return Document Revision History
Posted: 2007-07-18 |
|