New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 2D axis-aligned bounding box type #259
base: master
Are you sure you want to change the base?
Conversation
Like graphene_box_t, but for 2D areas. It's more efficient than rectangles, at the cost of legibility.
{ | ||
/*< private >*/ | ||
GRAPHENE_PRIVATE_FIELD (graphene_vec2_t, min); | ||
GRAPHENE_PRIVATE_FIELD (graphene_vec2_t, max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a single graphene_vec4_t
because the vec2's are just vec4's in disguise afaik?
The Rect type in GSK's Vulkan shader uses a vec4 itself, and that worked really well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial lane reads are always slower than full lane ones; if we store the min/max in the same SIMD type like this:
| min_x | min_y | max_x | max_y |
then it should be possible to optimise the access using:
graphene_simd4f_t min = graphene_simd4f_merge_low (box->value, graphene_sim4f_zero ());
graphene_simd4f_t max = graphene_simd4f_merge_high (box->value, graphene_simd4f_zero ());
graphene_point_t *max); | ||
GRAPHENE_AVAILABLE_IN_1_12 | ||
void graphene_box2d_get_vertices (const graphene_box2d_t *box, | ||
graphene_vec2_t vertices[]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A graphene_box2d_to_float (box, float[4])
would come in handy here for uploading to GLSL.
GRAPHENE_AVAILABLE_IN_1_12 | ||
void graphene_box2d_expand_scalar (const graphene_box2d_t *box, | ||
float scalar, | ||
graphene_box2d_t *res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a linear transform function / fused multiply-add ala scale * box + offset
is the one thing I've needed in the GSK clip rects to handle affine transforms. And it works as a fallback for all the other transforms (scales, offsets, etc), too.
GRAPHENE_AVAILABLE_IN_1_12 | ||
bool graphene_box2d_intersection (const graphene_box2d_t *a, | ||
const graphene_box2d_t *b, | ||
graphene_box2d_t *res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intersection checking is the one absolutely most critical operation we are doing when rendering in GTK.
In fact, in certain workloads (think a GtkListbox in a scrolledwindow, like gtk4-demo --run=listbox
) intersecting alone can take >50% of time spend in gsk_renderer_render()
(according to sysprof).
So having an (inline?) function that just does an intersection check and returns true/false
would be very neat. Something like bool graphene_box2d_intersects (a, b)
GRAPHENE_AVAILABLE_IN_1_12 | ||
graphene_box2d_t * graphene_box2d_init_from_vec2 (graphene_box2d_t *box, | ||
const graphene_vec2_t *min, | ||
const graphene_vec2_t *max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transitioning GTK code from using graphene_rect_t
would benefit from graphene_box2d_init_from_rect()
and graphene_rect_init_from_box2d()
.
graphene_point_t *min); | ||
GRAPHENE_AVAILABLE_IN_1_12 | ||
void graphene_box2d_get_max (const graphene_box2d_t *box, | ||
graphene_point_t *max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your opinion on graphene_box2d_get_minmax(box, &min, &max)
instead/on top of these two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fast path copy operation for both vertices would probably be okay, in the same way as sincos()
; I mainly kept the same API as graphene_box_t
, but I can see it being useful there, too.
Works like
graphene_box_t
, but in two dimensions.