summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libdimension-python/dimension.pxd6
-rw-r--r--libdimension-python/dimension.pyx10
-rw-r--r--libdimension/dimension/texture.h15
-rw-r--r--libdimension/object.c1
-rw-r--r--libdimension/scene.c4
-rw-r--r--libdimension/tests/render.c20
-rw-r--r--libdimension/texture.c27
7 files changed, 22 insertions, 61 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd
index b822827..33f2300 100644
--- a/libdimension-python/dimension.pxd
+++ b/libdimension-python/dimension.pxd
@@ -295,11 +295,9 @@ cdef extern from "../libdimension/dimension.h":
dmnsn_finish finish
dmnsn_matrix trans
- dmnsn_texture *dmnsn_new_texture()
- void dmnsn_delete_texture(dmnsn_texture *texture)
+ dmnsn_texture *dmnsn_new_texture(dmnsn_pool *pool)
- void dmnsn_texture_cascade(dmnsn_texture *default_texture,
- dmnsn_texture **texture)
+ void dmnsn_texture_cascade(dmnsn_texture *default_texture, dmnsn_texture **texture)
#############
# Interiors #
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index 7c951d6..2ab683d 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -963,7 +963,7 @@ cdef class Texture(_Transformable):
pigment -- the Pigment for the texture, or a color (default: None)
finish -- the Finish for the texture (default: None)
"""
- self._texture = dmnsn_new_texture()
+ self._texture = dmnsn_new_texture(_get_pool())
if pigment is not None:
self.pigment = Pigment(pigment)
@@ -971,9 +971,6 @@ cdef class Texture(_Transformable):
if finish is not None:
self.finish = finish
- def __dealloc__(self):
- dmnsn_delete_texture(self._texture)
-
property pigment:
"""The texture's pigment."""
def __get__(self):
@@ -1005,7 +1002,6 @@ cdef Texture _Texture(dmnsn_texture *texture):
"""Wrap a Texture object around a dmnsn_texture *."""
cdef Texture self = Texture.__new__(Texture)
self._texture = texture
- DMNSN_INCREF(self._texture)
return self
#############
@@ -1095,12 +1091,10 @@ cdef class Object(_Transformable):
else:
return _Texture(self._object.texture)
def __set__(self, Texture texture):
- dmnsn_delete_texture(self._object.texture)
if texture is None:
self._object.texture = NULL
else:
self._object.texture = texture._texture
- DMNSN_INCREF(self._object.texture)
property interior:
"""The object's Interior."""
@@ -1526,9 +1520,7 @@ cdef class Scene:
def __get__(self):
return _Texture(self._scene.default_texture)
def __set__(self, Texture texture not None):
- dmnsn_delete_texture(self._scene.default_texture)
self._scene.default_texture = texture._texture
- DMNSN_INCREF(self._scene.default_texture)
property default_interior:
"""The default Interior for objects."""
def __get__(self):
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;