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