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
325
326
327
|
/* $XFree86$ */
/**************************************************************************
Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
Cedar Park, Texas.
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
on the rights to use, copy, modify, merge, publish, distribute, sub
license, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Kevin E. Martin <kevin@precisioninsight.com>
*
*/
#if !defined(TAG) || !defined(IND)
this is an error
#endif
/* Draw a single triangle. Note that the device-dependent vertex data
might need to be changed based on the render state. */
static void TAG(triangle)(GLcontext *ctx,
GLuint e0, GLuint e1, GLuint e2,
GLuint pv)
{
r128ContextPtr r128ctx = R128_CONTEXT(ctx);
struct vertex_buffer *VB = ctx->VB;
r128VertexPtr r128verts = R128_DRIVER_DATA(VB)->verts;
const r128_vertex *v0 = &r128verts[e0].v;
const r128_vertex *v1 = &r128verts[e1].v;
const r128_vertex *v2 = &r128verts[e2].v;
#if (IND & R128_OFFSET_BIT)
GLfloat offset;
#endif
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
int c0 = *(int *)&r128verts[pv].v.dif_argb;
int c1 = c0;
int c2 = c0;
#endif
#if (IND & R128_OFFSET_BIT)
switch (ctx->Visual->DepthBits) {
case 16: offset = ctx->Polygon.OffsetUnits / 65536.0; break;
case 24: offset = ctx->Polygon.OffsetUnits / 16777216.0; break;
case 32: offset = ctx->Polygon.OffsetUnits / 4294967296.0; break;
default: offset = ctx->Polygon.OffsetUnits / 65536.0; break;
}
#endif
#if (IND & (R128_TWOSIDE_BIT | R128_OFFSET_BIT))
{
GLfloat ex = v0->x - v2->x;
GLfloat ey = v0->y - v2->y;
GLfloat fx = v1->x - v2->x;
GLfloat fy = v1->y - v2->y;
GLfloat c = ex*fy - ey*fx;
#if (IND & R128_TWOSIDE_BIT)
{
GLuint facing = (c > 0.0) ^ ctx->Polygon.FrontBit;
GLubyte (*vbcolor)[4] = VB->Color[facing]->data;
if (IND & R128_FLAT_BIT) {
R128_COLOR((char *)&c0, vbcolor[pv]);
c2 = c1 = c0;
} else {
R128_COLOR((char *)&c0, vbcolor[e0]);
R128_COLOR((char *)&c1, vbcolor[e1]);
R128_COLOR((char *)&c2, vbcolor[e2]);
}
}
#endif
#if (IND & R128_OFFSET_BIT)
{
if (c * c > 1e-16) {
GLfloat factor = ctx->Polygon.OffsetFactor;
GLfloat ez = v0->z - v2->z;
GLfloat fz = v1->z - v2->z;
GLfloat a = ey*fz - ez*fy;
GLfloat b = ez*fx - ex*fz;
GLfloat ic = 1.0 / c;
GLfloat ac = a * ic;
GLfloat bc = b * ic;
if (ac < 0.0f) ac = -ac;
if (bc < 0.0f) bc = -bc;
offset += MAX2(ac, bc) * factor;
}
}
#endif
}
#endif
LOCK_HARDWARE(r128ctx);
if (r128ctx->regs.tex_cntl_c & (R128_TEXMAP_ENABLE |
R128_SEC_TEXMAP_ENABLE)) {
BEGIN_CLIP_LOOP(r128ctx);
#if USE_RHW2
R128CCE3(R128_CCE_PACKET3_3D_RNDR_GEN_PRIM, 34);
#else
R128CCE3(R128_CCE_PACKET3_3D_RNDR_GEN_PRIM, 31);
#endif
R128CCE(R128_FULL_VERTEX_FORMAT);
R128CCE(R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST |
R128_CCE_VC_CNTL_PRIM_WALK_RING |
(3 << R128_CCE_VC_CNTL_NUM_SHIFT));
R128CCEF(v0->x);
R128CCEF(v0->y);
#if (IND & R128_OFFSET_BIT)
R128CCEF(v0->z + offset);
#else
R128CCEF(v0->z);
#endif
R128CCEF(v0->rhw);
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
R128CCE(c0);
#else
R128CCE(*(int *)&v0->dif_argb);
#endif
R128CCE(*(int *)&v0->spec_frgb);
R128CCEF(v0->tu0);
R128CCEF(v0->tv0);
R128CCEF(v0->tu1);
R128CCEF(v0->tv1);
#if USE_RHW2
R128CCEF(v0->rhw2);
#endif
R128CCEF(v1->x);
R128CCEF(v1->y);
#if (IND & R128_OFFSET_BIT)
R128CCEF(v1->z + offset);
#else
R128CCEF(v1->z);
#endif
R128CCEF(v1->rhw);
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
R128CCE(c1);
#else
R128CCE(*(int *)&v1->dif_argb);
#endif
R128CCE(*(int *)&v1->spec_frgb);
R128CCEF(v1->tu0);
R128CCEF(v1->tv0);
R128CCEF(v1->tu1);
R128CCEF(v1->tv1);
#if USE_RHW2
R128CCEF(v1->rhw2);
#endif
R128CCEF(v2->x);
R128CCEF(v2->y);
#if (IND & R128_OFFSET_BIT)
R128CCEF(v2->z + offset);
#else
R128CCEF(v2->z);
#endif
R128CCEF(v2->rhw);
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
R128CCE(c2);
#else
R128CCE(*(int *)&v2->dif_argb);
#endif
R128CCE(*(int *)&v2->spec_frgb);
R128CCEF(v2->tu0);
R128CCEF(v2->tv0);
R128CCEF(v2->tu1);
R128CCEF(v2->tv1);
#if USE_RHW2
R128CCEF(v2->rhw2);
#endif
R128CCE_SUBMIT_PACKETS();
END_CLIP_LOOP(r128ctx);
} else {
BEGIN_CLIP_LOOP(r128ctx);
R128CCE3(R128_CCE_PACKET3_3D_RNDR_GEN_PRIM, 13);
R128CCE(R128_CCE_VC_FRMT_DIFFUSE_ARGB);
R128CCE(R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST |
R128_CCE_VC_CNTL_PRIM_WALK_RING |
(3 << R128_CCE_VC_CNTL_NUM_SHIFT));
R128CCEF(v0->x);
R128CCEF(v0->y);
#if (IND & R128_OFFSET_BIT)
R128CCEF(v0->z + offset);
#else
R128CCEF(v0->z);
#endif
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
R128CCE(c0);
#else
R128CCE(*(int *)&v0->dif_argb);
#endif
R128CCEF(v1->x);
R128CCEF(v1->y);
#if (IND & R128_OFFSET_BIT)
R128CCEF(v1->z + offset);
#else
R128CCEF(v1->z);
#endif
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
R128CCE(c1);
#else
R128CCE(*(int *)&v1->dif_argb);
#endif
R128CCEF(v2->x);
R128CCEF(v2->y);
#if (IND & R128_OFFSET_BIT)
R128CCEF(v2->z + offset);
#else
R128CCEF(v2->z);
#endif
#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
R128CCE(c2);
#else
R128CCE(*(int *)&v2->dif_argb);
#endif
R128CCE_SUBMIT_PACKETS();
END_CLIP_LOOP(r128ctx);
}
UNLOCK_HARDWARE(r128ctx);
}
static void TAG(quad)(GLcontext *ctx,
GLuint v0, GLuint v1, GLuint v2, GLuint v3,
GLuint pv)
{
TAG(triangle)(ctx, v0, v1, v3, pv);
TAG(triangle)(ctx, v1, v2, v3, pv);
}
#if ((IND & ~R128_FLAT_BIT) == 0)
/* Draw a single line. Note that the device-dependent vertex data might
need to be changed based on the render state. */
static void TAG(line)(GLcontext *ctx,
GLuint v0, GLuint v1,
GLuint pv)
{
r128ContextPtr r128ctx = R128_CONTEXT(ctx);
r128VertexPtr r128verts = R128_DRIVER_DATA(ctx->VB)->verts;
r128_vertex tmp0 = r128verts[v0].v;
r128_vertex tmp1 = r128verts[v1].v;
float width = ctx->Line.Width;
if (IND & R128_FLAT_BIT) {
*(int *)&tmp1.dif_argb =
*(int *)&tmp0.dif_argb =
*(int *)&r128verts[pv].v.dif_argb;
}
r128DrawLine(r128ctx, &tmp0, &tmp1, width);
}
/* Draw a set of points. Note that the device-dependent vertex data
might need to be changed based on the render state. */
static void TAG(points)(GLcontext *ctx,
GLuint first, GLuint last)
{
r128ContextPtr r128ctx = R128_CONTEXT(ctx);
struct vertex_buffer *VB = ctx->VB;
r128VertexPtr r128verts = R128_DRIVER_DATA(VB)->verts;
GLfloat size = ctx->Point.Size * 0.5;
int i;
for(i = first; i <= last; i++) {
if(VB->ClipMask[i] == 0) {
r128_vertex *tmp = &r128verts[i].v;
r128DrawPoint(r128ctx, tmp, size);
}
}
}
#endif
/* Initialize the table of primitives to render. */
static void TAG(init)(void)
{
tri_tab[IND] = TAG(triangle);
quad_tab[IND] = TAG(quad);
#if ((IND & ~R128_FLAT_BIT) == 0)
line_tab[IND] = TAG(line);
points_tab[IND] = TAG(points);
#endif
}
#undef IND
#undef TAG
|