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 **************************************************************************/
29 * \brief Primitive rasterization/rendering (points, lines, triangles)
31 * \author Keith Whitwell <keith@tungstengraphics.com>
39 #include "sp_context.h"
40 #include "sp_headers.h"
41 #include "pipe/draw/draw_private.h"
43 #include "sp_prim_setup.h"
49 * This passes the quad to the first stage of per-fragment operations.
52 quad_emit(struct softpipe_context
*sp
, struct quad_header
*quad
)
54 sp
->quad
.first
->run(sp
->quad
.first
, quad
);
62 GLfloat dx
; /* X(v1) - X(v0), used only during setup */
63 GLfloat dy
; /* Y(v1) - Y(v0), used only during setup */
64 GLfloat dxdy
; /* dx/dy */
65 GLfloat sx
; /* first sample point x coord */
67 GLint lines
; /* number of lines on this edge */
72 * Triangle setup info (derived from draw_stage).
73 * Also used for line drawing (taking some liberties).
76 struct draw_stage stage
; /**< This must be first (base class) */
79 struct softpipe_context
*softpipe
;
81 /* Vertices are just an array of floats making up each attribute in
82 * turn. Currently fixed at 4 floats, but should change in time.
83 * Codegen will help cope with this.
85 const struct vertex_header
*vmax
;
86 const struct vertex_header
*vmid
;
87 const struct vertex_header
*vmin
;
88 const struct vertex_header
*vprovoke
;
96 struct setup_coefficient coef
[FRAG_ATTRIB_MAX
];
97 struct quad_header quad
;
100 GLint left
[2]; /**< [0] = row0, [1] = row1 */
104 GLuint mask
; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
111 * Basically a cast wrapper.
113 static inline struct setup_stage
*setup_stage( struct draw_stage
*stage
)
115 return (struct setup_stage
*)stage
;
120 * Given an X or Y coordinate, return the block/quad coordinate that it
123 static inline GLint
block( GLint x
)
131 * Run shader on a quad/block.
133 static void run_shader_block( struct setup_stage
*setup
,
134 GLint x
, GLint y
, GLuint mask
)
138 setup
->quad
.mask
= mask
;
140 quad_emit(setup
->softpipe
, &setup
->quad
);
145 * Compute mask which indicates which pixels in the 2x2 quad are actually inside
146 * the triangle's bounds.
148 * this is pretty nasty... may need to rework flush_spans again to
149 * fix it, if possible.
151 static GLuint
calculate_mask( struct setup_stage
*setup
,
156 if (x
>= setup
->span
.left
[0] && x
< setup
->span
.right
[0])
157 mask
|= MASK_BOTTOM_LEFT
;
159 if (x
>= setup
->span
.left
[1] && x
< setup
->span
.right
[1])
160 mask
|= MASK_TOP_LEFT
;
162 if (x
+1 >= setup
->span
.left
[0] && x
+1 < setup
->span
.right
[0])
163 mask
|= MASK_BOTTOM_RIGHT
;
165 if (x
+1 >= setup
->span
.left
[1] && x
+1 < setup
->span
.right
[1])
166 mask
|= MASK_TOP_RIGHT
;
173 * Render a horizontal span of quads
175 static void flush_spans( struct setup_stage
*setup
)
177 GLint minleft
, maxright
;
180 switch (setup
->span
.y_flags
) {
182 minleft
= MIN2(setup
->span
.left
[0], setup
->span
.left
[1]);
183 maxright
= MAX2(setup
->span
.right
[0], setup
->span
.right
[1]);
187 minleft
= setup
->span
.left
[0];
188 maxright
= setup
->span
.right
[0];
192 minleft
= setup
->span
.left
[1];
193 maxright
= setup
->span
.right
[1];
201 for (x
= block(minleft
); x
<= block(maxright
); )
203 run_shader_block( setup
, x
,
205 calculate_mask( setup
, x
) );
210 setup
->span
.y_flags
= 0;
211 setup
->span
.right
[0] = 0;
212 setup
->span
.right
[1] = 0;
216 static GLboolean
setup_sort_vertices( struct setup_stage
*setup
,
217 const struct prim_header
*prim
)
219 const struct vertex_header
*v0
= prim
->v
[0];
220 const struct vertex_header
*v1
= prim
->v
[1];
221 const struct vertex_header
*v2
= prim
->v
[2];
223 setup
->vprovoke
= v2
;
225 /* determine bottom to top order of vertices */
227 GLfloat y0
= v0
->data
[0][1];
228 GLfloat y1
= v1
->data
[0][1];
229 GLfloat y2
= v2
->data
[0][1];
272 setup
->ebot
.dx
= setup
->vmid
->data
[0][0] - setup
->vmin
->data
[0][0];
273 setup
->ebot
.dy
= setup
->vmid
->data
[0][1] - setup
->vmin
->data
[0][1];
274 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
275 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
276 setup
->etop
.dx
= setup
->vmax
->data
[0][0] - setup
->vmid
->data
[0][0];
277 setup
->etop
.dy
= setup
->vmax
->data
[0][1] - setup
->vmid
->data
[0][1];
280 * Compute triangle's area. Use 1/area to compute partial
281 * derivatives of attributes later.
283 * The area will be the same as prim->det, but the sign may be
284 * different depending on how the vertices get sorted above.
286 * To determine whether the primitive is front or back facing we
287 * use the prim->det value because its sign is correct.
290 const GLfloat area
= (setup
->emaj
.dx
* setup
->ebot
.dy
-
291 setup
->ebot
.dx
* setup
->emaj
.dy
);
293 setup
->oneoverarea
= 1.0 / area
;
295 _mesa_printf("%s one-over-area %f area %f det %f\n",
296 __FUNCTION__, setup->oneoverarea, area, prim->det );
300 /* We need to know if this is a front or back-facing triangle for:
301 * - the GLSL gl_FrontFacing fragment attribute (bool)
302 * - two-sided stencil test
304 setup
->quad
.facing
= (prim
->det
> 0.0) ^ (setup
->softpipe
->setup
.front_winding
== PIPE_WINDING_CW
);
311 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
312 * The value value comes from vertex->data[slot][i].
313 * The result will be put into setup->coef[slot].a0[i].
314 * \param slot which attribute slot
315 * \param i which component of the slot (0..3)
317 static void const_coeff( struct setup_stage
*setup
,
321 assert(slot
< FRAG_ATTRIB_MAX
);
324 setup
->coef
[slot
].dadx
[i
] = 0;
325 setup
->coef
[slot
].dady
[i
] = 0;
327 /* need provoking vertex info!
329 setup
->coef
[slot
].a0
[i
] = setup
->vprovoke
->data
[slot
][i
];
334 * Compute a0, dadx and dady for a linearly interpolated coefficient,
337 static void tri_linear_coeff( struct setup_stage
*setup
,
341 GLfloat botda
= setup
->vmid
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
342 GLfloat majda
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
343 GLfloat a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
344 GLfloat b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
346 assert(slot
< FRAG_ATTRIB_MAX
);
349 setup
->coef
[slot
].dadx
[i
] = a
* setup
->oneoverarea
;
350 setup
->coef
[slot
].dady
[i
] = b
* setup
->oneoverarea
;
352 /* calculate a0 as the value which would be sampled for the
353 * fragment at (0,0), taking into account that we want to sample at
354 * pixel centers, in other words (0.5, 0.5).
356 * this is neat but unfortunately not a good way to do things for
357 * triangles with very large values of dadx or dady as it will
358 * result in the subtraction and re-addition from a0 of a very
359 * large number, which means we'll end up loosing a lot of the
360 * fractional bits and precision from a0. the way to fix this is
361 * to define a0 as the sample at a pixel center somewhere near vmin
362 * instead - i'll switch to this later.
364 setup
->coef
[slot
].a0
[i
] = (setup
->vmin
->data
[slot
][i
] -
365 (setup
->coef
[slot
].dadx
[i
] * (setup
->vmin
->data
[0][0] - 0.5) +
366 setup
->coef
[slot
].dady
[i
] * (setup
->vmin
->data
[0][1] - 0.5)));
369 _mesa_printf("attr[%d].%c: %f dx:%f dy:%f\n",
371 setup->coef[slot].a0[i],
372 setup->coef[slot].dadx[i],
373 setup->coef[slot].dady[i]);
379 * Compute a0, dadx and dady for a perspective-corrected interpolant,
382 static void tri_persp_coeff( struct setup_stage
*setup
,
386 /* premultiply by 1/w:
388 GLfloat mina
= setup
->vmin
->data
[slot
][i
] * setup
->vmin
->data
[0][3];
389 GLfloat mida
= setup
->vmid
->data
[slot
][i
] * setup
->vmid
->data
[0][3];
390 GLfloat maxa
= setup
->vmax
->data
[slot
][i
] * setup
->vmax
->data
[0][3];
392 GLfloat botda
= mida
- mina
;
393 GLfloat majda
= maxa
- mina
;
394 GLfloat a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
395 GLfloat b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
397 assert(slot
< FRAG_ATTRIB_MAX
);
400 setup
->coef
[slot
].dadx
[i
] = a
* setup
->oneoverarea
;
401 setup
->coef
[slot
].dady
[i
] = b
* setup
->oneoverarea
;
402 setup
->coef
[slot
].a0
[i
] = (mina
-
403 (setup
->coef
[slot
].dadx
[i
] * (setup
->vmin
->data
[0][0] - 0.5) +
404 setup
->coef
[slot
].dady
[i
] * (setup
->vmin
->data
[0][1] - 0.5)));
410 * Compute the setup->coef[] array dadx, dady, a0 values.
411 * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
413 static void setup_tri_coefficients( struct setup_stage
*setup
)
415 const enum interp_mode
*interp
= setup
->softpipe
->interp
;
418 /* z and w are done by linear interpolation:
420 tri_linear_coeff(setup
, 0, 2);
421 tri_linear_coeff(setup
, 0, 3);
423 /* setup interpolation for all the remaining attributes:
425 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
426 switch (interp
[slot
]) {
427 case INTERP_CONSTANT
:
428 for (j
= 0; j
< NUM_CHANNELS
; j
++)
429 const_coeff(setup
, slot
, j
);
433 for (j
= 0; j
< NUM_CHANNELS
; j
++)
434 tri_linear_coeff(setup
, slot
, j
);
437 case INTERP_PERSPECTIVE
:
438 for (j
= 0; j
< NUM_CHANNELS
; j
++)
439 tri_persp_coeff(setup
, slot
, j
);
447 static void setup_tri_edges( struct setup_stage
*setup
)
449 GLfloat vmin_x
= setup
->vmin
->data
[0][0] + 0.5;
450 GLfloat vmid_x
= setup
->vmid
->data
[0][0] + 0.5;
452 GLfloat vmin_y
= setup
->vmin
->data
[0][1] - 0.5;
453 GLfloat vmid_y
= setup
->vmid
->data
[0][1] - 0.5;
454 GLfloat vmax_y
= setup
->vmax
->data
[0][1] - 0.5;
456 setup
->emaj
.sy
= ceilf(vmin_y
);
457 setup
->emaj
.lines
= (GLint
) ceilf(vmax_y
- setup
->emaj
.sy
);
458 setup
->emaj
.dxdy
= setup
->emaj
.dx
/ setup
->emaj
.dy
;
459 setup
->emaj
.sx
= vmin_x
+ (setup
->emaj
.sy
- vmin_y
) * setup
->emaj
.dxdy
;
461 setup
->etop
.sy
= ceilf(vmid_y
);
462 setup
->etop
.lines
= (GLint
) ceilf(vmax_y
- setup
->etop
.sy
);
463 setup
->etop
.dxdy
= setup
->etop
.dx
/ setup
->etop
.dy
;
464 setup
->etop
.sx
= vmid_x
+ (setup
->etop
.sy
- vmid_y
) * setup
->etop
.dxdy
;
466 setup
->ebot
.sy
= ceilf(vmin_y
);
467 setup
->ebot
.lines
= (GLint
) ceilf(vmid_y
- setup
->ebot
.sy
);
468 setup
->ebot
.dxdy
= setup
->ebot
.dx
/ setup
->ebot
.dy
;
469 setup
->ebot
.sx
= vmin_x
+ (setup
->ebot
.sy
- vmin_y
) * setup
->ebot
.dxdy
;
474 * Render the upper or lower half of a triangle.
475 * Scissoring is applied here too.
477 static void subtriangle( struct setup_stage
*setup
,
482 GLint y
, start_y
, finish_y
;
483 GLint sy
= (GLint
)eleft
->sy
;
485 assert((GLint
)eleft
->sy
== (GLint
) eright
->sy
);
486 assert((GLint
)eleft
->sy
>= 0); /* catch bug in x64? */
490 if (setup
->softpipe
->setup
.scissor
) {
492 finish_y
= start_y
+ lines
;
494 if (start_y
< setup
->softpipe
->scissor
.miny
)
495 start_y
= setup
->softpipe
->scissor
.miny
;
497 if (finish_y
> setup
->softpipe
->scissor
.maxy
)
498 finish_y
= setup
->softpipe
->scissor
.maxy
;
509 _mesa_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
512 for (y
= start_y
; y
< finish_y
; y
++) {
514 /* avoid accumulating adds as floats don't have the precision to
515 * accurately iterate large triangle edges that way. luckily we
516 * can just multiply these days.
518 * this is all drowned out by the attribute interpolation anyway.
520 GLint left
= (GLint
)(eleft
->sx
+ y
* eleft
->dxdy
);
521 GLint right
= (GLint
)(eright
->sx
+ y
* eright
->dxdy
);
525 if (setup
->softpipe
->setup
.scissor
) {
526 if (left
< setup
->softpipe
->scissor
.minx
)
527 left
= setup
->softpipe
->scissor
.minx
;
529 if (right
> setup
->softpipe
->scissor
.maxx
)
530 right
= setup
->softpipe
->scissor
.maxx
;
535 if (block(_y
) != setup
->span
.y
) {
537 setup
->span
.y
= block(_y
);
540 setup
->span
.left
[_y
&1] = left
;
541 setup
->span
.right
[_y
&1] = right
;
542 setup
->span
.y_flags
|= 1<<(_y
&1);
547 /* save the values so that emaj can be restarted:
549 eleft
->sx
+= lines
* eleft
->dxdy
;
550 eright
->sx
+= lines
* eright
->dxdy
;
557 * Do setup for triangle rasterization, then render the triangle.
559 static void setup_tri( struct draw_stage
*stage
,
560 struct prim_header
*prim
)
562 struct setup_stage
*setup
= setup_stage( stage
);
565 _mesa_printf("%s\n", __FUNCTION__ );
568 setup_sort_vertices( setup
, prim
);
569 setup_tri_coefficients( setup
);
570 setup_tri_edges( setup
);
573 setup
->span
.y_flags
= 0;
574 setup
->span
.right
[0] = 0;
575 setup
->span
.right
[1] = 0;
576 /* setup->span.z_mode = tri_z_mode( setup->ctx ); */
578 /* init_constant_attribs( setup ); */
580 if (setup
->oneoverarea
< 0.0) {
583 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
584 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
589 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
590 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
593 flush_spans( setup
);
599 * Compute a0, dadx and dady for a linearly interpolated coefficient,
603 line_linear_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
605 const GLfloat dz
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
606 const GLfloat dadx
= dz
* setup
->emaj
.dx
* setup
->oneoverarea
;
607 const GLfloat dady
= dz
* setup
->emaj
.dy
* setup
->oneoverarea
;
608 setup
->coef
[slot
].dadx
[i
] = dadx
;
609 setup
->coef
[slot
].dady
[i
] = dady
;
610 setup
->coef
[slot
].a0
[i
]
611 = (setup
->vmin
->data
[slot
][i
] -
612 (dadx
* (setup
->vmin
->data
[0][0] - 0.5) +
613 dady
* (setup
->vmin
->data
[0][1] - 0.5)));
618 * Compute a0, dadx and dady for a perspective-corrected interpolant,
622 line_persp_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
625 line_linear_coeff(setup
, slot
, i
); /* XXX temporary */
630 * Compute the setup->coef[] array dadx, dady, a0 values.
631 * Must be called after setup->vmin,vmax are initialized.
634 setup_line_coefficients(struct setup_stage
*setup
, struct prim_header
*prim
)
636 const enum interp_mode
*interp
= setup
->softpipe
->interp
;
639 /* use setup->vmin, vmax to point to vertices */
640 setup
->vprovoke
= prim
->v
[1];
641 setup
->vmin
= prim
->v
[0];
642 setup
->vmax
= prim
->v
[1];
644 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
645 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
646 /* NOTE: this is not really 1/area */
647 setup
->oneoverarea
= 1.0 / (setup
->emaj
.dx
* setup
->emaj
.dx
+
648 setup
->emaj
.dy
* setup
->emaj
.dy
);
650 /* z and w are done by linear interpolation:
652 line_linear_coeff(setup
, 0, 2);
653 line_linear_coeff(setup
, 0, 3);
655 /* setup interpolation for all the remaining attributes:
657 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
658 switch (interp
[slot
]) {
659 case INTERP_CONSTANT
:
660 for (j
= 0; j
< NUM_CHANNELS
; j
++)
661 const_coeff(setup
, slot
, j
);
665 for (j
= 0; j
< NUM_CHANNELS
; j
++)
666 line_linear_coeff(setup
, slot
, j
);
669 case INTERP_PERSPECTIVE
:
670 for (j
= 0; j
< NUM_CHANNELS
; j
++)
671 line_persp_coeff(setup
, slot
, j
);
679 * Plot a pixel in a line segment.
682 plot(struct setup_stage
*setup
, GLint x
, GLint y
)
684 const GLint iy
= y
& 1;
685 const GLint ix
= x
& 1;
686 const GLint quadX
= x
- ix
;
687 const GLint quadY
= y
- iy
;
688 const GLint mask
= (1 << ix
) << (2 * iy
);
690 if (quadX
!= setup
->quad
.x0
||
691 quadY
!= setup
->quad
.y0
)
693 /* flush prev quad, start new quad */
695 if (setup
->quad
.x0
!= -1)
696 quad_emit(setup
->softpipe
, &setup
->quad
);
698 setup
->quad
.x0
= quadX
;
699 setup
->quad
.y0
= quadY
;
700 setup
->quad
.mask
= 0x0;
703 setup
->quad
.mask
|= mask
;
709 * Do setup for line rasterization, then render the line.
710 * XXX single-pixel width, no stipple, etc
711 * XXX no scissoring yet.
714 setup_line(struct draw_stage
*stage
, struct prim_header
*prim
)
716 const struct vertex_header
*v0
= prim
->v
[0];
717 const struct vertex_header
*v1
= prim
->v
[1];
718 struct setup_stage
*setup
= setup_stage( stage
);
720 GLint x0
= (GLint
) v0
->data
[0][0];
721 GLint x1
= (GLint
) v1
->data
[0][0];
722 GLint y0
= (GLint
) v0
->data
[0][1];
723 GLint y1
= (GLint
) v1
->data
[0][1];
728 if (dx
== 0 && dy
== 0)
731 setup_line_coefficients(setup
, prim
);
734 dx
= -dx
; /* make positive */
742 dy
= -dy
; /* make positive */
752 setup
->quad
.x0
= setup
->quad
.y0
= -1;
753 setup
->quad
.mask
= 0x0;
756 /*** X-major line ***/
758 const GLint errorInc
= dy
+ dy
;
759 GLint error
= errorInc
- dx
;
760 const GLint errorDec
= error
- dx
;
762 for (i
= 0; i
< dx
; i
++) {
776 /*** Y-major line ***/
778 const GLint errorInc
= dx
+ dx
;
779 GLint error
= errorInc
- dy
;
780 const GLint errorDec
= error
- dy
;
782 for (i
= 0; i
< dy
; i
++) {
797 /* draw final quad */
798 if (setup
->quad
.mask
) {
799 quad_emit(setup
->softpipe
, &setup
->quad
);
805 * Do setup for point rasterization, then render the point.
806 * Round or square points...
807 * XXX could optimize a lot for 1-pixel points.
810 setup_point(struct draw_stage
*stage
, struct prim_header
*prim
)
812 struct setup_stage
*setup
= setup_stage( stage
);
813 /*XXX this should be a vertex attrib! */
814 GLfloat halfSize
= 0.5 * setup
->softpipe
->setup
.point_size
;
815 GLboolean round
= setup
->softpipe
->setup
.point_smooth
;
816 const struct vertex_header
*v0
= prim
->v
[0];
817 const GLfloat x
= v0
->data
[FRAG_ATTRIB_WPOS
][0];
818 const GLfloat y
= v0
->data
[FRAG_ATTRIB_WPOS
][1];
821 /* For points, all interpolants are constant-valued.
822 * However, for point sprites, we'll need to setup texcoords appropriately.
823 * XXX: which coefficients are the texcoords???
824 * We may do point sprites as textured quads...
826 * KW: We don't know which coefficients are texcoords - ultimately
827 * the choice of what interpolation mode to use for each attribute
828 * should be determined by the fragment program, using
829 * per-attribute declaration statements that include interpolation
830 * mode as a parameter. So either the fragment program will have
831 * to be adjusted for pointsprite vs normal point behaviour, or
832 * otherwise a special interpolation mode will have to be defined
833 * which matches the required behaviour for point sprites. But -
834 * the latter is not a feature of normal hardware, and as such
835 * probably should be ruled out on that basis.
837 setup
->vprovoke
= prim
->v
[0];
838 const_coeff(setup
, 0, 2);
839 const_coeff(setup
, 0, 3);
840 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
841 for (j
= 0; j
< NUM_CHANNELS
; j
++)
842 const_coeff(setup
, slot
, j
);
845 /* XXX need to clip against scissor bounds too */
847 if (halfSize
<= 0.5 && !round
) {
848 /* special case for 1-pixel points */
849 const GLint ix
= ((GLint
) x
) & 1;
850 const GLint iy
= ((GLint
) y
) & 1;
851 setup
->quad
.x0
= x
- ix
;
852 setup
->quad
.y0
= y
- iy
;
853 setup
->quad
.mask
= (1 << ix
) << (2 * iy
);
854 quad_emit(setup
->softpipe
, &setup
->quad
);
857 const GLint ixmin
= block((GLint
) (x
- halfSize
));
858 const GLint ixmax
= block((GLint
) (x
+ halfSize
));
859 const GLint iymin
= block((GLint
) (y
- halfSize
));
860 const GLint iymax
= block((GLint
) (y
+ halfSize
));
861 GLfloat halfSizeSquared
= halfSize
* halfSize
;
864 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
865 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
869 /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */
872 setup
->quad
.mask
= 0x0;
876 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
877 setup
->quad
.mask
|= MASK_BOTTOM_LEFT
;
881 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
882 setup
->quad
.mask
|= MASK_BOTTOM_RIGHT
;
886 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
887 setup
->quad
.mask
|= MASK_TOP_LEFT
;
891 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
892 setup
->quad
.mask
|= MASK_TOP_RIGHT
;
896 setup
->quad
.mask
= 0xf;
898 if (ix
+ 0.5 < x
- halfSize
)
899 setup
->quad
.mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
901 if (ix
+ 1.5 > x
+ halfSize
)
902 setup
->quad
.mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
904 if (iy
+ 0.5 < y
- halfSize
)
905 setup
->quad
.mask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
907 if (iy
+ 1.5 > y
+ halfSize
)
908 setup
->quad
.mask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
911 if (setup
->quad
.mask
) {
914 quad_emit( setup
->softpipe
, &setup
->quad
);
923 static void setup_begin( struct draw_stage
*stage
)
925 struct setup_stage
*setup
= setup_stage(stage
);
927 setup
->quad
.nr_attrs
= setup
->softpipe
->nr_frag_attrs
;
930 * XXX this is where we might map() the renderbuffers to begin
936 static void setup_end( struct draw_stage
*stage
)
939 * XXX this is where we might unmap() the renderbuffers after
946 * Create a new primitive setup/render stage.
948 struct draw_stage
*sp_draw_render_stage( struct softpipe_context
*softpipe
)
950 struct setup_stage
*setup
= CALLOC_STRUCT(setup_stage
);
952 setup
->softpipe
= softpipe
;
953 setup
->stage
.draw
= softpipe
->draw
;
954 setup
->stage
.begin
= setup_begin
;
955 setup
->stage
.point
= setup_point
;
956 setup
->stage
.line
= setup_line
;
957 setup
->stage
.tri
= setup_tri
;
958 setup
->stage
.end
= setup_end
;
960 setup
->quad
.coef
= setup
->coef
;
962 return &setup
->stage
;