]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_shared.h
I guess those glLoadIdentity calls were more important than expected
[xonotic/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 #define SHADOWMESHVERTEXHASH 1024
64 typedef struct shadowmeshvertexhash_s
65 {
66         struct shadowmeshvertexhash_s *next;
67 }
68 shadowmeshvertexhash_t;
69
70 typedef struct shadowmesh_s
71 {
72         struct shadowmesh_s *next;
73         int numverts, maxverts;
74         int numtriangles, maxtriangles;
75         float *verts;
76         int *elements;
77         int *neighbors;
78         // these are NULL after Mod_ShadowMesh_Finish is performed, only used
79         // while building meshes
80         shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
81 }
82 shadowmesh_t;
83
84
85 #include "model_brush.h"
86 #include "model_sprite.h"
87 #include "model_alias.h"
88
89 typedef struct model_s
90 {
91         char                    name[MAX_QPATH];
92         // model needs to be loaded if this is true
93         qboolean                needload;
94         // set if the model is used in current map, models which are not, are purged
95         qboolean                used;
96         // CRC of the file this model was loaded from, to reload if changed
97         qboolean                crc;
98         // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
99         qboolean                isworldmodel;
100         // true if this model is a HalfLife .bsp file
101         qboolean                ishlbsp;
102         // true if this model was not successfully loaded and should be purged
103         qboolean                error;
104
105         // mod_brush, mod_alias, mod_sprite
106         modtype_t               type;
107         // LordHavoc: Q2/ZYM model support
108         int                             aliastype;
109         // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
110         int                             fullbright;
111         // number of QC accessible frame(group)s in the model
112         int                             numframes;
113         // number of QC accessible skin(group)s in the model
114         int                             numskins;
115         // whether to randomize animated framegroups
116         synctype_t              synctype;
117
118
119         // flags from the model file
120         int                             flags;
121         // engine calculated flags, ones that can not be set in the file
122         int                             flags2;
123
124         // all models use textures...
125         rtexturepool_t  *texturepool;
126
127         // volume occupied by the model
128         // bounding box at angles '0 0 0'
129         vec3_t                  normalmins, normalmaxs;
130         // bounding box if yaw angle is not 0, but pitch and roll are
131         vec3_t                  yawmins, yawmaxs;
132         // bounding box if pitch or roll are used
133         vec3_t                  rotatedmins, rotatedmaxs;
134         // sphere radius, usable at any angles
135         float                   radius;
136         // squared sphere radius for easier comparisons
137         float                   radius2;
138
139         // brush model specific
140         int                             firstmodelsurface, nummodelsurfaces;
141
142         // lightmap format, set to r_lightmaprgba when model is loaded
143         int                             lightmaprgba;
144
145         int                             numsubmodels;
146         dmodel_t                *submodels;
147
148         int                             numplanes;
149         mplane_t                *planes;
150
151         // number of visible leafs, not counting 0 (solid)
152         int                             numleafs;
153         mleaf_t                 *leafs;
154
155         int                             numvertexes;
156         mvertex_t               *vertexes;
157
158         int                             numedges;
159         medge_t                 *edges;
160
161         int                             numnodes;
162         mnode_t                 *nodes;
163
164         int                             numtexinfo;
165         mtexinfo_t              *texinfo;
166
167         int                             numsurfaces;
168         msurface_t              *surfaces;
169         int                             *surfacevisframes;
170         int                             *surfacepvsframes;
171         msurface_t              *surfacepvsnext;
172
173         int                             numsurfedges;
174         int                             *surfedges;
175
176         int                             numclipnodes;
177         dclipnode_t             *clipnodes;
178
179         int                             nummarksurfaces;
180         int                             *marksurfaces;
181
182         hull_t                  hulls[MAX_MAP_HULLS];
183
184         int                             numtextures;
185         texture_t               *textures;
186
187         qbyte                   *visdata;
188         qbyte                   *lightdata;
189         char                    *entities;
190
191         int                             numportals;
192         mportal_t               *portals;
193
194         int                             numportalpoints;
195         mvertex_t               *portalpoints;
196
197         int                             numlights;
198         mlight_t                *lights;
199
200         // pvs visibility marking
201         mleaf_t                 *pvsviewleaf;
202         int                             pvsviewleafnovis;
203         int                             pvsframecount;
204         mleaf_t                 *pvsleafchain;
205         int                             *pvssurflist;
206         int                             pvssurflistlength;
207         // these get rebuilt as the player moves around if this is the world,
208         // otherwise they are left alone (no pvs for bmodels)
209         msurface_t              ***pvstexturechains;
210         msurface_t              **pvstexturechainsbuffer;
211         int                             *pvstexturechainslength;
212
213         // lightmap update chains for light styles
214         int                             light_styles;
215         qbyte                   *light_style;
216         int                             *light_stylevalue;
217         msurface_t              ***light_styleupdatechains;
218         msurface_t              **light_styleupdatechainsbuffer;
219         int                             light_scalebit;
220         float                   light_ambient;
221
222         // skin animation info
223         animscene_t             *skinscenes; // [numskins]
224         // skin frame info
225         skinframe_t             *skinframes;
226
227         animscene_t             *animscenes; // [numframes]
228
229         // mdl/md2/md3 models are the same after loading
230         int                             aliasnum_meshes;
231         aliasmesh_t             *aliasdata_meshes;
232
233         // for Zymotic models
234         int                             zymnum_verts;
235         int                             zymnum_tris;
236         int                             zymnum_shaders;
237         int                             zymnum_bones;
238         int                             zymnum_scenes;
239         float                   *zymdata_texcoords;
240         rtexture_t              **zymdata_textures;
241         qbyte                   *zymdata_trizone;
242         zymbone_t               *zymdata_bones;
243         unsigned int    *zymdata_vertbonecounts;
244         zymvertex_t             *zymdata_verts;
245         unsigned int    *zymdata_renderlist;
246         float                   *zymdata_poses;
247
248         int                             sprnum_type;
249         mspriteframe_t  *sprdata_frames;
250
251
252         // functions used in both rendering modes
253         // draw the model's sky polygons (only used by brush models)
254         void(*DrawSky)(struct entity_render_s *ent);
255
256         // functions used only in normal rendering mode
257         // draw the model
258         void(*Draw)(struct entity_render_s *ent);
259         // draw a fake shadow for the model
260         void(*DrawFakeShadow)(struct entity_render_s *ent);
261
262         // functions used only in shadow volume rendering mode
263         // draw a shadow volume for the model based on light source
264         void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
265         // draw the lighting on a model (through stencil)
266         void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor);
267
268         // memory pool for allocations
269         mempool_t               *mempool;
270 }
271 model_t;
272
273 //============================================================================
274
275 // this can be used for anything without a valid texture
276 extern rtexture_t *r_notexture;
277 // every texture must be in a pool...
278 extern rtexturepool_t *r_notexturepool;
279
280 // model loading
281 extern model_t *loadmodel;
282 extern qbyte *mod_base;
283 // sky/water subdivision
284 //extern cvar_t gl_subdivide_size;
285 // texture fullbrights
286 extern cvar_t r_fullbrights;
287
288 void Mod_Init (void);
289 void Mod_CheckLoaded (model_t *mod);
290 void Mod_ClearAll (void);
291 void Mod_ClearErrorModels (void);
292 model_t *Mod_FindName (const char *name);
293 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
294 void Mod_TouchModel (const char *name);
295 void Mod_UnloadModel (model_t *mod);
296
297 void Mod_ClearUsed(void);
298 void Mod_PurgeUnused(void);
299 void Mod_LoadModels(void);
300
301 extern model_t *loadmodel;
302 extern char loadname[32];       // for hunk tags
303
304 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore);
305 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
306 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
307 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
308
309 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
310 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
311 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
312 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
313 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
314 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts, int numtris, int *elements);
315 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
316 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
317 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
318 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
319
320 #endif  // __MODEL__
321