Add gfx_coord_array_resize

This commit is contained in:
Twinaphex 2016-03-05 09:43:15 +01:00
parent a73cbb6114
commit e0d7c25ea0

View File

@ -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);