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"
35 #include "sp_headers.h"
36 #include "pipe/draw/draw_private.h"
38 #include "sp_prim_setup.h"
44 * This passes the quad to the first stage of per-fragment operations.
47 quad_emit(struct softpipe_context
*sp
, struct quad_header
*quad
)
49 sp
->quad
.first
->run(sp
->quad
.first
, quad
);
57 GLfloat dx
; /* X(v1) - X(v0), used only during setup */
58 GLfloat dy
; /* Y(v1) - Y(v0), used only during setup */
59 GLfloat dxdy
; /* dx/dy */
60 GLfloat sx
; /* first sample point x coord */
62 GLint lines
; /* number of lines on this edge */
67 * Triangle setup info (derived from prim_stage).
68 * Also used for line drawing (taking some liberties).
71 struct prim_stage stage
; /**< This must be first (base class) */
74 struct softpipe_context
*softpipe
;
76 /* Vertices are just an array of floats making up each attribute in
77 * turn. Currently fixed at 4 floats, but should change in time.
78 * Codegen will help cope with this.
80 const struct vertex_header
*vmax
;
81 const struct vertex_header
*vmid
;
82 const struct vertex_header
*vmin
;
83 const struct vertex_header
*vprovoke
;
91 struct setup_coefficient coef
[FRAG_ATTRIB_MAX
];
92 struct quad_header quad
;
95 GLint left
[2]; /**< [0] = row0, [1] = row1 */
99 GLuint mask
; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
106 * Basically a cast wrapper.
108 static inline struct setup_stage
*setup_stage( struct prim_stage
*stage
)
110 return (struct setup_stage
*)stage
;
115 * Given an X or Y coordinate, return the block/quad coordinate that it
118 static inline GLint
block( GLint x
)
125 static void setup_begin( struct prim_stage
*stage
)
127 struct setup_stage
*setup
= setup_stage(stage
);
129 setup
->quad
.nr_attrs
= setup
->softpipe
->nr_frag_attrs
;
134 * Run shader on a quad/block.
136 static void run_shader_block( struct setup_stage
*setup
,
137 GLint x
, GLint y
, GLuint mask
)
141 setup
->quad
.mask
= mask
;
143 quad_emit(setup
->softpipe
, &setup
->quad
);
148 * Compute mask which indicates which pixels in the 2x2 quad are actually inside
149 * the triangle's bounds.
151 * this is pretty nasty... may need to rework flush_spans again to
152 * fix it, if possible.
154 static GLuint
calculate_mask( struct setup_stage
*setup
,
159 if (x
>= setup
->span
.left
[0] && x
< setup
->span
.right
[0])
160 mask
|= MASK_BOTTOM_LEFT
;
162 if (x
>= setup
->span
.left
[1] && x
< setup
->span
.right
[1])
163 mask
|= MASK_TOP_LEFT
;
165 if (x
+1 >= setup
->span
.left
[0] && x
+1 < setup
->span
.right
[0])
166 mask
|= MASK_BOTTOM_RIGHT
;
168 if (x
+1 >= setup
->span
.left
[1] && x
+1 < setup
->span
.right
[1])
169 mask
|= MASK_TOP_RIGHT
;
176 * Render a horizontal span of quads
178 static void flush_spans( struct setup_stage
*setup
)
180 GLint minleft
, maxright
;
183 switch (setup
->span
.y_flags
) {
185 minleft
= MIN2(setup
->span
.left
[0], setup
->span
.left
[1]);
186 maxright
= MAX2(setup
->span
.right
[0], setup
->span
.right
[1]);
190 minleft
= setup
->span
.left
[0];
191 maxright
= setup
->span
.right
[0];
195 minleft
= setup
->span
.left
[1];
196 maxright
= setup
->span
.right
[1];
204 for (x
= block(minleft
); x
<= block(maxright
); )
206 run_shader_block( setup
, x
,
208 calculate_mask( setup
, x
) );
213 setup
->span
.y_flags
= 0;
214 setup
->span
.right
[0] = 0;
215 setup
->span
.right
[1] = 0;
219 static GLboolean
setup_sort_vertices( struct setup_stage
*setup
,
220 const struct prim_header
*prim
)
222 const struct vertex_header
*v0
= prim
->v
[0];
223 const struct vertex_header
*v1
= prim
->v
[1];
224 const struct vertex_header
*v2
= prim
->v
[2];
226 setup
->vprovoke
= v2
;
228 /* determine bottom to top order of vertices */
230 GLfloat y0
= v0
->data
[0][1];
231 GLfloat y1
= v1
->data
[0][1];
232 GLfloat y2
= v2
->data
[0][1];
275 setup
->ebot
.dx
= setup
->vmid
->data
[0][0] - setup
->vmin
->data
[0][0];
276 setup
->ebot
.dy
= setup
->vmid
->data
[0][1] - setup
->vmin
->data
[0][1];
277 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
278 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
279 setup
->etop
.dx
= setup
->vmax
->data
[0][0] - setup
->vmid
->data
[0][0];
280 setup
->etop
.dy
= setup
->vmax
->data
[0][1] - setup
->vmid
->data
[0][1];
283 * Compute triangle's area. Use 1/area to compute partial
284 * derivatives of attributes later.
286 * The area will be the same as prim->det, but the sign may be
287 * different depending on how the vertices get sorted above.
289 * To determine whether the primitive is front or back facing we
290 * use the prim->det value because its sign is correct.
293 const GLfloat area
= (setup
->emaj
.dx
* setup
->ebot
.dy
-
294 setup
->ebot
.dx
* setup
->emaj
.dy
);
296 setup
->oneoverarea
= 1.0 / area
;
298 _mesa_printf("%s one-over-area %f area %f det %f\n",
299 __FUNCTION__, setup->oneoverarea, area, prim->det );
303 /* We need to know if this is a front or back-facing triangle for:
304 * - the GLSL gl_FrontFacing fragment attribute (bool)
305 * - two-sided stencil test
307 setup
->quad
.facing
= (prim
->det
> 0.0) ^ (setup
->softpipe
->setup
.front_winding
== PIPE_WINDING_CW
);
314 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
315 * The value value comes from vertex->data[slot][i].
316 * The result will be put into setup->coef[slot].a0[i].
317 * \param slot which attribute slot
318 * \param i which component of the slot (0..3)
320 static void const_coeff( struct setup_stage
*setup
,
324 assert(slot
< FRAG_ATTRIB_MAX
);
327 setup
->coef
[slot
].dadx
[i
] = 0;
328 setup
->coef
[slot
].dady
[i
] = 0;
330 /* need provoking vertex info!
332 setup
->coef
[slot
].a0
[i
] = setup
->vprovoke
->data
[slot
][i
];
337 * Compute a0, dadx and dady for a linearly interpolated coefficient,
340 static void tri_linear_coeff( struct setup_stage
*setup
,
344 GLfloat botda
= setup
->vmid
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
345 GLfloat majda
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
346 GLfloat a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
347 GLfloat b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
349 assert(slot
< FRAG_ATTRIB_MAX
);
352 setup
->coef
[slot
].dadx
[i
] = a
* setup
->oneoverarea
;
353 setup
->coef
[slot
].dady
[i
] = b
* setup
->oneoverarea
;
355 /* calculate a0 as the value which would be sampled for the
356 * fragment at (0,0), taking into account that we want to sample at
357 * pixel centers, in other words (0.5, 0.5).
359 * this is neat but unfortunately not a good way to do things for
360 * triangles with very large values of dadx or dady as it will
361 * result in the subtraction and re-addition from a0 of a very
362 * large number, which means we'll end up loosing a lot of the
363 * fractional bits and precision from a0. the way to fix this is
364 * to define a0 as the sample at a pixel center somewhere near vmin
365 * instead - i'll switch to this later.
367 setup
->coef
[slot
].a0
[i
] = (setup
->vmin
->data
[slot
][i
] -
368 (setup
->coef
[slot
].dadx
[i
] * (setup
->vmin
->data
[0][0] - 0.5) +
369 setup
->coef
[slot
].dady
[i
] * (setup
->vmin
->data
[0][1] - 0.5)));
371 _mesa_printf("attr[%d].%c: %f dx:%f dy:%f\n",
373 setup
->coef
[slot
].a0
[i
],
374 setup
->coef
[slot
].dadx
[i
],
375 setup
->coef
[slot
].dady
[i
]);
380 * Compute a0, dadx and dady for a perspective-corrected interpolant,
383 static void tri_persp_coeff( struct setup_stage
*setup
,
387 /* premultiply by 1/w:
389 GLfloat mina
= setup
->vmin
->data
[slot
][i
] * setup
->vmin
->data
[0][3];
390 GLfloat mida
= setup
->vmid
->data
[slot
][i
] * setup
->vmid
->data
[0][3];
391 GLfloat maxa
= setup
->vmax
->data
[slot
][i
] * setup
->vmax
->data
[0][3];
393 GLfloat botda
= mida
- mina
;
394 GLfloat majda
= maxa
- mina
;
395 GLfloat a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
396 GLfloat b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
398 assert(slot
< FRAG_ATTRIB_MAX
);
401 setup
->coef
[slot
].dadx
[i
] = a
* setup
->oneoverarea
;
402 setup
->coef
[slot
].dady
[i
] = b
* setup
->oneoverarea
;
403 setup
->coef
[slot
].a0
[i
] = (mina
-
404 (setup
->coef
[slot
].dadx
[i
] * (setup
->vmin
->data
[0][0] - 0.5) +
405 setup
->coef
[slot
].dady
[i
] * (setup
->vmin
->data
[0][1] - 0.5)));
411 * Compute the setup->coef[] array dadx, dady, a0 values.
412 * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
414 static void setup_tri_coefficients( struct setup_stage
*setup
)
416 const enum interp_mode
*interp
= setup
->softpipe
->interp
;
419 /* z and w are done by linear interpolation:
421 tri_linear_coeff(setup
, 0, 2);
422 tri_linear_coeff(setup
, 0, 3);
424 /* setup interpolation for all the remaining attributes:
426 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
427 switch (interp
[slot
]) {
428 case INTERP_CONSTANT
:
429 for (j
= 0; j
< NUM_CHANNELS
; j
++)
430 const_coeff(setup
, slot
, j
);
434 for (j
= 0; j
< NUM_CHANNELS
; j
++)
435 tri_linear_coeff(setup
, slot
, j
);
438 case INTERP_PERSPECTIVE
:
439 for (j
= 0; j
< NUM_CHANNELS
; j
++)
440 tri_persp_coeff(setup
, slot
, j
);
448 static void setup_tri_edges( struct setup_stage
*setup
)
450 GLfloat vmin_x
= setup
->vmin
->data
[0][0] + 0.5;
451 GLfloat vmid_x
= setup
->vmid
->data
[0][0] + 0.5;
453 GLfloat vmin_y
= setup
->vmin
->data
[0][1] - 0.5;
454 GLfloat vmid_y
= setup
->vmid
->data
[0][1] - 0.5;
455 GLfloat vmax_y
= setup
->vmax
->data
[0][1] - 0.5;
457 setup
->emaj
.sy
= ceilf(vmin_y
);
458 setup
->emaj
.lines
= (GLint
) ceilf(vmax_y
- setup
->emaj
.sy
);
459 setup
->emaj
.dxdy
= setup
->emaj
.dx
/ setup
->emaj
.dy
;
460 setup
->emaj
.sx
= vmin_x
+ (setup
->emaj
.sy
- vmin_y
) * setup
->emaj
.dxdy
;
462 setup
->etop
.sy
= ceilf(vmid_y
);
463 setup
->etop
.lines
= (GLint
) ceilf(vmax_y
- setup
->etop
.sy
);
464 setup
->etop
.dxdy
= setup
->etop
.dx
/ setup
->etop
.dy
;
465 setup
->etop
.sx
= vmid_x
+ (setup
->etop
.sy
- vmid_y
) * setup
->etop
.dxdy
;
467 setup
->ebot
.sy
= ceilf(vmin_y
);
468 setup
->ebot
.lines
= (GLint
) ceilf(vmid_y
- setup
->ebot
.sy
);
469 setup
->ebot
.dxdy
= setup
->ebot
.dx
/ setup
->ebot
.dy
;
470 setup
->ebot
.sx
= vmin_x
+ (setup
->ebot
.sy
- vmin_y
) * setup
->ebot
.dxdy
;
475 * Render the upper or lower half of a triangle.
476 * Scissoring is applied here too.
478 static void subtriangle( struct setup_stage
*setup
,
483 GLint y
, start_y
, finish_y
;
484 GLint sy
= (GLint
)eleft
->sy
;
486 assert((GLint
)eleft
->sy
== (GLint
) eright
->sy
);
487 assert((GLint
)eleft
->sy
>= 0); /* catch bug in x64? */
491 if (setup
->softpipe
->setup
.scissor
) {
493 finish_y
= start_y
+ lines
;
495 if (start_y
< setup
->softpipe
->scissor
.miny
)
496 start_y
= setup
->softpipe
->scissor
.miny
;
498 if (finish_y
> setup
->softpipe
->scissor
.maxy
)
499 finish_y
= setup
->softpipe
->scissor
.maxy
;
509 _mesa_printf("%s %d %d\n", __FUNCTION__
, start_y
, finish_y
);
511 for (y
= start_y
; y
< finish_y
; y
++) {
513 /* avoid accumulating adds as floats don't have the precision to
514 * accurately iterate large triangle edges that way. luckily we
515 * can just multiply these days.
517 * this is all drowned out by the attribute interpolation anyway.
519 GLint left
= (GLint
)(eleft
->sx
+ y
* eleft
->dxdy
);
520 GLint right
= (GLint
)(eright
->sx
+ y
* eright
->dxdy
);
524 if (setup
->softpipe
->setup
.scissor
) {
525 if (left
< setup
->softpipe
->scissor
.minx
)
526 left
= setup
->softpipe
->scissor
.minx
;
528 if (right
> setup
->softpipe
->scissor
.maxx
)
529 right
= setup
->softpipe
->scissor
.maxx
;
534 if (block(_y
) != setup
->span
.y
) {
536 setup
->span
.y
= block(_y
);
539 setup
->span
.left
[_y
&1] = left
;
540 setup
->span
.right
[_y
&1] = right
;
541 setup
->span
.y_flags
|= 1<<(_y
&1);
546 /* save the values so that emaj can be restarted:
548 eleft
->sx
+= lines
* eleft
->dxdy
;
549 eright
->sx
+= lines
* eright
->dxdy
;
556 * Do setup for triangle rasterization, then render the triangle.
558 static void setup_tri( struct prim_stage
*stage
,
559 struct prim_header
*prim
)
561 struct setup_stage
*setup
= setup_stage( stage
);
563 _mesa_printf("%s\n", __FUNCTION__
);
565 setup_sort_vertices( setup
, prim
);
566 setup_tri_coefficients( setup
);
567 setup_tri_edges( setup
);
570 setup
->span
.y_flags
= 0;
571 setup
->span
.right
[0] = 0;
572 setup
->span
.right
[1] = 0;
573 // setup->span.z_mode = tri_z_mode( setup->ctx );
575 // init_constant_attribs( setup );
577 if (setup
->oneoverarea
< 0.0) {
580 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
581 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
586 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
587 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
590 flush_spans( setup
);
596 * Compute a0, dadx and dady for a linearly interpolated coefficient,
600 line_linear_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
602 const GLfloat dz
= setup
->vmax
->data
[slot
][i
] - setup
->vmin
->data
[slot
][i
];
603 const GLfloat dadx
= dz
* setup
->emaj
.dx
* setup
->oneoverarea
;
604 const GLfloat dady
= dz
* setup
->emaj
.dy
* setup
->oneoverarea
;
605 setup
->coef
[slot
].dadx
[i
] = dadx
;
606 setup
->coef
[slot
].dady
[i
] = dady
;
607 setup
->coef
[slot
].a0
[i
]
608 = (setup
->vmin
->data
[slot
][i
] -
609 (dadx
* (setup
->vmin
->data
[0][0] - 0.5) +
610 dady
* (setup
->vmin
->data
[0][1] - 0.5)));
615 * Compute a0, dadx and dady for a perspective-corrected interpolant,
619 line_persp_coeff(struct setup_stage
*setup
, GLuint slot
, GLuint i
)
622 line_linear_coeff(setup
, slot
, i
); /* XXX temporary */
627 * Compute the setup->coef[] array dadx, dady, a0 values.
628 * Must be called after setup->vmin,vmax are initialized.
631 setup_line_coefficients(struct setup_stage
*setup
, struct prim_header
*prim
)
633 const enum interp_mode
*interp
= setup
->softpipe
->interp
;
636 /* use setup->vmin, vmax to point to vertices */
637 setup
->vprovoke
= prim
->v
[1];
638 setup
->vmin
= prim
->v
[0];
639 setup
->vmax
= prim
->v
[1];
641 setup
->emaj
.dx
= setup
->vmax
->data
[0][0] - setup
->vmin
->data
[0][0];
642 setup
->emaj
.dy
= setup
->vmax
->data
[0][1] - setup
->vmin
->data
[0][1];
643 /* NOTE: this is not really 1/area */
644 setup
->oneoverarea
= 1.0 / (setup
->emaj
.dx
* setup
->emaj
.dx
+
645 setup
->emaj
.dy
* setup
->emaj
.dy
);
647 /* z and w are done by linear interpolation:
649 line_linear_coeff(setup
, 0, 2);
650 line_linear_coeff(setup
, 0, 3);
652 /* setup interpolation for all the remaining attributes:
654 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
655 switch (interp
[slot
]) {
656 case INTERP_CONSTANT
:
657 for (j
= 0; j
< NUM_CHANNELS
; j
++)
658 const_coeff(setup
, slot
, j
);
662 for (j
= 0; j
< NUM_CHANNELS
; j
++)
663 line_linear_coeff(setup
, slot
, j
);
666 case INTERP_PERSPECTIVE
:
667 for (j
= 0; j
< NUM_CHANNELS
; j
++)
668 line_persp_coeff(setup
, slot
, j
);
676 * Plot a pixel in a line segment.
679 plot(struct setup_stage
*setup
, GLint x
, GLint y
)
681 const GLint iy
= y
& 1;
682 const GLint ix
= x
& 1;
683 const GLint quadX
= x
- ix
;
684 const GLint quadY
= y
- iy
;
685 const GLint mask
= (1 << ix
) << (2 * iy
);
687 if (quadX
!= setup
->quad
.x0
||
688 quadY
!= setup
->quad
.y0
)
690 /* flush prev quad, start new quad */
692 if (setup
->quad
.x0
!= -1)
693 quad_emit(setup
->softpipe
, &setup
->quad
);
695 setup
->quad
.x0
= quadX
;
696 setup
->quad
.y0
= quadY
;
697 setup
->quad
.mask
= 0x0;
700 setup
->quad
.mask
|= mask
;
706 * Do setup for line rasterization, then render the line.
707 * XXX single-pixel width, no stipple, etc
708 * XXX no scissoring yet.
711 setup_line(struct prim_stage
*stage
, struct prim_header
*prim
)
713 const struct vertex_header
*v0
= prim
->v
[0];
714 const struct vertex_header
*v1
= prim
->v
[1];
715 struct setup_stage
*setup
= setup_stage( stage
);
717 GLint x0
= (GLint
) v0
->data
[0][0];
718 GLint x1
= (GLint
) v1
->data
[0][0];
719 GLint y0
= (GLint
) v0
->data
[0][1];
720 GLint y1
= (GLint
) v1
->data
[0][1];
725 if (dx
== 0 && dy
== 0)
728 setup_line_coefficients(setup
, prim
);
731 dx
= -dx
; /* make positive */
739 dy
= -dy
; /* make positive */
749 setup
->quad
.x0
= setup
->quad
.y0
= -1;
750 setup
->quad
.mask
= 0x0;
753 /*** X-major line ***/
755 const GLint errorInc
= dy
+ dy
;
756 GLint error
= errorInc
- dx
;
757 const GLint errorDec
= error
- dx
;
759 for (i
= 0; i
< dx
; i
++) {
773 /*** Y-major line ***/
775 const GLint errorInc
= dx
+ dx
;
776 GLint error
= errorInc
- dy
;
777 const GLint errorDec
= error
- dy
;
779 for (i
= 0; i
< dy
; i
++) {
794 /* draw final quad */
795 if (setup
->quad
.mask
) {
796 quad_emit(setup
->softpipe
, &setup
->quad
);
802 * Do setup for point rasterization, then render the point.
803 * Round or square points...
804 * XXX could optimize a lot for 1-pixel points.
807 setup_point(struct prim_stage
*stage
, struct prim_header
*prim
)
809 struct setup_stage
*setup
= setup_stage( stage
);
810 /*XXX this should be a vertex attrib! */
811 GLfloat halfSize
= 0.5 * setup
->softpipe
->setup
.point_size
;
812 GLboolean round
= setup
->softpipe
->setup
.point_smooth
;
813 const struct vertex_header
*v0
= prim
->v
[0];
814 const GLfloat x
= v0
->data
[FRAG_ATTRIB_WPOS
][0];
815 const GLfloat y
= v0
->data
[FRAG_ATTRIB_WPOS
][1];
818 /* For points, all interpolants are constant-valued.
819 * However, for point sprites, we'll need to setup texcoords appropriately.
820 * XXX: which coefficients are the texcoords???
821 * We may do point sprites as textured quads...
823 * KW: We don't know which coefficients are texcoords - ultimately
824 * the choice of what interpolation mode to use for each attribute
825 * should be determined by the fragment program, using
826 * per-attribute declaration statements that include interpolation
827 * mode as a parameter. So either the fragment program will have
828 * to be adjusted for pointsprite vs normal point behaviour, or
829 * otherwise a special interpolation mode will have to be defined
830 * which matches the required behaviour for point sprites. But -
831 * the latter is not a feature of normal hardware, and as such
832 * probably should be ruled out on that basis.
834 setup
->vprovoke
= prim
->v
[0];
835 const_coeff(setup
, 0, 2);
836 const_coeff(setup
, 0, 3);
837 for (slot
= 1; slot
< setup
->quad
.nr_attrs
; slot
++) {
838 for (j
= 0; j
< NUM_CHANNELS
; j
++)
839 const_coeff(setup
, slot
, j
);
842 /* XXX need to clip against scissor bounds too */
844 if (halfSize
<= 0.5 && !round
) {
845 /* special case for 1-pixel points */
846 const GLint ix
= ((GLint
) x
) & 1;
847 const GLint iy
= ((GLint
) y
) & 1;
848 setup
->quad
.x0
= x
- ix
;
849 setup
->quad
.y0
= y
- iy
;
850 setup
->quad
.mask
= (1 << ix
) << (2 * iy
);
851 quad_emit(setup
->softpipe
, &setup
->quad
);
854 const GLint ixmin
= block((GLint
) (x
- halfSize
));
855 const GLint ixmax
= block((GLint
) (x
+ halfSize
));
856 const GLint iymin
= block((GLint
) (y
- halfSize
));
857 const GLint iymax
= block((GLint
) (y
+ halfSize
));
858 GLfloat halfSizeSquared
= halfSize
* halfSize
;
861 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
862 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
866 /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */
869 setup
->quad
.mask
= 0x0;
873 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
874 setup
->quad
.mask
|= MASK_BOTTOM_LEFT
;
878 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
879 setup
->quad
.mask
|= MASK_BOTTOM_RIGHT
;
883 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
884 setup
->quad
.mask
|= MASK_TOP_LEFT
;
888 if (dx
* dx
+ dy
* dy
<= halfSizeSquared
)
889 setup
->quad
.mask
|= MASK_TOP_RIGHT
;
893 setup
->quad
.mask
= 0xf;
895 if (ix
+ 0.5 < x
- halfSize
)
896 setup
->quad
.mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
898 if (ix
+ 1.5 > x
+ halfSize
)
899 setup
->quad
.mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
901 if (iy
+ 0.5 < y
- halfSize
)
902 setup
->quad
.mask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
904 if (iy
+ 1.5 > y
+ halfSize
)
905 setup
->quad
.mask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
908 if (setup
->quad
.mask
) {
911 quad_emit( setup
->softpipe
, &setup
->quad
);
920 static void setup_end( struct prim_stage
*stage
)
925 struct prim_stage
*prim_setup( struct softpipe_context
*softpipe
)
927 struct setup_stage
*setup
= CALLOC_STRUCT(setup_stage
);
929 setup
->softpipe
= softpipe
;
930 setup
->stage
.draw
= softpipe
->draw
;
931 setup
->stage
.begin
= setup_begin
;
932 setup
->stage
.point
= setup_point
;
933 setup
->stage
.line
= setup_line
;
934 setup
->stage
.tri
= setup_tri
;
935 setup
->stage
.end
= setup_end
;
937 setup
->quad
.coef
= setup
->coef
;
939 return &setup
->stage
;