summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-30 17:42:14 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-30 17:42:34 -0400
commitc2b4dcc7660407f687604afe2c03eff0a4ff3a16 (patch)
tree0c2448810fd79aa3ab9b71f627032f18e031db20 /libdimension
parent45e219eac23ea4a8181f68300fed693d9ac361a0 (diff)
downloaddimension-c2b4dcc7660407f687604afe2c03eff0a4ff3a16.tar.xz
camera: Use pool.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/camera.c20
-rw-r--r--libdimension/dimension/camera.h18
-rw-r--r--libdimension/dimension/cameras.h5
-rw-r--r--libdimension/perspective.c4
-rw-r--r--libdimension/scene.c1
-rw-r--r--libdimension/tests/render.c6
6 files changed, 12 insertions, 42 deletions
diff --git a/libdimension/camera.c b/libdimension/camera.c
index 38fde35..3db9f2c 100644
--- a/libdimension/camera.c
+++ b/libdimension/camera.c
@@ -26,16 +26,11 @@
#include "dimension-internal.h"
#include <stdlib.h>
-static void dmnsn_default_camera_free_fn(dmnsn_camera *camera)
-{
- dmnsn_free(camera);
-}
-
/* Allocate a new dummy camera */
dmnsn_camera *
-dmnsn_new_camera(void)
+dmnsn_new_camera(dmnsn_pool *pool)
{
- dmnsn_camera *camera = DMNSN_MALLOC(dmnsn_camera);
+ dmnsn_camera *camera = DMNSN_PALLOC(pool, dmnsn_camera);
dmnsn_init_camera(camera);
return camera;
}
@@ -44,18 +39,7 @@ dmnsn_new_camera(void)
void
dmnsn_init_camera(dmnsn_camera *camera)
{
- camera->free_fn = dmnsn_default_camera_free_fn;
camera->trans = dmnsn_identity_matrix();
- DMNSN_REFCOUNT_INIT(camera);
-}
-
-/* Free a dummy camera */
-void
-dmnsn_delete_camera(dmnsn_camera *camera)
-{
- if (DMNSN_DECREF(camera)) {
- camera->free_fn(camera);
- }
}
/* Invoke the camera ray function */
diff --git a/libdimension/dimension/camera.h b/libdimension/dimension/camera.h
index e94e227..3c6494c 100644
--- a/libdimension/dimension/camera.h
+++ b/libdimension/dimension/camera.h
@@ -36,28 +36,20 @@ typedef struct dmnsn_camera dmnsn_camera;
typedef dmnsn_line dmnsn_camera_ray_fn(const dmnsn_camera *camera,
double x, double y);
-/**
- * Camera destruction callback.
- * @param[in,out] camera The camera to delete.
- */
-typedef void dmnsn_camera_free_fn(dmnsn_camera *camera);
-
/** A camera. */
struct dmnsn_camera {
/* Callback functions */
dmnsn_camera_ray_fn *ray_fn; /**< Camera ray callback. */
- dmnsn_camera_free_fn *free_fn; /**< Destructor callback. */
dmnsn_matrix trans; /**< Transformation matrix. */
-
- DMNSN_REFCOUNT; /**< Reference count. */
};
/**
* Create a dummy camera.
+ * @param[in] pool The memory pool to allocate from.
* @return The allocated camera.
*/
-dmnsn_camera *dmnsn_new_camera(void);
+dmnsn_camera *dmnsn_new_camera(dmnsn_pool *pool);
/**
* Initialize a dmnsn_camera field.
@@ -66,12 +58,6 @@ dmnsn_camera *dmnsn_new_camera(void);
void dmnsn_init_camera(dmnsn_camera *camera);
/**
- * Delete a camera.
- * @param[in,out] camera The camera to delete.
- */
-void dmnsn_delete_camera(dmnsn_camera *camera);
-
-/**
* Invoke the camera ray callback, then correctly transform the ray.
* @param[in] camera The camera itself.
* @param[in] x The x coordinate of the pixel (in [0, 1]).
diff --git a/libdimension/dimension/cameras.h b/libdimension/dimension/cameras.h
index d7f44b2..9ef2646 100644
--- a/libdimension/dimension/cameras.h
+++ b/libdimension/dimension/cameras.h
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2009-2010 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -28,6 +28,7 @@
* (0, 0, 1). The feild of view is the section of the plane z = 1 from
* (-0.5, -0.5) to (0.5, 0.5). Rays are transformed by the camera's
* transformation matrix.
+ * @param[in] pool The memory pool to allocate from.
* @return A perspective camera.
*/
-dmnsn_camera *dmnsn_new_perspective_camera(void);
+dmnsn_camera *dmnsn_new_perspective_camera(dmnsn_pool *pool);
diff --git a/libdimension/perspective.c b/libdimension/perspective.c
index 10b7c18..a87f673 100644
--- a/libdimension/perspective.c
+++ b/libdimension/perspective.c
@@ -39,9 +39,9 @@ dmnsn_perspective_camera_ray_fn(const dmnsn_camera *camera, double x, double y)
/* Create a new perspective camera. */
dmnsn_camera *
-dmnsn_new_perspective_camera(void)
+dmnsn_new_perspective_camera(dmnsn_pool *pool)
{
- dmnsn_camera *camera = dmnsn_new_camera();
+ dmnsn_camera *camera = dmnsn_new_camera(pool);
camera->ray_fn = dmnsn_perspective_camera_ray_fn;
return camera;
}
diff --git a/libdimension/scene.c b/libdimension/scene.c
index cc2ee98..59b4dc5 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -66,7 +66,6 @@ dmnsn_delete_scene(dmnsn_scene *scene)
dmnsn_delete_array(scene->lights);
dmnsn_delete_array(scene->objects);
- dmnsn_delete_camera(scene->camera);
dmnsn_delete_interior(scene->default_interior);
dmnsn_delete_texture(scene->default_texture);
dmnsn_delete_pigment(scene->background);
diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c
index f5ba685..c89a679 100644
--- a/libdimension/tests/render.c
+++ b/libdimension/tests/render.c
@@ -42,7 +42,7 @@ dmnsn_test_scene_add_canvas(dmnsn_pool *pool, dmnsn_scene *scene)
}
static void
-dmnsn_test_scene_add_camera(dmnsn_scene *scene)
+dmnsn_test_scene_add_camera(dmnsn_pool *pool, dmnsn_scene *scene)
{
/* Set up the transformation matrix for the perspective camera */
dmnsn_matrix trans = dmnsn_scale_matrix(
@@ -64,7 +64,7 @@ dmnsn_test_scene_add_camera(dmnsn_scene *scene)
);
/* Create a perspective camera */
- scene->camera = dmnsn_new_perspective_camera();
+ scene->camera = dmnsn_new_perspective_camera(pool);
scene->camera->trans = trans;
}
@@ -306,7 +306,7 @@ dmnsn_new_test_scene(dmnsn_pool *pool)
dmnsn_scene *scene = dmnsn_new_scene(pool);
dmnsn_test_scene_set_defaults(scene);
dmnsn_test_scene_add_canvas(pool, scene);
- dmnsn_test_scene_add_camera(scene);
+ dmnsn_test_scene_add_camera(pool, scene);
dmnsn_test_scene_add_background(pool, scene);
dmnsn_test_scene_add_lights(scene);
dmnsn_test_scene_add_objects(scene);