Browse Source

ref_soft: mipmap support

pull/2/head
mittorn 6 years ago
parent
commit
bf0d694c71
  1. 2
      r_edge.c
  2. 81
      r_image.c
  3. 66
      r_surf.c

2
r_edge.c

@ -1011,7 +1011,7 @@ void D_SolidSurf (surf_t *s)
pface = s->msurf; pface = s->msurf;
#if 1 #if 1
miplevel = 0; //D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust); miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip );
#else #else
{ {
float dot; float dot;

81
r_image.c

@ -509,40 +509,67 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
if( !pic->buffer ) if( !pic->buffer )
return true; return true;
/// TODO: generate mipmaps buf = pic->buffer;
if( tex->flags & TF_HAS_ALPHA ) int mipCount = 4;//GL_CalcMipmapCount( tex, ( buf != NULL ));
tex->transparent = true;
tex->pixels[0] = Mem_Calloc( r_temppool, tex->width * tex->height * sizeof(pixel_t) + 64 ); // NOTE: only single uncompressed textures can be resamples, no mips, no layers, no sides
if(( tex->depth == 1 ) && ( pic->width != tex->width ) || ( pic->height != tex->height ))
data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap );
else data = buf;
for( i = 0; i < tex->width * tex->height; i++ ) //if( !ImageDXT( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
{ // data = GL_ApplyFilter( data, tex->width, tex->height );
unsigned int r, g, b, major, minor;
#if 0
r = pic->buffer[i * 4 + 0] * MASK(5-1) / 255;
g = pic->buffer[i * 4 + 1] * MASK(6-1) / 255;
b = pic->buffer[i * 4 + 2] * MASK(5-1) / 255;
#else
// seems to look better
r = pic->buffer[i * 4 + 0] * BIT(5) / 256;
g = pic->buffer[i * 4 + 1] * BIT(6) / 256;
b = pic->buffer[i * 4 + 2] * BIT(5) / 256;
#endif
// 565 to 332
major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2)));
// save minor GBRGBRGB // mips will be auto-generated if desired
minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0); for( j = 0; j < mipCount; j++ )
{
tex->pixels[0][i] = major << 8 | (minor & 0xFF); width = Q_max( 1, ( tex->width >> j ));
if( tex->transparent ) height = Q_max( 1, ( tex->height >> j ));
texsize = GL_CalcTextureSize( width, height, tex->depth );
size = GL_CalcImageSize( pic->type, width, height, tex->depth );
//GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data );
tex->pixels[j] = Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 64 );
int x, y;
if( tex->flags & TF_HAS_ALPHA )
tex->transparent = true;
for(i = 0; i < height * width; i++ )
{ {
unsigned int alpha = (pic->buffer[i * 4 + 3] * 8 / 256) << (16 - 3); unsigned int r, g, b, major, minor;
tex->pixels[0][i] = (tex->pixels[0][i] >> 3) | alpha; #if 0
r = data[i * 4 + 0] * MASK(5-1) / 255;
g = data[i * 4 + 1] * MASK(6-1) / 255;
b = data[i * 4 + 2] * MASK(5-1) / 255;
#else
// seems to look better
r = data[i * 4 + 0] * BIT(5) / 256;
g = data[i * 4 + 1] * BIT(6) / 256;
b = data[i * 4 + 2] * BIT(5) / 256;
#endif
// 565 to 332
major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2)));
// save minor GBRGBRGB
minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0);
tex->pixels[j][i] = major << 8 | (minor & 0xFF);
if( tex->transparent )
{
unsigned int alpha = (pic->buffer[i * 4 + 3] * 8 / 256) << (16 - 3);
tex->pixels[j][i] = (tex->pixels[j][i] >> 3) | alpha;
}
} }
}
if( mipCount > 1 )
GL_BuildMipMap( data, width, height, tex->depth, tex->flags );
tex->size += texsize;
tex->numMips++;
//GL_CheckTexImageError( tex );
}
#if 0 #if 0

66
r_surf.c

@ -200,7 +200,6 @@ void R_DrawSurface (void)
surfrowbytes = r_drawsurf.rowbytes; surfrowbytes = r_drawsurf.rowbytes;
mt = r_drawsurf.image; mt = r_drawsurf.image;
r_drawsurf.surfmip = 0;
r_source = mt->pixels[r_drawsurf.surfmip]; r_source = mt->pixels[r_drawsurf.surfmip];
@ -220,7 +219,7 @@ void R_DrawSurface (void)
//============================== //==============================
pblockdrawer = surfmiptable[0]; pblockdrawer = surfmiptable[r_drawsurf.surfmip];
// TODO: only needs to be set when there is a display settings change // TODO: only needs to be set when there is a display settings change
horzblockstep = blocksize; horzblockstep = blocksize;
@ -324,7 +323,7 @@ R_DrawSurfaceBlock8_mip1
void R_DrawSurfaceBlock8_mip1 (void) void R_DrawSurfaceBlock8_mip1 (void)
{ {
int v, i, b, lightstep, lighttemp, light; int v, i, b, lightstep, lighttemp, light;
unsigned char pix, *psource, *prowdest; pixel_t pix, *psource, *prowdest;
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
@ -333,11 +332,11 @@ void R_DrawSurfaceBlock8_mip1 (void)
{ {
// FIXME: make these locals? // FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM? // FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0]; //lightleft = r_lightptr[0];
lightright = r_lightptr[1]; //lightright = r_lightptr[1];
r_lightptr += r_lightwidth; //r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 3; //lightleftstep = (r_lightptr[0] - lightleft) >> 3;
lightrightstep = (r_lightptr[1] - lightright) >> 3; //lightrightstep = (r_lightptr[1] - lightright) >> 3;
for (i=0 ; i<8 ; i++) for (i=0 ; i<8 ; i++)
{ {
@ -349,14 +348,15 @@ void R_DrawSurfaceBlock8_mip1 (void)
for (b=7; b>=0; b--) for (b=7; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
prowdest[b] = ((unsigned char *)vid.colormap) prowdest[b] = pix;
[(light & 0xFF00) + pix]; //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix];
light += lightstep; light += lightstep;
} }
psource += sourcetstep; psource += sourcetstep;
lightright += lightrightstep; //lightright += lightrightstep;
lightleft += lightleftstep; //lightleft += lightleftstep;
prowdest += surfrowbytes; prowdest += surfrowbytes;
} }
@ -374,7 +374,7 @@ R_DrawSurfaceBlock8_mip2
void R_DrawSurfaceBlock8_mip2 (void) void R_DrawSurfaceBlock8_mip2 (void)
{ {
int v, i, b, lightstep, lighttemp, light; int v, i, b, lightstep, lighttemp, light;
unsigned char pix, *psource, *prowdest; pixel_t pix, *psource, *prowdest;
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
@ -383,11 +383,11 @@ void R_DrawSurfaceBlock8_mip2 (void)
{ {
// FIXME: make these locals? // FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM? // FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0]; //lightleft = r_lightptr[0];
lightright = r_lightptr[1]; //lightright = r_lightptr[1];
r_lightptr += r_lightwidth; //r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 2; //lightleftstep = (r_lightptr[0] - lightleft) >> 2;
lightrightstep = (r_lightptr[1] - lightright) >> 2; //lightrightstep = (r_lightptr[1] - lightright) >> 2;
for (i=0 ; i<4 ; i++) for (i=0 ; i<4 ; i++)
{ {
@ -399,14 +399,15 @@ void R_DrawSurfaceBlock8_mip2 (void)
for (b=3; b>=0; b--) for (b=3; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
prowdest[b] = ((unsigned char *)vid.colormap) prowdest[b] = pix;
[(light & 0xFF00) + pix]; //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix];
light += lightstep; light += lightstep;
} }
psource += sourcetstep; psource += sourcetstep;
lightright += lightrightstep; //lightright += lightrightstep;
lightleft += lightleftstep; //lightleft += lightleftstep;
prowdest += surfrowbytes; prowdest += surfrowbytes;
} }
@ -424,7 +425,7 @@ R_DrawSurfaceBlock8_mip3
void R_DrawSurfaceBlock8_mip3 (void) void R_DrawSurfaceBlock8_mip3 (void)
{ {
int v, i, b, lightstep, lighttemp, light; int v, i, b, lightstep, lighttemp, light;
unsigned char pix, *psource, *prowdest; pixel_t pix, *psource, *prowdest;
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
@ -433,11 +434,11 @@ void R_DrawSurfaceBlock8_mip3 (void)
{ {
// FIXME: make these locals? // FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM? // FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0]; //lightleft = r_lightptr[0];
lightright = r_lightptr[1]; //lightright = r_lightptr[1];
r_lightptr += r_lightwidth; //r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 1; //lightleftstep = (r_lightptr[0] - lightleft) >> 1;
lightrightstep = (r_lightptr[1] - lightright) >> 1; //lightrightstep = (r_lightptr[1] - lightright) >> 1;
for (i=0 ; i<2 ; i++) for (i=0 ; i<2 ; i++)
{ {
@ -449,14 +450,15 @@ void R_DrawSurfaceBlock8_mip3 (void)
for (b=1; b>=0; b--) for (b=1; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
prowdest[b] = ((unsigned char *)vid.colormap) prowdest[b] = pix;
[(light & 0xFF00) + pix]; //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix];
light += lightstep; light += lightstep;
} }
psource += sourcetstep; psource += sourcetstep;
lightright += lightrightstep; //lightright += lightrightstep;
lightleft += lightleftstep; //lightleft += lightleftstep;
prowdest += surfrowbytes; prowdest += surfrowbytes;
} }

Loading…
Cancel
Save