mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
367bd15ec5
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
106 lines
2.5 KiB
C
106 lines
2.5 KiB
C
/*
|
|
* Copyright 2016-2018 Józef Kucia for CodeWeavers
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
#ifndef __VKD3D_TEST_UTILS_H
|
|
#define __VKD3D_TEST_UTILS_H
|
|
|
|
#include <limits.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
|
|
struct vec2
|
|
{
|
|
float x, y;
|
|
};
|
|
|
|
struct vec4
|
|
{
|
|
float x, y, z, w;
|
|
};
|
|
|
|
static inline bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size)
|
|
{
|
|
size_t new_capacity, max_capacity;
|
|
void *new_elements;
|
|
|
|
if (element_count <= *capacity)
|
|
return true;
|
|
|
|
max_capacity = ~(size_t)0 / element_size;
|
|
if (max_capacity < element_count)
|
|
return false;
|
|
|
|
new_capacity = max(*capacity, 4);
|
|
while (new_capacity < element_count && new_capacity <= max_capacity / 2)
|
|
new_capacity *= 2;
|
|
|
|
if (new_capacity < element_count)
|
|
new_capacity = element_count;
|
|
|
|
if (!(new_elements = realloc(*elements, new_capacity * element_size)))
|
|
return false;
|
|
|
|
*elements = new_elements;
|
|
*capacity = new_capacity;
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool compare_float(float f, float g, unsigned int ulps)
|
|
{
|
|
int x, y;
|
|
union
|
|
{
|
|
float f;
|
|
int i;
|
|
} u;
|
|
|
|
u.f = f;
|
|
x = u.i;
|
|
u.f = g;
|
|
y = u.i;
|
|
|
|
if (x < 0)
|
|
x = INT_MIN - x;
|
|
if (y < 0)
|
|
y = INT_MIN - y;
|
|
|
|
if (abs(x - y) > ulps)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline bool compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
|
|
{
|
|
return compare_float(v1->x, v2->x, ulps)
|
|
&& compare_float(v1->y, v2->y, ulps)
|
|
&& compare_float(v1->z, v2->z, ulps)
|
|
&& compare_float(v1->w, v2->w, ulps);
|
|
}
|
|
|
|
static inline void set_rect(RECT *rect, int left, int top, int right, int bottom)
|
|
{
|
|
rect->left = left;
|
|
rect->right = right;
|
|
rect->top = top;
|
|
rect->bottom = bottom;
|
|
}
|
|
|
|
#endif
|