Browse Source

ref_soft: TriAPI texturing, rendermodes

pull/2/head
mittorn 6 years ago
parent
commit
7fc09da482
  1. 47
      r_image.c
  2. 2
      r_local.h
  3. 4
      r_main.c
  4. 3
      r_part.c
  5. 324
      r_polyse.c
  6. 8
      r_sprite.c
  7. 10
      r_studio.c
  8. 7
      r_trialias.c
  9. 39
      r_triapi.c

47
r_image.c

@ -42,9 +42,47 @@ GL_Bind @@ -42,9 +42,47 @@ GL_Bind
*/
void GL_Bind( int tmu, unsigned int texnum )
{
image_t *texture;
image_t *image;
extern void (*d_pdrawspans)(void *);
extern void R_PolysetFillSpans8 ( void * );
extern void R_PolysetDrawSpansConstant8_33( void *pspanpackage);
extern void R_PolysetDrawSpansTextureBlended( void *pspanpackage);
extern void R_PolysetDrawSpansBlended( void *pspanpackage);
extern void R_PolysetDrawSpansAdditive( void *pspanpackage);
extern void R_PolysetDrawSpansGlow( void *pspanpackage);
texture = &r_images[texnum];
image = &r_images[texnum];
//vid.rendermode = kRenderNormal;
if( vid.rendermode == kRenderNormal )
{
r_affinetridesc.pskin = image->pixels[0];
d_pdrawspans = R_PolysetFillSpans8 ;
}
else if( vid.rendermode == kRenderTransAdd)
{
r_affinetridesc.pskin = image->pixels[0];
d_pdrawspans = R_PolysetDrawSpansAdditive;
}
else if( vid.rendermode == kRenderGlow )
{
r_affinetridesc.pskin = image->pixels[0];
d_pdrawspans = R_PolysetDrawSpansGlow;
}
else if( image->alpha_pixels )
{
r_affinetridesc.pskin = image->alpha_pixels;
d_pdrawspans = R_PolysetDrawSpansTextureBlended;
}
else
{
r_affinetridesc.pskin = image->pixels[0];
d_pdrawspans = R_PolysetDrawSpansBlended;
}
r_affinetridesc.skinwidth = image->width;
r_affinetridesc.skinheight = image->height;
}
/*
@ -533,7 +571,10 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) @@ -533,7 +571,10 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
//GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data );
// increase size to workaround triangle renderer bugs
// it seems to assume memory readable. maybe it was pointed to WAD?
tex->pixels[j] = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 1024 ) + 512;
tex->pixels[j] = (byte*)Mem_Malloc( r_temppool, width * height * sizeof(pixel_t) + 1024 ) + 512;
memset( (byte*)tex->pixels[j] - 512, 0xFF, 512 );
memset( (byte*)tex->pixels[j] + width * height * sizeof(pixel_t), 0xFF, 512 );
if( j == 0 && tex->flags & TF_HAS_ALPHA )
tex->alpha_pixels = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 256 ) + 128;

2
r_local.h

@ -1340,6 +1340,8 @@ void R_SetUpWorldTransform (void); @@ -1340,6 +1340,8 @@ void R_SetUpWorldTransform (void);
#define BLEND_ALPHA_LOW(alpha, src, screen) (vid.alphamap[(alpha << 18) |( (src & 0xff00) << 2) | (screen >> 6)] | screen & 0x3f)
#define BLEND_ALPHA(alpha, src, dst) alpha > 3?BLEND_ALPHA_LOW(7 - 1 - alpha, dst,src):BLEND_ALPHA_LOW(alpha-1, src, dst)
#define BLEND_ADD(src, screen) vid.addmap[ src& 0xff00|(screen>>8)] << 8 | (screen & 0xff) | ((src & 0xff) >> 0);
#define BLEND_COLOR(src, color) vid.modmap[src & 0xff00|(color>>8)] << 8 | (src & color & 0xff) | ((src & 0xff) >> 3);
//
// engine callbacks

4
r_main.c

@ -976,6 +976,7 @@ void R_DrawEntitiesOnList( void ) @@ -976,6 +976,7 @@ void R_DrawEntitiesOnList( void )
extern void R_PolysetDrawSpansConstant8_33( void *pspanpackage);
extern void R_PolysetDrawSpans8_33( void *pspanpackage);
d_pdrawspans = R_PolysetFillSpans8;
GL_SetRenderMode(kRenderNormal);
// first draw solid entities
for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ )
{
@ -1120,8 +1121,7 @@ void R_DrawEntitiesOnList( void ) @@ -1120,8 +1121,7 @@ void R_DrawEntitiesOnList( void )
//GL_CheckForErrors();
// pglDisable( GL_BLEND ); // Trinity Render issues
d_pdrawspans = R_PolysetFillSpans8;
GL_SetRenderMode(kRenderNormal);
R_SetUpWorldTransform();
if( !RI.onlyClientDraw )
R_DrawViewModel();

3
r_part.c

@ -60,6 +60,7 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float @@ -60,6 +60,7 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float
//pglEnable( GL_BLEND );
//pglDisable( GL_ALPHA_TEST );
//pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
GL_SetRenderMode( kRenderTransAdd );
GL_Bind( XASH_TEXTURE0, tr.particleTexture );
//pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
@ -182,6 +183,8 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) @@ -182,6 +183,8 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers )
if( !cl_active_tracers )
return; // nothing to draw?
GL_SetRenderMode( kRenderTransAdd );
if( !TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_DOT_SPRITE ), 0 ))
return;

324
r_polyse.c

@ -682,6 +682,330 @@ void R_PolysetCalcGradients (int skinwidth) @@ -682,6 +682,330 @@ void R_PolysetCalcGradients (int skinwidth)
#endif
/*
================
R_PolysetDrawSpans8
================
*/
void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage)
{
int lcount;
pixel_t *lpdest;
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
short *lpz;
do
{
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
if (errorterm >= 0)
{
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
}
else
{
d_aspancount += ubasestep;
}
if (lcount)
{
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
lzi = pspanpackage->zi;
do
{
if ((lzi >> 16) >= *lpz)
{
#if 0
if((int)(lptex - (pixel_t*)r_affinetridesc.pskin) > r_affinetridesc.skinwidth * r_affinetridesc.skinheight || (int)(lptex - (pixel_t*)r_affinetridesc.pskin) < 0 )
{
printf("%d %d %d %d\n",(int)(lptex - (pixel_t*)r_affinetridesc.pskin), r_affinetridesc.skinwidth * r_affinetridesc.skinheight, lsfrac, a_ststepxwhole );
return;
}
#endif
pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )];
temp = BLEND_COLOR(temp, vid.color);
int alpha = vid.alpha;
if( alpha == 7 )
*lpdest = temp;
else if(alpha)
*lpdest = BLEND_ALPHA(alpha,temp,*lpdest);//vid.alphamap[temp+ *lpdest*256];
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
if (ltfrac & 0x10000)
{
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
} while (--lcount);
}
pspanpackage++;
} while (pspanpackage->count != -999999);
}
/*
================
R_PolysetDrawSpans8
================
*/
void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage)
{
int lcount;
pixel_t *lpdest;
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
short *lpz;
do
{
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
if (errorterm >= 0)
{
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
}
else
{
d_aspancount += ubasestep;
}
if (lcount)
{
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
lzi = pspanpackage->zi;
do
{
if ((lzi >> 16) >= *lpz)
{
#if 0
if((int)(lptex - (pixel_t*)r_affinetridesc.pskin) > r_affinetridesc.skinwidth * r_affinetridesc.skinheight || (int)(lptex - (pixel_t*)r_affinetridesc.pskin) < 0 )
{
printf("%d %d %d %d\n",(int)(lptex - (pixel_t*)r_affinetridesc.pskin), r_affinetridesc.skinwidth * r_affinetridesc.skinheight, lsfrac, a_ststepxwhole );
return;
}
#endif
pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )];
temp = BLEND_COLOR(temp, vid.color);
*lpdest = BLEND_ADD(temp,*lpdest);
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
if (ltfrac & 0x10000)
{
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
} while (--lcount);
}
pspanpackage++;
} while (pspanpackage->count != -999999);
}
/*
================
R_PolysetDrawSpans8
================
*/
void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage)
{
int lcount;
pixel_t *lpdest;
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
short *lpz;
do
{
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
if (errorterm >= 0)
{
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
}
else
{
d_aspancount += ubasestep;
}
if (lcount)
{
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
lzi = pspanpackage->zi;
do
{
//if ((lzi >> 16) >= *lpz)
{
#if 0
if((int)(lptex - (pixel_t*)r_affinetridesc.pskin) > r_affinetridesc.skinwidth * r_affinetridesc.skinheight || (int)(lptex - (pixel_t*)r_affinetridesc.pskin) < 0 )
{
printf("%d %d %d %d\n",(int)(lptex - (pixel_t*)r_affinetridesc.pskin), r_affinetridesc.skinwidth * r_affinetridesc.skinheight, lsfrac, a_ststepxwhole );
return;
}
#endif
pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )];
temp = BLEND_COLOR(temp, vid.color);
*lpdest = BLEND_ADD(temp,*lpdest);
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
if (ltfrac & 0x10000)
{
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
} while (--lcount);
}
pspanpackage++;
} while (pspanpackage->count != -999999);
}
/*
================
R_PolysetDrawSpans8
================
*/
void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage)
{
int lcount;
pixel_t *lpdest;
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
short *lpz;
do
{
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
if (errorterm >= 0)
{
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
}
else
{
d_aspancount += ubasestep;
}
if (lcount)
{
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
lzi = pspanpackage->zi;
do
{
if ((lzi >> 16) >= *lpz)
{
#if 0
if((int)(lptex - (pixel_t*)r_affinetridesc.pskin) > r_affinetridesc.skinwidth * r_affinetridesc.skinheight || (int)(lptex - (pixel_t*)r_affinetridesc.pskin) < 0 )
{
printf("%d %d %d %d\n",(int)(lptex - (pixel_t*)r_affinetridesc.pskin), r_affinetridesc.skinwidth * r_affinetridesc.skinheight, lsfrac, a_ststepxwhole );
return;
}
#endif
pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )];
int alpha = temp >> 13;
temp = temp << 3;
temp = BLEND_COLOR(temp, vid.color);
if( alpha == 7 )
*lpdest = temp;
else if(alpha)
*lpdest = BLEND_ALPHA(alpha,temp,*lpdest);//vid.alphamap[temp+ *lpdest*256];
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
if (ltfrac & 0x10000)
{
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
} while (--lcount);
}
pspanpackage++;
} while (pspanpackage->count != -999999);
}
/*
================
R_PolysetDrawSpans8

8
r_sprite.c

@ -671,7 +671,9 @@ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, flo @@ -671,7 +671,9 @@ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, flo
tr = gEngfuncs.EV_VisTraceLine( RI.vieworg, origin, r_traceglow->value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE));
if(( 1.0f - tr->fraction ) * dist > 8.0f )
{
return 0.0f;
}
}
if( renderfx == kRenderFxNoDissipation )
@ -731,10 +733,10 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, @@ -731,10 +733,10 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right,
image_t *image;
r_stats.c_sprite_polys++;
image = R_GetTexture(frame->gl_texturenum);
/*image = R_GetTexture(frame->gl_texturenum);
r_affinetridesc.pskin = image->pixels[0];
r_affinetridesc.skinwidth = image->width;
r_affinetridesc.skinheight = image->height;
r_affinetridesc.skinheight = image->height;*/
TriBegin( TRI_QUADS );
TriTexCoord2f( 0.0f, 1.0f );
@ -920,6 +922,8 @@ void R_DrawSpriteModel( cl_entity_t *e ) @@ -920,6 +922,8 @@ void R_DrawSpriteModel( cl_entity_t *e )
if( e->curstate.rendermode == kRenderGlow || e->curstate.rendermode == kRenderTransAdd )
R_AllowFog( false );
GL_SetRenderMode( e->curstate.rendermode );
#if 0
// select properly rendermode
switch( e->curstate.rendermode )

10
r_studio.c

@ -1814,14 +1814,10 @@ R_StudioSetupSkin @@ -1814,14 +1814,10 @@ R_StudioSetupSkin
static void R_StudioSetupSkin( studiohdr_t *ptexturehdr, int index )
{
mstudiotexture_t *ptexture = NULL;
image_t *image;
if( FBitSet( g_nForceFaceFlags, STUDIO_NF_CHROME ))
{
image = R_GetTexture(tr.whiteTexture);
r_affinetridesc.pskin = image->pixels[0];
r_affinetridesc.skinwidth = image->width;
r_affinetridesc.skinheight = image->height;
GL_Bind( XASH_TEXTURE0, tr.whiteTexture);
return;
}
@ -1835,10 +1831,6 @@ static void R_StudioSetupSkin( studiohdr_t *ptexturehdr, int index ) @@ -1835,10 +1831,6 @@ static void R_StudioSetupSkin( studiohdr_t *ptexturehdr, int index )
if( r_lightmap->value && !r_fullbright->value )
GL_Bind( XASH_TEXTURE0, tr.whiteTexture );
else GL_Bind( XASH_TEXTURE0, ptexture[index].index );
image = R_GetTexture(ptexture[index].index);
r_affinetridesc.pskin = image->pixels[0];
r_affinetridesc.skinwidth = image->width;
r_affinetridesc.skinheight = image->height;
}
/*

7
r_trialias.c

@ -238,6 +238,13 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) @@ -238,6 +238,13 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv )
fv->flags |= ALIAS_BOTTOM_CLIP;
}
void R_AliasWorldToScreen( const float *v, float *out )
{
out[0] = DotProduct(v, aliastransform[0]) + aliastransform[0][3];
out[1] = DotProduct(v, aliastransform[1]) + aliastransform[1][3];
out[2] = DotProduct(v, aliastransform[2]) + aliastransform[2][3];
}
void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, int s, int t )
{
vec3_t v = {x, y, z};

39
r_triapi.c

@ -155,7 +155,7 @@ void _TriColor4f( float rr, float gg, float bb, float aa ) @@ -155,7 +155,7 @@ void _TriColor4f( float rr, float gg, float bb, float aa )
if( light > 31 )
light = 31;
if( !vid.is2d )
if( !vid.is2d && vid.rendermode == kRenderNormal )
return;
vid.alpha = aa * 7;
@ -168,6 +168,12 @@ void _TriColor4f( float rr, float gg, float bb, float aa ) @@ -168,6 +168,12 @@ void _TriColor4f( float rr, float gg, float bb, float aa )
return;
}
r = rr * 31, g = gg * 63, b = bb * 31;
if( r > 31 )
r = 31;
if( g > 63 )
g = 63;
if( b > 31 )
b = 31;
major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2)));
@ -191,7 +197,7 @@ void TriColor4ub( byte r, byte g, byte b, byte a ) @@ -191,7 +197,7 @@ void TriColor4ub( byte r, byte g, byte b, byte a )
ds.triRGBA[2] = b * (1.0f / 255.0f);
ds.triRGBA[3] = a * (1.0f / 255.0f);
_TriColor4f( ds.triRGBA[0], ds.triRGBA[1], ds.triRGBA[2], ds.triRGBA[3] ); //1.0f );
_TriColor4f( ds.triRGBA[0], ds.triRGBA[1], ds.triRGBA[2], 1.0f );
}
/*
@ -201,8 +207,10 @@ TriColor4f @@ -201,8 +207,10 @@ TriColor4f
*/
void TriColor4f( float r, float g, float b, float a )
{
//if( a < 0.5 )
// a = 1;
if( ds.renderMode == kRenderTransAlpha )
TriColor4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f );
TriColor4ub( r * 255.0f, g * 255.0f, b * 255.0f, a * 255.0f );
else _TriColor4f( r * a, g * a, b * a, 1.0 );
ds.triRGBA[0] = r;
@ -220,8 +228,17 @@ TriTexCoord2f @@ -220,8 +228,17 @@ TriTexCoord2f
void TriTexCoord2f( float u, float v )
{
//pglTexCoord2f( u, v );
s = r_affinetridesc.skinwidth * bound(0,u,1);
t = r_affinetridesc.skinheight * bound(0,v,1);
while( u < 0 )
u = u + 1;
while( v < 0 )
v = v + 1;
while( u > 1 )
u = u - 1;
while( v > 1 )
v = v - 1;
s = r_affinetridesc.skinwidth * bound(0.01,u,0.99);
t = r_affinetridesc.skinheight * bound(0.01,v,0.99);
}
/*
@ -251,7 +268,7 @@ void TriVertex3f( float x, float y, float z ) @@ -251,7 +268,7 @@ void TriVertex3f( float x, float y, float z )
if( vertcount == 3 )
{
R_RenderTriangle( &triv[0], &triv[1], &triv[2] );
R_RenderTriangle( &triv[2], &triv[1], &triv[0] );
//R_RenderTriangle( &triv[2], &triv[1], &triv[0] );
vertcount = 0;
}
}
@ -262,6 +279,7 @@ void TriVertex3f( float x, float y, float z ) @@ -262,6 +279,7 @@ void TriVertex3f( float x, float y, float z )
if( vertcount >= 3 )
{
R_RenderTriangle( &triv[0], &triv[1], &triv[2] );
//R_RenderTriangle( &triv[2], &triv[1], &triv[0] );
triv[1] = triv[2];
vertcount = 2;
}
@ -305,7 +323,7 @@ void TriVertex3f( float x, float y, float z ) @@ -305,7 +323,7 @@ void TriVertex3f( float x, float y, float z )
}
#endif
}
void R_AliasWorldToScreen( const float *v, float *out );
/*
=============
TriWorldToScreen
@ -317,7 +335,9 @@ int TriWorldToScreen( const float *world, float *screen ) @@ -317,7 +335,9 @@ int TriWorldToScreen( const float *world, float *screen )
{
int retval;
// retval = R_WorldToScreen( world, screen );
R_AliasWorldToScreen( world, screen );
retval = 0;
screen[0] = 0.5f * screen[0] * (float)RI.viewport[2];
screen[1] = -0.5f * screen[1] * (float)RI.viewport[3];
@ -451,6 +471,9 @@ void TriBrightness( float brightness ) @@ -451,6 +471,9 @@ void TriBrightness( float brightness )
{
float r, g, b;
//if( brightness < 0.5 )
// brightness = 1; //0.5;
//ds.triRGBA[3] = 1;
r = ds.triRGBA[0] * ds.triRGBA[3] * brightness;
g = ds.triRGBA[1] * ds.triRGBA[3] * brightness;
b = ds.triRGBA[2] * ds.triRGBA[3] * brightness;

Loading…
Cancel
Save