ModelOverlay.h (4276B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition 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 BFG Edition 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 __MODELOVERLAY_H__ 30 #define __MODELOVERLAY_H__ 31 32 /* 33 =============================================================================== 34 35 Overlays are used for adding decals on top of dynamic models. 36 Projects an overlay onto deformable geometry and can be added to 37 a render entity to allow decals on top of dynamic models. 38 This does not generate tangent vectors, so it can't be used with 39 light interaction shaders. Materials for overlays should always 40 be clamped, because the projected texcoords can run well off the 41 texture since no new clip vertexes are generated. 42 Overlays with common materials will be merged together, but additional 43 overlays will be allocated as needed. The material should not be 44 one that receives lighting, because no interactions are generated 45 for these lightweight surfaces. 46 47 =============================================================================== 48 */ 49 50 static const int MAX_DEFERRED_OVERLAYS = 4; 51 static const int DEFFERED_OVERLAY_TIMEOUT = 200; // don't create a overlay if it wasn't visible within the first 200 milliseconds 52 static const int MAX_OVERLAYS = 8; 53 54 compile_time_assert( CONST_ISPOWEROFTWO( MAX_OVERLAYS ) ); 55 56 struct overlayProjectionParms_t { 57 idPlane localTextureAxis[2]; 58 const idMaterial * material; 59 int startTime; 60 }; 61 62 struct overlayVertex_t { 63 int vertexNum; 64 halfFloat_t st[2]; 65 }; 66 67 struct overlay_t { 68 int surfaceNum; 69 int surfaceId; 70 int maxReferencedVertex; 71 int numIndexes; 72 triIndex_t * indexes; 73 int numVerts; 74 overlayVertex_t * verts; 75 const idMaterial * material; 76 }; 77 78 class idRenderModelOverlay { 79 public: 80 idRenderModelOverlay(); 81 ~idRenderModelOverlay(); 82 83 void ReUse(); 84 85 void AddDeferredOverlay( const overlayProjectionParms_t & localParms ); 86 void CreateDeferredOverlays( const idRenderModel * model ); 87 88 unsigned int GetNumOverlayDrawSurfs(); 89 struct drawSurf_t * CreateOverlayDrawSurf( const struct viewEntity_t *space, const idRenderModel *baseModel, unsigned int index ); 90 91 void ReadFromDemoFile( class idDemoFile *f ); 92 void WriteToDemoFile( class idDemoFile *f ) const; 93 94 private: 95 overlay_t overlays[MAX_OVERLAYS]; 96 unsigned int firstOverlay; 97 unsigned int nextOverlay; 98 99 overlayProjectionParms_t deferredOverlays[MAX_DEFERRED_OVERLAYS]; 100 unsigned int firstDeferredOverlay; 101 unsigned int nextDeferredOverlay; 102 103 const idMaterial * overlayMaterials[MAX_OVERLAYS]; 104 unsigned int numOverlayMaterials; 105 106 void CreateOverlay( const idRenderModel *model, const idPlane localTextureAxis[2], const idMaterial *material ); 107 void FreeOverlay( overlay_t & overlay ); 108 }; 109 110 #endif /* !__MODELOVERLAY_H__ */