+ return pic;
+
+ if (numcachepics == MAX_CACHED_PICS)
+ {
+ Con_Printf ("Draw_CachePic: numcachepics == MAX_CACHED_PICS\n");
+ // FIXME: support NULL in callers?
+ return cachepics; // return the first one
+ }
+ pic = cachepics + (numcachepics++);
+ strlcpy (pic->name, path, sizeof(pic->name));
+ // link into list
+ pic->chain = cachepichash[hashkey];
+ cachepichash[hashkey] = pic;
+
+ // check whether it is an dynamic texture (if so, we can directly use its texture handler)
+ pic->tex = CL_GetDynTexture( path );
+ // if so, set the width/height, too
+ if( pic->tex ) {
+ pic->width = R_TextureWidth(pic->tex);
+ pic->height = R_TextureHeight(pic->tex);
+ // we're done now (early-out)
+ return pic;
+ }
+
+ flags = TEXF_ALPHA;
+ if (!(cachepicflags & CACHEPICFLAG_NOTPERSISTENT))
+ flags |= TEXF_PRECACHE;
+ if (!(cachepicflags & CACHEPICFLAG_NOCLAMP))
+ flags |= TEXF_CLAMP;
+ if (!(cachepicflags & CACHEPICFLAG_NOCOMPRESSION) && gl_texturecompression_2d.integer)
+ flags |= TEXF_COMPRESS;
+
+ // load a high quality image from disk if possible
+ pic->tex = loadtextureimage(drawtexturepool, path, false, flags, true);
+ if (pic->tex == NULL && !strncmp(path, "gfx/", 4))
+ {
+ // compatibility with older versions which did not require gfx/ prefix
+ pic->tex = loadtextureimage(drawtexturepool, path + 4, false, flags, true);
+ }
+ // if a high quality image was loaded, set the pic's size to match it, just
+ // in case there's no low quality version to get the size from
+ if (pic->tex)
+ {
+ pic->width = R_TextureWidth(pic->tex);
+ pic->height = R_TextureHeight(pic->tex);
+ }
+
+ // now read the low quality version (wad or lmp file), and take the pic
+ // size from that even if we don't upload the texture, this way the pics
+ // show up the right size in the menu even if they were replaced with
+ // higher or lower resolution versions
+ dpsnprintf(lmpname, sizeof(lmpname), "%s.lmp", path);
+ if (!strncmp(path, "gfx/", 4) && (lmpdata = FS_LoadFile(lmpname, tempmempool, false, &lmpsize)))
+ {
+ if (developer_loading.integer)
+ Con_Printf("loading lump \"%s\"\n", path);
+
+ if (lmpsize >= 9)
+ {
+ pic->width = lmpdata[0] + lmpdata[1] * 256 + lmpdata[2] * 65536 + lmpdata[3] * 16777216;
+ pic->height = lmpdata[4] + lmpdata[5] * 256 + lmpdata[6] * 65536 + lmpdata[7] * 16777216;
+ // if no high quality replacement image was found, upload the original low quality texture
+ if (!pic->tex)
+ pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, flags & ~TEXF_COMPRESS, palette_bgra_transparent);
+ }
+ Mem_Free(lmpdata);
+ }
+ else if ((lmpdata = W_GetLumpName (path + 4)))
+ {
+ if (developer_loading.integer)
+ Con_Printf("loading gfx.wad lump \"%s\"\n", path + 4);
+
+ if (!strcmp(path, "gfx/conchars"))
+ {
+ // conchars is a raw image and with color 0 as transparent instead of 255
+ pic->width = 128;
+ pic->height = 128;
+ // if no high quality replacement image was found, upload the original low quality texture
+ if (!pic->tex)
+ pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, lmpdata, TEXTYPE_PALETTE, flags & ~TEXF_COMPRESS, palette_bgra_font);
+ }
+ else
+ {
+ pic->width = lmpdata[0] + lmpdata[1] * 256 + lmpdata[2] * 65536 + lmpdata[3] * 16777216;
+ pic->height = lmpdata[4] + lmpdata[5] * 256 + lmpdata[6] * 65536 + lmpdata[7] * 16777216;
+ // if no high quality replacement image was found, upload the original low quality texture
+ if (!pic->tex)
+ pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, flags & ~TEXF_COMPRESS, palette_bgra_transparent);
+ }
+ }
+
+ // if it's not found on disk, generate an image
+ if (pic->tex == NULL)
+ {
+ pic->tex = draw_generatepic(path, (cachepicflags & CACHEPICFLAG_QUIET) != 0);
+ pic->width = R_TextureWidth(pic->tex);
+ pic->height = R_TextureHeight(pic->tex);
+ }
+
+ return pic;
+}
+
+cachepic_t *Draw_CachePic (const char *path)
+{
+ return Draw_CachePic_Flags (path, 0);
+}