blob: 8f41c788746588dbde17ad9ac558f4ccc180f562 [file] [log] [blame]
Keith Whitwellfabb9732003-12-21 17:54:31 +00001/*
2 * Copyright 2003 Tungsten Graphics, inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keithw@tungstengraphics.com>
26 */
27
Keith Whitwell79073402004-01-05 09:43:42 +000028#include "glheader.h"
29#include "context.h"
30#include "colormac.h"
31
32#include "t_context.h"
33#include "t_vertex.h"
34
35
36/* Build and manage clipspace/ndc/window vertices.
37 *
38 * Another new mechanism designed and crying out for codegen. Before
39 * that, it would be very interesting to investigate the merger of
40 * these vertices and those built in t_vtx_*.
41 */
Keith Whitwellfabb9732003-12-21 17:54:31 +000042
43
44
Keith Whitwell203dca42004-01-06 20:13:41 +000045
Keith Whitwell79073402004-01-05 09:43:42 +000046#define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace)
Keith Whitwellfabb9732003-12-21 17:54:31 +000047
Keith Whitwell58822572004-01-05 15:24:53 +000048static void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +000049 const GLfloat *in )
50{
51 GLfloat *out = (GLfloat *)v;
52 const GLfloat * const vp = a->vp;
53
54 out[0] = vp[0] * in[0] + vp[12];
55 out[1] = vp[5] * in[1] + vp[13];
56 out[2] = vp[10] * in[2] + vp[14];
57 out[3] = in[3];
58}
59
Keith Whitwell58822572004-01-05 15:24:53 +000060static void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
61 const GLfloat *in )
62{
63 GLfloat *out = (GLfloat *)v;
64 const GLfloat * const vp = a->vp;
65
66 out[0] = vp[0] * in[0] + vp[12];
67 out[1] = vp[5] * in[1] + vp[13];
68 out[2] = vp[10] * in[2] + vp[14];
69 out[3] = 1;
70}
71
72static void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
73 const GLfloat *in )
74{
75 GLfloat *out = (GLfloat *)v;
76 const GLfloat * const vp = a->vp;
77
78 out[0] = vp[0] * in[0] + vp[12];
79 out[1] = vp[5] * in[1] + vp[13];
80 out[2] = vp[14];
81 out[3] = 1;
82}
83
84static void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
85 const GLfloat *in )
86{
87 GLfloat *out = (GLfloat *)v;
88 const GLfloat * const vp = a->vp;
89
90 out[0] = vp[0] * in[0] + vp[12];
91 out[1] = vp[13];
92 out[2] = vp[14];
93 out[3] = 1;
94}
95
96static void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +000097 const GLfloat *in )
98{
99 GLfloat *out = (GLfloat *)v;
100 const GLfloat * const vp = a->vp;
101
102 out[0] = vp[0] * in[0] + vp[12];
103 out[1] = vp[5] * in[1] + vp[13];
104 out[2] = vp[10] * in[2] + vp[14];
105}
106
Keith Whitwell58822572004-01-05 15:24:53 +0000107static void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
108 const GLfloat *in )
109{
110 GLfloat *out = (GLfloat *)v;
111 const GLfloat * const vp = a->vp;
112
113 out[0] = vp[0] * in[0] + vp[12];
114 out[1] = vp[5] * in[1] + vp[13];
115 out[2] = vp[10] * in[2] + vp[14];
116}
117
118static void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
119 const GLfloat *in )
120{
121 GLfloat *out = (GLfloat *)v;
122 const GLfloat * const vp = a->vp;
123
124 out[0] = vp[0] * in[0] + vp[12];
125 out[1] = vp[13];
126 out[2] = vp[14];
127}
128
129static void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000130 const GLfloat *in )
131{
132 GLfloat *out = (GLfloat *)v;
133 const GLfloat * const vp = a->vp;
134
135 out[0] = vp[0] * in[0] + vp[12];
136 out[1] = vp[5] * in[1] + vp[13];
137}
138
Keith Whitwell58822572004-01-05 15:24:53 +0000139static void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
140 const GLfloat *in )
141{
142 GLfloat *out = (GLfloat *)v;
143 const GLfloat * const vp = a->vp;
144
145 out[0] = vp[0] * in[0] + vp[12];
146 out[1] = vp[13];
147}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000148
Keith Whitwell58822572004-01-05 15:24:53 +0000149
150static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000151{
152 GLfloat *out = (GLfloat *)(v);
153
154 out[0] = in[0];
155 out[1] = in[1];
156 out[2] = in[2];
157 out[3] = in[3];
158}
159
Keith Whitwell58822572004-01-05 15:24:53 +0000160static void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000161{
162 GLfloat *out = (GLfloat *)(v);
163
164 out[0] = in[0];
165 out[1] = in[1];
166 out[2] = in[2];
167 out[3] = 1;
168}
169
Keith Whitwell58822572004-01-05 15:24:53 +0000170static void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000171{
172 GLfloat *out = (GLfloat *)(v);
173
174 out[0] = in[0];
175 out[1] = in[1];
176 out[2] = 0;
177 out[3] = 1;
178}
179
Keith Whitwell58822572004-01-05 15:24:53 +0000180static void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000181{
182 GLfloat *out = (GLfloat *)(v);
183
184 out[0] = in[0];
185 out[1] = 0;
186 out[2] = 0;
187 out[3] = 1;
188}
189
Keith Whitwell58822572004-01-05 15:24:53 +0000190static void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
191{
192 GLfloat *out = (GLfloat *)(v);
193
194 out[0] = in[0];
195 out[1] = in[1];
196 out[2] = in[3];
197}
198
199static void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
200{
201 abort();
202}
203
204static void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
205{
206 GLfloat *out = (GLfloat *)(v);
207
208 out[0] = in[0];
209 out[1] = in[1];
210 out[2] = in[2];
211}
212
213static void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
214{
215 GLfloat *out = (GLfloat *)(v);
216
217 out[0] = in[0];
218 out[1] = in[1];
219 out[2] = 0;
220}
221
222static void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
223{
224 GLfloat *out = (GLfloat *)(v);
225
226 out[0] = in[0];
227 out[1] = 0;
228 out[2] = 0;
229}
230
231
232static void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
233{
234 GLfloat *out = (GLfloat *)(v);
235
236 out[0] = in[0];
237 out[1] = in[1];
238}
239
240static void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
241{
242 GLfloat *out = (GLfloat *)(v);
243
244 out[0] = in[0];
245 out[1] = 0;
246}
247
248static void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
249{
250 GLfloat *out = (GLfloat *)(v);
251
252 out[0] = in[0];
253}
254
255static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell79073402004-01-05 09:43:42 +0000256 const GLfloat *in )
257{
258 GLchan *c = (GLchan *)v;
259 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
260 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
261 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
262 UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]);
263}
264
Keith Whitwell58822572004-01-05 15:24:53 +0000265static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
266 const GLfloat *in )
267{
268 GLchan *c = (GLchan *)v;
269 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
270 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
271 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
272 c[3] = CHAN_MAX;
273}
274
275static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
276 const GLfloat *in )
277{
278 GLchan *c = (GLchan *)v;
279 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
280 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
281 c[2] = 0;
282 c[3] = CHAN_MAX;
283}
284
285static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
286 const GLfloat *in )
287{
288 GLchan *c = (GLchan *)v;
289 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
290 c[1] = 0;
291 c[2] = 0;
292 c[3] = CHAN_MAX;
293}
294
295static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000296 const GLfloat *in )
297{
298 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
299 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
300 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
301 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
302}
303
Keith Whitwell58822572004-01-05 15:24:53 +0000304static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
305 const GLfloat *in )
306{
307 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
308 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
309 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
310 v[3] = 0xff;
311}
312
313static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
314 const GLfloat *in )
315{
316 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
317 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
318 v[2] = 0;
319 v[3] = 0xff;
320}
321
322static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
323 const GLfloat *in )
324{
325 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
326 v[1] = 0;
327 v[2] = 0;
328 v[3] = 0xff;
329}
330
331static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000332 const GLfloat *in )
333{
334 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
335 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
336 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
337 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
338}
339
Keith Whitwell58822572004-01-05 15:24:53 +0000340static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v,
341 const GLfloat *in )
342{
343 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
344 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
345 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
346 v[3] = 0xff;
347}
348
349static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v,
350 const GLfloat *in )
351{
352 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
353 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
354 v[0] = 0;
355 v[3] = 0xff;
356}
357
358static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v,
359 const GLfloat *in )
360{
361 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
362 v[1] = 0;
363 v[0] = 0;
364 v[3] = 0xff;
365}
366
367static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000368 const GLfloat *in )
369{
370 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
371 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
372 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
373}
374
Keith Whitwell58822572004-01-05 15:24:53 +0000375static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000376 const GLfloat *in )
377{
Keith Whitwell58822572004-01-05 15:24:53 +0000378 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
379 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
380 v[2] = 0;
381}
382
383static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
384 const GLfloat *in )
385{
386 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
387 v[1] = 0;
388 v[2] = 0;
389}
390
391static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
392 const GLfloat *in )
393{
Keith Whitwellfabb9732003-12-21 17:54:31 +0000394 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
395 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
396 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
397}
398
Keith Whitwell58822572004-01-05 15:24:53 +0000399static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
400 const GLfloat *in )
401{
402 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
403 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
404 v[0] = 0;
405}
406
407static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
408 const GLfloat *in )
409{
410 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
411 v[1] = 0;
Keith Whitwellef167c62004-01-26 21:34:28 +0000412 v[0] = 0;
Keith Whitwell58822572004-01-05 15:24:53 +0000413}
414
415
416static void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000417 const GLfloat *in )
418{
419 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
420}
421
422
423/***********************************************************************
424 * Functions to perform the reverse operations to the above, for
425 * swrast translation and clip-interpolation.
426 *
427 * Currently always extracts a full 4 floats.
428 */
429
Keith Whitwell79073402004-01-05 09:43:42 +0000430static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000431 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000432{
433 const GLfloat *in = (const GLfloat *)v;
434 const GLfloat * const vp = a->vp;
435
Keith Whitwellef167c62004-01-26 21:34:28 +0000436 /* Although included for completeness, the position coordinate is
437 * usually handled differently during clipping.
438 */
Keith Whitwellfabb9732003-12-21 17:54:31 +0000439 out[0] = (in[0] - vp[12]) / vp[0];
440 out[1] = (in[1] - vp[13]) / vp[5];
441 out[2] = (in[2] - vp[14]) / vp[10];
442 out[3] = in[3];
443}
444
Keith Whitwell79073402004-01-05 09:43:42 +0000445static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000446 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000447{
448 const GLfloat *in = (const GLfloat *)v;
449 const GLfloat * const vp = a->vp;
450
451 out[0] = (in[0] - vp[12]) / vp[0];
452 out[1] = (in[1] - vp[13]) / vp[5];
453 out[2] = (in[2] - vp[14]) / vp[10];
454 out[3] = 1;
455}
456
457
Keith Whitwell79073402004-01-05 09:43:42 +0000458static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000459 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000460{
461 const GLfloat *in = (const GLfloat *)v;
462 const GLfloat * const vp = a->vp;
463
464 out[0] = (in[0] - vp[12]) / vp[0];
465 out[1] = (in[1] - vp[13]) / vp[5];
466 out[2] = 0;
467 out[3] = 1;
468}
469
470
Keith Whitwell58822572004-01-05 15:24:53 +0000471static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000472{
473 const GLfloat *in = (const GLfloat *)v;
474
475 out[0] = in[0];
476 out[1] = in[1];
477 out[2] = in[2];
478 out[3] = in[3];
479}
480
Keith Whitwell58822572004-01-05 15:24:53 +0000481static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000482{
483 const GLfloat *in = (const GLfloat *)v;
484
485 out[0] = in[0];
486 out[1] = in[1];
487 out[2] = in[3];
488 out[3] = 1;
489}
490
491
Keith Whitwell58822572004-01-05 15:24:53 +0000492static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000493{
494 const GLfloat *in = (const GLfloat *)v;
495
496 out[0] = in[0];
497 out[1] = in[1];
498 out[2] = in[2];
499 out[3] = 1;
500}
501
502
Keith Whitwell58822572004-01-05 15:24:53 +0000503static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000504{
505 const GLfloat *in = (const GLfloat *)v;
506
507 out[0] = in[0];
508 out[1] = in[1];
509 out[2] = 0;
510 out[3] = 1;
511}
512
Keith Whitwell58822572004-01-05 15:24:53 +0000513static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000514{
515 const GLfloat *in = (const GLfloat *)v;
516
517 out[0] = in[0];
518 out[1] = 0;
519 out[2] = 0;
520 out[3] = 1;
521}
522
Keith Whitwell79073402004-01-05 09:43:42 +0000523static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000524 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000525{
Keith Whitwell79073402004-01-05 09:43:42 +0000526 GLchan *c = (GLchan *)v;
527
528 out[0] = CHAN_TO_FLOAT(c[0]);
529 out[1] = CHAN_TO_FLOAT(c[1]);
530 out[2] = CHAN_TO_FLOAT(c[2]);
531 out[3] = CHAN_TO_FLOAT(c[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000532}
533
Keith Whitwell79073402004-01-05 09:43:42 +0000534static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000535 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000536{
Keith Whitwell79073402004-01-05 09:43:42 +0000537 out[0] = UBYTE_TO_FLOAT(v[0]);
538 out[1] = UBYTE_TO_FLOAT(v[1]);
539 out[2] = UBYTE_TO_FLOAT(v[2]);
540 out[3] = UBYTE_TO_FLOAT(v[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000541}
542
Keith Whitwell79073402004-01-05 09:43:42 +0000543static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000544 const GLubyte *v )
Keith Whitwell79073402004-01-05 09:43:42 +0000545{
546 out[2] = UBYTE_TO_FLOAT(v[0]);
547 out[1] = UBYTE_TO_FLOAT(v[1]);
548 out[0] = UBYTE_TO_FLOAT(v[2]);
549 out[3] = UBYTE_TO_FLOAT(v[3]);
550}
551
552static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000553 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000554{
Keith Whitwell79073402004-01-05 09:43:42 +0000555 out[0] = UBYTE_TO_FLOAT(v[0]);
556 out[1] = UBYTE_TO_FLOAT(v[1]);
557 out[2] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000558 out[3] = 1;
559}
560
Keith Whitwell79073402004-01-05 09:43:42 +0000561static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000562 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000563{
Keith Whitwell79073402004-01-05 09:43:42 +0000564 out[2] = UBYTE_TO_FLOAT(v[0]);
565 out[1] = UBYTE_TO_FLOAT(v[1]);
566 out[0] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000567 out[3] = 1;
568}
569
Keith Whitwell58822572004-01-05 15:24:53 +0000570static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000571{
Keith Whitwell79073402004-01-05 09:43:42 +0000572 out[0] = UBYTE_TO_FLOAT(v[0]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000573 out[1] = 0;
574 out[2] = 0;
575 out[3] = 1;
576}
577
Keith Whitwell79073402004-01-05 09:43:42 +0000578
Keith Whitwell79073402004-01-05 09:43:42 +0000579struct {
Keith Whitwell58822572004-01-05 15:24:53 +0000580 const char *name;
Keith Whitwell79073402004-01-05 09:43:42 +0000581 extract_func extract;
Keith Whitwell58822572004-01-05 15:24:53 +0000582 insert_func insert[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000583 GLuint attrsize;
584} format_info[EMIT_MAX] = {
585
Keith Whitwell58822572004-01-05 15:24:53 +0000586 { "1f",
587 extract_1f,
588 { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000589 sizeof(GLfloat) },
590
Keith Whitwell58822572004-01-05 15:24:53 +0000591 { "2f",
592 extract_2f,
593 { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000594 2 * sizeof(GLfloat) },
595
Keith Whitwell58822572004-01-05 15:24:53 +0000596 { "3f",
597 extract_3f,
598 { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000599 3 * sizeof(GLfloat) },
600
Keith Whitwell58822572004-01-05 15:24:53 +0000601 { "4f",
602 extract_4f,
603 { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000604 4 * sizeof(GLfloat) },
605
Keith Whitwell58822572004-01-05 15:24:53 +0000606 { "2f_viewport",
607 extract_2f_viewport,
608 { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2,
609 insert_2f_viewport_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000610 2 * sizeof(GLfloat) },
611
Keith Whitwell58822572004-01-05 15:24:53 +0000612 { "3f_viewport",
613 extract_3f_viewport,
614 { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3,
615 insert_3f_viewport_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000616 3 * sizeof(GLfloat) },
617
Keith Whitwell58822572004-01-05 15:24:53 +0000618 { "4f_viewport",
619 extract_4f_viewport,
620 { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3,
621 insert_4f_viewport_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000622 4 * sizeof(GLfloat) },
623
Keith Whitwell58822572004-01-05 15:24:53 +0000624 { "3f_xyw",
625 extract_3f_xyw,
626 { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err,
627 insert_3f_xyw_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000628 3 * sizeof(GLfloat) },
629
Keith Whitwell58822572004-01-05 15:24:53 +0000630 { "1ub_1f",
631 extract_1ub_1f,
632 { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000633 sizeof(GLubyte) },
634
Keith Whitwell58822572004-01-05 15:24:53 +0000635 { "3ub_3f_rgb",
636 extract_3ub_3f_rgb,
637 { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3,
638 insert_3ub_3f_rgb_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000639 3 * sizeof(GLubyte) },
640
Keith Whitwell58822572004-01-05 15:24:53 +0000641 { "3ub_3f_bgr",
642 extract_3ub_3f_bgr,
643 { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3,
644 insert_3ub_3f_bgr_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000645 3 * sizeof(GLubyte) },
646
Keith Whitwell58822572004-01-05 15:24:53 +0000647 { "4ub_4f_rgba",
648 extract_4ub_4f_rgba,
649 { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3,
650 insert_4ub_4f_rgba_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000651 4 * sizeof(GLubyte) },
652
Keith Whitwell58822572004-01-05 15:24:53 +0000653 { "4ub_4f_bgra",
654 extract_4ub_4f_bgra,
655 { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3,
656 insert_4ub_4f_bgra_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000657 4 * sizeof(GLubyte) },
658
Keith Whitwell58822572004-01-05 15:24:53 +0000659 { "4chan_4f_rgba",
660 extract_4chan_4f_rgba,
661 { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
662 insert_4chan_4f_rgba_4 },
Keith Whitwell4d36f332004-01-21 15:31:46 +0000663 4 * sizeof(GLchan) },
664
665 { "pad",
666 0,
667 { 0, 0, 0, 0 },
668 0 }
Keith Whitwell79073402004-01-05 09:43:42 +0000669
670};
671
672
Keith Whitwellfabb9732003-12-21 17:54:31 +0000673/***********************************************************************
674 * Generic (non-codegen) functions for whole vertices or groups of
675 * vertices
676 */
677
678static void generic_emit( GLcontext *ctx,
679 GLuint start, GLuint end,
Keith Whitwell79073402004-01-05 09:43:42 +0000680 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000681{
Keith Whitwell79073402004-01-05 09:43:42 +0000682 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
683 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
684 struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwell58822572004-01-05 15:24:53 +0000685 GLubyte *v = (GLubyte *)dest;
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000686 GLuint i, j;
Keith Whitwell79073402004-01-05 09:43:42 +0000687 GLuint count = vtx->attr_count;
688 GLuint stride;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000689
Keith Whitwell79073402004-01-05 09:43:42 +0000690 for (j = 0; j < count; j++) {
691 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
692 a[j].inputstride = vptr->stride;
Keith Whitwell44d4a8f2004-01-06 00:18:03 +0000693 a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
Keith Whitwell58822572004-01-05 15:24:53 +0000694 a[j].emit = a[j].insert[vptr->size - 1];
Keith Whitwellfabb9732003-12-21 17:54:31 +0000695 }
696
Keith Whitwell79073402004-01-05 09:43:42 +0000697 end -= start;
698 stride = vtx->vertex_size;
699
Keith Whitwellfabb9732003-12-21 17:54:31 +0000700 for (i = 0 ; i < end ; i++, v += stride) {
Keith Whitwell79073402004-01-05 09:43:42 +0000701 for (j = 0; j < count; j++) {
Keith Whitwell58822572004-01-05 15:24:53 +0000702 GLfloat *in = (GLfloat *)a[j].inputptr;
703 a[j].inputptr += a[j].inputstride;
704 a[j].emit( &a[j], v + a[j].vertoffset, in );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000705 }
706 }
707}
708
709
710static void generic_interp( GLcontext *ctx,
711 GLfloat t,
712 GLuint edst, GLuint eout, GLuint ein,
713 GLboolean force_boundary )
714{
Keith Whitwell79073402004-01-05 09:43:42 +0000715 TNLcontext *tnl = TNL_CONTEXT(ctx);
716 struct vertex_buffer *VB = &tnl->vb;
717 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell58822572004-01-05 15:24:53 +0000718 GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
719 GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
720 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000721 const struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000722 int attr_count = vtx->attr_count;
723 int j;
Keith Whitwell79073402004-01-05 09:43:42 +0000724
725 if (tnl->NeedNdcCoords) {
726 const GLfloat *dstclip = VB->ClipPtr->data[edst];
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000727 if (dstclip[3] != 0.0) {
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000728 const GLfloat w = 1.0f / dstclip[3];
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000729 GLfloat pos[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000730
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000731 pos[0] = dstclip[0] * w;
732 pos[1] = dstclip[1] * w;
733 pos[2] = dstclip[2] * w;
734 pos[3] = w;
Keith Whitwell79073402004-01-05 09:43:42 +0000735
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000736 a[0].insert[4-1]( &a[0], vdst, pos );
737 }
Keith Whitwell79073402004-01-05 09:43:42 +0000738 }
739 else {
Keith Whitwell58822572004-01-05 15:24:53 +0000740 a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
Keith Whitwell79073402004-01-05 09:43:42 +0000741 }
742
743
744 for (j = 1; j < attr_count; j++) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000745 GLfloat fin[4], fout[4], fdst[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000746
747 a[j].extract( &a[j], fin, vin + a[j].vertoffset );
748 a[j].extract( &a[j], fout, vout + a[j].vertoffset );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000749
750 INTERP_F( t, fdst[3], fout[3], fin[3] );
751 INTERP_F( t, fdst[2], fout[2], fin[2] );
752 INTERP_F( t, fdst[1], fout[1], fin[1] );
753 INTERP_F( t, fdst[0], fout[0], fin[0] );
754
Keith Whitwell58822572004-01-05 15:24:53 +0000755 a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000756 }
757}
758
759
760/* Extract color attributes from one vertex and insert them into
761 * another. (Shortcircuit extract/insert with memcpy).
762 */
Keith Whitwell79073402004-01-05 09:43:42 +0000763static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000764{
Keith Whitwell79073402004-01-05 09:43:42 +0000765 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell58822572004-01-05 15:24:53 +0000766 GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
767 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000768 const struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000769 int attr_count = vtx->attr_count;
770 int j;
771
772 for (j = 0; j < attr_count; j++) {
Keith Whitwell79073402004-01-05 09:43:42 +0000773 if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
774 a[j].attrib == VERT_ATTRIB_COLOR1) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000775
Brian Paul3663c0f2004-01-15 00:29:51 +0000776 _mesa_memcpy( vdst + a[j].vertoffset,
777 vsrc + a[j].vertoffset,
778 a[j].vertattrsize );
Keith Whitwell79073402004-01-05 09:43:42 +0000779 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000780 }
781}
782
Keith Whitwellfabb9732003-12-21 17:54:31 +0000783
Keith Whitwell79073402004-01-05 09:43:42 +0000784/* Helper functions for hardware which doesn't put back colors and/or
785 * edgeflags into vertices.
786 */
787static void generic_interp_extras( GLcontext *ctx,
788 GLfloat t,
789 GLuint dst, GLuint out, GLuint in,
790 GLboolean force_boundary )
791{
792 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
793
794 if (VB->ColorPtr[1]) {
795 assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
796
797 INTERP_4F( t,
798 VB->ColorPtr[1]->data[dst],
799 VB->ColorPtr[1]->data[out],
800 VB->ColorPtr[1]->data[in] );
801
802 if (VB->SecondaryColorPtr[1]) {
803 INTERP_3F( t,
804 VB->SecondaryColorPtr[1]->data[dst],
805 VB->SecondaryColorPtr[1]->data[out],
806 VB->SecondaryColorPtr[1]->data[in] );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000807 }
808 }
Keith Whitwell58822572004-01-05 15:24:53 +0000809 else if (VB->IndexPtr[1]) {
810 VB->IndexPtr[1]->data[dst][0] = LINTERP( t,
811 VB->IndexPtr[1]->data[out][0],
812 VB->IndexPtr[1]->data[in][0] );
813 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000814
Keith Whitwell79073402004-01-05 09:43:42 +0000815 if (VB->EdgeFlag) {
816 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
817 }
818
819 generic_interp(ctx, t, dst, out, in, force_boundary);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000820}
821
Keith Whitwell79073402004-01-05 09:43:42 +0000822static void generic_copy_pv_extras( GLcontext *ctx,
823 GLuint dst, GLuint src )
824{
825 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
826
827 if (VB->ColorPtr[1]) {
828 COPY_4FV( VB->ColorPtr[1]->data[dst],
829 VB->ColorPtr[1]->data[src] );
830
831 if (VB->SecondaryColorPtr[1]) {
832 COPY_4FV( VB->SecondaryColorPtr[1]->data[dst],
833 VB->SecondaryColorPtr[1]->data[src] );
834 }
835 }
Keith Whitwell58822572004-01-05 15:24:53 +0000836 else if (VB->IndexPtr[1]) {
837 VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
838 }
Keith Whitwell79073402004-01-05 09:43:42 +0000839
Keith Whitwellef167c62004-01-26 21:34:28 +0000840 generic_copy_pv(ctx, dst, src);
Keith Whitwell79073402004-01-05 09:43:42 +0000841}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000842
843
844
845
846
847
848/***********************************************************************
849 * Build codegen functions or return generic ones:
850 */
851
852
853static void choose_emit_func( GLcontext *ctx,
854 GLuint start, GLuint end,
Keith Whitwell79073402004-01-05 09:43:42 +0000855 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000856{
Keith Whitwell79073402004-01-05 09:43:42 +0000857 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
858 vtx->emit = generic_emit;
859 vtx->emit( ctx, start, end, dest );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000860}
861
862
863static void choose_interp_func( GLcontext *ctx,
864 GLfloat t,
865 GLuint edst, GLuint eout, GLuint ein,
866 GLboolean force_boundary )
867{
Keith Whitwell79073402004-01-05 09:43:42 +0000868 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
869
870 if (vtx->need_extras &&
871 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
872 vtx->interp = generic_interp_extras;
873 } else {
874 vtx->interp = generic_interp;
875 }
876
877 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000878}
879
880
Keith Whitwell79073402004-01-05 09:43:42 +0000881static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000882{
Keith Whitwell79073402004-01-05 09:43:42 +0000883 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
884
885 if (vtx->need_extras &&
886 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
887 vtx->copy_pv = generic_copy_pv_extras;
888 } else {
889 vtx->copy_pv = generic_copy_pv;
890 }
891
892 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000893}
894
895
896/***********************************************************************
897 * Public entrypoints, mostly dispatch to the above:
898 */
899
Keith Whitwellfabb9732003-12-21 17:54:31 +0000900
901/* Interpolate between two vertices to produce a third:
902 */
903void _tnl_interp( GLcontext *ctx,
904 GLfloat t,
905 GLuint edst, GLuint eout, GLuint ein,
906 GLboolean force_boundary )
907{
Keith Whitwell79073402004-01-05 09:43:42 +0000908 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
909 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000910}
911
912/* Copy colors from one vertex to another:
913 */
Keith Whitwell79073402004-01-05 09:43:42 +0000914void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000915{
Keith Whitwell79073402004-01-05 09:43:42 +0000916 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
917 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000918}
919
920
921/* Extract a named attribute from a hardware vertex. Will have to
922 * reverse any viewport transformation, swizzling or other conversions
923 * which may have been applied:
924 */
Keith Whitwell79073402004-01-05 09:43:42 +0000925void _tnl_get_attr( GLcontext *ctx, const void *vin,
926 GLenum attr, GLfloat *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000927{
Keith Whitwell79073402004-01-05 09:43:42 +0000928 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
929 const struct tnl_clipspace_attr *a = vtx->attr;
930 int attr_count = vtx->attr_count;
931 int j;
932
933 for (j = 0; j < attr_count; j++) {
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000934 if (a[j].attrib == (int)attr) {
Keith Whitwell44d4a8f2004-01-06 00:18:03 +0000935 a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset );
Keith Whitwell79073402004-01-05 09:43:42 +0000936 return;
937 }
938 }
939
940 /* Else return the value from ctx->Current
941 */
Brian Paul3663c0f2004-01-15 00:29:51 +0000942 _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
Keith Whitwell79073402004-01-05 09:43:42 +0000943}
944
945void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
946{
947 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
948
949 return vtx->vertex_buf + nr * vtx->vertex_size;
950}
951
952void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state )
953{
954 if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) {
955 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
956 vtx->new_inputs = ~0;
957 vtx->interp = choose_interp_func;
958 vtx->copy_pv = choose_copy_pv_func;
959 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000960}
961
962
Keith Whitwell79073402004-01-05 09:43:42 +0000963GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
Keith Whitwell58822572004-01-05 15:24:53 +0000964 GLuint nr, const GLfloat *vp,
965 GLuint unpacked_size )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000966{
Keith Whitwell79073402004-01-05 09:43:42 +0000967 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
968 int offset = 0;
Keith Whitwell4d36f332004-01-21 15:31:46 +0000969 GLuint i, j;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000970
Keith Whitwell79073402004-01-05 09:43:42 +0000971 assert(nr < _TNL_ATTRIB_MAX);
972 assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000973
Keith Whitwell79073402004-01-05 09:43:42 +0000974 vtx->emit = choose_emit_func;
975 vtx->interp = choose_interp_func;
976 vtx->copy_pv = choose_copy_pv_func;
977 vtx->new_inputs = ~0;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000978
Keith Whitwell4d36f332004-01-21 15:31:46 +0000979 for (j = 0, i = 0; i < nr; i++) {
Keith Whitwell79073402004-01-05 09:43:42 +0000980 GLuint format = map[i].format;
Keith Whitwell4d36f332004-01-21 15:31:46 +0000981 if (format == EMIT_PAD) {
982 offset += map[i].offset;
Keith Whitwell16f54212004-01-05 15:55:01 +0000983
Keith Whitwell4d36f332004-01-21 15:31:46 +0000984/* fprintf(stderr, "%d: pad %d, offset now %d\n", i, */
985/* map[i].offset, offset); */
Keith Whitwell16f54212004-01-05 15:55:01 +0000986
Keith Whitwell4d36f332004-01-21 15:31:46 +0000987 }
988 else {
989 vtx->attr[j].attrib = map[i].attrib;
990 vtx->attr[j].vp = vp;
991 vtx->attr[j].insert = format_info[format].insert;
992 vtx->attr[j].extract = format_info[format].extract;
993 vtx->attr[j].vertattrsize = format_info[format].attrsize;
Keith Whitwell44d4a8f2004-01-06 00:18:03 +0000994
Keith Whitwell4d36f332004-01-21 15:31:46 +0000995 if (unpacked_size)
996 vtx->attr[j].vertoffset = map[i].offset;
997 else
998 vtx->attr[j].vertoffset = offset;
999
1000/* fprintf(stderr, "%d: %s offset %d\n", i, */
1001/* format_info[format].name, vtx->attr[j].vertoffset); */
1002
1003 offset += format_info[format].attrsize;
1004 j++;
1005 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001006 }
Keith Whitwell79073402004-01-05 09:43:42 +00001007
Keith Whitwell4d36f332004-01-21 15:31:46 +00001008 vtx->attr_count = j;
1009
Keith Whitwell58822572004-01-05 15:24:53 +00001010 if (unpacked_size)
1011 vtx->vertex_size = unpacked_size;
1012 else
1013 vtx->vertex_size = offset;
Keith Whitwell79073402004-01-05 09:43:42 +00001014
Keith Whitwell58822572004-01-05 15:24:53 +00001015 assert(vtx->vertex_size <= vtx->max_vertex_size);
1016
Keith Whitwell79073402004-01-05 09:43:42 +00001017 return vtx->vertex_size;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001018}
1019
1020
1021
Keith Whitwell79073402004-01-05 09:43:42 +00001022void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001023{
Keith Whitwell79073402004-01-05 09:43:42 +00001024 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1025 vtx->new_inputs |= newinputs;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001026}
1027
1028
Keith Whitwell79073402004-01-05 09:43:42 +00001029
1030void _tnl_build_vertices( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001031 GLuint start,
1032 GLuint end,
1033 GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001034{
Keith Whitwell79073402004-01-05 09:43:42 +00001035 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1036 GLuint stride = vtx->vertex_size;
1037 GLubyte *v = ((GLubyte *)vtx->vertex_buf + (start*stride));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001038
Keith Whitwell79073402004-01-05 09:43:42 +00001039 newinputs |= vtx->new_inputs;
1040 vtx->new_inputs = 0;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001041
Keith Whitwell79073402004-01-05 09:43:42 +00001042 if (newinputs)
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001043 vtx->emit( ctx, start, end, v );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001044}
1045
Keith Whitwell79073402004-01-05 09:43:42 +00001046
1047void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001048 GLuint start,
1049 GLuint end,
1050 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001051{
Keith Whitwell79073402004-01-05 09:43:42 +00001052 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001053 vtx->emit( ctx, start, end, dest );
1054 return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001055}
1056
Keith Whitwell79073402004-01-05 09:43:42 +00001057
1058void _tnl_init_vertices( GLcontext *ctx,
1059 GLuint vb_size,
1060 GLuint max_vertex_size )
1061{
1062 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1063
Keith Whitwell58822572004-01-05 15:24:53 +00001064 _tnl_install_attrs( ctx, 0, 0, 0, 0 );
Keith Whitwell79073402004-01-05 09:43:42 +00001065
1066 vtx->need_extras = GL_TRUE;
Keith Whitwell58822572004-01-05 15:24:53 +00001067 if (max_vertex_size > vtx->max_vertex_size) {
1068 _tnl_free_vertices( ctx );
1069 vtx->max_vertex_size = max_vertex_size;
Brian Paulcb7c6892004-01-26 16:16:16 +00001070 vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 );
Keith Whitwell58822572004-01-05 15:24:53 +00001071 }
Keith Whitwell79073402004-01-05 09:43:42 +00001072}
1073
1074
1075void _tnl_free_vertices( GLcontext *ctx )
1076{
1077 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1078 if (vtx->vertex_buf) {
1079 ALIGN_FREE(vtx->vertex_buf);
1080 vtx->vertex_buf = 0;
1081 }
1082}