+
+ qfree(buffer);
+}
+
+void GL_Upload8 (int glslot, byte *data, int width, int height, int flags)
+{
+ byte *data32;
+ data32 = qmalloc(width*height*4);
+ Image_Copy8bitRGBA(data, data32, width*height, d_8to24table);
+ GL_Upload32(glslot, data32, width, height, flags);
+ qfree(data32);
+}
+
+void GL_UploadTexture (gltexture_t *glt)
+{
+ if (glt->inputtexels == NULL)
+ return;
+ if (glt->flags & TEXF_RGBA)
+ GL_Upload32(glt->texnum, glt->inputtexels, glt->width, glt->height, glt->flags);
+ else // 8bit
+ GL_Upload8(glt->texnum, glt->inputtexels, glt->width, glt->height, glt->flags);
+ glt->internalflags |= GLTEXF_UPLOADED;
+ qfree(glt->inputtexels);
+ glt->inputtexels = NULL;
+}
+
+int R_CalcTexelDataSize (int width, int height, int mipmapped)
+{
+ int width2, height2, size;
+ width2 = 1;while (width2 < width) width2 <<= 1;
+ height2 = 1;while (height2 < height) height2 <<= 1;
+ // calculate final size (mipmapped downward to this)
+ width2 >>= (int) r_picmip.value;
+ height2 >>= (int) r_picmip.value;
+ while (width2 > (int) r_max_size.value) width2 >>= 1;
+ while (height2 > (int) r_max_size.value) height2 >>= 1;
+ if (width2 < 1) width2 = 1;
+ if (height2 < 1) height2 = 1;
+
+ size = 0;
+ if (mipmapped)
+ {
+ while (width2 > 1 || height2 > 1)
+ {
+ size += width2 * height2;
+ if (width2 > 1)
+ width2 >>= 1;
+ if (height2 > 1)
+ height2 >>= 1;
+ }
+ size++; // count the last 1x1 mipmap
+ }
+ else
+ size = width2*height2;
+
+ size *= 4; // RGBA
+
+ return size;