1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
34 #include "sp_context.h"
42 * This passes the quad to the first stage of per-fragment operations.
45 quad_emit(struct softpipe_context
*sp
, struct quad_header
*quad
)
47 sp
->quad
.first
->run(sp
->quad
.first
, quad
);
55 GLfloat dx
; /* X(v1) - X(v0), used only during setup */
56 GLfloat dy
; /* Y(v1) - Y(v0), used only during setup */
57 GLfloat dxdy
; /* dx/dy */
58 GLfloat sx
; /* first sample point x coord */
60 GLint lines
; /* number of lines on this edge */
65 * Triangle setup info (derived from prim_stage).
66 * Also used for line drawing (taking some liberties).
69 struct prim_stage stage
; /**< This must be first */
71 /* Vertices are just an array of floats making up each attribute in
72 * turn. Currently fixed at 4 floats, but should change in time.
73 * Codegen will help cope with this.
75 const struct vertex_header
*vmax
;
76 const struct vertex_header
*vmid
;
77 const struct vertex_header
*vmin
;
78 const struct vertex_header
*vprovoke
;
86 struct setup_coefficient coef
[FRAG_ATTRIB_MAX
];
87 struct quad_header quad
;
90 GLint left
[2]; /**< [0] = row0, [1] = row1 */
94 GLuint mask
; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
101 * Basically a cast wrapper.
103 static inline struct setup_stage
*setup_stage( struct prim_stage
*stage
)
105 return (struct setup_stage
*)stage
;
110 * Given an X or Y coordinate, return the block/quad coordinate that it
113 static inline GLint
block( GLint x
)
120 static void setup_begin( struct prim_stage
*stage
)
122 setup_stage(stage
)->quad
.nr_attrs
= stage
->softpipe
->nr_frag_attrs
;
127 * Run shader on a quad/block.
129 static void run_shader_block( struct setup_stage
*setup
,
130 GLint x
, GLint y
, GLuint mask
)
134 setup
->quad
.mask
= mask
;
136 quad_emit(setup
->stage
.softpipe
, &setup
->quad
);
141 * Compute mask which indicates which pixels in the 2x2 quad are actually inside
142 * the triangle's bounds.
144 * this is pretty nasty... may need to rework flush_spans again to
145 * fix it, if possible.
147 static GLuint
calculate_mask( struct setup_stage
*setup
,
152 if (x
>= setup
->span
.left
[0] && x
< setup
->span
.right
[0])
153 mask
|= MASK_BOTTOM_LEFT
;
155 if (x
>= setup
->span
.left
[1] && x
< setup
->span
.right
[1])
156 mask
|= MASK_TOP_LEFT
;
158 if (x
+1 >= setup
->span
.left
[0] && x
+1 < setup
->span
.right
[0])
159 mask
|= MASK_BOTTOM_RIGHT
;
161 if (x
+1 >= setup
->span
.left
[1] && x
+1 < setup
->span
.right
[1])
162 mask
|= MASK_TOP_RIGHT
;
169 * Render a horizontal span of quads
171 static void flush_spans( struct setup_stage
*setup
)
173 GLint minleft
, maxright
;
176 switch (setup
->span
.y_flags
) {
178 minleft
= MIN2(setup
->span
.left
[0], setup
->span
.left
[1]);
179 maxright
= MAX2(setup
->span
.right
[0], setup
->span
.right
[1]);
183 minleft
= setup
->span
.left
[0];
184 maxright
= setup
->span
.right
[0];
188 minleft
= setup
->span
.left
[1];
189 maxright
= setup
->span
.right
[1];
197 for (x
= block(minleft
); x
<= block(maxright
); )
199 run_shader_block( setup
, x
,
201 calculate_mask( setup
, x
) );
206 setup
->span
.y_flags
= 0;
207 setup
->span
.right
[0] = 0;
208 setup
->span
.right
[1] = 0;
212 static GLboolean
setup_sort_vertices( struct setup_stage
*setup
,
213 const struct prim_header
*prim
)
215 const struct vertex_header
*v0
= prim
->v
[0];
216 const struct vertex_header
*v1
= prim
->v
[1];
217 const struct vertex_header
*v2
= prim
->v
[2];
219 setup
->vprovoke
= v2
;
221 /* determine bottom to top order of vertices */
223 GLfloat y0
= v0
->data
[0][1];
224 GLfloat y1
= v1
->data
[0][1];
225 GLfloat y2
= v2
->data
[0][1];
268 setup
->ebot
.dx
= setup
->vmid
->data
[0][0] - setup
->vmin
->data
[0][0];
269 setup
->ebot
.dy
= setup
->vmid
->data
[0][1] - setup
->vmin
->data
[0][1];
270 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
271 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
272 setup
->etop
.dx
= setup
->vmax
->data
[0][0] - setup
->vmid
->data
[0][0];
273 setup
->etop
.dy
= setup
->vmax
->data
[0][1] - setup
->vmid
->data
[0][1];
275 /* xxx: may need to adjust this sign according to the if-tree
278 * XXX: this is like 'det', but calculated from screen coords??
281 const GLfloat area
= (setup
->emaj
.dx
* setup
->ebot
.dy
-
282 setup
->ebot
.dx
* setup
->emaj
.dy
);
284 setup
->oneoverarea
= 1.0 / area
;
287 /* XXX need to know if this is a front or back-facing triangle:
288 * - the GLSL gl_FrontFacing fragment attribute (bool)
289 * - two-sided stencil test
291 setup
->quad
.facing
= 0;
293 _mesa_printf("%s one-over-area %f\n", __FUNCTION__
, setup
->oneoverarea
);
301 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
303 static void const_coeff( struct setup_stage
*setup
,
307 setup
->coef
[slot
].dadx
[i
] = 0;
308 setup
->coef
[slot
].dady
[i
] = 0;
310 /* need provoking vertex info!
312 setup
->coef
[slot
].a0
[i
] = setup
->vprovoke
->data
[slot
][i
];
317 * Compute a0, dadx and dady for a linearly interpolated coefficient,
320 static void tri_linear_coeff( struct setup_stage
*setup
,
324 GLfloat botda
= setup
->vmid
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
325 GLfloat majda
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
326 GLfloat a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
327 GLfloat b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
329 setup
->coef
[slot
].dadx
[i
] = a
* setup
->oneoverarea
;
330 setup
->coef
[slot
].dady
[i
] = b
* setup
->oneoverarea
;
332 /* calculate a0 as the value which would be sampled for the
333 * fragment at (0,0), taking into account that we want to sample at
334 * pixel centers, in other words (0.5, 0.5).
336 * this is neat but unfortunately not a good way to do things for
337 * triangles with very large values of dadx or dady as it will
338 * result in the subtraction and re-addition from a0 of a very
339 * large number, which means we'll end up loosing a lot of the
340 * fractional bits and precision from a0. the way to fix this is
341 * to define a0 as the sample at a pixel center somewhere near vmin
342 * instead - i'll switch to this later.
344 setup
->coef
[slot
].a0
[i
] = (setup
->vmin
->data
[slot
][i
] -
345 (setup
->coef
[slot
].dadx
[i
] * (setup
->vmin
->data
[0][0] - 0.5) +
346 setup
->coef
[slot
].dady
[i
] * (setup
->vmin
->data
[0][1] - 0.5)));
348 _mesa_printf("attr[%d].%c: %f dx:%f dy:%f\n",
350 setup
->coef
[slot
].a0
[i
],
351 setup
->coef
[slot
].dadx
[i
],
352 setup
->coef
[slot
].dady
[i
]);
357 * Compute a0, dadx and dady for a perspective-corrected interpolant,
360 static void tri_persp_coeff( struct setup_stage
*setup
,
364 /* premultiply by 1/w:
366 GLfloat mina
= setup
->vmin
->data
[slot
][i
] * setup
->vmin
->data
[0][3];
367 GLfloat mida
= setup
->vmid
->data
[slot
][i
] * setup
->vmid
->data
[0][3];
368 GLfloat maxa
= setup
->vmax
->data
[slot
][i
] * setup
->vmax
->data
[0][3];
370 GLfloat botda
= mida
- mina
;
371 GLfloat majda
= maxa
- mina
;
372 GLfloat a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
373 GLfloat b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
375 setup
->coef
[slot
].dadx
[i
] = a
* setup
->oneoverarea
;
376 setup
->coef
[slot
].dady
[i
] = b
* setup
->oneoverarea
;
377 setup
->coef
[slot
].a0
[i
] = (mina
-
378 (setup
->coef
[slot
].dadx
[i
] * (setup
->vmin
->data
[0][0] - 0.5) +
379 setup
->coef
[slot
].dady
[i
] * (setup
->vmin
->data
[0][1] - 0.5)));
385 * Compute the setup->coef[] array dadx, dady, a0 values.
386 * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
388 static void setup_tri_coefficients( struct setup_stage
*setup
)
390 const enum interp_mode
*interp
= setup
->stage
.softpipe
->interp
;
393 /* z and w are done by linear interpolation:
395 tri_linear_coeff(setup
, 0, 2);
396 tri_linear_coeff(setup
, 0, 3);
398 /* setup interpolation for all the remaining attributes:
400 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
401 switch (interp
[slot
]) {
402 case INTERP_CONSTANT
:
403 for (j
= 0; j
< NUM_CHANNELS
; j
++)
404 const_coeff(setup
, slot
, j
);
408 for (j
= 0; j
< NUM_CHANNELS
; j
++)
409 tri_linear_coeff(setup
, slot
, j
);
412 case INTERP_PERSPECTIVE
:
413 for (j
= 0; j
< NUM_CHANNELS
; j
++)
414 tri_persp_coeff(setup
, slot
, j
);
422 static void setup_tri_edges( struct setup_stage
*setup
)
424 GLfloat vmin_x
= setup
->vmin
->data
[0][0] + 0.5;
425 GLfloat vmid_x
= setup
->vmid
->data
[0][0] + 0.5;
427 GLfloat vmin_y
= setup
->vmin
->data
[0][1] - 0.5;
428 GLfloat vmid_y
= setup
->vmid
->data
[0][1] - 0.5;
429 GLfloat vmax_y
= setup
->vmax
->data
[0][1] - 0.5;
431 setup
->emaj
.sy
= ceilf(vmin_y
);
432 setup
->emaj
.lines
= (GLint
) ceilf(vmax_y
- setup
->emaj
.sy
);
433 setup
->emaj
.dxdy
= setup
->emaj
.dx
/ setup
->emaj
.dy
;
434 setup
->emaj
.sx
= vmin_x
+ (setup
->emaj
.sy
- vmin_y
) * setup
->emaj
.dxdy
;
436 setup
->etop
.sy
= ceilf(vmid_y
);
437 setup
->etop
.lines
= (GLint
) ceilf(vmax_y
- setup
->etop
.sy
);
438 setup
->etop
.dxdy
= setup
->etop
.dx
/ setup
->etop
.dy
;
439 setup
->etop
.sx
= vmid_x
+ (setup
->etop
.sy
- vmid_y
) * setup
->etop
.dxdy
;
441 setup
->ebot
.sy
= ceilf(vmin_y
);
442 setup
->ebot
.lines
= (GLint
) ceilf(vmid_y
- setup
->ebot
.sy
);
443 setup
->ebot
.dxdy
= setup
->ebot
.dx
/ setup
->ebot
.dy
;
444 setup
->ebot
.sx
= vmin_x
+ (setup
->ebot
.sy
- vmin_y
) * setup
->ebot
.dxdy
;
449 * Render the upper or lower half of a triangle.
450 * Scissoring is applied here too.
452 static void subtriangle( struct setup_stage
*setup
,
457 GLint y
, start_y
, finish_y
;
458 GLint sy
= (GLint
)eleft
->sy
;
460 assert((GLint
)eleft
->sy
== (GLint
) eright
->sy
);
461 assert((GLint
)eleft
->sy
>= 0); /* catch bug in x64? */
465 if (setup
->stage
.softpipe
->setup
.scissor
) {
467 finish_y
= start_y
+ lines
;
469 if (start_y
< setup
->stage
.softpipe
->scissor
.miny
)
470 start_y
= setup
->stage
.softpipe
->scissor
.miny
;
472 if (finish_y
> setup
->stage
.softpipe
->scissor
.maxy
)
473 finish_y
= setup
->stage
.softpipe
->scissor
.maxy
;
483 _mesa_printf("%s %d %d\n", __FUNCTION__
, start_y
, finish_y
);
485 for (y
= start_y
; y
< finish_y
; y
++) {
487 /* avoid accumulating adds as floats don't have the precision to
488 * accurately iterate large triangle edges that way. luckily we
489 * can just multiply these days.
491 * this is all drowned out by the attribute interpolation anyway.
493 GLint left
= (GLint
)(eleft
->sx
+ y
* eleft
->dxdy
);
494 GLint right
= (GLint
)(eright
->sx
+ y
* eright
->dxdy
);
498 if (setup
->stage
.softpipe
->setup
.scissor
) {
499 if (left
< setup
->stage
.softpipe
->scissor
.minx
)
500 left
= setup
->stage
.softpipe
->scissor
.minx
;
502 if (right
> setup
->stage
.softpipe
->scissor
.maxx
)
503 right
= setup
->stage
.softpipe
->scissor
.maxx
;
508 if (block(_y
) != setup
->span
.y
) {
510 setup
->span
.y
= block(_y
);
513 setup
->span
.left
[_y
&1] = left
;
514 setup
->span
.right
[_y
&1] = right
;
515 setup
->span
.y_flags
|= 1<<(_y
&1);
520 /* save the values so that emaj can be restarted:
522 eleft
->sx
+= lines
* eleft
->dxdy
;
523 eright
->sx
+= lines
* eright
->dxdy
;
530 * Do setup for triangle rasterization, then render the triangle.
532 static void setup_tri( struct prim_stage
*stage
,
533 struct prim_header
*prim
)
535 struct setup_stage
*setup
= setup_stage( stage
);
537 _mesa_printf("%s\n", __FUNCTION__
);
539 setup_sort_vertices( setup
, prim
);
540 setup_tri_coefficients( setup
);
541 setup_tri_edges( setup
);
544 setup
->span
.y_flags
= 0;
545 setup
->span
.right
[0] = 0;
546 setup
->span
.right
[1] = 0;
547 // setup->span.z_mode = tri_z_mode( setup->ctx );
549 // init_constant_attribs( setup );
551 if (setup
->oneoverarea
< 0.0) {
554 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
555 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
560 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
561 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
564 flush_spans( setup
);
570 * Compute a0, dadx and dady for a linearly interpolated coefficient,
574 line_linear_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
576 const GLfloat dz
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
577 const GLfloat dadx
= dz
* setup
->emaj
.dx
* setup
->oneoverarea
;
578 const GLfloat dady
= dz
* setup
->emaj
.dy
* setup
->oneoverarea
;
579 setup
->coef
[slot
].dadx
[i
] = dadx
;
580 setup
->coef
[slot
].dady
[i
] = dady
;
581 setup
->coef
[slot
].a0
[i
]
582 = (setup
->vmin
->data
[slot
][i
] -
583 (dadx
* (setup
->vmin
->data
[0][0] - 0.5) +
584 dady
* (setup
->vmin
->data
[0][1] - 0.5)));
589 * Compute a0, dadx and dady for a perspective-corrected interpolant,
593 line_persp_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
596 line_linear_coeff(setup
, slot
, i
); /* XXX temporary */
601 * Compute the setup->coef[] array dadx, dady, a0 values.
602 * Must be called after setup->vmin,vmax are initialized.
605 setup_line_coefficients(struct setup_stage
*setup
, struct prim_header
*prim
)
607 const enum interp_mode
*interp
= setup
->stage
.softpipe
->interp
;
610 /* use setup->vmin, vmax to point to vertices */
611 setup
->vprovoke
= prim
->v
[1];
612 setup
->vmin
= prim
->v
[0];
613 setup
->vmax
= prim
->v
[1];
615 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
616 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
617 /* NOTE: this is not really 1/area */
618 setup
->oneoverarea
= 1.0 / (setup
->emaj
.dx
* setup
->emaj
.dx
+
619 setup
->emaj
.dy
* setup
->emaj
.dy
);
621 /* z and w are done by linear interpolation:
623 line_linear_coeff(setup
, 0, 2);
624 line_linear_coeff(setup
, 0, 3);
626 /* setup interpolation for all the remaining attributes:
628 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
629 switch (interp
[slot
]) {
630 case INTERP_CONSTANT
:
631 for (j
= 0; j
< NUM_CHANNELS
; j
++)
632 const_coeff(setup
, slot
, j
);
636 for (j
= 0; j
< NUM_CHANNELS
; j
++)
637 line_linear_coeff(setup
, slot
, j
);
640 case INTERP_PERSPECTIVE
:
641 for (j
= 0; j
< NUM_CHANNELS
; j
++)
642 line_persp_coeff(setup
, slot
, j
);
650 * Plot a pixel in a line segment.
653 plot(struct setup_stage
*setup
, GLint x
, GLint y
)
655 const GLint iy
= y
& 1;
656 const GLint ix
= x
& 1;
657 const GLint quadX
= x
- ix
;
658 const GLint quadY
= y
- iy
;
659 const GLint mask
= (1 << ix
) << (2 * iy
);
661 if (quadX
!= setup
->quad
.x0
||
662 quadY
!= setup
->quad
.y0
)
664 /* flush prev quad, start new quad */
666 if (setup
->quad
.x0
!= -1)
667 quad_emit(setup
->stage
.softpipe
, &setup
->quad
);
669 setup
->quad
.x0
= quadX
;
670 setup
->quad
.y0
= quadY
;
671 setup
->quad
.mask
= 0x0;
674 setup
->quad
.mask
|= mask
;
680 * Do setup for line rasterization, then render the line.
681 * XXX single-pixel width, no stipple, etc
682 * XXX no scissoring yet.
685 setup_line(struct prim_stage
*stage
, struct prim_header
*prim
)
687 const struct vertex_header
*v0
= prim
->v
[0];
688 const struct vertex_header
*v1
= prim
->v
[1];
689 struct setup_stage
*setup
= setup_stage( stage
);
691 GLint x0
= (GLint
) v0
->data
[0][0];
692 GLint x1
= (GLint
) v1
->data
[0][0];
693 GLint y0
= (GLint
) v0
->data
[0][1];
694 GLint y1
= (GLint
) v1
->data
[0][1];
699 if (dx
== 0 && dy
== 0)
702 setup_line_coefficients(setup
, prim
);
705 dx
= -dx
; /* make positive */
713 dy
= -dy
; /* make positive */
723 setup
->quad
.x0
= setup
->quad
.y0
= -1;
724 setup
->quad
.mask
= 0x0;
727 /*** X-major line ***/
729 const GLint errorInc
= dy
+ dy
;
730 GLint error
= errorInc
- dx
;
731 const GLint errorDec
= error
- dx
;
733 for (i
= 0; i
< dx
; i
++) {
747 /*** Y-major line ***/
749 const GLint errorInc
= dx
+ dx
;
750 GLint error
= errorInc
- dy
;
751 const GLint errorDec
= error
- dy
;
753 for (i
= 0; i
< dy
; i
++) {
768 /* draw final quad */
769 if (setup
->quad
.mask
) {
770 quad_emit(setup
->stage
.softpipe
, &setup
->quad
);
776 * Do setup for point rasterization, then render the point.
777 * Round or square points...
778 * XXX could optimize a lot for 1-pixel points.
781 setup_point(struct prim_stage
*stage
, struct prim_header
*prim
)
783 struct setup_stage
*setup
= setup_stage( stage
);
784 /*XXX this should be a vertex attrib! */
785 GLfloat halfSize
= 0.5 * setup
->stage
.softpipe
->setup
.point_size
;
786 GLboolean round
= setup
->stage
.softpipe
->setup
.point_smooth
;
787 const struct vertex_header
*v0
= prim
->v
[0];
788 const GLfloat x
= v0
->data
[FRAG_ATTRIB_WPOS
][0];
789 const GLfloat y
= v0
->data
[FRAG_ATTRIB_WPOS
][1];
792 /* For points, all interpolants are constant-valued.
793 * However, for point sprites, we'll need to setup texcoords appropriately.
794 * XXX: which coefficients are the texcoords???
795 * We may do point sprites as textured quads...
797 * KW: We don't know which coefficients are texcoords - ultimately
798 * the choice of what interpolation mode to use for each attribute
799 * should be determined by the fragment program, using
800 * per-attribute declaration statements that include interpolation
801 * mode as a parameter. So either the fragment program will have
802 * to be adjusted for pointsprite vs normal point behaviour, or
803 * otherwise a special interpolation mode will have to be defined
804 * which matches the required behaviour for point sprites. But -
805 * the latter is not a feature of normal hardware, and as such
806 * probably should be ruled out on that basis.
808 setup
->vprovoke
= prim
->v
[0];
809 const_coeff(setup
, 0, 2);
810 const_coeff(setup
, 0, 3);
811 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
812 for (j
= 0; j
< NUM_CHANNELS
; j
++)
813 const_coeff(setup
, slot
, j
);
816 /* XXX need to clip against scissor bounds too */
818 if (halfSize
<= 0.5 && !round
) {
819 /* special case for 1-pixel points */
820 const GLint ix
= ((GLint
) x
) & 1;
821 const GLint iy
= ((GLint
) y
) & 1;
822 setup
->quad
.x0
= x
- ix
;
823 setup
->quad
.y0
= y
- iy
;
824 setup
->quad
.mask
= (1 << ix
) << (2 * iy
);
825 quad_emit(setup
->stage
.softpipe
, &setup
->quad
);
828 const GLint ixmin
= block((GLint
) (x
- halfSize
));
829 const GLint ixmax
= block((GLint
) (x
+ halfSize
));
830 const GLint iymin
= block((GLint
) (y
- halfSize
));
831 const GLint iymax
= block((GLint
) (y
+ halfSize
));
832 GLfloat halfSizeSquared
= halfSize
* halfSize
;
835 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
836 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
840 /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */
843 setup
->quad
.mask
= 0x0;
847 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
848 setup
->quad
.mask
|= MASK_BOTTOM_LEFT
;
852 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
853 setup
->quad
.mask
|= MASK_BOTTOM_RIGHT
;
857 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
858 setup
->quad
.mask
|= MASK_TOP_LEFT
;
862 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
863 setup
->quad
.mask
|= MASK_TOP_RIGHT
;
867 setup
->quad
.mask
= 0xf;
869 if (ix
+ 0.5 < x
- halfSize
)
870 setup
->quad
.mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
872 if (ix
+ 1.5 > x
+ halfSize
)
873 setup
->quad
.mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
875 if (iy
+ 0.5 < y
- halfSize
)
876 setup
->quad
.mask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
878 if (iy
+ 1.5 > y
+ halfSize
)
879 setup
->quad
.mask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
882 if (setup
->quad
.mask
) {
885 quad_emit( setup
->stage
.softpipe
, &setup
->quad
);
894 static void setup_end( struct prim_stage
*stage
)
899 struct prim_stage
*prim_setup( struct softpipe_context
*softpipe
)
901 struct setup_stage
*setup
= CALLOC_STRUCT(setup_stage
);
903 setup
->stage
.softpipe
= softpipe
;
904 setup
->stage
.begin
= setup_begin
;
905 setup
->stage
.point
= setup_point
;
906 setup
->stage
.line
= setup_line
;
907 setup
->stage
.tri
= setup_tri
;
908 setup
->stage
.end
= setup_end
;
910 setup
->quad
.coef
= setup
->coef
;
912 return &setup
->stage
;