C# Class Sparrow.Utils.VertexData

The VertexData 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.
Mostra file Open project: fmotagarcia/sparrow-sharp Class Usage Examples

Public Methods

Method Description
AlphaAt ( int index ) : float

Returns the alpha value of a vertex.

BoundsAfterTransformation ( Matrix matrix ) : Rectangle

Calculates the bounding rectangle of all vertices after being transformed by a matrix.

BoundsAfterTransformation ( Matrix matrix, int atIndex, int numVertices ) : Rectangle

Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.

ColorAt ( int index ) : uint

Returns the RGB color of a vertex (without premultiplied alpha).

CopyToVertexData ( VertexData target, bool copyColor, int atIndex ) : void

Copies the vertex data of this instance to another vertex data object, starting at a certain index.

CopyToVertexData ( VertexData target, bool copyColor, int atIndex, int numVertices ) : void

Copies a range of vertices of this instance to another vertex data object.

PositionAt ( int index ) : Point

Returns the position of a vertex.

ScaleAlphaBy ( float factor ) : void

Multiplies all alpha values with a certain factor.

ScaleAlphaBy ( float factor, int index, int numVertices ) : void

Multiplies a range of alpha values with a certain factor.

SetAlpha ( float alpha ) : void

Updates the alpha value of all vertices.

SetAlpha ( float alpha, int atIndex ) : void

Updates the alpha value of a vertex.

SetColor ( uint color ) : void

Updates the color of all vertexes. The method always expects non-premultiplied alpha values.

SetColor ( uint color, float alpha ) : void

Updates the color of all vertexes. The method always expects non-premultiplied alpha values.

SetColor ( uint color, float alpha, int atIndex ) : void

Updates the color of a vertex. The method always expects non-premultiplied alpha values.

SetColor ( uint color, int atIndex ) : void

Updates the color of a vertex. The method always expects non-premultiplied alpha values.

SetPosition ( Point position, int atIndex ) : void

Updates the position of a vertex.

SetPosition ( float x, float y, int atIndex ) : void

Updates the position of a vertex.

SetPremultipliedAlpha ( bool value, bool updateVertices ) : void

Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.

SetTexCoords ( Point texCoords, int atIndex ) : void

Updates the texture coordinates of a vertex.

SetTexCoords ( float x, float y, int atIndex ) : void

Updates the texture coordinates of a vertex.

TexCoordsAt ( int index ) : Point

Returns the texture coordinates of a vertex.

TransformVertices ( Matrix matrix, int atIndex, int numVertices ) : void

Transforms the positions of subsequent vertices by multiplication with a transformation matrix

VertexData ( int numVertices, bool premultipliedAlpha = false ) : System

Initializes a VertexData instance with a certain size.

Method Details

AlphaAt() public method

Returns the alpha value of a vertex.
public AlphaAt ( int index ) : float
index int
return float

BoundsAfterTransformation() public method

Calculates the bounding rectangle of all vertices after being transformed by a matrix.
public BoundsAfterTransformation ( Matrix matrix ) : Rectangle
matrix Matrix
return Sparrow.Geom.Rectangle

BoundsAfterTransformation() public method

Calculates the bounding rectangle of subsequent vertices after being transformed by a matrix.
public BoundsAfterTransformation ( Matrix matrix, int atIndex, int numVertices ) : Rectangle
matrix Matrix
atIndex int
numVertices int
return Sparrow.Geom.Rectangle

ColorAt() public method

Returns the RGB color of a vertex (without premultiplied alpha).
public ColorAt ( int index ) : uint
index int
return uint

CopyToVertexData() public method

Copies the vertex data of this instance to another vertex data object, starting at a certain index.
public CopyToVertexData ( VertexData target, bool copyColor, int atIndex ) : void
target VertexData
copyColor bool
atIndex int
return void

CopyToVertexData() public method

Copies a range of vertices of this instance to another vertex data object.
public CopyToVertexData ( VertexData target, bool copyColor, int atIndex, int numVertices ) : void
target VertexData
copyColor bool
atIndex int
numVertices int
return void

PositionAt() public method

Returns the position of a vertex.
public PositionAt ( int index ) : Point
index int
return Point

ScaleAlphaBy() public method

Multiplies all alpha values with a certain factor.
public ScaleAlphaBy ( float factor ) : void
factor float
return void

ScaleAlphaBy() public method

Multiplies a range of alpha values with a certain factor.
public ScaleAlphaBy ( float factor, int index, int numVertices ) : void
factor float
index int
numVertices int
return void

SetAlpha() public method

Updates the alpha value of all vertices.
public SetAlpha ( float alpha ) : void
alpha float
return void

SetAlpha() public method

Updates the alpha value of a vertex.
public SetAlpha ( float alpha, int atIndex ) : void
alpha float
atIndex int
return void

SetColor() public method

Updates the color of all vertexes. The method always expects non-premultiplied alpha values.
public SetColor ( uint color ) : void
color uint
return void

SetColor() public method

Updates the color of all vertexes. The method always expects non-premultiplied alpha values.
public SetColor ( uint color, float alpha ) : void
color uint
alpha float
return void

SetColor() public method

Updates the color of a vertex. The method always expects non-premultiplied alpha values.
public SetColor ( uint color, float alpha, int atIndex ) : void
color uint
alpha float
atIndex int
return void

SetColor() public method

Updates the color of a vertex. The method always expects non-premultiplied alpha values.
public SetColor ( uint color, int atIndex ) : void
color uint
atIndex int
return void

SetPosition() public method

Updates the position of a vertex.
public SetPosition ( Point position, int atIndex ) : void
position Point
atIndex int
return void

SetPosition() public method

Updates the position of a vertex.
public SetPosition ( float x, float y, int atIndex ) : void
x float
y float
atIndex int
return void

SetPremultipliedAlpha() public method

Changes the way alpha and color values are stored. Optionally, all exisiting vertices are updated.
public SetPremultipliedAlpha ( bool value, bool updateVertices ) : void
value bool
updateVertices bool
return void

SetTexCoords() public method

Updates the texture coordinates of a vertex.
public SetTexCoords ( Point texCoords, int atIndex ) : void
texCoords Point
atIndex int
return void

SetTexCoords() public method

Updates the texture coordinates of a vertex.
public SetTexCoords ( float x, float y, int atIndex ) : void
x float
y float
atIndex int
return void

TexCoordsAt() public method

Returns the texture coordinates of a vertex.
public TexCoordsAt ( int index ) : Point
index int
return Point

TransformVertices() public method

Transforms the positions of subsequent vertices by multiplication with a transformation matrix
public TransformVertices ( Matrix matrix, int atIndex, int numVertices ) : void
matrix Matrix
atIndex int
numVertices int
return void

VertexData() public method

Initializes a VertexData instance with a certain size.
public VertexData ( int numVertices, bool premultipliedAlpha = false ) : System
numVertices int
premultipliedAlpha bool
return System