From 26a878da48aa1f46c9aa6131fb5672f2fbfcb791 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 27 Apr 2012 14:40:06 +0900 Subject: [PATCH] Stub out the iqm loader. --- config.d/ac_config_files.m4 | 1 + config.d/build_control.m4 | 6 ++ include/QF/Makefile.am | 14 +-- include/QF/iqm.h | 117 ++++++++++++++++++++++++++ include/QF/model.h | 2 +- include/QF/plugin/vid_render.h | 1 + include/mod_internal.h | 1 + libs/models/Makefile.am | 5 +- libs/models/iqm/Makefile.am | 20 +++++ libs/models/iqm/gl_model_iqm.c | 53 ++++++++++++ libs/models/iqm/glsl_model_iqm.c | 51 +++++++++++ libs/models/iqm/model_iqm.c | 56 ++++++++++++ libs/models/iqm/sw_model_iqm.c | 47 +++++++++++ libs/models/model.c | 7 ++ libs/video/renderer/vid_render_gl.c | 1 + libs/video/renderer/vid_render_glsl.c | 1 + libs/video/renderer/vid_render_sw.c | 1 + libs/video/renderer/vid_render_sw32.c | 1 + 18 files changed, 376 insertions(+), 9 deletions(-) create mode 100644 include/QF/iqm.h create mode 100644 libs/models/iqm/Makefile.am create mode 100644 libs/models/iqm/gl_model_iqm.c create mode 100644 libs/models/iqm/glsl_model_iqm.c create mode 100644 libs/models/iqm/model_iqm.c create mode 100644 libs/models/iqm/sw_model_iqm.c diff --git a/config.d/ac_config_files.m4 b/config.d/ac_config_files.m4 index eaab675e1..a30263195 100644 --- a/config.d/ac_config_files.m4 +++ b/config.d/ac_config_files.m4 @@ -15,6 +15,7 @@ libs/models/Makefile libs/models/alias/Makefile libs/models/brush/Makefile + libs/models/iqm/Makefile libs/models/sprite/Makefile libs/models/test/Makefile libs/net/Makefile diff --git a/config.d/build_control.m4 b/config.d/build_control.m4 index 749c88bf0..9d0efa9aa 100644 --- a/config.d/build_control.m4 +++ b/config.d/build_control.m4 @@ -43,6 +43,7 @@ if test "x$HAVE_FBDEV" = xyes; then QF_NEED(models, [sw]) QF_NEED(alias, [sw]) QF_NEED(brush, [sw]) + QF_NEED(iqm, [sw]) QF_NEED(sprite, [sw]) if test "x$ASM_ARCH" = "xyes"; then QF_NEED(swrend, [asm]) @@ -71,6 +72,7 @@ if test "x$HAVE_X" = xyes; then QF_NEED(models, [sw gl glsl]) QF_NEED(alias, [sw gl glsl]) QF_NEED(brush, [sw gl glsl]) + QF_NEED(iqm, [sw gl glsl]) QF_NEED(sprite, [sw gl glsl]) if test "x$ASM_ARCH" = "xyes"; then QF_NEED(swrend, [asm]) @@ -93,6 +95,7 @@ if test "x$HAVE_SDL" = xyes; then QF_NEED(models, [sw gl glsl]) QF_NEED(alias, [sw gl glsl]) QF_NEED(brush, [sw gl glsl]) + QF_NEED(iqm, [sw gl glsl]) QF_NEED(sprite, [sw gl glsl]) if test "x$ASM_ARCH" = "xyes"; then QF_NEED(swrend, [asm]) @@ -113,6 +116,7 @@ if test "x$HAVE_SVGA" = xyes; then QF_NEED(models, [sw]) QF_NEED(alias, [sw]) QF_NEED(brush, [sw]) + QF_NEED(iqm, [sw]) QF_NEED(sprite, [sw]) if test "x$ASM_ARCH" = "xyes"; then QF_NEED(swrend, [asm]) @@ -133,6 +137,7 @@ fi # QF_NEED(models, [gl]) # QF_NEED(alias, [gl]) # QF_NEED(brush, [gl]) +# QF_NEED(iqm, [gl]) # QF_NEED(sprite, [gl]) # QF_NEED(vid, [common]) # QF_NEED(qw, [client common]) @@ -228,6 +233,7 @@ QF_PROCESS_NEED_DIRS(vid_render, [gl glsl sw sw32]) QF_PROCESS_NEED_LIBS(models, [gl glsl sw]) QF_PROCESS_NEED_LIBS(alias, [gl glsl sw]) QF_PROCESS_NEED_LIBS(brush, [gl glsl sw]) +QF_PROCESS_NEED_LIBS(iqm, [gl glsl sw]) QF_PROCESS_NEED_LIBS(sprite, [gl glsl sw]) QF_PROCESS_NEED_LIBS(vid, [common sdl svga x11]) diff --git a/include/QF/Makefile.am b/include/QF/Makefile.am index 952761b70..4ed32aecc 100644 --- a/include/QF/Makefile.am +++ b/include/QF/Makefile.am @@ -3,13 +3,13 @@ pkgincludedir = $(includedir)/QF nobase_pkginclude_HEADERS = \ bspfile.h cbuf.h cdaudio.h checksum.h clip_hull.h cmd.h \ console.h crc.h csqc.h cvar.h dstring.h draw.h gib.h hash.h hl.h \ - idparse.h image.h in_event.h info.h input.h joystick.h keys.h link.h \ - llist.h locs.h mathlib.h mdfour.h model.h modelgen.h msg.h object.h pak.h \ - pakfile.h pcx.h png.h plugin.h pr_comp.h pr_debug.h pr_obj.h progs.h \ - qargs.h qdefs.h qendian.h qfplist.h qtypes.h quakefs.h quakeio.h render.h \ - riff.h ruamoko.h screen.h script.h sizebuf.h skin.h sound.h spritegn.h \ - sys.h teamplay.h tga.h uint32.h va.h ver_check.h vid.h vrect.h view.h \ - wad.h wadfile.h winding.h zone.h \ + idparse.h image.h in_event.h info.h input.h iqm.h joystick.h keys.h \ + link.h llist.h locs.h mathlib.h mdfour.h model.h modelgen.h msg.h \ + object.h pak.h pakfile.h pcx.h png.h plugin.h pr_comp.h pr_debug.h \ + pr_obj.h progs.h qargs.h qdefs.h qendian.h qfplist.h qtypes.h quakefs.h \ + quakeio.h render.h riff.h ruamoko.h screen.h script.h sizebuf.h skin.h \ + sound.h spritegn.h sys.h teamplay.h tga.h uint32.h va.h ver_check.h vid.h \ + vrect.h view.h wad.h wadfile.h winding.h zone.h \ \ GL/ati.h GL/defines.h GL/extensions.h GL/funcs.h GL/qf_explosions.h \ GL/qf_funcs_list.h GL/qf_lightmap.h \ diff --git a/include/QF/iqm.h b/include/QF/iqm.h new file mode 100644 index 000000000..4dcaede6e --- /dev/null +++ b/include/QF/iqm.h @@ -0,0 +1,117 @@ +#ifndef __QF_iqm_h__ +#define __QF_iqm_h__ + +#include "QF/qtypes.h" + +#define IQM_MAGIC "INTERQUAKEMODEL" +#define IQM_SMAGIC 0x45544e49 +#define IQM_VERSION 2 + +typedef struct iqmheader_s { + char magic[16]; + uint32_t version; + uint32_t filesize; + uint32_t flags; + uint32_t num_text, ofs_text; + uint32_t num_meshes, ofs_meshes; + uint32_t num_vertexarrays, num_vertexes, ofs_vertexarrays; + uint32_t num_triangles, ofs_triangles, ofs_adjacency; + uint32_t num_joints, ofs_joints; + uint32_t num_poses, ofs_poses; + uint32_t num_anims, ofs_anims; + uint32_t num_frames, num_framechannels, ofs_frames, ofs_bounds; + uint32_t num_comment, ofs_comment; + uint32_t num_extensions, ofs_extensions; +} iqmheader; + +typedef struct iqmmesh_s { + uint32_t name; + uint32_t material; + uint32_t first_vertex, num_vertexes; + uint32_t first_triangle, num_triangles; +} iqmmesh; + +enum { + IQM_POSITION = 0, + IQM_TEXCOORD = 1, + IQM_NORMAL = 2, + IQM_TANGENT = 3, + IQM_BLENDINDEXES = 4, + IQM_BLENDWEIGHTS = 5, + IQM_COLOR = 6, + IQM_CUSTOM = 0x10 +}; + +enum { + IQM_BYTE = 0, + IQM_UBYTE = 1, + IQM_SHORT = 2, + IQM_USHORT = 3, + IQM_INT = 4, + IQM_UINT = 5, + IQM_HALF = 6, + IQM_FLOAT = 7, + IQM_DOUBLE = 8 +}; + +typedef struct iqmtriangle_s { + uint32_t vertex[3]; +} iqmtriangle; + +typedef struct iqmjointv1_s { + uint32_t name; + int32_t parent; + float translate[3], rotate[3], scale[3]; +} iqmjointv1; + +typedef struct iqmjoint_s { + uint32_t name; + int32_t parent; + float translate[3], rotate[4], scale[3]; +} iqmjoint; + +typedef struct iqmposev1_s { + int32_t parent; + uint32_t mask; + float channeloffset[9]; + float channelscale[9]; +} iqmposev1; + +typedef struct iqmpose_s { + int32_t parent; + uint32_t mask; + float channeloffset[10]; + float channelscale[10]; +} iqmpose; + +typedef struct iqmanim_s { + uint32_t name; + uint32_t first_frame, num_frames; + float framerate; + uint32_t flags; +} iqmanim; + +enum { + IQM_LOOP = 1<<0 +}; + +typedef struct iqmvertexarray_s { + uint32_t type; + uint32_t flags; + uint32_t format; + uint32_t size; + uint32_t offset; +} iqmvertexarray; + +typedef struct iqmbounds_s { + float bbmin[3], bbmax[3]; + float xyradius, radius; +} iqmbounds; + +typedef struct iqmextension_s { + uint32_t name; + uint32_t num_data, ofs_data; + uint32_t ofs_extensions; // pointer to next extension +} iqmextension; + +#endif//__QF_iqm_h__ diff --git a/include/QF/model.h b/include/QF/model.h index e89fbc7bc..e83a3fc21 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -333,7 +333,7 @@ extern int aliasbboxmaxs[3]; // Whole model ================================================================ -typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t; +typedef enum {mod_brush, mod_sprite, mod_alias, mod_iqm} modtype_t; #define EF_ROCKET 1 // leave a trail #define EF_GRENADE 2 // leave a trail diff --git a/include/QF/plugin/vid_render.h b/include/QF/plugin/vid_render.h index f316fcff5..343666dd7 100644 --- a/include/QF/plugin/vid_render.h +++ b/include/QF/plugin/vid_render.h @@ -84,6 +84,7 @@ typedef struct vid_model_funcs_s { void (*Mod_LoadLighting) (bsp_t *bsp); void (*Mod_SubdivideSurface) (msurface_t *fa); void (*Mod_ProcessTexture) (texture_t *tx); + void (*Mod_LoadIQM) (model_t *mod, void *buffer); void (*Mod_LoadAliasModel) (model_t *mod, void *buffer, cache_allocator_t allocator); void (*Mod_LoadSpriteModel) (model_t *mod, void *buffer); diff --git a/include/mod_internal.h b/include/mod_internal.h index 31673c8c3..b9dac0fb5 100644 --- a/include/mod_internal.h +++ b/include/mod_internal.h @@ -47,6 +47,7 @@ void gl_Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum); void glsl_Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum); void sw_Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum); +void Mod_LoadIQM (model_t *mod, void *buffer); void Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator); void Mod_LoadSpriteModel (model_t *mod, void *buffer); diff --git a/libs/models/Makefile.am b/libs/models/Makefile.am index e1223969e..425679829 100644 --- a/libs/models/Makefile.am +++ b/libs/models/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS= foreign -SUBDIRS= alias brush sprite . test +SUBDIRS= alias brush iqm sprite . test AM_CFLAGS= @PREFER_PIC@ INCLUDES= -I$(top_srcdir)/include @@ -27,6 +27,7 @@ gl_sources=gl_model_fullbright.c gl_skin.c skin.c gl_libs= \ alias/libalias_gl.la \ brush/libbrush_gl.la \ + iqm/libiqm_gl.la \ sprite/libsprite_gl.la \ $(top_builddir)/libs/image/libQFimage.la libmodels_gl_la_LDFLAGS= @@ -37,6 +38,7 @@ libmodels_gl_la_SOURCES= $(gl_sources) glsl_libs= \ alias/libalias_glsl.la \ brush/libbrush_glsl.la \ + iqm/libiqm_glsl.la \ sprite/libsprite_glsl.la \ $(top_builddir)/libs/image/libQFimage.la libmodels_glsl_la_LDFLAGS= @@ -47,6 +49,7 @@ libmodels_glsl_la_SOURCES= glsl_skin.c skin.c sw_libs= \ alias/libalias_sw.la \ brush/libbrush_sw.la \ + iqm/libiqm_sw.la \ sprite/libsprite_sw.la \ $(top_builddir)/libs/image/libQFimage.la libmodels_sw_la_LDFLAGS= diff --git a/libs/models/iqm/Makefile.am b/libs/models/iqm/Makefile.am new file mode 100644 index 000000000..0603bdbbe --- /dev/null +++ b/libs/models/iqm/Makefile.am @@ -0,0 +1,20 @@ +AUTOMAKE_OPTIONS= foreign + +AM_CFLAGS= @PREFER_PIC@ +INCLUDES= -I$(top_srcdir)/include + +noinst_LTLIBRARIES= @iqm_libs@ +EXTRA_LTLIBRARIES=libiqm_gl.la libiqm_glsl.la libiqm_sw.la + +iqm_src= model_iqm.c +gl_src= gl_model_iqm.c +glsl_src= glsl_model_iqm.c +sw_src= sw_model_iqm.c + +libiqm_gl_la_SOURCES= $(gl_src) $(iqm_src) + +libiqm_glsl_la_SOURCES= $(glsl_src) $(iqm_src) + +libiqm_sw_la_SOURCES= $(sw_src) $(iqm_src) + +EXTRA_DIST= $(gl_src) $(glsl_src) $(sw_src) $(iqm_src) diff --git a/libs/models/iqm/gl_model_iqm.c b/libs/models/iqm/gl_model_iqm.c new file mode 100644 index 000000000..25591ad2e --- /dev/null +++ b/libs/models/iqm/gl_model_iqm.c @@ -0,0 +1,53 @@ +/* + gl_model_iqm.c + + iqm model processing for GLSL + + Copyright (C) 2011 Bill Currie + + Author: Bill Currie + Date: 2012/04/27 + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include "QF/image.h" +#include "QF/qendian.h" +#include "QF/quakefs.h" +#include "QF/skin.h" +#include "QF/sys.h" +#include "QF/va.h" +#include "QF/vid.h" +#include "QF/GL/qf_textures.h" + +#include "mod_internal.h" + +#include "compat.h" diff --git a/libs/models/iqm/glsl_model_iqm.c b/libs/models/iqm/glsl_model_iqm.c new file mode 100644 index 000000000..8e0f013a3 --- /dev/null +++ b/libs/models/iqm/glsl_model_iqm.c @@ -0,0 +1,51 @@ +/* + glsl_model_iqm.c + + iqm model processing for GLSL + + Copyright (C) 2011 Bill Currie + + Author: Bill Currie + Date: 2012/04/27 + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include + +#include "QF/va.h" + +#include "QF/GLSL/defines.h" +#include "QF/GLSL/funcs.h" +//#include "QF/GLSL/qf_iqm.h" +#include "QF/GLSL/qf_textures.h" + +#include "mod_internal.h" +#include "r_shared.h" diff --git a/libs/models/iqm/model_iqm.c b/libs/models/iqm/model_iqm.c new file mode 100644 index 000000000..fc2a19667 --- /dev/null +++ b/libs/models/iqm/model_iqm.c @@ -0,0 +1,56 @@ +/* + model_iqm.c + + iqm model processing + + Copyright (C) 2011 Bill Currie + + Author: Bill Currie + Date: 2012/04/27 + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include "QF/crc.h" +#include "QF/msg.h" +#include "QF/qendian.h" +#include "QF/quakefs.h" +#include "QF/sys.h" + +#include "compat.h" +#include "d_iface.h" +#include "mod_internal.h" +#include "r_local.h" + +void +Mod_LoadIQM (model_t *mod, void *buffer) +{ +} diff --git a/libs/models/iqm/sw_model_iqm.c b/libs/models/iqm/sw_model_iqm.c new file mode 100644 index 000000000..904d156ca --- /dev/null +++ b/libs/models/iqm/sw_model_iqm.c @@ -0,0 +1,47 @@ +/* + sw_model_iqm.c + + iqm model processing for SW + + Copyright (C) 2011 Bill Currie + + Author: Bill Currie + Date: 2012/04/27 + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include "QF/qendian.h" +#include "QF/sys.h" + +#include "compat.h" +#include "d_iface.h" +#include "mod_internal.h" diff --git a/libs/models/model.c b/libs/models/model.c index bcdab68d5..5a2b54ad8 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -39,6 +39,7 @@ #endif #include "QF/cvar.h" +#include "QF/iqm.h" #include "QF/model.h" #include "QF/qendian.h" #include "QF/quakefs.h" @@ -194,6 +195,12 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator) mod->hasfullbrights = false; switch (LittleLong (*buf)) { + case IQM_SMAGIC: + if (strequal ((char *) buf, IQM_MAGIC)) { + if (mod_funcs) + mod_funcs->Mod_LoadIQM (mod, buf); + } + break; case IDHEADER_MDL: // Type 6: Quake 1 .mdl case HEADER_MDL16: // QF Type 6 extended for 16bit precision if (strequal (mod->name, "progs/grenade.mdl")) { diff --git a/libs/video/renderer/vid_render_gl.c b/libs/video/renderer/vid_render_gl.c index 97abf554f..f13b37d06 100644 --- a/libs/video/renderer/vid_render_gl.c +++ b/libs/video/renderer/vid_render_gl.c @@ -47,6 +47,7 @@ static vid_model_funcs_t model_funcs = { gl_Mod_SubdivideSurface, gl_Mod_ProcessTexture, + Mod_LoadIQM, Mod_LoadAliasModel, Mod_LoadSpriteModel, diff --git a/libs/video/renderer/vid_render_glsl.c b/libs/video/renderer/vid_render_glsl.c index 7ac53c200..2ffe78b82 100644 --- a/libs/video/renderer/vid_render_glsl.c +++ b/libs/video/renderer/vid_render_glsl.c @@ -47,6 +47,7 @@ static vid_model_funcs_t model_funcs = { glsl_Mod_SubdivideSurface, glsl_Mod_ProcessTexture, + Mod_LoadIQM, Mod_LoadAliasModel, Mod_LoadSpriteModel, diff --git a/libs/video/renderer/vid_render_sw.c b/libs/video/renderer/vid_render_sw.c index e077d72d9..d232d7d8c 100644 --- a/libs/video/renderer/vid_render_sw.c +++ b/libs/video/renderer/vid_render_sw.c @@ -40,6 +40,7 @@ static vid_model_funcs_t model_funcs = { sw_Mod_SubdivideSurface, sw_Mod_ProcessTexture, + Mod_LoadIQM, Mod_LoadAliasModel, Mod_LoadSpriteModel, diff --git a/libs/video/renderer/vid_render_sw32.c b/libs/video/renderer/vid_render_sw32.c index 2a7128f24..e1bcd79a8 100644 --- a/libs/video/renderer/vid_render_sw32.c +++ b/libs/video/renderer/vid_render_sw32.c @@ -45,6 +45,7 @@ static vid_model_funcs_t model_funcs = { sw_Mod_SubdivideSurface, sw_Mod_ProcessTexture, + Mod_LoadIQM, Mod_LoadAliasModel, Mod_LoadSpriteModel,