diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-05-31 15:06:09 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-05-31 15:06:09 -0400 |
commit | 74323fa54010d29737281579e4f3b4038da94989 (patch) | |
tree | cb0c97a58d5d103898b412be27f22f6893eb44ec /libdimension | |
parent | c42fd6547afed0b65260ae6a8a07cf9dcf084b67 (diff) | |
download | dimension-74323fa54010d29737281579e4f3b4038da94989.tar.xz |
texture: Use pool.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/texture.h | 15 | ||||
-rw-r--r-- | libdimension/object.c | 1 | ||||
-rw-r--r-- | libdimension/scene.c | 4 | ||||
-rw-r--r-- | libdimension/tests/render.c | 20 | ||||
-rw-r--r-- | libdimension/texture.c | 27 |
5 files changed, 19 insertions, 48 deletions
diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h index 52756ac..df08a4a 100644 --- a/libdimension/dimension/texture.h +++ b/libdimension/dimension/texture.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -31,21 +31,15 @@ typedef struct { dmnsn_matrix trans; /**< Transformation matrix. */ dmnsn_matrix trans_inv; /**< The inverse of the transformation matrix. */ - DMNSN_REFCOUNT; /**< Reference count. */ bool initialized; /**< @internal Whether the texture is initialized yet. */ } dmnsn_texture; /** * Create a blank texture. + * @param[in] pool The memory pool to allocate from. * @return The new texture. */ -dmnsn_texture *dmnsn_new_texture(void); - -/** - * Delete a texture. - * @param[in,out] texture The texture to delete. - */ -void dmnsn_delete_texture(dmnsn_texture *texture); +dmnsn_texture *dmnsn_new_texture(dmnsn_pool *pool); /** * Initialize a texture. Textures should not be used before being initialized, @@ -60,5 +54,4 @@ void dmnsn_texture_initialize(dmnsn_texture *texture); * @param[in] default_texture The default texture. * @param[in,out] texturep A pointer to the texture to fill. */ -void dmnsn_texture_cascade(dmnsn_texture *default_texture, - dmnsn_texture **texturep); +void dmnsn_texture_cascade(dmnsn_texture *default_texture, dmnsn_texture **texturep); diff --git a/libdimension/object.c b/libdimension/object.c index 7b6bb73..674eea8 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -68,7 +68,6 @@ dmnsn_delete_object(dmnsn_object *object) dmnsn_delete_object(*child); } dmnsn_delete_array(object->children); - dmnsn_delete_texture(object->texture); object->free_fn(object); } } diff --git a/libdimension/scene.c b/libdimension/scene.c index e1497cb..c3aac1f 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -35,8 +35,6 @@ dmnsn_scene_cleanup(void *ptr) dmnsn_delete_object(*object); } dmnsn_delete_array(scene->objects); - - dmnsn_delete_texture(scene->default_texture); } /* Allocate an empty scene */ @@ -46,7 +44,7 @@ dmnsn_new_scene(dmnsn_pool *pool) dmnsn_scene *scene = DMNSN_PALLOC_TIDY(pool, dmnsn_scene, dmnsn_scene_cleanup); scene->background = NULL; - scene->default_texture = dmnsn_new_texture(); + scene->default_texture = dmnsn_new_texture(pool); scene->default_interior = dmnsn_new_interior(pool); scene->canvas = NULL; scene->region_x = 0; diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index 38451f7..d093947 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -123,7 +123,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_new_vector(dmnsn_radians(45.0), 0.0, 0.0) ); - cube->texture = dmnsn_new_texture(); + cube->texture = dmnsn_new_texture(pool); dmnsn_tcolor cube_color = dmnsn_new_tcolor(dmnsn_blue, 0.75, 1.0/3.0); cube->texture->pigment = dmnsn_new_solid_pigment(pool, cube_color); @@ -134,7 +134,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene) cube->interior->ior = 1.1; dmnsn_object *sphere = dmnsn_new_sphere(); - sphere->texture = dmnsn_new_texture(); + sphere->texture = dmnsn_new_texture(pool); sphere->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_green)); sphere->texture->finish.specular = dmnsn_new_phong(pool, dmnsn_sRGB_inverse_gamma(0.2), 40.0); sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25)); @@ -177,7 +177,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_pigment_map_add_color(gradient_pigment_map, 4.0/6.0, dmnsn_blue); 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 = dmnsn_new_texture(pool); arrow->texture->pigment = dmnsn_new_pigment_map_pigment( pool, gradient, gradient_pigment_map, DMNSN_PIGMENT_MAP_SRGB ); @@ -203,7 +203,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 = dmnsn_new_texture(pool); torii->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_blue)); torii->texture->finish.ambient = dmnsn_new_ambient(pool, dmnsn_white); @@ -226,9 +226,9 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_vector b = dmnsn_new_vector(0.0, sqrt(3.0)/2.0, 0.5); dmnsn_vector c = dmnsn_z; dmnsn_texture *strip_textures[3] = { - dmnsn_new_texture(), - dmnsn_new_texture(), - dmnsn_new_texture(), + dmnsn_new_texture(pool), + dmnsn_new_texture(pool), + dmnsn_new_texture(pool), }; 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)); @@ -236,16 +236,12 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene) for (unsigned int i = 0; i < 128; ++i) { dmnsn_object *triangle = dmnsn_new_flat_triangle(a, b, c); triangle->texture = strip_textures[i%3]; - DMNSN_INCREF(triangle->texture); dmnsn_array_push(strip_array, &triangle); a = b; b = c; c = dmnsn_vector_add(a, dmnsn_z); } - for (unsigned int i = 0; i < 3; ++i) { - dmnsn_delete_texture(strip_textures[i]); - } dmnsn_object *strip = dmnsn_new_csg_union(strip_array); dmnsn_delete_array(strip_array); @@ -270,7 +266,7 @@ dmnsn_test_scene_add_ground(dmnsn_pool *pool, dmnsn_scene *scene) 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 = dmnsn_new_texture(pool); plane->texture->pigment = dmnsn_new_pigment_map_pigment( pool, checker, big_map, DMNSN_PIGMENT_MAP_REGULAR ); diff --git a/libdimension/texture.c b/libdimension/texture.c index 0727ea1..515e260 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -25,29 +25,17 @@ #include "dimension-internal.h" -/* Allocate a dummy texture */ dmnsn_texture * -dmnsn_new_texture(void) +dmnsn_new_texture(dmnsn_pool *pool) { - dmnsn_texture *texture = DMNSN_MALLOC(dmnsn_texture); - texture->pigment = NULL; - texture->finish = dmnsn_new_finish(); - texture->trans = dmnsn_identity_matrix(); + dmnsn_texture *texture = DMNSN_PALLOC(pool, dmnsn_texture); + texture->pigment = NULL; + texture->finish = dmnsn_new_finish(); + texture->trans = dmnsn_identity_matrix(); texture->initialized = false; - DMNSN_REFCOUNT_INIT(texture); return texture; } -/* Free a texture */ -void -dmnsn_delete_texture(dmnsn_texture *texture) -{ - if (DMNSN_DECREF(texture)) { - dmnsn_free(texture); - } -} - -/* Calculate matrix inverses */ void dmnsn_texture_initialize(dmnsn_texture *texture) { @@ -63,14 +51,11 @@ dmnsn_texture_initialize(dmnsn_texture *texture) } } -/* Cascade a texture */ void -dmnsn_texture_cascade(dmnsn_texture *default_texture, - dmnsn_texture **texturep) +dmnsn_texture_cascade(dmnsn_texture *default_texture, dmnsn_texture **texturep) { if (!*texturep) { *texturep = default_texture; - DMNSN_INCREF(*texturep); } dmnsn_texture *texture = *texturep; |