+cachepic_t *Draw_NewPic(char *picname, int width, int height, int alpha, qbyte *pixels)
+{
+ int crc, hashkey;
+ cachepic_t *pic;
+
+ crc = CRC_Block(picname, strlen(picname));
+ hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
+ for (pic = cachepichash[hashkey];pic;pic = pic->chain)
+ if (!strcmp (picname, pic->name))
+ break;
+
+ if (pic)
+ {
+ if (pic->tex && pic->width == width && pic->height == height)
+ {
+ R_UpdateTexture(pic->tex, pixels);
+ return pic;
+ }
+ }
+ else
+ {
+ if (pic == NULL)
+ {
+ if (numcachepics == MAX_CACHED_PICS)
+ Sys_Error ("numcachepics == MAX_CACHED_PICS");
+ pic = cachepics + (numcachepics++);
+ strcpy (pic->name, picname);
+ // link into list
+ pic->chain = cachepichash[hashkey];
+ cachepichash[hashkey] = pic;
+ }
+ }
+
+ pic->width = width;
+ pic->height = height;
+ if (pic->tex)
+ R_FreeTexture(pic->tex);
+ pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels, TEXTYPE_RGBA, alpha ? TEXF_ALPHA : 0, NULL);
+ return pic;
+}
+
+void Draw_FreePic(char *picname)
+{
+ int crc;
+ int hashkey;
+ cachepic_t *pic;
+ // this doesn't really free the pic, but does free it's texture
+ crc = CRC_Block(picname, strlen(picname));
+ hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
+ for (pic = cachepichash[hashkey];pic;pic = pic->chain)
+ {
+ if (!strcmp (picname, pic->name))
+ {
+ R_FreeTexture(pic->tex);
+ pic->width = 0;
+ pic->height = 0;
+ return;
+ }
+ }
+}
+