Fix setinfo.
[xonotic/darkplaces.git] / model_sprite.c
index 5d82993..215d681 100644 (file)
@@ -23,8 +23,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // on the same machine.
 
 #include "quakedef.h"
-
-cvar_t r_mipsprites = {CVAR_SAVE, "r_mipsprites", "1"};
+#include "image.h"
+
+cvar_t r_mipsprites = {CVAR_SAVE, "r_mipsprites", "1", "mipmaps sprites so they render faster in the distance and do not display noise artifacts"};
+cvar_t r_labelsprites_scale = {CVAR_SAVE, "r_labelsprites_scale", "1", "global scale to apply to label sprites before conversion to HUD coordinates"};
+cvar_t r_labelsprites_roundtopixels = {CVAR_SAVE, "r_labelsprites_roundtopixels", "1", "try to make label sprites sharper by rounding their size to 0.5x or 1x and by rounding their position to whole pixels if possible"};
+cvar_t r_overheadsprites_perspective = {CVAR_SAVE, "r_overheadsprites_perspective", "5", "fake perspective effect for SPR_OVERHEAD sprites"};
+cvar_t r_overheadsprites_pushback = {CVAR_SAVE, "r_overheadsprites_pushback", "15", "how far to pull the SPR_OVERHEAD sprites toward the eye (used to avoid intersections with 3D models)"};
+cvar_t r_overheadsprites_scalex = {CVAR_SAVE, "r_overheadsprites_scalex", "1", "additional scale for overhead sprites for x axis"};
+cvar_t r_overheadsprites_scaley = {CVAR_SAVE, "r_overheadsprites_scaley", "1", "additional scale for overhead sprites for y axis"};
+cvar_t r_track_sprites = {CVAR_SAVE, "r_track_sprites", "1", "track SPR_LABEL* sprites by putting them as indicator at the screen border to rotate to"};
+cvar_t r_track_sprites_flags = {CVAR_SAVE, "r_track_sprites_flags", "1", "1: Rotate sprites accordingly, 2: Make it a continuous rotation"};
+cvar_t r_track_sprites_scalew = {CVAR_SAVE, "r_track_sprites_scalew", "1", "width scaling of tracked sprites"};
+cvar_t r_track_sprites_scaleh = {CVAR_SAVE, "r_track_sprites_scaleh", "1", "height scaling of tracked sprites"};
 
 /*
 ===============
@@ -34,57 +45,72 @@ Mod_SpriteInit
 void Mod_SpriteInit (void)
 {
        Cvar_RegisterVariable(&r_mipsprites);
+       Cvar_RegisterVariable(&r_labelsprites_scale);
+       Cvar_RegisterVariable(&r_labelsprites_roundtopixels);
+       Cvar_RegisterVariable(&r_overheadsprites_perspective);
+       Cvar_RegisterVariable(&r_overheadsprites_pushback);
+       Cvar_RegisterVariable(&r_overheadsprites_scalex);
+       Cvar_RegisterVariable(&r_overheadsprites_scaley);
+       Cvar_RegisterVariable(&r_track_sprites);
+       Cvar_RegisterVariable(&r_track_sprites_flags);
+       Cvar_RegisterVariable(&r_track_sprites_scalew);
+       Cvar_RegisterVariable(&r_track_sprites_scaleh);
 }
 
-void Mod_Sprite_StripExtension(char *in, char *out)
+static void Mod_SpriteSetupTexture(texture_t *texture, skinframe_t *skinframe, qboolean fullbright, qboolean additive)
 {
-       char *end;
-       end = in + strlen(in);
-       if ((end - in) >= 6)
-               if (strcmp(end - 6, ".spr32") == 0)
-                       end -= 6;
-       if ((end - in) >= 4)
-               if (strcmp(end - 4, ".spr") == 0)
-                       end -= 4;
-       while (in < end)
-               *out++ = *in++;
-       *out++ = 0;
+       if (!skinframe)
+               skinframe = R_SkinFrame_LoadMissing();
+       texture->offsetmapping = OFFSETMAPPING_OFF;
+       texture->offsetscale = 1;
+       texture->offsetbias = 0;
+       texture->specularscalemod = 1;
+       texture->specularpowermod = 1;
+       texture->basematerialflags = MATERIALFLAG_WALL;
+       texture->basealpha = 1.0f;
+       if (fullbright)
+               texture->basematerialflags |= MATERIALFLAG_FULLBRIGHT;
+       if (additive)
+               texture->basematerialflags |= MATERIALFLAG_ADD | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW;
+       else if (skinframe->hasalpha)
+               texture->basematerialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW;
+       texture->currentmaterialflags = texture->basematerialflags;
+       texture->materialshaderpass = texture->shaderpasses[0] = Mod_CreateShaderPass(loadmodel->mempool, skinframe);
+       texture->currentskinframe = skinframe;
+       texture->surfaceflags = 0;
+       texture->supercontents = SUPERCONTENTS_SOLID;
+       if (!(texture->basematerialflags & MATERIALFLAG_BLENDED))
+               texture->supercontents |= SUPERCONTENTS_OPAQUE;
+       texture->transparentsort = TRANSPARENTSORT_DISTANCE;
+       // WHEN ADDING DEFAULTS HERE, REMEMBER TO PUT DEFAULTS IN ALL LOADERS
+       // JUST GREP FOR "specularscalemod = 1".
 }
 
-void Mod_Sprite_SharedSetup(long datapointer, int version, int *palette)
+extern cvar_t gl_texturecompression_sprites;
+
+static void Mod_Sprite_SharedSetup(const unsigned char *datapointer, int version, const unsigned int *palette, qboolean additive)
 {
-       int                                     i, j, k, groupframes, realframes, x, y, origin[2], width, height;
+       int                                     i, j, groupframes, realframes, x, y, origin[2], width, height;
+       qboolean                        fullbright;
        dspriteframetype_t      *pinframetype;
        dspriteframe_t          *pinframe;
        dspritegroup_t          *pingroup;
        dspriteinterval_t       *pinintervals;
+       skinframe_t                     *skinframe;
        float                           modelradius, interval;
-       char                            tempname[MAX_QPATH], name[MAX_QPATH];
-       qbyte                           *pixbuf;
-       long                            startframes;
+       char                            name[MAX_QPATH], fogname[MAX_QPATH];
+       const void                      *startframes;
+       int                 texflags = (r_mipsprites.integer ? TEXF_MIPMAP : 0) | ((gl_texturecompression.integer && gl_texturecompression_sprites.integer) ? TEXF_COMPRESS : 0) | TEXF_ISSPRITE | TEXF_PICMIP | TEXF_ALPHA | TEXF_CLAMP;
        modelradius = 0;
 
-       Mod_Sprite_StripExtension(loadmodel->name, tempname);
-
        if (loadmodel->numframes < 1)
-               Host_Error ("Mod_Sprite_SharedSetup: Invalid # of frames: %d\n", loadmodel->numframes);
-
-       loadmodel->type = mod_sprite;
-       loadmodel->flags = EF_FULLBRIGHT;
+               Host_Error ("Mod_Sprite_SharedSetup: Invalid # of frames: %d", loadmodel->numframes);
 
        // LordHavoc: hack to allow sprites to be non-fullbright
+       fullbright = true;
        for (i = 0;i < MAX_QPATH && loadmodel->name[i];i++)
-       {
                if (loadmodel->name[i] == '!')
-               {
-                       loadmodel->flags &= ~EF_FULLBRIGHT;
-                       break;
-               }
-       }
-
-       // LordHavoc: 32bit textures
-       if (version != SPRITE_VERSION && version != SPRITE32_VERSION && version != SPRITEHL_VERSION)
-               Host_Error("Mod_Sprite_SharedSetup: unsupported version %i, only %i (quake), %i (HalfLife), and %i (sprite32) supported", version, SPRITE_VERSION, SPRITEHL_VERSION, SPRITE32_VERSION);
+                       fullbright = false;
 
 //
 // load the frames
@@ -119,10 +145,13 @@ void Mod_Sprite_SharedSetup(long datapointer, int version, int *palette)
                realframes += groupframes;
        }
 
-       loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
-       loadmodel->sprdata_frames = Mem_Alloc(loadmodel->mempool, sizeof(mspriteframe_t) * realframes);
+       loadmodel->animscenes = (animscene_t *)Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
+       loadmodel->sprite.sprdata_frames = (mspriteframe_t *)Mem_Alloc(loadmodel->mempool, sizeof(mspriteframe_t) * realframes);
+       loadmodel->num_textures = realframes;
+       loadmodel->num_texturesperskin = 1;
+       loadmodel->data_textures = (texture_t *)Mem_Alloc(loadmodel->mempool, sizeof(texture_t) * loadmodel->num_textures);
 
-       datapointer = startframes;
+       datapointer = (unsigned char *)startframes;
        realframes = 0;
        for (i = 0;i < loadmodel->numframes;i++)
        {
@@ -149,7 +178,7 @@ void Mod_Sprite_SharedSetup(long datapointer, int version, int *palette)
                                Host_Error("Mod_Sprite_SharedSetup: invalid interval");
                }
 
-               sprintf(loadmodel->animscenes[i].name, "frame %i", i);
+               dpsnprintf(loadmodel->animscenes[i].name, sizeof(loadmodel->animscenes[i].name), "frame %i", i);
                loadmodel->animscenes[i].firstframe = realframes;
                loadmodel->animscenes[i].framecount = groupframes;
                loadmodel->animscenes[i].framerate = 1.0f / interval;
@@ -165,47 +194,55 @@ void Mod_Sprite_SharedSetup(long datapointer, int version, int *palette)
                        width = LittleLong (pinframe->width);
                        height = LittleLong (pinframe->height);
 
-                       loadmodel->sprdata_frames[realframes].left = origin[0];
-                       loadmodel->sprdata_frames[realframes].right = origin[0] + width;
-                       loadmodel->sprdata_frames[realframes].up = origin[1];
-                       loadmodel->sprdata_frames[realframes].down = origin[1] - height;
+                       loadmodel->sprite.sprdata_frames[realframes].left = origin[0];
+                       loadmodel->sprite.sprdata_frames[realframes].right = origin[0] + width;
+                       loadmodel->sprite.sprdata_frames[realframes].up = origin[1];
+                       loadmodel->sprite.sprdata_frames[realframes].down = origin[1] - height;
 
-                       x = max(loadmodel->sprdata_frames[realframes].left * loadmodel->sprdata_frames[realframes].left, loadmodel->sprdata_frames[realframes].right * loadmodel->sprdata_frames[realframes].right);
-                       y = max(loadmodel->sprdata_frames[realframes].up * loadmodel->sprdata_frames[realframes].up, loadmodel->sprdata_frames[realframes].down * loadmodel->sprdata_frames[realframes].down);
+                       x = (int)max(loadmodel->sprite.sprdata_frames[realframes].left * loadmodel->sprite.sprdata_frames[realframes].left, loadmodel->sprite.sprdata_frames[realframes].right * loadmodel->sprite.sprdata_frames[realframes].right);
+                       y = (int)max(loadmodel->sprite.sprdata_frames[realframes].up * loadmodel->sprite.sprdata_frames[realframes].up, loadmodel->sprite.sprdata_frames[realframes].down * loadmodel->sprite.sprdata_frames[realframes].down);
                        if (modelradius < x + y)
                                modelradius = x + y;
 
-                       if (groupframes > 1)
-                               sprintf (name, "%s_%i_%i", tempname, i, j);
-                       else
-                               sprintf (name, "%s_%i", tempname, i);
-                       loadmodel->sprdata_frames[realframes].texture = loadtextureimagewithmask(loadmodel->texturepool, name, 0, 0, false, r_mipsprites.integer, true);
-                       loadmodel->sprdata_frames[realframes].fogtexture = image_masktex;
-
-                       if (!loadmodel->sprdata_frames[realframes].texture)
+                       if (cls.state != ca_dedicated)
                        {
-                               pixbuf = Mem_Alloc(tempmempool, width*height*4);
-                               if (version == SPRITE32_VERSION)
-                                       memcpy(pixbuf, (qbyte *)datapointer, width*height*4);
-                               else //if (version == SPRITE_VERSION || version == SPRITEHL_VERSION)
-                                       Image_Copy8bitRGBA((qbyte *)datapointer, pixbuf, width*height, palette);
-
-                               loadmodel->sprdata_frames[realframes].texture = R_LoadTexture (loadmodel->texturepool, name, width, height, pixbuf, TEXTYPE_RGBA, TEXF_ALPHA | (r_mipsprites.integer ? TEXF_MIPMAP : 0) | TEXF_PRECACHE);
-
-                               // make fog version (just alpha)
-                               for (k = 0;k < width*height;k++)
+                               skinframe = NULL;
+                               // note: Nehahra's null.spr has width == 0 and height == 0
+                               if (width > 0 && height > 0)
                                {
-                                       pixbuf[k*4+0] = 255;
-                                       pixbuf[k*4+1] = 255;
-                                       pixbuf[k*4+2] = 255;
+                                       if (groupframes > 1)
+                                       {
+                                               dpsnprintf (name, sizeof(name), "%s_%i_%i", loadmodel->name, i, j);
+                                               dpsnprintf (fogname, sizeof(fogname), "%s_%i_%ifog", loadmodel->name, i, j);
+                                       }
+                                       else
+                                       {
+                                               dpsnprintf (name, sizeof(name), "%s_%i", loadmodel->name, i);
+                                               dpsnprintf (fogname, sizeof(fogname), "%s_%ifog", loadmodel->name, i);
+                                       }
+                                       if (!(skinframe = R_SkinFrame_LoadExternal(name, texflags | TEXF_COMPRESS, false, false)))
+                                       {
+                                               unsigned char *pixels = (unsigned char *) Mem_Alloc(loadmodel->mempool, width*height*4);
+                                               if (version == SPRITE32_VERSION)
+                                               {
+                                                       for (x = 0;x < width*height;x++)
+                                                       {
+                                                               pixels[x*4+2] = datapointer[x*4+0];
+                                                               pixels[x*4+1] = datapointer[x*4+1];
+                                                               pixels[x*4+0] = datapointer[x*4+2];
+                                                               pixels[x*4+3] = datapointer[x*4+3];
+                                                       }
+                                               }
+                                               else //if (version == SPRITEHL_VERSION || version == SPRITE_VERSION)
+                                                       Image_Copy8bitBGRA(datapointer, pixels, width*height, palette ? palette : palette_bgra_transparent);
+                                               skinframe = R_SkinFrame_LoadInternalBGRA(name, texflags, pixels, width, height, 0, 0, 0, false);
+                                               // texflags |= TEXF_COMPRESS;
+                                               Mem_Free(pixels);
+                                       }
                                }
-                               if (groupframes > 1)
-                                       sprintf (name, "%s_%i_%ifog", tempname, i, j);
-                               else
-                                       sprintf (name, "%s_%ifog", tempname, i);
-                               loadmodel->sprdata_frames[realframes].fogtexture = R_LoadTexture (loadmodel->texturepool, name, width, height, pixbuf, TEXTYPE_RGBA, TEXF_ALPHA | (r_mipsprites.integer ? TEXF_MIPMAP : 0) | TEXF_PRECACHE);
-
-                               Mem_Free(pixbuf);
+                               if (skinframe == NULL)
+                                       skinframe = R_SkinFrame_LoadMissing();
+                               Mod_SpriteSetupTexture(&loadmodel->data_textures[realframes], skinframe, fullbright, additive);
                        }
 
                        if (version == SPRITE32_VERSION)
@@ -222,119 +259,227 @@ void Mod_Sprite_SharedSetup(long datapointer, int version, int *palette)
                loadmodel->normalmins[i] = loadmodel->yawmins[i] = loadmodel->rotatedmins[i] = -modelradius;
                loadmodel->normalmaxs[i] = loadmodel->yawmaxs[i] = loadmodel->rotatedmaxs[i] = modelradius;
        }
-//     loadmodel->modelradius = modelradius;
+       loadmodel->radius = modelradius;
+       loadmodel->radius2 = modelradius * modelradius;
 }
 
-void Mod_Sprite_SERAddEntity(void)
+void Mod_IDSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
 {
-       R_ClipSprite();
-}
+       int version;
+       const unsigned char *datapointer;
 
+       datapointer = (unsigned char *)buffer;
+
+       loadmodel->modeldatatypestring = "SPR1";
+
+       loadmodel->type = mod_sprite;
 
-/*
-=================
-Mod_LoadSpriteModel
-=================
-*/
-void Mod_LoadSpriteModel (model_t *mod, void *buffer)
-{
-       int version;
-       loadmodel->SERAddEntity = Mod_Sprite_SERAddEntity;
-       loadmodel->Draw = R_DrawSpriteModel;
        loadmodel->DrawSky = NULL;
-       loadmodel->DrawShadow = NULL;
+       loadmodel->Draw = R_Model_Sprite_Draw;
+       loadmodel->DrawDepth = NULL;
+       loadmodel->DrawLight = NULL;
+       loadmodel->DrawAddWaterPlanes = NULL;
 
        version = LittleLong(((dsprite_t *)buffer)->version);
-       if (version == SPRITE_VERSION || SPRITE32_VERSION)
+       if (version == SPRITE_VERSION || version == SPRITE32_VERSION)
        {
-               dsprite_t                       *pinsprite;
-               long                            datapointer;
+               dsprite_t *pinqsprite;
 
-               datapointer = (long) buffer;
-
-               pinsprite = (dsprite_t *)datapointer;
+               pinqsprite = (dsprite_t *)datapointer;
                datapointer += sizeof(dsprite_t);
 
-               loadmodel->numframes = LittleLong (pinsprite->numframes);
-               loadmodel->sprnum_type = LittleLong (pinsprite->type);
-               loadmodel->synctype = LittleLong (pinsprite->synctype);
+               loadmodel->numframes = LittleLong (pinqsprite->numframes);
+               loadmodel->sprite.sprnum_type = LittleLong (pinqsprite->type);
+               loadmodel->synctype = (synctype_t)LittleLong (pinqsprite->synctype);
 
-               Mod_Sprite_SharedSetup(datapointer, LittleLong (pinsprite->version), d_8to24table);
+               Mod_Sprite_SharedSetup(datapointer, LittleLong (pinqsprite->version), NULL, false);
        }
        else if (version == SPRITEHL_VERSION)
        {
-               int                                     i, rendermode;
-               qbyte                           palette[256][4], *in;
-               dspritehl_t                     *pinsprite;
-               long                            datapointer;
-
-               datapointer = (long) buffer;
+               int i, rendermode;
+               unsigned char palette[256][4];
+               const unsigned char *in;
+               dspritehl_t *pinhlsprite;
 
-               pinsprite = (dspritehl_t *)datapointer;
+               pinhlsprite = (dspritehl_t *)datapointer;
                datapointer += sizeof(dspritehl_t);
 
-               loadmodel->numframes = LittleLong (pinsprite->numframes);
-               loadmodel->sprnum_type = LittleLong (pinsprite->type);
-               loadmodel->synctype = LittleLong (pinsprite->synctype);
-               rendermode = pinsprite->rendermode;
+               loadmodel->numframes = LittleLong (pinhlsprite->numframes);
+               loadmodel->sprite.sprnum_type = LittleLong (pinhlsprite->type);
+               loadmodel->synctype = (synctype_t)LittleLong (pinhlsprite->synctype);
+               rendermode = pinhlsprite->rendermode;
 
-               in = (qbyte *)datapointer;
+               in = datapointer;
                datapointer += 2;
                i = in[0] + in[1] * 256;
                if (i != 256)
-                       Host_Error ("Mod_LoadHLSprite: unexpected number of palette colors %i (should be 256)", i);
-               in = (qbyte *)datapointer;
+                       Host_Error ("Mod_IDSP_Load: unexpected number of palette colors %i (should be 256)", i);
+               in = datapointer;
                datapointer += 768;
                switch(rendermode)
                {
-               case SPRHL_NORMAL:
-                       for (i = 0;i < 255;i++)
+               case SPRHL_OPAQUE:
+                       for (i = 0;i < 256;i++)
                        {
-                               palette[i][0] = *in++;
-                               palette[i][1] = *in++;
-                               palette[i][2] = *in++;
+                               palette[i][2] = in[i*3+0];
+                               palette[i][1] = in[i*3+1];
+                               palette[i][0] = in[i*3+2];
                                palette[i][3] = 255;
                        }
-                       palette[255][0] = palette[255][1] = palette[255][2] = palette[255][3] = 0;
                        break;
                case SPRHL_ADDITIVE:
                        for (i = 0;i < 256;i++)
                        {
-                               palette[i][0] = *in++;
-                               palette[i][1] = *in++;
-                               palette[i][2] = *in++;
+                               palette[i][2] = in[i*3+0];
+                               palette[i][1] = in[i*3+1];
+                               palette[i][0] = in[i*3+2];
                                palette[i][3] = 255;
                        }
-       //              palette[255][0] = palette[255][1] = palette[255][2] = palette[255][3] = 0;
-                       loadmodel->flags |= EF_ADDITIVE;
+                       // also passes additive == true to Mod_Sprite_SharedSetup
                        break;
                case SPRHL_INDEXALPHA:
                        for (i = 0;i < 256;i++)
                        {
-                               palette[i][0] = 255;
-                               palette[i][1] = 255;
-                               palette[i][2] = 255;
+                               palette[i][2] = in[765];
+                               palette[i][1] = in[766];
+                               palette[i][0] = in[767];
                                palette[i][3] = i;
                                in += 3;
                        }
                        break;
                case SPRHL_ALPHATEST:
-                       for (i = 0;i < 255;i++)
+                       for (i = 0;i < 256;i++)
                        {
-                               palette[i][0] = *in++;
-                               palette[i][1] = *in++;
-                               palette[i][2] = *in++;
+                               palette[i][2] = in[i*3+0];
+                               palette[i][1] = in[i*3+1];
+                               palette[i][0] = in[i*3+2];
                                palette[i][3] = 255;
                        }
-                       palette[0][0] = palette[0][1] = palette[0][2] = palette[0][3] = 0;
+                       palette[255][0] = palette[255][1] = palette[255][2] = palette[255][3] = 0;
+                       // should this use alpha test or alpha blend?  (currently blend)
                        break;
                default:
-                       Host_Error("Mod_LoadHLSprite: unknown texFormat (%i, should be 0, 1, 2, or 3)\n", i);
+                       Host_Error("Mod_IDSP_Load: unknown texFormat (%i, should be 0, 1, 2, or 3)", i);
                        return;
                }
 
-               Mod_Sprite_SharedSetup(datapointer, LittleLong (pinsprite->version), (int *)(&palette[0][0]));
+               Mod_Sprite_SharedSetup(datapointer, LittleLong (pinhlsprite->version), (unsigned int *)(&palette[0][0]), rendermode == SPRHL_ADDITIVE);
        }
        else
-               Host_Error ("Mod_LoadSpriteModel: %s has wrong version number (%i should be 1 (quake) or 32 (sprite32) or 2 (halflife)", loadmodel->name, version);
+               Host_Error("Mod_IDSP_Load: %s has wrong version number (%i). Only %i (quake), %i (HalfLife), and %i (sprite32) supported",
+                                       loadmodel->name, version, SPRITE_VERSION, SPRITEHL_VERSION, SPRITE32_VERSION);
+
+       // TODO: Note that isanimated only means whether vertices change due to
+       // the animation. This may happen due to sprframe parameters changing.
+       // Mere texture chanegs OTOH shouldn't require isanimated to be 1.
+       loadmodel->surfmesh.isanimated = loadmodel->numframes > 1 || (loadmodel->animscenes && loadmodel->animscenes[0].framecount > 1);
+}
+
+
+void Mod_IDS2_Load(dp_model_t *mod, void *buffer, void *bufferend)
+{
+       int i, version;
+       qboolean fullbright;
+       const dsprite2_t *pinqsprite;
+       skinframe_t *skinframe;
+       float modelradius;
+       int texflags = (r_mipsprites.integer ? TEXF_MIPMAP : 0) | TEXF_ISSPRITE | TEXF_PICMIP | TEXF_COMPRESS | TEXF_ALPHA | TEXF_CLAMP;
+
+       loadmodel->modeldatatypestring = "SPR2";
+
+       loadmodel->type = mod_sprite;
+
+       loadmodel->DrawSky = NULL;
+       loadmodel->Draw = R_Model_Sprite_Draw;
+       loadmodel->DrawDepth = NULL;
+       loadmodel->DrawLight = NULL;
+       loadmodel->DrawAddWaterPlanes = NULL;
+
+       pinqsprite = (dsprite2_t *)buffer;
+
+       version = LittleLong(pinqsprite->version);
+       if (version != SPRITE2_VERSION)
+               Host_Error("Mod_IDS2_Load: %s has wrong version number (%i should be 2 (quake 2)", loadmodel->name, version);
+
+       loadmodel->numframes = LittleLong (pinqsprite->numframes);
+       if (loadmodel->numframes < 1)
+               Host_Error ("Mod_IDS2_Load: Invalid # of frames: %d", loadmodel->numframes);
+       loadmodel->sprite.sprnum_type = SPR_VP_PARALLEL;
+       loadmodel->synctype = ST_SYNC;
+
+       // LordHavoc: hack to allow sprites to be non-fullbright
+       fullbright = true;
+       for (i = 0;i < MAX_QPATH && loadmodel->name[i];i++)
+               if (loadmodel->name[i] == '!')
+                       fullbright = false;
+
+       loadmodel->animscenes = (animscene_t *)Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
+       loadmodel->sprite.sprdata_frames = (mspriteframe_t *)Mem_Alloc(loadmodel->mempool, sizeof(mspriteframe_t) * loadmodel->numframes);
+       loadmodel->num_textures = loadmodel->numframes;
+       loadmodel->num_texturesperskin = 1;
+       loadmodel->data_textures = (texture_t *)Mem_Alloc(loadmodel->mempool, sizeof(texture_t) * loadmodel->num_textures);
+
+       modelradius = 0;
+       for (i = 0;i < loadmodel->numframes;i++)
+       {
+               int origin[2], x, y, width, height;
+               const dsprite2frame_t *pinframe;
+               mspriteframe_t *sprframe;
+
+               dpsnprintf(loadmodel->animscenes[i].name, sizeof(loadmodel->animscenes[i].name), "frame %i", i);
+               loadmodel->animscenes[i].firstframe = i;
+               loadmodel->animscenes[i].framecount = 1;
+               loadmodel->animscenes[i].framerate = 10;
+               loadmodel->animscenes[i].loop = true;
+
+               pinframe = &pinqsprite->frames[i];
+
+               origin[0] = LittleLong (pinframe->origin_x);
+               origin[1] = LittleLong (pinframe->origin_y);
+               width = LittleLong (pinframe->width);
+               height = LittleLong (pinframe->height);
+
+               sprframe = &loadmodel->sprite.sprdata_frames[i];
+
+               // note that sp2 origin[0] is positive, where as it is negative in
+               // spr/spr32/hlspr
+               sprframe->left = -origin[0];
+               sprframe->right = -origin[0] + width;
+               sprframe->up = origin[1];
+               sprframe->down = origin[1] - height;
+
+               x = (int)max(sprframe->left * sprframe->left, sprframe->right * sprframe->right);
+               y = (int)max(sprframe->up * sprframe->up, sprframe->down * sprframe->down);
+               if (modelradius < x + y)
+                       modelradius = x + y;
+       }
+
+       if (cls.state != ca_dedicated)
+       {
+               for (i = 0;i < loadmodel->numframes;i++)
+               {
+                       const dsprite2frame_t *pinframe;
+                       pinframe = &pinqsprite->frames[i];
+                       if (!(skinframe = R_SkinFrame_LoadExternal(pinframe->name, texflags, false, false)))
+                       {
+                               Con_Printf("Mod_IDS2_Load: failed to load %s", pinframe->name);
+                               skinframe = R_SkinFrame_LoadMissing();
+                       }
+                       Mod_SpriteSetupTexture(&loadmodel->data_textures[i], skinframe, fullbright, false);
+               }
+       }
+
+       modelradius = sqrt(modelradius);
+       for (i = 0;i < 3;i++)
+       {
+               loadmodel->normalmins[i] = loadmodel->yawmins[i] = loadmodel->rotatedmins[i] = -modelradius;
+               loadmodel->normalmaxs[i] = loadmodel->yawmaxs[i] = loadmodel->rotatedmaxs[i] = modelradius;
+       }
+       loadmodel->radius = modelradius;
+       loadmodel->radius2 = modelradius * modelradius;
+
+       // TODO: Note that isanimated only means whether vertices change due to
+       // the animation. This may happen due to sprframe parameters changing.
+       // Mere texture chanegs OTOH shouldn't require isanimated to be 1.
+       loadmodel->surfmesh.isanimated = loadmodel->numframes > 1 || (loadmodel->animscenes && loadmodel->animscenes[0].framecount > 1);
 }