ref_soft: mipmap support

This commit is contained in:
mittorn 2019-03-23 02:37:56 +07:00
parent a2e689aba3
commit bf0d694c71
3 changed files with 89 additions and 60 deletions

View File

@ -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;

View File

@ -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 );
// mips will be auto-generated if desired
for( j = 0; j < mipCount; j++ )
{ {
unsigned int r, g, b, major, minor; width = Q_max( 1, ( tex->width >> j ));
#if 0 height = Q_max( 1, ( tex->height >> j ));
r = pic->buffer[i * 4 + 0] * MASK(5-1) / 255; texsize = GL_CalcTextureSize( width, height, tex->depth );
g = pic->buffer[i * 4 + 1] * MASK(6-1) / 255; size = GL_CalcImageSize( pic->type, width, height, tex->depth );
b = pic->buffer[i * 4 + 2] * MASK(5-1) / 255; //GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data );
#else tex->pixels[j] = Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 64 );
// seems to look better int x, y;
r = pic->buffer[i * 4 + 0] * BIT(5) / 256; if( tex->flags & TF_HAS_ALPHA )
g = pic->buffer[i * 4 + 1] * BIT(6) / 256; tex->transparent = true;
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 for(i = 0; i < height * width; i++ )
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[0][i] = major << 8 | (minor & 0xFF);
if( tex->transparent )
{ {
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

View File

@ -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;
} }