1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __MODELDECAL_H__
30 #define __MODELDECAL_H__
31 
32 #include "idlib/geometry/DrawVert.h"
33 #include "idlib/geometry/Winding.h"
34 
35 /*
36 ===============================================================================
37 
38 	Decals are lightweight primitives for bullet / blood marks.
39 	Decals with common materials will be merged together, but additional
40 	decals will be allocated as needed. The material should not be
41 	one that receives lighting, because no interactions are generated
42 	for these lightweight surfaces.
43 
44 	FIXME:	Decals on models in portalled off areas do not get freed
45 			until the area becomes visible again.
46 
47 ===============================================================================
48 */
49 
50 const int NUM_DECAL_BOUNDING_PLANES = 6;
51 
52 typedef struct decalProjectionInfo_s {
53 	idVec3						projectionOrigin;
54 	idBounds					projectionBounds;
55 	idPlane						boundingPlanes[6];
56 	idPlane						fadePlanes[2];
57 	idPlane						textureAxis[2];
58 	const idMaterial *			material;
59 	bool						parallel;
60 	float						fadeDepth;
61 	int							startTime;
62 	bool						force;
63 } decalProjectionInfo_t;
64 
65 
66 class idRenderModelDecal {
67 public:
68 								idRenderModelDecal( void );
69 								~idRenderModelDecal( void );
70 
71 	static idRenderModelDecal *	Alloc( void );
72 	static void					Free( idRenderModelDecal *decal );
73 
74 								// Creates decal projection info.
75 	static bool					CreateProjectionInfo( decalProjectionInfo_t &info, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
76 
77 								// Transform the projection info from global space to local.
78 	static void					GlobalProjectionInfoToLocal( decalProjectionInfo_t &localInfo, const decalProjectionInfo_t &info, const idVec3 &origin, const idMat3 &axis );
79 
80 								// Creates a deal on the given model.
81 	void						CreateDecal( const idRenderModel *model, const decalProjectionInfo_t &localInfo );
82 
83 								// Remove decals that are completely faded away.
84 	static idRenderModelDecal *	RemoveFadedDecals( idRenderModelDecal *decals, int time );
85 
86 								// Updates the vertex colors, removing any faded indexes,
87 								// then copy the verts to temporary vertex cache and adds a drawSurf.
88 	void						AddDecalDrawSurf( struct viewEntity_s *space );
89 
90 								// Returns the next decal in the chain.
Next(void)91 	idRenderModelDecal *		Next( void ) const { return nextDecal; }
92 
93 	void						ReadFromDemoFile( class idDemoFile *f );
94 	void						WriteToDemoFile( class idDemoFile *f ) const;
95 
96 private:
97 	static const int			MAX_DECAL_VERTS = 40;
98 	static const int			MAX_DECAL_INDEXES = 60;
99 
100 	const idMaterial *			material;
101 	srfTriangles_t				tri;
102 	idDrawVert					verts[MAX_DECAL_VERTS];
103 	float						vertDepthFade[MAX_DECAL_VERTS];
104 	glIndex_t					indexes[MAX_DECAL_INDEXES];
105 	int							indexStartTime[MAX_DECAL_INDEXES];
106 	idRenderModelDecal *		nextDecal;
107 
108 								// Adds the winding triangles to the appropriate decal in the
109 								// chain, creating a new one if necessary.
110 	void						AddWinding( const idWinding &w, const idMaterial *decalMaterial, const idPlane fadePlanes[2], float fadeDepth, int startTime );
111 
112 								// Adds depth faded triangles for the winding to the appropriate
113 								// decal in the chain, creating a new one if necessary.
114 								// The part of the winding at the front side of both fade planes is not faded.
115 								// The parts at the back sides of the fade planes are faded with the given depth.
116 	void						AddDepthFadedWinding( const idWinding &w, const idMaterial *decalMaterial, const idPlane fadePlanes[2], float fadeDepth, int startTime );
117 };
118 
119 #endif /* !__MODELDECAL_H__ */
120