Browse Source

ref_soft: Separate buffer for transparent textures

pull/2/head
mittorn 6 years ago
parent
commit
e0ce5640d1
  1. 14
      r_draw.c
  2. 8
      r_image.c
  3. 3
      r_local.h
  4. 14
      r_surf.c

14
r_draw.c

@ -70,6 +70,8 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
unsigned int height; unsigned int height;
unsigned int f, fstep; unsigned int f, fstep;
int skip; int skip;
qboolean transparent = false;
pixel_t *buffer;
if( x < 0 ) if( x < 0 )
{ {
@ -104,6 +106,14 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
dest = vid.buffer + y * vid.rowbytes + x; dest = vid.buffer + y * vid.rowbytes + x;
if( pic->alpha_pixels )
{
buffer = pic->alpha_pixels;
transparent = true;
}
else
buffer = pic->pixels[0];
#pragma omp parallel for schedule(static) #pragma omp parallel for schedule(static)
for (v=0 ; v<height ; v++) for (v=0 ; v<height ; v++)
@ -112,7 +122,7 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
pixel_t *dest = vid.buffer + (y + v) * vid.rowbytes + x; pixel_t *dest = vid.buffer + (y + v) * vid.rowbytes + x;
#endif #endif
sv = (skip + v)*(t2-t1)/h + t1; sv = (skip + v)*(t2-t1)/h + t1;
source = pic->pixels[0] + sv*pic->width + s1; source = buffer + sv*pic->width + s1;
{ {
f = 0; f = 0;
fstep = s2*0x10000/w; fstep = s2*0x10000/w;
@ -137,7 +147,7 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
int alpha = vid.alpha; int alpha = vid.alpha;
f += fstep; f += fstep;
if( pic->transparent ) if( transparent )
{ {
alpha &= src >> 16 - 3; alpha &= src >> 16 - 3;
src = src << 3; src = src << 3;

8
r_image.c

@ -530,9 +530,9 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
size = GL_CalcImageSize( pic->type, 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 ); //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 ); tex->pixels[j] = Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 64 );
if( j == 0 && tex->flags & TF_HAS_ALPHA )
tex->alpha_pixels = Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 64 );
int x, y; int x, y;
if( tex->flags & TF_HAS_ALPHA )
tex->transparent = true;
for(i = 0; i < height * width; i++ ) for(i = 0; i < height * width; i++ )
{ {
@ -554,10 +554,10 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
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); 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); tex->pixels[j][i] = major << 8 | (minor & 0xFF);
if( tex->transparent ) if( j == 0 && tex->alpha_pixels )
{ {
unsigned int alpha = (pic->buffer[i * 4 + 3] * 8 / 256) << (16 - 3); unsigned int alpha = (pic->buffer[i * 4 + 3] * 8 / 256) << (16 - 3);
tex->pixels[j][i] = (tex->pixels[j][i] >> 3) | alpha; tex->alpha_pixels[i] = (tex->pixels[j][i] >> 3) | alpha;
} }
} }

3
r_local.h

@ -358,8 +358,9 @@ typedef struct image_s
float yscale; float yscale;
imagetype_t type; imagetype_t type;
qboolean transparent;
pixel_t *pixels[4]; // mip levels pixel_t *pixels[4]; // mip levels
pixel_t *alpha_pixels; // mip levels
int servercount; int servercount;
uint hashValue; uint hashValue;

14
r_surf.c

@ -180,7 +180,6 @@ texture_t *R_TextureAnimation( msurface_t *s )
return base; return base;
} }
static char r_transtexture;
/* /*
=============== ===============
R_DrawSurface R_DrawSurface
@ -200,7 +199,6 @@ void R_DrawSurface (void)
surfrowbytes = r_drawsurf.rowbytes; surfrowbytes = r_drawsurf.rowbytes;
mt = r_drawsurf.image; mt = r_drawsurf.image;
r_transtexture = mt->transparent;
r_source = mt->pixels[r_drawsurf.surfmip]; r_source = mt->pixels[r_drawsurf.surfmip];
@ -277,7 +275,6 @@ void R_DrawSurfaceBlock8_mip0 (void)
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
char transtexture = r_transtexture;
for (v=0 ; v<r_numvblocks ; v++) for (v=0 ; v<r_numvblocks ; v++)
{ {
@ -299,8 +296,6 @@ void R_DrawSurfaceBlock8_mip0 (void)
for (b=15; b>=0; b--) for (b=15; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
if( transtexture )
pix = pix << 3;
prowdest[b] = pix; prowdest[b] = pix;
//((unsigned char *)vid.colormap) //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix]; //[(light & 0xFF00) + pix];
@ -328,7 +323,6 @@ void R_DrawSurfaceBlock8_mip1 (void)
{ {
int v, i, b, lightstep, lighttemp, light; int v, i, b, lightstep, lighttemp, light;
pixel_t pix, *psource, *prowdest; pixel_t pix, *psource, *prowdest;
char transtexture = r_transtexture;
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
@ -353,8 +347,6 @@ void R_DrawSurfaceBlock8_mip1 (void)
for (b=7; b>=0; b--) for (b=7; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
if( transtexture )
pix = pix << 3;
prowdest[b] = pix; prowdest[b] = pix;
//((unsigned char *)vid.colormap) //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix]; //[(light & 0xFF00) + pix];
@ -382,7 +374,6 @@ void R_DrawSurfaceBlock8_mip2 (void)
{ {
int v, i, b, lightstep, lighttemp, light; int v, i, b, lightstep, lighttemp, light;
pixel_t pix, *psource, *prowdest; pixel_t pix, *psource, *prowdest;
char transtexture = r_transtexture;
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
@ -407,8 +398,6 @@ void R_DrawSurfaceBlock8_mip2 (void)
for (b=3; b>=0; b--) for (b=3; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
if( transtexture )
pix = pix << 3;
prowdest[b] = pix; prowdest[b] = pix;
//((unsigned char *)vid.colormap) //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix]; //[(light & 0xFF00) + pix];
@ -436,7 +425,6 @@ void R_DrawSurfaceBlock8_mip3 (void)
{ {
int v, i, b, lightstep, lighttemp, light; int v, i, b, lightstep, lighttemp, light;
pixel_t pix, *psource, *prowdest; pixel_t pix, *psource, *prowdest;
char transtexture = r_transtexture;
psource = pbasesource; psource = pbasesource;
prowdest = prowdestbase; prowdest = prowdestbase;
@ -461,8 +449,6 @@ void R_DrawSurfaceBlock8_mip3 (void)
for (b=1; b>=0; b--) for (b=1; b>=0; b--)
{ {
pix = psource[b]; pix = psource[b];
if( transtexture )
pix = pix << 3;
prowdest[b] = pix; prowdest[b] = pix;
//((unsigned char *)vid.colormap) //((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix]; //[(light & 0xFF00) + pix];

Loading…
Cancel
Save