summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-31 13:54:56 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-31 13:55:26 -0400
commitc10255ab3da17507d63bdc7e1fdfc809ffd32f7f (patch)
treede65eefb9152ebb049c2adbb8e2cf00abe09063e /libdimension
parent70373204b341fc91694c0293796230e447c51067 (diff)
downloaddimension-c10255ab3da17507d63bdc7e1fdfc809ffd32f7f.tar.xz
pigment: Use pool.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/canvas_pigment.c16
-rw-r--r--libdimension/dimension/map.h6
-rw-r--r--libdimension/dimension/pigment.h17
-rw-r--r--libdimension/dimension/pigments.h17
-rw-r--r--libdimension/map.c33
-rw-r--r--libdimension/pigment.c21
-rw-r--r--libdimension/pigment_map.c26
-rw-r--r--libdimension/scene.c1
-rw-r--r--libdimension/solid_pigment.c6
-rw-r--r--libdimension/tests/render.c65
-rw-r--r--libdimension/texture.c2
11 files changed, 66 insertions, 144 deletions
diff --git a/libdimension/canvas_pigment.c b/libdimension/canvas_pigment.c
index bc5653e..d4812cf 100644
--- a/libdimension/canvas_pigment.c
+++ b/libdimension/canvas_pigment.c
@@ -35,8 +35,7 @@ typedef struct dmnsn_canvas_pigment {
static dmnsn_tcolor
dmnsn_canvas_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v)
{
- const dmnsn_canvas_pigment *canvas_pigment =
- (const dmnsn_canvas_pigment *)pigment;
+ const dmnsn_canvas_pigment *canvas_pigment = (const dmnsn_canvas_pigment *)pigment;
dmnsn_canvas *canvas = canvas_pigment->canvas;
size_t x = llround((fmod(v.x, 1.0) + 1.0)*(canvas->width - 1));
@@ -44,24 +43,15 @@ dmnsn_canvas_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v)
return dmnsn_canvas_get_pixel(canvas, x%canvas->width, y%canvas->height);
}
-/** Canvas pigment destructor. */
-static void
-dmnsn_canvas_pigment_free_fn(dmnsn_pigment *pigment)
-{
- dmnsn_canvas_pigment *canvas_pigment = (dmnsn_canvas_pigment *)pigment;
- dmnsn_free(canvas_pigment);
-}
-
/* Create a canvas color */
dmnsn_pigment *
-dmnsn_new_canvas_pigment(dmnsn_canvas *canvas)
+dmnsn_new_canvas_pigment(dmnsn_pool *pool, dmnsn_canvas *canvas)
{
- dmnsn_canvas_pigment *canvas_pigment = DMNSN_MALLOC(dmnsn_canvas_pigment);
+ dmnsn_canvas_pigment *canvas_pigment = DMNSN_PALLOC(pool, dmnsn_canvas_pigment);
canvas_pigment->canvas = canvas;
dmnsn_pigment *pigment = &canvas_pigment->pigment;
dmnsn_init_pigment(pigment);
pigment->pigment_fn = dmnsn_canvas_pigment_fn;
- pigment->free_fn = dmnsn_canvas_pigment_free_fn;
return pigment;
}
diff --git a/libdimension/dimension/map.h b/libdimension/dimension/map.h
index 77b1fe9..7229a24 100644
--- a/libdimension/dimension/map.h
+++ b/libdimension/dimension/map.h
@@ -24,11 +24,7 @@
*/
/** A map. */
-typedef struct dmnsn_map {
- dmnsn_free_fn *free_fn; /**< Destructor callback. */
- size_t obj_size; /**< @internal The size of the mapped objects. */
- dmnsn_array *array; /**< @internal The map entries. */
-} dmnsn_map;
+typedef struct dmnsn_map dmnsn_map;
/**
* Create an empty map.
diff --git a/libdimension/dimension/pigment.h b/libdimension/dimension/pigment.h
index 455ee72..14d8bae 100644
--- a/libdimension/dimension/pigment.h
+++ b/libdimension/dimension/pigment.h
@@ -41,17 +41,10 @@ typedef dmnsn_tcolor dmnsn_pigment_fn(const dmnsn_pigment *pigment,
*/
typedef void dmnsn_pigment_initialize_fn(dmnsn_pigment *pigment);
-/**
- * Pigment destructor callback.
- * @param[in,out] pigment The pigment to destroy.
- */
-typedef void dmnsn_pigment_free_fn(dmnsn_pigment *pigment);
-
/** A pigment. */
struct dmnsn_pigment {
dmnsn_pigment_fn *pigment_fn; /**< The pigment callback. */
dmnsn_pigment_initialize_fn *initialize_fn; /**< The initializer callback. */
- dmnsn_pigment_free_fn *free_fn; /**< The destructor callback. */
dmnsn_matrix trans; /**< Transformation matrix. */
dmnsn_matrix trans_inv; /**< The inverse of the transformation matrix. */
@@ -59,15 +52,15 @@ struct dmnsn_pigment {
/** Quick color -- used for low-quality renders. */
dmnsn_tcolor quick_color;
- DMNSN_REFCOUNT; /** Reference count. */
bool initialized; /** @internal Whether the pigment is initialized. */
};
/**
* Allocate a new dummy pigment.
+ * @param[in] pool The memory pool to allocate from.
* @return The allocated pigment.
*/
-dmnsn_pigment *dmnsn_new_pigment(void);
+dmnsn_pigment *dmnsn_new_pigment(dmnsn_pool *pool);
/**
* Initialize a dmnsn_pigment field.
@@ -76,12 +69,6 @@ dmnsn_pigment *dmnsn_new_pigment(void);
void dmnsn_init_pigment(dmnsn_pigment *pigment);
/**
- * Delete a pigment.
- * @param[in,out] pigment The pigment to delete.
- */
-void dmnsn_delete_pigment(dmnsn_pigment *pigment);
-
-/**
* Initialize a pigment. Pigments should not be used before being initialized,
* but should not be modified after being initialized. Pigments are generally
* initialized for you.
diff --git a/libdimension/dimension/pigments.h b/libdimension/dimension/pigments.h
index e2ea274..100016d 100644
--- a/libdimension/dimension/pigments.h
+++ b/libdimension/dimension/pigments.h
@@ -25,25 +25,27 @@
/**
* A solid color.
+ * @param[in] pool The memory pool to allocate from.
* @param[in] color The color of the pigment.
* @return A pigment with the color \p color everywhere.
*/
-dmnsn_pigment *dmnsn_new_solid_pigment(dmnsn_tcolor color);
+dmnsn_pigment *dmnsn_new_solid_pigment(dmnsn_pool *pool, dmnsn_tcolor color);
/**
* An image map. The image (regardless of its real dimensions) is projected
* on the x-y plane in tesselating unit squares.
+ * @param[in] pool The memory pool to allocate from.
* @param[in] canvas The canvas holding the image.
* @return An image-mapped pigment.
*/
-dmnsn_pigment *dmnsn_new_canvas_pigment(dmnsn_canvas *canvas);
+dmnsn_pigment *dmnsn_new_canvas_pigment(dmnsn_pool *pool, dmnsn_canvas *canvas);
/**
* Pigment map flags.
*/
typedef enum dmnsn_pigment_map_flags {
DMNSN_PIGMENT_MAP_REGULAR, /**< Calculate linear color gradients. */
- DMNSN_PIGMENT_MAP_SRGB /**< Calculate sRGB color gradients. */
+ DMNSN_PIGMENT_MAP_SRGB /**< Calculate sRGB color gradients. */
} dmnsn_pigment_map_flags;
/**
@@ -55,11 +57,10 @@ dmnsn_map *dmnsn_new_pigment_map(dmnsn_pool *pool);
/**
* A pigment-mapped pigment.
+ * @param[in] pool The memory pool to allocate from.
* @param[in,out] pattern The pattern of the pigment.
- * @param[in,out] map The pigment map to apply to the pattern.
- * @param[in] flags Gradient flags
+ * @param[in,out] map The pigment map to apply to the pattern.
+ * @param[in] flags Gradient flags
* @return A pigment mapping the pattern to other pigments.
*/
-dmnsn_pigment *dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern,
- dmnsn_map *map,
- dmnsn_pigment_map_flags flags);
+dmnsn_pigment *dmnsn_new_pigment_map_pigment(dmnsn_pool *pool, dmnsn_pattern *pattern, dmnsn_map *map, dmnsn_pigment_map_flags flags);
diff --git a/libdimension/map.c b/libdimension/map.c
index df07ec8..9a85773 100644
--- a/libdimension/map.c
+++ b/libdimension/map.c
@@ -25,41 +25,32 @@
#include "dimension.h"
+/** dmnsn_map definition. */
+struct dmnsn_map {
+ size_t obj_size; /**< @internal The size of the mapped objects. */
+ dmnsn_array *array; /**< @internal The map entries. */
+};
+
/** An [index, object] pair. */
typedef struct dmnsn_map_entry {
double n;
char object[];
} dmnsn_map_entry;
-static void
-dmnsn_map_cleanup(void *ptr)
-{
- dmnsn_map *map = ptr;
- if (map->free_fn) {
- for (size_t i = 0; i < dmnsn_array_size(map->array); ++i) {
- dmnsn_map_entry *entry = dmnsn_array_at(map->array, i);
- map->free_fn(entry->object);
- }
- }
-
- dmnsn_delete_array(map->array);
-}
-
dmnsn_map *
dmnsn_new_map(dmnsn_pool *pool, size_t size)
{
- dmnsn_map *map = DMNSN_PALLOC_TIDY(pool, dmnsn_map, dmnsn_map_cleanup);
- map->free_fn = NULL;
+ dmnsn_map *map = DMNSN_PALLOC(pool, dmnsn_map);
map->obj_size = size;
- map->array = dmnsn_new_array(sizeof(dmnsn_map_entry) + size);
+ map->array = dmnsn_palloc_array(pool, sizeof(dmnsn_map_entry) + size);
return map;
}
void
dmnsn_map_add_entry(dmnsn_map *map, double n, const void *obj)
{
- dmnsn_map_entry *entry
- = dmnsn_malloc(sizeof(dmnsn_map_entry) + map->obj_size);
+ char mem[sizeof(dmnsn_map_entry) + map->obj_size];
+ dmnsn_map_entry *entry = (dmnsn_map_entry *)mem;
entry->n = n;
memcpy(entry->object, obj, map->obj_size);
@@ -67,12 +58,12 @@ dmnsn_map_add_entry(dmnsn_map *map, double n, const void *obj)
size_t i;
for (i = dmnsn_array_size(map->array); i-- > 0;) {
dmnsn_map_entry *other = dmnsn_array_at(map->array, i);
- if (other->n <= n)
+ if (other->n <= n) {
break;
+ }
}
dmnsn_array_insert(map->array, i + 1, entry);
- dmnsn_free(entry);
}
size_t
diff --git a/libdimension/pigment.c b/libdimension/pigment.c
index e392d7b..5756087 100644
--- a/libdimension/pigment.c
+++ b/libdimension/pigment.c
@@ -25,17 +25,11 @@
#include "dimension-internal.h"
-static void
-dmnsn_default_pigment_free_fn(dmnsn_pigment *pigment)
-{
- dmnsn_free(pigment);
-}
-
/* Allocate a dummy pigment */
dmnsn_pigment *
-dmnsn_new_pigment(void)
+dmnsn_new_pigment(dmnsn_pool *pool)
{
- dmnsn_pigment *pigment = DMNSN_MALLOC(dmnsn_pigment);
+ dmnsn_pigment *pigment = DMNSN_PALLOC(pool, dmnsn_pigment);
dmnsn_init_pigment(pigment);
return pigment;
}
@@ -46,20 +40,9 @@ dmnsn_init_pigment(dmnsn_pigment *pigment)
{
pigment->pigment_fn = NULL;
pigment->initialize_fn = NULL;
- pigment->free_fn = dmnsn_default_pigment_free_fn;
pigment->trans = dmnsn_identity_matrix();
pigment->quick_color = DMNSN_TCOLOR(dmnsn_black);
pigment->initialized = false;
- DMNSN_REFCOUNT_INIT(pigment);
-}
-
-/* Free a pigment */
-void
-dmnsn_delete_pigment(dmnsn_pigment *pigment)
-{
- if (DMNSN_DECREF(pigment)) {
- pigment->free_fn(pigment);
- }
}
/* Precompute pigment properties */
diff --git a/libdimension/pigment_map.c b/libdimension/pigment_map.c
index a8a4b75..a4240d2 100644
--- a/libdimension/pigment_map.c
+++ b/libdimension/pigment_map.c
@@ -33,20 +33,10 @@ dmnsn_initialize_mapped_pigment(void *ptr)
dmnsn_pigment_initialize(*pigment);
}
-/** Free a pigment in a pigment map. */
-static void
-dmnsn_delete_mapped_pigment(void *ptr)
-{
- dmnsn_pigment **pigment = ptr;
- dmnsn_delete_pigment(*pigment);
-}
-
dmnsn_map *
dmnsn_new_pigment_map(dmnsn_pool *pool)
{
- dmnsn_map *pigment_map = dmnsn_new_map(pool, sizeof(dmnsn_pigment *));
- pigment_map->free_fn = dmnsn_delete_mapped_pigment;
- return pigment_map;
+ return dmnsn_new_map(pool, sizeof(dmnsn_pigment *));
}
/** Pigment map type. */
@@ -57,14 +47,6 @@ typedef struct dmnsn_pigment_map {
dmnsn_pigment_map_flags flags;
} dmnsn_pigment_map;
-/** Free a pigment map. */
-static void
-dmnsn_pigment_map_free_fn(dmnsn_pigment *pigment)
-{
- dmnsn_pigment_map *pigment_map = (dmnsn_pigment_map *)pigment;
- dmnsn_free(pigment_map);
-}
-
/** pigment_map pigment callback. */
static dmnsn_tcolor
dmnsn_pigment_map_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v)
@@ -99,10 +81,9 @@ dmnsn_pigment_map_initialize_fn(dmnsn_pigment *pigment)
}
dmnsn_pigment *
-dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map,
- dmnsn_pigment_map_flags flags)
+dmnsn_new_pigment_map_pigment(dmnsn_pool *pool, dmnsn_pattern *pattern, dmnsn_map *map, dmnsn_pigment_map_flags flags)
{
- dmnsn_pigment_map *pigment_map = DMNSN_MALLOC(dmnsn_pigment_map);
+ dmnsn_pigment_map *pigment_map = DMNSN_PALLOC(pool, dmnsn_pigment_map);
pigment_map->pattern = pattern;
pigment_map->map = map;
pigment_map->flags = flags;
@@ -111,6 +92,5 @@ dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map,
dmnsn_init_pigment(pigment);
pigment->pigment_fn = dmnsn_pigment_map_pigment_fn;
pigment->initialize_fn = dmnsn_pigment_map_initialize_fn;
- pigment->free_fn = dmnsn_pigment_map_free_fn;
return pigment;
}
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 4a083cf..e1497cb 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -37,7 +37,6 @@ dmnsn_scene_cleanup(void *ptr)
dmnsn_delete_array(scene->objects);
dmnsn_delete_texture(scene->default_texture);
- dmnsn_delete_pigment(scene->background);
}
/* Allocate an empty scene */
diff --git a/libdimension/solid_pigment.c b/libdimension/solid_pigment.c
index 7f91819..1f6cf6f 100644
--- a/libdimension/solid_pigment.c
+++ b/libdimension/solid_pigment.c
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2010-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -28,9 +28,9 @@
/* Create a solid color */
dmnsn_pigment *
-dmnsn_new_solid_pigment(dmnsn_tcolor color)
+dmnsn_new_solid_pigment(dmnsn_pool *pool, dmnsn_tcolor color)
{
- dmnsn_pigment *pigment = dmnsn_new_pigment();
+ dmnsn_pigment *pigment = dmnsn_new_pigment(pool);
pigment->quick_color = color;
return pigment;
}
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 <stdio.h>
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);
diff --git a/libdimension/texture.c b/libdimension/texture.c
index 516a50b..37a937b 100644
--- a/libdimension/texture.c
+++ b/libdimension/texture.c
@@ -44,7 +44,6 @@ dmnsn_delete_texture(dmnsn_texture *texture)
{
if (DMNSN_DECREF(texture)) {
dmnsn_delete_finish(texture->finish);
- dmnsn_delete_pigment(texture->pigment);
dmnsn_free(texture);
}
}
@@ -79,7 +78,6 @@ dmnsn_texture_cascade(dmnsn_texture *default_texture,
if (!texture->pigment) {
texture->pigment = default_texture->pigment;
- DMNSN_INCREF(texture->pigment);
}
dmnsn_finish_cascade(&default_texture->finish, &texture->finish);