OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 34 of file C4FoWDrawStrategy.h.

Constructor & Destructor Documentation

C4FoWDrawTriangulator::C4FoWDrawTriangulator ( )

Definition at line 26 of file C4FoWDrawStrategy.cpp.

26  :
27  mode(M_Fan), cur_vertices(0), begin_vertices(0)
28 {
29 }

Member Function Documentation

void C4FoWDrawTriangulator::AddVertex ( )

Definition at line 64 of file C4FoWDrawStrategy.cpp.

Referenced by C4FoWDrawStrategy::DrawDarkVertex(), and C4FoWDrawStrategy::DrawLightVertex().

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

Here is the caller graph for this function:

void C4FoWDrawTriangulator::Fan ( )

Definition at line 31 of file C4FoWDrawStrategy.cpp.

Referenced by C4FoWDrawStrategy::BeginFan(), and C4FoWDrawStrategy::BeginIntermediateFade().

32 {
33  FinishPrimitive();
34  mode = M_Fan;
35 }

Here is the caller graph for this function:

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

Definition at line 45 of file C4FoWDrawStrategy.h.

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

45 { return &indices[0]; }

Here is the caller graph for this function:

unsigned int C4FoWDrawTriangulator::GetNIndices ( ) const
inline

Definition at line 46 of file C4FoWDrawStrategy.h.

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

46 { return indices.size(); }

Here is the caller graph for this function:

void C4FoWDrawTriangulator::Quads ( )

Definition at line 37 of file C4FoWDrawStrategy.cpp.

Referenced by C4FoWDrawStrategy::BeginFade(), and C4FoWDrawStrategy::BeginFanMaxed().

38 {
39  FinishPrimitive();
40  mode = M_Quads;
41 }

Here is the caller graph for this function:

void C4FoWDrawTriangulator::Reset ( )

Definition at line 103 of file C4FoWDrawStrategy.cpp.

Referenced by C4FoWDrawStrategy::End().

104 {
105  FinishPrimitive();
106  begin_vertices = 0;
107 
108  // Assume this keeps capacity
109  indices.resize(0);
110 }

Here is the caller graph for this function:


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