1ca152911ebe623365f9abaf94d0bf138e2406cf
1 /**************************************************************************
3 * Copyright 2010, VMware, inc.
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 VMWARE 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 **************************************************************************/
30 static boolean
TAG(do_cliptest
)( struct pt_post_vs
*pvs
,
31 struct draw_vertex_info
*info
)
33 struct vertex_header
*out
= info
->verts
;
34 const float *scale
= pvs
->draw
->viewport
.scale
;
35 const float *trans
= pvs
->draw
->viewport
.translate
;
36 /* const */ float (*plane
)[4] = pvs
->draw
->plane
;
37 const unsigned pos
= draw_current_shader_position_output(pvs
->draw
);
38 const unsigned ef
= pvs
->draw
->vs
.edgeflag_output
;
39 const unsigned nr
= pvs
->draw
->nr_planes
;
40 const unsigned flags
= (FLAGS
);
41 unsigned need_pipeline
= 0;
44 for (j
= 0; j
< info
->count
; j
++) {
45 float *position
= out
->data
[pos
];
48 initialize_vertex_header(out
);
50 if (flags
& (DO_CLIP_XY
| DO_CLIP_XY_GUARD_BAND
|
51 DO_CLIP_FULL_Z
| DO_CLIP_HALF_Z
| DO_CLIP_USER
)) {
52 out
->clip
[0] = position
[0];
53 out
->clip
[1] = position
[1];
54 out
->clip
[2] = position
[2];
55 out
->clip
[3] = position
[3];
57 /* Do the hardwired planes first:
59 if (flags
& DO_CLIP_XY_GUARD_BAND
) {
60 if (-0.50 * position
[0] + position
[3] < 0) mask
|= (1<<0);
61 if ( 0.50 * position
[0] + position
[3] < 0) mask
|= (1<<1);
62 if (-0.50 * position
[1] + position
[3] < 0) mask
|= (1<<2);
63 if ( 0.50 * position
[1] + position
[3] < 0) mask
|= (1<<3);
65 else if (flags
& DO_CLIP_XY
) {
66 if (-position
[0] + position
[3] < 0) mask
|= (1<<0);
67 if ( position
[0] + position
[3] < 0) mask
|= (1<<1);
68 if (-position
[1] + position
[3] < 0) mask
|= (1<<2);
69 if ( position
[1] + position
[3] < 0) mask
|= (1<<3);
72 /* Clip Z planes according to full cube, half cube or none.
74 if (flags
& DO_CLIP_FULL_Z
) {
75 if ( position
[2] + position
[3] < 0) mask
|= (1<<4);
76 if (-position
[2] + position
[3] < 0) mask
|= (1<<5);
78 else if (flags
& DO_CLIP_HALF_Z
) {
79 if ( position
[2] < 0) mask
|= (1<<4);
80 if (-position
[2] + position
[3] < 0) mask
|= (1<<5);
83 if (flags
& DO_CLIP_USER
) {
85 for (i
= 6; i
< nr
; i
++) {
86 if (dot4(position
, plane
[i
]) < 0)
92 need_pipeline
|= out
->clipmask
;
95 if ((flags
& DO_VIEWPORT
) && mask
== 0)
98 float w
= 1.0f
/ position
[3];
100 /* Viewport mapping */
101 position
[0] = position
[0] * w
* scale
[0] + trans
[0];
102 position
[1] = position
[1] * w
* scale
[1] + trans
[1];
103 position
[2] = position
[2] * w
* scale
[2] + trans
[2];
107 if ((flags
& DO_EDGEFLAG
) && ef
) {
108 const float *edgeflag
= out
->data
[ef
];
109 out
->edgeflag
= !(edgeflag
[0] != 1.0f
);
110 need_pipeline
|= !out
->edgeflag
;
113 out
= (struct vertex_header
*)( (char *)out
+ info
->stride
);
116 return need_pipeline
!= 0;