blob: 2ed4c417590314babea5643d077c89a4f33cd33d [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
Keith Whitwell699fc6b2005-01-05 20:56:05 +000053static INLINE void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Brian Paulfde4c532004-03-13 18:27:06 +000054 const GLfloat *in )
Keith Whitwellfabb9732003-12-21 17:54:31 +000055{
56 GLfloat *out = (GLfloat *)v;
57 const GLfloat * const vp = a->vp;
58
59 out[0] = vp[0] * in[0] + vp[12];
60 out[1] = vp[5] * in[1] + vp[13];
61 out[2] = vp[10] * in[2] + vp[14];
62 out[3] = in[3];
63}
64
Keith Whitwell699fc6b2005-01-05 20:56:05 +000065static INLINE void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +000066 const GLfloat *in )
67{
68 GLfloat *out = (GLfloat *)v;
69 const GLfloat * const vp = a->vp;
70
71 out[0] = vp[0] * in[0] + vp[12];
72 out[1] = vp[5] * in[1] + vp[13];
73 out[2] = vp[10] * in[2] + vp[14];
74 out[3] = 1;
75}
76
Keith Whitwell699fc6b2005-01-05 20:56:05 +000077static INLINE void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +000078 const GLfloat *in )
79{
80 GLfloat *out = (GLfloat *)v;
81 const GLfloat * const vp = a->vp;
82
83 out[0] = vp[0] * in[0] + vp[12];
84 out[1] = vp[5] * in[1] + vp[13];
85 out[2] = vp[14];
86 out[3] = 1;
87}
88
Keith Whitwell699fc6b2005-01-05 20:56:05 +000089static INLINE void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +000090 const GLfloat *in )
91{
92 GLfloat *out = (GLfloat *)v;
93 const GLfloat * const vp = a->vp;
94
95 out[0] = vp[0] * in[0] + vp[12];
96 out[1] = vp[13];
97 out[2] = vp[14];
98 out[3] = 1;
99}
100
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000101static INLINE void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000102 const GLfloat *in )
103{
104 GLfloat *out = (GLfloat *)v;
105 const GLfloat * const vp = a->vp;
106
107 out[0] = vp[0] * in[0] + vp[12];
108 out[1] = vp[5] * in[1] + vp[13];
109 out[2] = vp[10] * in[2] + vp[14];
110}
111
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000112static INLINE void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000113 const GLfloat *in )
114{
115 GLfloat *out = (GLfloat *)v;
116 const GLfloat * const vp = a->vp;
117
118 out[0] = vp[0] * in[0] + vp[12];
119 out[1] = vp[5] * in[1] + vp[13];
120 out[2] = vp[10] * in[2] + vp[14];
121}
122
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000123static INLINE void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000124 const GLfloat *in )
125{
126 GLfloat *out = (GLfloat *)v;
127 const GLfloat * const vp = a->vp;
128
129 out[0] = vp[0] * in[0] + vp[12];
130 out[1] = vp[13];
131 out[2] = vp[14];
132}
133
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000134static INLINE void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000135 const GLfloat *in )
136{
137 GLfloat *out = (GLfloat *)v;
138 const GLfloat * const vp = a->vp;
139
140 out[0] = vp[0] * in[0] + vp[12];
141 out[1] = vp[5] * in[1] + vp[13];
142}
143
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000144static INLINE void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000145 const GLfloat *in )
146{
147 GLfloat *out = (GLfloat *)v;
148 const GLfloat * const vp = a->vp;
149
150 out[0] = vp[0] * in[0] + vp[12];
151 out[1] = vp[13];
152}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000153
Keith Whitwell58822572004-01-05 15:24:53 +0000154
Brian Paulfde4c532004-03-13 18:27:06 +0000155/*
156 * These functions do the same as above, except for the viewport mapping.
157 */
158
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000159static INLINE void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000160{
161 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000162 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000163
164 out[0] = in[0];
165 out[1] = in[1];
166 out[2] = in[2];
167 out[3] = in[3];
168}
169
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000170static INLINE void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000171{
172 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000173 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000174
175 out[0] = in[0];
176 out[1] = in[1];
177 out[2] = in[2];
178 out[3] = 1;
179}
180
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000181static INLINE void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000182{
183 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000184 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000185
186 out[0] = in[0];
187 out[1] = in[1];
188 out[2] = 0;
189 out[3] = 1;
190}
191
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000192static INLINE void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000193{
194 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000195 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000196
197 out[0] = in[0];
198 out[1] = 0;
199 out[2] = 0;
200 out[3] = 1;
201}
202
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000203static INLINE void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000204{
205 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000206 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000207
208 out[0] = in[0];
209 out[1] = in[1];
210 out[2] = in[3];
211}
212
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000213static INLINE void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000214{
Brian Paula6c423d2004-08-25 15:59:48 +0000215 (void) a; (void) v; (void) in;
Keith Whitwell58822572004-01-05 15:24:53 +0000216 abort();
217}
218
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000219static INLINE void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000220{
221 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000222 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000223
224 out[0] = in[0];
225 out[1] = in[1];
226 out[2] = in[2];
227}
228
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000229static INLINE void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000230{
231 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000232 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000233
234 out[0] = in[0];
235 out[1] = in[1];
236 out[2] = 0;
237}
238
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000239static INLINE void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000240{
241 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000242 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000243
244 out[0] = in[0];
245 out[1] = 0;
246 out[2] = 0;
247}
248
249
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000250static INLINE void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000251{
252 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000253 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000254
255 out[0] = in[0];
256 out[1] = in[1];
257}
258
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000259static INLINE void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000260{
261 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000262 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000263
264 out[0] = in[0];
265 out[1] = 0;
266}
267
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000268static INLINE void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell58822572004-01-05 15:24:53 +0000269{
270 GLfloat *out = (GLfloat *)(v);
Brian Paula6c423d2004-08-25 15:59:48 +0000271 (void) a;
272
Keith Whitwell58822572004-01-05 15:24:53 +0000273 out[0] = in[0];
274}
275
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000276static INLINE void insert_null( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
277{
278 (void) a; (void) v; (void) in;
279}
280
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000281static INLINE void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell79073402004-01-05 09:43:42 +0000282 const GLfloat *in )
283{
284 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000285 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000286 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
287 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
288 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
289 UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]);
290}
291
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000292static INLINE void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000293 const GLfloat *in )
294{
295 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000296 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000297 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
298 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
299 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
300 c[3] = CHAN_MAX;
301}
302
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000303static INLINE void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000304 const GLfloat *in )
305{
306 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000307 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000308 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
309 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
310 c[2] = 0;
311 c[3] = CHAN_MAX;
312}
313
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000314static INLINE void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000315 const GLfloat *in )
316{
317 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000318 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000319 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
320 c[1] = 0;
321 c[2] = 0;
322 c[3] = CHAN_MAX;
323}
324
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000325static INLINE void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000326 const GLfloat *in )
327{
Brian Paula6c423d2004-08-25 15:59:48 +0000328 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000329 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
330 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
331 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
332 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
333}
334
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000335static INLINE void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000336 const GLfloat *in )
337{
Brian Paula6c423d2004-08-25 15:59:48 +0000338 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000339 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
340 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
341 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
342 v[3] = 0xff;
343}
344
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000345static INLINE void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000346 const GLfloat *in )
347{
Brian Paula6c423d2004-08-25 15:59:48 +0000348 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000349 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
350 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
351 v[2] = 0;
352 v[3] = 0xff;
353}
354
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000355static INLINE void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000356 const GLfloat *in )
357{
Brian Paula6c423d2004-08-25 15:59:48 +0000358 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000359 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
360 v[1] = 0;
361 v[2] = 0;
362 v[3] = 0xff;
363}
364
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000365static INLINE void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000366 const GLfloat *in )
367{
Brian Paula6c423d2004-08-25 15:59:48 +0000368 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000369 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
370 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
371 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
372 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
373}
374
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000375static INLINE void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000376 const GLfloat *in )
377{
Brian Paula6c423d2004-08-25 15:59:48 +0000378 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000379 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
380 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
381 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
382 v[3] = 0xff;
383}
384
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000385static INLINE void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000386 const GLfloat *in )
387{
Brian Paula6c423d2004-08-25 15:59:48 +0000388 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000389 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
390 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
391 v[0] = 0;
392 v[3] = 0xff;
393}
394
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000395static INLINE void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000396 const GLfloat *in )
397{
Brian Paula6c423d2004-08-25 15:59:48 +0000398 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000399 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
400 v[1] = 0;
401 v[0] = 0;
402 v[3] = 0xff;
403}
404
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000405static INLINE void insert_4ub_4f_argb_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick40e85222004-10-17 21:53:43 +0000406 const GLfloat *in )
407{
408 (void) a;
409 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
410 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
411 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
412 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
413}
414
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000415static INLINE void insert_4ub_4f_argb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick40e85222004-10-17 21:53:43 +0000416 const GLfloat *in )
417{
418 (void) a;
419 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
420 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
421 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
422 v[0] = 0xff;
423}
424
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000425static INLINE void insert_4ub_4f_argb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick40e85222004-10-17 21:53:43 +0000426 const GLfloat *in )
427{
428 (void) a;
429 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
430 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
431 v[3] = 0x00;
432 v[0] = 0xff;
433}
434
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000435static INLINE void insert_4ub_4f_argb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick40e85222004-10-17 21:53:43 +0000436 const GLfloat *in )
437{
438 (void) a;
439 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
440 v[2] = 0x00;
441 v[3] = 0x00;
442 v[0] = 0xff;
443}
444
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000445static INLINE void insert_4ub_4f_abgr_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick74b00802004-10-23 00:42:17 +0000446 const GLfloat *in )
447{
448 (void) a;
449 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
450 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
451 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
452 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
453}
454
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000455static INLINE void insert_4ub_4f_abgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick74b00802004-10-23 00:42:17 +0000456 const GLfloat *in )
457{
458 (void) a;
459 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
460 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
461 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
462 v[0] = 0xff;
463}
464
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000465static INLINE void insert_4ub_4f_abgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick74b00802004-10-23 00:42:17 +0000466 const GLfloat *in )
467{
468 (void) a;
469 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
470 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
471 v[1] = 0x00;
472 v[0] = 0xff;
473}
474
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000475static INLINE void insert_4ub_4f_abgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Ian Romanick74b00802004-10-23 00:42:17 +0000476 const GLfloat *in )
477{
478 (void) a;
479 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
480 v[2] = 0x00;
481 v[1] = 0x00;
482 v[0] = 0xff;
483}
484
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000485static INLINE void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000486 const GLfloat *in )
487{
Brian Paula6c423d2004-08-25 15:59:48 +0000488 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000489 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
490 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
491 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
492}
493
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000494static INLINE void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000495 const GLfloat *in )
496{
Brian Paula6c423d2004-08-25 15:59:48 +0000497 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000498 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
499 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
500 v[2] = 0;
501}
502
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000503static INLINE void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000504 const GLfloat *in )
505{
Brian Paula6c423d2004-08-25 15:59:48 +0000506 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000507 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
508 v[1] = 0;
509 v[2] = 0;
510}
511
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000512static INLINE void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000513 const GLfloat *in )
514{
Brian Paula6c423d2004-08-25 15:59:48 +0000515 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000516 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
517 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
518 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
519}
520
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000521static INLINE void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000522 const GLfloat *in )
523{
Brian Paula6c423d2004-08-25 15:59:48 +0000524 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000525 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
526 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
527 v[0] = 0;
528}
529
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000530static INLINE void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell58822572004-01-05 15:24:53 +0000531 const GLfloat *in )
532{
Brian Paula6c423d2004-08-25 15:59:48 +0000533 (void) a;
Keith Whitwell58822572004-01-05 15:24:53 +0000534 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
535 v[1] = 0;
Keith Whitwellef167c62004-01-26 21:34:28 +0000536 v[0] = 0;
Keith Whitwell58822572004-01-05 15:24:53 +0000537}
538
539
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000540static INLINE void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000541 const GLfloat *in )
542{
Brian Paula6c423d2004-08-25 15:59:48 +0000543 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000544 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
545}
546
547
548/***********************************************************************
549 * Functions to perform the reverse operations to the above, for
550 * swrast translation and clip-interpolation.
551 *
552 * Currently always extracts a full 4 floats.
553 */
554
Keith Whitwell79073402004-01-05 09:43:42 +0000555static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000556 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000557{
558 const GLfloat *in = (const GLfloat *)v;
559 const GLfloat * const vp = a->vp;
560
Keith Whitwellef167c62004-01-26 21:34:28 +0000561 /* Although included for completeness, the position coordinate is
562 * usually handled differently during clipping.
563 */
Keith Whitwellfabb9732003-12-21 17:54:31 +0000564 out[0] = (in[0] - vp[12]) / vp[0];
565 out[1] = (in[1] - vp[13]) / vp[5];
566 out[2] = (in[2] - vp[14]) / vp[10];
567 out[3] = in[3];
568}
569
Keith Whitwell79073402004-01-05 09:43:42 +0000570static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000571 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000572{
573 const GLfloat *in = (const GLfloat *)v;
574 const GLfloat * const vp = a->vp;
575
576 out[0] = (in[0] - vp[12]) / vp[0];
577 out[1] = (in[1] - vp[13]) / vp[5];
578 out[2] = (in[2] - vp[14]) / vp[10];
579 out[3] = 1;
580}
581
582
Keith Whitwell79073402004-01-05 09:43:42 +0000583static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000584 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000585{
586 const GLfloat *in = (const GLfloat *)v;
587 const GLfloat * const vp = a->vp;
588
589 out[0] = (in[0] - vp[12]) / vp[0];
590 out[1] = (in[1] - vp[13]) / vp[5];
591 out[2] = 0;
592 out[3] = 1;
593}
594
595
Keith Whitwell58822572004-01-05 15:24:53 +0000596static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000597{
598 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000599 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000600
601 out[0] = in[0];
602 out[1] = in[1];
603 out[2] = in[2];
604 out[3] = in[3];
605}
606
Keith Whitwell58822572004-01-05 15:24:53 +0000607static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000608{
609 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000610 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000611
612 out[0] = in[0];
613 out[1] = in[1];
Keith Whitwellbacd9d12004-01-30 11:16:12 +0000614 out[2] = 0;
615 out[3] = in[2];
Keith Whitwellfabb9732003-12-21 17:54:31 +0000616}
617
618
Keith Whitwell58822572004-01-05 15:24:53 +0000619static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000620{
621 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000622 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000623
624 out[0] = in[0];
625 out[1] = in[1];
626 out[2] = in[2];
627 out[3] = 1;
628}
629
630
Keith Whitwell58822572004-01-05 15:24:53 +0000631static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000632{
633 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000634 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000635
636 out[0] = in[0];
637 out[1] = in[1];
638 out[2] = 0;
639 out[3] = 1;
640}
641
Keith Whitwell58822572004-01-05 15:24:53 +0000642static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000643{
644 const GLfloat *in = (const GLfloat *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000645 (void) a;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000646
647 out[0] = in[0];
648 out[1] = 0;
649 out[2] = 0;
650 out[3] = 1;
651}
652
Keith Whitwell79073402004-01-05 09:43:42 +0000653static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000654 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000655{
Keith Whitwell79073402004-01-05 09:43:42 +0000656 GLchan *c = (GLchan *)v;
Brian Paula6c423d2004-08-25 15:59:48 +0000657 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000658
659 out[0] = CHAN_TO_FLOAT(c[0]);
660 out[1] = CHAN_TO_FLOAT(c[1]);
661 out[2] = CHAN_TO_FLOAT(c[2]);
662 out[3] = CHAN_TO_FLOAT(c[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000663}
664
Keith Whitwell79073402004-01-05 09:43:42 +0000665static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000666 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000667{
Brian Paula6c423d2004-08-25 15:59:48 +0000668 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000669 out[0] = UBYTE_TO_FLOAT(v[0]);
670 out[1] = UBYTE_TO_FLOAT(v[1]);
671 out[2] = UBYTE_TO_FLOAT(v[2]);
672 out[3] = UBYTE_TO_FLOAT(v[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000673}
674
Keith Whitwell79073402004-01-05 09:43:42 +0000675static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000676 const GLubyte *v )
Keith Whitwell79073402004-01-05 09:43:42 +0000677{
Brian Paula6c423d2004-08-25 15:59:48 +0000678 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000679 out[2] = UBYTE_TO_FLOAT(v[0]);
680 out[1] = UBYTE_TO_FLOAT(v[1]);
681 out[0] = UBYTE_TO_FLOAT(v[2]);
682 out[3] = UBYTE_TO_FLOAT(v[3]);
683}
684
Ian Romanick40e85222004-10-17 21:53:43 +0000685static void extract_4ub_4f_argb( const struct tnl_clipspace_attr *a, GLfloat *out,
686 const GLubyte *v )
687{
688 (void) a;
689 out[3] = UBYTE_TO_FLOAT(v[0]);
690 out[0] = UBYTE_TO_FLOAT(v[1]);
691 out[1] = UBYTE_TO_FLOAT(v[2]);
692 out[2] = UBYTE_TO_FLOAT(v[3]);
693}
694
Ian Romanick74b00802004-10-23 00:42:17 +0000695static void extract_4ub_4f_abgr( const struct tnl_clipspace_attr *a, GLfloat *out,
696 const GLubyte *v )
697{
698 (void) a;
699 out[3] = UBYTE_TO_FLOAT(v[0]);
700 out[2] = UBYTE_TO_FLOAT(v[1]);
701 out[1] = UBYTE_TO_FLOAT(v[2]);
702 out[0] = UBYTE_TO_FLOAT(v[3]);
703}
704
Keith Whitwell79073402004-01-05 09:43:42 +0000705static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000706 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000707{
Brian Paula6c423d2004-08-25 15:59:48 +0000708 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000709 out[0] = UBYTE_TO_FLOAT(v[0]);
710 out[1] = UBYTE_TO_FLOAT(v[1]);
711 out[2] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000712 out[3] = 1;
713}
714
Keith Whitwell79073402004-01-05 09:43:42 +0000715static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000716 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000717{
Brian Paula6c423d2004-08-25 15:59:48 +0000718 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000719 out[2] = UBYTE_TO_FLOAT(v[0]);
720 out[1] = UBYTE_TO_FLOAT(v[1]);
721 out[0] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000722 out[3] = 1;
723}
724
Keith Whitwell58822572004-01-05 15:24:53 +0000725static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000726{
Brian Paula6c423d2004-08-25 15:59:48 +0000727 (void) a;
Keith Whitwell79073402004-01-05 09:43:42 +0000728 out[0] = UBYTE_TO_FLOAT(v[0]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000729 out[1] = 0;
730 out[2] = 0;
731 out[3] = 1;
732}
733
Keith Whitwell79073402004-01-05 09:43:42 +0000734
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000735const static struct {
Keith Whitwell58822572004-01-05 15:24:53 +0000736 const char *name;
Keith Whitwell3d383612004-07-01 13:14:05 +0000737 tnl_extract_func extract;
738 tnl_insert_func insert[4];
Brian Paulfde4c532004-03-13 18:27:06 +0000739 const GLuint attrsize;
Keith Whitwell79073402004-01-05 09:43:42 +0000740} format_info[EMIT_MAX] = {
741
Keith Whitwell58822572004-01-05 15:24:53 +0000742 { "1f",
743 extract_1f,
744 { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000745 sizeof(GLfloat) },
746
Keith Whitwell58822572004-01-05 15:24:53 +0000747 { "2f",
748 extract_2f,
749 { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000750 2 * sizeof(GLfloat) },
751
Keith Whitwell58822572004-01-05 15:24:53 +0000752 { "3f",
753 extract_3f,
754 { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000755 3 * sizeof(GLfloat) },
756
Keith Whitwell58822572004-01-05 15:24:53 +0000757 { "4f",
758 extract_4f,
759 { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000760 4 * sizeof(GLfloat) },
761
Keith Whitwell58822572004-01-05 15:24:53 +0000762 { "2f_viewport",
763 extract_2f_viewport,
764 { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2,
765 insert_2f_viewport_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000766 2 * sizeof(GLfloat) },
767
Keith Whitwell58822572004-01-05 15:24:53 +0000768 { "3f_viewport",
769 extract_3f_viewport,
770 { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3,
771 insert_3f_viewport_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000772 3 * sizeof(GLfloat) },
773
Keith Whitwell58822572004-01-05 15:24:53 +0000774 { "4f_viewport",
775 extract_4f_viewport,
776 { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3,
777 insert_4f_viewport_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000778 4 * sizeof(GLfloat) },
779
Keith Whitwell58822572004-01-05 15:24:53 +0000780 { "3f_xyw",
781 extract_3f_xyw,
782 { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err,
783 insert_3f_xyw_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000784 3 * sizeof(GLfloat) },
785
Keith Whitwell58822572004-01-05 15:24:53 +0000786 { "1ub_1f",
787 extract_1ub_1f,
788 { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000789 sizeof(GLubyte) },
790
Keith Whitwell58822572004-01-05 15:24:53 +0000791 { "3ub_3f_rgb",
792 extract_3ub_3f_rgb,
793 { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3,
794 insert_3ub_3f_rgb_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000795 3 * sizeof(GLubyte) },
796
Keith Whitwell58822572004-01-05 15:24:53 +0000797 { "3ub_3f_bgr",
798 extract_3ub_3f_bgr,
799 { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3,
800 insert_3ub_3f_bgr_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000801 3 * sizeof(GLubyte) },
802
Keith Whitwell58822572004-01-05 15:24:53 +0000803 { "4ub_4f_rgba",
804 extract_4ub_4f_rgba,
805 { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3,
806 insert_4ub_4f_rgba_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000807 4 * sizeof(GLubyte) },
808
Keith Whitwell58822572004-01-05 15:24:53 +0000809 { "4ub_4f_bgra",
810 extract_4ub_4f_bgra,
811 { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3,
812 insert_4ub_4f_bgra_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000813 4 * sizeof(GLubyte) },
814
Ian Romanick40e85222004-10-17 21:53:43 +0000815 { "4ub_4f_argb",
816 extract_4ub_4f_argb,
817 { insert_4ub_4f_argb_1, insert_4ub_4f_argb_2, insert_4ub_4f_argb_3,
818 insert_4ub_4f_argb_4 },
819 4 * sizeof(GLubyte) },
820
Ian Romanick74b00802004-10-23 00:42:17 +0000821 { "4ub_4f_abgr",
822 extract_4ub_4f_abgr,
823 { insert_4ub_4f_abgr_1, insert_4ub_4f_abgr_2, insert_4ub_4f_abgr_3,
824 insert_4ub_4f_abgr_4 },
825 4 * sizeof(GLubyte) },
826
Keith Whitwell58822572004-01-05 15:24:53 +0000827 { "4chan_4f_rgba",
828 extract_4chan_4f_rgba,
829 { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
830 insert_4chan_4f_rgba_4 },
Keith Whitwell4d36f332004-01-21 15:31:46 +0000831 4 * sizeof(GLchan) },
832
833 { "pad",
834 0,
835 { 0, 0, 0, 0 },
836 0 }
Keith Whitwell79073402004-01-05 09:43:42 +0000837
838};
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000839
840
841
842
843/***********************************************************************
844 * Hardwired fastpaths for emitting whole vertices or groups of
845 * vertices
846 */
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000847static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest);
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000848
Keith Whitwellfa136222005-01-07 15:54:48 +0000849
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000850#define EMIT5(NR, F0, F1, F2, F3, F4, NAME) \
851static void NAME( GLcontext *ctx, \
852 GLuint count, \
853 GLubyte *v ) \
854{ \
855 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); \
856 struct tnl_clipspace_attr *a = vtx->attr; \
857 GLuint i; \
858 \
859 if (vtx->attr_count != NR || \
860 (NR > 0 && a[0].emit != F0) || \
861 (NR > 1 && a[1].emit != F1) || \
862 (NR > 2 && a[2].emit != F2) || \
863 (NR > 3 && a[3].emit != F3) || \
864 (NR > 4 && a[4].emit != F4)) { \
865 choose_emit_func( ctx, count, v ); \
866 return; \
867 } \
868 \
869 for (i = 0 ; i < count ; i++, v += vtx->vertex_size) { \
870 if (NR > 0) { \
871 F0( &a[0], v + a[0].vertoffset, (GLfloat *)a[0].inputptr ); \
872 a[0].inputptr += a[0].inputstride; \
873 } \
874 \
875 if (NR > 1) { \
876 F1( &a[1], v + a[1].vertoffset, (GLfloat *)a[1].inputptr ); \
877 a[1].inputptr += a[1].inputstride; \
878 } \
879 \
880 if (NR > 2) { \
Keith Whitwellf0e4f5e2005-01-07 16:43:39 +0000881 F2( &a[2], v + a[2].vertoffset, (GLfloat *)a[2].inputptr ); \
882 a[2].inputptr += a[2].inputstride; \
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000883 } \
884 \
885 if (NR > 3) { \
Keith Whitwellf0e4f5e2005-01-07 16:43:39 +0000886 F3( &a[3], v + a[3].vertoffset, (GLfloat *)a[3].inputptr ); \
887 a[3].inputptr += a[3].inputstride; \
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000888 } \
889 \
890 if (NR > 4) { \
Keith Whitwellf0e4f5e2005-01-07 16:43:39 +0000891 F4( &a[4], v + a[4].vertoffset, (GLfloat *)a[4].inputptr ); \
892 a[4].inputptr += a[4].inputstride; \
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000893 } \
894 } \
Keith Whitwellfa136222005-01-07 15:54:48 +0000895}
896
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000897
898#define EMIT2(F0, F1, NAME) EMIT5(2, F0, F1, insert_null, \
899 insert_null, insert_null, NAME)
Keith Whitwellfa136222005-01-07 15:54:48 +0000900
Keith Whitwellf0e4f5e2005-01-07 16:43:39 +0000901#define EMIT3(F0, F1, F2, NAME) EMIT5(3, F0, F1, F2, insert_null, \
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000902 insert_null, NAME)
903
Keith Whitwellf0e4f5e2005-01-07 16:43:39 +0000904#define EMIT4(F0, F1, F2, F3, NAME) EMIT5(4, F0, F1, F2, F3, \
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000905 insert_null, NAME)
906
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000907
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000908EMIT2(insert_3f_viewport_3, insert_4ub_4f_rgba_4, emit_viewport3_rgba4)
909EMIT2(insert_3f_viewport_3, insert_4ub_4f_bgra_4, emit_viewport3_bgra4)
910EMIT2(insert_3f_3, insert_4ub_4f_rgba_4, emit_xyz3_rgba4)
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000911
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000912EMIT3(insert_4f_viewport_4, insert_4ub_4f_rgba_4, insert_2f_2, emit_viewport4_rgba4_st2)
913EMIT3(insert_4f_viewport_4, insert_4ub_4f_bgra_4, insert_2f_2, emit_viewport4_bgra4_st2)
914EMIT3(insert_4f_4, insert_4ub_4f_rgba_4, insert_2f_2, emit_xyzw4_rgba4_st2)
Keith Whitwell699fc6b2005-01-05 20:56:05 +0000915
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000916EMIT4(insert_4f_viewport_4, insert_4ub_4f_rgba_4, insert_2f_2, insert_2f_2, emit_viewport4_rgba4_st2_st2)
917EMIT4(insert_4f_viewport_4, insert_4ub_4f_bgra_4, insert_2f_2, insert_2f_2, emit_viewport4_bgra4_st2_st2)
918EMIT4(insert_4f_4, insert_4ub_4f_rgba_4, insert_2f_2, insert_2f_2, emit_xyzw4_rgba4_st2_st2)
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000919
920
Keith Whitwellae73b3d2005-01-07 16:25:40 +0000921
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000922
Keith Whitwell79073402004-01-05 09:43:42 +0000923
Keith Whitwellfabb9732003-12-21 17:54:31 +0000924/***********************************************************************
925 * Generic (non-codegen) functions for whole vertices or groups of
926 * vertices
927 */
928
929static void generic_emit( GLcontext *ctx,
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000930 GLuint count,
931 GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000932{
Keith Whitwell79073402004-01-05 09:43:42 +0000933 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
934 struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000935 const GLuint attr_count = vtx->attr_count;
936 const GLuint stride = vtx->vertex_size;
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000937 GLuint i, j;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000938
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000939 for (i = 0 ; i < count ; i++, v += stride) {
940 for (j = 0; j < attr_count; j++) {
Keith Whitwell58822572004-01-05 15:24:53 +0000941 GLfloat *in = (GLfloat *)a[j].inputptr;
942 a[j].inputptr += a[j].inputstride;
943 a[j].emit( &a[j], v + a[j].vertoffset, in );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000944 }
945 }
946}
947
948
949static void generic_interp( GLcontext *ctx,
950 GLfloat t,
951 GLuint edst, GLuint eout, GLuint ein,
952 GLboolean force_boundary )
953{
Keith Whitwell79073402004-01-05 09:43:42 +0000954 TNLcontext *tnl = TNL_CONTEXT(ctx);
955 struct vertex_buffer *VB = &tnl->vb;
956 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Brian Paulfde4c532004-03-13 18:27:06 +0000957 const GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
958 const GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
Keith Whitwell58822572004-01-05 15:24:53 +0000959 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000960 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +0000961 const GLuint attr_count = vtx->attr_count;
962 GLuint j;
Brian Paula6c423d2004-08-25 15:59:48 +0000963 (void) force_boundary;
Keith Whitwell79073402004-01-05 09:43:42 +0000964
965 if (tnl->NeedNdcCoords) {
966 const GLfloat *dstclip = VB->ClipPtr->data[edst];
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000967 if (dstclip[3] != 0.0) {
Karl Schultzc6c4cd82004-01-13 01:11:09 +0000968 const GLfloat w = 1.0f / dstclip[3];
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000969 GLfloat pos[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000970
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000971 pos[0] = dstclip[0] * w;
972 pos[1] = dstclip[1] * w;
973 pos[2] = dstclip[2] * w;
974 pos[3] = w;
Keith Whitwell79073402004-01-05 09:43:42 +0000975
Keith Whitwellfb2a95b2004-01-08 13:55:24 +0000976 a[0].insert[4-1]( &a[0], vdst, pos );
977 }
Keith Whitwell79073402004-01-05 09:43:42 +0000978 }
979 else {
Keith Whitwell58822572004-01-05 15:24:53 +0000980 a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
Keith Whitwell79073402004-01-05 09:43:42 +0000981 }
982
983
984 for (j = 1; j < attr_count; j++) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000985 GLfloat fin[4], fout[4], fdst[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000986
987 a[j].extract( &a[j], fin, vin + a[j].vertoffset );
988 a[j].extract( &a[j], fout, vout + a[j].vertoffset );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000989
990 INTERP_F( t, fdst[3], fout[3], fin[3] );
991 INTERP_F( t, fdst[2], fout[2], fin[2] );
992 INTERP_F( t, fdst[1], fout[1], fin[1] );
993 INTERP_F( t, fdst[0], fout[0], fin[0] );
994
Keith Whitwell58822572004-01-05 15:24:53 +0000995 a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000996 }
997}
998
999
1000/* Extract color attributes from one vertex and insert them into
1001 * another. (Shortcircuit extract/insert with memcpy).
1002 */
Keith Whitwell79073402004-01-05 09:43:42 +00001003static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001004{
Keith Whitwell79073402004-01-05 09:43:42 +00001005 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell58822572004-01-05 15:24:53 +00001006 GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
1007 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +00001008 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +00001009 const GLuint attr_count = vtx->attr_count;
1010 GLuint j;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001011
1012 for (j = 0; j < attr_count; j++) {
Keith Whitwell79073402004-01-05 09:43:42 +00001013 if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
1014 a[j].attrib == VERT_ATTRIB_COLOR1) {
Keith Whitwellfabb9732003-12-21 17:54:31 +00001015
Brian Paul3663c0f2004-01-15 00:29:51 +00001016 _mesa_memcpy( vdst + a[j].vertoffset,
1017 vsrc + a[j].vertoffset,
1018 a[j].vertattrsize );
Keith Whitwell79073402004-01-05 09:43:42 +00001019 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001020 }
1021}
1022
Keith Whitwellfabb9732003-12-21 17:54:31 +00001023
Keith Whitwell79073402004-01-05 09:43:42 +00001024/* Helper functions for hardware which doesn't put back colors and/or
1025 * edgeflags into vertices.
1026 */
1027static void generic_interp_extras( GLcontext *ctx,
1028 GLfloat t,
1029 GLuint dst, GLuint out, GLuint in,
1030 GLboolean force_boundary )
1031{
1032 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
1033
Keith Whitwella887a442005-01-10 12:30:08 +00001034 /* If stride is zero, ColorPtr[1] is constant across the VB, so
1035 * there is no point interpolating between two values as they will
1036 * be identical. In all other cases, this value is generated by
1037 * t_vb_lighttmp.h and has a stride of 4 dwords.
1038 */
1039 if (VB->ColorPtr[1] && VB->ColorPtr[1]->stride) {
Keith Whitwell79073402004-01-05 09:43:42 +00001040 assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
1041
1042 INTERP_4F( t,
1043 VB->ColorPtr[1]->data[dst],
1044 VB->ColorPtr[1]->data[out],
1045 VB->ColorPtr[1]->data[in] );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001046 }
Keith Whitwella887a442005-01-10 12:30:08 +00001047
1048 if (VB->SecondaryColorPtr[1]) {
1049 assert(VB->SecondaryColorPtr[1]->stride == 4 * sizeof(GLfloat));
1050
1051 INTERP_3F( t,
1052 VB->SecondaryColorPtr[1]->data[dst],
1053 VB->SecondaryColorPtr[1]->data[out],
1054 VB->SecondaryColorPtr[1]->data[in] );
1055 }
1056
1057 if (VB->IndexPtr[1]) {
Keith Whitwell58822572004-01-05 15:24:53 +00001058 VB->IndexPtr[1]->data[dst][0] = LINTERP( t,
1059 VB->IndexPtr[1]->data[out][0],
1060 VB->IndexPtr[1]->data[in][0] );
1061 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001062
Keith Whitwell79073402004-01-05 09:43:42 +00001063 if (VB->EdgeFlag) {
1064 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
1065 }
1066
1067 generic_interp(ctx, t, dst, out, in, force_boundary);
Keith Whitwellfabb9732003-12-21 17:54:31 +00001068}
1069
Keith Whitwell79073402004-01-05 09:43:42 +00001070static void generic_copy_pv_extras( GLcontext *ctx,
1071 GLuint dst, GLuint src )
1072{
1073 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
1074
Keith Whitwella887a442005-01-10 12:30:08 +00001075 /* See above comment:
1076 */
1077 if (VB->ColorPtr[1] && VB->ColorPtr[1]->stride) {
Keith Whitwell79073402004-01-05 09:43:42 +00001078 COPY_4FV( VB->ColorPtr[1]->data[dst],
1079 VB->ColorPtr[1]->data[src] );
Keith Whitwell79073402004-01-05 09:43:42 +00001080 }
Keith Whitwella887a442005-01-10 12:30:08 +00001081
1082 if (VB->SecondaryColorPtr[1]) {
1083 COPY_4FV( VB->SecondaryColorPtr[1]->data[dst],
1084 VB->SecondaryColorPtr[1]->data[src] );
1085 }
1086
1087 if (VB->IndexPtr[1]) {
Keith Whitwell58822572004-01-05 15:24:53 +00001088 VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
1089 }
Keith Whitwell79073402004-01-05 09:43:42 +00001090
Keith Whitwellef167c62004-01-26 21:34:28 +00001091 generic_copy_pv(ctx, dst, src);
Keith Whitwell79073402004-01-05 09:43:42 +00001092}
Keith Whitwellfabb9732003-12-21 17:54:31 +00001093
1094
1095
1096
Keith Whitwellfabb9732003-12-21 17:54:31 +00001097/***********************************************************************
1098 * Build codegen functions or return generic ones:
1099 */
1100
1101
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001102static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest)
Keith Whitwellfabb9732003-12-21 17:54:31 +00001103{
Keith Whitwell79073402004-01-05 09:43:42 +00001104 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001105 struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001106 const GLuint attr_count = vtx->attr_count;
1107
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001108 vtx->emit = 0;
1109
1110 if (0)
1111 vtx->emit = _tnl_codegen_emit(ctx);
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001112
Keith Whitwellfa136222005-01-07 15:54:48 +00001113 /* Does it fit a hardwired fastpath? Help! this is growing out of
1114 * control!
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001115 */
Keith Whitwell699fc6b2005-01-05 20:56:05 +00001116 switch (attr_count) {
1117 case 2:
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001118 if (a[0].emit == insert_3f_viewport_3) {
1119 if (a[1].emit == insert_4ub_4f_bgra_4)
1120 vtx->emit = emit_viewport3_bgra4;
1121 else if (a[1].emit == insert_4ub_4f_rgba_4)
1122 vtx->emit = emit_viewport3_rgba4;
1123 }
Keith Whitwellfa136222005-01-07 15:54:48 +00001124 else if (a[0].emit == insert_3f_3 &&
1125 a[1].emit == insert_4ub_4f_rgba_4) {
1126 vtx->emit = emit_xyz3_rgba4;
1127 }
Keith Whitwell699fc6b2005-01-05 20:56:05 +00001128 break;
1129 case 3:
Keith Whitwellfa136222005-01-07 15:54:48 +00001130 if (a[2].emit == insert_2f_2) {
1131 if (a[1].emit == insert_4ub_4f_rgba_4) {
1132 if (a[0].emit == insert_4f_viewport_4)
1133 vtx->emit = emit_viewport4_rgba4_st2;
1134 else if (a[0].emit == insert_4f_4)
1135 vtx->emit = emit_xyzw4_rgba4_st2;
1136 }
1137 else if (a[1].emit == insert_4ub_4f_bgra_4 &&
1138 a[0].emit == insert_4f_viewport_4)
Keith Whitwell699fc6b2005-01-05 20:56:05 +00001139 vtx->emit = emit_viewport4_bgra4_st2;
Keith Whitwellfa136222005-01-07 15:54:48 +00001140 }
Felix Kuehlinge4499ed2005-01-08 15:51:11 +00001141 break;
Keith Whitwellfa136222005-01-07 15:54:48 +00001142 case 4:
1143 if (a[2].emit == insert_2f_2 &&
1144 a[3].emit == insert_2f_2) {
1145 if (a[1].emit == insert_4ub_4f_rgba_4) {
1146 if (a[0].emit == insert_4f_viewport_4)
1147 vtx->emit = emit_viewport4_rgba4_st2_st2;
1148 else if (a[0].emit == insert_4f_4)
1149 vtx->emit = emit_xyzw4_rgba4_st2_st2;
1150 }
1151 else if (a[1].emit == insert_4ub_4f_bgra_4 &&
1152 a[0].emit == insert_4f_viewport_4)
1153 vtx->emit = emit_viewport4_bgra4_st2_st2;
Keith Whitwell699fc6b2005-01-05 20:56:05 +00001154 }
1155 break;
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001156 }
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001157
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001158 /* Otherwise use the generic version:
1159 */
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001160 if (!vtx->emit)
1161 vtx->emit = generic_emit;
1162
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001163 vtx->emit( ctx, count, dest );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001164}
1165
1166
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001167
Keith Whitwellfabb9732003-12-21 17:54:31 +00001168static void choose_interp_func( GLcontext *ctx,
1169 GLfloat t,
1170 GLuint edst, GLuint eout, GLuint ein,
1171 GLboolean force_boundary )
1172{
Keith Whitwell79073402004-01-05 09:43:42 +00001173 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1174
1175 if (vtx->need_extras &&
1176 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
1177 vtx->interp = generic_interp_extras;
1178 } else {
1179 vtx->interp = generic_interp;
1180 }
1181
1182 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001183}
1184
1185
Keith Whitwell79073402004-01-05 09:43:42 +00001186static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001187{
Keith Whitwell79073402004-01-05 09:43:42 +00001188 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1189
1190 if (vtx->need_extras &&
1191 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
1192 vtx->copy_pv = generic_copy_pv_extras;
1193 } else {
1194 vtx->copy_pv = generic_copy_pv;
1195 }
1196
1197 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001198}
1199
1200
1201/***********************************************************************
1202 * Public entrypoints, mostly dispatch to the above:
1203 */
1204
Keith Whitwellfabb9732003-12-21 17:54:31 +00001205
1206/* Interpolate between two vertices to produce a third:
1207 */
1208void _tnl_interp( GLcontext *ctx,
1209 GLfloat t,
1210 GLuint edst, GLuint eout, GLuint ein,
1211 GLboolean force_boundary )
1212{
Keith Whitwell79073402004-01-05 09:43:42 +00001213 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1214 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001215}
1216
1217/* Copy colors from one vertex to another:
1218 */
Keith Whitwell79073402004-01-05 09:43:42 +00001219void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001220{
Keith Whitwell79073402004-01-05 09:43:42 +00001221 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1222 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001223}
1224
1225
1226/* Extract a named attribute from a hardware vertex. Will have to
1227 * reverse any viewport transformation, swizzling or other conversions
1228 * which may have been applied:
1229 */
Keith Whitwell79073402004-01-05 09:43:42 +00001230void _tnl_get_attr( GLcontext *ctx, const void *vin,
1231 GLenum attr, GLfloat *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001232{
Keith Whitwell79073402004-01-05 09:43:42 +00001233 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1234 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +00001235 const GLuint attr_count = vtx->attr_count;
1236 GLuint j;
Keith Whitwell79073402004-01-05 09:43:42 +00001237
1238 for (j = 0; j < attr_count; j++) {
Brian Paulbdd15b52004-05-04 15:11:06 +00001239 if (a[j].attrib == attr) {
Keith Whitwell44d4a8f2004-01-06 00:18:03 +00001240 a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset );
Keith Whitwell79073402004-01-05 09:43:42 +00001241 return;
1242 }
1243 }
1244
Keith Whitwellfa136222005-01-07 15:54:48 +00001245 /* Else return the value from ctx->Current.
Keith Whitwell79073402004-01-05 09:43:42 +00001246 */
Brian Paul3663c0f2004-01-15 00:29:51 +00001247 _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
Keith Whitwell79073402004-01-05 09:43:42 +00001248}
1249
Keith Whitwell47736342004-02-16 15:15:24 +00001250
1251/* Complementary operation to the above.
1252 */
1253void _tnl_set_attr( GLcontext *ctx, void *vout,
1254 GLenum attr, const GLfloat *src )
1255{
1256 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1257 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +00001258 const GLuint attr_count = vtx->attr_count;
1259 GLuint j;
Keith Whitwell47736342004-02-16 15:15:24 +00001260
1261 for (j = 0; j < attr_count; j++) {
Brian Paulbdd15b52004-05-04 15:11:06 +00001262 if (a[j].attrib == attr) {
Keith Whitwell47736342004-02-16 15:15:24 +00001263 a[j].insert[4-1]( &a[j], (GLubyte *)vout + a[j].vertoffset, src );
1264 return;
1265 }
1266 }
1267}
1268
1269
Keith Whitwell79073402004-01-05 09:43:42 +00001270void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
1271{
1272 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1273
1274 return vtx->vertex_buf + nr * vtx->vertex_size;
1275}
1276
1277void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state )
1278{
1279 if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) {
1280 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1281 vtx->new_inputs = ~0;
1282 vtx->interp = choose_interp_func;
1283 vtx->copy_pv = choose_copy_pv_func;
1284 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001285}
1286
1287
Keith Whitwell79073402004-01-05 09:43:42 +00001288GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
Keith Whitwell58822572004-01-05 15:24:53 +00001289 GLuint nr, const GLfloat *vp,
1290 GLuint unpacked_size )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001291{
Keith Whitwell79073402004-01-05 09:43:42 +00001292 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Brian Paulfde4c532004-03-13 18:27:06 +00001293 GLuint offset = 0;
Keith Whitwell4d36f332004-01-21 15:31:46 +00001294 GLuint i, j;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001295
Keith Whitwell79073402004-01-05 09:43:42 +00001296 assert(nr < _TNL_ATTRIB_MAX);
1297 assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
Keith Whitwellfabb9732003-12-21 17:54:31 +00001298
Keith Whitwellfa136222005-01-07 15:54:48 +00001299 if (vtx->emit == generic_emit)
1300 vtx->emit = choose_emit_func;
1301
Keith Whitwell79073402004-01-05 09:43:42 +00001302 vtx->interp = choose_interp_func;
1303 vtx->copy_pv = choose_copy_pv_func;
1304 vtx->new_inputs = ~0;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001305
Keith Whitwell4d36f332004-01-21 15:31:46 +00001306 for (j = 0, i = 0; i < nr; i++) {
Brian Paulfde4c532004-03-13 18:27:06 +00001307 const GLuint format = map[i].format;
Keith Whitwell4d36f332004-01-21 15:31:46 +00001308 if (format == EMIT_PAD) {
Brian Paulbbea6ec2004-07-02 14:35:50 +00001309 /*
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001310 fprintf(stderr, "%d: pad %d, offset %d\n", i,
1311 map[i].offset, offset);
Brian Paulbbea6ec2004-07-02 14:35:50 +00001312 */
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001313 offset += map[i].offset;
Keith Whitwell16f54212004-01-05 15:55:01 +00001314
Keith Whitwell4d36f332004-01-21 15:31:46 +00001315 }
1316 else {
1317 vtx->attr[j].attrib = map[i].attrib;
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001318 vtx->attr[j].format = format;
Keith Whitwell4d36f332004-01-21 15:31:46 +00001319 vtx->attr[j].vp = vp;
1320 vtx->attr[j].insert = format_info[format].insert;
1321 vtx->attr[j].extract = format_info[format].extract;
1322 vtx->attr[j].vertattrsize = format_info[format].attrsize;
Keith Whitwell44d4a8f2004-01-06 00:18:03 +00001323
Keith Whitwell4d36f332004-01-21 15:31:46 +00001324 if (unpacked_size)
1325 vtx->attr[j].vertoffset = map[i].offset;
1326 else
1327 vtx->attr[j].vertoffset = offset;
1328
Brian Paulbbea6ec2004-07-02 14:35:50 +00001329 /*
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001330 fprintf(stderr, "%d: %s, vp %p, offset %d\n", i,
1331 format_info[format].name, (void *)vp,
1332 vtx->attr[j].vertoffset);
Brian Paulbbea6ec2004-07-02 14:35:50 +00001333 */
Keith Whitwell4d36f332004-01-21 15:31:46 +00001334 offset += format_info[format].attrsize;
1335 j++;
1336 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001337 }
Keith Whitwell79073402004-01-05 09:43:42 +00001338
Keith Whitwell4d36f332004-01-21 15:31:46 +00001339 vtx->attr_count = j;
1340
Keith Whitwell58822572004-01-05 15:24:53 +00001341 if (unpacked_size)
1342 vtx->vertex_size = unpacked_size;
1343 else
1344 vtx->vertex_size = offset;
Keith Whitwell79073402004-01-05 09:43:42 +00001345
Keith Whitwell58822572004-01-05 15:24:53 +00001346 assert(vtx->vertex_size <= vtx->max_vertex_size);
1347
Keith Whitwell79073402004-01-05 09:43:42 +00001348 return vtx->vertex_size;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001349}
1350
1351
1352
Keith Whitwell79073402004-01-05 09:43:42 +00001353void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001354{
Keith Whitwell79073402004-01-05 09:43:42 +00001355 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1356 vtx->new_inputs |= newinputs;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001357}
1358
1359
Keith Whitwell79073402004-01-05 09:43:42 +00001360void _tnl_build_vertices( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001361 GLuint start,
1362 GLuint end,
1363 GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001364{
Keith Whitwell79073402004-01-05 09:43:42 +00001365 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001366
Keith Whitwell79073402004-01-05 09:43:42 +00001367 newinputs |= vtx->new_inputs;
1368 vtx->new_inputs = 0;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001369
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001370 if (newinputs) {
1371 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
1372 struct tnl_clipspace_attr *a = vtx->attr;
1373 const GLuint stride = vtx->vertex_size;
1374 const GLuint count = vtx->attr_count;
1375 GLuint j;
1376
1377 for (j = 0; j < count; j++) {
1378 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
1379 a[j].inputstride = vptr->stride;
1380 a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
1381 a[j].emit = a[j].insert[vptr->size - 1];
1382 }
1383
1384 vtx->emit( ctx, end - start,
1385 (GLubyte *)vtx->vertex_buf + start * stride );
1386 }
Keith Whitwellfabb9732003-12-21 17:54:31 +00001387}
1388
Keith Whitwellfa136222005-01-07 15:54:48 +00001389/* Emit VB vertices start..end to dest. Note that VB vertex at
1390 * postion start will be emitted to dest at position zero.
1391 */
Keith Whitwell79073402004-01-05 09:43:42 +00001392void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001393 GLuint start,
1394 GLuint end,
1395 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001396{
Keith Whitwell79073402004-01-05 09:43:42 +00001397 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +00001398 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
1399 struct tnl_clipspace_attr *a = vtx->attr;
1400 const GLuint count = vtx->attr_count;
1401 GLuint j;
1402
1403 for (j = 0; j < count; j++) {
1404 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
1405 a[j].inputstride = vptr->stride;
1406 a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
1407 a[j].emit = a[j].insert[vptr->size - 1];
1408 }
1409
1410 /* Note: dest should not be adjusted for non-zero 'start' values:
1411 */
1412 vtx->emit( ctx, end - start, dest );
1413
Keith Whitwell8d97ad12004-01-19 23:29:40 +00001414 return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001415}
1416
Keith Whitwell79073402004-01-05 09:43:42 +00001417
1418void _tnl_init_vertices( GLcontext *ctx,
1419 GLuint vb_size,
1420 GLuint max_vertex_size )
1421{
1422 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1423
Keith Whitwell58822572004-01-05 15:24:53 +00001424 _tnl_install_attrs( ctx, 0, 0, 0, 0 );
Keith Whitwell79073402004-01-05 09:43:42 +00001425
1426 vtx->need_extras = GL_TRUE;
Keith Whitwell58822572004-01-05 15:24:53 +00001427 if (max_vertex_size > vtx->max_vertex_size) {
1428 _tnl_free_vertices( ctx );
1429 vtx->max_vertex_size = max_vertex_size;
Brian Paulcb7c6892004-01-26 16:16:16 +00001430 vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 );
Keith Whitwellfa136222005-01-07 15:54:48 +00001431 vtx->emit = choose_emit_func;
Keith Whitwell58822572004-01-05 15:24:53 +00001432 }
Keith Whitwell009aa3e2004-06-30 11:48:21 +00001433
1434 _tnl_init_c_codegen( &vtx->codegen );
Keith Whitwell79073402004-01-05 09:43:42 +00001435}
1436
1437
1438void _tnl_free_vertices( GLcontext *ctx )
1439{
1440 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1441 if (vtx->vertex_buf) {
1442 ALIGN_FREE(vtx->vertex_buf);
1443 vtx->vertex_buf = 0;
1444 }
1445}