Mac Developer Library

Developer

AppKit Framework Reference NSOpenGLView Class Reference

Options
Deployment Target:

On This Page
Language:

NSOpenGLView

An NSOpenGLView object maintains an NSOpenGLPixelFormat and NSOpenGLContext object into which OpenGL calls can be rendered. The view provides methods for accessing and managing the NSOpenGLPixelFormat and NSOpenGLContext objects, as well as notifications of visible region changes.

An NSOpenGLView object cannot have subviews. You can, however, divide a single NSOpenGLView into multiple rendering areas using the glViewport function.

When creating an NSOpenGLView object in Interface Builder, you use the inspector window to specify the pixel format attributes you want for the view. Only those attributes listed in the Interface Builder inspector are set when the view is instantiated.

  • Returns an NSOpenGLView object initialized with the specified frame rectangle and pixel format.

    Declaration

    Swift

    init?(frame frameRect: NSRect, pixelFormat format: NSOpenGLPixelFormat?)

    Objective-C

    - (instancetype)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format

    Parameters

    frameRect

    The frame rectangle for the view, specified in the coordinate system of its parent view.

    format

    The pixel format to use when creating the view's NSOpenGLContext object.

    Return Value

    An initialized NSOpenGLView object, or nil if the object could not be initialized.

    Availability

    Available in OS X v10.0 and later.

  • Used by subclasses to initialize OpenGL state.

    Declaration

    Swift

    func prepareOpenGL()

    Objective-C

    - (void)prepareOpenGL

    Discussion

    This method is called only once after the OpenGL context is made the current context. Subclasses that implement this method can use it to configure the Open GL state in preparation for drawing.

    Availability

    Available in OS X v10.3 and later.

  • Releases the NSOpenGLContext object associated with the view.

    Declaration

    Swift

    func clearGLContext()

    Objective-C

    - (void)clearGLContext

    Discussion

    If necessary, this method calls the clearDrawable method of the context object before releasing it.

    Availability

    Available in OS X v10.0 and later.

    See Also

    openGLContext

  • The NSOpenGLContext object associated with the receiver.

    Declaration

    Swift

    var openGLContext: NSOpenGLContext?

    Objective-C

    @property(strong) NSOpenGLContext *openGLContext

    Discussion

    If the receiver has no associated context object, a new NSOpenGLContext object is created. The new object is initialized with the receiver’s pixel format information.

    Availability

    Available in OS X v10.0 and later.

  • Called by Cocoa when the view's visible rectangle or bounds change.

    Declaration

    Swift

    func reshape()

    Objective-C

    - (void)reshape

    Discussion

    Cocoa typically calls this method during scrolling and resize operations but may call it in other situations when the view's rectangles change. The default implementation does nothing. You can override this method if you need to adjust the viewport and display frustum.

    Availability

    Available in OS X v10.0 and later.

  • Called by Cocoa when the view’s window moves or when the view itself moves or is resized.

    Declaration

    Swift

    func update()

    Objective-C

    - (void)update

    Discussion

    The default implementation simply calls the update method of NSOpenGLContext. You can override this method to perform additional update operations on the context or if you need to add locks for multithreaded access to multiple contexts.

    Availability

    Available in OS X v10.0 and later.

  • Enables extended dynamic range values on the screen.

    Declaration

    Objective-C

    @property BOOL wantsExtendedDynamicRangeOpenGLSurface;

    Discussion

    If any view on the screen has this enabled, the screen which the OpenGL surface is on may have its maximumExtendedDynamicRangeColorComponentValue value increased. When composited by the Window Server, color values rendered by this OpenGL surface will be clamped to the screen’s maximumExtendedDynamicRangeColorComponentValue value rather than 1.0.