diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-03-06 19:18:10 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-03-09 16:47:59 +0300 |
commit | 598ab525da3df3fef2033c159c570688c7282a8f (patch) | |
tree | ba2bd0b8fc6ee5d264512bf655def1a6ee5d7b31 /source/blender/draw/engines/workbench | |
parent | ee5d7bc16b243f309c84bce5deddf3a86b7f4c14 (diff) |
Cleanup: Replace ABS/SQUARE/CUBE with function calls
While it might be handy to have type-less functionality which is
similar to how C++ math is implemented it can not be easily achieved
with just preprocessor in a way which does not have side-effects on
wrong usage.
There macros where often used on a non-trivial expression, and there
was at least one usage where it was causing an actual side effect/bug
on Windows (see change around square_f(sh[index++]) in studiolight.c).
For such cases it is handy to have a function which is guaranteed to
have zero side-effects. The motivation behind actually removing the
macros is that there is already a way to do similar calculation. Also,
not having such macros is a way to guarantee that its usage is not
changed in a way which have side-effects and that it's not used as an
inspiration for cases where it should not be used.
Differential Revision: https://developer.blender.org/D7051
Diffstat (limited to 'source/blender/draw/engines/workbench')
3 files changed, 8 insertions, 7 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c index 056e6a6c364..623a3c0cb15 100644 --- a/source/blender/draw/engines/workbench/workbench_data.c +++ b/source/blender/draw/engines/workbench/workbench_data.c @@ -177,8 +177,8 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd) copy_v3_v3(wd->object_outline_color, wpd->shading.object_outline_color); wd->object_outline_color[3] = 1.0f; - wd->curvature_ridge = 0.5f / max_ff(SQUARE(wpd->shading.curvature_ridge_factor), 1e-4f); - wd->curvature_valley = 0.7f / max_ff(SQUARE(wpd->shading.curvature_valley_factor), 1e-4f); + wd->curvature_ridge = 0.5f / max_ff(square_f(wpd->shading.curvature_ridge_factor), 1e-4f); + wd->curvature_valley = 0.7f / max_ff(square_f(wpd->shading.curvature_valley_factor), 1e-4f); /* Will be NULL when rendering. */ if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { diff --git a/source/blender/draw/engines/workbench/workbench_effect_dof.c b/source/blender/draw/engines/workbench/workbench_effect_dof.c index 3709c5600e6..ae3e2218463 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_dof.c +++ b/source/blender/draw/engines/workbench/workbench_effect_dof.c @@ -77,8 +77,9 @@ static void square_to_circle(float x, float y, float *r, float *T) } } -#define KERNEL_RAD 3 -#define SAMP_LEN SQUARE(KERNEL_RAD * 2 + 1) +#define SQUARE_UNSAFE(a) ((a) * (a)) +#define KERNEL_RAD (3) +#define SAMP_LEN SQUARE_UNSAFE(KERNEL_RAD * 2 + 1) static void workbench_dof_setup_samples(struct GPUUniformBuffer **ubo, float **data, diff --git a/source/blender/draw/engines/workbench/workbench_effect_taa.c b/source/blender/draw/engines/workbench/workbench_effect_taa.c index 772d859392b..e2864f8c832 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_taa.c +++ b/source/blender/draw/engines/workbench/workbench_effect_taa.c @@ -43,7 +43,7 @@ static void workbench_taa_jitter_init_order(float (*table)[2], int num) float closest_squared_distance = 1.0f; for (int index = 0; index < num; index++) { - const float squared_dist = SQUARE(table[index][0]) + SQUARE(table[index][1]); + const float squared_dist = square_f(table[index][0]) + square_f(table[index][1]); if (squared_dist < closest_squared_distance) { closest_squared_distance = squared_dist; closest_index = index; @@ -66,8 +66,8 @@ static void workbench_taa_jitter_init_order(float (*table)[2], int num) float f_squared_dist = 0.0; int f_index = i; for (int j = i + 1; j < num; j++) { - const float squared_dist = SQUARE(table[i][0] - table[j][0]) + - SQUARE(table[i][1] - table[j][1]); + const float squared_dist = square_f(table[i][0] - table[j][0]) + + square_f(table[i][1] - table[j][1]); if (squared_dist > f_squared_dist) { f_squared_dist = squared_dist; f_index = j; |