SPVertexData Class Reference
| Inherits from | NSObject |
| Conforms to | NSCopying |
| Declared in | SPVertexData.h |
Overview
The SPVertexData class manages a raw list of vertex information, allowing direct upload to OpenGL vertex buffers.
You only have to work with this class if you create display objects with a custom render function. If you don’t plan to do that, you can safely ignore it.
To render objects with OpenGL, you have to organize vertex data in so-called vertex buffers. Those buffers reside in graphics memory and can be accessed very efficiently by the GPU. Before you can move data into vertex buffers, you have to set it up in conventional memory - that is, in a byte array. That array contains all vertex information (the coordinates, color, and texture coordinates) - one vertex after the other.
To simplify creating and working with such a bulky list, the VertexData class was created. It contains methods to specify and modify vertex data. The raw array managed by the class can then easily be uploaded to a vertex buffer.
Premultiplied Alpha
The color values of texture files may contain premultiplied alpha values, which
means that the RGB values were multiplied with the alpha value
before saving them. On rendering, it makes a difference in which way the alpha value is saved;
for that reason, the VertexData class mimics this behavior. You can choose how the alpha
values should be handled via the premultipliedAlpha property.
Tasks
Initialization
-
– initWithSize:premultipliedAlpha:Initializes a VertexData instance with a certain size. Designated Initializer.
-
– initWithSize:Initializes a VertexData instance with a certain size, disabling premultiplied alpha.
-
– initInitializes an empty VertexData object. Use the
appendVertex:method and thenumVerticesproperty to change its size later.
Methods
-
– copyToVertexData:Copies the vertex data of this instance to another vertex data object, starting at element 0.
-
– copyToVertexData:atIndex:Copies the vertex data of this instance to another vertex data object, starting at a certain index.
-
– copyToVertexData:atIndex:numVertices:Copies a range of vertices of this instance to another vertex data object.
-
– vertexAtIndex:Returns a vertex at a certain position
-
– setVertex:atIndex:Updates the vertex at a certain position.
-
– appendVertex:Adds a vertex at the end, raising the number of vertices by one.
-
– positionAtIndex:Returns the position of a vertex.
-
– setPosition:atIndex:Updates the position of a vertex.
-
– setPositionWithX:y:atIndex:Updates the position of a vertex.
-
– texCoordsAtIndex:Returns the texture coordinates of a vertex.
-
– setTexCoords:atIndex:Updates the texture coordinates of a vertex.
-
– setTexCoordsWithX:y:atIndex:Updates the texture coordinates of a vertex.
-
– setColor:alpha:atIndex:Updates the RGB color and the alpha value of a vertex.
-
– setColor:alpha:Updates the RGB color and the alpha value of all vertices.
-
– colorAtIndex:Returns the RGB color of a vertex (without premultiplied alpha).
-
– setColor:atIndex:Sets the RGB color of a vertex. The method always expects non-premultiplied alpha values.
-
– setColor:Sets the RGB color of all vertices at once. The method always expects non-premultiplied alpha values.
-
– alphaAtIndex:Returns the alpha value of a vertex.
-
– setAlpha:atIndex:Updates the alpha value of a vertex.
-
– setAlpha:Updates the alpha value of all vertices.
-
– scaleAlphaBy:Multiplies all alpha values with a certain factor.
-
– scaleAlphaBy:atIndex:numVertices:Multiplies a range of alpha values with a certain factor.
-
– setPremultipliedAlpha:updateVertices:Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.
-
– transformVerticesWithMatrix:atIndex:numVertices:Transforms the positions of subsequent vertices by multiplication with a transformation matrix.
-
– boundsCalculates the bounding rectangle of all vertices.
-
– boundsAfterTransformation:Calculates the bounding rectangle of all vertices after being transformed by a matrix.
-
– boundsAfterTransformation:atIndex:numVertices:Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.
Properties
-
verticesReturns a pointer to the raw vertex data.
property -
numVerticesIndicates the size of the VertexData object. You can resize the object any time; if you make it bigger, it will be filled up with vertices that have all properties zeroed, except for the alpha value (it’s
property1). -
premultipliedAlphaIndicates if the rgb values are stored premultiplied with the alpha value. If you change this property, all color data will be updated accordingly.
property -
tintedIndicates if any vertices have a non-white color or are not fully opaque.
property
Properties
numVertices
Indicates the size of the VertexData object. You can resize the object any time; if you
make it bigger, it will be filled up with vertices that have all properties zeroed, except
for the alpha value (it’s 1).
@property (nonatomic, assign) int numVerticesDiscussion
Indicates the size of the VertexData object. You can resize the object any time; if you
make it bigger, it will be filled up with vertices that have all properties zeroed, except
for the alpha value (it’s 1).
Declared In
SPVertexData.hpremultipliedAlpha
Indicates if the rgb values are stored premultiplied with the alpha value. If you change this property, all color data will be updated accordingly.
@property (nonatomic, assign) BOOL premultipliedAlphaDiscussion
Indicates if the rgb values are stored premultiplied with the alpha value. If you change this property, all color data will be updated accordingly.
Declared In
SPVertexData.hInstance Methods
alphaAtIndex:
Returns the alpha value of a vertex.
- (float)alphaAtIndex:(int)indexDiscussion
Returns the alpha value of a vertex.
Declared In
SPVertexData.happendVertex:
Adds a vertex at the end, raising the number of vertices by one.
- (void)appendVertex:(SPVertex)vertexDiscussion
Adds a vertex at the end, raising the number of vertices by one.
Declared In
SPVertexData.hbounds
Calculates the bounding rectangle of all vertices.
- (SPRectangle *)boundsDiscussion
Calculates the bounding rectangle of all vertices.
Declared In
SPVertexData.hboundsAfterTransformation:
Calculates the bounding rectangle of all vertices after being transformed by a matrix.
- (SPRectangle *)boundsAfterTransformation:(SPMatrix *)matrixDiscussion
Calculates the bounding rectangle of all vertices after being transformed by a matrix.
Declared In
SPVertexData.hboundsAfterTransformation:atIndex:numVertices:
Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.
- (SPRectangle *)boundsAfterTransformation:(SPMatrix *)matrix atIndex:(int)index numVertices:(int)countDiscussion
Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.
Declared In
SPVertexData.hcolorAtIndex:
Returns the RGB color of a vertex (without premultiplied alpha).
- (uint)colorAtIndex:(int)indexDiscussion
Returns the RGB color of a vertex (without premultiplied alpha).
Declared In
SPVertexData.hcopyToVertexData:
Copies the vertex data of this instance to another vertex data object, starting at element 0.
- (void)copyToVertexData:(SPVertexData *)targetDiscussion
Copies the vertex data of this instance to another vertex data object, starting at element 0.
Declared In
SPVertexData.hcopyToVertexData:atIndex:
Copies the vertex data of this instance to another vertex data object, starting at a certain index.
- (void)copyToVertexData:(SPVertexData *)target atIndex:(int)targetIndexDiscussion
Copies the vertex data of this instance to another vertex data object, starting at a certain index.
Declared In
SPVertexData.hcopyToVertexData:atIndex:numVertices:
Copies a range of vertices of this instance to another vertex data object.
- (void)copyToVertexData:(SPVertexData *)target atIndex:(int)targetIndex numVertices:(int)countDiscussion
Copies a range of vertices of this instance to another vertex data object.
Declared In
SPVertexData.hinit
Initializes an empty VertexData object. Use the appendVertex: method and the numVertices
property to change its size later.
- (instancetype)initDiscussion
Initializes an empty VertexData object. Use the appendVertex: method and the numVertices
property to change its size later.
Declared In
SPVertexData.hinitWithSize:
Initializes a VertexData instance with a certain size, disabling premultiplied alpha.
- (instancetype)initWithSize:(int)numVerticesDiscussion
Initializes a VertexData instance with a certain size, disabling premultiplied alpha.
Declared In
SPVertexData.hinitWithSize:premultipliedAlpha:
Initializes a VertexData instance with a certain size. Designated Initializer.
- (instancetype)initWithSize:(int)numVertices premultipliedAlpha:(BOOL)pmaDiscussion
Initializes a VertexData instance with a certain size. Designated Initializer.
Declared In
SPVertexData.hpositionAtIndex:
Returns the position of a vertex.
- (SPPoint *)positionAtIndex:(int)indexDiscussion
Returns the position of a vertex.
Declared In
SPVertexData.hscaleAlphaBy:
Multiplies all alpha values with a certain factor.
- (void)scaleAlphaBy:(float)factorDiscussion
Multiplies all alpha values with a certain factor.
Declared In
SPVertexData.hscaleAlphaBy:atIndex:numVertices:
Multiplies a range of alpha values with a certain factor.
- (void)scaleAlphaBy:(float)factor atIndex:(int)index numVertices:(int)countDiscussion
Multiplies a range of alpha values with a certain factor.
Declared In
SPVertexData.hsetAlpha:
Updates the alpha value of all vertices.
- (void)setAlpha:(float)alphaDiscussion
Updates the alpha value of all vertices.
Declared In
SPVertexData.hsetAlpha:atIndex:
Updates the alpha value of a vertex.
- (void)setAlpha:(float)alpha atIndex:(int)indexDiscussion
Updates the alpha value of a vertex.
Declared In
SPVertexData.hsetColor:
Sets the RGB color of all vertices at once. The method always expects non-premultiplied alpha values.
- (void)setColor:(uint)colorDiscussion
Sets the RGB color of all vertices at once. The method always expects non-premultiplied alpha values.
Declared In
SPVertexData.hsetColor:alpha:
Updates the RGB color and the alpha value of all vertices.
- (void)setColor:(uint)color alpha:(float)alphaDiscussion
Updates the RGB color and the alpha value of all vertices.
Declared In
SPVertexData.hsetColor:alpha:atIndex:
Updates the RGB color and the alpha value of a vertex.
- (void)setColor:(uint)color alpha:(float)alpha atIndex:(int)indexDiscussion
Updates the RGB color and the alpha value of a vertex.
Declared In
SPVertexData.hsetColor:atIndex:
Sets the RGB color of a vertex. The method always expects non-premultiplied alpha values.
- (void)setColor:(uint)color atIndex:(int)indexDiscussion
Sets the RGB color of a vertex. The method always expects non-premultiplied alpha values.
Declared In
SPVertexData.hsetPosition:atIndex:
Updates the position of a vertex.
- (void)setPosition:(SPPoint *)position atIndex:(int)indexDiscussion
Updates the position of a vertex.
Declared In
SPVertexData.hsetPositionWithX:y:atIndex:
Updates the position of a vertex.
- (void)setPositionWithX:(float)x y:(float)y atIndex:(int)indexDiscussion
Updates the position of a vertex.
Declared In
SPVertexData.hsetPremultipliedAlpha:updateVertices:
Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.
- (void)setPremultipliedAlpha:(BOOL)value updateVertices:(BOOL)updateDiscussion
Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.
Declared In
SPVertexData.hsetTexCoords:atIndex:
Updates the texture coordinates of a vertex.
- (void)setTexCoords:(SPPoint *)texCoords atIndex:(int)indexDiscussion
Updates the texture coordinates of a vertex.
Declared In
SPVertexData.hsetTexCoordsWithX:y:atIndex:
Updates the texture coordinates of a vertex.
- (void)setTexCoordsWithX:(float)x y:(float)y atIndex:(int)indexDiscussion
Updates the texture coordinates of a vertex.
Declared In
SPVertexData.hsetVertex:atIndex:
Updates the vertex at a certain position.
- (void)setVertex:(SPVertex)vertex atIndex:(int)indexDiscussion
Updates the vertex at a certain position.
Declared In
SPVertexData.htexCoordsAtIndex:
Returns the texture coordinates of a vertex.
- (SPPoint *)texCoordsAtIndex:(int)indexDiscussion
Returns the texture coordinates of a vertex.
Declared In
SPVertexData.htransformVerticesWithMatrix:atIndex:numVertices:
Transforms the positions of subsequent vertices by multiplication with a transformation matrix.
- (void)transformVerticesWithMatrix:(SPMatrix *)matrix atIndex:(int)index numVertices:(int)countDiscussion
Transforms the positions of subsequent vertices by multiplication with a transformation matrix.
Declared In
SPVertexData.h