star-sf

Set of surface and volume scattering functions
git clone git://git.meso-star.fr/star-sf.git
Log | Files | Refs | README | LICENSE

commit 1e0e4d12a0e75a61acb906957fdebc670e82fe48
parent 8005d7cc672004954559d2ffd7b10ee9fe29ca92
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  8 Sep 2016 14:57:43 +0200

Check that the ssf_specular_reflection is invoked on the right BxDF

Diffstat:
Msrc/ssf_bxdf_c.h | 6++++++
Msrc/ssf_specular_reflection.c | 1+
Msrc/test_ssf_specular_reflection.c | 4++++
Msrc/test_ssf_utils.h | 35++++++++++++++++++++++++++++++++++-
4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/src/ssf_bxdf_c.h b/src/ssf_bxdf_c.h @@ -30,6 +30,12 @@ struct ssf_bxdf { struct mem_allocator* allocator; }; +#define BXDF_TYPE_EQ(A, B) \ + ( (A)->init == (B)->init \ + && (A)->release == (B)->release \ + && (A)->sample == (B)->sample \ + && (A)->sizeof_bxdf == (B)->sizeof_bxdf \ + && (A)->alignof_bxdf == (B)->alignof_bxdf) #endif /* SSF_BXDF_C_H */ diff --git a/src/ssf_specular_reflection.c b/src/ssf_specular_reflection.c @@ -75,6 +75,7 @@ res_T ssf_specular_reflection_setup(struct ssf_bxdf* bxdf, const double reflectivity) { if(!bxdf || reflectivity < 0) return RES_BAD_ARG; + if(!BXDF_TYPE_EQ(&bxdf->type, &ssf_specular_reflection)) return RES_BAD_ARG; ((struct specular_reflection*)bxdf->data)->reflectivity = reflectivity; return RES_OK; } diff --git a/src/test_ssf_specular_reflection.c b/src/test_ssf_specular_reflection.c @@ -23,6 +23,7 @@ main(int argc, char** argv) { struct mem_allocator allocator; struct ssf_bxdf* brdf; + struct ssf_bxdf* dummy; double w[3]; double N[3]; double dir[4]; @@ -31,12 +32,14 @@ main(int argc, char** argv) mem_init_proxy_allocator(&allocator, &mem_default_allocator); CHECK(ssf_bxdf_create(&allocator, &ssf_specular_reflection, &brdf), RES_OK); + CHECK(ssf_bxdf_create(&allocator, &bxdf_dummy, &dummy), RES_OK); CHECK(ssf_specular_reflection_setup(NULL, -1.0), RES_BAD_ARG); CHECK(ssf_specular_reflection_setup(brdf, -1.0), RES_BAD_ARG); CHECK(ssf_specular_reflection_setup(NULL, 1.0), RES_BAD_ARG); CHECK(ssf_specular_reflection_setup(brdf, 1.0), RES_OK); CHECK(ssf_specular_reflection_setup(brdf, 0.0), RES_OK); + CHECK(ssf_specular_reflection_setup(dummy, 0.0), RES_BAD_ARG); d3(N, 0.0, 1.0, 0.0); @@ -71,6 +74,7 @@ main(int argc, char** argv) CHECK(d3_eq_eps(w, dir, 1.e-6), 1); CHECK(ssf_bxdf_ref_put(brdf), RES_OK); + CHECK(ssf_bxdf_ref_put(dummy), RES_OK); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_ssf_utils.h b/src/test_ssf_utils.h @@ -19,7 +19,40 @@ #include <rsys/mem_allocator.h> #include <stdio.h> -static void +static INLINE res_T +bxdf_dummy_init(struct mem_allocator* allocator, void* bxdf) +{ + (void)allocator, (void)bxdf; + return RES_OK; +} + +static INLINE void +bxdf_dummy_release(void* bxdf) +{ + (void)bxdf; +} + +static INLINE double +bxdf_dummy_sample + (void* bxdf, + const double u, + const double v, + const double w[3], + const double N[3], + double dir[4]) +{ + (void)bxdf, (void)u, (void)v, (void)w, (void)N, (void)dir; + return 0.0; +} + +static const struct ssf_bxdf_type bxdf_dummy = { + bxdf_dummy_init, + bxdf_dummy_release, + bxdf_dummy_sample, + 0, 1 +}; + +static INLINE void check_memory_allocator(struct mem_allocator* allocator) { if(MEM_ALLOCATED_SIZE(allocator)) {