{{newin|[[0.10.0]]|100|type=function}}
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 <code>1 + 4 * ( id - 1 )</code>.
== Function ==
=== Synopsis ===
<source lang="lua">
SpriteBatch:attachAttribute( name, mesh )
</source>
=== Arguments ===
{{param|string|name|The name of the vertex attribute to attach.}}
{{param|Mesh|mesh|The Mesh to get the vertex attribute from.}}
=== Returns ===
Nothing.

== Notes ==
If a [[Mesh]] wasn't [[love.graphics.newMesh|created]] with a custom vertex format, it will have 3 vertex attributes named <code>VertexPosition</code>, <code>VertexTexCoord</code>, and <code>VertexColor</code>. 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 [[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 ==
* [[parent::SpriteBatch]]
* [[Mesh]]
* [[Mesh:getVertexFormat]]
* [[love.graphics.draw]]
[[Category:Functions]]
{{#set:Description=Attaches a per-vertex attribute from a [[Mesh]] onto this SpriteBatch, for use when drawing.}}
== Other Languages ==
{{i18n|SpriteBatch:attachAttribute}}