From 66cfa344b8aeaaaf19c3e609032807046c906d78 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 26 Nov 2007 21:54:11 +0000 Subject: [PATCH] removed support for TEXTYPE_RGB renamed Image_Resample to Image_Resample32 and removed bpp param renamed Image_MipReduce to Image_MipReduce32 and removed bpp param changed q3bsp lightmap loader to convert to 32bit before upload git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7716 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rsurf.c | 50 ++------- gl_textures.c | 32 ++---- image.c | 289 +++++-------------------------------------------- image.h | 4 +- model_brush.c | 56 +++++----- model_shared.h | 3 - r_light.c | 2 +- r_textures.h | 2 - 8 files changed, 79 insertions(+), 359 deletions(-) diff --git a/gl_rsurf.c b/gl_rsurf.c index 5cd7f27a..8ec12e9b 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -96,24 +96,12 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface) // 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); @@ -145,28 +133,14 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface) 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); } diff --git a/gl_textures.c b/gl_textures.c index f32c848e..24c9d69f 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -48,12 +48,10 @@ typedef struct textypeinfo_s 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}; @@ -152,9 +150,6 @@ static textypeinfo_t *R_GetTexTypeInfo(int textype, int flags) { 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: @@ -168,8 +163,6 @@ static textypeinfo_t *R_GetTexTypeInfo(int textype, int flags) { case TEXTYPE_PALETTE: return &textype_palette_compress; - case TEXTYPE_RGB: - return &textype_rgb_compress; case TEXTYPE_RGBA: return &textype_rgba_compress; default: @@ -186,9 +179,6 @@ static textypeinfo_t *R_GetTexTypeInfo(int textype, int flags) { 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: @@ -202,8 +192,6 @@ static textypeinfo_t *R_GetTexTypeInfo(int textype, int flags) { case TEXTYPE_PALETTE: return &textype_palette; - case TEXTYPE_RGB: - return &textype_rgb; case TEXTYPE_RGBA: return &textype_rgba; default: @@ -830,13 +818,13 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy { 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; } } @@ -857,7 +845,7 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy { 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 } @@ -869,7 +857,7 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy { 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 } @@ -881,7 +869,7 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy { 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 } @@ -897,13 +885,13 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy 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; @@ -912,7 +900,7 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy { 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 } @@ -992,10 +980,6 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden } } 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) { diff --git a/image.c b/image.c index dd2d1591..5059710e 100644 --- a/image.c +++ b/image.c @@ -1215,35 +1215,6 @@ static void Image_Resample32LerpLine (const unsigned char *in, unsigned char *ou } } -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) { @@ -1386,169 +1357,26 @@ void Image_Resample32Nolerp(const void *indata, int inwidth, int inheight, void } } -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; @@ -1566,7 +1394,7 @@ void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, in // 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; @@ -1574,72 +1402,34 @@ void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, in { // 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 @@ -1648,37 +1438,18 @@ void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, in { // 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"); diff --git a/image.h b/image.h index 47f5f4cf..24152f90 100644 --- a/image.h +++ b/image.h @@ -35,10 +35,10 @@ qboolean Image_WriteTGARGB_preflipped (const char *filename, int width, int heig 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); diff --git a/model_brush.c b/model_brush.c index ebcd7bf1..055dd106 100644 --- a/model_brush.c +++ b/model_brush.c @@ -30,7 +30,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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)"}; @@ -58,7 +57,6 @@ void Mod_BrushInit(void) 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); @@ -2402,9 +2400,9 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l) 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); @@ -3519,9 +3517,6 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend) // 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++) @@ -4140,9 +4135,6 @@ void static Mod_Q2BSP_Load(model_t *mod, void *buffer, void *bufferend) 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++) @@ -4453,8 +4445,9 @@ static void Mod_Q3BSP_LoadTriangles(lump_t *l) 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; @@ -4533,15 +4526,22 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump) 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]) { @@ -4557,29 +4557,25 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump) 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); } } } @@ -5211,7 +5207,7 @@ static void Mod_Q3BSP_LightPoint(model_t *model, const vec3_t p, vec3_t ambientc 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) { diff --git a/model_shared.h b/model_shared.h index 7c81f0a0..b49bdd06 100644 --- a/model_shared.h +++ b/model_shared.h @@ -666,9 +666,6 @@ model_brush_t; typedef struct model_brushq1_s { - // lightmap format, set to r_lightmaprgba when model is loaded - int lightmaprgba; - dmodel_t *submodels; int numvertexes; diff --git a/r_light.c b/r_light.c index 29fa6cb6..2452e9a6 100644 --- a/r_light.c +++ b/r_light.c @@ -62,7 +62,7 @@ void r_light_newmap(void) { 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) diff --git a/r_textures.h b/r_textures.h index 51978f81..4df426a6 100644 --- a/r_textures.h +++ b/r_textures.h @@ -25,8 +25,6 @@ // 8bit paletted #define TEXTYPE_PALETTE 1 -// 24bit RGB -#define TEXTYPE_RGB 2 // 32bit RGBA #define TEXTYPE_RGBA 3 -- 2.39.2