From c10255ab3da17507d63bdc7e1fdfc809ffd32f7f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 31 May 2014 13:54:56 -0400 Subject: pigment: Use pool. --- libdimension/tests/render.c | 65 +++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'libdimension/tests') diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index 3a5f134..b5e2e41 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -23,11 +23,10 @@ #include static void -dmnsn_test_scene_set_defaults(dmnsn_scene *scene) +dmnsn_test_scene_set_defaults(dmnsn_pool *pool, dmnsn_scene *scene) { /* Default texture */ - scene->default_texture->pigment = - dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_black)); + scene->default_texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_black)); dmnsn_finish *default_finish = &scene->default_texture->finish; default_finish->ambient = dmnsn_new_ambient( dmnsn_color_from_sRGB(dmnsn_color_mul(0.1, dmnsn_white)) @@ -82,14 +81,14 @@ dmnsn_test_scene_add_background(dmnsn_pool *pool, dmnsn_scene *scene) fclose(png); } if (png_canvas) { - png_pigment = dmnsn_new_canvas_pigment(png_canvas); + png_pigment = dmnsn_new_canvas_pigment(pool, png_canvas); png_pigment->trans = dmnsn_rotation_matrix( dmnsn_new_vector(0.0, dmnsn_radians(53.0), 0.0) ); } else { /* Loading png2.png failed, possibly compiled with --disable-png */ fprintf(stderr, "--- WARNING: Couldn't open or read png2.png! ---\n"); - png_pigment = dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_orange)); + png_pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_orange)); } dmnsn_map_add_entry(sky_gradient_pigment_map, 0.0, &png_pigment); @@ -97,12 +96,12 @@ dmnsn_test_scene_add_background(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_new_color(0.0, 0.1, 0.2) ); dmnsn_tcolor tbackground = dmnsn_new_tcolor(background, 0.1, 0.0); - dmnsn_pigment *bkgpigment = dmnsn_new_solid_pigment(tbackground); + dmnsn_pigment *bkgpigment = dmnsn_new_solid_pigment(pool, tbackground); dmnsn_map_add_entry(sky_gradient_pigment_map, 0.35, &bkgpigment); - scene->background = - dmnsn_new_pigment_map_pigment(sky_gradient, sky_gradient_pigment_map, - DMNSN_PIGMENT_MAP_SRGB); + scene->background = dmnsn_new_pigment_map_pigment( + pool, sky_gradient, sky_gradient_pigment_map, DMNSN_PIGMENT_MAP_SRGB + ); } static void @@ -126,7 +125,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene) cube->texture = dmnsn_new_texture(); dmnsn_tcolor cube_color = dmnsn_new_tcolor(dmnsn_blue, 0.75, 1.0/3.0); - cube->texture->pigment = dmnsn_new_solid_pigment(cube_color); + cube->texture->pigment = dmnsn_new_solid_pigment(pool, cube_color); dmnsn_color reflect = dmnsn_color_from_sRGB(dmnsn_color_mul(0.5, dmnsn_white)); @@ -138,7 +137,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_object *sphere = dmnsn_new_sphere(); sphere->texture = dmnsn_new_texture(); - sphere->texture->pigment = dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_green)); + sphere->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_green)); sphere->texture->finish.specular = dmnsn_new_phong(dmnsn_sRGB_inverse_gamma(0.2), 40.0); sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25)); @@ -147,11 +146,11 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_array_push(scene->objects, &hollow_cube); } -#define dmnsn_pigment_map_add_color(map, n, color) \ - do { \ - dmnsn_tcolor tcolor = DMNSN_TCOLOR(color); \ - dmnsn_pigment *pigment = dmnsn_new_solid_pigment(tcolor); \ - dmnsn_map_add_entry(map, n, &pigment); \ +#define dmnsn_pigment_map_add_color(map, n, color) \ + do { \ + dmnsn_tcolor tcolor = DMNSN_TCOLOR(color); \ + dmnsn_pigment *pigment = dmnsn_new_solid_pigment(pool, tcolor); \ + dmnsn_map_add_entry(map, n, &pigment); \ } while (0) static void @@ -182,9 +181,9 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_pigment_map_add_color(gradient_pigment_map, 5.0/6.0, dmnsn_magenta); dmnsn_pigment_map_add_color(gradient_pigment_map, 1.0, dmnsn_red); arrow->texture = dmnsn_new_texture(); - arrow->texture->pigment = - dmnsn_new_pigment_map_pigment(gradient, gradient_pigment_map, - DMNSN_PIGMENT_MAP_SRGB); + arrow->texture->pigment = dmnsn_new_pigment_map_pigment( + pool, gradient, gradient_pigment_map, DMNSN_PIGMENT_MAP_SRGB + ); arrow->texture->trans = dmnsn_matrix_mul( @@ -208,7 +207,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_object *torii = dmnsn_new_csg_union(torus_array); dmnsn_delete_array(torus_array); torii->texture = dmnsn_new_texture(); - torii->texture->pigment = dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_blue)); + torii->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_blue)); torii->texture->finish.ambient = dmnsn_new_ambient(dmnsn_white); dmnsn_array *spike_array = DMNSN_NEW_ARRAY(dmnsn_object *); @@ -223,7 +222,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) } static void -dmnsn_test_scene_add_triangle_strip(dmnsn_scene *scene) +dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene) { dmnsn_array *strip_array = DMNSN_NEW_ARRAY(dmnsn_object *); dmnsn_vector a = dmnsn_zero; @@ -234,12 +233,9 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_scene *scene) dmnsn_new_texture(), dmnsn_new_texture(), }; - strip_textures[0]->pigment = - dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_red)); - strip_textures[1]->pigment = - dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_orange)); - strip_textures[2]->pigment = - dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_yellow)); + strip_textures[0]->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_red)); + strip_textures[1]->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_orange)); + strip_textures[2]->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_yellow)); for (unsigned int i = 0; i < 128; ++i) { dmnsn_object *triangle = dmnsn_new_flat_triangle(a, b, c); triangle->texture = strip_textures[i%3]; @@ -269,17 +265,18 @@ dmnsn_test_scene_add_ground(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_map *small_map = dmnsn_new_pigment_map(pool); dmnsn_pigment_map_add_color(small_map, 0.0, dmnsn_black); dmnsn_pigment_map_add_color(small_map, 1.0, dmnsn_white); - dmnsn_pigment *small_pigment = - dmnsn_new_pigment_map_pigment(checker, small_map, - DMNSN_PIGMENT_MAP_REGULAR); + dmnsn_pigment *small_pigment = dmnsn_new_pigment_map_pigment( + pool, checker, small_map, DMNSN_PIGMENT_MAP_REGULAR + ); small_pigment->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0)); dmnsn_map *big_map = dmnsn_new_pigment_map(pool); dmnsn_pigment_map_add_color(big_map, 0.0, dmnsn_white); dmnsn_map_add_entry(big_map, 1.0, &small_pigment); plane->texture = dmnsn_new_texture(); - plane->texture->pigment = - dmnsn_new_pigment_map_pigment(checker, big_map, DMNSN_PIGMENT_MAP_REGULAR); + plane->texture->pigment = dmnsn_new_pigment_map_pigment( + pool, checker, big_map, DMNSN_PIGMENT_MAP_REGULAR + ); plane->texture->pigment->quick_color = DMNSN_TCOLOR( dmnsn_color_from_sRGB( dmnsn_new_color(1.0, 0.5, 0.75) @@ -293,7 +290,7 @@ dmnsn_test_scene_add_objects(dmnsn_pool *pool, dmnsn_scene *scene) { dmnsn_test_scene_add_hollow_cube(pool, scene); dmnsn_test_scene_add_spike(pool, scene); - dmnsn_test_scene_add_triangle_strip(scene); + dmnsn_test_scene_add_triangle_strip(pool, scene); dmnsn_test_scene_add_ground(pool, scene); } @@ -304,7 +301,7 @@ static dmnsn_scene * dmnsn_new_test_scene(dmnsn_pool *pool) { dmnsn_scene *scene = dmnsn_new_scene(pool); - dmnsn_test_scene_set_defaults(scene); + dmnsn_test_scene_set_defaults(pool, scene); dmnsn_test_scene_add_canvas(pool, scene); dmnsn_test_scene_add_camera(pool, scene); dmnsn_test_scene_add_background(pool, scene); -- cgit v1.2.3