CCGLView Class Reference

Inherits from UIView
Conforms to CCDirectorView
Declared in CCGLView.h

Overview

CCGLView Class. This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. The view content is basically an EAGL surface you render your OpenGL scene into.

This class is normally set up for you in the AppDelegate instance of the Cocos2D project template, but you may need to create it yourself in mixed UIKit / Cocos2D apps or tweak some of its parameters, for instance to enable the framebuffer’s alpha channel in order to see views underneath the CCGLView.

Note: Setting the view non-opaque will only work if the pixelFormat is also set to kEAGLColorFormatRGBA8 upon initialization.

Note: This documentation is for the iOS version of the class. OS X use specific variants of CCGLView which inherit from other base classes (ie NSOpenGLView on OS X).

Parameters:

  • viewWithFrame: size of the OpenGL view. For full screen use _window.bounds.
  • pixelFormat: Format of the render buffer. Use kEAGLColorFormatRGBA8 for better color precision (eg: gradients) at the expense of doubling memory usage and performance.
    • Possible values: kEAGLColorFormatRGBA8, kEAGLColorFormatRGB565
  • depthFormat: Use stencil if you plan to use CCClippingNode. Use depth if you plan to use 3D effects.
    • Possible values: 0, GL_DEPTH_COMPONENT24_OES, GL_DEPTH24_STENCIL8_OES
  • sharegroup: OpenGL sharegroup. Useful if you want to share the same OpenGL context between different threads.
  • multiSampling: Whether or not to enable multisampling.
  • numberOfSamples: Only valid if multisampling is enabled
    • Possible values: any integer in the range 0 (off) to glGetIntegerv(GL_MAX_SAMPLES_APPLE) where the latter is device-dependent.

Creating a CCGLView

+ viewWithFrame:

creates an initializes an CCGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer.

+ (id)viewWithFrame:(CGRect)frame

Parameters

frame

The frame of the view.

Declared In

CCGLView.h

+ viewWithFrame:pixelFormat:

creates an initializes an CCGLView with a frame, a color buffer format, and 0-bit depth buffer.

+ (id)viewWithFrame:(CGRect)frame pixelFormat:(NSString *)format

Parameters

frame

The frame of the view.

format

The pixel format of the render buffer, either: kEAGLColorFormatRGBA8 (24-bit colors, 8-bit alpha) or kEAGLColorFormatRGB565 (16-bit colors, no alpha).

Declared In

CCGLView.h

+ viewWithFrame:pixelFormat:depthFormat:

creates an initializes an CCGLView with a frame, a color buffer format, and a depth buffer.

+ (id)viewWithFrame:(CGRect)frame pixelFormat:(NSString *)format depthFormat:(GLuint)depth

Parameters

frame

The frame of the view.

format

The pixel format of the render buffer, either: kEAGLColorFormatRGBA8 (24-bit colors, 8-bit alpha) or kEAGLColorFormatRGB565 (16-bit colors, no alpha).

depth

The size and format of the depth buffer, use 0 to disable depth buffer. Otherwise use GL_DEPTH24_STENCIL8_OES or GL_DEPTH_COMPONENT24_OES.

Declared In

CCGLView.h

+ viewWithFrame:pixelFormat:depthFormat:preserveBackbuffer:sharegroup:multiSampling:numberOfSamples:

creates an initializes an CCGLView with a frame, a color buffer format, a depth buffer format, a sharegroup, and multisamping.

+ (id)viewWithFrame:(CGRect)frame pixelFormat:(NSString *)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup *)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples

Parameters

frame

The frame of the view.

format

The pixel format of the render buffer, either: kEAGLColorFormatRGBA8 (24-bit colors, 8-bit alpha) or kEAGLColorFormatRGB565 (16-bit colors, no alpha).

depth

The size and format of the depth buffer, use 0 to disable depth buffer. Otherwise use GL_DEPTH24_STENCIL8_OES or GL_DEPTH_COMPONENT24_OES.

retained

Whether to clear the backbuffer before drawing to it. YES = don’t clear, NO = clear.

sharegroup

An OpenGL sharegroup or nil.

multisampling

Whether to enable multisampling (AA).

samples

The number of samples used in multisampling, from 0 (no AA) to glGetIntegerv(GL_MAX_SAMPLES_APPLE). Only takes effect if the preceding multisampling parameters is set to YES.

Declared In

CCGLView.h

– initWithFrame:

Initializes an CCGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer

- (id)initWithFrame:(CGRect)frame

Parameters

frame

The frame of the view.

Declared In

CCGLView.h

– initWithFrame:pixelFormat:

Initializes an CCGLView with a frame, a color buffer format, and 0-bit depth buffer

- (id)initWithFrame:(CGRect)frame pixelFormat:(NSString *)format

Parameters

frame

The frame of the view.

format

The pixel format of the render buffer, either: kEAGLColorFormatRGBA8 (24-bit colors, 8-bit alpha) or kEAGLColorFormatRGB565 (16-bit colors, no alpha).

Declared In

CCGLView.h

– initWithFrame:pixelFormat:depthFormat:preserveBackbuffer:sharegroup:multiSampling:numberOfSamples:

Initializes an CCGLView with a frame, a color buffer format, a depth buffer format, a sharegroup and multisampling support

- (id)initWithFrame:(CGRect)frame pixelFormat:(NSString *)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup *)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples

Parameters

frame

The frame of the view.

format

The pixel format of the render buffer, either: kEAGLColorFormatRGBA8 (24-bit colors, 8-bit alpha) or kEAGLColorFormatRGB565 (16-bit colors, no alpha).

depth

The size and format of the depth buffer, use 0 to disable depth buffer. Otherwise use GL_DEPTH24_STENCIL8_OES or GL_DEPTH_COMPONENT24_OES.

retained

Whether to clear the backbuffer before drawing to it. YES = don’t clear, NO = clear.

sharegroup

An OpenGL sharegroup or nil.

sampling

Whether to enable multisampling (AA).

nSamples

The number of samples used in multisampling, from 0 (no AA) to glGetIntegerv(GL_MAX_SAMPLES_APPLE). Only takes effect if the preceding multisampling parameters is set to YES.

Declared In

CCGLView.h

Framebuffer Information

  pixelFormat

pixel format: it could be RGBA8 (32-bit) or RGB565 (16-bit)

@property (nonatomic, readonly) NSString *pixelFormat

Declared In

CCGLView.h

  depthFormat

depth format of the render buffer: 0, 16 or 24 bits

@property (nonatomic, readonly) GLuint depthFormat

Declared In

CCGLView.h

  surfaceSize

returns surface size in pixels

@property (nonatomic, readonly) CGSize surfaceSize

Declared In

CCGLView.h

  context

OpenGL context

@property (nonatomic, readonly) EAGLContext *context

Declared In

CCGLView.h

  multiSampling

Whether multisampling is enabled.

@property (nonatomic, readwrite) BOOL multiSampling

Declared In

CCGLView.h