Skip to content

Commit

Permalink
Use single vec4 for box2d
Browse files Browse the repository at this point in the history
Pack the minimum and maximum vertices into a single vector, and use
merge low/high operators to extract the values. This reduces the size of
a box2d instance, and makes it more compact. It's also more efficient to
extract both vertices when passing them to GL, by using a single read.
  • Loading branch information
ebassi committed Aug 11, 2024
1 parent dc43a2c commit c176f94
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 91 deletions.
21 changes: 18 additions & 3 deletions include/graphene-box2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "graphene-types.h"
#include "graphene-vec2.h"
#include "graphene-vec4.h"

GRAPHENE_BEGIN_DECLS

Expand All @@ -26,8 +27,7 @@ GRAPHENE_BEGIN_DECLS
struct _graphene_box2d_t
{
/*< private >*/
GRAPHENE_PRIVATE_FIELD (graphene_vec2_t, min);
GRAPHENE_PRIVATE_FIELD (graphene_vec2_t, max);
GRAPHENE_PRIVATE_FIELD (graphene_vec4_t, minmax);
};

GRAPHENE_AVAILABLE_IN_1_12
Expand All @@ -54,7 +54,9 @@ 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);

GRAPHENE_AVAILABLE_IN_1_12
graphene_box2d_t * graphene_box2d_init_from_rect (graphene_box2d_t *box,
const graphene_rect_t *rect);
GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_expand (const graphene_box2d_t *box,
const graphene_point_t *point,
Expand Down Expand Up @@ -87,6 +89,10 @@ GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_get_center (const graphene_box2d_t *box,
graphene_point_t *center);
GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_get_minmax (const graphene_box2d_t *box,
graphene_point_t *min,
graphene_point_t *max);
GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_get_min (const graphene_box2d_t *box,
graphene_point_t *min);
GRAPHENE_AVAILABLE_IN_1_12
Expand All @@ -96,11 +102,20 @@ GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_get_vertices (const graphene_box2d_t *box,
graphene_vec2_t vertices[]);
GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_to_float (const graphene_box2d_t *box,
float v[4]);
GRAPHENE_AVAILABLE_IN_1_12
void graphene_box2d_to_rect (const graphene_box2d_t *box,
graphene_rect_t *rect);
GRAPHENE_AVAILABLE_IN_1_12
bool graphene_box2d_contains_point (const graphene_box2d_t *box,
const graphene_point_t *point);
GRAPHENE_AVAILABLE_IN_1_12
bool graphene_box2d_contains_box (const graphene_box2d_t *a,
const graphene_box2d_t *b);
GRAPHENE_AVAILABLE_IN_1_12
bool graphene_box2d_contains_rect (const graphene_box2d_t *box,
const graphene_rect_t *rect);

GRAPHENE_AVAILABLE_IN_1_12
bool graphene_box2d_equal (const graphene_box2d_t *a,
Expand Down
Loading

0 comments on commit c176f94

Please sign in to comment.