File: DecalsDrawerGL4.h

package info (click to toggle)
spring 98.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,928 kB
  • ctags: 60,665
  • sloc: cpp: 356,167; ansic: 39,434; python: 12,228; java: 12,203; awk: 5,856; sh: 1,719; xml: 997; perl: 405; php: 253; objc: 194; makefile: 72; sed: 2
file content (154 lines) | stat: -rw-r--r-- 3,492 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef SHADER_GROUND_DECAL_DRAWER_H
#define SHADER_GROUND_DECAL_DRAWER_H

#include <list>
#include <vector>

#include "Rendering/Env/IGroundDecalDrawer.h"
#include "Rendering/GL/myGL.h"
#include "Rendering/GL/VBO.h"
#include "System/EventClient.h"
#include "Sim/Projectiles/ExplosionListener.h"
#include "System/float3.h"
#include "System/float4.h"
#include "System/type2.h"

#if !defined(GL_VERSION_4_0) || HEADLESS
	class CDecalsDrawerGL4: public IGroundDecalDrawer
	{
	public:
		CDecalsDrawerGL4();
		virtual ~CDecalsDrawerGL4() {}

		virtual void Draw() {}
		virtual void Update() {}

		virtual void ForceRemoveSolidObject(CSolidObject* object) {}
		virtual void RemoveSolidObject(CSolidObject* object, GhostSolidObject* gb) {}
		virtual void GhostDestroyed(GhostSolidObject* gb) {}
		virtual void GhostCreated(CSolidObject* object, GhostSolidObject* gb) {}
	};
#else

namespace Shader {
	struct IProgramObject;
}


class CDecalsDrawerGL4: public IGroundDecalDrawer, public CEventClient, public IExplosionListener
{
public:
	CDecalsDrawerGL4();
	virtual ~CDecalsDrawerGL4();

	virtual void Draw();
	virtual void Update() {}

	virtual void ForceRemoveSolidObject(CSolidObject* object) {/*FIXME*/}
	virtual void RemoveSolidObject(CSolidObject* object, GhostSolidObject* gb) {/*FIXME*/}
	virtual void GhostDestroyed(GhostSolidObject* gb) {/*FIXME*/}
	virtual void GhostCreated(CSolidObject* object, GhostSolidObject* gb) {/*FIXME*/}

	virtual void ExplosionOccurred(const CExplosionEvent&);

private:
	void AddExplosion(float3 pos, float damage, float radius, bool addScar);

public:
	bool WantsEvent(const std::string& eventName) {
		return
			   (eventName == "UnitCreated")
			|| (eventName == "UnitDestroyed")
			|| (eventName == "ViewResize")
		;
		/*return
			(eventName == "UnitMoved") ||
			(eventName == "SunChanged");*/
	}
	bool GetFullRead() const { return true; }
	int GetReadAllyTeam() const { return AllAccessTeam; }

	void UnitCreated(const CUnit* unit, const CUnit* builder);
	void UnitDestroyed(const CUnit* unit, const CUnit* attacker);

	void ViewResize();

	//void SunChanged(const float3& sunDir);
	//void UnitMoved(const CUnit*);

private:
	struct Decal {
		Decal()
			: pos(ZeroVector)
			, size(0.0f, 0.0f)
			, rot(0.0f)
			, alpha(1.0f)
			, texOffsets(0.0f, 0.0f, 0.0f, 0.0f)
		{}

		float3 pos;
		float2 size;
		float rot;
		float alpha;
		float4 texOffsets;
	};

	struct BuildingGroundDecal { //FIXME
		BuildingGroundDecal()
			: owner(NULL)
			, gbOwner(NULL)
			, size(0,0)
			, facing(-1)
			, pos(ZeroVector)
			, radius(0.0f)
			, alpha(1.0f)
			, alphaFalloff(1.0f)
		{}

		const CUnit* owner;
		const GhostSolidObject* gbOwner;
		int2 size;
		int facing;
		float3 pos;
		float radius;
		float alpha;
		float alphaFalloff;
	};

private:
	void LoadShaders();
	void GenerateAtlasTexture();

	void CreateBoundingBoxVBOs();
	void CreateStructureVBOs();

	void UpdateVisibilityVBO();
	void UpdateDecalsVBO();

	void DrawDecals();
	//void DrawTracks();

private:
	VBO vboVertices;
	VBO vboIndices;
	VBO uboDecalsStructures;
	VBO uboGroundLighting;
	VBO vboVisibilityFeeback;

	std::vector<Decal*> decals; //FIXME use mt-safe container!
	size_t lastUpdate;

	size_t maxDecals;

	GLuint tbo;
	GLuint depthTex;
	GLuint atlasTex;
	//GLuint decalShader;
	Shader::IProgramObject* decalShader;
};

#endif // !defined(GL_VERSION_4_0) || HEADLESS

#endif // SHADER_GROUND_DECAL_DRAWER_H