This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/vid_gl/r_model.h

343 lines
7.8 KiB
C
Raw Normal View History

2009-07-12 22:00:00 +02:00
/*
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 2002-2007 Victor Luchits
2008-11-15 22:00:00 +01:00
2009-07-12 22:00:00 +02:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
2008-11-15 22:00:00 +01:00
2009-07-12 22:00:00 +02:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2009-09-04 22:00:00 +02:00
#ifndef R_MODEL_H
#define R_MODEL_H
2009-07-12 22:00:00 +02:00
/*
d*_t structures are on-disk representations
m*_t structures are in-memory
*/
/*
==============================================================================
BRUSH MODELS
==============================================================================
*/
//
// in memory representation
//
2008-11-15 22:00:00 +01:00
typedef struct
{
2009-08-05 22:00:00 +02:00
vec3_t mins, maxs;
2010-05-22 22:00:00 +02:00
vec3_t origin;
2009-08-05 22:00:00 +02:00
float radius;
2010-05-22 22:00:00 +02:00
int firstnode; // used for lighting bmodels
int firstface;
int numfaces;
2010-05-27 22:00:00 +02:00
int visleafs;
2009-07-12 22:00:00 +02:00
} mmodel_t;
2008-11-15 22:00:00 +01:00
typedef struct
{
2009-08-05 22:00:00 +02:00
ref_shader_t *shader;
2010-08-12 22:00:00 +02:00
mplane_t *visibleplane;
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
int numplanes;
2010-08-12 22:00:00 +02:00
mplane_t *planes;
2009-07-12 22:00:00 +02:00
} mfog_t;
2008-11-15 22:00:00 +01:00
2010-06-29 22:00:00 +02:00
typedef struct decal_s
{
struct decal_s *pnext; // linked list for each surface
struct msurface_s *psurf; // surface id for persistence / unlinking
ref_shader_t *shader; // decal image
vec3_t position; // location of the decal center in world space.
2010-07-01 22:00:00 +02:00
vec3_t worldPos; // untransformed position, keep for serialization
2010-06-29 22:00:00 +02:00
vec3_t saxis; // direction of the s axis in world space
2010-06-30 22:00:00 +02:00
float dx, dy; // Offsets into surface texture
2010-06-29 22:00:00 +02:00
float scale; // pixel scale
short flags; // decal flags FDECAL_*
short entityIndex; // entity this is attached to
2010-06-30 22:00:00 +02:00
mesh_t *mesh; // cached mesh, created on first decal rendering
2010-06-29 22:00:00 +02:00
2010-06-30 22:00:00 +02:00
// dynamic decals stuff
2010-06-29 22:00:00 +02:00
float fadeDuration; // Negative value means to fade in
float fadeStartTime;
2010-07-01 22:00:00 +02:00
float currentFrame; // for animated decals
2010-06-29 22:00:00 +02:00
rgba_t color;
} decal_t;
2010-05-24 22:00:00 +02:00
// miptex features (will be convert to a shader settings)
#define MIPTEX_CONVEYOR BIT( 0 ) // create conveyour surface
#define MIPTEX_LIQUID BIT( 1 ) // is a liquid
#define MIPTEX_TRANSPARENT BIT( 2 ) // transparent texture
#define MIPTEX_RENDERMODE BIT( 3 ) // this surface requires a rendermode stuff
2010-06-01 22:00:00 +02:00
#define MIPTEX_NOLIGHTMAP BIT( 4 ) // this surface if fullbright
2010-06-16 22:00:00 +02:00
#define MIPTEX_WARPSURFACE BIT( 5 ) // this surface is warped
2010-05-24 22:00:00 +02:00
2010-05-22 22:00:00 +02:00
typedef struct mtexinfo_s
{
float vecs[2][4];
short texturenum; // number in cached.textures
2010-06-16 22:00:00 +02:00
short width;
short height;
2010-05-22 22:00:00 +02:00
} mtexinfo_t;
2010-06-29 22:00:00 +02:00
typedef struct msurface_s
2008-11-15 22:00:00 +01:00
{
2010-05-22 22:00:00 +02:00
int visframe; // should be drawn when node is crossed
int flags; // see SURF_ for details
2009-10-28 22:00:00 +01:00
int contents;
2009-07-12 22:00:00 +02:00
2010-05-22 22:00:00 +02:00
int firstedge; // look up in model->edges[]. negative
int numedges; // numbers are backwards edges
short textureMins[2];
short extents[2];
mtexinfo_t *texinfo;
2009-08-05 22:00:00 +02:00
ref_shader_t *shader;
mesh_t *mesh;
mfog_t *fog;
2010-06-29 22:00:00 +02:00
decal_t *pdecals; // linked surface decals
2010-08-12 22:00:00 +02:00
mplane_t *plane;
2009-07-12 22:00:00 +02:00
union
{
2009-08-05 22:00:00 +02:00
float origin[3];
float mins[3];
2009-07-12 22:00:00 +02:00
};
union
{
2009-08-05 22:00:00 +02:00
float maxs[3];
float color[3];
2009-07-12 22:00:00 +02:00
};
2010-05-22 22:00:00 +02:00
// lighting info
int lmWidth;
int lmHeight;
int lmS;
int lmT;
2010-05-31 22:00:00 +02:00
int lmNum; // real lightmap texnum
2010-05-22 22:00:00 +02:00
byte *samples;
int numstyles;
2010-05-31 22:00:00 +02:00
byte styles[LM_STYLES];
float cached[LM_STYLES]; // values currently used in lightmap
2010-05-22 22:00:00 +02:00
2010-06-01 22:00:00 +02:00
int superLightStyle;
2010-05-31 22:00:00 +02:00
int fragmentframe; // for multi-check avoidance
2009-07-12 22:00:00 +02:00
} msurface_t;
2010-05-22 22:00:00 +02:00
#define CONTENTS_NODE 1 // fake contents to determine nodes
2009-07-12 22:00:00 +02:00
typedef struct mnode_s
{
// common with leaf
2010-08-12 22:00:00 +02:00
mplane_t *plane;
2009-08-05 22:00:00 +02:00
int pvsframe;
2010-05-22 22:00:00 +02:00
int contents; // for fast checking solid leafs
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
float mins[3];
float maxs[3]; // for bounding box culling
2009-07-12 22:00:00 +02:00
struct mnode_s *parent;
2008-11-15 22:00:00 +01:00
2009-07-12 22:00:00 +02:00
// node specific
struct mnode_s *children[2];
2010-05-22 22:00:00 +02:00
msurface_t *firstface; // used for grab lighting info, decals etc
uint numfaces;
2009-07-12 22:00:00 +02:00
} mnode_t;
typedef struct mleaf_s
2008-11-15 22:00:00 +01:00
{
2009-07-12 22:00:00 +02:00
// common with node
2010-08-12 22:00:00 +02:00
mplane_t *plane;
2009-08-05 22:00:00 +02:00
int pvsframe;
2010-05-22 22:00:00 +02:00
int contents;
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
float mins[3];
float maxs[3]; // for bounding box culling
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
struct mnode_s *parent;
2008-11-15 22:00:00 +01:00
2009-07-12 22:00:00 +02:00
// leaf specific
2010-05-22 22:00:00 +02:00
byte *compressed_vis;
2009-08-05 22:00:00 +02:00
int visframe;
2008-11-15 22:00:00 +01:00
2010-05-22 22:00:00 +02:00
msurface_t **firstMarkSurface;
int numMarkSurfaces;
2009-07-12 22:00:00 +02:00
} mleaf_t;
2008-11-15 22:00:00 +01:00
2009-07-12 22:00:00 +02:00
typedef struct
{
2009-08-05 22:00:00 +02:00
byte ambient[LM_STYLES][3];
byte diffuse[LM_STYLES][3];
byte styles[LM_STYLES];
byte direction[2];
2009-07-12 22:00:00 +02:00
} mgridlight_t;
typedef struct
2008-11-15 22:00:00 +01:00
{
2009-08-05 22:00:00 +02:00
int texNum;
float texMatrix[2][2];
2009-07-12 22:00:00 +02:00
} mlightmapRect_t;
typedef struct
{
2009-08-05 22:00:00 +02:00
int numsubmodels;
2009-07-12 22:00:00 +02:00
mmodel_t *submodels;
2009-08-05 22:00:00 +02:00
int nummodelsurfaces;
msurface_t *firstmodelsurface;
2009-07-12 22:00:00 +02:00
2010-05-22 22:00:00 +02:00
mnode_t *firstmodelnode; // used for lighting bmodels
2009-08-05 22:00:00 +02:00
int numplanes;
2010-08-12 22:00:00 +02:00
mplane_t *planes;
2009-07-12 22:00:00 +02:00
2010-05-22 22:00:00 +02:00
int numleafs; // number of visible leafs, not counting 0
2009-08-05 22:00:00 +02:00
mleaf_t *leafs;
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
int numnodes;
mnode_t *nodes;
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
int numsurfaces;
msurface_t *surfaces;
2010-05-22 22:00:00 +02:00
msurface_t **marksurfaces;
2009-07-12 22:00:00 +02:00
2010-06-06 22:00:00 +02:00
int numgridpoints;
2009-07-12 22:00:00 +02:00
mgridlight_t *lightgrid;
2010-05-22 22:00:00 +02:00
int numtexinfo;
mtexinfo_t *texinfo;
byte *visdata; // compressed visdata
byte *lightdata;
2009-08-05 22:00:00 +02:00
int numfogs;
mfog_t *fogs;
mfog_t *globalfog;
2009-07-12 22:00:00 +02:00
2009-08-05 22:00:00 +02:00
vec3_t gridSize;
vec3_t gridMins;
int gridBounds[4];
2009-07-12 22:00:00 +02:00
} mbrushmodel_t;
/*
==============================================================================
2009-08-02 22:00:00 +02:00
STUDIO MODELS
2009-07-12 22:00:00 +02:00
==============================================================================
*/
2010-07-08 22:00:00 +02:00
typedef struct
2009-08-30 22:00:00 +02:00
{
2010-07-08 22:00:00 +02:00
studiohdr_t *phdr;
studiohdr_t *thdr;
2009-08-30 22:00:00 +02:00
void *submodels;
int numsubmodels;
vec3_t *m_pSVectors; // UNDONE: calc SVectors on loading, simple transform on rendering
2010-07-08 22:00:00 +02:00
} mstudiodata_t;
2009-07-12 22:00:00 +02:00
/*
==============================================================================
SPRITE MODELS
==============================================================================
*/
//
// in memory representation
//
2009-08-04 22:00:00 +02:00
typedef struct mspriteframe_s
2009-07-12 22:00:00 +02:00
{
2009-08-04 22:00:00 +02:00
int width;
int height;
float up, down, left, right;
float radius;
shader_t shader;
} mspriteframe_t;
2009-07-12 22:00:00 +02:00
2009-08-04 22:00:00 +02:00
typedef struct
{
int numframes;
float *intervals;
mspriteframe_t *frames[1];
} mspritegroup_t;
2009-07-12 22:00:00 +02:00
2009-08-04 22:00:00 +02:00
typedef struct
{
frametype_t type;
mspriteframe_t *frameptr;
} mspriteframedesc_t;
2009-07-12 22:00:00 +02:00
typedef struct
{
2009-08-04 22:00:00 +02:00
int type;
int rendermode;
2009-08-02 22:00:00 +02:00
int numframes;
2009-08-04 22:00:00 +02:00
mspriteframedesc_t frames[1];
} msprite_t;
2009-07-12 22:00:00 +02:00
//===================================================================
//
// Whole model
//
typedef struct ref_model_s
{
2009-08-01 22:00:00 +02:00
char *name;
2009-07-12 22:00:00 +02:00
modtype_t type;
2009-09-04 22:00:00 +02:00
int touchFrame; // registration sequence
2009-07-12 22:00:00 +02:00
// volume occupied by the model graphics
2009-08-01 22:00:00 +02:00
vec3_t mins, maxs;
float radius;
2009-08-28 22:00:00 +02:00
int flags; // effect flags
2009-07-12 22:00:00 +02:00
// memory representation pointer
2009-08-01 22:00:00 +02:00
byte *mempool;
void *extradata;
2009-07-12 22:00:00 +02:00
2009-08-01 22:00:00 +02:00
// shader pointers for refresh registration_sequence
int numshaders;
ref_shader_t **shaders;
2009-07-12 22:00:00 +02:00
} ref_model_t;
//============================================================================
void R_InitModels( void );
void R_ShutdownModels( void );
void Mod_ClearAll( void );
2009-08-02 22:00:00 +02:00
ref_model_t *Mod_ForName( const char *name, bool crash );
2010-05-22 22:00:00 +02:00
mleaf_t *Mod_PointInLeaf( const vec3_t p, ref_model_t *model );
byte *Mod_LeafPVS( mleaf_t *leaf, ref_model_t *model );
2009-08-02 22:00:00 +02:00
uint Mod_Handle( ref_model_t *mod );
ref_model_t *Mod_ForHandle( unsigned int elem );
2009-09-01 22:00:00 +02:00
ref_model_t *R_RegisterModel( const char *name );
2010-05-27 22:00:00 +02:00
void R_BeginRegistration( const char *model );
2009-09-01 22:00:00 +02:00
void R_EndRegistration( const char *skyname );
2010-06-10 22:00:00 +02:00
texture_t *Mod_LoadTexture( mip_t *mt );
2009-07-12 22:00:00 +02:00
2009-08-02 22:00:00 +02:00
#define Mod_Malloc( mod, size ) Mem_Alloc(( mod )->mempool, size )
2009-08-08 22:00:00 +02:00
#define Mod_Realloc( mod, data, size ) Mem_Realloc(( mod )->mempool, data, size )
2009-07-12 22:00:00 +02:00
#define Mod_Free( data ) Mem_Free( data )
void Mod_Modellist_f( void );
2008-11-15 22:00:00 +01:00
2009-09-04 22:00:00 +02:00
#endif // R_MODEL_H