Merge branch '7.8'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_tri.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Binning code for triangles
30 */
31
32 #include "util/u_math.h"
33 #include "util/u_memory.h"
34 #include "lp_perf.h"
35 #include "lp_setup_context.h"
36 #include "lp_rast.h"
37
38 #define NUM_CHANNELS 4
39
40
41 /**
42 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
43 */
44 static void constant_coef( struct lp_setup_context *setup,
45 struct lp_rast_triangle *tri,
46 unsigned slot,
47 const float value,
48 unsigned i )
49 {
50 tri->inputs.a0[slot][i] = value;
51 tri->inputs.dadx[slot][i] = 0.0f;
52 tri->inputs.dady[slot][i] = 0.0f;
53 }
54
55
56 /**
57 * Compute a0, dadx and dady for a linearly interpolated coefficient,
58 * for a triangle.
59 */
60 static void linear_coef( struct lp_setup_context *setup,
61 struct lp_rast_triangle *tri,
62 float oneoverarea,
63 unsigned slot,
64 const float (*v1)[4],
65 const float (*v2)[4],
66 const float (*v3)[4],
67 unsigned vert_attr,
68 unsigned i)
69 {
70 float a1 = v1[vert_attr][i];
71 float a2 = v2[vert_attr][i];
72 float a3 = v3[vert_attr][i];
73
74 float da12 = a1 - a2;
75 float da31 = a3 - a1;
76 float dadx = (da12 * tri->dy31 - tri->dy12 * da31) * oneoverarea;
77 float dady = (da31 * tri->dx12 - tri->dx31 * da12) * oneoverarea;
78
79 tri->inputs.dadx[slot][i] = dadx;
80 tri->inputs.dady[slot][i] = dady;
81
82 /* calculate a0 as the value which would be sampled for the
83 * fragment at (0,0), taking into account that we want to sample at
84 * pixel centers, in other words (0.5, 0.5).
85 *
86 * this is neat but unfortunately not a good way to do things for
87 * triangles with very large values of dadx or dady as it will
88 * result in the subtraction and re-addition from a0 of a very
89 * large number, which means we'll end up loosing a lot of the
90 * fractional bits and precision from a0. the way to fix this is
91 * to define a0 as the sample at a pixel center somewhere near vmin
92 * instead - i'll switch to this later.
93 */
94 tri->inputs.a0[slot][i] = (a1 -
95 (dadx * (v1[0][0] - setup->pixel_offset) +
96 dady * (v1[0][1] - setup->pixel_offset)));
97 }
98
99
100 /**
101 * Compute a0, dadx and dady for a perspective-corrected interpolant,
102 * for a triangle.
103 * We basically multiply the vertex value by 1/w before computing
104 * the plane coefficients (a0, dadx, dady).
105 * Later, when we compute the value at a particular fragment position we'll
106 * divide the interpolated value by the interpolated W at that fragment.
107 */
108 static void perspective_coef( struct lp_setup_context *setup,
109 struct lp_rast_triangle *tri,
110 float oneoverarea,
111 unsigned slot,
112 const float (*v1)[4],
113 const float (*v2)[4],
114 const float (*v3)[4],
115 unsigned vert_attr,
116 unsigned i)
117 {
118 /* premultiply by 1/w (v[0][3] is always 1/w):
119 */
120 float a1 = v1[vert_attr][i] * v1[0][3];
121 float a2 = v2[vert_attr][i] * v2[0][3];
122 float a3 = v3[vert_attr][i] * v3[0][3];
123 float da12 = a1 - a2;
124 float da31 = a3 - a1;
125 float dadx = (da12 * tri->dy31 - tri->dy12 * da31) * oneoverarea;
126 float dady = (da31 * tri->dx12 - tri->dx31 * da12) * oneoverarea;
127
128 tri->inputs.dadx[slot][i] = dadx;
129 tri->inputs.dady[slot][i] = dady;
130 tri->inputs.a0[slot][i] = (a1 -
131 (dadx * (v1[0][0] - setup->pixel_offset) +
132 dady * (v1[0][1] - setup->pixel_offset)));
133 }
134
135
136 /**
137 * Special coefficient setup for gl_FragCoord.
138 * X and Y are trivial
139 * Z and W are copied from position_coef which should have already been computed.
140 * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
141 */
142 static void
143 setup_fragcoord_coef(struct lp_setup_context *setup,
144 struct lp_rast_triangle *tri,
145 float oneoverarea,
146 unsigned slot,
147 const float (*v1)[4],
148 const float (*v2)[4],
149 const float (*v3)[4])
150 {
151 /*X*/
152 tri->inputs.a0[slot][0] = 0.0;
153 tri->inputs.dadx[slot][0] = 1.0;
154 tri->inputs.dady[slot][0] = 0.0;
155 /*Y*/
156 tri->inputs.a0[slot][1] = 0.0;
157 tri->inputs.dadx[slot][1] = 0.0;
158 tri->inputs.dady[slot][1] = 1.0;
159 /*Z*/
160 linear_coef(setup, tri, oneoverarea, slot, v1, v2, v3, 0, 2);
161 /*W*/
162 linear_coef(setup, tri, oneoverarea, slot, v1, v2, v3, 0, 3);
163 }
164
165
166 static void setup_facing_coef( struct lp_setup_context *setup,
167 struct lp_rast_triangle *tri,
168 unsigned slot,
169 boolean frontface )
170 {
171 constant_coef( setup, tri, slot, 1.0f - frontface, 0 );
172 constant_coef( setup, tri, slot, 0.0f, 1 ); /* wasted */
173 constant_coef( setup, tri, slot, 0.0f, 2 ); /* wasted */
174 constant_coef( setup, tri, slot, 0.0f, 3 ); /* wasted */
175 }
176
177
178 /**
179 * Compute the tri->coef[] array dadx, dady, a0 values.
180 */
181 static void setup_tri_coefficients( struct lp_setup_context *setup,
182 struct lp_rast_triangle *tri,
183 float oneoverarea,
184 const float (*v1)[4],
185 const float (*v2)[4],
186 const float (*v3)[4],
187 boolean frontface)
188 {
189 unsigned slot;
190
191 /* The internal position input is in slot zero:
192 */
193 setup_fragcoord_coef(setup, tri, oneoverarea, 0, v1, v2, v3);
194
195 /* setup interpolation for all the remaining attributes:
196 */
197 for (slot = 0; slot < setup->fs.nr_inputs; slot++) {
198 unsigned vert_attr = setup->fs.input[slot].src_index;
199 unsigned i;
200
201 switch (setup->fs.input[slot].interp) {
202 case LP_INTERP_CONSTANT:
203 for (i = 0; i < NUM_CHANNELS; i++)
204 constant_coef(setup, tri, slot+1, v3[vert_attr][i], i);
205 break;
206
207 case LP_INTERP_LINEAR:
208 for (i = 0; i < NUM_CHANNELS; i++)
209 linear_coef(setup, tri, oneoverarea, slot+1, v1, v2, v3, vert_attr, i);
210 break;
211
212 case LP_INTERP_PERSPECTIVE:
213 for (i = 0; i < NUM_CHANNELS; i++)
214 perspective_coef(setup, tri, oneoverarea, slot+1, v1, v2, v3, vert_attr, i);
215 break;
216
217 case LP_INTERP_POSITION:
218 /* XXX: fix me - duplicates the values in slot zero.
219 */
220 setup_fragcoord_coef(setup, tri, oneoverarea, slot+1, v1, v2, v3);
221 break;
222
223 case LP_INTERP_FACING:
224 setup_facing_coef(setup, tri, slot+1, frontface);
225 break;
226
227 default:
228 assert(0);
229 }
230 }
231 }
232
233
234
235 static INLINE int subpixel_snap( float a )
236 {
237 return util_iround(FIXED_ONE * a - (FIXED_ONE / 2));
238 }
239
240
241
242 /**
243 * Alloc space for a new triangle plus the input.a0/dadx/dady arrays
244 * immediately after it.
245 * The memory is allocated from the per-scene pool, not per-tile.
246 * \param tri_size returns number of bytes allocated
247 * \param nr_inputs number of fragment shader inputs
248 * \return pointer to triangle space
249 */
250 static INLINE struct lp_rast_triangle *
251 alloc_triangle(struct lp_scene *scene, unsigned nr_inputs, unsigned *tri_size)
252 {
253 unsigned input_array_sz = NUM_CHANNELS * (nr_inputs + 1) * sizeof(float);
254 struct lp_rast_triangle *tri;
255 unsigned bytes;
256 char *inputs;
257
258 assert(sizeof(*tri) % 16 == 0);
259
260 bytes = sizeof(*tri) + (3 * input_array_sz);
261
262 tri = lp_scene_alloc_aligned( scene, bytes, 16 );
263
264 inputs = (char *) (tri + 1);
265 tri->inputs.a0 = (float (*)[4]) inputs;
266 tri->inputs.dadx = (float (*)[4]) (inputs + input_array_sz);
267 tri->inputs.dady = (float (*)[4]) (inputs + 2 * input_array_sz);
268
269 *tri_size = bytes;
270
271 return tri;
272 }
273
274
275 /**
276 * Print triangle vertex attribs (for debug).
277 */
278 static void
279 print_triangle(struct lp_setup_context *setup,
280 const float (*v1)[4],
281 const float (*v2)[4],
282 const float (*v3)[4])
283 {
284 uint i;
285
286 debug_printf("llvmpipe triangle\n");
287 for (i = 0; i < setup->fs.nr_inputs; i++) {
288 debug_printf(" v1[%d]: %f %f %f %f\n", i,
289 v1[i][0], v1[i][1], v1[i][2], v1[i][3]);
290 }
291 for (i = 0; i < setup->fs.nr_inputs; i++) {
292 debug_printf(" v2[%d]: %f %f %f %f\n", i,
293 v2[i][0], v2[i][1], v2[i][2], v2[i][3]);
294 }
295 for (i = 0; i < setup->fs.nr_inputs; i++) {
296 debug_printf(" v3[%d]: %f %f %f %f\n", i,
297 v3[i][0], v3[i][1], v3[i][2], v3[i][3]);
298 }
299 }
300
301
302 /**
303 * Do basic setup for triangle rasterization and determine which
304 * framebuffer tiles are touched. Put the triangle in the scene's
305 * bins for the tiles which we overlap.
306 */
307 static void
308 do_triangle_ccw(struct lp_setup_context *setup,
309 const float (*v1)[4],
310 const float (*v2)[4],
311 const float (*v3)[4],
312 boolean frontfacing )
313 {
314 /* x/y positions in fixed point */
315 const int x1 = subpixel_snap(v1[0][0] + 0.5 - setup->pixel_offset);
316 const int x2 = subpixel_snap(v2[0][0] + 0.5 - setup->pixel_offset);
317 const int x3 = subpixel_snap(v3[0][0] + 0.5 - setup->pixel_offset);
318 const int y1 = subpixel_snap(v1[0][1] + 0.5 - setup->pixel_offset);
319 const int y2 = subpixel_snap(v2[0][1] + 0.5 - setup->pixel_offset);
320 const int y3 = subpixel_snap(v3[0][1] + 0.5 - setup->pixel_offset);
321
322 struct lp_scene *scene = lp_setup_get_current_scene(setup);
323 struct lp_rast_triangle *tri;
324 int area;
325 float oneoverarea;
326 int minx, maxx, miny, maxy;
327 unsigned tri_bytes;
328
329 if (0)
330 print_triangle(setup, v1, v2, v3);
331
332 tri = alloc_triangle(scene, setup->fs.nr_inputs, &tri_bytes);
333
334 #ifdef DEBUG
335 tri->v[0][0] = v1[0][0];
336 tri->v[1][0] = v2[0][0];
337 tri->v[2][0] = v3[0][0];
338 tri->v[0][1] = v1[0][1];
339 tri->v[1][1] = v2[0][1];
340 tri->v[2][1] = v3[0][1];
341 #endif
342
343 tri->dx12 = x1 - x2;
344 tri->dx23 = x2 - x3;
345 tri->dx31 = x3 - x1;
346
347 tri->dy12 = y1 - y2;
348 tri->dy23 = y2 - y3;
349 tri->dy31 = y3 - y1;
350
351 area = (tri->dx12 * tri->dy31 - tri->dx31 * tri->dy12);
352
353 LP_COUNT(nr_tris);
354
355 /* Cull non-ccw and zero-sized triangles.
356 *
357 * XXX: subject to overflow??
358 */
359 if (area <= 0) {
360 lp_scene_putback_data( scene, tri_bytes );
361 LP_COUNT(nr_culled_tris);
362 return;
363 }
364
365 /* Bounding rectangle (in pixels) */
366 minx = (MIN3(x1, x2, x3) + (FIXED_ONE-1)) >> FIXED_ORDER;
367 maxx = (MAX3(x1, x2, x3) + (FIXED_ONE-1)) >> FIXED_ORDER;
368 miny = (MIN3(y1, y2, y3) + (FIXED_ONE-1)) >> FIXED_ORDER;
369 maxy = (MAX3(y1, y2, y3) + (FIXED_ONE-1)) >> FIXED_ORDER;
370
371 if (setup->scissor_test) {
372 minx = MAX2(minx, setup->scissor.current.minx);
373 maxx = MIN2(maxx, setup->scissor.current.maxx);
374 miny = MAX2(miny, setup->scissor.current.miny);
375 maxy = MIN2(maxy, setup->scissor.current.maxy);
376 }
377
378 if (miny == maxy ||
379 minx == maxx) {
380 lp_scene_putback_data( scene, tri_bytes );
381 LP_COUNT(nr_culled_tris);
382 return;
383 }
384
385 /*
386 */
387 oneoverarea = ((float)FIXED_ONE) / (float)area;
388
389 /* Setup parameter interpolants:
390 */
391 setup_tri_coefficients( setup, tri, oneoverarea, v1, v2, v3, frontfacing );
392
393 tri->inputs.facing = frontfacing ? 1.0F : -1.0F;
394
395 /* half-edge constants, will be interated over the whole render target.
396 */
397 tri->c1 = tri->dy12 * x1 - tri->dx12 * y1;
398 tri->c2 = tri->dy23 * x2 - tri->dx23 * y2;
399 tri->c3 = tri->dy31 * x3 - tri->dx31 * y3;
400
401 /* correct for top-left fill convention:
402 */
403 if (tri->dy12 < 0 || (tri->dy12 == 0 && tri->dx12 > 0)) tri->c1++;
404 if (tri->dy23 < 0 || (tri->dy23 == 0 && tri->dx23 > 0)) tri->c2++;
405 if (tri->dy31 < 0 || (tri->dy31 == 0 && tri->dx31 > 0)) tri->c3++;
406
407 tri->dy12 *= FIXED_ONE;
408 tri->dy23 *= FIXED_ONE;
409 tri->dy31 *= FIXED_ONE;
410
411 tri->dx12 *= FIXED_ONE;
412 tri->dx23 *= FIXED_ONE;
413 tri->dx31 *= FIXED_ONE;
414
415 /* find trivial reject offsets for each edge for a single-pixel
416 * sized block. These will be scaled up at each recursive level to
417 * match the active blocksize. Scaling in this way works best if
418 * the blocks are square.
419 */
420 tri->eo1 = 0;
421 if (tri->dy12 < 0) tri->eo1 -= tri->dy12;
422 if (tri->dx12 > 0) tri->eo1 += tri->dx12;
423
424 tri->eo2 = 0;
425 if (tri->dy23 < 0) tri->eo2 -= tri->dy23;
426 if (tri->dx23 > 0) tri->eo2 += tri->dx23;
427
428 tri->eo3 = 0;
429 if (tri->dy31 < 0) tri->eo3 -= tri->dy31;
430 if (tri->dx31 > 0) tri->eo3 += tri->dx31;
431
432 /* Calculate trivial accept offsets from the above.
433 */
434 tri->ei1 = tri->dx12 - tri->dy12 - tri->eo1;
435 tri->ei2 = tri->dx23 - tri->dy23 - tri->eo2;
436 tri->ei3 = tri->dx31 - tri->dy31 - tri->eo3;
437
438 /* Fill in the inputs.step[][] arrays.
439 * We've manually unrolled some loops here.
440 */
441 {
442 const int xstep1 = -tri->dy12;
443 const int xstep2 = -tri->dy23;
444 const int xstep3 = -tri->dy31;
445 const int ystep1 = tri->dx12;
446 const int ystep2 = tri->dx23;
447 const int ystep3 = tri->dx31;
448
449 #define SETUP_STEP(i, x, y) \
450 do { \
451 tri->inputs.step[0][i] = x * xstep1 + y * ystep1; \
452 tri->inputs.step[1][i] = x * xstep2 + y * ystep2; \
453 tri->inputs.step[2][i] = x * xstep3 + y * ystep3; \
454 } while (0)
455
456 SETUP_STEP(0, 0, 0);
457 SETUP_STEP(1, 1, 0);
458 SETUP_STEP(2, 0, 1);
459 SETUP_STEP(3, 1, 1);
460
461 SETUP_STEP(4, 2, 0);
462 SETUP_STEP(5, 3, 0);
463 SETUP_STEP(6, 2, 1);
464 SETUP_STEP(7, 3, 1);
465
466 SETUP_STEP(8, 0, 2);
467 SETUP_STEP(9, 1, 2);
468 SETUP_STEP(10, 0, 3);
469 SETUP_STEP(11, 1, 3);
470
471 SETUP_STEP(12, 2, 2);
472 SETUP_STEP(13, 3, 2);
473 SETUP_STEP(14, 2, 3);
474 SETUP_STEP(15, 3, 3);
475 #undef STEP
476 }
477
478 /*
479 * All fields of 'tri' are now set. The remaining code here is
480 * concerned with binning.
481 */
482
483 /* Convert to tile coordinates:
484 */
485 minx = minx / TILE_SIZE;
486 miny = miny / TILE_SIZE;
487 maxx = maxx / TILE_SIZE;
488 maxy = maxy / TILE_SIZE;
489
490 /*
491 * Clamp to framebuffer size
492 */
493 minx = MAX2(minx, 0);
494 miny = MAX2(miny, 0);
495 maxx = MIN2(maxx, scene->tiles_x - 1);
496 maxy = MIN2(maxy, scene->tiles_y - 1);
497
498 /* Determine which tile(s) intersect the triangle's bounding box
499 */
500 if (miny == maxy && minx == maxx)
501 {
502 /* Triangle is contained in a single tile:
503 */
504 lp_scene_bin_command( scene, minx, miny, lp_rast_triangle,
505 lp_rast_arg_triangle(tri) );
506 }
507 else
508 {
509 int c1 = (tri->c1 +
510 tri->dx12 * miny * TILE_SIZE -
511 tri->dy12 * minx * TILE_SIZE);
512 int c2 = (tri->c2 +
513 tri->dx23 * miny * TILE_SIZE -
514 tri->dy23 * minx * TILE_SIZE);
515 int c3 = (tri->c3 +
516 tri->dx31 * miny * TILE_SIZE -
517 tri->dy31 * minx * TILE_SIZE);
518
519 int ei1 = tri->ei1 << TILE_ORDER;
520 int ei2 = tri->ei2 << TILE_ORDER;
521 int ei3 = tri->ei3 << TILE_ORDER;
522
523 int eo1 = tri->eo1 << TILE_ORDER;
524 int eo2 = tri->eo2 << TILE_ORDER;
525 int eo3 = tri->eo3 << TILE_ORDER;
526
527 int xstep1 = -(tri->dy12 << TILE_ORDER);
528 int xstep2 = -(tri->dy23 << TILE_ORDER);
529 int xstep3 = -(tri->dy31 << TILE_ORDER);
530
531 int ystep1 = tri->dx12 << TILE_ORDER;
532 int ystep2 = tri->dx23 << TILE_ORDER;
533 int ystep3 = tri->dx31 << TILE_ORDER;
534 int x, y;
535
536
537 /* Test tile-sized blocks against the triangle.
538 * Discard blocks fully outside the tri. If the block is fully
539 * contained inside the tri, bin an lp_rast_shade_tile command.
540 * Else, bin a lp_rast_triangle command.
541 */
542 for (y = miny; y <= maxy; y++)
543 {
544 int cx1 = c1;
545 int cx2 = c2;
546 int cx3 = c3;
547 boolean in = FALSE; /* are we inside the triangle? */
548
549 for (x = minx; x <= maxx; x++)
550 {
551 if (cx1 + eo1 < 0 ||
552 cx2 + eo2 < 0 ||
553 cx3 + eo3 < 0)
554 {
555 /* do nothing */
556 LP_COUNT(nr_empty_64);
557 if (in)
558 break; /* exiting triangle, all done with this row */
559 }
560 else if (cx1 + ei1 > 0 &&
561 cx2 + ei2 > 0 &&
562 cx3 + ei3 > 0)
563 {
564 /* triangle covers the whole tile- shade whole tile */
565 LP_COUNT(nr_fully_covered_64);
566 in = TRUE;
567 if(setup->fs.current.opaque) {
568 lp_scene_bin_reset( scene, x, y );
569 lp_scene_bin_command( scene, x, y,
570 lp_rast_set_state,
571 lp_rast_arg_state(setup->fs.stored) );
572 }
573 lp_scene_bin_command( scene, x, y,
574 lp_rast_shade_tile,
575 lp_rast_arg_inputs(&tri->inputs) );
576 }
577 else
578 {
579 /* rasterizer/shade partial tile */
580 LP_COUNT(nr_partially_covered_64);
581 in = TRUE;
582 lp_scene_bin_command( scene, x, y,
583 lp_rast_triangle,
584 lp_rast_arg_triangle(tri) );
585 }
586
587 /* Iterate cx values across the region:
588 */
589 cx1 += xstep1;
590 cx2 += xstep2;
591 cx3 += xstep3;
592 }
593
594 /* Iterate c values down the region:
595 */
596 c1 += ystep1;
597 c2 += ystep2;
598 c3 += ystep3;
599 }
600 }
601 }
602
603
604 /**
605 * Draw triangle if it's CW, cull otherwise.
606 */
607 static void triangle_cw( struct lp_setup_context *setup,
608 const float (*v0)[4],
609 const float (*v1)[4],
610 const float (*v2)[4] )
611 {
612 do_triangle_ccw( setup, v1, v0, v2, !setup->ccw_is_frontface );
613 }
614
615
616 /**
617 * Draw triangle if it's CCW, cull otherwise.
618 */
619 static void triangle_ccw( struct lp_setup_context *setup,
620 const float (*v0)[4],
621 const float (*v1)[4],
622 const float (*v2)[4] )
623 {
624 do_triangle_ccw( setup, v0, v1, v2, setup->ccw_is_frontface );
625 }
626
627
628
629 /**
630 * Draw triangle whether it's CW or CCW.
631 */
632 static void triangle_both( struct lp_setup_context *setup,
633 const float (*v0)[4],
634 const float (*v1)[4],
635 const float (*v2)[4] )
636 {
637 /* edge vectors e = v0 - v2, f = v1 - v2 */
638 const float ex = v0[0][0] - v2[0][0];
639 const float ey = v0[0][1] - v2[0][1];
640 const float fx = v1[0][0] - v2[0][0];
641 const float fy = v1[0][1] - v2[0][1];
642
643 /* det = cross(e,f).z */
644 if (ex * fy - ey * fx < 0.0f)
645 triangle_ccw( setup, v0, v1, v2 );
646 else
647 triangle_cw( setup, v0, v1, v2 );
648 }
649
650
651 static void triangle_nop( struct lp_setup_context *setup,
652 const float (*v0)[4],
653 const float (*v1)[4],
654 const float (*v2)[4] )
655 {
656 }
657
658
659 void
660 lp_setup_choose_triangle( struct lp_setup_context *setup )
661 {
662 switch (setup->cullmode) {
663 case PIPE_WINDING_NONE:
664 setup->triangle = triangle_both;
665 break;
666 case PIPE_WINDING_CCW:
667 setup->triangle = triangle_cw;
668 break;
669 case PIPE_WINDING_CW:
670 setup->triangle = triangle_ccw;
671 break;
672 default:
673 setup->triangle = triangle_nop;
674 break;
675 }
676 }