-
Notifications
You must be signed in to change notification settings - Fork 2
/
md3gl.h
executable file
·211 lines (167 loc) · 6.77 KB
/
md3gl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
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 3 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MD3_GL_H_
#define _MD3_GL_H_
#include "mdr.h"
typedef struct
{
unsigned char *Data; // actual texture bitmap
unsigned int Width, Height; // size of TextureData
GLenum _Type; // type of texture ie. (not actually used)
GLuint Bind; // id the texture is bound to
char *File; // allocated string storing path name
int numUsed;
} TextureGL;
typedef struct
{
GLuint *textureBinds; // array of texture binds, one for each mesh
int topTextureBind;
Vec3 *iterVerts; // arrays of vertices for interpolation, one for each mesh
NodeDictionary textureRes; // map of texture names to TextureGL data, stores texture resources
} MD3GL;
typedef struct
{
Vec3 *pVerts;
short *pNormalIndexes;
} FMeshFrame;
/*
run time model data structure
*/
struct gl_mesh
{
char sName[64];
unsigned int iNumVertices; // number of vertices in model
unsigned int iNumTriangles; // number of triangles in gl_model
unsigned int iNumMeshFrames; // same as global frame but convenient
TriVec *triangles; // array of triangle vertex indices of size iNumTriangles
TexVec *textureCoord; // array of float s/t texture coordinates of size iNumVertices
FMeshFrame *meshFrames; // 2d array of size of [iNumFrames][vertexNum] stores mesh frame vertices
Vec3 *iterMesh; // buffer mesh frame used to store interpolated mesh of size vertexNum
unsigned int iNumSkins; // number of skins this model has
GLuint *bindings; // array of texture bindings of size skinNum;
char sTextureName[MAX_QPATH]; // only bother storing first one
};
struct gl_model;
struct gl_model
{
// common to any model format:
//
modelType_t modelType;
unsigned int iNumFrames; // number of frames in gl_model
unsigned int iNumTags; // number of tags in gl_model
unsigned int currentFrame; // current frame being displayed
// tag info is duplicated here, even for MDR types, so rest of code works ok
TagFrame *tags; // 2d array of tags size [iNumFrames][iNumTags]
gl_model **linkedModels; // array of links of size iNumTags, each link corresponds to a tag
gl_model *parent;
// some stuff for dealing with MD3 LODs (which are actually seperate models)...
//
gl_model *pModel_LOD0; // for the LOD0 (default) model, this will be NULL, for other LODs, this will point at original LOD0 model)
gl_model *pModel_LOD1;
gl_model *pModel_LOD2;
// other stuff...
//
unsigned int iNumMeshes; // number of meshes in whole model
NodePosition modelListPosition; // link to its mdview.modelList
float CTM_matrix[16]; // object transformation matrix for manipulating mesh
gl_mesh *pMeshes; // array of meshes of size meshNum
md3BoundFrame_t *pMD3BoundFrames; // array of boundary frames size [iNumFrames]
// this requires more work once the script parser is done
bool isBlended;
GLenum blendParam1, blendParam2;
int iRenderedTris;
int iRenderedVerts;
char sHeadSkinName[32]; // should be enough
char sMD3BaseName[1024];
char sMDXFullPathname[1024];
model_t Q3ModelStuff;
};
#define NEAR_GL_PLANE 0.1
#define FAR_GL_PLANE 512
void initialize_glstate();
bool loadmd3gl( MD3GL &data );
void rendermd3gl( MD3GL &mdl );
void freemd3gl( MD3GL &data );
void renderFrame();
bool bIsWireFrame(void);
bool bIsTextured(void);
void oglStateFlatTextured();
void oglStateShadedTexturedAndWireFrame();
void oglStateShadedTextured();
void oglStateShadedFlat();
void oglStateWireframe();
/*
damn smart and efficient texture loader,
first searches for an existing teature name is parent directories
then checks if texture has already been loaded,
otherwise it loads it up, enters in textureRes manager and returns the new binding
*/
extern bool gbIgnoreTextureLoad;
GLuint loadTexture( LPCSTR texturepath );
/*
frees a texture resource, called whenever a mesh is being freed. a texture is freed only if nothing is using it anymore
*/
void freeTexture( GLuint bind );
/*
deletes the entire texture resource manager with all its textures, usually called at the end of the program
or when a whole new model is loaded
*/
void freeTextureRes();
/*
reloads all texture resources from disk
*/
void refreshTextureRes();
/*
chooses the specific filter to be applied based on current mode
*/
void setTextureToFilter();
/*
sets texture parameters to the current texMode
*/
void setTextureFilter();
/*
renders the current frame
*/
void draw_view();
void draw_viewSkeleton();
typedef unsigned int glIndex_t;
typedef struct shaderCommands_s
{
glIndex_t indexes[SHADER_MAX_INDEXES];
vec4_t xyz[SHADER_MAX_VERTEXES];
vec4_t normal[SHADER_MAX_VERTEXES];
vec2_t texCoords[SHADER_MAX_VERTEXES][2];
/* color4ub_t vertexColors[SHADER_MAX_VERTEXES];
int vertexDlightBits[SHADER_MAX_VERTEXES];
stageVars_t svars;
color4ub_t constantColor255[SHADER_MAX_VERTEXES];
shader_t *shader;
int fogNum;
int dlightBits; // or together of all vertexDlightBits
*/
int numIndexes;
int numVertexes;
/*
// info extracted from current shader
int numPasses;
void (*currentStageIteratorFunc)( void );
shaderStage_t **xstages;
*/
} shaderCommands_t;
LPCSTR SkinName_FromPathedModelName(LPCSTR psModelPathName);
bool Model_ApplySkin(gl_model* model, LPCSTR psSkinFilename);
bool ApplyNewSkin(LPCSTR psSkinFullPathName);
gl_model* R_FindModel( gl_model* model, LPCSTR psModelBaseName);
shaderCommands_t* Freeze_Surface( md4Surface_t *surface, int iFrame );
#endif