yquake2remaster/src/client/refresh/gl3/gl3_md2.c

164 lines
4.2 KiB
C
Raw Normal View History

2010-10-21 08:19:32 +00:00
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* 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.
*
* 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.
*
* =======================================================================
*
* MD2 file format
*
* =======================================================================
*/
#include "header/local.h"
2010-10-21 08:19:32 +00:00
void
GL3_LoadMD2(gl3model_t *mod, void *buffer)
2010-10-21 08:19:32 +00:00
{
int i, j;
2012-07-21 12:09:45 +00:00
dmdl_t *pinmodel, *pheader;
dstvert_t *pinst, *poutst;
dtriangle_t *pintri, *pouttri;
daliasframe_t *pinframe, *poutframe;
int *pincmd, *poutcmd;
2010-10-21 08:19:32 +00:00
int version;
2012-07-21 12:09:45 +00:00
pinmodel = (dmdl_t *)buffer;
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
version = LittleLong(pinmodel->version);
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
if (version != ALIAS_VERSION)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "%s has wrong version number (%i should be %i)",
2012-07-21 12:09:45 +00:00
mod->name, version, ALIAS_VERSION);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
pheader = Hunk_Alloc(LittleLong(pinmodel->ofs_end));
2010-10-21 08:19:32 +00:00
/* byte swap the header fields and sanity check */
2012-07-21 12:09:45 +00:00
for (i = 0; i < sizeof(dmdl_t) / 4; i++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
((int *)pheader)[i] = LittleLong(((int *)buffer)[i]);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
if (pheader->skinheight > MAX_LBM_HEIGHT)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "model %s has a skin taller than %d", mod->name,
2012-07-21 12:09:45 +00:00
MAX_LBM_HEIGHT);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
if (pheader->num_xyz <= 0)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "model %s has no vertices", mod->name);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
if (pheader->num_xyz > MAX_VERTS)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "model %s has too many vertices", mod->name);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
if (pheader->num_st <= 0)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "model %s has no st vertices", mod->name);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
if (pheader->num_tris <= 0)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "model %s has no triangles", mod->name);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
if (pheader->num_frames <= 0)
2010-10-21 08:19:32 +00:00
{
ri.Sys_Error(ERR_DROP, "model %s has no frames", mod->name);
2010-10-21 08:19:32 +00:00
}
/* load base s and t vertices (not used in gl version) */
2012-07-21 12:09:45 +00:00
pinst = (dstvert_t *)((byte *)pinmodel + pheader->ofs_st);
poutst = (dstvert_t *)((byte *)pheader + pheader->ofs_st);
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
for (i = 0; i < pheader->num_st; i++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
poutst[i].s = LittleShort(pinst[i].s);
poutst[i].t = LittleShort(pinst[i].t);
2010-10-21 08:19:32 +00:00
}
/* load triangle lists */
2012-07-21 12:09:45 +00:00
pintri = (dtriangle_t *)((byte *)pinmodel + pheader->ofs_tris);
pouttri = (dtriangle_t *)((byte *)pheader + pheader->ofs_tris);
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
for (i = 0; i < pheader->num_tris; i++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
for (j = 0; j < 3; j++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
pouttri[i].index_xyz[j] = LittleShort(pintri[i].index_xyz[j]);
pouttri[i].index_st[j] = LittleShort(pintri[i].index_st[j]);
2010-10-21 08:19:32 +00:00
}
}
/* load the frames */
2012-07-21 12:09:45 +00:00
for (i = 0; i < pheader->num_frames; i++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
pinframe = (daliasframe_t *)((byte *)pinmodel
+ pheader->ofs_frames + i * pheader->framesize);
poutframe = (daliasframe_t *)((byte *)pheader
+ pheader->ofs_frames + i * pheader->framesize);
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
memcpy(poutframe->name, pinframe->name, sizeof(poutframe->name));
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
for (j = 0; j < 3; j++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
poutframe->scale[j] = LittleFloat(pinframe->scale[j]);
poutframe->translate[j] = LittleFloat(pinframe->translate[j]);
2010-10-21 08:19:32 +00:00
}
/* verts are all 8 bit, so no swapping needed */
2012-07-21 12:09:45 +00:00
memcpy(poutframe->verts, pinframe->verts,
pheader->num_xyz * sizeof(dtrivertx_t));
2010-10-21 08:19:32 +00:00
}
mod->type = mod_alias;
/* load the glcmds */
2012-07-21 12:09:45 +00:00
pincmd = (int *)((byte *)pinmodel + pheader->ofs_glcmds);
poutcmd = (int *)((byte *)pheader + pheader->ofs_glcmds);
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
for (i = 0; i < pheader->num_glcmds; i++)
2010-10-21 08:19:32 +00:00
{
2012-07-21 12:09:45 +00:00
poutcmd[i] = LittleLong(pincmd[i]);
2010-10-21 08:19:32 +00:00
}
/* register all skins */
2012-07-21 12:09:45 +00:00
memcpy((char *)pheader + pheader->ofs_skins,
(char *)pinmodel + pheader->ofs_skins,
pheader->num_skins * MAX_SKINNAME);
2010-10-21 08:19:32 +00:00
2012-07-21 12:09:45 +00:00
for (i = 0; i < pheader->num_skins; i++)
2010-10-21 08:19:32 +00:00
{
mod->skins[i] = GL3_FindImage(
2012-07-21 12:09:45 +00:00
(char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME,
it_skin);
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00
mod->mins[0] = -32;
mod->mins[1] = -32;
mod->mins[2] = -32;
mod->maxs[0] = 32;
mod->maxs[1] = 32;
mod->maxs[2] = 32;
2010-10-21 08:19:32 +00:00
}
2012-07-21 12:09:45 +00:00