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.
-
– init
Initializes an empty VertexData object. Use the
appendVertex:
method and thenumVertices
property 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.
-
– bounds
Calculates 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
-
vertices
Returns a pointer to the raw vertex data.
property -
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
property1
). -
premultipliedAlpha
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 -
tinted
Indicates 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 numVertices
Discussion
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.h
premultipliedAlpha
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 premultipliedAlpha
Discussion
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.h
Instance Methods
alphaAtIndex:
Returns the alpha value of a vertex.
- (float)alphaAtIndex:(int)index
Discussion
Returns the alpha value of a vertex.
Declared In
SPVertexData.h
appendVertex:
Adds a vertex at the end, raising the number of vertices by one.
- (void)appendVertex:(SPVertex)vertex
Discussion
Adds a vertex at the end, raising the number of vertices by one.
Declared In
SPVertexData.h
bounds
Calculates the bounding rectangle of all vertices.
- (SPRectangle *)bounds
Discussion
Calculates the bounding rectangle of all vertices.
Declared In
SPVertexData.h
boundsAfterTransformation:
Calculates the bounding rectangle of all vertices after being transformed by a matrix.
- (SPRectangle *)boundsAfterTransformation:(SPMatrix *)matrix
Discussion
Calculates the bounding rectangle of all vertices after being transformed by a matrix.
Declared In
SPVertexData.h
boundsAfterTransformation:atIndex:numVertices:
Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.
- (SPRectangle *)boundsAfterTransformation:(SPMatrix *)matrix atIndex:(int)index numVertices:(int)count
Discussion
Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.
Declared In
SPVertexData.h
colorAtIndex:
Returns the RGB color of a vertex (without premultiplied alpha).
- (uint)colorAtIndex:(int)index
Discussion
Returns the RGB color of a vertex (without premultiplied alpha).
Declared In
SPVertexData.h
copyToVertexData:
Copies the vertex data of this instance to another vertex data object, starting at element 0.
- (void)copyToVertexData:(SPVertexData *)target
Discussion
Copies the vertex data of this instance to another vertex data object, starting at element 0.
Declared In
SPVertexData.h
copyToVertexData:atIndex:
Copies the vertex data of this instance to another vertex data object, starting at a certain index.
- (void)copyToVertexData:(SPVertexData *)target atIndex:(int)targetIndex
Discussion
Copies the vertex data of this instance to another vertex data object, starting at a certain index.
Declared In
SPVertexData.h
copyToVertexData:atIndex:numVertices:
Copies a range of vertices of this instance to another vertex data object.
- (void)copyToVertexData:(SPVertexData *)target atIndex:(int)targetIndex numVertices:(int)count
Discussion
Copies a range of vertices of this instance to another vertex data object.
Declared In
SPVertexData.h
init
Initializes an empty VertexData object. Use the appendVertex:
method and the numVertices
property to change its size later.
- (instancetype)init
Discussion
Initializes an empty VertexData object. Use the appendVertex:
method and the numVertices
property to change its size later.
Declared In
SPVertexData.h
initWithSize:
Initializes a VertexData instance with a certain size, disabling premultiplied alpha.
- (instancetype)initWithSize:(int)numVertices
Discussion
Initializes a VertexData instance with a certain size, disabling premultiplied alpha.
Declared In
SPVertexData.h
initWithSize:premultipliedAlpha:
Initializes a VertexData instance with a certain size. Designated Initializer.
- (instancetype)initWithSize:(int)numVertices premultipliedAlpha:(BOOL)pma
Discussion
Initializes a VertexData instance with a certain size. Designated Initializer.
Declared In
SPVertexData.h
positionAtIndex:
Returns the position of a vertex.
- (SPPoint *)positionAtIndex:(int)index
Discussion
Returns the position of a vertex.
Declared In
SPVertexData.h
scaleAlphaBy:
Multiplies all alpha values with a certain factor.
- (void)scaleAlphaBy:(float)factor
Discussion
Multiplies all alpha values with a certain factor.
Declared In
SPVertexData.h
scaleAlphaBy:atIndex:numVertices:
Multiplies a range of alpha values with a certain factor.
- (void)scaleAlphaBy:(float)factor atIndex:(int)index numVertices:(int)count
Discussion
Multiplies a range of alpha values with a certain factor.
Declared In
SPVertexData.h
setAlpha:
Updates the alpha value of all vertices.
- (void)setAlpha:(float)alpha
Discussion
Updates the alpha value of all vertices.
Declared In
SPVertexData.h
setAlpha:atIndex:
Updates the alpha value of a vertex.
- (void)setAlpha:(float)alpha atIndex:(int)index
Discussion
Updates the alpha value of a vertex.
Declared In
SPVertexData.h
setColor:
Sets the RGB color of all vertices at once. The method always expects non-premultiplied alpha values.
- (void)setColor:(uint)color
Discussion
Sets the RGB color of all vertices at once. The method always expects non-premultiplied alpha values.
Declared In
SPVertexData.h
setColor:alpha:
Updates the RGB color and the alpha value of all vertices.
- (void)setColor:(uint)color alpha:(float)alpha
Discussion
Updates the RGB color and the alpha value of all vertices.
Declared In
SPVertexData.h
setColor:alpha:atIndex:
Updates the RGB color and the alpha value of a vertex.
- (void)setColor:(uint)color alpha:(float)alpha atIndex:(int)index
Discussion
Updates the RGB color and the alpha value of a vertex.
Declared In
SPVertexData.h
setColor:atIndex:
Sets the RGB color of a vertex. The method always expects non-premultiplied alpha values.
- (void)setColor:(uint)color atIndex:(int)index
Discussion
Sets the RGB color of a vertex. The method always expects non-premultiplied alpha values.
Declared In
SPVertexData.h
setPosition:atIndex:
Updates the position of a vertex.
- (void)setPosition:(SPPoint *)position atIndex:(int)index
Discussion
Updates the position of a vertex.
Declared In
SPVertexData.h
setPositionWithX:y:atIndex:
Updates the position of a vertex.
- (void)setPositionWithX:(float)x y:(float)y atIndex:(int)index
Discussion
Updates the position of a vertex.
Declared In
SPVertexData.h
setPremultipliedAlpha:updateVertices:
Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.
- (void)setPremultipliedAlpha:(BOOL)value updateVertices:(BOOL)update
Discussion
Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.
Declared In
SPVertexData.h
setTexCoords:atIndex:
Updates the texture coordinates of a vertex.
- (void)setTexCoords:(SPPoint *)texCoords atIndex:(int)index
Discussion
Updates the texture coordinates of a vertex.
Declared In
SPVertexData.h
setTexCoordsWithX:y:atIndex:
Updates the texture coordinates of a vertex.
- (void)setTexCoordsWithX:(float)x y:(float)y atIndex:(int)index
Discussion
Updates the texture coordinates of a vertex.
Declared In
SPVertexData.h
setVertex:atIndex:
Updates the vertex at a certain position.
- (void)setVertex:(SPVertex)vertex atIndex:(int)index
Discussion
Updates the vertex at a certain position.
Declared In
SPVertexData.h
texCoordsAtIndex:
Returns the texture coordinates of a vertex.
- (SPPoint *)texCoordsAtIndex:(int)index
Discussion
Returns the texture coordinates of a vertex.
Declared In
SPVertexData.h
transformVerticesWithMatrix:atIndex:numVertices:
Transforms the positions of subsequent vertices by multiplication with a transformation matrix.
- (void)transformVerticesWithMatrix:(SPMatrix *)matrix atIndex:(int)index numVertices:(int)count
Discussion
Transforms the positions of subsequent vertices by multiplication with a transformation matrix.
Declared In
SPVertexData.h