+static textypeinfo_t *R_GetTexTypeInfo(int textype, int flags)
+{
+ if (flags & TEXF_ALPHA)
+ {
+ switch(textype)
+ {
+ case TEXTYPE_PALETTE:
+ return &textype_palette_alpha;
+ case TEXTYPE_RGB:
+ Host_Error("R_GetTexTypeInfo: RGB format has no alpha, TEXF_ALPHA not allowed");
+ return NULL;
+ case TEXTYPE_RGBA:
+ return &textype_rgba_alpha;
+ default:
+ Host_Error("R_GetTexTypeInfo: unknown texture format");
+ return NULL;
+ }
+ }
+ else
+ {
+ switch(textype)
+ {
+ case TEXTYPE_PALETTE:
+ return &textype_palette;
+ case TEXTYPE_RGB:
+ return &textype_rgb;
+ case TEXTYPE_RGBA:
+ return &textype_rgba;
+ default:
+ Host_Error("R_GetTexTypeInfo: unknown texture format");
+ return NULL;
+ }
+ }
+}
+
+static void R_UploadTexture(gltexture_t *t);
+
+static void R_PrecacheTexture(gltexture_t *glt)
+{
+ int precache;
+ precache = false;
+ if (glt->flags & TEXF_ALWAYSPRECACHE)
+ precache = true;
+ else if (r_precachetextures.integer >= 2)
+ precache = true;
+ else if (r_precachetextures.integer >= 1)
+ if (glt->flags & TEXF_PRECACHE)
+ precache = true;
+
+ if (precache)
+ R_UploadTexture(glt);
+}
+
+int R_RealGetTexture(rtexture_t *rt)
+{
+ if (rt)
+ {
+ gltexture_t *glt;
+ glt = (gltexture_t *)rt;
+ if (glt->flags & GLTEXF_UPLOAD)
+ R_UploadTexture(glt);
+ return glt->texnum;
+ }
+ else
+ return 0;
+}
+
+void R_FreeTexture(rtexture_t *rt)
+{
+ gltexture_t *glt, **gltpointer;
+
+ glt = (gltexture_t *)rt;
+ if (glt == NULL)
+ Host_Error("R_FreeTexture: texture == NULL");
+
+ for (gltpointer = &glt->pool->gltchain;*gltpointer && *gltpointer != glt;gltpointer = &(*gltpointer)->chain);
+ if (*gltpointer == glt)
+ *gltpointer = glt->chain;
+ else
+ Host_Error("R_FreeTexture: texture \"%s\" not linked in pool", glt->identifier);
+
+ if (glt->texnum)
+ {
+ CHECKGLERROR
+ qglDeleteTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
+ }
+
+ if (glt->inputtexels)
+ Mem_Free(glt->inputtexels);
+ Mem_Free(glt);
+}
+
+rtexturepool_t *R_AllocTexturePool(void)
+{
+ gltexturepool_t *pool;
+ if (texturemempool == NULL)
+ return NULL;
+ pool = (gltexturepool_t *)Mem_Alloc(texturemempool, sizeof(gltexturepool_t));
+ if (pool == NULL)
+ return NULL;
+ pool->next = gltexturepoolchain;
+ gltexturepoolchain = pool;
+ pool->sentinel = TEXTUREPOOL_SENTINEL;
+ return (rtexturepool_t *)pool;
+}
+
+void R_FreeTexturePool(rtexturepool_t **rtexturepool)
+{
+ gltexturepool_t *pool, **poolpointer;
+ if (rtexturepool == NULL)
+ return;
+ if (*rtexturepool == NULL)
+ return;
+ pool = (gltexturepool_t *)(*rtexturepool);
+ *rtexturepool = NULL;
+ if (pool->sentinel != TEXTUREPOOL_SENTINEL)
+ Host_Error("R_FreeTexturePool: pool already freed");
+ for (poolpointer = &gltexturepoolchain;*poolpointer && *poolpointer != pool;poolpointer = &(*poolpointer)->next);
+ if (*poolpointer == pool)
+ *poolpointer = pool->next;
+ else
+ Host_Error("R_FreeTexturePool: pool not linked");
+ while (pool->gltchain)
+ R_FreeTexture((rtexture_t *)pool->gltchain);
+ Mem_Free(pool);
+}
+
+
+typedef struct glmode_s