diff --git a/Makefile.common b/Makefile.common index 53308385e8..e933af5797 100644 --- a/Makefile.common +++ b/Makefile.common @@ -772,11 +772,7 @@ endif OBJ += gfx/video_context_driver.o \ gfx/drivers_context/gfx_null_ctx.o \ - gfx/video_state_tracker.o \ - $(LIBRETRO_COMM_DIR)/gfx/math/vector_2.o \ - $(LIBRETRO_COMM_DIR)/gfx/math/vector_3.o \ - $(LIBRETRO_COMM_DIR)/gfx/math/vector_4.o \ - $(LIBRETRO_COMM_DIR)/gfx/math/matrix_3x3.o + gfx/video_state_tracker.o ifeq ($(HAVE_KMS), 1) HAVE_AND_WILL_USE_DRM = 1 diff --git a/griffin/griffin.c b/griffin/griffin.c index a1f748935b..ae8d7c7bbf 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -281,11 +281,6 @@ VIDEO IMAGE VIDEO DRIVER ============================================================ */ -#include "../libretro-common/gfx/math/matrix_3x3.c" -#include "../libretro-common/gfx/math/vector_2.c" -#include "../libretro-common/gfx/math/vector_3.c" -#include "../libretro-common/gfx/math/vector_4.c" - #if defined(GEKKO) #ifdef HW_RVL #include "../gfx/drivers/gx_gfx_vi_encoder.c" diff --git a/libretro-common/gfx/math/matrix_3x3.c b/libretro-common/gfx/math/matrix_3x3.c deleted file mode 100644 index df092d3b7a..0000000000 --- a/libretro-common/gfx/math/matrix_3x3.c +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright (C) 2010-2017 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this file (matrix_3x3.c). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include -#include - -#define FLOATS_ARE_EQUAL(x, y) (fabs(x - y) <= 0.00001f * ((x) > (y) ? (y) : (x))) -#define FLOAT_IS_ZERO(x) (FLOATS_ARE_EQUAL((x) + 1, 1)) - -bool matrix_3x3_invert(math_matrix_3x3 *mat) -{ - float det = matrix_3x3_determinant(*mat); - - if (FLOAT_IS_ZERO(det)) - return false; - - matrix_3x3_adjoint(*mat); - matrix_3x3_divide_scalar(*mat, det); - - return true; -} - -bool matrix_3x3_square_to_quad( - const float dx0, const float dy0, - const float dx1, const float dy1, - const float dx3, const float dy3, - const float dx2, const float dy2, - math_matrix_3x3 *mat) -{ - float a, b, d, e; - float ax = dx0 - dx1 + dx2 - dx3; - float ay = dy0 - dy1 + dy2 - dy3; - float c = dx0; - float f = dy0; - float g = 0; - float h = 0; - - if (FLOAT_IS_ZERO(ax) && FLOAT_IS_ZERO(ay)) - { - /* affine case */ - a = dx1 - dx0; - b = dx2 - dx1; - d = dy1 - dy0; - e = dy2 - dy1; - } - else - { - float ax1 = dx1 - dx2; - float ax2 = dx3 - dx2; - float ay1 = dy1 - dy2; - float ay2 = dy3 - dy2; - - /* determinants */ - float gtop = ax * ay2 - ax2 * ay; - float htop = ax1 * ay - ax * ay1; - float bottom = ax1 * ay2 - ax2 * ay1; - - if (!bottom) - return false; - - g = gtop / bottom; - h = htop / bottom; - - a = dx1 - dx0 + g * dx1; - b = dx3 - dx0 + h * dx3; - d = dy1 - dy0 + g * dy1; - e = dy3 - dy0 + h * dy3; - } - - - matrix_3x3_init(*mat, - a, d, g, - b, e, h, - c, f, 1.f); - - return true; -} - -bool matrix_3x3_quad_to_square( - const float sx0, const float sy0, - const float sx1, const float sy1, - const float sx2, const float sy2, - const float sx3, const float sy3, - math_matrix_3x3 *mat) -{ - return matrix_3x3_square_to_quad(sx0, sy0, sx1, sy1, - sx2, sy2, sx3, sy3, - mat) ? matrix_3x3_invert(mat) : false; -} - -bool matrix_3x3_quad_to_quad( - const float dx0, const float dy0, - const float dx1, const float dy1, - const float dx2, const float dy2, - const float dx3, const float dy3, - const float sx0, const float sy0, - const float sx1, const float sy1, - const float sx2, const float sy2, - const float sx3, const float sy3, - math_matrix_3x3 *mat) -{ - math_matrix_3x3 square_to_quad; - - if (matrix_3x3_square_to_quad(dx0, dy0, dx1, dy1, - dx2, dy2, dx3, dy3, - &square_to_quad)) - { - math_matrix_3x3 quad_to_square; - if (matrix_3x3_quad_to_square(sx0, sy0, sx1, sy1, - sx2, sy2, sx3, sy3, - &quad_to_square)) - { - matrix_3x3_multiply(*mat, quad_to_square, square_to_quad); - - return true; - } - } - - return false; -} diff --git a/libretro-common/gfx/math/vector_2.c b/libretro-common/gfx/math/vector_2.c deleted file mode 100644 index 3525c30278..0000000000 --- a/libretro-common/gfx/math/vector_2.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2010-2017 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this file (vector_2.c). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include - -#include - -float vec2_dot(const float *a, const float *b) -{ - return (a[0]*b[0]) + (a[1]*b[1]); -} - -float vec2_cross(const float *a, const float *b) -{ - return (a[0]*b[1]) - (a[1]*b[0]); -} - -void vec2_add(float *dst, const float *src) -{ - dst[0] += src[0]; - dst[1] += src[1]; -} - -void vec2_subtract(float *dst, const float *src) -{ - dst[0] -= src[0]; - dst[1] -= src[1]; -} - -void vec2_copy(float *dst, const float *src) -{ - dst[0] = src[0]; - dst[1] = src[1]; -} diff --git a/libretro-common/gfx/math/vector_3.c b/libretro-common/gfx/math/vector_3.c deleted file mode 100644 index da695b3c09..0000000000 --- a/libretro-common/gfx/math/vector_3.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (C) 2010-2017 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this file (vector_3.c). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include - -#include - -float vec3_dot(const float *a, const float *b) -{ - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -} - -void vec3_cross(float* dst, const float *a, const float *b) -{ - dst[0] = a[1]*b[2] - a[2]*b[1]; - dst[1] = a[2]*b[0] - a[0]*b[2]; - dst[2] = a[0]*b[1] - a[1]*b[0]; -} - -float vec3_length(const float *a) -{ - float length_sq = vec3_dot(a,a); - return sqrtf(length_sq); -} - -void vec3_add(float *dst, const float *src) -{ - dst[0] += src[0]; - dst[1] += src[1]; - dst[2] += src[2]; -} - -void vec3_subtract(float *dst, const float *src) -{ - dst[0] -= src[0]; - dst[1] -= src[1]; - dst[2] -= src[2]; -} - -void vec3_scale(float *dst, const float scale) -{ - dst[0] *= scale; - dst[1] *= scale; - dst[2] *= scale; -} - -void vec3_copy(float *dst, const float *src) -{ - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; -} - -void vec3_normalize(float *dst) -{ - float length = vec3_length(dst); - vec3_scale(dst,1.0f/length); -} diff --git a/libretro-common/gfx/math/vector_4.c b/libretro-common/gfx/math/vector_4.c deleted file mode 100644 index 957fd1be31..0000000000 --- a/libretro-common/gfx/math/vector_4.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 2010-2017 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this file (vector_4.c). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include - -#include - -void vec4_add(float *dst, const float *src) -{ - dst[0] += src[0]; - dst[1] += src[1]; - dst[2] += src[2]; - dst[3] += src[3]; -} - -void vec4_subtract(float *dst, const float *src) -{ - dst[0] -= src[0]; - dst[1] -= src[1]; - dst[2] -= src[2]; - dst[3] -= src[3]; -} - -void vec4_scale(float *dst, const float scale) -{ - dst[0] *= scale; - dst[1] *= scale; - dst[2] *= scale; - dst[3] *= scale; -} - -void vec4_copy(float *dst, const float *src) -{ - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; -} diff --git a/libretro-common/include/gfx/math/matrix_3x3.h b/libretro-common/include/gfx/math/matrix_3x3.h index 06bb542677..9bdd886945 100644 --- a/libretro-common/include/gfx/math/matrix_3x3.h +++ b/libretro-common/include/gfx/math/matrix_3x3.h @@ -24,8 +24,11 @@ #define __LIBRETRO_SDK_GFX_MATH_MATRIX_3X3_H__ #include +#include +#include #include +#include RETRO_BEGIN_DECLS @@ -131,27 +134,120 @@ typedef struct math_matrix_3x3 MAT_ELEM_3X3(mat, 2, 1) = -(MAT_ELEM_3X3(mat, 0, 0) * MAT_ELEM_3X3(mat, 2, 1) - MAT_ELEM_3X3(mat, 0, 1) * MAT_ELEM_3X3(mat, 2, 0)); \ MAT_ELEM_3X3(mat, 2, 2) = (MAT_ELEM_3X3(mat, 0, 0) * MAT_ELEM_3X3(mat, 1, 1) - MAT_ELEM_3X3(mat, 0, 1) * MAT_ELEM_3X3(mat, 1, 0)) -bool matrix_3x3_invert(math_matrix_3x3 *mat); +#define FLOATS_ARE_EQUAL(x, y) (fabs(x - y) <= 0.00001f * ((x) > (y) ? (y) : (x))) +#define FLOAT_IS_ZERO(x) (FLOATS_ARE_EQUAL((x) + 1, 1)) -bool matrix_3x3_square_to_quad(const float dx0, const float dy0, - const float dx1, const float dy1, - const float dx3, const float dy3, - const float dx2, const float dy2, - math_matrix_3x3 *mat); -bool matrix_3x3_quad_to_square(const float sx0, const float sy0, - const float sx1, const float sy1, - const float sx2, const float sy2, - const float sx3, const float sy3, - math_matrix_3x3 *mat); -bool matrix_3x3_quad_to_quad(const float dx0, const float dy0, - const float dx1, const float dy1, - const float dx2, const float dy2, - const float dx3, const float dy3, - const float sx0, const float sy0, - const float sx1, const float sy1, - const float sx2, const float sy2, - const float sx3, const float sy3, - math_matrix_3x3 *mat); +static INLINE bool matrix_3x3_invert(math_matrix_3x3 *mat) +{ + float det = matrix_3x3_determinant(*mat); + + if (FLOAT_IS_ZERO(det)) + return false; + + matrix_3x3_adjoint(*mat); + matrix_3x3_divide_scalar(*mat, det); + + return true; +} + +static INLINE bool matrix_3x3_square_to_quad( + const float dx0, const float dy0, + const float dx1, const float dy1, + const float dx3, const float dy3, + const float dx2, const float dy2, + math_matrix_3x3 *mat) +{ + float a, b, d, e; + float ax = dx0 - dx1 + dx2 - dx3; + float ay = dy0 - dy1 + dy2 - dy3; + float c = dx0; + float f = dy0; + float g = 0; + float h = 0; + + if (FLOAT_IS_ZERO(ax) && FLOAT_IS_ZERO(ay)) + { + /* affine case */ + a = dx1 - dx0; + b = dx2 - dx1; + d = dy1 - dy0; + e = dy2 - dy1; + } + else + { + float ax1 = dx1 - dx2; + float ax2 = dx3 - dx2; + float ay1 = dy1 - dy2; + float ay2 = dy3 - dy2; + + /* determinants */ + float gtop = ax * ay2 - ax2 * ay; + float htop = ax1 * ay - ax * ay1; + float bottom = ax1 * ay2 - ax2 * ay1; + + if (!bottom) + return false; + + g = gtop / bottom; + h = htop / bottom; + + a = dx1 - dx0 + g * dx1; + b = dx3 - dx0 + h * dx3; + d = dy1 - dy0 + g * dy1; + e = dy3 - dy0 + h * dy3; + } + + + matrix_3x3_init(*mat, + a, d, g, + b, e, h, + c, f, 1.f); + + return true; +} + +static INLINE bool matrix_3x3_quad_to_square( + const float sx0, const float sy0, + const float sx1, const float sy1, + const float sx2, const float sy2, + const float sx3, const float sy3, + math_matrix_3x3 *mat) +{ + return matrix_3x3_square_to_quad(sx0, sy0, sx1, sy1, + sx2, sy2, sx3, sy3, + mat) ? matrix_3x3_invert(mat) : false; +} + +static INLINE bool matrix_3x3_quad_to_quad( + const float dx0, const float dy0, + const float dx1, const float dy1, + const float dx2, const float dy2, + const float dx3, const float dy3, + const float sx0, const float sy0, + const float sx1, const float sy1, + const float sx2, const float sy2, + const float sx3, const float sy3, + math_matrix_3x3 *mat) +{ + math_matrix_3x3 square_to_quad; + + if (matrix_3x3_square_to_quad(dx0, dy0, dx1, dy1, + dx2, dy2, dx3, dy3, + &square_to_quad)) + { + math_matrix_3x3 quad_to_square; + if (matrix_3x3_quad_to_square(sx0, sy0, sx1, sy1, + sx2, sy2, sx3, sy3, + &quad_to_square)) + { + matrix_3x3_multiply(*mat, quad_to_square, square_to_quad); + + return true; + } + } + + return false; +} RETRO_END_DECLS diff --git a/libretro-common/include/gfx/math/vector_2.h b/libretro-common/include/gfx/math/vector_2.h index 3b208d3af1..5248693b06 100644 --- a/libretro-common/include/gfx/math/vector_2.h +++ b/libretro-common/include/gfx/math/vector_2.h @@ -24,6 +24,7 @@ #define __LIBRETRO_SDK_GFX_MATH_VECTOR_2_H__ #include +#include #include @@ -31,15 +32,21 @@ RETRO_BEGIN_DECLS typedef float vec2_t[2]; -float vec2_dot(const float *a, const float *b); +#define vec2_dot(a, b) ((a[0] * b[0]) + (a[1] * b[1])) -float vec2_cross(const float *a, const float *b) ; +#define vec2_cross(a, b) ((a[0]*b[1]) - (a[1]*b[0])) -void vec2_add(float *dst, const float *src); +#define vec2_add(dst, src) \ + dst[0] += src[0]; \ + dst[1] += src[1] -void vec2_subtract(float *dst, const float *src); +#define vec2_subtract(dst, src) \ + dst[0] -= src[0]; \ + dst[1] -= src[1] -void vec2_copy(float *dst, const float *src); +#define vec2_copy(dst, src) \ + dst[0] = src[0]; \ + dst[1] = src[1] RETRO_END_DECLS diff --git a/libretro-common/include/gfx/math/vector_3.h b/libretro-common/include/gfx/math/vector_3.h index f9e67cc279..67256172f0 100644 --- a/libretro-common/include/gfx/math/vector_3.h +++ b/libretro-common/include/gfx/math/vector_3.h @@ -24,6 +24,7 @@ #define __LIBRETRO_SDK_GFX_MATH_VECTOR_3_H__ #include +#include #include @@ -31,21 +32,36 @@ RETRO_BEGIN_DECLS typedef float vec3_t[3]; -float vec3_dot(const float *a, const float *b); +#define vec3_dot(a, b) (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) -void vec3_cross(float* dst, const float *a, const float *b); +#define vec3_cross(dst, a, b) \ + dst[0] = a[1]*b[2] - a[2]*b[1]; \ + dst[1] = a[2]*b[0] - a[0]*b[2]; \ + dst[2] = a[0]*b[1] - a[1]*b[0] -float vec3_length(const float *a); +#define vec3_length(a) sqrtf(vec3_dot(a,a)) -void vec3_add(float *dst, const float *src); +#define vec3_add(dst, src) \ + dst[0] += src[0]; \ + dst[1] += src[1]; \ + dst[2] += src[2] -void vec3_subtract(float *dst, const float *src); +#define vec3_subtract(dst, src) \ + dst[0] -= src[0]; \ + dst[1] -= src[1]; \ + dst[2] -= src[2] -void vec3_scale(float *dst, const float scale); +#define vec3_scale(dst, scale) \ + dst[0] *= scale; \ + dst[1] *= scale; \ + dst[2] *= scale -void vec3_copy(float *dst, const float *src); +#define vec3_copy(dst, src) \ + dst[0] = src[0]; \ + dst[1] = src[1]; \ + dst[2] = src[2] -void vec3_normalize(float *dst); +#define vec3_normalize(dst) vec3_scale(dst,1.0f / vec3_length(dst)) RETRO_END_DECLS diff --git a/libretro-common/include/gfx/math/vector_4.h b/libretro-common/include/gfx/math/vector_4.h index d7c9223556..3b9510c511 100644 --- a/libretro-common/include/gfx/math/vector_4.h +++ b/libretro-common/include/gfx/math/vector_4.h @@ -24,6 +24,7 @@ #define __LIBRETRO_SDK_GFX_MATH_VECTOR_4_H__ #include +#include #include @@ -31,13 +32,29 @@ RETRO_BEGIN_DECLS typedef float vec4_t[4]; -void vec4_add(float *dst, const float *src); +#define vec4_add(dst, src) \ + dst[0] += src[0]; \ + dst[1] += src[1]; \ + dst[2] += src[2]; \ + dst[3] += src[3] -void vec4_subtract(float *dst, const float *src); +#define vec4_subtract(dst, src) \ + dst[0] -= src[0]; \ + dst[1] -= src[1]; \ + dst[2] -= src[2]; \ + dst[3] -= src[3] -void vec4_scale(float *dst, const float scale); +#define vec4_scale(dst, scale) \ + dst[0] *= scale; \ + dst[1] *= scale; \ + dst[2] *= scale; \ + dst[3] *= scale -void vec4_copy(float *dst, const float *src); +#define vec4_copy(dst, src) \ + dst[0] = src[0]; \ + dst[1] = src[1]; \ + dst[2] = src[2]; \ + dst[3] = src[3] RETRO_END_DECLS