1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef PROJECTILE_DRAWER_HDR
4 #define PROJECTILE_DRAWER_HDR
5 
6 #include "Rendering/GL/myGL.h"
7 #include <list>
8 #include <set>
9 
10 #include "lib/gml/ThreadSafeContainers.h"
11 #include "Rendering/GL/FBO.h"
12 #include "Sim/Projectiles/ProjectileFunctors.h"
13 #include "System/EventClient.h"
14 
15 class CTextureAtlas;
16 struct AtlasedTexture;
17 class CGroundFlash;
18 struct FlyingPiece;
19 class IWorldObjectModelRenderer;
20 class LuaTable;
21 
22 
23 typedef ThreadListSimRender<std::list<CGroundFlash*>, std::set<CGroundFlash*>, CGroundFlash*> GroundFlashContainer;
24 typedef ThreadListSimRender<std::set<FlyingPiece*, FlyingPieceComparator>, void, FlyingPiece*> FlyingPieceContainer;
25 
26 
27 class CProjectileDrawer: public CEventClient {
28 public:
29 	CProjectileDrawer();
30 	~CProjectileDrawer();
31 
32 	typedef std::set<CProjectile*, ProjectileDistanceComparator> SortedProjectileSet;
33 	typedef std::list<CProjectile*> UnsortedProjectileList;
34 
35 	void Draw(bool drawReflection, bool drawRefraction = false);
36 	void DrawProjectilesMiniMap();
37 	bool DrawProjectileModel(const CProjectile* projectile, bool shadowPass);
38 	void DrawGroundFlashes();
39 	void DrawShadowPass();
40 
41 	void LoadWeaponTextures();
42 	void UpdateTextures();
43 
44 	void Update();
45 
46 
WantsEvent(const std::string & eventName)47 	bool WantsEvent(const std::string& eventName) {
48 		return (eventName == "RenderProjectileCreated" || eventName == "RenderProjectileDestroyed");
49 	}
GetFullRead()50 	bool GetFullRead() const { return true; }
GetReadAllyTeam()51 	int GetReadAllyTeam() const { return AllAccessTeam; }
52 
53 	void RenderProjectileCreated(const CProjectile* projectile);
54 	void RenderProjectileDestroyed(const CProjectile* projectile);
55 
IncPerlinTexObjectCount()56 	void IncPerlinTexObjectCount() { perlinTexObjects++; }
DecPerlinTexObjectCount()57 	void DecPerlinTexObjectCount() { perlinTexObjects--; }
58 
59 
60 	CTextureAtlas* textureAtlas;  ///< texture atlas for projectiles
61 	CTextureAtlas* groundFXAtlas; ///< texture atlas for ground fx
62 
63 	// texture-coordinates for projectiles
64 	AtlasedTexture* flaretex;
65 	AtlasedTexture* dguntex;            ///< dgun texture
66 	AtlasedTexture* flareprojectiletex; ///< texture used by flares that trick missiles
67 	AtlasedTexture* sbtrailtex;         ///< default first section of starburst missile trail texture
68 	AtlasedTexture* missiletrailtex;    ///< default first section of missile trail texture
69 	AtlasedTexture* muzzleflametex;     ///< default muzzle flame texture
70 	AtlasedTexture* repulsetex;         ///< texture of impact on repulsor
71 	AtlasedTexture* sbflaretex;         ///< default starburst  missile flare texture
72 	AtlasedTexture* missileflaretex;    ///< default missile flare texture
73 	AtlasedTexture* beamlaserflaretex;  ///< default beam laser flare texture
74 	AtlasedTexture* explotex;
75 	AtlasedTexture* explofadetex;
76 	AtlasedTexture* heatcloudtex;
77 	AtlasedTexture* circularthingytex;
78 	AtlasedTexture* bubbletex;          ///< torpedo trail texture
79 	AtlasedTexture* geosquaretex;       ///< unknown use
80 	AtlasedTexture* gfxtex;             ///< nanospray texture
81 	AtlasedTexture* projectiletex;      ///< appears to be unused
82 	AtlasedTexture* repulsegfxtex;      ///< used by repulsor
83 	AtlasedTexture* sphereparttex;      ///< sphere explosion texture
84 	AtlasedTexture* torpedotex;         ///< appears in-game as a 1 texel texture
85 	AtlasedTexture* wrecktex;           ///< smoking explosion part texture
86 	AtlasedTexture* plasmatex;          ///< default plasma texture
87 	AtlasedTexture* laserendtex;
88 	AtlasedTexture* laserfallofftex;
89 	AtlasedTexture* randdotstex;
90 	AtlasedTexture* smoketrailtex;
91 	AtlasedTexture* waketex;
92 	AtlasedTexture* perlintex;
93 	AtlasedTexture* flametex;
94 
95 	AtlasedTexture* groundflashtex;
96 	AtlasedTexture* groundringtex;
97 
98 	AtlasedTexture* seismictex;
99 
100 	std::vector<const AtlasedTexture*> smoketex;
101 
102 private:
103 	void ParseAtlasTextures(const bool, const LuaTable&, std::set<std::string>&, CTextureAtlas*);
104 
105 	void DrawProjectiles(int modelType, int numFlyingPieces, int* drawnPieces, bool drawReflection, bool drawRefraction);
106 	void DrawProjectilesSet(std::set<CProjectile*>& projectiles, bool drawReflection, bool drawRefraction);
107 	void DrawProjectile(CProjectile* projectile, bool drawReflection, bool drawRefraction);
108 	void DrawProjectilesShadow(int modelType);
109 	void DrawProjectileShadow(CProjectile* projectile);
110 	void DrawProjectilesSetShadow(std::set<CProjectile*>& projectiles);
111 	void DrawFlyingPieces(int modelType, int numFlyingPieces, int* drawnPieces);
112 
113 	void UpdatePerlin();
114 	void GenerateNoiseTex(unsigned int tex, int size);
115 
116 	GLuint perlinTex[8];
117 	float perlinBlend[4];
118 	FBO perlinFB;
119 	int perlinTexObjects;
120 	bool drawPerlinTex;
121 
122 	/// projectiles without a model
123 	std::set<CProjectile*> renderProjectiles;
124 	/// projectiles with a model
125 	std::vector<IWorldObjectModelRenderer*> modelRenderers;
126 
127 	/**
128 	 * z-sorted set of projectiles without models; used
129 	 * to render particle effects in back-to-front order
130 	 */
131 	SortedProjectileSet zSortedProjectiles;
132 	UnsortedProjectileList unsortedProjectiles;
133 };
134 
135 extern CProjectileDrawer* projectileDrawer;
136 
137 #endif // PROJECTILE_DRAWER_HDR
138