OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4FoWDrawStrategy.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2014-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef C4FOWDRAWSTRATEGY_H
17 #define C4FOWDRAWSTRATEGY_H
18 
20 
21 #ifndef USE_CONSOLE
22 
23 #include "graphics/C4DrawGL.h"
24 #include "graphics/C4Shader.h"
25 #include <list>
26 
27 class C4FoWRegion;
28 class C4TargetFacet;
29 class C4FoWLight;
30 
35 {
36 public:
38 
39  void Fan();
40  void Quads();
41 
42  void AddVertex();
43  void Reset();
44 
45  const unsigned int* GetIndices() const { return &indices[0]; }
46  unsigned int GetNIndices() const { return indices.size(); }
47 
48 private:
49  void FinishPrimitive();
50 
51  enum Mode {
52  M_Fan,
53  M_Quads
54  };
55 
56  std::vector<unsigned int> indices; // TODO should be GLuint?
57  unsigned int begin_vertices;
58  unsigned int cur_vertices;
59  Mode mode;
60 };
61 
70 {
71 public:
73  virtual ~C4FoWDrawStrategy() {}
74 
75  // Drawing phases
76  enum DrawPhase {
82  } phase;
83 
85  virtual void Begin(const C4FoWRegion* region) = 0;
87  virtual void End(C4ShaderCall& call) { triangulator.Reset(); }
88 
89  virtual void DrawLightVertex(float x, float y) { triangulator.AddVertex(); }
90  virtual void DrawDarkVertex(float x, float y) { triangulator.AddVertex(); }
91 
93  virtual void BeginFan() { triangulator.Fan(); phase = P_Fan; };
95  virtual void EndFan() { };
96 
98  virtual void BeginFanMaxed() { triangulator.Quads(); phase = P_FanMaxed; };
100  virtual void EndFanMaxed() { };
101 
103  virtual void BeginFade() { triangulator.Quads(); phase = P_Fade; };
105  virtual void EndFade() { };
106 
110  virtual void EndIntermediateFade() { };
111 
112 protected:
114 };
115 
119 {
120 public:
123 
124  virtual void DrawLightVertex(float x, float y);
125  virtual void DrawDarkVertex(float x, float y);
126  virtual void Begin(const C4FoWRegion* region);
127  virtual void End(C4ShaderCall& call);
128 
129 private:
130  void DrawVertex(float x, float y, bool shadeLight);
131 
132  static const float C4FoWSmooth;
133 
134  const C4FoWLight* light;
135  const C4FoWRegion* region;
136 
137  struct Vertex {
138  float x, y; // position in upper half of texture
139  float r1, g1, b1, a1; // color for first pass
140  float r2, g2, b2, a2; // color for second pass
141  float r3, g3, b3, a3; // color for third pass
142  };
143 
144  GLuint bo[2];
145  std::vector<Vertex> vertices;
146  unsigned int vbo_size;
147  unsigned int ibo_size;
148  unsigned int vaoids[3]; // Three VAOs for the three passes
149 };
150 
155 {
156 public:
157  C4FoWDrawWireframeStrategy(const C4FoWLight* light, const C4TargetFacet *screen);
158  virtual ~C4FoWDrawWireframeStrategy();
159  // : light(light), screen(screen), vbo(0) {};
160 
161  virtual void DrawLightVertex(float x, float y);
162  virtual void DrawDarkVertex(float x, float y);
163  virtual void Begin(const C4FoWRegion* region);
164  virtual void End(C4ShaderCall& call);
165 
166 private:
167  struct Vertex {
168  float x, y;
169  float r, g, b, a;
170  };
171 
172  void DrawVertex(Vertex& vertex);
173 
174  const C4FoWLight* light;
175  const C4TargetFacet* screen;
176 
177  GLuint bo[2];
178  GLuint ibo;
179  std::vector<Vertex> vertices;
180  unsigned int vbo_size;
181  unsigned int ibo_size;
182  unsigned int vaoid;
183 };
184 
185 #endif
186 
187 #endif
virtual void EndFade()
#define b
virtual void BeginFade()
enum C4FoWDrawStrategy::DrawPhase phase
#define a
virtual void DrawDarkVertex(float x, float y)
virtual void DrawDarkVertex(float x, float y)
unsigned int GetNIndices() const
virtual void EndFan()
C4FoWDrawLightTextureStrategy(const C4FoWLight *light)
virtual void Begin(const C4FoWRegion *region)
virtual void DrawDarkVertex(float x, float y)
virtual void EndFanMaxed()
C4FoWDrawTriangulator triangulator
virtual void EndIntermediateFade()
C4FoWDrawWireframeStrategy(const C4FoWLight *light, const C4TargetFacet *screen)
virtual void DrawLightVertex(float x, float y)
virtual ~C4FoWDrawStrategy()
virtual void DrawLightVertex(float x, float y)
virtual void BeginFanMaxed()
const unsigned int * GetIndices() const
virtual void BeginFan()
virtual void End(C4ShaderCall &call)
virtual void DrawLightVertex(float x, float y)
virtual void Begin(const C4FoWRegion *region)
virtual void End(C4ShaderCall &call)
virtual void BeginIntermediateFade()
virtual void End(C4ShaderCall &call)
virtual void Begin(const C4FoWRegion *region)=0