]> icculus.org git repositories - divverent/darkplaces.git/blob - model_shared.h
fixed some dynamic lighting bugs related to glowing self
[divverent/darkplaces.git] / model_shared.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef __MODEL__
22 #define __MODEL__
23
24 #ifndef SYNCTYPE_T
25 #define SYNCTYPE_T
26 typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
27 #endif
28
29 /*
30
31 d*_t structures are on-disk representations
32 m*_t structures are in-memory
33
34 */
35
36 typedef enum {mod_invalid, mod_brush, mod_sprite, mod_alias} modtype_t;
37
38 typedef struct animscene_s
39 {
40         char name[32]; // for viewthing support
41         int firstframe;
42         int framecount;
43         int loop; // true or false
44         float framerate;
45 }
46 animscene_t;
47
48 typedef struct skinframe_s
49 {
50         rtexture_t *base; // original texture minus pants/shirt/glow
51         rtexture_t *pants; // pants only (in greyscale)
52         rtexture_t *shirt; // shirt only (in greyscale)
53         rtexture_t *glow; // glow only
54         rtexture_t *merged; // original texture minus glow
55         rtexture_t *fog; // white texture with alpha of the base texture, NULL if not transparent
56         rtexture_t *nmap; // normalmap (bumpmap for dot3)
57         rtexture_t *gloss; // glossmap (for dot3)
58 }
59 skinframe_t;
60
61 #define MAX_SKINS 256
62
63 typedef struct shadowmesh_s
64 {
65         struct shadowmesh_s *next;
66         int numverts, maxverts;
67         int numtriangles, maxtriangles;
68         float *verts;
69         int *elements;
70         int *neighbors;
71 }
72 shadowmesh_t;
73
74
75 #include "model_brush.h"
76 #include "model_sprite.h"
77 #include "model_alias.h"
78
79 typedef struct model_s
80 {
81         char                    name[MAX_QPATH];
82         // model needs to be loaded if this is true
83         qboolean                needload;
84         // set if the model is used in current map, models which are not, are purged
85         qboolean                used;
86         // CRC of the file this model was loaded from, to reload if changed
87         qboolean                crc;
88         // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
89         qboolean                isworldmodel;
90         // true if this model is a HalfLife .bsp file
91         qboolean                ishlbsp;
92
93         // mod_brush, mod_alias, mod_sprite
94         modtype_t               type;
95         // LordHavoc: Q2/ZYM model support
96         int                             aliastype;
97         // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
98         int                             fullbright;
99         // number of QC accessable frame(group)s in the model
100         int                             numframes;
101         // whether to randomize animated framegroups
102         synctype_t              synctype;
103
104         // used for sprites and models
105         int                             numtris;
106         // used for models
107         int                             numskins;
108         // used by models
109         int                             numverts;
110
111         // flags from the model file
112         int                             flags;
113         // engine calculated flags, ones that can not be set in the file
114         int                             flags2;
115
116         // all models use textures...
117         rtexturepool_t  *texturepool;
118
119         // volume occupied by the model
120         // bounding box at angles '0 0 0'
121         vec3_t                  normalmins, normalmaxs;
122         // bounding box if yaw angle is not 0, but pitch and roll are
123         vec3_t                  yawmins, yawmaxs;
124         // bounding box if pitch or roll are used
125         vec3_t                  rotatedmins, rotatedmaxs;
126         // sphere radius, usable at any angles
127         float                   radius;
128         // squared sphere radius for easier comparisons
129         float                   radius2;
130
131         // brush model specific
132         int                             firstmodelsurface, nummodelsurfaces;
133
134         // lightmap format, set to r_lightmaprgba when model is loaded
135         int                             lightmaprgba;
136
137         int                             numsubmodels;
138         dmodel_t                *submodels;
139
140         int                             numplanes;
141         mplane_t                *planes;
142
143         // number of visible leafs, not counting 0 (solid)
144         int                             numleafs;
145         mleaf_t                 *leafs;
146
147         int                             numvertexes;
148         mvertex_t               *vertexes;
149
150         int                             numedges;
151         medge_t                 *edges;
152
153         int                             numnodes;
154         mnode_t                 *nodes;
155
156         int                             numtexinfo;
157         mtexinfo_t              *texinfo;
158
159         int                             numsurfaces;
160         msurface_t              *surfaces;
161         int                             *surfacevisframes;
162         int                             *surfacepvsframes;
163         msurface_t              *surfacepvsnext;
164
165         int                             numsurfedges;
166         int                             *surfedges;
167
168         int                             numclipnodes;
169         dclipnode_t             *clipnodes;
170
171         int                             nummarksurfaces;
172         int                             *marksurfaces;
173
174         hull_t                  hulls[MAX_MAP_HULLS];
175
176         int                             numtextures;
177         texture_t               *textures;
178
179         msurface_t              **texturesurfacechains;
180
181         qbyte                   *visdata;
182         qbyte                   *lightdata;
183         char                    *entities;
184
185         int                             numportals;
186         mportal_t               *portals;
187
188         int                             numportalpoints;
189         mvertex_t               *portalpoints;
190
191         int                             numlights;
192         mlight_t                *lights;
193
194         // used only for casting dynamic shadow volumes
195         shadowmesh_t    *shadowmesh;
196         vec3_t                  shadowmesh_mins, shadowmesh_maxs, shadowmesh_center;
197         float                   shadowmesh_radius;
198
199         // pvs visibility marking
200         mleaf_t                 *pvsviewleaf;
201         int                             pvsviewleafnovis;
202         int                             pvsframecount;
203
204         // skin animation info
205         animscene_t             *skinscenes; // [numskins]
206         // skin frame info
207         skinframe_t             *skinframes;
208
209         animscene_t             *animscenes; // [numframes]
210
211         // Q1 and Q2 models are the same after loading
212         int                             *mdlmd2data_indices;
213         float                   *mdlmd2data_texcoords;
214         md2frame_t              *mdlmd2data_frames;
215         trivertx_t              *mdlmd2data_pose;
216         int                             *mdlmd2data_triangleneighbors;
217
218         // for Zymotic models
219         int                             zymnum_verts;
220         int                             zymnum_tris;
221         int                             zymnum_shaders;
222         int                             zymnum_bones;
223         int                             zymnum_scenes;
224         float                   *zymdata_texcoords;
225         rtexture_t              **zymdata_textures;
226         qbyte                   *zymdata_trizone;
227         zymbone_t               *zymdata_bones;
228         unsigned int    *zymdata_vertbonecounts;
229         zymvertex_t             *zymdata_verts;
230         unsigned int    *zymdata_renderlist;
231         float                   *zymdata_poses;
232
233         int                             sprnum_type;
234         mspriteframe_t  *sprdata_frames;
235
236
237         // functions used in both rendering modes
238         // draw the model's sky polygons (only used by brush models)
239         void(*DrawSky)(struct entity_render_s *ent);
240
241         // functions used only in normal rendering mode
242         // draw the model
243         void(*Draw)(struct entity_render_s *ent);
244         // draw a fake shadow for the model
245         void(*DrawFakeShadow)(struct entity_render_s *ent);
246
247         // functions used only in shadow volume rendering mode
248         // draw a shadow volume for the model based on light source
249         void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
250         // draw the lighting on a model (through stencil)
251         void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float lightdistbias, float lightsubtract, float *lightcolor);
252
253         // memory pool for allocations
254         mempool_t               *mempool;
255 }
256 model_t;
257
258 //============================================================================
259
260 // this can be used for anything without a valid texture
261 extern rtexture_t *r_notexture;
262 // every texture must be in a pool...
263 extern rtexturepool_t *r_notexturepool;
264
265 // model loading
266 extern model_t *loadmodel;
267 extern qbyte *mod_base;
268 // sky/water subdivision
269 //extern cvar_t gl_subdivide_size;
270 // texture fullbrights
271 extern cvar_t r_fullbrights;
272
273 void Mod_Init (void);
274 void Mod_CheckLoaded (model_t *mod);
275 void Mod_ClearAll (void);
276 model_t *Mod_FindName (const char *name);
277 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
278 void Mod_TouchModel (const char *name);
279 void Mod_UnloadModel (model_t *mod);
280
281 void Mod_ClearUsed(void);
282 void Mod_PurgeUnused(void);
283 void Mod_LoadModels(void);
284
285 extern model_t *loadmodel;
286 extern char loadname[32];       // for hunk tags
287
288 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end);
289 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
290 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
291
292 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
293 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
294 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
295 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
296 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool);
297 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
298 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
299 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
300
301 #endif  // __MODEL__
302