blob: 984241c6a7776826d63329fa6ffdd6a731147d3d [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 Whitwellfabb9732003-12-21 17:54:31 +000046
Brian Paulfde4c532004-03-13 18:27:06 +000047
48/*
49 * These functions take the NDC coordinates pointed to by 'in', apply the
50 * NDC->Viewport mapping and store the results at 'v'.
51 */
52
53static void
54insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
55 const GLfloat *in )
Keith Whitwellfabb9732003-12-21 17:54:31 +000056{
57 GLfloat *out = (GLfloat *)v;
58 const GLfloat * const vp = a->vp;
59
60 out[0] = vp[0] * in[0] + vp[12];
61 out[1] = vp[5] * in[1] + vp[13];
62 out[2] = vp[10] * in[2] + vp[14];
63 out[3] = in[3];
64}
65
Keith Whitwell58822572004-01-05 15:24:53 +000066static void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
67 const GLfloat *in )
68{
69 GLfloat *out = (GLfloat *)v;
70 const GLfloat * const vp = a->vp;
71
72 out[0] = vp[0] * in[0] + vp[12];
73 out[1] = vp[5] * in[1] + vp[13];
74 out[2] = vp[10] * in[2] + vp[14];
75 out[3] = 1;
76}
77
78static void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
79 const GLfloat *in )
80{
81 GLfloat *out = (GLfloat *)v;
82 const GLfloat * const vp = a->vp;
83
84 out[0] = vp[0] * in[0] + vp[12];
85 out[1] = vp[5] * in[1] + vp[13];
86 out[2] = vp[14];
87 out[3] = 1;
88}
89
90static void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
91 const GLfloat *in )
92{
93 GLfloat *out = (GLfloat *)v;
94 const GLfloat * const vp = a->vp;
95
96 out[0] = vp[0] * in[0] + vp[12];
97 out[1] = vp[13];
98 out[2] = vp[14];
99 out[3] = 1;
100}
101
102static void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000103 const GLfloat *in )
104{
105 GLfloat *out = (GLfloat *)v;
106 const GLfloat * const vp = a->vp;
107
108 out[0] = vp[0] * in[0] + vp[12];
109 out[1] = vp[5] * in[1] + vp[13];
110 out[2] = vp[10] * in[2] + vp[14];
111}
112
Keith Whitwell58822572004-01-05 15:24:53 +0000113static void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
114 const GLfloat *in )
115{
116 GLfloat *out = (GLfloat *)v;
117 const GLfloat * const vp = a->vp;
118
119 out[0] = vp[0] * in[0] + vp[12];
120 out[1] = vp[5] * in[1] + vp[13];
121 out[2] = vp[10] * in[2] + vp[14];
122}
123
124static void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
125 const GLfloat *in )
126{
127 GLfloat *out = (GLfloat *)v;
128 const GLfloat * const vp = a->vp;
129
130 out[0] = vp[0] * in[0] + vp[12];
131 out[1] = vp[13];
132 out[2] = vp[14];
133}
134
135static void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000136 const GLfloat *in )
137{
138 GLfloat *out = (GLfloat *)v;
139 const GLfloat * const vp = a->vp;
140
141 out[0] = vp[0] * in[0] + vp[12];
142 out[1] = vp[5] * in[1] + vp[13];
143}
144
Keith Whitwell58822572004-01-05 15:24:53 +0000145static void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
146 const GLfloat *in )
147{
148 GLfloat *out = (GLfloat *)v;
149 const GLfloat * const vp = a->vp;
150
151 out[0] = vp[0] * in[0] + vp[12];
152 out[1] = vp[13];
153}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000154
Keith Whitwell58822572004-01-05 15:24:53 +0000155
Brian Paulfde4c532004-03-13 18:27:06 +0000156/*
157 * These functions do the same as above, except for the viewport mapping.
158 */
159
Keith Whitwell58822572004-01-05 15:24:53 +0000160static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000161{
162 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000163 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000164
165 out[0] = in[0];
166 out[1] = in[1];
167 out[2] = in[2];
168 out[3] = in[3];
169}
170
Keith Whitwell58822572004-01-05 15:24:53 +0000171static void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000172{
173 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000174 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000175
176 out[0] = in[0];
177 out[1] = in[1];
178 out[2] = in[2];
179 out[3] = 1;
180}
181
Keith Whitwell58822572004-01-05 15:24:53 +0000182static void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000183{
184 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000185 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000186
187 out[0] = in[0];
188 out[1] = in[1];
189 out[2] = 0;
190 out[3] = 1;
191}
192
Keith Whitwell58822572004-01-05 15:24:53 +0000193static void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000194{
195 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000196 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000197
198 out[0] = in[0];
199 out[1] = 0;
200 out[2] = 0;
201 out[3] = 1;
202}
203
Keith Whitwell58822572004-01-05 15:24:53 +0000204static void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
205{
206 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000207 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000208
209 out[0] = in[0];
210 out[1] = in[1];
211 out[2] = in[3];
212}
213
214static void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
215{
Brian Paula6c423d2004-08-25 15:59:48 +0000216 (void) a; (void) v; (void) in;
Keith Whitwell58822572004-01-05 15:24:53 +0000217 abort();
218}
219
220static void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
221{
222 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000223 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000224
225 out[0] = in[0];
226 out[1] = in[1];
227 out[2] = in[2];
228}
229
230static void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
231{
232 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000233 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000234
235 out[0] = in[0];
236 out[1] = in[1];
237 out[2] = 0;
238}
239
240static void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
241{
242 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000243 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000244
245 out[0] = in[0];
246 out[1] = 0;
247 out[2] = 0;
248}
249
250
251static void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
252{
253 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000254 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000255
256 out[0] = in[0];
257 out[1] = in[1];
258}
259
260static void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
261{
262 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000263 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000264
265 out[0] = in[0];
266 out[1] = 0;
267}
268
269static void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
270{
271 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000272 (void) a;
273
Keith Whitwell58822572004-01-05 15:24:53 +0000274 out[0] = in[0];
275}
276
277static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell79073402004-01-05 09:43:42 +0000278 const GLfloat *in )
279{
280 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000281 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000282 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
283 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
284 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
285 UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]);
286}
287
Keith Whitwell58822572004-01-05 15:24:53 +0000288static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
289 const GLfloat *in )
290{
291 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000292 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000293 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
294 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
295 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
296 c[3] = CHAN_MAX;
297}
298
299static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
300 const GLfloat *in )
301{
302 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000303 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000304 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
305 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
306 c[2] = 0;
307 c[3] = CHAN_MAX;
308}
309
310static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
311 const GLfloat *in )
312{
313 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000314 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000315 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
316 c[1] = 0;
317 c[2] = 0;
318 c[3] = CHAN_MAX;
319}
320
321static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000322 const GLfloat *in )
323{
Brian Paula6c423d2004-08-25 15:59:48 +0000324 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000325 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
326 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
327 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
328 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
329}
330
Keith Whitwell58822572004-01-05 15:24:53 +0000331static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
332 const GLfloat *in )
333{
Brian Paula6c423d2004-08-25 15:59:48 +0000334 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000335 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
336 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
337 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
338 v[3] = 0xff;
339}
340
341static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
342 const GLfloat *in )
343{
Brian Paula6c423d2004-08-25 15:59:48 +0000344 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000345 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
346 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
347 v[2] = 0;
348 v[3] = 0xff;
349}
350
351static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
352 const GLfloat *in )
353{
Brian Paula6c423d2004-08-25 15:59:48 +0000354 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000355 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
356 v[1] = 0;
357 v[2] = 0;
358 v[3] = 0xff;
359}
360
361static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000362 const GLfloat *in )
363{
Brian Paula6c423d2004-08-25 15:59:48 +0000364 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000365 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
366 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
367 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
368 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
369}
370
Keith Whitwell58822572004-01-05 15:24:53 +0000371static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v,
372 const GLfloat *in )
373{
Brian Paula6c423d2004-08-25 15:59:48 +0000374 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000375 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
376 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
377 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
378 v[3] = 0xff;
379}
380
381static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v,
382 const GLfloat *in )
383{
Brian Paula6c423d2004-08-25 15:59:48 +0000384 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000385 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
386 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
387 v[0] = 0;
388 v[3] = 0xff;
389}
390
391static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v,
392 const GLfloat *in )
393{
Brian Paula6c423d2004-08-25 15:59:48 +0000394 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000395 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
396 v[1] = 0;
397 v[0] = 0;
398 v[3] = 0xff;
399}
400
Ian Romanick40e85222004-10-17 21:53:43 +0000401static void insert_4ub_4f_argb_4( const struct tnl_clipspace_attr *a, GLubyte *v,
402 const GLfloat *in )
403{
404 (void) a;
405 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
406 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
407 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
408 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
409}
410
411static void insert_4ub_4f_argb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
412 const GLfloat *in )
413{
414 (void) a;
415 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
416 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
417 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
418 v[0] = 0xff;
419}
420
421static void insert_4ub_4f_argb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
422 const GLfloat *in )
423{
424 (void) a;
425 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
426 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
427 v[3] = 0x00;
428 v[0] = 0xff;
429}
430
431static void insert_4ub_4f_argb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
432 const GLfloat *in )
433{
434 (void) a;
435 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
436 v[2] = 0x00;
437 v[3] = 0x00;
438 v[0] = 0xff;
439}
440
Ian Romanick74b00802004-10-23 00:42:17 +0000441static void insert_4ub_4f_abgr_4( const struct tnl_clipspace_attr *a, GLubyte *v,
442 const GLfloat *in )
443{
444 (void) a;
445 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
446 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
447 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
448 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
449}
450
451static void insert_4ub_4f_abgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
452 const GLfloat *in )
453{
454 (void) a;
455 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
456 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
457 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
458 v[0] = 0xff;
459}
460
461static void insert_4ub_4f_abgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
462 const GLfloat *in )
463{
464 (void) a;
465 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
466 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
467 v[1] = 0x00;
468 v[0] = 0xff;
469}
470
471static void insert_4ub_4f_abgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
472 const GLfloat *in )
473{
474 (void) a;
475 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
476 v[2] = 0x00;
477 v[1] = 0x00;
478 v[0] = 0xff;
479}
480
Keith Whitwell58822572004-01-05 15:24:53 +0000481static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000482 const GLfloat *in )
483{
Brian Paula6c423d2004-08-25 15:59:48 +0000484 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000485 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
486 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
487 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
488}
489
Keith Whitwell58822572004-01-05 15:24:53 +0000490static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000491 const GLfloat *in )
492{
Brian Paula6c423d2004-08-25 15:59:48 +0000493 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000494 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
495 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
496 v[2] = 0;
497}
498
499static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
500 const GLfloat *in )
501{
Brian Paula6c423d2004-08-25 15:59:48 +0000502 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000503 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
504 v[1] = 0;
505 v[2] = 0;
506}
507
508static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
509 const GLfloat *in )
510{
Brian Paula6c423d2004-08-25 15:59:48 +0000511 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000512 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
513 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
514 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
515}
516
Keith Whitwell58822572004-01-05 15:24:53 +0000517static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
518 const GLfloat *in )
519{
Brian Paula6c423d2004-08-25 15:59:48 +0000520 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000521 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
522 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
523 v[0] = 0;
524}
525
526static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
527 const GLfloat *in )
528{
Brian Paula6c423d2004-08-25 15:59:48 +0000529 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000530 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
531 v[1] = 0;
Keith Whitwellef167c62004-01-26 21:34:28 +0000532 v[0] = 0;
Keith Whitwell58822572004-01-05 15:24:53 +0000533}
534
535
536static void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000537 const GLfloat *in )
538{
Brian Paula6c423d2004-08-25 15:59:48 +0000539 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000540 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
541}
542
543
544/***********************************************************************
545 * Functions to perform the reverse operations to the above, for
546 * swrast translation and clip-interpolation.
547 *
548 * Currently always extracts a full 4 floats.
549 */
550
Keith Whitwell79073402004-01-05 09:43:42 +0000551static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000552 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000553{
554 const GLfloat *in = (const GLfloat *)v;
555 const GLfloat * const vp = a->vp;
556
Keith Whitwellef167c62004-01-26 21:34:28 +0000557 /* Although included for completeness, the position coordinate is
558 * usually handled differently during clipping.
559 */
Keith Whitwellfabb9732003-12-21 17:54:31 +0000560 out[0] = (in[0] - vp[12]) / vp[0];
561 out[1] = (in[1] - vp[13]) / vp[5];
562 out[2] = (in[2] - vp[14]) / vp[10];
563 out[3] = in[3];
564}
565
Keith Whitwell79073402004-01-05 09:43:42 +0000566static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000567 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000568{
569 const GLfloat *in = (const GLfloat *)v;
570 const GLfloat * const vp = a->vp;
571
572 out[0] = (in[0] - vp[12]) / vp[0];
573 out[1] = (in[1] - vp[13]) / vp[5];
574 out[2] = (in[2] - vp[14]) / vp[10];
575 out[3] = 1;
576}
577
578
Keith Whitwell79073402004-01-05 09:43:42 +0000579static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000580 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000581{
582 const GLfloat *in = (const GLfloat *)v;
583 const GLfloat * const vp = a->vp;
584
585 out[0] = (in[0] - vp[12]) / vp[0];
586 out[1] = (in[1] - vp[13]) / vp[5];
587 out[2] = 0;
588 out[3] = 1;
589}
590
591
Keith Whitwell58822572004-01-05 15:24:53 +0000592static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000593{
594 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000595 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000596
597 out[0] = in[0];
598 out[1] = in[1];
599 out[2] = in[2];
600 out[3] = in[3];
601}
602
Keith Whitwell58822572004-01-05 15:24:53 +0000603static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000604{
605 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000606 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000607
608 out[0] = in[0];
609 out[1] = in[1];
Keith Whitwellbacd9d12004-01-30 11:16:12 +0000610 out[2] = 0;
611 out[3] = in[2];
Keith Whitwellfabb9732003-12-21 17:54:31 +0000612}
613
614
Keith Whitwell58822572004-01-05 15:24:53 +0000615static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000616{
617 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000618 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000619
620 out[0] = in[0];
621 out[1] = in[1];
622 out[2] = in[2];
623 out[3] = 1;
624}
625
626
Keith Whitwell58822572004-01-05 15:24:53 +0000627static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000628{
629 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000630 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000631
632 out[0] = in[0];
633 out[1] = in[1];
634 out[2] = 0;
635 out[3] = 1;
636}
637
Keith Whitwell58822572004-01-05 15:24:53 +0000638static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000639{
640 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000641 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000642
643 out[0] = in[0];
644 out[1] = 0;
645 out[2] = 0;
646 out[3] = 1;
647}
648
Keith Whitwell79073402004-01-05 09:43:42 +0000649static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000650 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000651{
Keith Whitwell79073402004-01-05 09:43:42 +0000652 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000653 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000654
655 out[0] = CHAN_TO_FLOAT(c[0]);
656 out[1] = CHAN_TO_FLOAT(c[1]);
657 out[2] = CHAN_TO_FLOAT(c[2]);
658 out[3] = CHAN_TO_FLOAT(c[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000659}
660
Keith Whitwell79073402004-01-05 09:43:42 +0000661static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000662 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000663{
Brian Paula6c423d2004-08-25 15:59:48 +0000664 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000665 out[0] = UBYTE_TO_FLOAT(v[0]);
666 out[1] = UBYTE_TO_FLOAT(v[1]);
667 out[2] = UBYTE_TO_FLOAT(v[2]);
668 out[3] = UBYTE_TO_FLOAT(v[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000669}
670
Keith Whitwell79073402004-01-05 09:43:42 +0000671static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000672 const GLubyte *v )
Keith Whitwell79073402004-01-05 09:43:42 +0000673{
Brian Paula6c423d2004-08-25 15:59:48 +0000674 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000675 out[2] = UBYTE_TO_FLOAT(v[0]);
676 out[1] = UBYTE_TO_FLOAT(v[1]);
677 out[0] = UBYTE_TO_FLOAT(v[2]);
678 out[3] = UBYTE_TO_FLOAT(v[3]);
679}
680
Ian Romanick40e85222004-10-17 21:53:43 +0000681static void extract_4ub_4f_argb( const struct tnl_clipspace_attr *a, GLfloat *out,
682 const GLubyte *v )
683{
684 (void) a;
685 out[3] = UBYTE_TO_FLOAT(v[0]);
686 out[0] = UBYTE_TO_FLOAT(v[1]);
687 out[1] = UBYTE_TO_FLOAT(v[2]);
688 out[2] = UBYTE_TO_FLOAT(v[3]);
689}
690
Ian Romanick74b00802004-10-23 00:42:17 +0000691static void extract_4ub_4f_abgr( const struct tnl_clipspace_attr *a, GLfloat *out,
692 const GLubyte *v )
693{
694 (void) a;
695 out[3] = UBYTE_TO_FLOAT(v[0]);
696 out[2] = UBYTE_TO_FLOAT(v[1]);
697 out[1] = UBYTE_TO_FLOAT(v[2]);
698 out[0] = UBYTE_TO_FLOAT(v[3]);
699}
700
Keith Whitwell79073402004-01-05 09:43:42 +0000701static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000702 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000703{
Brian Paula6c423d2004-08-25 15:59:48 +0000704 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000705 out[0] = UBYTE_TO_FLOAT(v[0]);
706 out[1] = UBYTE_TO_FLOAT(v[1]);
707 out[2] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000708 out[3] = 1;
709}
710
Keith Whitwell79073402004-01-05 09:43:42 +0000711static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000712 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000713{
Brian Paula6c423d2004-08-25 15:59:48 +0000714 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000715 out[2] = UBYTE_TO_FLOAT(v[0]);
716 out[1] = UBYTE_TO_FLOAT(v[1]);
717 out[0] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000718 out[3] = 1;
719}
720
Keith Whitwell58822572004-01-05 15:24:53 +0000721static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000722{
Brian Paula6c423d2004-08-25 15:59:48 +0000723 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000724 out[0] = UBYTE_TO_FLOAT(v[0]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000725 out[1] = 0;
726 out[2] = 0;
727 out[3] = 1;
728}
729
Keith Whitwell79073402004-01-05 09:43:42 +0000730
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000731static struct {
Keith Whitwell58822572004-01-05 15:24:53 +0000732 const char *name;
Keith Whitwell3d383612004-07-01 13:14:05 +0000733 tnl_extract_func extract;
734 tnl_insert_func insert[4];
Brian Paulfde4c532004-03-13 18:27:06 +0000735 const GLuint attrsize;
Keith Whitwell79073402004-01-05 09:43:42 +0000736} format_info[EMIT_MAX] = {
737
Keith Whitwell58822572004-01-05 15:24:53 +0000738 { "1f",
739 extract_1f,
740 { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000741 sizeof(GLfloat) },
742
Keith Whitwell58822572004-01-05 15:24:53 +0000743 { "2f",
744 extract_2f,
745 { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000746 2 * sizeof(GLfloat) },
747
Keith Whitwell58822572004-01-05 15:24:53 +0000748 { "3f",
749 extract_3f,
750 { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000751 3 * sizeof(GLfloat) },
752
Keith Whitwell58822572004-01-05 15:24:53 +0000753 { "4f",
754 extract_4f,
755 { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000756 4 * sizeof(GLfloat) },
757
Keith Whitwell58822572004-01-05 15:24:53 +0000758 { "2f_viewport",
759 extract_2f_viewport,
760 { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2,
761 insert_2f_viewport_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000762 2 * sizeof(GLfloat) },
763
Keith Whitwell58822572004-01-05 15:24:53 +0000764 { "3f_viewport",
765 extract_3f_viewport,
766 { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3,
767 insert_3f_viewport_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000768 3 * sizeof(GLfloat) },
769
Keith Whitwell58822572004-01-05 15:24:53 +0000770 { "4f_viewport",
771 extract_4f_viewport,
772 { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3,
773 insert_4f_viewport_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000774 4 * sizeof(GLfloat) },
775
Keith Whitwell58822572004-01-05 15:24:53 +0000776 { "3f_xyw",
777 extract_3f_xyw,
778 { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err,
779 insert_3f_xyw_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000780 3 * sizeof(GLfloat) },
781
Keith Whitwell58822572004-01-05 15:24:53 +0000782 { "1ub_1f",
783 extract_1ub_1f,
784 { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000785 sizeof(GLubyte) },
786
Keith Whitwell58822572004-01-05 15:24:53 +0000787 { "3ub_3f_rgb",
788 extract_3ub_3f_rgb,
789 { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3,
790 insert_3ub_3f_rgb_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000791 3 * sizeof(GLubyte) },
792
Keith Whitwell58822572004-01-05 15:24:53 +0000793 { "3ub_3f_bgr",
794 extract_3ub_3f_bgr,
795 { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3,
796 insert_3ub_3f_bgr_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000797 3 * sizeof(GLubyte) },
798
Keith Whitwell58822572004-01-05 15:24:53 +0000799 { "4ub_4f_rgba",
800 extract_4ub_4f_rgba,
801 { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3,
802 insert_4ub_4f_rgba_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000803 4 * sizeof(GLubyte) },
804
Keith Whitwell58822572004-01-05 15:24:53 +0000805 { "4ub_4f_bgra",
806 extract_4ub_4f_bgra,
807 { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3,
808 insert_4ub_4f_bgra_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000809 4 * sizeof(GLubyte) },
810
Ian Romanick40e85222004-10-17 21:53:43 +0000811 { "4ub_4f_argb",
812 extract_4ub_4f_argb,
813 { insert_4ub_4f_argb_1, insert_4ub_4f_argb_2, insert_4ub_4f_argb_3,
814 insert_4ub_4f_argb_4 },
815 4 * sizeof(GLubyte) },
816
Ian Romanick74b00802004-10-23 00:42:17 +0000817 { "4ub_4f_abgr",
818 extract_4ub_4f_abgr,
819 { insert_4ub_4f_abgr_1, insert_4ub_4f_abgr_2, insert_4ub_4f_abgr_3,
820 insert_4ub_4f_abgr_4 },
821 4 * sizeof(GLubyte) },
822
Keith Whitwell58822572004-01-05 15:24:53 +0000823 { "4chan_4f_rgba",
824 extract_4chan_4f_rgba,
825 { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
826 insert_4chan_4f_rgba_4 },
Keith Whitwell4d36f332004-01-21 15:31:46 +0000827 4 * sizeof(GLchan) },
828
829 { "pad",
830 0,
831 { 0, 0, 0, 0 },
832 0 }
Keith Whitwell79073402004-01-05 09:43:42 +0000833
834};
835
836
Keith Whitwellfabb9732003-12-21 17:54:31 +0000837/***********************************************************************
838 * Generic (non-codegen) functions for whole vertices or groups of
839 * vertices
840 */
841
842static void generic_emit( GLcontext *ctx,
843 GLuint start, GLuint end,
Keith Whitwell79073402004-01-05 09:43:42 +0000844 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000845{
Keith Whitwell79073402004-01-05 09:43:42 +0000846 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
847 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
848 struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwell58822572004-01-05 15:24:53 +0000849 GLubyte *v = (GLubyte *)dest;
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000850 GLuint i, j;
Brian Paulfde4c532004-03-13 18:27:06 +0000851 const GLuint count = vtx->attr_count;
Keith Whitwell79073402004-01-05 09:43:42 +0000852 GLuint stride;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000853
Keith Whitwell79073402004-01-05 09:43:42 +0000854 for (j = 0; j < count; j++) {
855 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
856 a[j].inputstride = vptr->stride;
Keith Whitwell44d4a8f2004-01-06 00:18:03 +0000857 a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
Keith Whitwell58822572004-01-05 15:24:53 +0000858 a[j].emit = a[j].insert[vptr->size - 1];
Keith Whitwellfabb9732003-12-21 17:54:31 +0000859 }
860
Keith Whitwell79073402004-01-05 09:43:42 +0000861 end -= start;
862 stride = vtx->vertex_size;
863
Keith Whitwellfabb9732003-12-21 17:54:31 +0000864 for (i = 0 ; i < end ; i++, v += stride) {
Keith Whitwell79073402004-01-05 09:43:42 +0000865 for (j = 0; j < count; j++) {
Keith Whitwell58822572004-01-05 15:24:53 +0000866 GLfloat *in = (GLfloat *)a[j].inputptr;
867 a[j].inputptr += a[j].inputstride;
868 a[j].emit( &a[j], v + a[j].vertoffset, in );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000869 }
870 }
871}
872
873
874static void generic_interp( GLcontext *ctx,
875 GLfloat t,
876 GLuint edst, GLuint eout, GLuint ein,
877 GLboolean force_boundary )
878{
Keith Whitwell79073402004-01-05 09:43:42 +0000879 TNLcontext *tnl = TNL_CONTEXT(ctx);
880 struct vertex_buffer *VB = &tnl->vb;
881 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Brian Paulfde4c532004-03-13 18:27:06 +0000882 const GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
883 const GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
Keith Whitwell58822572004-01-05 15:24:53 +0000884 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000885 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +0000886 const GLuint attr_count = vtx->attr_count;
887 GLuint j;
Brian Paula6c423d2004-08-25 15:59:48 +0000888 (void) force_boundary;
Keith Whitwell79073402004-01-05 09:43:42 +0000889
890 if (tnl->NeedNdcCoords) {
891 const GLfloat *dstclip = VB->ClipPtr->data[edst];
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000892 if (dstclip[3] != 0.0) {
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000893 const GLfloat w = 1.0f / dstclip[3];
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000894 GLfloat pos[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000895
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000896 pos[0] = dstclip[0] * w;
897 pos[1] = dstclip[1] * w;
898 pos[2] = dstclip[2] * w;
899 pos[3] = w;
Keith Whitwell79073402004-01-05 09:43:42 +0000900
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000901 a[0].insert[4-1]( &a[0], vdst, pos );
902 }
Keith Whitwell79073402004-01-05 09:43:42 +0000903 }
904 else {
Keith Whitwell58822572004-01-05 15:24:53 +0000905 a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
Keith Whitwell79073402004-01-05 09:43:42 +0000906 }
907
908
909 for (j = 1; j < attr_count; j++) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000910 GLfloat fin[4], fout[4], fdst[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000911
912 a[j].extract( &a[j], fin, vin + a[j].vertoffset );
913 a[j].extract( &a[j], fout, vout + a[j].vertoffset );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000914
915 INTERP_F( t, fdst[3], fout[3], fin[3] );
916 INTERP_F( t, fdst[2], fout[2], fin[2] );
917 INTERP_F( t, fdst[1], fout[1], fin[1] );
918 INTERP_F( t, fdst[0], fout[0], fin[0] );
919
Keith Whitwell58822572004-01-05 15:24:53 +0000920 a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000921 }
922}
923
924
925/* Extract color attributes from one vertex and insert them into
926 * another. (Shortcircuit extract/insert with memcpy).
927 */
Keith Whitwell79073402004-01-05 09:43:42 +0000928static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000929{
Keith Whitwell79073402004-01-05 09:43:42 +0000930 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell58822572004-01-05 15:24:53 +0000931 GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
932 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000933 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +0000934 const GLuint attr_count = vtx->attr_count;
935 GLuint j;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000936
937 for (j = 0; j < attr_count; j++) {
Keith Whitwell79073402004-01-05 09:43:42 +0000938 if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
939 a[j].attrib == VERT_ATTRIB_COLOR1) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000940
Brian Paul3663c0f2004-01-15 00:29:51 +0000941 _mesa_memcpy( vdst + a[j].vertoffset,
942 vsrc + a[j].vertoffset,
943 a[j].vertattrsize );
Keith Whitwell79073402004-01-05 09:43:42 +0000944 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000945 }
946}
947
Keith Whitwellfabb9732003-12-21 17:54:31 +0000948
Keith Whitwell79073402004-01-05 09:43:42 +0000949/* Helper functions for hardware which doesn't put back colors and/or
950 * edgeflags into vertices.
951 */
952static void generic_interp_extras( GLcontext *ctx,
953 GLfloat t,
954 GLuint dst, GLuint out, GLuint in,
955 GLboolean force_boundary )
956{
957 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
958
959 if (VB->ColorPtr[1]) {
960 assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
961
962 INTERP_4F( t,
963 VB->ColorPtr[1]->data[dst],
964 VB->ColorPtr[1]->data[out],
965 VB->ColorPtr[1]->data[in] );
966
967 if (VB->SecondaryColorPtr[1]) {
968 INTERP_3F( t,
969 VB->SecondaryColorPtr[1]->data[dst],
970 VB->SecondaryColorPtr[1]->data[out],
971 VB->SecondaryColorPtr[1]->data[in] );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000972 }
973 }
Keith Whitwell58822572004-01-05 15:24:53 +0000974 else if (VB->IndexPtr[1]) {
975 VB->IndexPtr[1]->data[dst][0] = LINTERP( t,
976 VB->IndexPtr[1]->data[out][0],
977 VB->IndexPtr[1]->data[in][0] );
978 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000979
Keith Whitwell79073402004-01-05 09:43:42 +0000980 if (VB->EdgeFlag) {
981 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
982 }
983
984 generic_interp(ctx, t, dst, out, in, force_boundary);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000985}
986
Keith Whitwell79073402004-01-05 09:43:42 +0000987static void generic_copy_pv_extras( GLcontext *ctx,
988 GLuint dst, GLuint src )
989{
990 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
991
992 if (VB->ColorPtr[1]) {
993 COPY_4FV( VB->ColorPtr[1]->data[dst],
994 VB->ColorPtr[1]->data[src] );
995
996 if (VB->SecondaryColorPtr[1]) {
997 COPY_4FV( VB->SecondaryColorPtr[1]->data[dst],
998 VB->SecondaryColorPtr[1]->data[src] );
999 }
1000 }
Keith Whitwell58822572004-01-05 15:24:53 +00001001 else if (VB->IndexPtr[1]) {
1002 VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
1003 }
Keith Whitwell79073402004-01-05 09:43:42 +00001004
Keith Whitwellef167c62004-01-26 21:34:28 +00001005 generic_copy_pv(ctx, dst, src);
Keith Whitwell79073402004-01-05 09:43:42 +00001006}
Keith Whitwellfabb9732003-12-21 17:54:31 +00001007
1008
1009
1010
Keith Whitwellfabb9732003-12-21 17:54:31 +00001011/***********************************************************************
1012 * Build codegen functions or return generic ones:
1013 */
1014
1015
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001016static void do_emit( GLcontext *ctx, GLuint start, GLuint end,
1017 void *dest)
Keith Whitwellfabb9732003-12-21 17:54:31 +00001018{
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001019 TNLcontext *tnl = TNL_CONTEXT(ctx);
1020 struct vertex_buffer *VB = &tnl->vb;
Keith Whitwell79073402004-01-05 09:43:42 +00001021 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001022 struct tnl_clipspace_attr *a = vtx->attr;
1023 const GLuint count = vtx->attr_count;
1024 GLuint j;
1025
1026 for (j = 0; j < count; j++) {
1027 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
1028 a[j].inputstride = vptr->stride;
1029 a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
1030 a[j].emit = a[j].insert[vptr->size - 1];
1031 }
1032
1033 vtx->emit = 0;
1034
1035 if (0)
1036 vtx->emit = _tnl_codegen_emit(ctx);
1037
1038 if (!vtx->emit)
1039 vtx->emit = generic_emit;
1040
Keith Whitwell79073402004-01-05 09:43:42 +00001041 vtx->emit( ctx, start, end, dest );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001042}
1043
1044
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001045
Keith Whitwellfabb9732003-12-21 17:54:31 +00001046static void choose_interp_func( GLcontext *ctx,
1047 GLfloat t,
1048 GLuint edst, GLuint eout, GLuint ein,
1049 GLboolean force_boundary )
1050{
Keith Whitwell79073402004-01-05 09:43:42 +00001051 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1052
1053 if (vtx->need_extras &&
1054 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
1055 vtx->interp = generic_interp_extras;
1056 } else {
1057 vtx->interp = generic_interp;
1058 }
1059
1060 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001061}
1062
1063
Keith Whitwell79073402004-01-05 09:43:42 +00001064static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001065{
Keith Whitwell79073402004-01-05 09:43:42 +00001066 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1067
1068 if (vtx->need_extras &&
1069 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
1070 vtx->copy_pv = generic_copy_pv_extras;
1071 } else {
1072 vtx->copy_pv = generic_copy_pv;
1073 }
1074
1075 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001076}
1077
1078
1079/***********************************************************************
1080 * Public entrypoints, mostly dispatch to the above:
1081 */
1082
Keith Whitwellfabb9732003-12-21 17:54:31 +00001083
1084/* Interpolate between two vertices to produce a third:
1085 */
1086void _tnl_interp( GLcontext *ctx,
1087 GLfloat t,
1088 GLuint edst, GLuint eout, GLuint ein,
1089 GLboolean force_boundary )
1090{
Keith Whitwell79073402004-01-05 09:43:42 +00001091 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1092 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001093}
1094
1095/* Copy colors from one vertex to another:
1096 */
Keith Whitwell79073402004-01-05 09:43:42 +00001097void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001098{
Keith Whitwell79073402004-01-05 09:43:42 +00001099 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1100 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001101}
1102
1103
1104/* Extract a named attribute from a hardware vertex. Will have to
1105 * reverse any viewport transformation, swizzling or other conversions
1106 * which may have been applied:
1107 */
Keith Whitwell79073402004-01-05 09:43:42 +00001108void _tnl_get_attr( GLcontext *ctx, const void *vin,
1109 GLenum attr, GLfloat *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001110{
Keith Whitwell79073402004-01-05 09:43:42 +00001111 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1112 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +00001113 const GLuint attr_count = vtx->attr_count;
1114 GLuint j;
Keith Whitwell79073402004-01-05 09:43:42 +00001115
1116 for (j = 0; j < attr_count; j++) {
Brian Paulbdd15b52004-05-04 15:11:06 +00001117 if (a[j].attrib == attr) {
Keith Whitwell44d4a8f2004-01-06 00:18:03 +00001118 a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset );
Keith Whitwell79073402004-01-05 09:43:42 +00001119 return;
1120 }
1121 }
1122
Keith Whitwell47736342004-02-16 15:15:24 +00001123 /* Else return the value from ctx->Current -- dangerous???
Keith Whitwell79073402004-01-05 09:43:42 +00001124 */
Brian Paul3663c0f2004-01-15 00:29:51 +00001125 _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
Keith Whitwell79073402004-01-05 09:43:42 +00001126}
1127
Keith Whitwell47736342004-02-16 15:15:24 +00001128
1129/* Complementary operation to the above.
1130 */
1131void _tnl_set_attr( GLcontext *ctx, void *vout,
1132 GLenum attr, const GLfloat *src )
1133{
1134 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1135 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +00001136 const GLuint attr_count = vtx->attr_count;
1137 GLuint j;
Keith Whitwell47736342004-02-16 15:15:24 +00001138
1139 for (j = 0; j < attr_count; j++) {
Brian Paulbdd15b52004-05-04 15:11:06 +00001140 if (a[j].attrib == attr) {
Keith Whitwell47736342004-02-16 15:15:24 +00001141 a[j].insert[4-1]( &a[j], (GLubyte *)vout + a[j].vertoffset, src );
1142 return;
1143 }
1144 }
1145}
1146
1147
Keith Whitwell79073402004-01-05 09:43:42 +00001148void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
1149{
1150 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1151
1152 return vtx->vertex_buf + nr * vtx->vertex_size;
1153}
1154
1155void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state )
1156{
1157 if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) {
1158 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1159 vtx->new_inputs = ~0;
1160 vtx->interp = choose_interp_func;
1161 vtx->copy_pv = choose_copy_pv_func;
1162 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001163}
1164
1165
Keith Whitwell79073402004-01-05 09:43:42 +00001166GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
Keith Whitwell58822572004-01-05 15:24:53 +00001167 GLuint nr, const GLfloat *vp,
1168 GLuint unpacked_size )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001169{
Keith Whitwell79073402004-01-05 09:43:42 +00001170 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Brian Paulfde4c532004-03-13 18:27:06 +00001171 GLuint offset = 0;
Keith Whitwell4d36f332004-01-21 15:31:46 +00001172 GLuint i, j;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001173
Keith Whitwell79073402004-01-05 09:43:42 +00001174 assert(nr < _TNL_ATTRIB_MAX);
1175 assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
Keith Whitwellfabb9732003-12-21 17:54:31 +00001176
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001177 vtx->emit = 0;
Keith Whitwell79073402004-01-05 09:43:42 +00001178 vtx->interp = choose_interp_func;
1179 vtx->copy_pv = choose_copy_pv_func;
1180 vtx->new_inputs = ~0;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001181
Keith Whitwell4d36f332004-01-21 15:31:46 +00001182 for (j = 0, i = 0; i < nr; i++) {
Brian Paulfde4c532004-03-13 18:27:06 +00001183 const GLuint format = map[i].format;
Keith Whitwell4d36f332004-01-21 15:31:46 +00001184 if (format == EMIT_PAD) {
Brian Paulbbea6ec2004-07-02 14:35:50 +00001185 /*
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001186 fprintf(stderr, "%d: pad %d, offset %d\n", i,
1187 map[i].offset, offset);
Brian Paulbbea6ec2004-07-02 14:35:50 +00001188 */
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001189 offset += map[i].offset;
Keith Whitwell16f54212004-01-05 15:55:01 +00001190
Keith Whitwell4d36f332004-01-21 15:31:46 +00001191 }
1192 else {
1193 vtx->attr[j].attrib = map[i].attrib;
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001194 vtx->attr[j].format = format;
Keith Whitwell4d36f332004-01-21 15:31:46 +00001195 vtx->attr[j].vp = vp;
1196 vtx->attr[j].insert = format_info[format].insert;
1197 vtx->attr[j].extract = format_info[format].extract;
1198 vtx->attr[j].vertattrsize = format_info[format].attrsize;
Keith Whitwell44d4a8f2004-01-06 00:18:03 +00001199
Keith Whitwell4d36f332004-01-21 15:31:46 +00001200 if (unpacked_size)
1201 vtx->attr[j].vertoffset = map[i].offset;
1202 else
1203 vtx->attr[j].vertoffset = offset;
1204
Brian Paulbbea6ec2004-07-02 14:35:50 +00001205 /*
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001206 fprintf(stderr, "%d: %s, vp %p, offset %d\n", i,
1207 format_info[format].name, (void *)vp,
1208 vtx->attr[j].vertoffset);
Brian Paulbbea6ec2004-07-02 14:35:50 +00001209 */
Keith Whitwell4d36f332004-01-21 15:31:46 +00001210 offset += format_info[format].attrsize;
1211 j++;
1212 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001213 }
Keith Whitwell79073402004-01-05 09:43:42 +00001214
Keith Whitwell4d36f332004-01-21 15:31:46 +00001215 vtx->attr_count = j;
1216
Keith Whitwell58822572004-01-05 15:24:53 +00001217 if (unpacked_size)
1218 vtx->vertex_size = unpacked_size;
1219 else
1220 vtx->vertex_size = offset;
Keith Whitwell79073402004-01-05 09:43:42 +00001221
Keith Whitwell58822572004-01-05 15:24:53 +00001222 assert(vtx->vertex_size <= vtx->max_vertex_size);
1223
Keith Whitwell79073402004-01-05 09:43:42 +00001224 return vtx->vertex_size;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001225}
1226
1227
1228
Keith Whitwell79073402004-01-05 09:43:42 +00001229void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001230{
Keith Whitwell79073402004-01-05 09:43:42 +00001231 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1232 vtx->new_inputs |= newinputs;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001233}
1234
1235
Keith Whitwell79073402004-01-05 09:43:42 +00001236void _tnl_build_vertices( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001237 GLuint start,
1238 GLuint end,
1239 GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001240{
Keith Whitwell79073402004-01-05 09:43:42 +00001241 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Brian Paulfde4c532004-03-13 18:27:06 +00001242 const GLuint stride = vtx->vertex_size;
1243 GLubyte *vDest = ((GLubyte *)vtx->vertex_buf + (start*stride));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001244
Keith Whitwell79073402004-01-05 09:43:42 +00001245 newinputs |= vtx->new_inputs;
1246 vtx->new_inputs = 0;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001247
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001248 if (newinputs)
1249 do_emit( ctx, start, end, vDest );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001250}
1251
Keith Whitwell79073402004-01-05 09:43:42 +00001252
1253void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001254 GLuint start,
1255 GLuint end,
1256 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001257{
Keith Whitwell79073402004-01-05 09:43:42 +00001258 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001259 do_emit( ctx, start, end, dest );
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001260 return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001261}
1262
Keith Whitwell79073402004-01-05 09:43:42 +00001263
1264void _tnl_init_vertices( GLcontext *ctx,
1265 GLuint vb_size,
1266 GLuint max_vertex_size )
1267{
1268 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1269
Keith Whitwell58822572004-01-05 15:24:53 +00001270 _tnl_install_attrs( ctx, 0, 0, 0, 0 );
Keith Whitwell79073402004-01-05 09:43:42 +00001271
1272 vtx->need_extras = GL_TRUE;
Keith Whitwell58822572004-01-05 15:24:53 +00001273 if (max_vertex_size > vtx->max_vertex_size) {
1274 _tnl_free_vertices( ctx );
1275 vtx->max_vertex_size = max_vertex_size;
Brian Paulcb7c6892004-01-26 16:16:16 +00001276 vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 );
Keith Whitwell58822572004-01-05 15:24:53 +00001277 }
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001278
1279 _tnl_init_c_codegen( &vtx->codegen );
Keith Whitwell79073402004-01-05 09:43:42 +00001280}
1281
1282
1283void _tnl_free_vertices( GLcontext *ctx )
1284{
1285 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1286 if (vtx->vertex_buf) {
1287 ALIGN_FREE(vtx->vertex_buf);
1288 vtx->vertex_buf = 0;
1289 }
1290}