From 7acd8ea6673b7a90ed4041408ccf1b024b8a007a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 12 Jun 2011 02:37:51 -0600 Subject: Vast libdimension API and internals improvements. Couldn't really do these while I was trying to be POV-Ray compatible, 'cause they would've broken compatibility. --- libdimension/texture.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'libdimension/texture.c') diff --git a/libdimension/texture.c b/libdimension/texture.c index c65c913..6f52abe 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -31,10 +31,10 @@ dmnsn_new_texture(void) { dmnsn_texture *texture = dmnsn_malloc(sizeof(dmnsn_texture)); texture->pigment = NULL; - texture->finish = NULL; + texture->finish = dmnsn_new_finish(); texture->trans = dmnsn_identity_matrix(); - texture->refcount = 0; - texture->should_init = true; + texture->refcount = 1; + texture->initialized = false; return texture; } @@ -42,7 +42,7 @@ dmnsn_new_texture(void) void dmnsn_delete_texture(dmnsn_texture *texture) { - if (texture && DMNSN_DECREF(texture)) { + if (DMNSN_DECREF(texture)) { dmnsn_delete_finish(texture->finish); dmnsn_delete_pigment(texture->pigment); dmnsn_free(texture); @@ -53,10 +53,34 @@ dmnsn_delete_texture(dmnsn_texture *texture) void dmnsn_initialize_texture(dmnsn_texture *texture) { + dmnsn_assert(!texture->initialized, "Texture double-initialized."); + texture->initialized = true; + texture->trans_inv = dmnsn_matrix_inverse(texture->trans); - if (texture->pigment) { - texture->pigment->trans - = dmnsn_matrix_mul(texture->trans, texture->pigment->trans); + + if (!texture->pigment->initialized) { + texture->pigment->trans = dmnsn_matrix_mul(texture->trans, + texture->pigment->trans); dmnsn_initialize_pigment(texture->pigment); } } + +/* Cascade a texture */ +void +dmnsn_texture_cascade(dmnsn_texture *default_texture, + dmnsn_texture **texturep) +{ + if (!*texturep) { + *texturep = default_texture; + DMNSN_INCREF(*texturep); + } + + dmnsn_texture *texture = *texturep; + + if (!texture->pigment) { + texture->pigment = default_texture->pigment; + DMNSN_INCREF(texture->pigment); + } + + dmnsn_finish_cascade(&default_texture->finish, &texture->finish); +} -- cgit v1.2.3