OpenClonk
C4FoWDrawTriangulator Class Reference

#include <C4FoWDrawStrategy.h>

Public Member Functions

 C4FoWDrawTriangulator ()
 
void Fan ()
 
void Quads ()
 
void AddVertex ()
 
void Reset ()
 
const unsigned int * GetIndices () const
 
unsigned int GetNIndices () const
 

Detailed Description

This class decomposes Triangle fans and quads into individual triangles. This is used to so that all FoW elements can be drawn as triangles in a single glDrawElements call.

Definition at line 33 of file C4FoWDrawStrategy.h.

Constructor & Destructor Documentation

◆ C4FoWDrawTriangulator()

C4FoWDrawTriangulator::C4FoWDrawTriangulator ( )
default

Member Function Documentation

◆ AddVertex()

void C4FoWDrawTriangulator::AddVertex ( )

Definition at line 61 of file C4FoWDrawStrategy.cpp.

62 {
63  switch (mode)
64  {
65  case M_Fan:
66  ++cur_vertices;
67  if (cur_vertices == 3)
68  {
69  indices.push_back(begin_vertices);
70  indices.push_back(begin_vertices + 1);
71  indices.push_back(begin_vertices + 2);
72  }
73  else if (cur_vertices > 3)
74  {
75  indices.push_back(begin_vertices);
76  indices.push_back(begin_vertices + cur_vertices - 2);
77  indices.push_back(begin_vertices + cur_vertices - 1);
78  }
79  break;
80  case M_Quads:
81  ++cur_vertices;
82  if (cur_vertices % 4 == 0)
83  {
84  // upper tri
85  indices.push_back(begin_vertices + cur_vertices - 4);
86  indices.push_back(begin_vertices + cur_vertices - 3);
87  indices.push_back(begin_vertices + cur_vertices - 2);
88 
89  // lower tri
90  indices.push_back(begin_vertices + cur_vertices - 4);
91  indices.push_back(begin_vertices + cur_vertices - 2);
92  indices.push_back(begin_vertices + cur_vertices - 1);
93  }
94  break;
95  default:
96  assert(false);
97  }
98 }

◆ Fan()

void C4FoWDrawTriangulator::Fan ( )

Definition at line 28 of file C4FoWDrawStrategy.cpp.

29 {
30  FinishPrimitive();
31  mode = M_Fan;
32 }

◆ GetIndices()

const unsigned int* C4FoWDrawTriangulator::GetIndices ( ) const
inline

Definition at line 44 of file C4FoWDrawStrategy.h.

Referenced by C4FoWDrawLightTextureStrategy::End(), and C4FoWDrawWireframeStrategy::End().

44 { return &indices[0]; }
Here is the caller graph for this function:

◆ GetNIndices()

unsigned int C4FoWDrawTriangulator::GetNIndices ( ) const
inline

Definition at line 45 of file C4FoWDrawStrategy.h.

Referenced by C4FoWDrawLightTextureStrategy::End(), and C4FoWDrawWireframeStrategy::End().

45 { return indices.size(); }
Here is the caller graph for this function:

◆ Quads()

void C4FoWDrawTriangulator::Quads ( )

Definition at line 34 of file C4FoWDrawStrategy.cpp.

35 {
36  FinishPrimitive();
37  mode = M_Quads;
38 }

◆ Reset()

void C4FoWDrawTriangulator::Reset ( )

Definition at line 100 of file C4FoWDrawStrategy.cpp.

101 {
102  FinishPrimitive();
103  begin_vertices = 0;
104 
105  // Assume this keeps capacity
106  indices.resize(0);
107 }

The documentation for this class was generated from the following files: