From 4d58dae59f651b4a203b082275724ea15fdbe780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 19 Jan 2022 10:59:34 +0100 Subject: [PATCH] sw_engine: Replace non-portable min/max with tvgMath.h macros This would fail building with Visual Studio 2017, at least downstream in Godot where we undefine old Windows compilers' non-standard `min`/`max` macros (see `minmax.h`/`NOMINMAX`). --- AUTHORS | 1 + src/lib/sw_engine/tvgSwRenderer.cpp | 9 +++++---- src/lib/tvgMath.h | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 3e3effdf..0f8ba2dd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,3 +14,4 @@ Patryk Kaczmarek Michal Maciola Peter Vullings K. S. Ernest (iFire) Lee +Rémi Verschelde diff --git a/src/lib/sw_engine/tvgSwRenderer.cpp b/src/lib/sw_engine/tvgSwRenderer.cpp index f63cece8..49a4b5ea 100644 --- a/src/lib/sw_engine/tvgSwRenderer.cpp +++ b/src/lib/sw_engine/tvgSwRenderer.cpp @@ -23,6 +23,7 @@ #include "tvgSwCommon.h" #include "tvgTaskScheduler.h" #include "tvgSwRenderer.h" +#include "tvgMath.h" /************************************************************************/ /* Internal Class Implementation */ @@ -594,10 +595,10 @@ void* SwRenderer::prepareCommon(SwTask* task, const RenderTransform* transform, task->surface = surface; task->mpool = mpool; task->flags = flags; - task->bbox.min.x = max(static_cast(0), static_cast(vport.x)); - task->bbox.min.y = max(static_cast(0), static_cast(vport.y)); - task->bbox.max.x = min(static_cast(surface->w), static_cast(vport.x + vport.w)); - task->bbox.max.y = min(static_cast(surface->h), static_cast(vport.y + vport.h)); + task->bbox.min.x = mathMax(static_cast(0), static_cast(vport.x)); + task->bbox.min.y = mathMax(static_cast(0), static_cast(vport.y)); + task->bbox.max.x = mathMin(static_cast(surface->w), static_cast(vport.x + vport.w)); + task->bbox.max.y = mathMin(static_cast(surface->h), static_cast(vport.y + vport.h)); if (!task->pushed) { task->pushed = true; diff --git a/src/lib/tvgMath.h b/src/lib/tvgMath.h index da931993..d4d3ad96 100644 --- a/src/lib/tvgMath.h +++ b/src/lib/tvgMath.h @@ -29,6 +29,10 @@ #include "tvgCommon.h" +#define mathMin(x, y) (((x) < (y)) ? (x) : (y)) +#define mathMax(x, y) (((x) > (y)) ? (x) : (y)) + + static inline bool mathZero(float a) { return (fabsf(a) < FLT_EPSILON) ? true : false; @@ -154,4 +158,4 @@ static inline Matrix mathMultiply(const Matrix* lhs, const Matrix* rhs) } -#endif //_TVG_MATH_H_ \ No newline at end of file +#endif //_TVG_MATH_H_