summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/ffb/ffb_tritmp.h
blob: ba73122389800584abd8cc8079e30833fa104cb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_tritmp.h,v 1.1 2000/06/20 05:08:40 dawes Exp $ */

static void TAG(ffb_triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2, GLuint pv)
{
	ffbContextPtr fmesa = FFB_CONTEXT(ctx);
	ffb_fbcPtr ffb = fmesa->regs;
	struct vertex_buffer *VB = ctx->VB;
	ffb_vertex *ffbVB = FFB_DRIVER_DATA(VB)->verts;
	const ffb_vertex *v0 = &ffbVB[e0];
	const ffb_vertex *v1 = &ffbVB[e1];
	const ffb_vertex *v2 = &ffbVB[e2];
#if (IND & FFB_TRI_OFFSET_BIT)
	GLuint ffb_zoffset = FFB_Z_FROM_FLOAT(ctx->PolygonZoffset);
#endif
#if (IND & FFB_TRI_FLAT_BIT)
	GLuint const_fg;
#endif
#if (IND & FFB_TRI_TWOSIDE_BIT)
	int which_color = (VB->ColorPtr == VB->Color[0]) ? 0 : 1;
#else
	const int which_color = 0;
#endif

#if (IND & FFB_TRI_CULL_BIT)
	{
		GLfloat (*win)[4] = VB->Win.data;
		GLfloat ex = win[e1][0] - win[e0][0];
		GLfloat ey = win[e1][1] - win[e0][1];
		GLfloat fx = win[e2][0] - win[e0][0];
		GLfloat fy = win[e2][1] - win[e0][1];
		GLfloat c = ex*fy-ey*fx;

		/* Culled... */
		if (c * ctx->backface_sign > 0)
			return;
	}
#endif

#if (IND & FFB_TRI_FLAT_BIT)
	const_fg = (((GLuint)VB->Color[which_color]->data[pv][0] << 0) |
		    ((GLuint)VB->Color[which_color]->data[pv][1] << 8) |
		    ((GLuint)VB->Color[which_color]->data[pv][2] << 16) |
		    ((GLuint)VB->Color[which_color]->data[pv][3] << 24));
#endif

	FFB_DUMP_PRIM(TRIANGLE);

#if (IND & FFB_TRI_FLAT_BIT)
	FFBFifo(fmesa, 1);
	ffb->fg = const_fg;
#endif

	/* First, check for a triangle strip/fan sequences.
	 * These checks rely on how MESA sends these primitives
	 * down to us in render_tmp.h
	 */
	if (v0 == fmesa->vtx_cache[1] &&
	    v1 == fmesa->vtx_cache[2] &&
	    v2 != fmesa->vtx_cache[0]) {
#if (IND & FFB_TRI_FLAT_BIT)
		FFBFifo(fmesa, 3);
#else
#if (IND & FFB_TRI_ALPHA_BIT)
		FFBFifo(fmesa, 7);
#else
		FFBFifo(fmesa, 6);
#endif
#endif
		FFB_DUMP_VERTEX(v2);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
		ffb->alpha = v2->color[which_color].alpha;
#endif
		ffb->red = v2->color[which_color].red;
		ffb->green = v2->color[which_color].green;
		ffb->blue = v2->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
		ffb->z = v2->z + ffb_zoffset;
#else
		ffb->z = v2->z;
#endif
		ffb->y = v2->y;
		ffb->x = v2->x;

		goto update_vcache;
	} else if (v0 == fmesa->vtx_cache[0] &&
		   v1 == fmesa->vtx_cache[2] &&
		   v2 != fmesa->vtx_cache[1]) {
#if (IND & FFB_TRI_FLAT_BIT)
		FFBFifo(fmesa, 3);
#else
#if (IND & FFB_TRI_ALPHA_BIT)
		FFBFifo(fmesa, 7);
#else
		FFBFifo(fmesa, 6);
#endif
#endif
		FFB_DUMP_VERTEX(v2);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
		ffb->alpha = v2->color[which_color].alpha;
#endif
		ffb->red = v2->color[which_color].red;
		ffb->green = v2->color[which_color].green;
		ffb->blue = v2->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
		ffb->z = v2->z + ffb_zoffset;
#else
		ffb->z = v2->z;
#endif
		ffb->dmyf = v2->y;
		ffb->dmxf = v2->x;

		goto update_vcache;
	}

#if (IND & FFB_TRI_FLAT_BIT)
	FFBFifo(fmesa, 9);
#else
#if (IND & FFB_TRI_ALPHA_BIT)
	FFBFifo(fmesa, 21);
#else
	FFBFifo(fmesa, 18);
#endif
#endif

	FFB_DUMP_VERTEX(v0);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v0->color[which_color].alpha;
#endif
	ffb->red = v0->color[which_color].red;
	ffb->green = v0->color[which_color].green;
	ffb->blue = v0->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v0->z + ffb_zoffset;
#else
	ffb->z = v0->z;
#endif
	ffb->ryf = v0->y;
	ffb->rxf = v0->x;

	FFB_DUMP_VERTEX(v1);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v1->color[which_color].alpha;
#endif
	ffb->red = v1->color[which_color].red;
	ffb->green = v1->color[which_color].green;
	ffb->blue = v1->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v1->z + ffb_zoffset;
#else
	ffb->z = v1->z;
#endif
	ffb->y = v1->y;
	ffb->x = v1->x;

	FFB_DUMP_VERTEX(v2);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v2->color[which_color].alpha;
#endif
	ffb->red = v2->color[which_color].red;
	ffb->green = v2->color[which_color].green;
	ffb->blue = v2->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v2->z + ffb_zoffset;
#else
	ffb->z = v2->z;
#endif
	ffb->y = v2->y;
	ffb->x = v2->x;

update_vcache:
	fmesa->vtx_cache[0] = (void *)v0;
	fmesa->vtx_cache[1] = (void *)v1;
	fmesa->vtx_cache[2] = (void *)v2;

	fmesa->ffbScreen->rp_active = 1;
}


static void TAG(ffb_quad)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2, GLuint e3, GLuint pv)
{
	ffbContextPtr fmesa = FFB_CONTEXT(ctx);
	ffb_fbcPtr ffb = fmesa->regs;
	struct vertex_buffer *VB = ctx->VB;
	ffb_vertex *ffbVB = FFB_DRIVER_DATA(VB)->verts;
	const ffb_vertex *v0 = &ffbVB[e0];
	const ffb_vertex *v1 = &ffbVB[e1];
	const ffb_vertex *v2 = &ffbVB[e2];
	const ffb_vertex *v3 = &ffbVB[e3];
#if (IND & FFB_TRI_OFFSET_BIT)
	GLuint ffb_zoffset = FFB_Z_FROM_FLOAT(ctx->PolygonZoffset);
#endif
#if (IND & FFB_TRI_FLAT_BIT)
	GLuint const_fg;
#endif
#if (IND & FFB_TRI_TWOSIDE_BIT)
	int which_color = (VB->ColorPtr == VB->Color[0]) ? 0 : 1;
#else
	const int which_color = 0;
#endif

#if (IND & FFB_TRI_CULL_BIT)
	{
		GLfloat (*win)[4] = VB->Win.data;
		GLfloat ex = win[e2][0] - win[e0][0];
		GLfloat ey = win[e2][1] - win[e0][1];
		GLfloat fx = win[e3][0] - win[e1][0];
		GLfloat fy = win[e3][1] - win[e1][1];
		GLfloat c = ex*fy-ey*fx;

		/* Culled... */
		if (c * ctx->backface_sign > 0)
			return;
	}
#endif

#if (IND & FFB_TRI_FLAT_BIT)
	const_fg = (((GLuint)VB->Color[which_color]->data[pv][0] << 0) |
		    ((GLuint)VB->Color[which_color]->data[pv][1] << 8) |
		    ((GLuint)VB->Color[which_color]->data[pv][2] << 16) |
		    ((GLuint)VB->Color[which_color]->data[pv][3] << 24));
#endif

	FFB_DUMP_PRIM(QUAD);

#if (IND & FFB_TRI_FLAT_BIT)
	FFBFifo(fmesa, 13);
	ffb->fg = const_fg;
#else
#if (IND & FFB_TRI_ALPHA_BIT)
	FFBFifo(fmesa, 28);
#else
	FFBFifo(fmesa, 24);
#endif
#endif

	FFB_DUMP_VERTEX(v0);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v0->color[which_color].alpha;
#endif
	ffb->red = v0->color[which_color].red;
	ffb->green = v0->color[which_color].green;
	ffb->blue = v0->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v0->z + ffb_zoffset;
#else
	ffb->z = v0->z;
#endif
	ffb->ryf = v0->y;
	ffb->rxf = v0->x;

	FFB_DUMP_VERTEX(v1);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v1->color[which_color].alpha;
#endif
	ffb->red = v1->color[which_color].red;
	ffb->green = v1->color[which_color].green;
	ffb->blue = v1->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v1->z + ffb_zoffset;
#else
	ffb->z = v1->z;
#endif
	ffb->y = v1->y;
	ffb->x = v1->x;

	FFB_DUMP_VERTEX(v2);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v2->color[which_color].alpha;
#endif
	ffb->red = v2->color[which_color].red;
	ffb->green = v2->color[which_color].green;
	ffb->blue = v2->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v2->z + ffb_zoffset;
#else
	ffb->z = v2->z;
#endif
	ffb->y = v2->y;
	ffb->x = v2->x;

	FFB_DUMP_VERTEX(v3);
#if !(IND & FFB_TRI_FLAT_BIT)
#if (IND & FFB_TRI_ALPHA_BIT)
	ffb->alpha = v3->color[which_color].alpha;
#endif
	ffb->red = v3->color[which_color].red;
	ffb->green = v3->color[which_color].green;
	ffb->blue = v3->color[which_color].blue;
#endif
#if (IND & FFB_TRI_OFFSET_BIT)
	ffb->z = v3->z + ffb_zoffset;
#else
	ffb->z = v3->z;
#endif
	ffb->dmyf = v3->y;
	ffb->dmxf = v3->x;

	fmesa->ffbScreen->rp_active = 1;
}

static void TAG(init)(void)
{
	ffb_tri_tab[IND]	= TAG(ffb_triangle);
	ffb_quad_tab[IND]	= TAG(ffb_quad);
}

#undef IND
#undef TAG