![Big Grin :D](./images/smilies/icon_biggrin.gif)
I don't know if any other engine does this, but it's something that every other GL engine should do.
Because they were an approximation of the truecolor mipmaps ID wished they could have used... like the ones glquake generates.MDave wrote:Amen!I always wondered why ID never used them for glquake.
Code: Select all
static unsigned upload[1024*512];
Code: Select all
/*
if (mipmap)
{
int miplevel;
miplevel = 0;
while (scaled_width > 1 || scaled_height > 1)
{
GL_MipMap ((byte *)scaled, scaled_width, scaled_height);
scaled_width >>= 1;
scaled_height >>= 1;
if (scaled_width < 1)
scaled_width = 1;
if (scaled_height < 1)
scaled_height = 1;
miplevel++;
glTexImage2D (GL_TEXTURE_2D, miplevel, samples, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
}
}
*/
if (mipmap)
{
int miplevel = 1;
// if it's an 8 bit texture coming from a BSP we handle it differently, as we want to take the first 4 (i.e.
// (next 3) miplevels from the BSP... this ensures that the colour balance correctly matches software quake
// if ((flags & TEX_BSP) && !(flags & TEX_32BIT))
// {
// BSP textures are ensured to be large enough to survive this...
for (; miplevel < 4; miplevel++)
{
// advance to next stored BSP mipmap
data += width * height;
// take down width and height
width >>= 1;
height >>= 1;
// take down scaled_width and scaled_height
scaled_width >>= 1;
scaled_height >>= 1;
// deal with texture resizing
if (width == scaled_width && height == scaled_height)
{
int i;
int size = width * height;
// upload is already set and valid, so we can copy it right in
for (i = 0; i < size; i++) upload[i] = d_8to24table[data[i]];
}
else
{
// resample the new data into upload (already set and valid here too), never a 32 bpp base
GL_ResampleTexture (data, width, height, upload, scaled_width, scaled_height);
}
// upload (don't increment miplevel for this one as the for loop does it for us)
glTexImage2D (GL_TEXTURE_2D, miplevel, GL_RGBA, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, upload);
}
// }
// BSP mipmapping sets up so that it will fall through correctly to here...
while (scaled_width > 1 || scaled_height > 1)
{
// generate our mipmaps
GL_MipMap ((byte *) upload, scaled_width, scaled_height);
// take down to next level
scaled_width >>= 1;
scaled_height >>= 1;
// never go < 1
if (scaled_width < 1) scaled_width = 1;
if (scaled_height < 1) scaled_height = 1;
glTexImage2D (GL_TEXTURE_2D, miplevel++, GL_RGBA, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, upload);
}
}