Class

GLKView

A default implementation for views that draw their content using OpenGL ES.

Overview

The GLKView class simplifies the effort required to create an OpenGL ES application by directly managing a framebuffer object on your behalf; your application simply needs to draw into the framebuffer when the contents need to be updated.

To use this class in your application, create a new GLKView object and provide it an OpenGL ES context. Then, modify the view’s drawable​Color​Format, drawable​Depth​Format, drawable​Stencil​Format, and drawable​Multisample properties to configure the format of the drawable’s framebuffer object. After this, the view automatically creates or updates the framebuffer object whenever the view must be redrawn. A GLKView object uses the regular view drawing cycle for a UIView object, calling its draw(_:​) method whenever the contents of the view need to be updated. Before calling its draw(_:​) method, the view makes its EAGLContext object the current OpenGL ES context and binds its framebuffer object to the OpenGL ES context as the target for rendering commands. Your application’s implementation of the draw(_:​) method should call one or more OpenGL ES functions to render an image into the framebuffer object. Then, the view resolves any multisampling that you may have enabled and delivers the finished results.

The GLKView class can be used in conjunction with a GLKView​Controller object to create an animation rendering loop that redraws the contents of the view at a specified frame rate.

Subclassing Notes

Typically, there is no need to subclass the GLKView class. Instead, provide a delegate object to draw the view’s contents. See GLKView​Delegate.

Symbols

Initializing the View

Delegate

Configuring the Framebuffer Object

Read-only Framebuffer Properties

var drawable​Height:​ Int

The height, in pixels, of the underlying framebuffer object.

var drawable​Width:​ Int

The width, in pixels, of the underlying framebuffer object.

Drawing Your View’s Contents

var context:​ EAGLContext

The OpenGL ES context used when drawing the view’s contents.

func bind​Drawable()

Binds the underlying framebuffer object to OpenGL ES.

var enable​Set​Needs​Display:​ Bool

A Boolean value that indicates whether the view responds to messages that invalidate the view’s contents.

func display()

Redraws the view’s contents immediately.

var snapshot:​ UIImage

Draws the contents of the view and returns them as a new image object.

Deleting the View’s Underlying Framebuffer Object

func delete​Drawable()

Deletes the drawable object associated with the view.

Constants

GLKView​Drawable​Color​Format

The format of the color renderbuffer.

GLKView​Drawable​Depth​Format

The format of the depth renderbuffer.

GLKView​Drawable​Stencil​Format

The format of the stencil renderbuffer.

GLKView​Drawable​Multisample

The format of the multisampling buffer.