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 
26 class C4FoWRegion;
27 class C4TargetFacet;
28 class C4FoWLight;
29 
34 {
35 public:
37 
38  void Fan();
39  void Quads();
40 
41  void AddVertex();
42  void Reset();
43 
44  const unsigned int* GetIndices() const { return &indices[0]; }
45  unsigned int GetNIndices() const { return indices.size(); }
46 
47 private:
48  void FinishPrimitive();
49 
50  enum Mode {
51  M_Fan,
52  M_Quads
53  };
54 
55  std::vector<unsigned int> indices; // TODO should be GLuint?
56  unsigned int begin_vertices{0};
57  unsigned int cur_vertices{0};
58  Mode mode{M_Fan};
59 };
60 
69 {
70 public:
71  C4FoWDrawStrategy() = default;
72  virtual ~C4FoWDrawStrategy() = default;
73 
74  // Drawing phases
75  enum DrawPhase {
81  } phase{P_None};
82 
84  virtual void Begin(const C4FoWRegion* region) = 0;
86  virtual void End(C4ShaderCall& call) { triangulator.Reset(); }
87 
88  virtual void DrawLightVertex(float x, float y) { triangulator.AddVertex(); }
89  virtual void DrawDarkVertex(float x, float y) { triangulator.AddVertex(); }
90 
92  virtual void BeginFan() { triangulator.Fan(); phase = P_Fan; };
94  virtual void EndFan() { };
95 
97  virtual void BeginFanMaxed() { triangulator.Quads(); phase = P_FanMaxed; };
99  virtual void EndFanMaxed() { };
100 
102  virtual void BeginFade() { triangulator.Quads(); phase = P_Fade; };
104  virtual void EndFade() { };
105 
107  virtual void BeginIntermediateFade() { triangulator.Fan(); phase = P_Intermediate; };
109  virtual void EndIntermediateFade() { };
110 
111 protected:
113 };
114 
118 {
119 public:
122 
123  void DrawLightVertex(float x, float y) override;
124  void DrawDarkVertex(float x, float y) override;
125  void Begin(const C4FoWRegion* region) override;
126  void End(C4ShaderCall& call) override;
127 
128 private:
129  void DrawVertex(float x, float y, bool shadeLight);
130 
131  static const float C4FoWSmooth;
132 
133  const C4FoWLight* light;
134  const C4FoWRegion* region;
135 
136  struct Vertex {
137  float x, y; // position in upper half of texture
138  float r1, g1, b1, a1; // color for first pass
139  float r2, g2, b2, a2; // color for second pass
140  float r3, g3, b3, a3; // color for third pass
141  };
142 
143  GLuint bo[2];
144  std::vector<Vertex> vertices;
145  unsigned int vbo_size;
146  unsigned int ibo_size;
147  unsigned int vaoids[3]; // Three VAOs for the three passes
148 };
149 
154 {
155 public:
156  C4FoWDrawWireframeStrategy(const C4FoWLight* light, const C4TargetFacet *screen);
157  ~C4FoWDrawWireframeStrategy() override;
158  // : light(light), screen(screen), vbo(0) {};
159 
160  void DrawLightVertex(float x, float y) override;
161  void DrawDarkVertex(float x, float y) override;
162  void Begin(const C4FoWRegion* region) override;
163  void End(C4ShaderCall& call) override;
164 
165 private:
166  struct Vertex {
167  float x, y;
168  float r, g, b, a;
169  };
170 
171  void DrawVertex(Vertex& vertex);
172 
173  const C4FoWLight* light;
174  const C4TargetFacet* screen;
175 
176  GLuint bo[2];
177  GLuint ibo;
178  std::vector<Vertex> vertices;
179  unsigned int vbo_size;
180  unsigned int ibo_size;
181  unsigned int vaoid;
182 };
183 
184 #endif
185 
186 #endif
void DrawLightVertex(float x, float y) override
void Begin(const C4FoWRegion *region) override
virtual void EndFade()
#define b
virtual void BeginFade()
void DrawDarkVertex(float x, float y) override
C4FoWDrawStrategy()=default
virtual ~C4FoWDrawStrategy()=default
#define a
void End(C4ShaderCall &call) override
virtual void DrawDarkVertex(float x, float y)
unsigned int GetNIndices() const
virtual void EndFan()
C4FoWDrawLightTextureStrategy(const C4FoWLight *light)
void DrawLightVertex(float x, float y) override
virtual void EndFanMaxed()
void DrawDarkVertex(float x, float y) override
C4FoWDrawTriangulator triangulator
virtual void EndIntermediateFade()
C4FoWDrawWireframeStrategy(const C4FoWLight *light, const C4TargetFacet *screen)
virtual void DrawLightVertex(float x, float y)
virtual void BeginFanMaxed()
const unsigned int * GetIndices() const
void End(C4ShaderCall &call) override
virtual void BeginFan()
virtual void End(C4ShaderCall &call)
virtual void BeginIntermediateFade()
void Begin(const C4FoWRegion *region) override
enum C4FoWDrawStrategy::DrawPhase P_None
virtual void Begin(const C4FoWRegion *region)=0