vkQuake2 doxygen  1.0 dev
vk_model.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 Copyright (C) 2018-2019 Krzysztof Kondrak
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 
14 See the GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 */
21 
22 /*
23 
24 d*_t structures are on-disk representations
25 m*_t structures are in-memory
26 
27 */
28 
29 /*
30 ==============================================================================
31 
32 BRUSH MODELS
33 
34 ==============================================================================
35 */
36 
37 
38 //
39 // in memory representation
40 //
41 // !!! if this is changed, it must be changed in asm_draw.h too !!!
42 typedef struct
43 {
44  vec3_t position;
45 } mvertex_t;
46 
47 typedef struct
48 {
49  vec3_t mins, maxs;
50  vec3_t origin; // for sounds or lights
51  float radius;
52  int headnode;
53  int visleafs; // not including the solid leaf 0
54  int firstface, numfaces;
55 } mmodel_t;
56 
57 
58 #define SIDE_FRONT 0
59 #define SIDE_BACK 1
60 #define SIDE_ON 2
61 
62 
63 #define SURF_PLANEBACK 2
64 #define SURF_DRAWSKY 4
65 #define SURF_DRAWTURB 0x10
66 #define SURF_DRAWBACKGROUND 0x40
67 #define SURF_UNDERWATER 0x80
68 
69 // !!! if this is changed, it must be changed in asm_draw.h too !!!
70 typedef struct
71 {
72  unsigned short v[2];
73  unsigned int cachededgeoffset;
74 } medge_t;
75 
76 typedef struct mtexinfo_s
77 {
78  float vecs[2][4];
79  int flags;
80  int numframes;
81  struct mtexinfo_s *next; // animation chain
82  image_t *image;
83 } mtexinfo_t;
84 
85 #define VERTEXSIZE 7
86 
87 typedef struct vkpoly_s
88 {
89  struct vkpoly_s *next;
90  struct vkpoly_s *chain;
91  int numverts;
92  int flags; // for SURF_UNDERWATER (not needed anymore?)
93  float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
94 } vkpoly_t;
95 
96 typedef struct msurface_s
97 {
98  int visframe; // should be drawn when node is crossed
99 
100  cplane_t *plane;
101  int flags;
102 
103  int firstedge; // look up in model->surfedges[], negative numbers
104  int numedges; // are backwards edges
105 
106  short texturemins[2];
107  short extents[2];
108 
109  int light_s, light_t; // gl lightmap coordinates
110  int dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps
111 
112  vkpoly_t *polys; // multiple if warped
113  struct msurface_s *texturechain;
114  struct msurface_s *lightmapchain;
115 
117 
118 // lighting info
119  int dlightframe;
120  int dlightbits;
121 
122  int lightmaptexturenum;
123  byte styles[MAXLIGHTMAPS];
124  float cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
125  byte *samples; // [numstyles*surfsize]
126 } msurface_t;
127 
128 typedef struct mnode_s
129 {
130 // common with leaf
131  int contents; // -1, to differentiate from leafs
132  int visframe; // node needs to be traversed if current
133 
134  float minmaxs[6]; // for bounding box culling
135 
136  struct mnode_s *parent;
137 
138 // node specific
139  cplane_t *plane;
140  struct mnode_s *children[2];
141 
142  unsigned short firstsurface;
143  unsigned short numsurfaces;
144 } mnode_t;
145 
146 
147 
148 typedef struct mleaf_s
149 {
150 // common with node
151  int contents; // wil be a negative contents number
152  int visframe; // node needs to be traversed if current
153 
154  float minmaxs[6]; // for bounding box culling
155 
156  struct mnode_s *parent;
157 
158 // leaf specific
159  int cluster;
160  int area;
161 
163  int nummarksurfaces;
164 } mleaf_t;
165 
166 
167 //===================================================================
168 
169 //
170 // Whole model
171 //
172 
174 
175 typedef struct model_s
176 {
177  char name[MAX_QPATH];
178 
180 
181  modtype_t type;
182  int numframes;
183 
184  int flags;
185 
186 //
187 // volume occupied by the model graphics
188 //
189  vec3_t mins, maxs;
190  float radius;
191 
192 //
193 // solid volume for clipping
194 //
197 
198 //
199 // brush model
200 //
202  int lightmap; // only for submodels
203 
204  int numsubmodels;
206 
207  int numplanes;
208  cplane_t *planes;
209 
210  int numleafs; // number of visible leafs, not counting 0
211  mleaf_t *leafs;
212 
213  int numvertexes;
215 
216  int numedges;
217  medge_t *edges;
218 
219  int numnodes;
220  int firstnode;
221  mnode_t *nodes;
222 
223  int numtexinfo;
225 
226  int numsurfaces;
228 
229  int numsurfedges;
230  int *surfedges;
231 
232  int nummarksurfaces;
234 
235  dvis_t *vis;
236 
237  byte *lightdata;
238 
239  // for alias models and skins
241 
242  int extradatasize;
243  void *extradata;
244 } model_t;
245 
246 //============================================================================
247 
248 void Mod_Init (void);
249 model_t *Mod_ForName (char *name, qboolean crash);
250 mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
251 byte *Mod_ClusterPVS (int cluster, model_t *model);
252 
253 void Mod_Modellist_f (void);
254 
255 void *Hunk_Begin (int maxsize);
256 void *Hunk_Alloc (int size);
257 int Hunk_End (void);
258 void Hunk_Free (void *base);
259 
260 void Mod_FreeAll (void);
261 void Mod_Free (model_t *mod);
model_s::numvertexes
int numvertexes
Definition: r_model.h:207
model_s::clipmins
vec3_t clipmins
Definition: r_model.h:191
msurface_s::dlight_s
int dlight_s
Definition: gl_model.h:109
msurface_s::plane
mplane_t * plane
Definition: r_model.h:100
msurface_s::styles
byte styles[MAXLIGHTMAPS]
Definition: r_model.h:115
MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:80
mtexinfo_s::numframes
int numframes
Definition: r_model.h:89
mleaf_s::area
int area
Definition: r_model.h:155
model_s::numplanes
int numplanes
Definition: r_model.h:201
Mod_Init
void Mod_Init(void)
Definition: r_model.c:78
model_s::vis
dvis_t * vis
Definition: r_model.h:229
mvertex_t
Definition: r_model.h:45
model_s::nummodelsurfaces
int nummodelsurfaces
Definition: r_model.h:196
mod_brush
@ mod_brush
Definition: vk_model.h:173
msurface_t
struct msurface_s msurface_t
msurface_s::light_t
int light_t
Definition: gl_model.h:108
mod_alias
@ mod_alias
Definition: vk_model.h:173
v
GLdouble v
Definition: qgl_win.c:143
mod_bad
@ mod_bad
Definition: vk_model.h:173
model_s::clipmaxs
vec3_t clipmaxs
Definition: r_model.h:191
model_s::flags
int flags
Definition: r_model.h:180
model_s::edges
medge_t * edges
Definition: r_model.h:211
msurface_s::dlight_t
int dlight_t
Definition: gl_model.h:109
vkpoly_s::verts
float verts[4][VERTEXSIZE]
Definition: vk_model.h:93
mtexinfo_s
Definition: r_model.h:83
mnode_s::visframe
int visframe
Definition: r_model.h:127
qboolean
qboolean
Definition: q_shared.h:63
Mod_Free
void Mod_Free(model_t *mod)
Definition: r_model.c:1313
msurface_s::numedges
int numedges
Definition: r_model.h:104
Mod_ClusterPVS
byte * Mod_ClusterPVS(int cluster, model_t *model)
Definition: r_model.c:268
msurface_s::visframe
int visframe
Definition: r_model.h:95
msurface_s::dlightframe
int dlightframe
Definition: r_model.h:97
model_s::firstnode
int firstnode
Definition: r_model.h:214
msurface_s::polys
vkpoly_t * polys
Definition: vk_model.h:112
mleaf_s::visframe
int visframe
Definition: r_model.h:147
mnode_s::parent
struct mnode_s * parent
Definition: r_model.h:131
mnode_s
Definition: r_model.h:123
model_s
Definition: r_model.h:171
mleaf_s::firstmarksurface
msurface_t ** firstmarksurface
Definition: r_model.h:157
dvis_t
Definition: qfiles.h:463
model_s::lightmap
int lightmap
Definition: gl_model.h:201
Mod_Modellist_f
void Mod_Modellist_f(void)
Definition: r_model.c:55
model_s::marksurfaces
msurface_t ** marksurfaces
Definition: r_model.h:227
msurface_s::samples
byte * samples
Definition: r_model.h:116
mmodel_t
Definition: gl_model.h:46
vkpoly_s
Definition: vk_model.h:87
mnode_s::children
struct mnode_s * children[2]
Definition: r_model.h:135
mleaf_s::contents
int contents
Definition: r_model.h:146
msurface_s::extents
short extents[2]
Definition: r_model.h:110
modtype_t
modtype_t
Definition: r_model.h:169
msurface_s::cached_light
float cached_light[MAXLIGHTMAPS]
Definition: gl_model.h:123
Hunk_Free
void Hunk_Free(void *base)
Definition: q_shwin.c:99
mleaf_s
Definition: r_model.h:143
model_s::extradata
void * extradata
Definition: r_model.h:235
Hunk_Alloc
void * Hunk_Alloc(int size)
Definition: q_shwin.c:57
Mod_ForName
model_t * Mod_ForName(char *name, qboolean crash)
Definition: r_model.c:90
model_s::clipbox
qboolean clipbox
Definition: r_model.h:190
model_s::numsubmodels
int numsubmodels
Definition: r_model.h:198
model_s::numedges
int numedges
Definition: r_model.h:210
model_s::registration_sequence
int registration_sequence
Definition: r_model.h:175
mtexinfo_s::image
image_t * image
Definition: r_model.h:87
model_s::numframes
int numframes
Definition: r_model.h:178
VERTEXSIZE
#define VERTEXSIZE
Definition: vk_model.h:85
model_s::texinfo
mtexinfo_t * texinfo
Definition: r_model.h:218
medge_t
Definition: r_model.h:77
model_s::type
modtype_t type
Definition: r_model.h:177
mnode_s::minmaxs
short minmaxs[6]
Definition: r_model.h:129
model_t
struct model_s model_t
vkpoly_s::next
struct vkpoly_s * next
Definition: vk_model.h:89
model_s::numsurfedges
int numsurfedges
Definition: r_model.h:223
mnode_t
struct mnode_s mnode_t
msurface_s::texinfo
mtexinfo_t * texinfo
Definition: r_model.h:112
model_s::leafs
mleaf_t * leafs
Definition: r_model.h:205
model_s::nodes
mnode_t * nodes
Definition: r_model.h:215
model_s::mins
vec3_t mins
Definition: r_model.h:185
mleaf_s::cluster
int cluster
Definition: r_model.h:154
vkpoly_s::chain
struct vkpoly_s * chain
Definition: vk_model.h:90
msurface_s::texturechain
struct msurface_s * texturechain
Definition: gl_model.h:112
Hunk_End
int Hunk_End(void)
Definition: q_shwin.c:81
msurface_s::lightmapchain
struct msurface_s * lightmapchain
Definition: gl_model.h:113
Mod_PointInLeaf
mleaf_t * Mod_PointInLeaf(float *p, model_t *model)
model_s::lightdata
byte * lightdata
Definition: r_model.h:231
model_s::surfedges
int * surfedges
Definition: r_model.h:224
mleaf_s::minmaxs
short minmaxs[6]
Definition: r_model.h:149
mleaf_s::nummarksurfaces
int nummarksurfaces
Definition: r_model.h:158
MAX_MD2SKINS
#define MAX_MD2SKINS
Definition: qfiles.h:92
vkpoly_t
struct vkpoly_s vkpoly_t
name
cvar_t * name
Definition: cl_main.c:79
MAXLIGHTMAPS
#define MAXLIGHTMAPS
Definition: qfiles.h:409
msurface_s::flags
int flags
Definition: r_model.h:101
modtype_t
modtype_t
Definition: vk_model.h:173
vkpoly_s::numverts
int numverts
Definition: vk_model.h:91
model_s::maxs
vec3_t maxs
Definition: r_model.h:185
model_s::radius
float radius
Definition: gl_model.h:189
mtexinfo_s::next
struct mtexinfo_s * next
Definition: r_model.h:90
model_s::skins
image_t * skins[MAX_MD2SKINS]
Definition: r_model.h:234
mtexinfo_s::vecs
float vecs[2][4]
Definition: r_model.h:85
model_s::name
char name[MAX_QPATH]
Definition: r_model.h:173
msurface_s::light_s
int light_s
Definition: gl_model.h:108
model_s::numtexinfo
int numtexinfo
Definition: r_model.h:217
mnode_s::contents
int contents
Definition: r_model.h:126
mnode_s::firstsurface
unsigned short firstsurface
Definition: r_model.h:137
Hunk_Begin
void * Hunk_Begin(int maxsize)
Definition: q_shwin.c:41
mleaf_s::parent
struct mnode_s * parent
Definition: r_model.h:151
mod_sprite
@ mod_sprite
Definition: vk_model.h:173
model_s::firstmodelsurface
int firstmodelsurface
Definition: r_model.h:196
model_s::surfaces
msurface_t * surfaces
Definition: r_model.h:221
mnode_s::plane
mplane_t * plane
Definition: r_model.h:134
model_s::numleafs
int numleafs
Definition: r_model.h:204
msurface_s::lightmaptexturenum
int lightmaptexturenum
Definition: gl_model.h:121
model_s::submodels
dmodel_t * submodels
Definition: r_model.h:199
msurface_s
Definition: r_model.h:93
mtexinfo_s::flags
int flags
Definition: r_model.h:88
model_s::numnodes
int numnodes
Definition: r_model.h:213
Mod_FreeAll
void Mod_FreeAll(void)
Definition: r_model.c:1324
msurface_s::texturemins
short texturemins[2]
Definition: r_model.h:109
model_s::planes
mplane_t * planes
Definition: r_model.h:202
image_s
Definition: r_local.h:71
msurface_s::dlightbits
int dlightbits
Definition: r_model.h:98
cplane_s
Definition: q_shared.h:413
mnode_s::numsurfaces
unsigned short numsurfaces
Definition: r_model.h:138
model_s::vertexes
mvertex_t * vertexes
Definition: r_model.h:208
mleaf_t
struct mleaf_s mleaf_t
model_s::nummarksurfaces
int nummarksurfaces
Definition: r_model.h:226
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:134
msurface_s::firstedge
int firstedge
Definition: r_model.h:103
mtexinfo_t
struct mtexinfo_s mtexinfo_t
vkpoly_s::flags
int flags
Definition: vk_model.h:92
model_s::extradatasize
int extradatasize
Definition: r_model.h:236
model_s::numsurfaces
int numsurfaces
Definition: r_model.h:220