File: GrassDrawer.h

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (121 lines) | stat: -rw-r--r-- 2,505 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef GRASSDRAWER_H
#define GRASSDRAWER_H

#include <vector>
#include "System/float3.h"
#include "System/EventClient.h"

namespace Shader {
	struct IProgramObject;
}

class CVertexArray;
struct VA_TYPE_TN;


class CGrassDrawer : public CEventClient
{
public:
	CGrassDrawer();
	~CGrassDrawer();

	void Draw();
	void DrawShadow();
	void AddGrass(const float3& pos);
	void ResetPos(const float3& pos);
	void RemoveGrass(const float3& pos);

	void ChangeDetail(int detail);

	/// @see ConfigHandler::ConfigNotifyCallback
	void ConfigNotify(const std::string& key, const std::string& value);

public:
	// EventClient
	void UnsyncedHeightMapUpdate(const SRectangle& rect);
	void Update();

public:
	struct InviewNearGrass {
		int x;
		int y;
		float dist;
	};
	struct GrassStruct {
		GrassStruct()
			: posX(0)
			, posZ(0)
			, va(nullptr)
			, lastSeen(0)
			, lastDist(0.f)
		{}
		~GrassStruct();

		int posX, posZ;
		CVertexArray* va;
		int lastSeen;
		float lastDist;
	};

	enum GrassShaderProgram {
		GRASS_PROGRAM_NEAR        = 0,
		GRASS_PROGRAM_DIST        = 1,
		GRASS_PROGRAM_SHADOW_GEN  = 2,
		GRASS_PROGRAM_LAST        = 3
	};

protected:
	void LoadGrassShaders();
	void CreateGrassBladeTex(unsigned char* buf);
	void CreateFarTex();
	void CreateGrassDispList(int listNum);

	void EnableShader(const GrassShaderProgram type);
	void SetupGlStateNear();
	void ResetGlStateNear();
	void SetupGlStateFar();
	void ResetGlStateFar();
	void DrawNear(const std::vector<InviewNearGrass>& inviewGrass);
	void DrawFarBillboards(const std::vector<GrassStruct*>& inviewGrass);
	void DrawNearBillboards(const std::vector<InviewNearGrass>& inviewNearGrass);
	void DrawBillboard(const int x, const int y, const float dist, VA_TYPE_TN* va_tn);

	void ResetPos(const int grassBlockX, const int grassBlockZ);

protected:
	friend class CGrassBlockDrawer;

	bool grassOff;

	int blocksX;
	int blocksY;

	unsigned int grassDL;
	unsigned int grassBladeTex;
	unsigned int farTex;
	CVertexArray* farnearVA;

	std::vector<Shader::IProgramObject*> grassShaders;
	Shader::IProgramObject* grassShader;

	float maxGrassDist;
	float maxDetailedDist;
	int detailedBlocks;
	int numTurfs;
	int strawPerTurf;

	float3 oldCamPos;
	float3 oldCamDir;
	int lastVisibilityUpdate;
	bool updateBillboards;

	std::vector<GrassStruct> grass;
	unsigned char* grassMap;
};

extern CGrassDrawer* grassDrawer; //FIXME can be nullptr


#endif /* GRASSDRAWER_H */