File: GrassDrawer.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (130 lines) | stat: -rw-r--r-- 2,618 bytes parent folder | download
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
122
123
124
125
126
127
128
129
130
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef GRASSDRAWER_H
#define GRASSDRAWER_H

#include <vector>

#include "Rendering/GL/VertexArray.h"
#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);
	unsigned char GetGrass(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()
			: va(128)
			, posX(0)
			, posZ(0)
			, lastSeen(0)
			, lastFar(0)
			, lastDist(0.0f)
		{}

		CVertexArray va;

		int posX;
		int posZ;

		int lastSeen;
		int lastFar;
		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;

	int blocksX;
	int blocksY;

	unsigned int grassDL;
	unsigned int grassBladeTex;
	unsigned int farTex;

	CVertexArray farnearVA;

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

	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 grassOff;
	bool updateBillboards;
	bool updateVisibility;
};

extern CGrassDrawer* grassDrawer;


#endif /* GRASSDRAWER_H */