From e0d7c25ea049982709fa3760baf2b5b40b19a7f6 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 5 Mar 2016 09:43:15 +0100 Subject: [PATCH] Add gfx_coord_array_resize --- gfx/video_coord_array.c | 48 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/gfx/video_coord_array.c b/gfx/video_coord_array.c index bfccd11c0b..711bbcb073 100644 --- a/gfx/video_coord_array.c +++ b/gfx/video_coord_array.c @@ -36,38 +36,40 @@ static INLINE bool realloc_checked(void **ptr, size_t size) return *ptr == nptr; } -bool gfx_coord_array_add(gfx_coord_array_t *ca, - const gfx_coords_t *coords, unsigned count) +static bool gfx_coord_array_resize(gfx_coord_array_t *ca, + unsigned count) { - size_t base_size, offset; - bool success = false; - - count = MIN(count, coords->vertices); - if (ca->coords.vertices + count >= ca->allocated) { unsigned alloc_size = next_pow2(ca->coords.vertices + count); size_t base_size = sizeof(float) * alloc_size; - bool vert_ok = realloc_checked((void**)&ca->coords.vertex, - 2 * base_size); - bool color_ok = realloc_checked((void**)&ca->coords.color, - 4 * base_size); - bool tex_ok = realloc_checked((void**)&ca->coords.tex_coord, - 2 * base_size); - bool lut_ok = realloc_checked((void**)&ca->coords.lut_tex_coord, - 2 * base_size); + if (!realloc_checked((void**)&ca->coords.vertex, + 2 * base_size)) + return false; + if (!realloc_checked((void**)&ca->coords.color, + 4 * base_size)) + return false; + if (!realloc_checked((void**)&ca->coords.tex_coord, + 2 * base_size)) + return false; + if (!realloc_checked((void**)&ca->coords.lut_tex_coord, + 2 * base_size)) + return false; - if (vert_ok && color_ok && tex_ok && lut_ok) - { - ca->allocated = alloc_size; - success = true; - } + ca->allocated = alloc_size; } - else - success = true; - if (!success) /* Allocation failed. */ + return true; +} + +bool gfx_coord_array_add(gfx_coord_array_t *ca, + const gfx_coords_t *coords, unsigned count) +{ + size_t base_size, offset; + count = MIN(count, coords->vertices); + + if (!gfx_coord_array_resize(ca, count)) return false; base_size = count * sizeof(float);