# TriangleMode

## Description

`enum` `Tinman.Terrain.Kernel.TriangleMode`

Enumeration of triangle modes.

## Public / Constants

### TriangleStrip

`public` `constant` `TriangleStrip` → `(0:int32)`

The triangulation process will create a continuous triangle strip (around 1.61 indices per triangle).

The TriangleStrip mode yields graphics primitives of type Primitive.TriangleStrip, which can be rendered with a IPrimitiveRenderer, using direct draw calls.

Fun fact: the average ratio of indices per triangle approximates the value of the 'golden ratio':
https://en.wikipedia.org/wiki/Golden_ratio

### TriangleList

`public` `constant` `TriangleList` → `(1:int32)`

The triangulation process will create a continuous triangle list (3 indices per triangle).

The TriangleList mode yields graphics primitives of type Primitive.TriangleList, which can be rendered with a IPrimitiveRenderer, using direct draw calls.

### TriangleTerminal

`public` `constant` `TriangleTerminal` → `(2:int32)`

The triangulation process will create a continuous list of terminal triangle codes (around 0.25 indices per triangle).

A terminal triangle does not have a vertex on its spine CV (see XDag). A terminal triangle code has the following layout:

```bits [0.. 1]  : child index of C in V (LL=0, LR=1, RL=2, RR=3)
bits [1.. 2]  : child index of V in P (LL=0, LR=1, RL=2, RR=3)
bits [3.. 3]  : triangulate (V,P,C)?
bits [4.. 4]  : triangulate (V,C,G/A)?
bits [5.. 5]  : flip triangle winding?
bits [6..31]  : index of vertex P

V
/|.
/ | .
/  |  .
/   |   .
/    |    .
/     |     .
/......|.......
P       C      G/A```

The following figure shows the possible combinations for triangulation on the GPU:

```               V.?L == C                                   V.?R == C
V                                           V
/|\                                         /|\
/ | \                                       / | \
LL /  |  \ LR                               RL /  |  \ RR
/   |   \                                   /   |   \
RL /|\  |  /|\ LR                           RL /|\  |  /|\ LR
/ | \ | / | \                               / | \ | / | \
/_\|__\|/__|/_\                             /_\|__\|/__|/_\
P   LR  C  RL  G/A                         G/A  LR  C  RL   P

V.LL == C             V.RL == C             V.RR == C             V.LR == C
V                     V                     V                     V
/|\                   /|\                   /|\                   /|\
/ | \                 / | \                 / | \                 / | \
LL /  |  \ LR         LL /  |  \ LR         RL /  |  \ RR         RL /  |  \ RR
/   |   \             /   |   \             /   |   \             /   |   \
RL /|\  |  /|\ LR     RL /|\  |  /|\ LR     RL /|\  |  /|\ LR     RL /|\  |  /|\ LR
/ | \ | / | \         / | \ | / | \         / | \ | / | \         / | \ | / | \
/_\|__\|/__|/_\       /_\|__\|/__|/_\       /_\|__\|/__|/_\       /_\|__\|/__|/_\
P   LR  C  RL   G     P   LR  C  RL   A     G   LR  C  RL   P     A   LR  C  RL   P```

The TriangleTerminal mode yields graphics primitives of type Primitive.TriangleList, which can be rendered with a IPrimitiveRenderer using indirect draw calls (see TriangulationBatch.Indirect).

### SectorList

`public` `constant` `SectorList` → `(3:int32)`

The triangulation process will create a continuous sequence of sector codes, each representing a mesh sector resp. leaf quadrant (1 index per sector resp. quadrant).

Sector codes have the following layout:

```bits [0.. 2] : index of leaf quadrant Q in the range [0..3] or 4 for whole sector
bits [3.. 3] : flip triangle winding?
bits [4..31] : index of vertex V

V.L = L    V.LL.LL = Q0
V.R = R    V.LL.LR = Q1
V.G = G    V.RL.LL = Q2
V.A = A    V.RL.LR = Q3

A--------RL-------R
|        |        |
|        |        |
|   Q3   |   Q2   |
|        |        |
|        |        |
LR-------V-------RR
|        |        |
|        |        |
|   Q0   |   Q1   |
|        |        |
|        |        |
L--------LL-------G```

The TriangleTerminal mode yields graphics primitives of type Primitive.TriangleList, which can be rendered with a IPrimitiveRenderer using indirect draw calls (see TriangulationBatch.Indirect).