+ image = Mem_Alloc(texturemempool, sizeof(gltextureimage_t));
+ if (image == NULL)
+ Sys_Error("R_FindImageForTexture: ran out of memory\n");
+ //memset(image, 0, sizeof(*image));
+ image->type = GLIMAGETYPE_FRAGMENTS;
+ image->width = block_size;
+ image->height = block_size;
+ image->blockallocation = Mem_Alloc(texturemempool, block_size * sizeof(short));
+ memset(image->blockallocation, 0, block_size * sizeof(short));
+
+ x = 0;
+ y = 0;
+ for (i = 0;i < w;i++)
+ image->blockallocation[x + i] = y + h;
+ }
+ else
+ {
+ for (imagechainpointer = &pool->imagechain;*imagechainpointer;imagechainpointer = &(*imagechainpointer)->imagechain);
+
+ image = Mem_Alloc(texturemempool, sizeof(gltextureimage_t));
+ if (image == NULL)
+ Sys_Error("R_FindImageForTexture: ran out of memory\n");
+ //memset(image, 0, sizeof(*image));
+ image->type = GLIMAGETYPE_TILE;
+ image->blockallocation = NULL;
+
+ // calculate final size
+ if (r_max_size.integer > realmaxsize)
+ Cvar_SetValue("r_max_size", realmaxsize);
+ for (image->width = 1;image->width < glt->width;image->width <<= 1);
+ for (image->height = 1;image->height < glt->height;image->height <<= 1);
+ for (image->width >>= r_picmip.integer;image->width > r_max_size.integer;image->width >>= 1);
+ for (image->height >>= r_picmip.integer;image->height > r_max_size.integer;image->height >>= 1);
+ if (image->width < 1) image->width = 1;
+ if (image->height < 1) image->height = 1;
+ }
+ image->glinternalformat = texinfo->glinternalformat;
+ image->glformat = texinfo->glformat;
+ image->flags = (glt->flags & (TEXF_MIPMAP | TEXF_ALPHA)) | GLTEXF_UPLOAD;
+ image->bytesperpixel = texinfo->internalbytesperpixel;
+ for (i = 1;i < MAX_GLTEXTURES;i++)
+ if (!gltexnuminuse[i])
+ break;
+ if (i < MAX_GLTEXTURES)
+ gltexnuminuse[image->texnum = i] = true;
+ else
+ Sys_Error("R_FindImageForTexture: ran out of GL textures\n");
+ *imagechainpointer = image;
+ image->texturecount++;
+
+ glt->x = x;
+ glt->y = y;
+ glt->image = image;
+}
+
+// note: R_FindImageForTexture must be called before this
+static void R_UploadTexture (gltexture_t *glt)
+{
+ if (!(glt->flags & (GLTEXF_UPLOAD | GLTEXF_PROCEDURAL)))
+ return;
+
+ if (glt->flags & GLTEXF_PROCEDURAL)
+ {
+ if (glt->generate)