1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef _BASE_GROUND_DRAWER_H
4 #define _BASE_GROUND_DRAWER_H
5 
6 #include <map>
7 #include "MapDrawPassTypes.h"
8 #include "Rendering/GL/myGL.h"
9 #include "Rendering/GL/PBO.h"
10 #include "System/float3.h"
11 #include "System/type2.h"
12 
13 #define NUM_INFOTEXTURES (1 + 4 + 3)
14 
15 class CMetalMap;
16 class CHeightLinePalette;
17 class CBaseGroundTextures;
18 class CCamera;
19 
20 namespace GL {
21 	struct GeometryBuffer;
22 	struct LightHandler;
23 }
24 
25 class CBaseGroundDrawer
26 {
27 public:
28 	enum {
29 		COLOR_R = 2,
30 		COLOR_G = 1,
31 		COLOR_B = 0,
32 		COLOR_A = 3,
33 	};
34 	enum BaseGroundDrawMode {
35 		drawNormal   = 0,
36 		drawLos      = 1, // L (';' does not toggle it)
37 		drawMetal    = 2, // F4
38 		drawHeight   = 3, // F1
39 		drawPathTrav = 4, // F2
40 		drawPathHeat = 5, // not hotkeyed, command-only
41 		drawPathFlow = 6, // not hotkeyed, command-only
42 		drawPathCost = 7, // not hotkeyed, command-only
43 	};
44 
45 	CBaseGroundDrawer();
46 	virtual ~CBaseGroundDrawer();
47 	CBaseGroundDrawer(const CBaseGroundDrawer&) = delete; // no-copy
48 
49 	virtual void Draw(const DrawPass::e& drawPass) = 0;
DrawShadowPass()50 	virtual void DrawShadowPass() {}
51 
SetupBaseDrawPass()52 	virtual void SetupBaseDrawPass() {}
SetupReflDrawPass()53 	virtual void SetupReflDrawPass() {}
SetupRefrDrawPass()54 	virtual void SetupRefrDrawPass() {}
55 
56 	virtual void Update() = 0;
57 	virtual void UpdateSunDir() = 0;
58 
59 	virtual void IncreaseDetail() = 0;
60 	virtual void DecreaseDetail() = 0;
61 	virtual int GetGroundDetail(const DrawPass::e& drawPass = DrawPass::Normal) const = 0;
62 
SetDrawMode(BaseGroundDrawMode dm)63 	virtual void SetDrawMode(BaseGroundDrawMode dm) { drawMode = dm; }
SetDrawDeferredPass(bool)64 	virtual void SetDrawDeferredPass(bool) {}
ToggleMapBorder()65 	virtual bool ToggleMapBorder() { drawMapEdges = !drawMapEdges; return drawMapEdges; }
66 
GetLightHandler()67 	virtual const GL::LightHandler* GetLightHandler() const { return NULL; }
GetLightHandler()68 	virtual       GL::LightHandler* GetLightHandler()       { return NULL; }
GetGeometryBuffer()69 	virtual const GL::GeometryBuffer* GetGeometryBuffer() const { return NULL; }
GetGeometryBuffer()70 	virtual       GL::GeometryBuffer* GetGeometryBuffer()       { return NULL; }
71 
72 	void DrawTrees(bool drawReflection = false) const;
73 
74 	// Everything that deals with drawing extra textures on top
75 	void DisableExtraTexture();
76 	void SetHeightTexture();
77 	void SetMetalTexture();
78 	void TogglePathTexture(BaseGroundDrawMode);
79 	void ToggleLosTexture();
80 	void ToggleRadarAndJammer();
81 	bool UpdateExtraTexture(unsigned int texDrawMode);
82 
DrawExtraTex()83 	bool DrawExtraTex() const { return drawMode != drawNormal; }
DrawDeferred()84 	bool DrawDeferred() const { return drawDeferred; }
85 
UseAdvShading()86 	bool UseAdvShading() const { return advShading; }
WireFrameMode()87 	bool WireFrameMode() const { return wireframe; }
88 
UseAdvShadingRef()89 	bool& UseAdvShadingRef() { return advShading; }
WireFrameModeRef()90 	bool& WireFrameModeRef() { return wireframe; }
91 
92 
GetDrawMode()93 	BaseGroundDrawMode GetDrawMode() const { return drawMode; }
GetGroundTextures()94 	CBaseGroundTextures* GetGroundTextures() { return groundTextures; }
95 
GetInfoTexture(unsigned int idx)96 	GLuint GetInfoTexture(unsigned int idx) const { return infoTextureIDs[idx]; }
GetActiveInfoTexture()97 	GLuint GetActiveInfoTexture() const { return infoTextureIDs[drawMode]; }
98 
99 	int2 GetInfoTexSize() const;
100 
101 	void UpdateCamRestraints(CCamera* camera);
102 
103 public:
104 	bool drawRadarAndJammer;
105 	bool drawLineOfSight;
106 
107 	bool highResLosTex;
108 	bool highResInfoTex;
109 	bool highResInfoTexWanted;
110 
111 	float LODScaleReflection;
112 	float LODScaleRefraction;
113 	float LODScaleTerrainReflection;
114 
115 	int jamColor[3];
116 	int losColor[3];
117 	int radarColor[3];
118 	int alwaysColor[3];
119 
120 	static const int losColorScale = 10000;
121 
122 	int updateTextureState;
123 	int extraTextureUpdateRate;
124 
125 protected:
126 	BaseGroundDrawMode drawMode;
127 
128 	// note: first texture ID is always 0!
129 	GLuint infoTextureIDs[NUM_INFOTEXTURES];
130 
131 	PBO infoTexPBO;
132 
133 	CHeightLinePalette* heightLinePal;
134 	CBaseGroundTextures* groundTextures;
135 
136 	bool drawMapEdges;
137 	bool drawDeferred;
138 
139 	bool wireframe;
140 	bool advShading;
141 };
142 
143 #endif // _BASE_GROUND_DRAWER_H
144