Quake II RTX doxygen  1.0 dev
aclip.c File Reference
#include "sw.h"

Go to the source code of this file.

Functions

static void R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
 
static void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
 
static void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
 
static void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
 
static void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
 
static int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count, void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out))
 
void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2)
 

Function Documentation

◆ R_Alias_clip_bottom()

static void R_Alias_clip_bottom ( finalvert_t pfv0,
finalvert_t pfv1,
finalvert_t out 
)
static

Definition at line 115 of file aclip.c.

117 {
118  float scale;
119 
120  if (pfv0->v >= pfv1->v) {
121  scale = (float)(r_refdef.vrectbottom - pfv0->v) / (pfv1->v - pfv0->v);
122 
123  out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
124  out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
125  out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
126  out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
127  out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
128  out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
129  } else {
130  scale = (float)(r_refdef.vrectbottom - pfv1->v) / (pfv0->v - pfv1->v);
131 
132  out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
133  out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
134  out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
135  out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
136  out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
137  out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
138  }
139 }

Referenced by R_AliasClipTriangle().

◆ R_Alias_clip_left()

static void R_Alias_clip_left ( finalvert_t pfv0,
finalvert_t pfv1,
finalvert_t out 
)
static

Definition at line 46 of file aclip.c.

47 {
48  float scale;
49 
50  if (pfv0->v >= pfv1->v) {
51  scale = (float)(r_refdef.vrect.x - pfv0->u) / (pfv1->u - pfv0->u);
52  out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
53  out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
54  out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
55  out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
56  out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
57  out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
58  } else {
59  scale = (float)(r_refdef.vrect.x - pfv1->u) / (pfv0->u - pfv1->u);
60  out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
61  out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
62  out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
63  out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
64  out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
65  out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
66  }
67 }

Referenced by R_AliasClipTriangle().

◆ R_Alias_clip_right()

static void R_Alias_clip_right ( finalvert_t pfv0,
finalvert_t pfv1,
finalvert_t out 
)
static

Definition at line 69 of file aclip.c.

70 {
71  float scale;
72 
73  if (pfv0->v >= pfv1->v) {
74  scale = (float)(r_refdef.vrectright - pfv0->u) / (pfv1->u - pfv0->u);
75  out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
76  out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
77  out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
78  out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
79  out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
80  out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
81  } else {
82  scale = (float)(r_refdef.vrectright - pfv1->u) / (pfv0->u - pfv1->u);
83  out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
84  out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
85  out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
86  out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
87  out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
88  out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
89  }
90 }

Referenced by R_AliasClipTriangle().

◆ R_Alias_clip_top()

static void R_Alias_clip_top ( finalvert_t pfv0,
finalvert_t pfv1,
finalvert_t out 
)
static

Definition at line 92 of file aclip.c.

93 {
94  float scale;
95 
96  if (pfv0->v >= pfv1->v) {
97  scale = (float)(r_refdef.vrect.y - pfv0->v) / (pfv1->v - pfv0->v);
98  out->u = pfv0->u + (pfv1->u - pfv0->u) * scale + 0.5;
99  out->v = pfv0->v + (pfv1->v - pfv0->v) * scale + 0.5;
100  out->s = pfv0->s + (pfv1->s - pfv0->s) * scale + 0.5;
101  out->t = pfv0->t + (pfv1->t - pfv0->t) * scale + 0.5;
102  out->l = pfv0->l + (pfv1->l - pfv0->l) * scale + 0.5;
103  out->zi = pfv0->zi + (pfv1->zi - pfv0->zi) * scale + 0.5;
104  } else {
105  scale = (float)(r_refdef.vrect.y - pfv1->v) / (pfv0->v - pfv1->v);
106  out->u = pfv1->u + (pfv0->u - pfv1->u) * scale + 0.5;
107  out->v = pfv1->v + (pfv0->v - pfv1->v) * scale + 0.5;
108  out->s = pfv1->s + (pfv0->s - pfv1->s) * scale + 0.5;
109  out->t = pfv1->t + (pfv0->t - pfv1->t) * scale + 0.5;
110  out->l = pfv1->l + (pfv0->l - pfv1->l) * scale + 0.5;
111  out->zi = pfv1->zi + (pfv0->zi - pfv1->zi) * scale + 0.5;
112  }
113 }

Referenced by R_AliasClipTriangle().

◆ R_Alias_clip_z()

static void R_Alias_clip_z ( finalvert_t pfv0,
finalvert_t pfv1,
finalvert_t out 
)
static

Definition at line 29 of file aclip.c.

30 {
31  float scale;
32 
33  scale = (ALIAS_Z_CLIP_PLANE - pfv0->xyz[2]) / (pfv1->xyz[2] - pfv0->xyz[2]);
34 
35  out->xyz[0] = pfv0->xyz[0] + (pfv1->xyz[0] - pfv0->xyz[0]) * scale;
36  out->xyz[1] = pfv0->xyz[1] + (pfv1->xyz[1] - pfv0->xyz[1]) * scale;
37  out->xyz[2] = ALIAS_Z_CLIP_PLANE;
38 
39  out->s = pfv0->s + (pfv1->s - pfv0->s) * scale;
40  out->t = pfv0->t + (pfv1->t - pfv0->t) * scale;
41  out->l = pfv0->l + (pfv1->l - pfv0->l) * scale;
42 
44 }

Referenced by R_AliasClipTriangle().

◆ R_AliasClip()

static int R_AliasClip ( finalvert_t in,
finalvert_t out,
int  flag,
int  count,
void(*)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)  clip 
)
static

Definition at line 141 of file aclip.c.

143 {
144  int i, j, k;
145  int flags, oldflags;
146 
147  j = count - 1;
148  k = 0;
149  for (i = 0; i < count; j = i, i++) {
150  oldflags = in[j].flags & flag;
151  flags = in[i].flags & flag;
152 
153  if (flags && oldflags)
154  continue;
155  if (oldflags ^ flags) {
156  clip(&in[j], &in[i], &out[k]);
157  out[k].flags = 0;
158  if (out[k].u < r_refdef.vrect.x)
159  out[k].flags |= ALIAS_LEFT_CLIP;
160  if (out[k].v < r_refdef.vrect.y)
161  out[k].flags |= ALIAS_TOP_CLIP;
162  if (out[k].u > r_refdef.vrectright)
163  out[k].flags |= ALIAS_RIGHT_CLIP;
164  if (out[k].v > r_refdef.vrectbottom)
165  out[k].flags |= ALIAS_BOTTOM_CLIP;
166  k++;
167  }
168  if (!flags) {
169  out[k] = in[i];
170  k++;
171  }
172  }
173 
174  return k;
175 }

Referenced by R_AliasClipTriangle().

◆ R_AliasClipTriangle()

void R_AliasClipTriangle ( finalvert_t index0,
finalvert_t index1,
finalvert_t index2 
)

Definition at line 183 of file aclip.c.

184 {
185  finalvert_t fv[2][8];
186  int i, k, pingpong;
187  unsigned clipflags;
188 
189 // copy vertexes and fix seam texture coordinates
190  fv[0][0] = *index0;
191  fv[0][1] = *index1;
192  fv[0][2] = *index2;
193 
194 // clip
195  clipflags = fv[0][0].flags | fv[0][1].flags | fv[0][2].flags;
196 
197  if (clipflags & ALIAS_Z_CLIP) {
198  k = R_AliasClip(fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z);
199  if (k == 0)
200  return;
201 
202  pingpong = 1;
203  clipflags = fv[1][0].flags | fv[1][1].flags | fv[1][2].flags;
204  } else {
205  pingpong = 0;
206  k = 3;
207  }
208 
209  if (clipflags & ALIAS_LEFT_CLIP) {
210  k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
212  if (k == 0)
213  return;
214 
215  pingpong ^= 1;
216  }
217 
218  if (clipflags & ALIAS_RIGHT_CLIP) {
219  k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
221  if (k == 0)
222  return;
223 
224  pingpong ^= 1;
225  }
226 
227  if (clipflags & ALIAS_BOTTOM_CLIP) {
228  k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
230  if (k == 0)
231  return;
232 
233  pingpong ^= 1;
234  }
235 
236  if (clipflags & ALIAS_TOP_CLIP) {
237  k = R_AliasClip(fv[pingpong], fv[pingpong ^ 1],
239  if (k == 0)
240  return;
241 
242  pingpong ^= 1;
243  }
244 
245  for (i = 0; i < k; i++) {
246  if (fv[pingpong][i].u < r_refdef.vrect.x)
247  fv[pingpong][i].u = r_refdef.vrect.x;
248  else if (fv[pingpong][i].u > r_refdef.vrectright)
249  fv[pingpong][i].u = r_refdef.vrectright;
250 
251  if (fv[pingpong][i].v < r_refdef.vrect.y)
252  fv[pingpong][i].v = r_refdef.vrect.y;
253  else if (fv[pingpong][i].v > r_refdef.vrectbottom)
254  fv[pingpong][i].v = r_refdef.vrectbottom;
255 
256  fv[pingpong][i].flags = 0;
257  }
258 
259 // draw triangles
260  for (i = 1; i < k - 1; i++) {
261  aliastriangleparms.a = &fv[pingpong][0];
262  aliastriangleparms.b = &fv[pingpong][i];
263  aliastriangleparms.c = &fv[pingpong][i + 1];
264  R_DrawTriangle();
265  }
266 }

Referenced by R_AliasPreparePoints().

ALIAS_Z_CLIP_PLANE
#define ALIAS_Z_CLIP_PLANE
Definition: sw.h:105
finalvert_s::u
int u
Definition: sw.h:163
aliastriangleparms_t::b
finalvert_t * b
Definition: sw.h:294
fv
static float fv
Definition: edge.c:59
R_Alias_clip_top
static void R_Alias_clip_top(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
Definition: aclip.c:92
r_refdef
oldrefdef_t r_refdef
Definition: main.c:57
finalvert_s::t
int t
Definition: sw.h:163
R_Alias_clip_right
static void R_Alias_clip_right(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
Definition: aclip.c:69
ALIAS_BOTTOM_CLIP
#define ALIAS_BOTTOM_CLIP
Definition: sw.h:90
finalvert_s
Definition: sw.h:162
finalvert_s::v
int v
Definition: sw.h:163
ALIAS_RIGHT_CLIP
#define ALIAS_RIGHT_CLIP
Definition: sw.h:89
R_AliasClip
static int R_AliasClip(finalvert_t *in, finalvert_t *out, int flag, int count, void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out))
Definition: aclip.c:141
ALIAS_LEFT_CLIP
#define ALIAS_LEFT_CLIP
Definition: sw.h:87
finalvert_s::xyz
float xyz[3]
Definition: sw.h:167
ALIAS_Z_CLIP
#define ALIAS_Z_CLIP
Definition: sw.h:91
finalvert_s::zi
int zi
Definition: sw.h:165
ALIAS_TOP_CLIP
#define ALIAS_TOP_CLIP
Definition: sw.h:88
aliastriangleparms_t::a
finalvert_t * a
Definition: sw.h:294
oldrefdef_t::vrect
vrect_t vrect
Definition: sw.h:132
finalvert_s::s
int s
Definition: sw.h:163
finalvert_s::flags
int flags
Definition: sw.h:166
aliastriangleparms_t::c
finalvert_t * c
Definition: sw.h:294
oldrefdef_t::vrectright
int vrectright
Definition: sw.h:133
R_DrawTriangle
void R_DrawTriangle(void)
Definition: polyset.c:113
R_Alias_clip_bottom
static void R_Alias_clip_bottom(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
Definition: aclip.c:115
R_Alias_clip_z
static void R_Alias_clip_z(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
Definition: aclip.c:29
R_AliasProjectAndClipTestFinalVert
void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv)
Definition: alias.c:188
aliastriangleparms
aliastriangleparms_t aliastriangleparms
Definition: polyset.c:47
finalvert_s::l
int l
Definition: sw.h:164
oldrefdef_t::vrectbottom
int vrectbottom
Definition: sw.h:133
R_Alias_clip_left
static void R_Alias_clip_left(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
Definition: aclip.c:46