From 3c2ad5e6496cc518f6abd23a5a5332314e8dab80 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 5 Oct 2015 23:08:35 +0200 Subject: [PATCH 1/1] Call init_lanczos_table() once instead of checking for it all the time. --- resample_effect.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/resample_effect.cpp b/resample_effect.cpp index 958ed25..95f5575 100644 --- a/resample_effect.cpp +++ b/resample_effect.cpp @@ -74,6 +74,9 @@ float lanczos_weight(float x) // // Solve for e = 1e-6 yields a step size of 0.0027, which to cover the range // 0..3 needs 1109 steps. We round up to the next power of two, just to be sure. +// +// You need to call lanczos_table_init_done before the first call to +// lanczos_weight_cached. #define LANCZOS_TABLE_SIZE 2048 bool lanczos_table_init_done = false; float lanczos_table[LANCZOS_TABLE_SIZE + 2]; @@ -88,11 +91,6 @@ void init_lanczos_table() float lanczos_weight_cached(float x) { - if (!lanczos_table_init_done) { - // Could in theory race between two threads if we are unlucky, - // but that is harmless, since they'll write the same data. - init_lanczos_table(); - } x = fabs(x); if (x > LANCZOS_RADIUS) { return 0.0f; @@ -461,6 +459,12 @@ SingleResamplePassEffect::SingleResamplePassEffect(ResampleEffect *parent) register_uniform_float("whole_pixel_offset", &uniform_whole_pixel_offset); glGenTextures(1, &texnum); + + if (!lanczos_table_init_done) { + // Could in theory race between two threads if we are unlucky, + // but that is harmless, since they'll write the same data. + init_lanczos_table(); + } } SingleResamplePassEffect::~SingleResamplePassEffect() -- 2.39.2