]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/renderer/ModelDecal.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / renderer / ModelDecal.h
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 /*
33 ===============================================================================
34
35         Decals are lightweight primitives for bullet / blood marks.
36         Decals with common materials will be merged together, but additional
37         decals will be allocated as needed. The material should not be
38         one that receives lighting, because no interactions are generated
39         for these lightweight surfaces.
40
41         FIXME:  Decals on models in portalled off areas do not get freed
42                         until the area becomes visible again.
43
44 ===============================================================================
45 */
46
47 const int NUM_DECAL_BOUNDING_PLANES = 6;
48
49 typedef struct decalProjectionInfo_s {
50         idVec3                                          projectionOrigin;
51         idBounds                                        projectionBounds;
52         idPlane                                         boundingPlanes[6];
53         idPlane                                         fadePlanes[2];
54         idPlane                                         textureAxis[2];
55         const idMaterial *                      material;
56         bool                                            parallel;
57         float                                           fadeDepth;
58         int                                                     startTime;
59         bool                                            force;
60 } decalProjectionInfo_t;
61
62
63 class idRenderModelDecal {
64 public:
65                                                                 idRenderModelDecal( void );
66                                                                 ~idRenderModelDecal( void );
67
68         static idRenderModelDecal *     Alloc( void );
69         static void                                     Free( idRenderModelDecal *decal );
70
71                                                                 // Creates decal projection info.
72         static bool                                     CreateProjectionInfo( decalProjectionInfo_t &info, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
73
74                                                                 // Transform the projection info from global space to local.
75         static void                                     GlobalProjectionInfoToLocal( decalProjectionInfo_t &localInfo, const decalProjectionInfo_t &info, const idVec3 &origin, const idMat3 &axis );
76
77                                                                 // Creates a deal on the given model.
78         void                                            CreateDecal( const idRenderModel *model, const decalProjectionInfo_t &localInfo );
79
80                                                                 // Remove decals that are completely faded away.
81         static idRenderModelDecal *     RemoveFadedDecals( idRenderModelDecal *decals, int time );
82
83                                                                 // Updates the vertex colors, removing any faded indexes,
84                                                                 // then copy the verts to temporary vertex cache and adds a drawSurf.
85         void                                            AddDecalDrawSurf( struct viewEntity_s *space );
86
87                                                                 // Returns the next decal in the chain.
88         idRenderModelDecal *            Next( void ) const { return nextDecal; }
89
90         void                                            ReadFromDemoFile( class idDemoFile *f );
91         void                                            WriteToDemoFile( class idDemoFile *f ) const;
92
93 private:
94         static const int                        MAX_DECAL_VERTS = 40;
95         static const int                        MAX_DECAL_INDEXES = 60;
96
97         const idMaterial *                      material;
98         srfTriangles_t                          tri;
99         idDrawVert                                      verts[MAX_DECAL_VERTS];
100         float                                           vertDepthFade[MAX_DECAL_VERTS];
101         glIndex_t                                       indexes[MAX_DECAL_INDEXES];
102         int                                                     indexStartTime[MAX_DECAL_INDEXES];
103         idRenderModelDecal *            nextDecal;
104
105                                                                 // Adds the winding triangles to the appropriate decal in the
106                                                                 // chain, creating a new one if necessary.
107         void                                            AddWinding( const idWinding &w, const idMaterial *decalMaterial, const idPlane fadePlanes[2], float fadeDepth, int startTime );
108
109                                                                 // Adds depth faded triangles for the winding to the appropriate
110                                                                 // decal in the chain, creating a new one if necessary.
111                                                                 // The part of the winding at the front side of both fade planes is not faded.
112                                                                 // The parts at the back sides of the fade planes are faded with the given depth.
113         void                                            AddDepthFadedWinding( const idWinding &w, const idMaterial *decalMaterial, const idPlane fadePlanes[2], float fadeDepth, int startTime );
114 };
115
116 #endif /* !__MODELDECAL_H__ */