SPRenderSupport Class Reference
| Inherits from | NSObject |
| Declared in | SPRenderSupport.h |
Overview
A class that contains helper methods simplifying OpenGL rendering.
An SPRenderSupport instance is passed to any render: method. It saves information about the current render state, like the alpha value, modelview matrix, and blend mode.
It also keeps a list of quad batches, which can be used to render a high number of quads very efficiently; only changes in the state of added quads trigger OpenGL draw calls.
Furthermore, several static helper methods can be used for different needs whenever some OpenGL processing is required.
Tasks
Methods
-
– nextFrameResets the render state stack to the default.
-
– batchQuad:Adds a quad or image to the current batch of unrendered quads. If there is a state change, all previous quads are rendered at once, and the batch is reset. Note that the values for alpha and blend mode are taken from the current render state, not the quad.
-
– finishQuadBatchRenders the current quad batch and resets it.
-
– purgeBuffersClears all vertex and index buffers, releasing the associated memory. Useful in low-memory situations. Don’t call from within a render method!
-
– clearClears OpenGL’s color buffer.
-
– clearWithColor:Clears OpenGL’s color buffer with a specified color.
-
– clearWithColor:alpha:Clears OpenGL’s color buffer with a specified color and alpha.
-
+ clearWithColor:alpha:Clears OpenGL’s color buffer with a specified color and alpha.
-
+ checkForOpenGLErrorChecks for an OpenGL error. If there is one, it is logged an the error code is returned.
-
– addDrawCalls:Raises the number of draw calls by a specific value. Call this method in custom render methods to keep the statistics display in sync.
-
– setupOrthographicProjectionWithLeft:right:top:bottom:Sets up the projection matrix for ortographic 2D rendering.
State Manipulation
-
– pushStateWithMatrix:alpha:blendMode:Adds a new render state to the stack. The passed matrix is prepended to the modelview matrix; the alpha value is multiplied with the current alpha; the blend mode replaces the existing mode (except
SPBlendModeAuto, which will cause the current mode to prevail). -
– popStateRestores the previous render state.
-
– applyBlendModeForPremultipliedAlpha:Activates the current blend mode.
Clipping
-
– pushClipRect:The clipping rectangle can be used to limit rendering in the current render target to a certain area. This method expects the rectangle in stage coordinates. Internally, it uses the ‘glScissor’ command of OpenGL, which works with pixel coordinates. Any pushed rectangle is intersected with the previous rectangle; the method returns that intersection.
-
– popClipRectRestores the clipping rectangle that was last pushed to the stack.
-
– applyClipRectUpdates the scissor rectangle using the current clipping rectangle. This method is called automatically when either the projection matrix or the clipping rectangle changes.
Properties
-
projectionMatrixReturns the current projection matrix. CAUTION: Use with care! Each call returns the same instance.
property -
mvpMatrixCalculates the product of modelview and projection matrix. CAUTION: Use with care! Each call returns the same instance.
property -
modelviewMatrixReturns the current modelview matrix. CAUTION: Use with care! Returns not a copy, but the internally used instance.
property -
alphaThe current (accumulated) alpha value.
property -
blendModeThe current blend mode.
property -
renderTargetThe texture that is currently being rendered into, or ‘nil’ to render into the back buffer. If you set a new target, it is immediately activated.
property -
numDrawCallsIndicates the number of OpenGL ES draw calls since the last call to
propertynextFrame.
Properties
alpha
The current (accumulated) alpha value.
@property (nonatomic, assign) float alphaDiscussion
The current (accumulated) alpha value.
Declared In
SPRenderSupport.hblendMode
The current blend mode.
@property (nonatomic, assign) uint blendModeDiscussion
The current blend mode.
Declared In
SPRenderSupport.hmodelviewMatrix
Returns the current modelview matrix. CAUTION: Use with care! Returns not a copy, but the internally used instance.
@property (nonatomic, readonly) SPMatrix *modelviewMatrixDiscussion
Returns the current modelview matrix. CAUTION: Use with care! Returns not a copy, but the internally used instance.
Declared In
SPRenderSupport.hmvpMatrix
Calculates the product of modelview and projection matrix. CAUTION: Use with care! Each call returns the same instance.
@property (nonatomic, readonly) SPMatrix *mvpMatrixDiscussion
Calculates the product of modelview and projection matrix. CAUTION: Use with care! Each call returns the same instance.
Declared In
SPRenderSupport.hnumDrawCalls
Indicates the number of OpenGL ES draw calls since the last call to nextFrame.
@property (nonatomic, readonly) int numDrawCallsDiscussion
Indicates the number of OpenGL ES draw calls since the last call to nextFrame.
Declared In
SPRenderSupport.hprojectionMatrix
Returns the current projection matrix. CAUTION: Use with care! Each call returns the same instance.
@property (nonatomic, copy) SPMatrix *projectionMatrixDiscussion
Returns the current projection matrix. CAUTION: Use with care! Each call returns the same instance.
Declared In
SPRenderSupport.hrenderTarget
The texture that is currently being rendered into, or ‘nil’ to render into the back buffer. If you set a new target, it is immediately activated.
@property (nonatomic, strong) SPTexture *renderTargetDiscussion
The texture that is currently being rendered into, or ‘nil’ to render into the back buffer. If you set a new target, it is immediately activated.
Declared In
SPRenderSupport.hClass Methods
Instance Methods
addDrawCalls:
Raises the number of draw calls by a specific value. Call this method in custom render methods to keep the statistics display in sync.
- (void)addDrawCalls:(int)countDiscussion
Raises the number of draw calls by a specific value. Call this method in custom render methods to keep the statistics display in sync.
Declared In
SPRenderSupport.happlyBlendModeForPremultipliedAlpha:
Activates the current blend mode.
- (void)applyBlendModeForPremultipliedAlpha:(BOOL)pmaDiscussion
Activates the current blend mode.
Declared In
SPRenderSupport.happlyClipRect
Updates the scissor rectangle using the current clipping rectangle. This method is called automatically when either the projection matrix or the clipping rectangle changes.
- (void)applyClipRectDiscussion
Updates the scissor rectangle using the current clipping rectangle. This method is called automatically when either the projection matrix or the clipping rectangle changes.
Declared In
SPRenderSupport.hbatchQuad:
Adds a quad or image to the current batch of unrendered quads. If there is a state change, all previous quads are rendered at once, and the batch is reset. Note that the values for alpha and blend mode are taken from the current render state, not the quad.
- (void)batchQuad:(SPQuad *)quadDiscussion
Adds a quad or image to the current batch of unrendered quads. If there is a state change, all previous quads are rendered at once, and the batch is reset. Note that the values for alpha and blend mode are taken from the current render state, not the quad.
Declared In
SPRenderSupport.hclear
Clears OpenGL’s color buffer.
- (void)clearDiscussion
Clears OpenGL’s color buffer.
Declared In
SPRenderSupport.hclearWithColor:
Clears OpenGL’s color buffer with a specified color.
- (void)clearWithColor:(uint)colorDiscussion
Clears OpenGL’s color buffer with a specified color.
Declared In
SPRenderSupport.hclearWithColor:alpha:
Clears OpenGL’s color buffer with a specified color and alpha.
- (void)clearWithColor:(uint)color alpha:(float)alphaDiscussion
Clears OpenGL’s color buffer with a specified color and alpha.
Declared In
SPRenderSupport.hfinishQuadBatch
Renders the current quad batch and resets it.
- (void)finishQuadBatchDiscussion
Renders the current quad batch and resets it.
Declared In
SPRenderSupport.hnextFrame
Resets the render state stack to the default.
- (void)nextFrameDiscussion
Resets the render state stack to the default.
Declared In
SPRenderSupport.hpopClipRect
Restores the clipping rectangle that was last pushed to the stack.
- (void)popClipRectDiscussion
Restores the clipping rectangle that was last pushed to the stack.
Declared In
SPRenderSupport.hpopState
Restores the previous render state.
- (void)popStateDiscussion
Restores the previous render state.
Declared In
SPRenderSupport.hpurgeBuffers
Clears all vertex and index buffers, releasing the associated memory. Useful in low-memory situations. Don’t call from within a render method!
- (void)purgeBuffersDiscussion
Clears all vertex and index buffers, releasing the associated memory. Useful in low-memory situations. Don’t call from within a render method!
Declared In
SPRenderSupport.hpushClipRect:
The clipping rectangle can be used to limit rendering in the current render target to a certain area. This method expects the rectangle in stage coordinates. Internally, it uses the ‘glScissor’ command of OpenGL, which works with pixel coordinates. Any pushed rectangle is intersected with the previous rectangle; the method returns that intersection.
- (SPRectangle *)pushClipRect:(SPRectangle *)clipRectDiscussion
The clipping rectangle can be used to limit rendering in the current render target to a certain area. This method expects the rectangle in stage coordinates. Internally, it uses the ‘glScissor’ command of OpenGL, which works with pixel coordinates. Any pushed rectangle is intersected with the previous rectangle; the method returns that intersection.
Declared In
SPRenderSupport.hpushStateWithMatrix:alpha:blendMode:
Adds a new render state to the stack. The passed matrix is prepended to the modelview matrix;
the alpha value is multiplied with the current alpha; the blend mode replaces the existing
mode (except SPBlendModeAuto, which will cause the current mode to prevail).
- (void)pushStateWithMatrix:(SPMatrix *)matrix alpha:(float)alpha blendMode:(uint)blendModeDiscussion
Adds a new render state to the stack. The passed matrix is prepended to the modelview matrix;
the alpha value is multiplied with the current alpha; the blend mode replaces the existing
mode (except SPBlendModeAuto, which will cause the current mode to prevail).
Declared In
SPRenderSupport.hsetupOrthographicProjectionWithLeft:right:top:bottom:
Sets up the projection matrix for ortographic 2D rendering.
- (void)setupOrthographicProjectionWithLeft:(float)left right:(float)right top:(float)top bottom:(float)bottomDiscussion
Sets up the projection matrix for ortographic 2D rendering.
Declared In
SPRenderSupport.h