Difference between revisions of "SpriteBatch:attachAttribute"

(Created page)
 
m
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
Attaches a per-vertex attribute from a [[Mesh]] onto this SpriteBatch, for use when drawing. This can be combined with a [[Shader]] to augment a SpriteBatch with per-vertex or additional per-sprite information instead of just having per-sprite colors.
 
Attaches a per-vertex attribute from a [[Mesh]] onto this SpriteBatch, for use when drawing. This can be combined with a [[Shader]] to augment a SpriteBatch with per-vertex or additional per-sprite information instead of just having per-sprite colors.
  
Each sprite in a SpriteBatch has 4 vertices in the following order: top-left, bottom-left, top-right, bottom-right. The index returned by [[SpriteBatch:add]] (and used by [[SpriteBatch:set]]) can be multiplied by 4 to determine the first vertex in a specific sprite. A Mesh must have at least 4 * [[SpriteBatch:getBufferSize]] vertices in order to be attachable to a SpriteBatch.
+
Each sprite in a SpriteBatch has 4 vertices in the following order: top-left, bottom-left, top-right, bottom-right. The index returned by [[SpriteBatch:add]] (and used by [[SpriteBatch:set]]) can used to determine the first vertex of a specific sprite with the formula <code>1 + 4 * ( id - 1 )</code>.
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 18: Line 18:
  
 
Custom named attributes can be accessed in a [[Shader|vertex shader]] by declaring them as <code>attribute vec4 MyCustomAttributeName;</code> at the top-level of the vertex shader code. The name must match what was specified in the Mesh's vertex format and in the <code>name</code> argument of [[SpriteBatch:attachAttribute]].
 
Custom named attributes can be accessed in a [[Shader|vertex shader]] by declaring them as <code>attribute vec4 MyCustomAttributeName;</code> at the top-level of the vertex shader code. The name must match what was specified in the Mesh's vertex format and in the <code>name</code> argument of [[SpriteBatch:attachAttribute]].
 +
 +
A Mesh must have at least 4 * [[SpriteBatch:getBufferSize]] vertices in order to be attachable to a SpriteBatch.
  
 
== See Also ==
 
== See Also ==

Latest revision as of 06:37, 2 December 2017

Available since LÖVE 0.10.0
This function is not supported in earlier versions.

Attaches a per-vertex attribute from a Mesh onto this SpriteBatch, for use when drawing. This can be combined with a Shader to augment a SpriteBatch with per-vertex or additional per-sprite information instead of just having per-sprite colors.

Each sprite in a SpriteBatch has 4 vertices in the following order: top-left, bottom-left, top-right, bottom-right. The index returned by SpriteBatch:add (and used by SpriteBatch:set) can used to determine the first vertex of a specific sprite with the formula 1 + 4 * ( id - 1 ).

Function

Synopsis

SpriteBatch:attachAttribute( name, mesh )

Arguments

string name
The name of the vertex attribute to attach.
Mesh mesh
The Mesh to get the vertex attribute from.

Returns

Nothing.

Notes

If a Mesh wasn't created with a custom vertex format, it will have 3 vertex attributes named VertexPosition, VertexTexCoord, and VertexColor. If vertex attributes with those names are attached to the SpriteBatch, it will override the SpriteBatch's sprite positions, texture coordinates, and sprite colors, respectively.

Custom named attributes can be accessed in a vertex shader by declaring them as attribute vec4 MyCustomAttributeName; at the top-level of the vertex shader code. The name must match what was specified in the Mesh's vertex format and in the name argument of SpriteBatch:attachAttribute.

A Mesh must have at least 4 * SpriteBatch:getBufferSize vertices in order to be attachable to a SpriteBatch.

See Also

Other Languages