NSOpenGLLayer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.6 and later.
Companion guide
Declared in
NSOpenGLLayer.h

Overview

NSOpenGLLayer is a subclass of CAOpenGLLayer that is suitable for rendering OpenGL into layers. Unlike CAOpenGLLayer, NSOpenGLLayer uses distinctly Application Kit types.

Tasks

Drawing the Content

Managing the Pixel Format

Managing the Rendering Context

Accessing the Associated View

Properties

openGLContext

The layer’s NSOpenGLContext.

@property(retain) NSOpenGLContext *openGLContext
Discussion

Provides access to the layer's associated NSOpenGLContext. Subclasses shouldn't invoke setOpenGLContext:, but can override it if desired to intercept assignment of the layer's context.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h

openGLPixelFormat

Provides access to the layer's associated NSOpenGLPixelFormat.

@property(retain) NSOpenGLPixelFormat *openGLPixelFormat
Discussion

Subclasses shouldn't invoke setOpenGLPixelFormat:, but can override it if desired to intercept assignment of the layer's pixel format.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h

view

Returns the view associated with the layer.

@property(assign) NSView *view
Discussion

Subclasses shouldn't invoke setView:, but can override it if desired to intercept the layer's association to, or dissociation from, a view.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h

Instance Methods

canDrawInOpenGLContext:pixelFormat:forLayerTime:displayTime:

Invoked to ask the layer whether it can (or should) draw.

- (BOOL)canDrawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
Parameters
context

The NSOpenGLContext in to which the OpenGL content would be drawn.

pixelFormat

The pixel format used when the context was created.

timeInterval

The current layer time.

timeStamp

The display timestamp associated with timeInterval. Can be null.

Return Value

YES if the receiver should render OpenGL content, NO otherwise.

Discussion

This method is called before attempting to render the frame for the layer time specified by timeInterval. If the method returns NO, the frame is skipped. The default implementation always returns YES.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h

drawInOpenGLContext:pixelFormat:forLayerTime:displayTime:

Draws the OpenGL content for the specified time.

- (void)drawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
Parameters
context

The NSOpenGLContext in to which the OpenGL content would be drawn.

pixelFormat

The pixel format used when the context was created.

timeInterval

The current layer time.

timeStamp

The display timestamp associated with timeInterval. Can be null.

Discussion

This method is called when a new frame needs to be generated for the layer time specified by timeInterval.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h

openGLContextForPixelFormat:

Returns the OpenGL context to use for the requested pixel format.

- (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat
Parameters
pixelFormat

The pixel format.

Return Value

An autoreleased NSOpenGLContext.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h

openGLPixelFormatForDisplayMask:

Returns the OpenGL pixel format suitable for the specified displays.

- (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask
Parameters
mask

A mask specifying the displays the returned NSOpenGLPixelFormat must be suitable for.

Return Value

An autoreleased NSOpenGLPixelFormat object suitable for the displays.

Discussion

You must include an NSOpenGLPFAScreenMask specification in the pixel format attribute list that's used to instantiate the NSOpenGLPixelFormat.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSOpenGLLayer.h