blob: c8cfb6e10657960c3dfcf0766596d6c1cf4ce00a [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 Whitwell79073402004-01-05 09:43:42 +000045#define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace)
Keith Whitwellfabb9732003-12-21 17:54:31 +000046
Keith Whitwell58822572004-01-05 15:24:53 +000047static void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +000048 const GLfloat *in )
49{
50 GLfloat *out = (GLfloat *)v;
51 const GLfloat * const vp = a->vp;
52
53 out[0] = vp[0] * in[0] + vp[12];
54 out[1] = vp[5] * in[1] + vp[13];
55 out[2] = vp[10] * in[2] + vp[14];
56 out[3] = in[3];
57}
58
Keith Whitwell58822572004-01-05 15:24:53 +000059static void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
60 const GLfloat *in )
61{
62 GLfloat *out = (GLfloat *)v;
63 const GLfloat * const vp = a->vp;
64
65 out[0] = vp[0] * in[0] + vp[12];
66 out[1] = vp[5] * in[1] + vp[13];
67 out[2] = vp[10] * in[2] + vp[14];
68 out[3] = 1;
69}
70
71static void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
72 const GLfloat *in )
73{
74 GLfloat *out = (GLfloat *)v;
75 const GLfloat * const vp = a->vp;
76
77 out[0] = vp[0] * in[0] + vp[12];
78 out[1] = vp[5] * in[1] + vp[13];
79 out[2] = vp[14];
80 out[3] = 1;
81}
82
83static void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
84 const GLfloat *in )
85{
86 GLfloat *out = (GLfloat *)v;
87 const GLfloat * const vp = a->vp;
88
89 out[0] = vp[0] * in[0] + vp[12];
90 out[1] = vp[13];
91 out[2] = vp[14];
92 out[3] = 1;
93}
94
95static void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +000096 const GLfloat *in )
97{
98 GLfloat *out = (GLfloat *)v;
99 const GLfloat * const vp = a->vp;
100
101 out[0] = vp[0] * in[0] + vp[12];
102 out[1] = vp[5] * in[1] + vp[13];
103 out[2] = vp[10] * in[2] + vp[14];
104}
105
Keith Whitwell58822572004-01-05 15:24:53 +0000106static void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
107 const GLfloat *in )
108{
109 GLfloat *out = (GLfloat *)v;
110 const GLfloat * const vp = a->vp;
111
112 out[0] = vp[0] * in[0] + vp[12];
113 out[1] = vp[5] * in[1] + vp[13];
114 out[2] = vp[10] * in[2] + vp[14];
115}
116
117static void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
118 const GLfloat *in )
119{
120 GLfloat *out = (GLfloat *)v;
121 const GLfloat * const vp = a->vp;
122
123 out[0] = vp[0] * in[0] + vp[12];
124 out[1] = vp[13];
125 out[2] = vp[14];
126}
127
128static void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000129 const GLfloat *in )
130{
131 GLfloat *out = (GLfloat *)v;
132 const GLfloat * const vp = a->vp;
133
134 out[0] = vp[0] * in[0] + vp[12];
135 out[1] = vp[5] * in[1] + vp[13];
136}
137
Keith Whitwell58822572004-01-05 15:24:53 +0000138static void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
139 const GLfloat *in )
140{
141 GLfloat *out = (GLfloat *)v;
142 const GLfloat * const vp = a->vp;
143
144 out[0] = vp[0] * in[0] + vp[12];
145 out[1] = vp[13];
146}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000147
Keith Whitwell58822572004-01-05 15:24:53 +0000148
149static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000150{
151 GLfloat *out = (GLfloat *)(v);
152
153 out[0] = in[0];
154 out[1] = in[1];
155 out[2] = in[2];
156 out[3] = in[3];
157}
158
Keith Whitwell58822572004-01-05 15:24:53 +0000159static void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000160{
161 GLfloat *out = (GLfloat *)(v);
162
163 out[0] = in[0];
164 out[1] = in[1];
165 out[2] = in[2];
166 out[3] = 1;
167}
168
Keith Whitwell58822572004-01-05 15:24:53 +0000169static void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000170{
171 GLfloat *out = (GLfloat *)(v);
172
173 out[0] = in[0];
174 out[1] = in[1];
175 out[2] = 0;
176 out[3] = 1;
177}
178
Keith Whitwell58822572004-01-05 15:24:53 +0000179static void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
Keith Whitwell79073402004-01-05 09:43:42 +0000180{
181 GLfloat *out = (GLfloat *)(v);
182
183 out[0] = in[0];
184 out[1] = 0;
185 out[2] = 0;
186 out[3] = 1;
187}
188
Keith Whitwell58822572004-01-05 15:24:53 +0000189static void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
190{
191 GLfloat *out = (GLfloat *)(v);
192
193 out[0] = in[0];
194 out[1] = in[1];
195 out[2] = in[3];
196}
197
198static void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
199{
200 abort();
201}
202
203static void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
204{
205 GLfloat *out = (GLfloat *)(v);
206
207 out[0] = in[0];
208 out[1] = in[1];
209 out[2] = in[2];
210}
211
212static void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
213{
214 GLfloat *out = (GLfloat *)(v);
215
216 out[0] = in[0];
217 out[1] = in[1];
218 out[2] = 0;
219}
220
221static void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
222{
223 GLfloat *out = (GLfloat *)(v);
224
225 out[0] = in[0];
226 out[1] = 0;
227 out[2] = 0;
228}
229
230
231static void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
232{
233 GLfloat *out = (GLfloat *)(v);
234
235 out[0] = in[0];
236 out[1] = in[1];
237}
238
239static void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
240{
241 GLfloat *out = (GLfloat *)(v);
242
243 out[0] = in[0];
244 out[1] = 0;
245}
246
247static void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
248{
249 GLfloat *out = (GLfloat *)(v);
250
251 out[0] = in[0];
252}
253
254static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwell79073402004-01-05 09:43:42 +0000255 const GLfloat *in )
256{
257 GLchan *c = (GLchan *)v;
258 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
259 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
260 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
261 UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]);
262}
263
Keith Whitwell58822572004-01-05 15:24:53 +0000264static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
265 const GLfloat *in )
266{
267 GLchan *c = (GLchan *)v;
268 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
269 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
270 UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
271 c[3] = CHAN_MAX;
272}
273
274static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
275 const GLfloat *in )
276{
277 GLchan *c = (GLchan *)v;
278 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
279 UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
280 c[2] = 0;
281 c[3] = CHAN_MAX;
282}
283
284static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
285 const GLfloat *in )
286{
287 GLchan *c = (GLchan *)v;
288 UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
289 c[1] = 0;
290 c[2] = 0;
291 c[3] = CHAN_MAX;
292}
293
294static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000295 const GLfloat *in )
296{
297 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
298 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
299 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
300 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
301}
302
Keith Whitwell58822572004-01-05 15:24:53 +0000303static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
304 const GLfloat *in )
305{
306 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
307 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
308 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
309 v[3] = 0xff;
310}
311
312static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
313 const GLfloat *in )
314{
315 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
316 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
317 v[2] = 0;
318 v[3] = 0xff;
319}
320
321static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
322 const GLfloat *in )
323{
324 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
325 v[1] = 0;
326 v[2] = 0;
327 v[3] = 0xff;
328}
329
330static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000331 const GLfloat *in )
332{
333 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
334 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
335 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
336 UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
337}
338
Keith Whitwell58822572004-01-05 15:24:53 +0000339static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v,
340 const GLfloat *in )
341{
342 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
343 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
344 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
345 v[3] = 0xff;
346}
347
348static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v,
349 const GLfloat *in )
350{
351 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
352 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
353 v[0] = 0;
354 v[3] = 0xff;
355}
356
357static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v,
358 const GLfloat *in )
359{
360 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
361 v[1] = 0;
362 v[0] = 0;
363 v[3] = 0xff;
364}
365
366static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000367 const GLfloat *in )
368{
369 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
370 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
371 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
372}
373
Keith Whitwell58822572004-01-05 15:24:53 +0000374static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000375 const GLfloat *in )
376{
Keith Whitwell58822572004-01-05 15:24:53 +0000377 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
378 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
379 v[2] = 0;
380}
381
382static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
383 const GLfloat *in )
384{
385 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
386 v[1] = 0;
387 v[2] = 0;
388}
389
390static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
391 const GLfloat *in )
392{
Keith Whitwellfabb9732003-12-21 17:54:31 +0000393 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
394 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
395 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
396}
397
Keith Whitwell58822572004-01-05 15:24:53 +0000398static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
399 const GLfloat *in )
400{
401 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
402 UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
403 v[0] = 0;
404}
405
406static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
407 const GLfloat *in )
408{
409 UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
410 v[1] = 0;
411 v[0]= 0;
412}
413
414
415static void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v,
Keith Whitwellfabb9732003-12-21 17:54:31 +0000416 const GLfloat *in )
417{
418 UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
419}
420
421
422/***********************************************************************
423 * Functions to perform the reverse operations to the above, for
424 * swrast translation and clip-interpolation.
425 *
426 * Currently always extracts a full 4 floats.
427 */
428
Keith Whitwell79073402004-01-05 09:43:42 +0000429static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000430 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000431{
432 const GLfloat *in = (const GLfloat *)v;
433 const GLfloat * const vp = a->vp;
434
435 out[0] = (in[0] - vp[12]) / vp[0];
436 out[1] = (in[1] - vp[13]) / vp[5];
437 out[2] = (in[2] - vp[14]) / vp[10];
438 out[3] = in[3];
439}
440
Keith Whitwell79073402004-01-05 09:43:42 +0000441static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000442 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000443{
444 const GLfloat *in = (const GLfloat *)v;
445 const GLfloat * const vp = a->vp;
446
447 out[0] = (in[0] - vp[12]) / vp[0];
448 out[1] = (in[1] - vp[13]) / vp[5];
449 out[2] = (in[2] - vp[14]) / vp[10];
450 out[3] = 1;
451}
452
453
Keith Whitwell79073402004-01-05 09:43:42 +0000454static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000455 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000456{
457 const GLfloat *in = (const GLfloat *)v;
458 const GLfloat * const vp = a->vp;
459
460 out[0] = (in[0] - vp[12]) / vp[0];
461 out[1] = (in[1] - vp[13]) / vp[5];
462 out[2] = 0;
463 out[3] = 1;
464}
465
466
Keith Whitwell58822572004-01-05 15:24:53 +0000467static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000468{
469 const GLfloat *in = (const GLfloat *)v;
470
471 out[0] = in[0];
472 out[1] = in[1];
473 out[2] = in[2];
474 out[3] = in[3];
475}
476
Keith Whitwell58822572004-01-05 15:24:53 +0000477static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000478{
479 const GLfloat *in = (const GLfloat *)v;
480
481 out[0] = in[0];
482 out[1] = in[1];
483 out[2] = in[3];
484 out[3] = 1;
485}
486
487
Keith Whitwell58822572004-01-05 15:24:53 +0000488static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000489{
490 const GLfloat *in = (const GLfloat *)v;
491
492 out[0] = in[0];
493 out[1] = in[1];
494 out[2] = in[2];
495 out[3] = 1;
496}
497
498
Keith Whitwell58822572004-01-05 15:24:53 +0000499static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000500{
501 const GLfloat *in = (const GLfloat *)v;
502
503 out[0] = in[0];
504 out[1] = in[1];
505 out[2] = 0;
506 out[3] = 1;
507}
508
Keith Whitwell58822572004-01-05 15:24:53 +0000509static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000510{
511 const GLfloat *in = (const GLfloat *)v;
512
513 out[0] = in[0];
514 out[1] = 0;
515 out[2] = 0;
516 out[3] = 1;
517}
518
Keith Whitwell79073402004-01-05 09:43:42 +0000519static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000520 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000521{
Keith Whitwell79073402004-01-05 09:43:42 +0000522 GLchan *c = (GLchan *)v;
523
524 out[0] = CHAN_TO_FLOAT(c[0]);
525 out[1] = CHAN_TO_FLOAT(c[1]);
526 out[2] = CHAN_TO_FLOAT(c[2]);
527 out[3] = CHAN_TO_FLOAT(c[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000528}
529
Keith Whitwell79073402004-01-05 09:43:42 +0000530static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000531 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000532{
Keith Whitwell79073402004-01-05 09:43:42 +0000533 out[0] = UBYTE_TO_FLOAT(v[0]);
534 out[1] = UBYTE_TO_FLOAT(v[1]);
535 out[2] = UBYTE_TO_FLOAT(v[2]);
536 out[3] = UBYTE_TO_FLOAT(v[3]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000537}
538
Keith Whitwell79073402004-01-05 09:43:42 +0000539static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000540 const GLubyte *v )
Keith Whitwell79073402004-01-05 09:43:42 +0000541{
542 out[2] = UBYTE_TO_FLOAT(v[0]);
543 out[1] = UBYTE_TO_FLOAT(v[1]);
544 out[0] = UBYTE_TO_FLOAT(v[2]);
545 out[3] = UBYTE_TO_FLOAT(v[3]);
546}
547
548static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000549 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000550{
Keith Whitwell79073402004-01-05 09:43:42 +0000551 out[0] = UBYTE_TO_FLOAT(v[0]);
552 out[1] = UBYTE_TO_FLOAT(v[1]);
553 out[2] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000554 out[3] = 1;
555}
556
Keith Whitwell79073402004-01-05 09:43:42 +0000557static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out,
Keith Whitwell58822572004-01-05 15:24:53 +0000558 const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000559{
Keith Whitwell79073402004-01-05 09:43:42 +0000560 out[2] = UBYTE_TO_FLOAT(v[0]);
561 out[1] = UBYTE_TO_FLOAT(v[1]);
562 out[0] = UBYTE_TO_FLOAT(v[2]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000563 out[3] = 1;
564}
565
Keith Whitwell58822572004-01-05 15:24:53 +0000566static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000567{
Keith Whitwell79073402004-01-05 09:43:42 +0000568 out[0] = UBYTE_TO_FLOAT(v[0]);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000569 out[1] = 0;
570 out[2] = 0;
571 out[3] = 1;
572}
573
Keith Whitwell79073402004-01-05 09:43:42 +0000574
Keith Whitwell79073402004-01-05 09:43:42 +0000575struct {
Keith Whitwell58822572004-01-05 15:24:53 +0000576 const char *name;
Keith Whitwell79073402004-01-05 09:43:42 +0000577 extract_func extract;
Keith Whitwell58822572004-01-05 15:24:53 +0000578 insert_func insert[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000579 GLuint attrsize;
580} format_info[EMIT_MAX] = {
581
Keith Whitwell58822572004-01-05 15:24:53 +0000582 { "1f",
583 extract_1f,
584 { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000585 sizeof(GLfloat) },
586
Keith Whitwell58822572004-01-05 15:24:53 +0000587 { "2f",
588 extract_2f,
589 { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000590 2 * sizeof(GLfloat) },
591
Keith Whitwell58822572004-01-05 15:24:53 +0000592 { "3f",
593 extract_3f,
594 { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000595 3 * sizeof(GLfloat) },
596
Keith Whitwell58822572004-01-05 15:24:53 +0000597 { "4f",
598 extract_4f,
599 { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000600 4 * sizeof(GLfloat) },
601
Keith Whitwell58822572004-01-05 15:24:53 +0000602 { "2f_viewport",
603 extract_2f_viewport,
604 { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2,
605 insert_2f_viewport_2 },
Keith Whitwell79073402004-01-05 09:43:42 +0000606 2 * sizeof(GLfloat) },
607
Keith Whitwell58822572004-01-05 15:24:53 +0000608 { "3f_viewport",
609 extract_3f_viewport,
610 { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3,
611 insert_3f_viewport_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000612 3 * sizeof(GLfloat) },
613
Keith Whitwell58822572004-01-05 15:24:53 +0000614 { "4f_viewport",
615 extract_4f_viewport,
616 { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3,
617 insert_4f_viewport_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000618 4 * sizeof(GLfloat) },
619
Keith Whitwell58822572004-01-05 15:24:53 +0000620 { "3f_xyw",
621 extract_3f_xyw,
622 { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err,
623 insert_3f_xyw_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000624 3 * sizeof(GLfloat) },
625
Keith Whitwell58822572004-01-05 15:24:53 +0000626 { "1ub_1f",
627 extract_1ub_1f,
628 { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 },
Keith Whitwell79073402004-01-05 09:43:42 +0000629 sizeof(GLubyte) },
630
Keith Whitwell58822572004-01-05 15:24:53 +0000631 { "3ub_3f_rgb",
632 extract_3ub_3f_rgb,
633 { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3,
634 insert_3ub_3f_rgb_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000635 3 * sizeof(GLubyte) },
636
Keith Whitwell58822572004-01-05 15:24:53 +0000637 { "3ub_3f_bgr",
638 extract_3ub_3f_bgr,
639 { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3,
640 insert_3ub_3f_bgr_3 },
Keith Whitwell79073402004-01-05 09:43:42 +0000641 3 * sizeof(GLubyte) },
642
Keith Whitwell58822572004-01-05 15:24:53 +0000643 { "4ub_4f_rgba",
644 extract_4ub_4f_rgba,
645 { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3,
646 insert_4ub_4f_rgba_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000647 4 * sizeof(GLubyte) },
648
Keith Whitwell58822572004-01-05 15:24:53 +0000649 { "4ub_4f_bgra",
650 extract_4ub_4f_bgra,
651 { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3,
652 insert_4ub_4f_bgra_4 },
Keith Whitwell79073402004-01-05 09:43:42 +0000653 4 * sizeof(GLubyte) },
654
Keith Whitwell58822572004-01-05 15:24:53 +0000655 { "4chan_4f_rgba",
656 extract_4chan_4f_rgba,
657 { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
658 insert_4chan_4f_rgba_4 },
659 4 * sizeof(GLchan) }
Keith Whitwell79073402004-01-05 09:43:42 +0000660
661};
662
663
Keith Whitwellfabb9732003-12-21 17:54:31 +0000664/***********************************************************************
665 * Generic (non-codegen) functions for whole vertices or groups of
666 * vertices
667 */
668
669static void generic_emit( GLcontext *ctx,
670 GLuint start, GLuint end,
Keith Whitwell79073402004-01-05 09:43:42 +0000671 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000672{
Keith Whitwell79073402004-01-05 09:43:42 +0000673 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
674 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
675 struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwell58822572004-01-05 15:24:53 +0000676 GLubyte *v = (GLubyte *)dest;
Keith Whitwell79073402004-01-05 09:43:42 +0000677 int i, j;
678 GLuint count = vtx->attr_count;
679 GLuint stride;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000680
Keith Whitwell79073402004-01-05 09:43:42 +0000681 for (j = 0; j < count; j++) {
682 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
683 a[j].inputstride = vptr->stride;
Keith Whitwell58822572004-01-05 15:24:53 +0000684 a[j].inputptr = (GLubyte *)STRIDE_4F(vptr->data, start * vptr->stride);
685 a[j].emit = a[j].insert[vptr->size - 1];
Keith Whitwellfabb9732003-12-21 17:54:31 +0000686 }
687
Keith Whitwell79073402004-01-05 09:43:42 +0000688 end -= start;
689 stride = vtx->vertex_size;
690
Keith Whitwellfabb9732003-12-21 17:54:31 +0000691 for (i = 0 ; i < end ; i++, v += stride) {
Keith Whitwell79073402004-01-05 09:43:42 +0000692 for (j = 0; j < count; j++) {
Keith Whitwell58822572004-01-05 15:24:53 +0000693 GLfloat *in = (GLfloat *)a[j].inputptr;
694 a[j].inputptr += a[j].inputstride;
695 a[j].emit( &a[j], v + a[j].vertoffset, in );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000696 }
697 }
698}
699
700
701static void generic_interp( GLcontext *ctx,
702 GLfloat t,
703 GLuint edst, GLuint eout, GLuint ein,
704 GLboolean force_boundary )
705{
Keith Whitwell79073402004-01-05 09:43:42 +0000706 TNLcontext *tnl = TNL_CONTEXT(ctx);
707 struct vertex_buffer *VB = &tnl->vb;
708 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell58822572004-01-05 15:24:53 +0000709 GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
710 GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
711 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000712 const struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000713 int attr_count = vtx->attr_count;
714 int j;
Keith Whitwell79073402004-01-05 09:43:42 +0000715
716 if (tnl->NeedNdcCoords) {
717 const GLfloat *dstclip = VB->ClipPtr->data[edst];
718 const GLfloat w = 1.0 / dstclip[3];
719 GLfloat pos[4];
720
721 pos[0] = dstclip[0] * w;
722 pos[1] = dstclip[1] * w;
723 pos[2] = dstclip[2] * w;
724 pos[3] = w;
725
Keith Whitwell58822572004-01-05 15:24:53 +0000726 a[0].insert[4-1]( &a[0], vdst, pos );
Keith Whitwell79073402004-01-05 09:43:42 +0000727 }
728 else {
Keith Whitwell58822572004-01-05 15:24:53 +0000729 a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
Keith Whitwell79073402004-01-05 09:43:42 +0000730 }
731
732
733 for (j = 1; j < attr_count; j++) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000734 GLfloat fin[4], fout[4], fdst[4];
Keith Whitwell79073402004-01-05 09:43:42 +0000735
736 a[j].extract( &a[j], fin, vin + a[j].vertoffset );
737 a[j].extract( &a[j], fout, vout + a[j].vertoffset );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000738
739 INTERP_F( t, fdst[3], fout[3], fin[3] );
740 INTERP_F( t, fdst[2], fout[2], fin[2] );
741 INTERP_F( t, fdst[1], fout[1], fin[1] );
742 INTERP_F( t, fdst[0], fout[0], fin[0] );
743
Keith Whitwell58822572004-01-05 15:24:53 +0000744 a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000745 }
746}
747
748
749/* Extract color attributes from one vertex and insert them into
750 * another. (Shortcircuit extract/insert with memcpy).
751 */
Keith Whitwell79073402004-01-05 09:43:42 +0000752static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000753{
Keith Whitwell79073402004-01-05 09:43:42 +0000754 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell58822572004-01-05 15:24:53 +0000755 GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
756 GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
Keith Whitwell79073402004-01-05 09:43:42 +0000757 const struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000758 int attr_count = vtx->attr_count;
759 int j;
760
761 for (j = 0; j < attr_count; j++) {
Keith Whitwell79073402004-01-05 09:43:42 +0000762 if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
763 a[j].attrib == VERT_ATTRIB_COLOR1) {
Keith Whitwellfabb9732003-12-21 17:54:31 +0000764
765 memcpy( vdst + a[j].vertoffset,
766 vsrc + a[j].vertoffset,
767 a[j].vertattrsize );
Keith Whitwell79073402004-01-05 09:43:42 +0000768 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000769 }
770}
771
Keith Whitwellfabb9732003-12-21 17:54:31 +0000772
Keith Whitwell79073402004-01-05 09:43:42 +0000773/* Helper functions for hardware which doesn't put back colors and/or
774 * edgeflags into vertices.
775 */
776static void generic_interp_extras( GLcontext *ctx,
777 GLfloat t,
778 GLuint dst, GLuint out, GLuint in,
779 GLboolean force_boundary )
780{
781 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
782
783 if (VB->ColorPtr[1]) {
784 assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
785
786 INTERP_4F( t,
787 VB->ColorPtr[1]->data[dst],
788 VB->ColorPtr[1]->data[out],
789 VB->ColorPtr[1]->data[in] );
790
791 if (VB->SecondaryColorPtr[1]) {
792 INTERP_3F( t,
793 VB->SecondaryColorPtr[1]->data[dst],
794 VB->SecondaryColorPtr[1]->data[out],
795 VB->SecondaryColorPtr[1]->data[in] );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000796 }
797 }
Keith Whitwell58822572004-01-05 15:24:53 +0000798 else if (VB->IndexPtr[1]) {
799 VB->IndexPtr[1]->data[dst][0] = LINTERP( t,
800 VB->IndexPtr[1]->data[out][0],
801 VB->IndexPtr[1]->data[in][0] );
802 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000803
Keith Whitwell79073402004-01-05 09:43:42 +0000804 if (VB->EdgeFlag) {
805 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
806 }
807
808 generic_interp(ctx, t, dst, out, in, force_boundary);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000809}
810
Keith Whitwell79073402004-01-05 09:43:42 +0000811static void generic_copy_pv_extras( GLcontext *ctx,
812 GLuint dst, GLuint src )
813{
814 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
815
816 if (VB->ColorPtr[1]) {
817 COPY_4FV( VB->ColorPtr[1]->data[dst],
818 VB->ColorPtr[1]->data[src] );
819
820 if (VB->SecondaryColorPtr[1]) {
821 COPY_4FV( VB->SecondaryColorPtr[1]->data[dst],
822 VB->SecondaryColorPtr[1]->data[src] );
823 }
824 }
Keith Whitwell58822572004-01-05 15:24:53 +0000825 else if (VB->IndexPtr[1]) {
826 VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
827 }
Keith Whitwell79073402004-01-05 09:43:42 +0000828
829 _tnl_copy_pv(ctx, dst, src);
830}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000831
832
833
834
835
836
837/***********************************************************************
838 * Build codegen functions or return generic ones:
839 */
840
841
842static void choose_emit_func( 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 tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
847 vtx->emit = generic_emit;
848 vtx->emit( ctx, start, end, dest );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000849}
850
851
852static void choose_interp_func( GLcontext *ctx,
853 GLfloat t,
854 GLuint edst, GLuint eout, GLuint ein,
855 GLboolean force_boundary )
856{
Keith Whitwell79073402004-01-05 09:43:42 +0000857 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
858
859 if (vtx->need_extras &&
860 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
861 vtx->interp = generic_interp_extras;
862 } else {
863 vtx->interp = generic_interp;
864 }
865
866 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000867}
868
869
Keith Whitwell79073402004-01-05 09:43:42 +0000870static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000871{
Keith Whitwell79073402004-01-05 09:43:42 +0000872 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
873
874 if (vtx->need_extras &&
875 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
876 vtx->copy_pv = generic_copy_pv_extras;
877 } else {
878 vtx->copy_pv = generic_copy_pv;
879 }
880
881 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000882}
883
884
885/***********************************************************************
886 * Public entrypoints, mostly dispatch to the above:
887 */
888
Keith Whitwellfabb9732003-12-21 17:54:31 +0000889
890/* Interpolate between two vertices to produce a third:
891 */
892void _tnl_interp( GLcontext *ctx,
893 GLfloat t,
894 GLuint edst, GLuint eout, GLuint ein,
895 GLboolean force_boundary )
896{
Keith Whitwell79073402004-01-05 09:43:42 +0000897 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
898 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000899}
900
901/* Copy colors from one vertex to another:
902 */
Keith Whitwell79073402004-01-05 09:43:42 +0000903void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000904{
Keith Whitwell79073402004-01-05 09:43:42 +0000905 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
906 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000907}
908
909
910/* Extract a named attribute from a hardware vertex. Will have to
911 * reverse any viewport transformation, swizzling or other conversions
912 * which may have been applied:
913 */
Keith Whitwell79073402004-01-05 09:43:42 +0000914void _tnl_get_attr( GLcontext *ctx, const void *vin,
915 GLenum attr, GLfloat *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000916{
Keith Whitwell79073402004-01-05 09:43:42 +0000917 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
918 const struct tnl_clipspace_attr *a = vtx->attr;
919 int attr_count = vtx->attr_count;
920 int j;
921
922 for (j = 0; j < attr_count; j++) {
923 if (a[j].attrib == attr) {
924 a[j].extract( &a[j], dest, vin );
925 return;
926 }
927 }
928
929 /* Else return the value from ctx->Current
930 */
931 memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
932}
933
934void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
935{
936 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
937
938 return vtx->vertex_buf + nr * vtx->vertex_size;
939}
940
941void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state )
942{
943 if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) {
944 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
945 vtx->new_inputs = ~0;
946 vtx->interp = choose_interp_func;
947 vtx->copy_pv = choose_copy_pv_func;
948 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000949}
950
951
Keith Whitwell79073402004-01-05 09:43:42 +0000952GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
Keith Whitwell58822572004-01-05 15:24:53 +0000953 GLuint nr, const GLfloat *vp,
954 GLuint unpacked_size )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000955{
Keith Whitwell79073402004-01-05 09:43:42 +0000956 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
957 int offset = 0;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000958 int i;
959
Keith Whitwell79073402004-01-05 09:43:42 +0000960 assert(nr < _TNL_ATTRIB_MAX);
961 assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000962
963 vtx->attr_count = nr;
Keith Whitwell79073402004-01-05 09:43:42 +0000964 vtx->emit = choose_emit_func;
965 vtx->interp = choose_interp_func;
966 vtx->copy_pv = choose_copy_pv_func;
967 vtx->new_inputs = ~0;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000968
969 for (i = 0; i < nr; i++) {
Keith Whitwell79073402004-01-05 09:43:42 +0000970 GLuint format = map[i].format;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000971 vtx->attr[i].attrib = map[i].attrib;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000972 vtx->attr[i].vp = vp;
Keith Whitwell79073402004-01-05 09:43:42 +0000973 vtx->attr[i].insert = format_info[format].insert;
974 vtx->attr[i].extract = format_info[format].extract;
975 vtx->attr[i].vertattrsize = format_info[format].attrsize;
Keith Whitwell16f54212004-01-05 15:55:01 +0000976
977 if (unpacked_size)
Keith Whitwell58822572004-01-05 15:24:53 +0000978 vtx->attr[i].vertoffset = map[i].offset;
Keith Whitwell16f54212004-01-05 15:55:01 +0000979 else
980 vtx->attr[i].vertoffset = offset;
981
982 offset += format_info[format].attrsize;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000983 }
Keith Whitwell79073402004-01-05 09:43:42 +0000984
Keith Whitwell58822572004-01-05 15:24:53 +0000985 if (unpacked_size)
986 vtx->vertex_size = unpacked_size;
987 else
988 vtx->vertex_size = offset;
Keith Whitwell79073402004-01-05 09:43:42 +0000989
Keith Whitwell58822572004-01-05 15:24:53 +0000990 assert(vtx->vertex_size <= vtx->max_vertex_size);
991
Keith Whitwell79073402004-01-05 09:43:42 +0000992 return vtx->vertex_size;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000993}
994
995
996
Keith Whitwell79073402004-01-05 09:43:42 +0000997void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000998{
Keith Whitwell79073402004-01-05 09:43:42 +0000999 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1000 vtx->new_inputs |= newinputs;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001001}
1002
1003
Keith Whitwell79073402004-01-05 09:43:42 +00001004
1005void _tnl_build_vertices( GLcontext *ctx,
1006 GLuint start,
1007 GLuint count,
1008 GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001009{
Keith Whitwell79073402004-01-05 09:43:42 +00001010 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1011 GLuint stride = vtx->vertex_size;
1012 GLubyte *v = ((GLubyte *)vtx->vertex_buf + (start*stride));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001013
Keith Whitwell79073402004-01-05 09:43:42 +00001014 newinputs |= vtx->new_inputs;
1015 vtx->new_inputs = 0;
Keith Whitwellfabb9732003-12-21 17:54:31 +00001016
Keith Whitwell79073402004-01-05 09:43:42 +00001017 if (newinputs)
1018 vtx->emit( ctx, start, count, v );
Keith Whitwellfabb9732003-12-21 17:54:31 +00001019}
1020
Keith Whitwell79073402004-01-05 09:43:42 +00001021
1022void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
1023 GLuint start,
1024 GLuint count,
1025 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +00001026{
Keith Whitwell79073402004-01-05 09:43:42 +00001027 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1028 vtx->emit( ctx, start, count, dest );
Keith Whitwell58822572004-01-05 15:24:53 +00001029 return (void *)((GLubyte *)dest + vtx->vertex_size * (count - start));
Keith Whitwellfabb9732003-12-21 17:54:31 +00001030}
1031
Keith Whitwell79073402004-01-05 09:43:42 +00001032
1033void _tnl_init_vertices( GLcontext *ctx,
1034 GLuint vb_size,
1035 GLuint max_vertex_size )
1036{
1037 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1038
Keith Whitwell58822572004-01-05 15:24:53 +00001039 _tnl_install_attrs( ctx, 0, 0, 0, 0 );
Keith Whitwell79073402004-01-05 09:43:42 +00001040
1041 vtx->need_extras = GL_TRUE;
Keith Whitwell58822572004-01-05 15:24:53 +00001042 if (max_vertex_size > vtx->max_vertex_size) {
1043 _tnl_free_vertices( ctx );
1044 vtx->max_vertex_size = max_vertex_size;
1045 vtx->vertex_buf = (GLubyte *)ALIGN_MALLOC(vb_size * max_vertex_size, 32 );
1046 }
Keith Whitwell79073402004-01-05 09:43:42 +00001047}
1048
1049
1050void _tnl_free_vertices( GLcontext *ctx )
1051{
1052 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
1053 if (vtx->vertex_buf) {
1054 ALIGN_FREE(vtx->vertex_buf);
1055 vtx->vertex_buf = 0;
1056 }
1057}