Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2020-03-06 19:18:10 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2020-03-09 16:47:59 +0300
commit598ab525da3df3fef2033c159c570688c7282a8f (patch)
treeba2bd0b8fc6ee5d264512bf655def1a6ee5d7b31 /source/blender/draw/engines
parentee5d7bc16b243f309c84bce5deddf3a86b7f4c14 (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')
-rw-r--r--source/blender/draw/engines/eevee/eevee_lightprobes.c2
-rw-r--r--source/blender/draw/engines/eevee/eevee_private.h2
-rw-r--r--source/blender/draw/engines/workbench/workbench_data.c4
-rw-r--r--source/blender/draw/engines/workbench/workbench_effect_dof.c5
-rw-r--r--source/blender/draw/engines/workbench/workbench_effect_taa.c6
5 files changed, 10 insertions, 9 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index 1f12ef1f379..4fbecfe3120 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -765,7 +765,7 @@ void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ved
sldata->common_data.prb_lod_cube_max = (float)light_cache->mips_len - 1.0f;
sldata->common_data.prb_lod_planar_max = (float)MAX_PLANAR_LOD_LEVEL;
sldata->common_data.prb_irradiance_vis_size = light_cache->vis_res;
- sldata->common_data.prb_irradiance_smooth = SQUARE(scene_eval->eevee.gi_irradiance_smoothing);
+ sldata->common_data.prb_irradiance_smooth = square_f(scene_eval->eevee.gi_irradiance_smoothing);
sldata->common_data.prb_num_render_cube = max_ii(1, light_cache->cube_len);
sldata->common_data.prb_num_render_grid = max_ii(1, light_cache->grid_len);
sldata->common_data.prb_num_planar = pinfo->num_planar;
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index 9a8b2cb793a..5ffea393e1f 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -140,7 +140,7 @@ extern struct DrawEngineType draw_engine_eevee_type;
BLI_INLINE int octahedral_size_from_cubesize(int cube_size)
{
- int cube_pixel_count = SQUARE(cube_size) * 6.0f;
+ int cube_pixel_count = square_i(cube_size) * 6;
int octa_size = (int)ceilf(sqrtf(cube_pixel_count));
int lod_count = log2_floor_u(octa_size) - MIN_CUBE_LOD_LEVEL;
/* Find lowest lod size and grow back to avoid having non matching mipsizes that would
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;