Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

General Approach

The general approach to setting up full scene anti-aliasing is as follows:

  1. Check to see what's supported. Not all hardware is capable of supporting the ARB multisample extension, so you need to check for this functionality (see “Detecting Functionality”).

    To find out what type of anti-aliasing a specific renderer supports, call the function CGLDescribeRenderer. Supply the renderer property kCGLRPSampleModes to find out whether the renderer supports multisampling and supersampling. Supply kCGLRPSampleAlpha to see whether the renderer supports alpha sampling.

    You can choose to exclude unsupported hardware from the pixel format search by specifying only the hardware that supports multisample anti-aliasing. Keep in mind that if you exclude unsupported hardware, the unsupported displays will not render anything. If you instead choose to include unsupported hardware, OpenGL uses normal aliased rendering to the unsupported displays and multisampled rendering to supported displays.

  2. Include these buffer attributes in the attributes array:

    • The appropriate sample buffer attribute constant (NSOpenGLPFASampleBuffers, AGL_SAMPLE_BUFFERS_ARB, or kCGLPFASampleBuffers) along with the number of multisample buffers. At this time the specification allows only one multisample buffer.

    • The appropriate samples constant (,NSOpenGLPFASamples, AGL_SAMPLES_ARB, or kCGLPFASamples) along with the number of samples per pixel. You can supply 2, 4, 6, or more depending on what the renderer supports and the amount of VRAM available. The value that you supply affects the quality, memory use, and speed of the multisampling operation. For fastest performance, and to use the least amount of video memory, specify 2 samples. When you need more quality, specify 4 or more.

    • The no recovery attribute ( NSOpenGLPFANoRecovery, AGL_NO_RECOVERY, or kCGLPFANoRecovery). Although enabling this attribute is not mandatory, it's recommended to prevent OpenGL from using software fallback as a renderer. The software renderer does not support multisample antialiasing prior to Mac OS X v10.4. In versions that the software renderer does support multisampling (4, 9, or 16 samples), antialiasing performance is slow.

  3. Optionally provide a hint for the type of anti-aliasing you want—multisampling, supersampling, or alpha sampling. See “Hinting for a Specific Anti-Aliasing Technique.”

  4. Enable multisampling with the following command:

    glEnable(GL_MULTISAMPLE);

    Regardless of the enabled state, OpenGL always uses the multisample buffer if you supply the appropriate buffer attributes when you set up the pixel format object. If you haven't supplied the appropriate attributes, enabling multisampling has no effect.

    When multisampling is disabled, all coverage values are set to 1, which gives the appearance of rendering without multisampling.

    Some graphics hardware leaves multisampling enabled all the time. However, don't rely on hardware to have multisampling enabled; use glEnable to programmatically turn on this feature.

  5. Optionally provide hints for the rendering algorithm. You perform this optional step only if you want OpenGL to compute coverage values by a method other than uniformly weighting samples and averaging them.

    Some hardware supports a multisample filter hint through an OpenGL extension—GL_NV_multisample_filter_hint. This hint allows an OpenGL implementation to use an alternative method of resolving the color of multisampled pixels.

    You can specify that OpenGL uses faster or nicer rendering by calling the OpenGL function glHint, passing the constant GL_MULTISAMPLE_FILTER_HINT_NV as the target parameter and GL_FASTEST or GL_NICEST as the mode parameter. Hints allow the hardware to optimize the output if it can. There is no performance penalty or returned error for issuing a hint that's not supported.

    For more information, see the OpenGL extension registry for NV_multisample_filter_hint.

“Setting Up Full Scene Anti-Aliasing” provides specific code examples.



< Previous PageNext Page > Hide TOC


Last updated: 2008-06-09




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice