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
);
572 setup
->quad
.prim
= PRIM_TRI
;
575 setup
->span
.y_flags
= 0;
576 setup
->span
.right
[0] = 0;
577 setup
->span
.right
[1] = 0;
578 /* setup->span.z_mode = tri_z_mode( setup->ctx ); */
580 /* init_constant_attribs( setup ); */
582 if (setup
->oneoverarea
< 0.0) {
585 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
586 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
591 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
592 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
595 flush_spans( setup
);
601 * Compute a0, dadx and dady for a linearly interpolated coefficient,
605 line_linear_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
607 const GLfloat dz
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
608 const GLfloat dadx
= dz
* setup
->emaj
.dx
* setup
->oneoverarea
;
609 const GLfloat dady
= dz
* setup
->emaj
.dy
* setup
->oneoverarea
;
610 setup
->coef
[slot
].dadx
[i
] = dadx
;
611 setup
->coef
[slot
].dady
[i
] = dady
;
612 setup
->coef
[slot
].a0
[i
]
613 = (setup
->vmin
->data
[slot
][i
] -
614 (dadx
* (setup
->vmin
->data
[0][0] - 0.5) +
615 dady
* (setup
->vmin
->data
[0][1] - 0.5)));
620 * Compute a0, dadx and dady for a perspective-corrected interpolant,
624 line_persp_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
627 line_linear_coeff(setup
, slot
, i
); /* XXX temporary */
632 * Compute the setup->coef[] array dadx, dady, a0 values.
633 * Must be called after setup->vmin,vmax are initialized.
636 setup_line_coefficients(struct setup_stage
*setup
, struct prim_header
*prim
)
638 const enum interp_mode
*interp
= setup
->softpipe
->interp
;
641 /* use setup->vmin, vmax to point to vertices */
642 setup
->vprovoke
= prim
->v
[1];
643 setup
->vmin
= prim
->v
[0];
644 setup
->vmax
= prim
->v
[1];
646 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
647 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
648 /* NOTE: this is not really 1/area */
649 setup
->oneoverarea
= 1.0 / (setup
->emaj
.dx
* setup
->emaj
.dx
+
650 setup
->emaj
.dy
* setup
->emaj
.dy
);
652 /* z and w are done by linear interpolation:
654 line_linear_coeff(setup
, 0, 2);
655 line_linear_coeff(setup
, 0, 3);
657 /* setup interpolation for all the remaining attributes:
659 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
660 switch (interp
[slot
]) {
661 case INTERP_CONSTANT
:
662 for (j
= 0; j
< NUM_CHANNELS
; j
++)
663 const_coeff(setup
, slot
, j
);
667 for (j
= 0; j
< NUM_CHANNELS
; j
++)
668 line_linear_coeff(setup
, slot
, j
);
671 case INTERP_PERSPECTIVE
:
672 for (j
= 0; j
< NUM_CHANNELS
; j
++)
673 line_persp_coeff(setup
, slot
, j
);
681 * Plot a pixel in a line segment.
684 plot(struct setup_stage
*setup
, GLint x
, GLint y
)
686 const GLint iy
= y
& 1;
687 const GLint ix
= x
& 1;
688 const GLint quadX
= x
- ix
;
689 const GLint quadY
= y
- iy
;
690 const GLint mask
= (1 << ix
) << (2 * iy
);
692 if (quadX
!= setup
->quad
.x0
||
693 quadY
!= setup
->quad
.y0
)
695 /* flush prev quad, start new quad */
697 if (setup
->quad
.x0
!= -1)
698 quad_emit(setup
->softpipe
, &setup
->quad
);
700 setup
->quad
.x0
= quadX
;
701 setup
->quad
.y0
= quadY
;
702 setup
->quad
.mask
= 0x0;
705 setup
->quad
.mask
|= mask
;
711 * Do setup for line rasterization, then render the line.
712 * XXX single-pixel width, no stipple, etc
713 * XXX no scissoring yet.
716 setup_line(struct draw_stage
*stage
, struct prim_header
*prim
)
718 const struct vertex_header
*v0
= prim
->v
[0];
719 const struct vertex_header
*v1
= prim
->v
[1];
720 struct setup_stage
*setup
= setup_stage( stage
);
722 GLint x0
= (GLint
) v0
->data
[0][0];
723 GLint x1
= (GLint
) v1
->data
[0][0];
724 GLint y0
= (GLint
) v0
->data
[0][1];
725 GLint y1
= (GLint
) v1
->data
[0][1];
730 if (dx
== 0 && dy
== 0)
733 setup_line_coefficients(setup
, prim
);
736 dx
= -dx
; /* make positive */
744 dy
= -dy
; /* make positive */
754 setup
->quad
.x0
= setup
->quad
.y0
= -1;
755 setup
->quad
.mask
= 0x0;
756 setup
->quad
.prim
= PRIM_LINE
;
759 /*** X-major line ***/
761 const GLint errorInc
= dy
+ dy
;
762 GLint error
= errorInc
- dx
;
763 const GLint errorDec
= error
- dx
;
765 for (i
= 0; i
< dx
; i
++) {
779 /*** Y-major line ***/
781 const GLint errorInc
= dx
+ dx
;
782 GLint error
= errorInc
- dy
;
783 const GLint errorDec
= error
- dy
;
785 for (i
= 0; i
< dy
; i
++) {
800 /* draw final quad */
801 if (setup
->quad
.mask
) {
802 quad_emit(setup
->softpipe
, &setup
->quad
);
808 * Do setup for point rasterization, then render the point.
809 * Round or square points...
810 * XXX could optimize a lot for 1-pixel points.
813 setup_point(struct draw_stage
*stage
, struct prim_header
*prim
)
815 struct setup_stage
*setup
= setup_stage( stage
);
816 /*XXX this should be a vertex attrib! */
817 GLfloat halfSize
= 0.5 * setup
->softpipe
->setup
.point_size
;
818 GLboolean round
= setup
->softpipe
->setup
.point_smooth
;
819 const struct vertex_header
*v0
= prim
->v
[0];
820 const GLfloat x
= v0
->data
[FRAG_ATTRIB_WPOS
][0];
821 const GLfloat y
= v0
->data
[FRAG_ATTRIB_WPOS
][1];
824 /* For points, all interpolants are constant-valued.
825 * However, for point sprites, we'll need to setup texcoords appropriately.
826 * XXX: which coefficients are the texcoords???
827 * We may do point sprites as textured quads...
829 * KW: We don't know which coefficients are texcoords - ultimately
830 * the choice of what interpolation mode to use for each attribute
831 * should be determined by the fragment program, using
832 * per-attribute declaration statements that include interpolation
833 * mode as a parameter. So either the fragment program will have
834 * to be adjusted for pointsprite vs normal point behaviour, or
835 * otherwise a special interpolation mode will have to be defined
836 * which matches the required behaviour for point sprites. But -
837 * the latter is not a feature of normal hardware, and as such
838 * probably should be ruled out on that basis.
840 setup
->vprovoke
= prim
->v
[0];
841 const_coeff(setup
, 0, 2);
842 const_coeff(setup
, 0, 3);
843 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
844 for (j
= 0; j
< NUM_CHANNELS
; j
++)
845 const_coeff(setup
, slot
, j
);
848 setup
->quad
.prim
= PRIM_POINT
;
850 /* XXX need to clip against scissor bounds too */
852 if (halfSize
<= 0.5 && !round
) {
853 /* special case for 1-pixel points */
854 const GLint ix
= ((GLint
) x
) & 1;
855 const GLint iy
= ((GLint
) y
) & 1;
856 setup
->quad
.x0
= x
- ix
;
857 setup
->quad
.y0
= y
- iy
;
858 setup
->quad
.mask
= (1 << ix
) << (2 * iy
);
859 quad_emit(setup
->softpipe
, &setup
->quad
);
862 const GLint ixmin
= block((GLint
) (x
- halfSize
));
863 const GLint ixmax
= block((GLint
) (x
+ halfSize
));
864 const GLint iymin
= block((GLint
) (y
- halfSize
));
865 const GLint iymax
= block((GLint
) (y
+ halfSize
));
870 const GLfloat rmin
= halfSize
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
871 const GLfloat rmax
= halfSize
+ 0.7071F
;
872 const GLfloat rmin2
= MAX2(0.0F
, rmin
* rmin
);
873 const GLfloat rmax2
= rmax
* rmax
;
874 const GLfloat cscale
= 1.0F
/ (rmax2
- rmin2
);
876 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
877 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
878 GLfloat dx
, dy
, dist2
, cover
;
880 setup
->quad
.mask
= 0x0;
884 dist2
= dx
* dx
+ dy
* dy
;
885 if (dist2
<= rmax2
) {
886 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
887 setup
->quad
.coverage
[QUAD_BOTTOM_LEFT
] = MIN2(cover
, 1.0);
888 setup
->quad
.mask
|= MASK_BOTTOM_LEFT
;
893 dist2
= dx
* dx
+ dy
* dy
;
894 if (dist2
<= rmax2
) {
895 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
896 setup
->quad
.coverage
[QUAD_BOTTOM_RIGHT
] = MIN2(cover
, 1.0);
897 setup
->quad
.mask
|= MASK_BOTTOM_RIGHT
;
902 dist2
= dx
* dx
+ dy
* dy
;
903 if (dist2
<= rmax2
) {
904 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
905 setup
->quad
.coverage
[QUAD_TOP_LEFT
] = MIN2(cover
, 1.0);
906 setup
->quad
.mask
|= MASK_TOP_LEFT
;
911 dist2
= dx
* dx
+ dy
* dy
;
912 if (dist2
<= rmax2
) {
913 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
914 setup
->quad
.coverage
[QUAD_TOP_RIGHT
] = MIN2(cover
, 1.0);
915 setup
->quad
.mask
|= MASK_TOP_RIGHT
;
918 if (setup
->quad
.mask
) {
921 quad_emit( setup
->softpipe
, &setup
->quad
);
928 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
929 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
930 setup
->quad
.mask
= 0xf;
932 if (ix
+ 0.5 < x
- halfSize
) {
933 /* fragment is past left edge of point, turn off left bits */
934 setup
->quad
.mask
&= ~(MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
937 if (ix
+ 1.5 > x
+ halfSize
) {
938 /* past the right edge */
939 setup
->quad
.mask
&= ~(MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
942 if (iy
+ 0.5 < y
- halfSize
) {
943 /* below the bottom edge */
944 setup
->quad
.mask
&= ~(MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
947 if (iy
+ 1.5 > y
+ halfSize
) {
948 /* above the top edge */
949 setup
->quad
.mask
&= ~(MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
952 if (setup
->quad
.mask
) {
955 quad_emit( setup
->softpipe
, &setup
->quad
);
965 static void setup_begin( struct draw_stage
*stage
)
967 struct setup_stage
*setup
= setup_stage(stage
);
969 setup
->quad
.nr_attrs
= setup
->softpipe
->nr_frag_attrs
;
972 * XXX this is where we might map() the renderbuffers to begin
978 static void setup_end( struct draw_stage
*stage
)
981 * XXX this is where we might unmap() the renderbuffers after
988 * Create a new primitive setup/render stage.
990 struct draw_stage
*sp_draw_render_stage( struct softpipe_context
*softpipe
)
992 struct setup_stage
*setup
= CALLOC_STRUCT(setup_stage
);
994 setup
->softpipe
= softpipe
;
995 setup
->stage
.draw
= softpipe
->draw
;
996 setup
->stage
.begin
= setup_begin
;
997 setup
->stage
.point
= setup_point
;
998 setup
->stage
.line
= setup_line
;
999 setup
->stage
.tri
= setup_tri
;
1000 setup
->stage
.end
= setup_end
;
1002 setup
->quad
.coef
= setup
->coef
;
1004 return &setup
->stage
;