Use the actual clip rectangle.

Use rect_overlap in draw_rectangle_outline.
Reorganized a bit to test earlier to avoid unnecessary work.
This commit is contained in:
Simon Anciaux 2024-09-26 14:31:02 +02:00 committed by Peter Slattery
parent 33c3428796
commit e4a4910e6b
1 changed files with 75 additions and 90 deletions

View File

@ -132,6 +132,9 @@ end_render_section(Render_Target *target){
internal void
draw_rectangle_outline(Render_Target *target, Rect_f32 rect, f32 roundness, f32 thickness, u32 color){
if ( rect_overlap(rect, target->current_clip_box) ) {
if (roundness < epsilon_f32){
roundness = 0.f;
}
@ -153,19 +156,6 @@ draw_rectangle_outline(Render_Target *target, Rect_f32 rect, f32 roundness, f32
vertices[i].half_thickness = half_thickness;
}
// NOTE simon (03/04/24): If any vertex is in the render target bounds, we draw the rectangle.
// It would be better to use the current clip rect, but it's not available here. We could pass
// it down in the function signature if necessary.
// This is not in the loop to try minimize the impact it could have on performance when there
// are a lot of vertex (we don't test duplicated vertex positions).
Rect_f32 target_rect = Rf32( 0, 0, ( f32 ) target->width, ( f32 ) target->height );
b32 draw = false;
draw = draw || rect_contains_point( target_rect, vertices[ 0 ].xy );
draw = draw || rect_contains_point( target_rect, vertices[ 1 ].xy );
draw = draw || rect_contains_point( target_rect, vertices[ 2 ].xy );
draw = draw || rect_contains_point( target_rect, vertices[ 5 ].xy );
if ( draw ) {
draw__write_vertices_in_current_group(target, vertices, ArrayCount(vertices));
}
}
@ -209,6 +199,14 @@ draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, Vec2_f32 p,
vertices[2].xy = p_x_min + y_max;
vertices[5].xy = p_x_max + y_max;
/* NOTE simon (26/09/24): We don't use rect_overlap here because the text rect is not guaranteed to be axis aligned. */
b32 draw = rect_contains_point( target->current_clip_box, vertices[ 0 ].xy );
draw = draw || rect_contains_point( target->current_clip_box, vertices[ 1 ].xy );
draw = draw || rect_contains_point( target->current_clip_box, vertices[ 2 ].xy );
draw = draw || rect_contains_point( target->current_clip_box, vertices[ 5 ].xy );
if ( draw ) {
#if 0
Vec2_f32 xy_min = p + bounds.xy_off.x0*x_axis + bounds.xy_off.y0*y_axis;
Vec2_f32 xy_max = p + bounds.xy_off.x1*x_axis + bounds.xy_off.y1*y_axis;
@ -255,19 +253,6 @@ draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, Vec2_f32 p,
vertices[i].half_thickness = 0.f;
}
// NOTE simon (03/04/24): If any vertex is in the render target bounds, we draw the rectangle.
// It would be better to use the current clip rect, but it's not available here. We could pass
// it down in the function signature if necessary.
// This is not in the loop to try minimize the impact it could have on performance when there
// are a lot of vertex (we don't test duplicated vertex positions).
Rect_f32 target_rect = Rf32( 0, 0, ( f32 ) target->width, ( f32 ) target->height );
b32 draw = false;
draw = draw || rect_contains_point( target_rect, vertices[ 0 ].xy );
draw = draw || rect_contains_point( target_rect, vertices[ 1 ].xy );
draw = draw || rect_contains_point( target_rect, vertices[ 2 ].xy );
draw = draw || rect_contains_point( target_rect, vertices[ 5 ].xy );
if ( draw ) {
draw__write_vertices_in_current_group(target, vertices, ArrayCount(vertices));
}
}