1 #ifndef UTIL_BOX_INLINES_H
2 #define UTIL_BOX_INLINES_H
4 #include "pipe/p_state.h"
5 #include "util/u_math.h"
8 void u_box_1d( unsigned x
,
10 struct pipe_box
*box
)
21 void u_box_2d( unsigned x
,
25 struct pipe_box
*box
)
36 void u_box_origin_2d( unsigned w
,
38 struct pipe_box
*box
)
49 void u_box_2d_zslice( unsigned x
,
54 struct pipe_box
*box
)
65 void u_box_3d( unsigned x
,
71 struct pipe_box
*box
)
81 /* Clips @dst to width @w and height @h.
82 * Returns -1 if the resulting box would be empty (then @dst is left unchanged).
83 * 0 if nothing has been reduced.
84 * 1 if width has been reduced.
85 * 2 if height has been reduced.
86 * 3 if both width and height have been reduced.
90 u_box_clip_2d(struct pipe_box
*dst
,
91 const struct pipe_box
*box
, int w
, int h
)
94 int a
[2], b
[2], dim
[2];
98 if (!box
->width
|| !box
->height
)
104 b
[0] = box
->x
+ box
->width
;
105 b
[1] = box
->y
+ box
->height
;
107 for (i
= 0; i
< 2; ++i
) {
108 start
= (a
[i
] <= b
[i
]) ? &a
[i
] : &b
[i
];
109 end
= (a
[i
] <= b
[i
]) ? &b
[i
] : &a
[i
];
111 if (*end
< 0 || *start
>= dim
[i
])
126 dst
->width
= b
[0] - a
[0];
127 dst
->height
= b
[1] - a
[1];
132 static INLINE
int64_t
133 u_box_volume_3d(const struct pipe_box
*box
)
135 return (int64_t)box
->width
* box
->height
* box
->depth
;
138 /* Aliasing of @dst permitted. */
140 u_box_union_2d(struct pipe_box
*dst
,
141 const struct pipe_box
*a
, const struct pipe_box
*b
)
143 dst
->x
= MIN2(a
->x
, b
->x
);
144 dst
->y
= MIN2(a
->y
, b
->y
);
146 dst
->width
= MAX2(a
->x
+ a
->width
, b
->x
+ b
->width
) - dst
->x
;
147 dst
->height
= MAX2(a
->y
+ a
->height
, b
->y
+ b
->height
) - dst
->y
;
150 /* Aliasing of @dst permitted. */
152 u_box_union_3d(struct pipe_box
*dst
,
153 const struct pipe_box
*a
, const struct pipe_box
*b
)
155 dst
->x
= MIN2(a
->x
, b
->x
);
156 dst
->y
= MIN2(a
->y
, b
->y
);
157 dst
->z
= MIN2(a
->z
, b
->z
);
159 dst
->width
= MAX2(a
->x
+ a
->width
, b
->x
+ b
->width
) - dst
->x
;
160 dst
->height
= MAX2(a
->y
+ a
->height
, b
->y
+ b
->height
) - dst
->y
;
161 dst
->depth
= MAX2(a
->z
+ a
->depth
, b
->z
+ b
->depth
) - dst
->z
;
164 static INLINE boolean
165 u_box_test_intersection_2d(const struct pipe_box
*a
,
166 const struct pipe_box
*b
)
169 int a_l
[2], a_r
[2], b_l
[2], b_r
[2];
171 a_l
[0] = MIN2(a
->x
, a
->x
+ a
->width
);
172 a_r
[0] = MAX2(a
->x
, a
->x
+ a
->width
);
173 a_l
[1] = MIN2(a
->y
, a
->y
+ a
->height
);
174 a_r
[1] = MAX2(a
->y
, a
->y
+ a
->height
);
176 b_l
[0] = MIN2(b
->x
, b
->x
+ b
->width
);
177 b_r
[0] = MAX2(b
->x
, b
->x
+ b
->width
);
178 b_l
[1] = MIN2(b
->y
, b
->y
+ b
->height
);
179 b_r
[1] = MAX2(b
->y
, b
->y
+ b
->height
);
181 for (i
= 0; i
< 2; ++i
) {
182 if (a_l
[i
] > b_r
[i
] || a_r
[i
] < b_l
[i
])
189 u_box_minify_2d(struct pipe_box
*dst
,
190 const struct pipe_box
*src
, unsigned l
)
192 dst
->x
= src
->x
>> l
;
193 dst
->y
= src
->y
>> l
;
194 dst
->width
= MAX2(src
->width
>> l
, 1);
195 dst
->height
= MAX2(src
->height
>> l
, 1);