SPQuadBatch Class Reference
| Inherits from | SPDisplayObject : SPEventDispatcher : NSObject |
| Declared in | SPQuadBatch.h |
Overview
Optimizes rendering of a number of quads with an identical state.
The majority of all rendered objects in Sparrow are quads. In fact, all the default
leaf nodes of Sparrow are quads (the SPImage and SPQuad classes). The rendering of those
quads can be accelerated by a big factor if all quads with an identical state are sent
to the GPU in just one call. That’s what the SPQuadBatch class can do.
The flatten method of the SPSprite class uses this class internally to optimize its
rendering performance. In most situations, it is recommended to stick with flattened
sprites, because they are easier to use. Sometimes, however, it makes sense
to use the SPQuadBatch class directly: e.g. you can add one quad multiple times to
a quad batch, whereas you can only add it once to a sprite. Furthermore, this class
does not dispatch ADDED or ADDED_TO_STAGE events when a quad
is added, which makes it more lightweight.
One QuadBatch object is bound to a specific render state. The first object you add to a batch will decide on the QuadBatch’s state, that is: its texture, its settings for smoothing and repetition, and if it’s tinted (colored vertices and/or transparency). When you reset the batch, it will accept a new state on the next added quad.
Tasks
Initialization
-
– initWithCapacity:Initialize a QuadBatch with a certain capacity. The batch will grow dynamically if it exceeds this value. Designated Initializer.
-
– initInitialize a QuadBatch with a capacity of 16 quads.
-
+ quadBatchCreate a new, empty quad batch.
Methods
-
– resetResets the batch. The vertex- and index-buffers keep their size, so that they can be reused.
-
– addQuad:Adds a quad or image. Make sure you only add quads with an equal state.
-
– addQuad:alpha:Adds a quad or image using a custom alpha value (ignoring the quad’s original alpha). Make sure you only add quads with an equal state.
-
– addQuad:alpha:blendMode:Adds a quad or image to the batch, using custom alpha and blend mode values (ignoring the quad’s original values). Make sure you only add quads with an equal state.
-
– addQuad:alpha:blendMode:matrix:Adds a quad or image to the batch, using custom alpha and blend mode values (ignoring the quad’s original values) and transforming each vertex by a certain transformation matrix. Make sure you only add quads with an equal state.
-
– addQuadBatch:Adds another quad batch to this batch.
-
– addQuadBatch:alpha:Adds another quad batch to this batch, using a custom alpha value (ignoring the batch’s original alpha).
-
– addQuadBatch:alpha:blendMode:Adds another quad batch to this batch, using custom alpha and blend mode values (ignoring the batch’s original values). Just like the
addQuad:method, you have to make sure that you only add batches with an equal state. -
– addQuadBatch:alpha:blendMode:matrix:Adds another quad batch to this batch, using custom alpha and blend mode values (ignoring the batch’s original values) and transforming each vertex by a certain transformation matrix. Just like the
addQuad:method, you have to make sure that you only add batches with an equal state. -
– isStateChangeWithTinted:texture:alpha:premultipliedAlpha:blendMode:numQuads:Indicates if specific quads can be added to the batch without causing a state change. A state change occurs if the quad uses a different base texture, has a different
smoothing,repeator ‘tinted’ setting, or if the batch is full (one batch can contain up to 8192 quads). -
– renderWithMvpMatrix:alpha:blendMode:Renders the batch with custom alpha and blend mode values, as well as a custom mvp matrix.
-
– renderWithMvpMatrix:Renders the batch with a custom mvp matrix.
-
+ compileObject:Analyses an object that is made up exclusively of quads (or other containers) and creates an array of
SPQuadBatchobjects representing it. This can be used to render the container very efficiently. The ‘flatten’-method of theSPSpriteclass uses this method internally. */ -
+ compileObject:intoArray:Analyses an object that is made up exclusively of quads (or other containers) and saves the resulting quad batches into the specified an array; batches inside that array are reused.
Properties
-
numQuadsThe number of quads that has been added to the batch.
property -
tintedIndicates if any vertices have a non-white color or are not fully opaque.
property -
textureThe current texture of the batch, if there is one.
property -
premultipliedAlphaIndicates if the rgb values are stored premultiplied with the alpha value.
property
Properties
numQuads
The number of quads that has been added to the batch.
@property (nonatomic, readonly) int numQuadsDiscussion
The number of quads that has been added to the batch.
Declared In
SPQuadBatch.hpremultipliedAlpha
Indicates if the rgb values are stored premultiplied with the alpha value.
@property (nonatomic, readonly) BOOL premultipliedAlphaDiscussion
Indicates if the rgb values are stored premultiplied with the alpha value.
Declared In
SPQuadBatch.hClass Methods
compileObject:
Analyses an object that is made up exclusively of quads (or other containers) and creates an
array of SPQuadBatch objects representing it. This can be used to render the container very
efficiently. The ‘flatten’-method of the SPSprite class uses this method internally. */
+ (NSMutableArray *)compileObject:(SPDisplayObject *)objectDiscussion
Analyses an object that is made up exclusively of quads (or other containers) and creates an
array of SPQuadBatch objects representing it. This can be used to render the container very
efficiently. The ‘flatten’-method of the SPSprite class uses this method internally. */
Declared In
SPQuadBatch.hcompileObject:intoArray:
Analyses an object that is made up exclusively of quads (or other containers) and saves the resulting quad batches into the specified an array; batches inside that array are reused.
+ (NSMutableArray *)compileObject:(SPDisplayObject *)object intoArray:(NSMutableArray *)quadBatchesDiscussion
Analyses an object that is made up exclusively of quads (or other containers) and saves the resulting quad batches into the specified an array; batches inside that array are reused.
Declared In
SPQuadBatch.hInstance Methods
addQuad:
Adds a quad or image. Make sure you only add quads with an equal state.
- (void)addQuad:(SPQuad *)quadDiscussion
Adds a quad or image. Make sure you only add quads with an equal state.
Declared In
SPQuadBatch.haddQuad:alpha:
Adds a quad or image using a custom alpha value (ignoring the quad’s original alpha). Make sure you only add quads with an equal state.
- (void)addQuad:(SPQuad *)quad alpha:(float)alphaDiscussion
Adds a quad or image using a custom alpha value (ignoring the quad’s original alpha). Make sure you only add quads with an equal state.
Declared In
SPQuadBatch.haddQuad:alpha:blendMode:
Adds a quad or image to the batch, using custom alpha and blend mode values (ignoring the quad’s original values). Make sure you only add quads with an equal state.
- (void)addQuad:(SPQuad *)quad alpha:(float)alpha blendMode:(uint)blendModeDiscussion
Adds a quad or image to the batch, using custom alpha and blend mode values (ignoring the quad’s original values). Make sure you only add quads with an equal state.
Declared In
SPQuadBatch.haddQuad:alpha:blendMode:matrix:
Adds a quad or image to the batch, using custom alpha and blend mode values (ignoring the quad’s original values) and transforming each vertex by a certain transformation matrix. Make sure you only add quads with an equal state.
- (void)addQuad:(SPQuad *)quad alpha:(float)alpha blendMode:(uint)blendMode matrix:(SPMatrix *)matrixDiscussion
Adds a quad or image to the batch, using custom alpha and blend mode values (ignoring the quad’s original values) and transforming each vertex by a certain transformation matrix. Make sure you only add quads with an equal state.
Declared In
SPQuadBatch.haddQuadBatch:
Adds another quad batch to this batch.
- (void)addQuadBatch:(SPQuadBatch *)quadBatchDiscussion
Adds another quad batch to this batch.
Declared In
SPQuadBatch.haddQuadBatch:alpha:
Adds another quad batch to this batch, using a custom alpha value (ignoring the batch’s original alpha).
- (void)addQuadBatch:(SPQuadBatch *)quadBatch alpha:(float)alphaDiscussion
Adds another quad batch to this batch, using a custom alpha value (ignoring the batch’s original alpha).
Declared In
SPQuadBatch.haddQuadBatch:alpha:blendMode:
Adds another quad batch to this batch, using custom alpha and blend mode values (ignoring the
batch’s original values). Just like the addQuad: method, you have to make sure that you only
add batches with an equal state.
- (void)addQuadBatch:(SPQuadBatch *)quadBatch alpha:(float)alpha blendMode:(uint)blendModeDiscussion
Adds another quad batch to this batch, using custom alpha and blend mode values (ignoring the
batch’s original values). Just like the addQuad: method, you have to make sure that you only
add batches with an equal state.
Declared In
SPQuadBatch.haddQuadBatch:alpha:blendMode:matrix:
Adds another quad batch to this batch, using custom alpha and blend mode values (ignoring the
batch’s original values) and transforming each vertex by a certain transformation matrix. Just
like the addQuad: method, you have to make sure that you only add batches with an equal state.
- (void)addQuadBatch:(SPQuadBatch *)quadBatch alpha:(float)alpha blendMode:(uint)blendMode matrix:(SPMatrix *)matrixDiscussion
Adds another quad batch to this batch, using custom alpha and blend mode values (ignoring the
batch’s original values) and transforming each vertex by a certain transformation matrix. Just
like the addQuad: method, you have to make sure that you only add batches with an equal state.
Declared In
SPQuadBatch.hinit
Initialize a QuadBatch with a capacity of 16 quads.
- (instancetype)initDiscussion
Initialize a QuadBatch with a capacity of 16 quads.
Declared In
SPQuadBatch.hinitWithCapacity:
Initialize a QuadBatch with a certain capacity. The batch will grow dynamically if it exceeds this value. Designated Initializer.
- (instancetype)initWithCapacity:(int)capacityDiscussion
Initialize a QuadBatch with a certain capacity. The batch will grow dynamically if it exceeds this value. Designated Initializer.
Declared In
SPQuadBatch.hisStateChangeWithTinted:texture:alpha:premultipliedAlpha:blendMode:numQuads:
Indicates if specific quads can be added to the batch without causing a state change.
A state change occurs if the quad uses a different base texture, has a different smoothing,
repeat or ‘tinted’ setting, or if the batch is full (one batch can contain up to 8192 quads).
- (BOOL)isStateChangeWithTinted:(BOOL)tinted texture:(SPTexture *)texture alpha:(float)alpha premultipliedAlpha:(BOOL)pma blendMode:(uint)blendMode numQuads:(int)numQuadsDiscussion
Indicates if specific quads can be added to the batch without causing a state change.
A state change occurs if the quad uses a different base texture, has a different smoothing,
repeat or ‘tinted’ setting, or if the batch is full (one batch can contain up to 8192 quads).
Declared In
SPQuadBatch.hrenderWithMvpMatrix:
Renders the batch with a custom mvp matrix.
- (void)renderWithMvpMatrix:(SPMatrix *)matrixDiscussion
Renders the batch with a custom mvp matrix.
Declared In
SPQuadBatch.hrenderWithMvpMatrix:alpha:blendMode:
Renders the batch with custom alpha and blend mode values, as well as a custom mvp matrix.
- (void)renderWithMvpMatrix:(SPMatrix *)matrix alpha:(float)alpha blendMode:(uint)blendModeDiscussion
Renders the batch with custom alpha and blend mode values, as well as a custom mvp matrix.
Declared In
SPQuadBatch.h