2.4
Meshes

- 2.4.1. Overview
- 2.4.2. Attributes
- 2.4.3. Types

2.4.1
Overview
1
A mesh is a collection of vertices that make up the triangles that define a polyhedral object, allocated on the GPU upon which the renderer is executing. In practical terms, a mesh is a pair (a, i), where a is an OpenGL vertex buffer object consisting of vertices, an i is an OpenGL element buffer object consisting of indices that describe how to draw the mesh as a series of triangles.
2
The contents of a are mutable, but mesh references are considered to be immutable.
2.4.2
Attributes
1
A mesh consists of vertices. A vertex can be considered to be a value of a record type, with the fields of the record referred to as the attributes of the vertex. In the r2 package, an array buffer containing vertex data is specified using the array buffer types from jcanephora. The jcanephora package allows programmers to specify the exact types of array buffers, allows for the full inspection of type information at runtime, including the ability to reference attributes by name, and allows for type-safe modification of the contents of array buffers using an efficient cursor interface.
2
Each attribute within an array buffer is assigned a numeric attribute index. A numeric index is an arbitrary number between (including) 0 and some OpenGL implementation-defined upper limit. On modern graphics hardware, OpenGL allows for at least 16 numeric attributes. The indices are used to create an association between fields in the array buffer and shader inputs. For the sake of sanity and consistency, it is the responsibility of rendering systems using OpenGL to establish conventions for the assignment of numeric attribute indices in shaders and array buffers [12]. For example, many systems state that attribute 0 should be of type vec4 and should represent vertex positions. Shaders simply assume that data arriving on attribute input 0 represents position data, and programmers are expected to create meshes where attribute 0 points to the field within the array that contains position data.
3
The r2 package uses the following conventions everywhere:
2.4.2.4 Mesh attribute conventions

Index | Type | Description
--- | --- | ---
0 | vec3 | The object-space position of the vertex
1 | vec2 | The UV coordinates of the vertex
2 | vec3 | The object-space normal vector of the vertex
3 | vec4 | The tangent vector of the vertex

5
Batched instances are expected to use the following additional conventions:
2.4.2.6 Batched instance attribute conventions

Index | Type | Description
--- | --- | ---
4 | vec4 | Column 0 of the per-instance model matrix for batched instances.
5 | vec4 | Column 1 of the per-instance model matrix for batched instances.
6 | vec4 | Column 2 of the per-instance model matrix for batched instances.
7 | vec4 | Column 3 of the per-instance model matrix for batched instances.

2.4.3
Types
1
In the r2 package, the given attribute conventions are specified by the R2AttributeConventions type.

[12]
Naturally, as is standard with OpenGL, failing to associate the correct shader attributes with the correct vertex attributes results in silent failure and/or bizarre visual results.