VertexData
public class
loom2d.utils.VertexData
Description
The VertexData class manages a raw list of vertex information, allowing direct upload to Loom 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 GPUs, 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 Vector object. The vector 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 Vector managed by the class can then easily be uploaded to a vertex buffer.
Premultiplied Alpha
The color values of some bitmaps contain premultiplied alpha values, which
means that the rgb
values were multiplied with the alpha
value
before saving them. Since textures are created from bitmap data, they contain the values in
the same style. 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.
API overview
Constructor
VertexData
(
numVertices: Number
,
premultipliedAlpha: Boolean
= false
)
Create a new VertexData object with a specified number of vertices
Attributes
Public attributes
numVertices: Number |
The total number of vertices |
premultipliedAlpha: Boolean |
read-only
Indicates if the rgb values are stored premultiplied with the alpha value |
rawData: Vector.<Number> |
read-only
The raw vertex data; not a copy! |
tinted: Boolean |
read-only
Indicates if any vertices have a non-white color or are not fully opaque |
Constants
Constants
COLOR_OFFSET: Number |
static
The offset of color data (r, g, b, a) within a vertex |
ELEMENTS_PER_VERTEX: Number |
static
The total number of elements (Numbers) stored per vertex |
POSITION_OFFSET: Number |
static
The offset of position data (x, y) within a vertex |
TEXCOORD_OFFSET: Number |
static
The offset of texture coordinates (u, v) within a vertex |
Functions
Public functions
append ( data: VertexData ): Void |
Appends the vertices from another VertexData object |
clone ( vertexID: Number = 0 , numVertices: Number = ): VertexData |
Creates a duplicate of either the complete vertex data object, or of a subset |
copyTo ( targetData: VertexData , targetVertexID: Number = 0 , vertexID: Number = 0 , numVertices: Number = ): Void |
Copies the vertex data (or a range of it, defined by 'vertexID' and 'numVertices') of this instance to another vertex data object, starting at a certain index |
getAlpha ( vertexID: Number ): Number |
Returns the alpha value of a vertex in the range 0-1 |
getBounds ( transformationMatrix: Matrix = null , vertexID: Number = 0 , numVertices: Number = , resultRect: Rectangle = null ): Rectangle |
Calculates the bounds of the vertices, which are optionally transformed by a matrix |
getColor ( vertexID: Number ): Number |
Returns the RGB color of a vertex (no alpha) |
getPosition ( vertexID: Number ): Point |
Returns the position of a vertex |
getTexCoords ( vertexID: Number , texCoords: Point ): Void |
Returns the texture coordinates of a vertex in the range 0-1 |
scaleAlpha ( vertexID: Number , alpha: Number , numVertices: Number = 1 ): Void |
Multiplies the alpha value of subsequent vertices with a certain delta |
setAlpha ( vertexID: Number , alpha: Number ): Void |
Updates the alpha value of a vertex (range 0-1) |
setColor ( vertexID: Number , color: Number ): Void |
Updates the RGB color values of a vertex |
setPosition ( vertexID: Number , x: Number , y: Number ): Void |
Updates the position values of a vertex |
setPremultipliedAlpha ( value: Boolean , updateData: Boolean = true ): Void |
Changes the way alpha and color values are stored |
setTexCoords ( vertexID: Number , u: Number , v: Number ): Void |
Updates the texture coordinates of a vertex (range 0-1) |
setUniformAlpha ( alpha: Number ): Void |
Sets all vertices of the object to the same alpha values |
setUniformColor ( color: Number ): Void |
Sets all vertices of the object to the same color values |
transformVertex ( vertexID: Number , matrix: Matrix , numVertices: Number = 1 ): Void |
Transforms the position of subsequent vertices by multiplication with a transformation matrix |
translateVertex ( vertexID: Number , deltaX: Number , deltaY: Number ): Void |
Translate the position of a vertex by a certain offset |
Constructor
Attributes
premultipliedAlpha: Boolean
read-only
Indicates if the rgb values are stored premultiplied with the alpha value.
Constants
Functions
append ( data: VertexData ): Void
Appends the vertices from another VertexData object.
Parameters
data: VertexData |
clone ( vertexID: Number = 0 , numVertices: Number = ): VertexData
Creates a duplicate of either the complete vertex data object, or of a subset. To clone all vertices, set 'numVertices' to '-1'.
Parameters
vertexID: Number = 0 | |
numVertices: Number = |
copyTo ( targetData: VertexData , targetVertexID: Number = 0 , vertexID: Number = 0 , numVertices: Number = ): Void
Copies the vertex data (or a range of it, defined by 'vertexID' and 'numVertices') of this instance to another vertex data object, starting at a certain index.
Parameters
targetData: VertexData | |
targetVertexID: Number = 0 | |
vertexID: Number = 0 | |
numVertices: Number = |
getAlpha ( vertexID: Number ): Number
Returns the alpha value of a vertex in the range 0-1.
Parameters
vertexID: Number |
getBounds ( transformationMatrix: Matrix = null , vertexID: Number = 0 , numVertices: Number = , resultRect: Rectangle = null ): Rectangle
Calculates the bounds of the vertices, which are optionally transformed by a matrix. If you pass a 'resultRect', the result will be stored in this rectangle instead of creating a new object. To use all vertices for the calculation, set 'numVertices' to '-1'.
Parameters
transformationMatrix: Matrix = null | |
vertexID: Number = 0 | |
numVertices: Number = | |
resultRect: Rectangle = null |
getColor ( vertexID: Number ): Number
Returns the RGB color of a vertex (no alpha).
Parameters
vertexID: Number |
getFullTypeName
(): String
Inherited from Object
native
Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.
Returns
String | fully qualified type name of the Object. |
getPosition ( vertexID: Number ): Point
Returns the position of a vertex.
Parameters
vertexID: Number |
getTexCoords ( vertexID: Number , texCoords: Point ): Void
Returns the texture coordinates of a vertex in the range 0-1.
Parameters
vertexID: Number | |
texCoords: Point |
getType
(): Type
Inherited from Object
native
Gets the Type that describes the Object.
Returns
Type | The Type that describes the object. |
getTypeName
(): String
Inherited from Object
native
Gets the type name of the Object.
Returns
String | type name of the Object. |
scaleAlpha ( vertexID: Number , alpha: Number , numVertices: Number = 1 ): Void
Multiplies the alpha value of subsequent vertices with a certain delta.
Parameters
vertexID: Number | |
alpha: Number | |
numVertices: Number = 1 |
setAlpha ( vertexID: Number , alpha: Number ): Void
Updates the alpha value of a vertex (range 0-1).
Parameters
vertexID: Number | |
alpha: Number |
setColor ( vertexID: Number , color: Number ): Void
Updates the RGB color values of a vertex.
Parameters
vertexID: Number | |
color: Number |
setPosition ( vertexID: Number , x: Number , y: Number ): Void
Updates the position values of a vertex.
Parameters
vertexID: Number | |
x: Number | |
y: Number |
setPremultipliedAlpha ( value: Boolean , updateData: Boolean = true ): Void
Changes the way alpha and color values are stored. Updates all exisiting vertices.
Parameters
value: Boolean | |
updateData: Boolean = true |
setTexCoords ( vertexID: Number , u: Number , v: Number ): Void
Updates the texture coordinates of a vertex (range 0-1).
Parameters
vertexID: Number | |
u: Number | |
v: Number |
setUniformAlpha ( alpha: Number ): Void
Sets all vertices of the object to the same alpha values.
Parameters
alpha: Number |
setUniformColor ( color: Number ): Void
Sets all vertices of the object to the same color values.
Parameters
color: Number |
toString
(): String
Inherited from Object
native
Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().
Returns
String | String that described the Object. |