Beispiel #1
0
/*
================
R_AliasPrepareUnclippedPoints
================
*/
void R_AliasPrepareUnclippedPoints (void)
{
	stvert_t	*pstverts;
	finalvert_t	*fv;
	mtriangle_t	*ptri;
	int	i;

	pstverts = (stvert_t *)((byte *)paliashdr + paliashdr->stverts);
	r_anumverts = pmdl->numverts;
// FIXME: just use pfinalverts directly?
	fv = pfinalverts;

	R_AliasTransformAndProjectFinalVerts (fv, pstverts);

	r_affinetridesc.pfinalverts = pfinalverts;
	r_affinetridesc.ptriangles = (mtriangle_t *)
					((byte *)paliashdr + paliashdr->triangles);
	r_affinetridesc.numtriangles = 1;//pmdl->numtris;

	ptri = (mtriangle_t *)((byte *)paliashdr + paliashdr->triangles);
	for (i = 0 ; i < pmdl->numtris ; i++, ptri++)
	{
		finalvert_t	*pfv[3];

		pfv[0] = &pfinalverts[ptri->vertindex[0]];
		pfv[1] = &pfinalverts[ptri->vertindex[1]];
		pfv[2] = &pfinalverts[ptri->vertindex[2]];

		//jfm: fill in the triangles s and t into the finalvert
		pfv[0]->v[2] = pstverts[ptri->stindex[0]].s;
		pfv[0]->v[3] = pstverts[ptri->stindex[0]].t;
		pfv[0]->flags = pstverts[ptri->stindex[0]].onseam;

		pfv[1]->v[2] = pstverts[ptri->stindex[1]].s;
		pfv[1]->v[3] = pstverts[ptri->stindex[1]].t;
		pfv[1]->flags = pstverts[ptri->stindex[1]].onseam;

		pfv[2]->v[2] = pstverts[ptri->stindex[2]].s;
		pfv[2]->v[3] = pstverts[ptri->stindex[2]].t;
		pfv[2]->flags = pstverts[ptri->stindex[2]].onseam;

		r_affinetridesc.ptriangles = ptri;

		if (r_affinetridesc.drawtype)
		{
			if ((currententity->model->flags & EF_SPECIAL_TRANS))
			{
				D_PolysetDrawFinalVertsT5 (pfv[0],pfv[1],pfv[2]);
				D_PolysetDrawT5 ();
			}
			else if (currententity->drawflags & DRF_TRANSLUCENT)
			{
				D_PolysetDrawFinalVertsT (pfv[0],pfv[1],pfv[2]);
				D_PolysetDrawT ();
			}
			else if ((currententity->model->flags & EF_TRANSPARENT))
			{
				D_PolysetDrawFinalVertsT2 (pfv[0],pfv[1],pfv[2]);
				D_PolysetDrawT2 ();
			}
			else if ((currententity->model->flags & EF_HOLEY))
			{
				D_PolysetDrawFinalVertsT3 (pfv[0],pfv[1],pfv[2]);
				D_PolysetDrawT3 ();
			}
			else
			{
				D_PolysetDrawFinalVerts (pfv[0],pfv[1],pfv[2]);
				D_PolysetDraw ();
			}
		}
		else
		{
			if ((currententity->model->flags & EF_SPECIAL_TRANS))
				D_PolysetDrawT5 ();
			else if (currententity->drawflags & DRF_TRANSLUCENT)
				D_PolysetDrawT ();
			else if ((currententity->model->flags & EF_TRANSPARENT))
				D_PolysetDrawT2 ();
			else if ((currententity->model->flags & EF_HOLEY))
				D_PolysetDrawT3 ();
			else
				D_PolysetDraw ();
		}
	}
}
/*
================
R_AliasClipTriangle
================
*/
void R_AliasClipTriangle (mtriangle_t *ptri)
{
	int			i, k, pingpong;
	mtriangle_t		mtri;
	unsigned int		clipflags;

// copy vertexes and fix seam texture coordinates
	if (ptri->facesfront)
	{
		fv[0][0] = pfinalverts[ptri->vertindex[0]];
		fv[0][1] = pfinalverts[ptri->vertindex[1]];
		fv[0][2] = pfinalverts[ptri->vertindex[2]];
	}
	else
	{
		for (i = 0; i < 3; i++)
		{
			fv[0][i] = pfinalverts[ptri->vertindex[i]];

			if (fv[0][i].flags & ALIAS_ONSEAM)
				fv[0][i].v[2] += r_affinetridesc.seamfixupX16;
		}
	}

// clip
	clipflags = fv[0][0].flags | fv[0][1].flags | fv[0][2].flags;

	if (clipflags & ALIAS_Z_CLIP)
	{
		for (i = 0; i < 3; i++)
			av[i] = pauxverts[ptri->vertindex[i]];

		k = R_AliasClip (fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z);
		if (k == 0)
			return;

		pingpong = 1;
		clipflags = fv[1][0].flags | fv[1][1].flags | fv[1][2].flags;
	}
	else
	{
		pingpong = 0;
		k = 3;
	}

	if (clipflags & ALIAS_LEFT_CLIP)
	{
		k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
							ALIAS_LEFT_CLIP, k, R_Alias_clip_left);
		if (k == 0)
			return;

		pingpong ^= 1;
	}

	if (clipflags & ALIAS_RIGHT_CLIP)
	{
		k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
							ALIAS_RIGHT_CLIP, k, R_Alias_clip_right);
		if (k == 0)
			return;

		pingpong ^= 1;
	}

	if (clipflags & ALIAS_BOTTOM_CLIP)
	{
		k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
							ALIAS_BOTTOM_CLIP, k, R_Alias_clip_bottom);
		if (k == 0)
			return;

		pingpong ^= 1;
	}

	if (clipflags & ALIAS_TOP_CLIP)
	{
		k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
							ALIAS_TOP_CLIP, k, R_Alias_clip_top);
		if (k == 0)
			return;

		pingpong ^= 1;
	}

	for (i = 0; i < k; i++)
	{
		if (fv[pingpong][i].v[0] < r_refdef.aliasvrect.x)
			fv[pingpong][i].v[0] = r_refdef.aliasvrect.x;
		else if (fv[pingpong][i].v[0] > r_refdef.aliasvrectright)
			fv[pingpong][i].v[0] = r_refdef.aliasvrectright;

		if (fv[pingpong][i].v[1] < r_refdef.aliasvrect.y)
			fv[pingpong][i].v[1] = r_refdef.aliasvrect.y;
		else if (fv[pingpong][i].v[1] > r_refdef.aliasvrectbottom)
			fv[pingpong][i].v[1] = r_refdef.aliasvrectbottom;

		fv[pingpong][i].flags = 0;
	}

// draw triangles
	mtri.facesfront = ptri->facesfront;
	r_affinetridesc.ptriangles = &mtri;
	r_affinetridesc.pfinalverts = fv[pingpong];

// FIXME: do all at once as trifan?
	mtri.vertindex[0] = 0;
	for (i = 1; i < k - 1; i++)
	{
		mtri.vertindex[1] = i;
		mtri.vertindex[2] = i+1;
		if ((currententity->model->flags & EF_SPECIAL_TRANS))
			D_PolysetDrawT5 ();
		else if (currententity->drawflags & DRF_TRANSLUCENT)
			D_PolysetDrawT ();
		else if ((currententity->model->flags & EF_TRANSPARENT))
			D_PolysetDrawT2 ();
		else if ((currententity->model->flags & EF_HOLEY))
			D_PolysetDrawT3 ();
		else
			D_PolysetDraw ();
	}
}
Beispiel #3
0
/*
================
R_AliasPreparePoints

General clipped case
================
*/
static void R_AliasPreparePoints (void)
{
	int			i;
	stvert_t	*pstverts;
	finalvert_t	*fv;
	auxvert_t	*av;
	mtriangle_t	*ptri;
	finalvert_t	*pfv[3];

	pstverts = (stvert_t *)((byte *)paliashdr + paliashdr->stverts);
	r_anumverts = pmdl->numverts;
	fv = pfinalverts;
	av = pauxverts;

	for (i = 0 ; i < r_anumverts ; i++, fv++, av++, r_apverts++)
	{
		fv->flags = 0;
		R_AliasTransformFinalVert (fv, av, r_apverts);
		if (av->fv[2] < ALIAS_Z_CLIP_PLANE)
			fv->flags |= ALIAS_Z_CLIP;
		else
		{
			R_AliasProjectFinalVert (fv, av);

			if (fv->v[0] < r_refdef.aliasvrect.x)
				fv->flags |= ALIAS_LEFT_CLIP;
			if (fv->v[1] < r_refdef.aliasvrect.y)
				fv->flags |= ALIAS_TOP_CLIP;
			if (fv->v[0] > r_refdef.aliasvrectright)
				fv->flags |= ALIAS_RIGHT_CLIP;
			if (fv->v[1] > r_refdef.aliasvrectbottom)
				fv->flags |= ALIAS_BOTTOM_CLIP;
		}
	}

//
// clip and draw all triangles
//
	r_affinetridesc.numtriangles = 1;

	ptri = (mtriangle_t *)((byte *)paliashdr + paliashdr->triangles);
	for (i = 0 ; i < pmdl->numtris ; i++, ptri++)
	{
		pfv[0] = &pfinalverts[ptri->vertindex[0]];
		pfv[1] = &pfinalverts[ptri->vertindex[1]];
		pfv[2] = &pfinalverts[ptri->vertindex[2]];

		if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags & (ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP) )
			continue;		// completely clipped

		//jfm: fill in the triangles s and t into the finalvert
		pfv[0]->v[2] = pstverts[ptri->stindex[0]].s;
		pfv[0]->v[3] = pstverts[ptri->stindex[0]].t;
		pfv[0]->flags |= pstverts[ptri->stindex[0]].onseam;

		pfv[1]->v[2] = pstverts[ptri->stindex[1]].s;
		pfv[1]->v[3] = pstverts[ptri->stindex[1]].t;
		pfv[1]->flags |= pstverts[ptri->stindex[1]].onseam;

		pfv[2]->v[2] = pstverts[ptri->stindex[2]].s;
		pfv[2]->v[3] = pstverts[ptri->stindex[2]].t;
		pfv[2]->flags |= pstverts[ptri->stindex[2]].onseam;

		if ( ! ( (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) & (ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP) ) )
		{	// totally unclipped
			r_affinetridesc.pfinalverts = pfinalverts;
			r_affinetridesc.ptriangles = ptri;

			if ((currententity->model->flags & EF_SPECIAL_TRANS))
				D_PolysetDrawT5 ();
			else if (currententity->drawflags & DRF_TRANSLUCENT)
				D_PolysetDrawT ();
			else if ((currententity->model->flags & EF_TRANSPARENT))
				D_PolysetDrawT2 ();
			else if ((currententity->model->flags & EF_HOLEY))
				D_PolysetDrawT3 ();
			else
				D_PolysetDraw ();
		}
		else
		{	// partially clipped
			R_AliasClipTriangle (ptri);
		}
	}
}