// scaling, and remaps the 0-65536 (2x overbright) to 0-256, it will
// be doubled during rendering to achieve 2x overbright
// (0 = 0.0, 128 = 1.0, 256 = 2.0)
- if (model->brushq1.lightmaprgba)
+ for (i = 0;i < size;i++)
{
- for (i = 0;i < size;i++)
- {
- l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
- l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
- l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
- *out++ = 255;
- }
- }
- else
- {
- for (i = 0;i < size;i++)
- {
- l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
- l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
- l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
- }
+ l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
+ l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
+ l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
+ *out++ = 255;
}
R_UpdateTexture(surface->lightmaptexture, templight, surface->lightmapinfo->lightmaporigin[0], surface->lightmapinfo->lightmaporigin[1], smax, tmax);
bl = intblocklights;
out = templight;
// we simply renormalize the weighted normals to get a valid deluxemap
- if (model->brushq1.lightmaprgba)
+ for (i = 0;i < size;i++, bl += 3)
{
- for (i = 0;i < size;i++, bl += 3)
- {
- VectorCopy(bl, n);
- VectorNormalize(n);
- l = (int)(n[0] * 128 + 128);*out++ = bound(0, l, 255);
- l = (int)(n[1] * 128 + 128);*out++ = bound(0, l, 255);
- l = (int)(n[2] * 128 + 128);*out++ = bound(0, l, 255);
- *out++ = 255;
- }
- }
- else
- {
- for (i = 0;i < size;i++, bl += 3)
- {
- VectorCopy(bl, n);
- VectorNormalize(n);
- l = (int)(n[0] * 128 + 128);*out++ = bound(0, l, 255);
- l = (int)(n[1] * 128 + 128);*out++ = bound(0, l, 255);
- l = (int)(n[2] * 128 + 128);*out++ = bound(0, l, 255);
- }
+ VectorCopy(bl, n);
+ VectorNormalize(n);
+ l = (int)(n[0] * 128 + 128);*out++ = bound(0, l, 255);
+ l = (int)(n[1] * 128 + 128);*out++ = bound(0, l, 255);
+ l = (int)(n[2] * 128 + 128);*out++ = bound(0, l, 255);
+ *out++ = 255;
}
R_UpdateTexture(surface->deluxemaptexture, templight, surface->lightmapinfo->lightmaporigin[0], surface->lightmapinfo->lightmaporigin[1], smax, tmax);
}
textypeinfo_t;
static textypeinfo_t textype_palette = {TEXTYPE_PALETTE, 1, 4, 4.0f, GL_RGBA , 3};
-static textypeinfo_t textype_rgb = {TEXTYPE_RGB , 3, 3, 4.0f, GL_RGB , 3};
static textypeinfo_t textype_rgba = {TEXTYPE_RGBA , 4, 4, 4.0f, GL_RGBA , 3};
static textypeinfo_t textype_palette_alpha = {TEXTYPE_PALETTE, 1, 4, 4.0f, GL_RGBA , 4};
static textypeinfo_t textype_rgba_alpha = {TEXTYPE_RGBA , 4, 4, 4.0f, GL_RGBA , 4};
static textypeinfo_t textype_palette_compress = {TEXTYPE_PALETTE, 1, 4, 0.5f, GL_RGBA , GL_COMPRESSED_RGB_ARB};
-static textypeinfo_t textype_rgb_compress = {TEXTYPE_RGB , 3, 3, 0.5f, GL_RGB , GL_COMPRESSED_RGB_ARB};
static textypeinfo_t textype_rgba_compress = {TEXTYPE_RGBA , 4, 4, 0.5f, GL_RGBA , GL_COMPRESSED_RGB_ARB};
static textypeinfo_t textype_palette_alpha_compress = {TEXTYPE_PALETTE, 1, 4, 1.0f, GL_RGBA , GL_COMPRESSED_RGBA_ARB};
static textypeinfo_t textype_rgba_alpha_compress = {TEXTYPE_RGBA , 4, 4, 1.0f, GL_RGBA , GL_COMPRESSED_RGBA_ARB};
{
case TEXTYPE_PALETTE:
return &textype_palette_alpha_compress;
- 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_compress;
default:
{
case TEXTYPE_PALETTE:
return &textype_palette_compress;
- case TEXTYPE_RGB:
- return &textype_rgb_compress;
case TEXTYPE_RGBA:
return &textype_rgba_compress;
default:
{
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:
{
case TEXTYPE_PALETTE:
return &textype_palette;
- case TEXTYPE_RGB:
- return &textype_rgb;
case TEXTYPE_RGBA:
return &textype_rgba;
default:
{
if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
{
- Image_Resample(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, glt->bytesperpixel, r_lerpimages.integer);
+ Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer);
prevbuffer = resizebuffer;
}
// picmip/max_size
while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth)
{
- Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth, glt->bytesperpixel);
+ Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth);
prevbuffer = resizebuffer;
}
}
{
while (width > 1 || height > 1 || depth > 1)
{
- Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
+ Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
prevbuffer = resizebuffer;
qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
{
while (width > 1 || height > 1 || depth > 1)
{
- Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
+ Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
prevbuffer = resizebuffer;
qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
{
while (width > 1 || height > 1 || depth > 1)
{
- Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
+ Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
prevbuffer = resizebuffer;
qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel;
if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
{
- Image_Resample(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, glt->bytesperpixel, r_lerpimages.integer);
+ Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer);
prevbuffer = resizebuffer;
}
// picmip/max_size
while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth)
{
- Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth, glt->bytesperpixel);
+ Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth);
prevbuffer = resizebuffer;
}
mip = 0;
{
while (width > 1 || height > 1 || depth > 1)
{
- Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
+ Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
prevbuffer = resizebuffer;
qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
}
}
break;
- case TEXTYPE_RGB:
- if (flags & TEXF_ALPHA)
- Host_Error("R_LoadTexture: RGB has no alpha, don't specify TEXF_ALPHA");
- break;
case TEXTYPE_RGBA:
if (flags & TEXF_ALPHA)
{
}
}
-static void Image_Resample24LerpLine (const unsigned char *in, unsigned char *out, int inwidth, int outwidth)
-{
- int j, xi, oldx = 0, f, fstep, endx, lerp;
- fstep = (int) (inwidth*65536.0f/outwidth);
- endx = (inwidth-1);
- for (j = 0,f = 0;j < outwidth;j++, f += fstep)
- {
- xi = f >> 16;
- if (xi != oldx)
- {
- in += (xi - oldx) * 3;
- oldx = xi;
- }
- if (xi < endx)
- {
- lerp = f & 0xFFFF;
- *out++ = (unsigned char) ((((in[3] - in[0]) * lerp) >> 16) + in[0]);
- *out++ = (unsigned char) ((((in[4] - in[1]) * lerp) >> 16) + in[1]);
- *out++ = (unsigned char) ((((in[5] - in[2]) * lerp) >> 16) + in[2]);
- }
- else // last pixel of the line has no pixel to lerp to
- {
- *out++ = in[0];
- *out++ = in[1];
- *out++ = in[2];
- }
- }
-}
-
#define LERPBYTE(i) r = resamplerow1[i];out[i] = (unsigned char) ((((resamplerow2[i] - r) * lerp) >> 16) + r)
void Image_Resample32Lerp(const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
{
}
}
-void Image_Resample24Lerp(const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
-{
- int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth3 = inwidth * 3, outwidth3 = outwidth * 3;
- unsigned char *out;
- const unsigned char *inrow;
- unsigned char *resamplerow1;
- unsigned char *resamplerow2;
- out = (unsigned char *)outdata;
- fstep = (int) (inheight*65536.0f/outheight);
-
- resamplerow1 = (unsigned char *)Mem_Alloc(tempmempool, outwidth*3*2);
- resamplerow2 = resamplerow1 + outwidth*3;
-
- inrow = (const unsigned char *)indata;
- oldy = 0;
- Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
- Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
- for (i = 0, f = 0;i < outheight;i++,f += fstep)
- {
- yi = f >> 16;
- if (yi < endy)
- {
- lerp = f & 0xFFFF;
- if (yi != oldy)
- {
- inrow = (unsigned char *)indata + inwidth3*yi;
- if (yi == oldy+1)
- memcpy(resamplerow1, resamplerow2, outwidth3);
- else
- Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
- Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
- oldy = yi;
- }
- j = outwidth - 4;
- while(j >= 0)
- {
- LERPBYTE( 0);
- LERPBYTE( 1);
- LERPBYTE( 2);
- LERPBYTE( 3);
- LERPBYTE( 4);
- LERPBYTE( 5);
- LERPBYTE( 6);
- LERPBYTE( 7);
- LERPBYTE( 8);
- LERPBYTE( 9);
- LERPBYTE(10);
- LERPBYTE(11);
- out += 12;
- resamplerow1 += 12;
- resamplerow2 += 12;
- j -= 4;
- }
- if (j & 2)
- {
- LERPBYTE( 0);
- LERPBYTE( 1);
- LERPBYTE( 2);
- LERPBYTE( 3);
- LERPBYTE( 4);
- LERPBYTE( 5);
- out += 6;
- resamplerow1 += 6;
- resamplerow2 += 6;
- }
- if (j & 1)
- {
- LERPBYTE( 0);
- LERPBYTE( 1);
- LERPBYTE( 2);
- out += 3;
- resamplerow1 += 3;
- resamplerow2 += 3;
- }
- resamplerow1 -= outwidth3;
- resamplerow2 -= outwidth3;
- }
- else
- {
- if (yi != oldy)
- {
- inrow = (unsigned char *)indata + inwidth3*yi;
- if (yi == oldy+1)
- memcpy(resamplerow1, resamplerow2, outwidth3);
- else
- Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
- oldy = yi;
- }
- memcpy(out, resamplerow1, outwidth3);
- }
- }
- Mem_Free(resamplerow1);
- resamplerow1 = NULL;
- resamplerow2 = NULL;
-}
-
-void Image_Resample24Nolerp(const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
-{
- int i, j, f, inwidth3 = inwidth * 3;
- unsigned frac, fracstep;
- unsigned char *inrow, *out;
- out = (unsigned char *)outdata;
-
- fracstep = inwidth*0x10000/outwidth;
- for (i = 0;i < outheight;i++)
- {
- inrow = (unsigned char *)indata + inwidth3*(i*inheight/outheight);
- frac = fracstep >> 1;
- j = outwidth - 4;
- while (j >= 0)
- {
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- j -= 4;
- }
- if (j & 2)
- {
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- out += 2;
- }
- if (j & 1)
- {
- f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
- out += 1;
- }
- }
-}
-
/*
================
Image_Resample
================
*/
-void Image_Resample (const void *indata, int inwidth, int inheight, int indepth, void *outdata, int outwidth, int outheight, int outdepth, int bytesperpixel, int quality)
+void Image_Resample32(const void *indata, int inwidth, int inheight, int indepth, void *outdata, int outwidth, int outheight, int outdepth, int quality)
{
if (indepth != 1 || outdepth != 1)
{
Con_Printf ("Image_Resample: 3D resampling not supported\n");
return;
}
- if (bytesperpixel == 4)
- {
- if (quality)
- Image_Resample32Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
- else
- Image_Resample32Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
- }
- else if (bytesperpixel == 3)
- {
- if (quality)
- Image_Resample24Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
- else
- Image_Resample24Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
- }
+ if (quality)
+ Image_Resample32Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
else
- Con_Printf ("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
+ Image_Resample32Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
}
// in can be the same as out
-void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth, int bytesperpixel)
+void Image_MipReduce32(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth)
{
const unsigned char *inrow;
int x, y, nextrow;
// note: if given odd width/height this discards the last row/column of
// pixels, rather than doing a proper box-filter scale down
inrow = in;
- nextrow = *width * bytesperpixel;
+ nextrow = *width * 4;
if (*width > destwidth)
{
*width >>= 1;
{
// reduce both
*height >>= 1;
- if (bytesperpixel == 4)
+ for (y = 0;y < *height;y++, inrow += nextrow * 2)
{
- for (y = 0;y < *height;y++, inrow += nextrow * 2)
+ for (in = inrow, x = 0;x < *width;x++)
{
- for (in = inrow, x = 0;x < *width;x++)
- {
- out[0] = (unsigned char) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
- out[1] = (unsigned char) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
- out[2] = (unsigned char) ((in[2] + in[6] + in[nextrow+2] + in[nextrow+6]) >> 2);
- out[3] = (unsigned char) ((in[3] + in[7] + in[nextrow+3] + in[nextrow+7]) >> 2);
- out += 4;
- in += 8;
- }
- }
- }
- else if (bytesperpixel == 3)
- {
- for (y = 0;y < *height;y++, inrow += nextrow * 2)
- {
- for (in = inrow, x = 0;x < *width;x++)
- {
- out[0] = (unsigned char) ((in[0] + in[3] + in[nextrow ] + in[nextrow+3]) >> 2);
- out[1] = (unsigned char) ((in[1] + in[4] + in[nextrow+1] + in[nextrow+4]) >> 2);
- out[2] = (unsigned char) ((in[2] + in[5] + in[nextrow+2] + in[nextrow+5]) >> 2);
- out += 3;
- in += 6;
- }
+ out[0] = (unsigned char) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
+ out[1] = (unsigned char) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
+ out[2] = (unsigned char) ((in[2] + in[6] + in[nextrow+2] + in[nextrow+6]) >> 2);
+ out[3] = (unsigned char) ((in[3] + in[7] + in[nextrow+3] + in[nextrow+7]) >> 2);
+ out += 4;
+ in += 8;
}
}
- else
- Con_Printf ("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
}
else
{
// reduce width
- if (bytesperpixel == 4)
- {
- for (y = 0;y < *height;y++, inrow += nextrow)
- {
- for (in = inrow, x = 0;x < *width;x++)
- {
- out[0] = (unsigned char) ((in[0] + in[4]) >> 1);
- out[1] = (unsigned char) ((in[1] + in[5]) >> 1);
- out[2] = (unsigned char) ((in[2] + in[6]) >> 1);
- out[3] = (unsigned char) ((in[3] + in[7]) >> 1);
- out += 4;
- in += 8;
- }
- }
- }
- else if (bytesperpixel == 3)
+ for (y = 0;y < *height;y++, inrow += nextrow)
{
- for (y = 0;y < *height;y++, inrow += nextrow)
+ for (in = inrow, x = 0;x < *width;x++)
{
- for (in = inrow, x = 0;x < *width;x++)
- {
- out[0] = (unsigned char) ((in[0] + in[3]) >> 1);
- out[1] = (unsigned char) ((in[1] + in[4]) >> 1);
- out[2] = (unsigned char) ((in[2] + in[5]) >> 1);
- out += 3;
- in += 6;
- }
+ out[0] = (unsigned char) ((in[0] + in[4]) >> 1);
+ out[1] = (unsigned char) ((in[1] + in[5]) >> 1);
+ out[2] = (unsigned char) ((in[2] + in[6]) >> 1);
+ out[3] = (unsigned char) ((in[3] + in[7]) >> 1);
+ out += 4;
+ in += 8;
}
}
- else
- Con_Printf ("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
}
}
else
{
// reduce height
*height >>= 1;
- if (bytesperpixel == 4)
+ for (y = 0;y < *height;y++, inrow += nextrow * 2)
{
- for (y = 0;y < *height;y++, inrow += nextrow * 2)
+ for (in = inrow, x = 0;x < *width;x++)
{
- for (in = inrow, x = 0;x < *width;x++)
- {
- out[0] = (unsigned char) ((in[0] + in[nextrow ]) >> 1);
- out[1] = (unsigned char) ((in[1] + in[nextrow+1]) >> 1);
- out[2] = (unsigned char) ((in[2] + in[nextrow+2]) >> 1);
- out[3] = (unsigned char) ((in[3] + in[nextrow+3]) >> 1);
- out += 4;
- in += 4;
- }
+ out[0] = (unsigned char) ((in[0] + in[nextrow ]) >> 1);
+ out[1] = (unsigned char) ((in[1] + in[nextrow+1]) >> 1);
+ out[2] = (unsigned char) ((in[2] + in[nextrow+2]) >> 1);
+ out[3] = (unsigned char) ((in[3] + in[nextrow+3]) >> 1);
+ out += 4;
+ in += 4;
}
}
- else if (bytesperpixel == 3)
- {
- for (y = 0;y < *height;y++, inrow += nextrow * 2)
- {
- for (in = inrow, x = 0;x < *width;x++)
- {
- out[0] = (unsigned char) ((in[0] + in[nextrow ]) >> 1);
- out[1] = (unsigned char) ((in[1] + in[nextrow+1]) >> 1);
- out[2] = (unsigned char) ((in[2] + in[nextrow+2]) >> 1);
- out += 3;
- in += 3;
- }
- }
- }
- else
- Con_Printf ("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
}
else
Con_Printf ("Image_MipReduce: desired size already achieved\n");
void Image_WriteTGARGBA (const char *filename, int width, int height, const unsigned char *data);
// resizes the image (in can not be the same as out)
-void Image_Resample (const void *indata, int inwidth, int inheight, int indepth, void *outdata, int outwidth, int outheight, int outdepth, int bytesperpixel, int quality);
+void Image_Resample32(const void *indata, int inwidth, int inheight, int indepth, void *outdata, int outwidth, int outheight, int outdepth, int quality);
// scales the image down by a power of 2 (in can be the same as out)
-void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth, int bytesperpixel);
+void Image_MipReduce32(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth);
// only used by menuplyr coloring
unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, int matchheight, qboolean loadAs8Bit);
cvar_t halflifebsp = {0, "halflifebsp", "0", "indicates the current map is hlbsp format (useful to know because of different bounding box sizes)"};
cvar_t mcbsp = {0, "mcbsp", "0", "indicates the current map is mcbsp format (useful to know because of different bounding box sizes)"};
cvar_t r_novis = {0, "r_novis", "0", "draws whole level, see also sv_cullentities_pvs 0"};
-cvar_t r_lightmaprgba = {0, "r_lightmaprgba", "1", "whether to use RGBA (32bit) or RGB (24bit) lightmaps"};
cvar_t r_picmipworld = {CVAR_SAVE, "r_picmipworld", "1", "whether gl_picmip shall apply to world textures too"};
cvar_t r_nosurftextures = {0, "r_nosurftextures", "0", "pretends there was no texture lump found in the q1bsp/hlbsp loading (useful for debugging this rare case)"};
cvar_t r_subdivisions_tolerance = {0, "r_subdivisions_tolerance", "4", "maximum error tolerance on curve subdivision for rendering purposes (in other words, the curves will be given as many polygons as necessary to represent curves at this quality)"};
Cvar_RegisterVariable(&halflifebsp);
Cvar_RegisterVariable(&mcbsp);
Cvar_RegisterVariable(&r_novis);
- Cvar_RegisterVariable(&r_lightmaprgba);
Cvar_RegisterVariable(&r_picmipworld);
Cvar_RegisterVariable(&r_nosurftextures);
Cvar_RegisterVariable(&r_subdivisions_tolerance);
if (loadmodel->texturepool == NULL)
loadmodel->texturepool = R_AllocTexturePool();
// could not find room, make a new lightmap
- lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_RGBA, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
if (loadmodel->brushq1.nmaplightdata)
- deluxemaptexture = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, loadmodel->brushq1.lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
+ deluxemaptexture = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_RGBA, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL);
lightmapnumber++;
memset(lightmap_lineused, 0, sizeof(lightmap_lineused));
Mod_Q1BSP_AllocLightmapBlock(lightmap_lineused, lightmapsize, lightmapsize, ssize, tsize, &lightmapx, &lightmapy);
// load into heap
- // store which lightmap format to use
- mod->brushq1.lightmaprgba = r_lightmaprgba.integer;
-
mod->brush.qw_md4sum = 0;
mod->brush.qw_md4sum2 = 0;
for (i = 0;i < HEADER_LUMPS;i++)
for (i = 0;i < (int) sizeof(*header) / 4;i++)
((int *)header)[i] = LittleLong(((int *)header)[i]);
- // store which lightmap format to use
- mod->brushq1.lightmaprgba = r_lightmaprgba.integer;
-
mod->brush.qw_md4sum = 0;
mod->brush.qw_md4sum2 = 0;
for (i = 0;i < Q2HEADER_LUMPS;i++)
static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
{
q3dlightmap_t *in;
- int i, j, count, power, power2, mask, endlightmap, mergewidth, mergeheight;
+ int i, j, k, count, power, power2, mask, endlightmap, mergewidth, mergeheight;
unsigned char *c;
+ unsigned char convertedpixels[128*128*4];
if (!l->filelen)
return;
if (loadmodel->texturepool == NULL && cls.state != ca_dedicated)
loadmodel->texturepool = R_AllocTexturePool();
- if (loadmodel->brushq3.num_lightmapmergepower > 0)
+ power = loadmodel->brushq3.num_lightmapmergepower;
+ power2 = power * 2;
+ mask = (1 << power) - 1;
+ for (i = 0;i < count;i++)
{
- power = loadmodel->brushq3.num_lightmapmergepower;
- power2 = power * 2;
- mask = (1 << power) - 1;
- for (i = 0;i < count;i++)
+ // figure out which merged lightmap texture this fits into
+ int lightmapindex = i >> (loadmodel->brushq3.deluxemapping + power2);
+ for (k = 0;k < 128*128;k++)
+ {
+ convertedpixels[k*4+0] = in[i].rgb[k*3+0];
+ convertedpixels[k*4+1] = in[i].rgb[k*3+1];
+ convertedpixels[k*4+2] = in[i].rgb[k*3+2];
+ convertedpixels[k*4+3] = 255;
+ }
+ if (loadmodel->brushq3.num_lightmapmergepower > 0)
{
- // figure out which merged lightmap texture this fits into
- int lightmapindex = i >> (loadmodel->brushq3.deluxemapping + power2);
// if the lightmap has not been allocated yet, create it
if (!loadmodel->brushq3.data_lightmaps[lightmapindex])
{
for (mergeheight = 1;mergewidth*mergeheight < j && mergeheight < (1 << power);mergeheight *= 2)
;
Con_DPrintf("lightmap merge texture #%i is %ix%i (%i of %i used)\n", lightmapindex, mergewidth*128, mergeheight*128, min(j, mergewidth*mergeheight), mergewidth*mergeheight);
- loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : 0), NULL);
+ loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGBA, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : 0), NULL);
if (loadmodel->brushq3.data_deluxemaps)
- loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : 0), NULL);
+ loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), mergewidth * 128, mergeheight * 128, NULL, TEXTYPE_RGBA, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : 0), NULL);
}
mergewidth = R_TextureWidth(loadmodel->brushq3.data_lightmaps[lightmapindex]) / 128;
mergeheight = R_TextureHeight(loadmodel->brushq3.data_lightmaps[lightmapindex]) / 128;
j = (i >> loadmodel->brushq3.deluxemapping) & ((1 << power2) - 1);
if (loadmodel->brushq3.deluxemapping && (i & 1))
- R_UpdateTexture(loadmodel->brushq3.data_deluxemaps[lightmapindex], in[i].rgb, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
+ R_UpdateTexture(loadmodel->brushq3.data_deluxemaps[lightmapindex], convertedpixels, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
else
- R_UpdateTexture(loadmodel->brushq3.data_lightmaps [lightmapindex], in[i].rgb, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
+ R_UpdateTexture(loadmodel->brushq3.data_lightmaps [lightmapindex], convertedpixels, (j % mergewidth) * 128, (j / mergewidth) * 128, 128, 128);
}
- }
- else
- {
- for (i = 0;i < count;i++)
+ else
{
// figure out which merged lightmap texture this fits into
- int lightmapindex = i >> loadmodel->brushq3.deluxemapping;
if (loadmodel->brushq3.deluxemapping && (i & 1))
- loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), 128, 128, in[i].rgb, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : 0), NULL);
+ loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), 128, 128, convertedpixels, TEXTYPE_RGBA, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : 0), NULL);
else
- loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), 128, 128, in[i].rgb, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : 0), NULL);
+ loadmodel->brushq3.data_lightmaps [lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), 128, 128, convertedpixels, TEXTYPE_RGBA, TEXF_FORCELINEAR | TEXF_PRECACHE | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : 0), NULL);
}
}
}
q3dlightgrid_t *a, *s;
// scale lighting by lightstyle[0] so that darkmode in dpmod works properly
- stylescale = r_refdef.lightstylevalue[0] * (1.0f / 264.0f);
+ stylescale = r_refdef.lightstylevalue[0] * (1.0f / 256.0f);
if (!model->brushq3.num_lightgrid)
{
typedef struct model_brushq1_s
{
- // lightmap format, set to r_lightmaprgba when model is loaded
- int lightmaprgba;
-
dmodel_t *submodels;
int numvertexes;
{
int i;
for (i = 0;i < MAX_LIGHTSTYLES;i++)
- r_refdef.lightstylevalue[i] = 264; // normal light value
+ r_refdef.lightstylevalue[i] = 256; // normal light value
}
void R_Light_Init(void)
// 8bit paletted
#define TEXTYPE_PALETTE 1
-// 24bit RGB
-#define TEXTYPE_RGB 2
// 32bit RGBA
#define TEXTYPE_RGBA 3