?? r_polyse.c
字號:
lpz++;
} while (--lcount);
}
pspanpackage++;
} while (pspanpackage->count != -999999);
}
#if !id386
void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage)
{
int lcount;
do
{
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
if (errorterm >= 0)
{
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
}
else
{
d_aspancount += ubasestep;
}
if (lcount)
{
int lsfrac, ltfrac;
byte *lpdest;
byte *lptex;
int llight;
int lzi;
short *lpz;
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)
{
//PGM
if(r_newrefdef.rdflags & RDF_IRGOGGLES && currententity->flags & RF_IR_VISIBLE)
*lpdest = ((byte *)vid.colormap)[irtable[*lptex]];
else
*lpdest = ((byte *)vid.colormap)[*lptex + (llight & 0xFF00)];
//PGM
*lpz = lzi >> 16;
}
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);
}
#endif
/*
================
R_PolysetFillSpans8
================
*/
void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
{
int color;
// FIXME: do z buffering
color = d_aflatcolor++;
while (1)
{
int lcount;
byte *lpdest;
lcount = pspanpackage->count;
if (lcount == -1)
return;
if (lcount)
{
lpdest = pspanpackage->pdest;
do
{
*lpdest++ = color;
} while (--lcount);
}
pspanpackage++;
}
}
/*
================
R_RasterizeAliasPolySmooth
================
*/
void R_RasterizeAliasPolySmooth (void)
{
int initialleftheight, initialrightheight;
int *plefttop, *prighttop, *pleftbottom, *prightbottom;
int working_lstepx, originalcount;
plefttop = pedgetable->pleftedgevert0;
prighttop = pedgetable->prightedgevert0;
pleftbottom = pedgetable->pleftedgevert1;
prightbottom = pedgetable->prightedgevert1;
initialleftheight = pleftbottom[1] - plefttop[1];
initialrightheight = prightbottom[1] - prighttop[1];
//
// set the s, t, and light gradients, which are consistent across the triangle
// because being a triangle, things are affine
//
R_PolysetCalcGradients (r_affinetridesc.skinwidth);
//
// rasterize the polygon
//
//
// scan out the top (and possibly only) part of the left edge
//
d_pedgespanpackage = a_spans;
ystart = plefttop[1];
d_aspancount = plefttop[0] - prighttop[0];
d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
(plefttop[3] >> 16) * r_affinetridesc.skinwidth;
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_sfrac = (plefttop[2] & 0xFFFF) << 16;
d_tfrac = (plefttop[3] & 0xFFFF) << 16;
}
//#else
else
#endif
{
d_sfrac = plefttop[2] & 0xFFFF;
d_tfrac = plefttop[3] & 0xFFFF;
}
//#endif
d_light = plefttop[4];
d_zi = plefttop[5];
d_pdest = (byte *)d_viewbuffer +
ystart * r_screenwidth + plefttop[0];
d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
if (initialleftheight == 1)
{
d_pedgespanpackage->pdest = d_pdest;
d_pedgespanpackage->pz = d_pz;
d_pedgespanpackage->count = d_aspancount;
d_pedgespanpackage->ptex = d_ptex;
d_pedgespanpackage->sfrac = d_sfrac;
d_pedgespanpackage->tfrac = d_tfrac;
// FIXME: need to clamp l, s, t, at both ends?
d_pedgespanpackage->light = d_light;
d_pedgespanpackage->zi = d_zi;
d_pedgespanpackage++;
}
else
{
R_PolysetSetUpForLineScan(plefttop[0], plefttop[1],
pleftbottom[0], pleftbottom[1]);
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_pzbasestep = (d_zwidth + ubasestep) << 1;
d_pzextrastep = d_pzbasestep + 2;
}
//#else
else
#endif
{
d_pzbasestep = d_zwidth + ubasestep;
d_pzextrastep = d_pzbasestep + 1;
}
//#endif
d_pdestbasestep = r_screenwidth + ubasestep;
d_pdestextrastep = d_pdestbasestep + 1;
// TODO: can reuse partial expressions here
// for negative steps in x along left edge, bias toward overflow rather than
// underflow (sort of turning the floor () we did in the gradient calcs into
// ceil (), but plus a little bit)
if (ubasestep < 0)
working_lstepx = r_lstepx - 1;
else
working_lstepx = r_lstepx;
d_countextrastep = ubasestep + 1;
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
((r_tstepy + r_tstepx * ubasestep) >> 16) *
r_affinetridesc.skinwidth;
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
}
else
#endif
{
//#else
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
}
//#endif
d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
r_affinetridesc.skinwidth;
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) << 16;
d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) << 16;
}
else
#endif
{
//#else
d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) & 0xFFFF;
d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) & 0xFFFF;
}
//#endif
d_lightextrastep = d_lightbasestep + working_lstepx;
d_ziextrastep = d_zibasestep + r_zistepx;
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
R_PolysetScanLeftEdge (initialleftheight);
}
else
#endif
{
R_PolysetScanLeftEdge_C(initialleftheight);
}
}
//
// scan out the bottom part of the left edge, if it exists
//
if (pedgetable->numleftedges == 2)
{
int height;
plefttop = pleftbottom;
pleftbottom = pedgetable->pleftedgevert2;
height = pleftbottom[1] - plefttop[1];
// TODO: make this a function; modularize this function in general
ystart = plefttop[1];
d_aspancount = plefttop[0] - prighttop[0];
d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
(plefttop[3] >> 16) * r_affinetridesc.skinwidth;
d_sfrac = 0;
d_tfrac = 0;
d_light = plefttop[4];
d_zi = plefttop[5];
d_pdest = (byte *)d_viewbuffer + ystart * r_screenwidth + plefttop[0];
d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
if (height == 1)
{
d_pedgespanpackage->pdest = d_pdest;
d_pedgespanpackage->pz = d_pz;
d_pedgespanpackage->count = d_aspancount;
d_pedgespanpackage->ptex = d_ptex;
d_pedgespanpackage->sfrac = d_sfrac;
d_pedgespanpackage->tfrac = d_tfrac;
// FIXME: need to clamp l, s, t, at both ends?
d_pedgespanpackage->light = d_light;
d_pedgespanpackage->zi = d_zi;
d_pedgespanpackage++;
}
else
{
R_PolysetSetUpForLineScan(plefttop[0], plefttop[1],
pleftbottom[0], pleftbottom[1]);
d_pdestbasestep = r_screenwidth + ubasestep;
d_pdestextrastep = d_pdestbasestep + 1;
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_pzbasestep = (d_zwidth + ubasestep) << 1;
d_pzextrastep = d_pzbasestep + 2;
}
//#else
else
#endif
{
d_pzbasestep = d_zwidth + ubasestep;
d_pzextrastep = d_pzbasestep + 1;
}
//#endif
if (ubasestep < 0)
working_lstepx = r_lstepx - 1;
else
working_lstepx = r_lstepx;
d_countextrastep = ubasestep + 1;
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
((r_tstepy + r_tstepx * ubasestep) >> 16) *
r_affinetridesc.skinwidth;
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
}
//#else
else
#endif
{
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
}
//#endif
d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
r_affinetridesc.skinwidth;
//#if id386ALIAS
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
d_sfracextrastep = ((r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF)<<16;
d_tfracextrastep = ((r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF)<<16;
}
#endif
//#endif
{
d_sfracextrastep = (r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF;
d_tfracextrastep = (r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF;
}
//#endif
d_lightextrastep = d_lightbasestep + working_lstepx;
d_ziextrastep = d_zibasestep + r_zistepx;
#if id386
if ( d_pdrawspans == R_PolysetDrawSpans8_Opaque )
{
R_PolysetScanLeftEdge (height);
}
else
#endif
{
R_PolysetScanLeftEdge_C(height);
}
}
}
// scan out the top (and possibly only) part of the right edge, updating the
// count field
d_pedgespanpackage = a_spans;
R_PolysetSetUpForLineScan(prighttop[0], prighttop[1],
prightbottom[0], prightbottom[1]);
d_aspancount = 0;
d_countextrastep = ubasestep + 1;
originalcount = a_spans[initialrightheight].count;
a_spans[initialrightheight].count = -999999; // mark end of the spanpackages
(*d_pdrawspans) (a_spans);
// scan out the bottom part of the right edge, if it exists
if (pedgetable->numrightedges == 2)
{
int height;
spanpackage_t *pstart;
pstart = a_spans + initialrightheight;
pstart->count = originalcount;
d_aspancount = prightbottom[0] - prighttop[0];
prighttop = prightbottom;
prightbottom = pedgetable->prightedgevert2;
height = prightbottom[1] - prighttop[1];
R_PolysetSetUpForLineScan(prighttop[0], prighttop[1],
prightbottom[0], prightbottom[1]);
d_countextrastep = ubasestep + 1;
a_spans[initialrightheight + height].count = -999999;
// mark end of the spanpackages
(*d_pdrawspans) (pstart);
}
}
/*
================
R_PolysetSetEdgeTable
================
*/
void R_PolysetSetEdgeTable (void)
{
int edgetableindex;
edgetableindex = 0; // assume the vertices are already in
// top to bottom order
//
// determine which edges are right & left, and the order in which
// to rasterize them
//
if (r_p0[1] >= r_p1[1])
{
if (r_p0[1] == r_p1[1])
{
if (r_p0[1] < r_p2[1])
pedgetable = &edgetables[2];
else
pedgetable = &edgetables[5];
return;
}
else
{
edgetableindex = 1;
}
}
if (r_p0[1] == r_p2[1])
{
if (edgetableindex)
pedgetable = &edgetables[8];
else
pedgetable = &edgetables[9];
return;
}
else if (r_p1[1] == r_p2[1])
{
if (edgetableindex)
pedgetable = &edgetables[10];
else
pedgetable = &edgetables[11];
return;
}
if (r_p0[1] > r_p2[1])
edgetableindex += 2;
if (r_p1[1] > r_p2[1])
edgetableindex += 4;
pedgetable = &edgetables[edgetableindex];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -