2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
33 ===============================================================================
37 ===============================================================================
40 // shared between the renderer, game, and Maya export DLL
41 #define MD5_VERSION_STRING "MD5Version"
42 #define MD5_MESH_EXT "md5mesh"
43 #define MD5_ANIM_EXT "md5anim"
44 #define MD5_CAMERA_EXT "md5camera"
45 #define MD5_VERSION 10
47 // using shorts for triangle indexes can save a significant amount of traffic, but
48 // to support the large models that renderBump loads, they need to be 32 bits
51 #define GL_INDEX_TYPE GL_UNSIGNED_INT
52 typedef int glIndex_t;
56 #define GL_INDEX_TYPE GL_UNSIGNED_SHORT
57 typedef short glIndex_t;
63 // NOTE: making this a glIndex is dubious, as there can be 2x the faces as verts
64 glIndex_t p1, p2; // planes defining the edge
65 glIndex_t v1, v2; // verts defining the edge
68 // this is used for calculating unsmoothed normals and tangents for deformed models
69 typedef struct dominantTri_s {
71 float normalizationScale[3];
74 typedef struct lightingCache_s {
75 idVec3 localLightVector; // this is the statically computed vector to the light
76 // in texture space for cards without vertex programs
79 typedef struct shadowCache_s {
80 idVec4 xyz; // we use homogenous coordinate tricks
83 const int SHADOW_CAP_INFINITE = 64;
85 // our only drawing geometry type
86 typedef struct srfTriangles_s {
87 idBounds bounds; // for culling
89 int ambientViewCount; // if == tr.viewCount, it is visible this view
91 bool generateNormals; // create normals from geometry, instead of using explicit ones
92 bool tangentsCalculated; // set when the vertex tangents have been calculated
93 bool facePlanesCalculated; // set when the face planes have been calculated
94 bool perfectHull; // true if there aren't any dangling edges
95 bool deformedSurface; // if true, indexes, silIndexes, mirrorVerts, and silEdges are
96 // pointers into the original surface, and should not be freed
98 int numVerts; // number of vertices
99 idDrawVert * verts; // vertices, allocated with special allocator
101 int numIndexes; // for shadows, this has both front and rear end caps and silhouette planes
102 glIndex_t * indexes; // indexes, allocated with special allocator
104 glIndex_t * silIndexes; // indexes changed to be the first vertex with same XYZ, ignoring normal and texcoords
106 int numMirroredVerts; // this many verts at the end of the vert list are tangent mirrors
107 int * mirroredVerts; // tri->mirroredVerts[0] is the mirror of tri->numVerts - tri->numMirroredVerts + 0
109 int numDupVerts; // number of duplicate vertexes
110 int * dupVerts; // pairs of the number of the first vertex and the number of the duplicate vertex
112 int numSilEdges; // number of silhouette edges
113 silEdge_t * silEdges; // silhouette edges
115 idPlane * facePlanes; // [numIndexes/3] plane equations
117 dominantTri_t * dominantTris; // [numVerts] for deformed surface fast tangent calculation
119 int numShadowIndexesNoFrontCaps; // shadow volumes with front caps omitted
120 int numShadowIndexesNoCaps; // shadow volumes with the front and rear caps omitted
122 int shadowCapPlaneBits; // bits 0-5 are set when that plane of the interacting light has triangles
123 // projected on it, which means that if the view is on the outside of that
124 // plane, we need to draw the rear caps of the shadow volume
125 // turboShadows will have SHADOW_CAP_INFINITE
127 shadowCache_t * shadowVertexes; // these will be copied to shadowCache when it is going to be drawn.
128 // these are NULL when vertex programs are available
130 struct srfTriangles_s * ambientSurface; // for light interactions, point back at the original surface that generated
131 // the interaction, which we will get the ambientCache from
133 struct srfTriangles_s * nextDeferredFree; // chain of tris to free next frame
135 // data in vertex object space, not directly readable by the CPU
136 struct vertCache_s * indexCache; // int
137 struct vertCache_s * ambientCache; // idDrawVert
138 struct vertCache_s * lightingCache; // lightingCache_t
139 struct vertCache_s * shadowCache; // shadowCache_t
142 typedef idList<srfTriangles_t *> idTriList;
144 typedef struct modelSurface_s {
146 const idMaterial * shader;
147 srfTriangles_t * geometry;
151 DM_STATIC, // never creates a dynamic model
152 DM_CACHED, // once created, stays constant until the entity is updated (animating characters)
153 DM_CONTINUOUS // must be recreated for every single view (time dependent things like particles)
162 idMD5Joint() { parent = NULL; }
164 const idMD5Joint * parent;
168 // the init methods may be called again on an already created model when
169 // a reloadModels is issued
171 class idRenderModel {
173 virtual ~idRenderModel() {};
175 // Loads static models only, dynamic models must be loaded by the modelManager
176 virtual void InitFromFile( const char *fileName ) = 0;
178 // renderBump uses this to load the very high poly count models, skipping the
179 // shadow and tangent generation, along with some surface cleanup to make it load faster
180 virtual void PartialInitFromFile( const char *fileName ) = 0;
182 // this is used for dynamically created surfaces, which are assumed to not be reloadable.
183 // It can be called again to clear out the surfaces of a dynamic model for regeneration.
184 virtual void InitEmpty( const char *name ) = 0;
186 // dynamic model instantiations will be created with this
187 // the geometry data will be owned by the model, and freed when it is freed
188 // the geoemtry should be raw triangles, with no extra processing
189 virtual void AddSurface( modelSurface_t surface ) = 0;
191 // cleans all the geometry and performs cross-surface processing
193 // Creates the duplicated back side geometry for two sided, alpha tested, lit materials
194 // This does not need to be called if none of the surfaces added with AddSurface require
195 // light interaction, and all the triangles are already well formed.
196 virtual void FinishSurfaces() = 0;
198 // frees all the data, but leaves the class around for dangling references,
199 // which can regenerate the data with LoadModel()
200 virtual void PurgeModel() = 0;
202 // resets any model information that needs to be reset on a same level load etc..
203 // currently only implemented for liquids
204 virtual void Reset() = 0;
206 // used for initial loads, reloadModel, and reloading the data of purged models
207 // Upon exit, the model will absolutely be valid, but possibly as a default model
208 virtual void LoadModel() = 0;
211 virtual bool IsLoaded() = 0;
212 virtual void SetLevelLoadReferenced( bool referenced ) = 0;
213 virtual bool IsLevelLoadReferenced() = 0;
215 // models that are already loaded at level start time
216 // will still touch their data to make sure they
218 virtual void TouchData() = 0;
220 // dump any ambient caches on the model surfaces
221 virtual void FreeVertexCache() = 0;
223 // returns the name of the model
224 virtual const char * Name() const = 0;
226 // prints a detailed report on the model for printModel
227 virtual void Print() const = 0;
229 // prints a single line report for listModels
230 virtual void List() const = 0;
232 // reports the amount of memory (roughly) consumed by the model
233 virtual int Memory() const = 0;
236 virtual ID_TIME_T Timestamp() const = 0;
238 // returns the number of surfaces
239 virtual int NumSurfaces() const = 0;
241 // NumBaseSurfaces will not count any overlays added to dynamic models
242 virtual int NumBaseSurfaces() const = 0;
244 // get a pointer to a surface
245 virtual const modelSurface_t *Surface( int surfaceNum ) const = 0;
247 // Allocates surface triangles.
248 // Allocates memory for srfTriangles_t::verts and srfTriangles_t::indexes
249 // The allocated memory is not initialized.
250 // srfTriangles_t::numVerts and srfTriangles_t::numIndexes are set to zero.
251 virtual srfTriangles_t * AllocSurfaceTriangles( int numVerts, int numIndexes ) const = 0;
253 // Frees surfaces triangles.
254 virtual void FreeSurfaceTriangles( srfTriangles_t *tris ) const = 0;
256 // created at load time by stitching together all surfaces and sharing
257 // the maximum number of edges. This may be incorrect if a skin file
258 // remaps surfaces between shadow casting and non-shadow casting, or
259 // if some surfaces are noSelfShadow and others aren't
260 virtual srfTriangles_t * ShadowHull() const = 0;
262 // models of the form "_area*" may have a prelight shadow model associated with it
263 virtual bool IsStaticWorldModel() const = 0;
265 // models parsed from inside map files or dynamically created cannot be reloaded by
267 virtual bool IsReloadable() const = 0;
269 // md3, md5, particles, etc
270 virtual dynamicModel_t IsDynamicModel() const = 0;
272 // if the load failed for any reason, this will return true
273 virtual bool IsDefaultModel() const = 0;
275 // dynamic models should return a fast, conservative approximation
276 // static models should usually return the exact value
277 virtual idBounds Bounds( const struct renderEntity_s *ent = NULL ) const = 0;
279 // returns value != 0.0f if the model requires the depth hack
280 virtual float DepthHack() const = 0;
282 // returns a static model based on the definition and view
283 // currently, this will be regenerated for every view, even though
284 // some models, like character meshes, could be used for multiple (mirror)
285 // views in a frame, or may stay static for multiple frames (corpses)
286 // The renderer will delete the returned dynamic model the next view
287 // This isn't const, because it may need to reload a purged model if it
288 // wasn't precached correctly.
289 virtual idRenderModel * InstantiateDynamicModel( const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel ) = 0;
291 // Returns the number of joints or 0 if the model is not an MD5
292 virtual int NumJoints( void ) const = 0;
294 // Returns the MD5 joints or NULL if the model is not an MD5
295 virtual const idMD5Joint * GetJoints( void ) const = 0;
297 // Returns the handle for the joint with the given name.
298 virtual jointHandle_t GetJointHandle( const char *name ) const = 0;
300 // Returns the name for the joint with the given handle.
301 virtual const char * GetJointName( jointHandle_t handle ) const = 0;
303 // Returns the default animation pose or NULL if the model is not an MD5.
304 virtual const idJointQuat * GetDefaultPose( void ) const = 0;
306 // Returns number of the joint nearest to the given triangle.
307 virtual int NearestJoint( int surfaceNum, int a, int c, int b ) const = 0;
309 // Writing to and reading from a demo file.
310 virtual void ReadFromDemoFile( class idDemoFile *f ) = 0;
311 virtual void WriteToDemoFile( class idDemoFile *f ) = 0;
314 #endif /* !__MODEL_H__ */