forked from bartvdbraak/blender
Cleanup: add ImageKey to avoid longer argument lists and duplicated code
This commit is contained in:
parent
78391def6e
commit
d675cf20a1
@ -640,6 +640,14 @@ static ShaderNode *add_node(Scene *scene,
|
||||
BL::Image b_image(b_image_node.image());
|
||||
BL::ImageUser b_image_user(b_image_node.image_user());
|
||||
ImageTextureNode *image = new ImageTextureNode();
|
||||
|
||||
image->interpolation = get_image_interpolation(b_image_node);
|
||||
image->extension = get_image_extension(b_image_node);
|
||||
image->projection = (NodeImageProjection)b_image_node.projection();
|
||||
image->projection_blend = b_image_node.projection_blend();
|
||||
BL::TexMapping b_texture_mapping(b_image_node.texture_mapping());
|
||||
get_tex_mapping(&image->tex_mapping, b_texture_mapping);
|
||||
|
||||
if (b_image) {
|
||||
/* builtin images will use callback-based reading because
|
||||
* they could only be loaded correct from blender side
|
||||
@ -682,21 +690,10 @@ static ShaderNode *add_node(Scene *scene,
|
||||
/* TODO(sergey): Does not work properly when we change builtin type. */
|
||||
#if 0
|
||||
if (b_image.is_updated()) {
|
||||
scene->image_manager->tag_reload_image(image->filename.string(),
|
||||
image->builtin_data,
|
||||
get_image_interpolation(b_image_node),
|
||||
get_image_extension(b_image_node),
|
||||
image->use_alpha,
|
||||
image->colorspace);
|
||||
scene->image_manager->tag_reload_image(image->image_key());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
image->projection = (NodeImageProjection)b_image_node.projection();
|
||||
image->interpolation = get_image_interpolation(b_image_node);
|
||||
image->extension = get_image_extension(b_image_node);
|
||||
image->projection_blend = b_image_node.projection_blend();
|
||||
BL::TexMapping b_texture_mapping(b_image_node.texture_mapping());
|
||||
get_tex_mapping(&image->tex_mapping, b_texture_mapping);
|
||||
node = image;
|
||||
}
|
||||
else if (b_node.is_a(&RNA_ShaderNodeTexEnvironment)) {
|
||||
@ -704,6 +701,12 @@ static ShaderNode *add_node(Scene *scene,
|
||||
BL::Image b_image(b_env_node.image());
|
||||
BL::ImageUser b_image_user(b_env_node.image_user());
|
||||
EnvironmentTextureNode *env = new EnvironmentTextureNode();
|
||||
|
||||
env->interpolation = get_image_interpolation(b_env_node);
|
||||
env->projection = (NodeEnvironmentProjection)b_env_node.projection();
|
||||
BL::TexMapping b_texture_mapping(b_env_node.texture_mapping());
|
||||
get_tex_mapping(&env->tex_mapping, b_texture_mapping);
|
||||
|
||||
if (b_image) {
|
||||
bool is_builtin = b_image.packed_file() || b_image.source() == BL::Image::source_GENERATED ||
|
||||
b_image.source() == BL::Image::source_MOVIE ||
|
||||
@ -731,19 +734,10 @@ static ShaderNode *add_node(Scene *scene,
|
||||
/* TODO(sergey): Does not work properly when we change builtin type. */
|
||||
#if 0
|
||||
if (b_image.is_updated()) {
|
||||
scene->image_manager->tag_reload_image(env->filename.string(),
|
||||
env->builtin_data,
|
||||
get_image_interpolation(b_env_node),
|
||||
EXTENSION_REPEAT,
|
||||
env->use_alpha,
|
||||
env->colorspace);
|
||||
scene->image_manager->tag_reload_image(env->image_key());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
env->interpolation = get_image_interpolation(b_env_node);
|
||||
env->projection = (NodeEnvironmentProjection)b_env_node.projection();
|
||||
BL::TexMapping b_texture_mapping(b_env_node.texture_mapping());
|
||||
get_tex_mapping(&env->tex_mapping, b_texture_mapping);
|
||||
node = env;
|
||||
}
|
||||
else if (b_node.is_a(&RNA_ShaderNodeTexGradient)) {
|
||||
@ -896,12 +890,7 @@ static ShaderNode *add_node(Scene *scene,
|
||||
if (true) {
|
||||
point_density->add_image();
|
||||
b_point_density_node.cache_point_density(b_depsgraph);
|
||||
scene->image_manager->tag_reload_image(point_density->filename.string(),
|
||||
point_density->builtin_data,
|
||||
point_density->interpolation,
|
||||
EXTENSION_CLIP,
|
||||
IMAGE_ALPHA_AUTO,
|
||||
u_colorspace_raw);
|
||||
scene->image_manager->tag_reload_image(point_density->image_key());
|
||||
}
|
||||
node = point_density;
|
||||
|
||||
|
@ -51,18 +51,13 @@ static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Mesh *mesh, float
|
||||
Attribute *attr = mesh->attributes.add(std);
|
||||
VoxelAttribute *volume_data = attr->data_voxel();
|
||||
ImageMetaData metadata;
|
||||
bool animated = false;
|
||||
|
||||
ImageKey key;
|
||||
key.filename = Attribute::standard_name(std);
|
||||
key.builtin_data = b_ob.ptr.data;
|
||||
|
||||
volume_data->manager = image_manager;
|
||||
volume_data->slot = image_manager->add_image(Attribute::standard_name(std),
|
||||
b_ob.ptr.data,
|
||||
animated,
|
||||
frame,
|
||||
INTERPOLATION_LINEAR,
|
||||
EXTENSION_CLIP,
|
||||
IMAGE_ALPHA_AUTO,
|
||||
u_colorspace_raw,
|
||||
metadata);
|
||||
volume_data->slot = image_manager->add_image(key, frame, metadata);
|
||||
}
|
||||
|
||||
/* Create a matrix to transform from object space to mesh texture space.
|
||||
|
@ -129,7 +129,7 @@ bool ImageManager::set_animation_frame_update(int frame)
|
||||
|
||||
for (size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
||||
for (size_t slot = 0; slot < images[type].size(); slot++) {
|
||||
if (images[type][slot] && images[type][slot]->animated)
|
||||
if (images[type][slot] && images[type][slot]->key.animated)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -198,17 +198,14 @@ void ImageManager::metadata_detect_colorspace(ImageMetaData &metadata, const cha
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageManager::get_image_metadata(const string &filename,
|
||||
void *builtin_data,
|
||||
ustring colorspace,
|
||||
ImageMetaData &metadata)
|
||||
bool ImageManager::get_image_metadata(const ImageKey &key, ImageMetaData &metadata)
|
||||
{
|
||||
metadata = ImageMetaData();
|
||||
metadata.colorspace = colorspace;
|
||||
metadata.colorspace = key.colorspace;
|
||||
|
||||
if (builtin_data) {
|
||||
if (key.builtin_data) {
|
||||
if (builtin_image_info_cb) {
|
||||
builtin_image_info_cb(filename, builtin_data, metadata);
|
||||
builtin_image_info_cb(key.filename, key.builtin_data, metadata);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
@ -227,23 +224,23 @@ bool ImageManager::get_image_metadata(const string &filename,
|
||||
}
|
||||
|
||||
/* Perform preliminary checks, with meaningful logging. */
|
||||
if (!path_exists(filename)) {
|
||||
VLOG(1) << "File '" << filename << "' does not exist.";
|
||||
if (!path_exists(key.filename)) {
|
||||
VLOG(1) << "File '" << key.filename << "' does not exist.";
|
||||
return false;
|
||||
}
|
||||
if (path_is_directory(filename)) {
|
||||
VLOG(1) << "File '" << filename << "' is a directory, can't use as image.";
|
||||
if (path_is_directory(key.filename)) {
|
||||
VLOG(1) << "File '" << key.filename << "' is a directory, can't use as image.";
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_ptr<ImageInput> in(ImageInput::create(filename));
|
||||
unique_ptr<ImageInput> in(ImageInput::create(key.filename));
|
||||
|
||||
if (!in) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageSpec spec;
|
||||
if (!in->open(filename, spec)) {
|
||||
if (!in->open(key.filename, spec)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -294,33 +291,12 @@ bool ImageManager::get_image_metadata(const string &filename,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool image_equals(ImageManager::Image *image,
|
||||
const string &filename,
|
||||
void *builtin_data,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace)
|
||||
{
|
||||
return image->filename == filename && image->builtin_data == builtin_data &&
|
||||
image->interpolation == interpolation && image->extension == extension &&
|
||||
image->alpha_type == alpha_type && image->colorspace == colorspace;
|
||||
}
|
||||
|
||||
int ImageManager::add_image(const string &filename,
|
||||
void *builtin_data,
|
||||
bool animated,
|
||||
float frame,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace,
|
||||
ImageMetaData &metadata)
|
||||
int ImageManager::add_image(const ImageKey &key, float frame, ImageMetaData &metadata)
|
||||
{
|
||||
Image *img;
|
||||
size_t slot;
|
||||
|
||||
get_image_metadata(filename, builtin_data, colorspace, metadata);
|
||||
get_image_metadata(key, metadata);
|
||||
ImageDataType type = metadata.type;
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
@ -338,21 +314,11 @@ int ImageManager::add_image(const string &filename,
|
||||
/* Fnd existing image. */
|
||||
for (slot = 0; slot < images[type].size(); slot++) {
|
||||
img = images[type][slot];
|
||||
if (img &&
|
||||
image_equals(
|
||||
img, filename, builtin_data, interpolation, extension, alpha_type, colorspace)) {
|
||||
if (img && img->key == key) {
|
||||
if (img->frame != frame) {
|
||||
img->frame = frame;
|
||||
img->need_load = true;
|
||||
}
|
||||
if (img->alpha_type != alpha_type) {
|
||||
img->alpha_type = alpha_type;
|
||||
img->need_load = true;
|
||||
}
|
||||
if (img->colorspace != colorspace) {
|
||||
img->colorspace = colorspace;
|
||||
img->need_load = true;
|
||||
}
|
||||
if (!(img->metadata == metadata)) {
|
||||
img->metadata = metadata;
|
||||
img->need_load = true;
|
||||
@ -381,7 +347,7 @@ int ImageManager::add_image(const string &filename,
|
||||
"ImageManager::add_image: Reached image limit (%d), "
|
||||
"skipping '%s'\n",
|
||||
max_num_images,
|
||||
filename.c_str());
|
||||
key.filename.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -391,17 +357,11 @@ int ImageManager::add_image(const string &filename,
|
||||
|
||||
/* Add new image. */
|
||||
img = new Image();
|
||||
img->filename = filename;
|
||||
img->builtin_data = builtin_data;
|
||||
img->key = key;
|
||||
img->frame = frame;
|
||||
img->metadata = metadata;
|
||||
img->need_load = true;
|
||||
img->animated = animated;
|
||||
img->frame = frame;
|
||||
img->interpolation = interpolation;
|
||||
img->extension = extension;
|
||||
img->users = 1;
|
||||
img->alpha_type = alpha_type;
|
||||
img->colorspace = colorspace;
|
||||
img->mem = NULL;
|
||||
|
||||
images[type][slot] = img;
|
||||
@ -442,24 +402,13 @@ void ImageManager::remove_image(int flat_slot)
|
||||
need_update = true;
|
||||
}
|
||||
|
||||
void ImageManager::remove_image(const string &filename,
|
||||
void *builtin_data,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace)
|
||||
void ImageManager::remove_image(const ImageKey &key)
|
||||
{
|
||||
size_t slot;
|
||||
|
||||
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
||||
for (slot = 0; slot < images[type].size(); slot++) {
|
||||
if (images[type][slot] && image_equals(images[type][slot],
|
||||
filename,
|
||||
builtin_data,
|
||||
interpolation,
|
||||
extension,
|
||||
alpha_type,
|
||||
colorspace)) {
|
||||
if (images[type][slot] && images[type][slot]->key == key) {
|
||||
remove_image(type_index_to_flattened_slot(slot, (ImageDataType)type));
|
||||
return;
|
||||
}
|
||||
@ -471,22 +420,11 @@ void ImageManager::remove_image(const string &filename,
|
||||
* without bunch of arguments passing around making code readability even
|
||||
* more cluttered.
|
||||
*/
|
||||
void ImageManager::tag_reload_image(const string &filename,
|
||||
void *builtin_data,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace)
|
||||
void ImageManager::tag_reload_image(const ImageKey &key)
|
||||
{
|
||||
for (size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
||||
for (size_t slot = 0; slot < images[type].size(); slot++) {
|
||||
if (images[type][slot] && image_equals(images[type][slot],
|
||||
filename,
|
||||
builtin_data,
|
||||
interpolation,
|
||||
extension,
|
||||
alpha_type,
|
||||
colorspace)) {
|
||||
if (images[type][slot] && images[type][slot]->key == key) {
|
||||
images[type][slot]->need_load = true;
|
||||
break;
|
||||
}
|
||||
@ -498,23 +436,24 @@ static bool image_associate_alpha(ImageManager::Image *img)
|
||||
{
|
||||
/* For typical RGBA images we let OIIO convert to associated alpha,
|
||||
* but some types we want to leave the RGB channels untouched. */
|
||||
return !(ColorSpaceManager::colorspace_is_data(img->colorspace) ||
|
||||
img->alpha_type == IMAGE_ALPHA_IGNORE || img->alpha_type == IMAGE_ALPHA_CHANNEL_PACKED);
|
||||
return !(ColorSpaceManager::colorspace_is_data(img->key.colorspace) ||
|
||||
img->key.alpha_type == IMAGE_ALPHA_IGNORE ||
|
||||
img->key.alpha_type == IMAGE_ALPHA_CHANNEL_PACKED);
|
||||
}
|
||||
|
||||
bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *in)
|
||||
{
|
||||
if (img->filename == "")
|
||||
if (img->key.filename == "")
|
||||
return false;
|
||||
|
||||
if (!img->builtin_data) {
|
||||
if (!img->key.builtin_data) {
|
||||
/* NOTE: Error logging is done in meta data acquisition. */
|
||||
if (!path_exists(img->filename) || path_is_directory(img->filename)) {
|
||||
if (!path_exists(img->key.filename) || path_is_directory(img->key.filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* load image from file through OIIO */
|
||||
*in = unique_ptr<ImageInput>(ImageInput::create(img->filename));
|
||||
*in = unique_ptr<ImageInput>(ImageInput::create(img->key.filename));
|
||||
|
||||
if (!*in)
|
||||
return false;
|
||||
@ -526,7 +465,7 @@ bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *i
|
||||
config.attribute("oiio:UnassociatedAlpha", 1);
|
||||
}
|
||||
|
||||
if (!(*in)->open(img->filename, spec, config)) {
|
||||
if (!(*in)->open(img->key.filename, spec, config)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -628,8 +567,8 @@ bool ImageManager::file_load_image(Image *img,
|
||||
else {
|
||||
/* Read pixels through callback. */
|
||||
if (FileFormat == TypeDesc::FLOAT) {
|
||||
builtin_image_float_pixels_cb(img->filename,
|
||||
img->builtin_data,
|
||||
builtin_image_float_pixels_cb(img->key.filename,
|
||||
img->key.builtin_data,
|
||||
0, /* TODO(lukas): Support tiles here? */
|
||||
(float *)&pixels[0],
|
||||
num_pixels * components,
|
||||
@ -637,8 +576,8 @@ bool ImageManager::file_load_image(Image *img,
|
||||
img->metadata.builtin_free_cache);
|
||||
}
|
||||
else if (FileFormat == TypeDesc::UINT8) {
|
||||
builtin_image_pixels_cb(img->filename,
|
||||
img->builtin_data,
|
||||
builtin_image_pixels_cb(img->key.filename,
|
||||
img->key.builtin_data,
|
||||
0, /* TODO(lukas): Support tiles here? */
|
||||
(uchar *)&pixels[0],
|
||||
num_pixels * components,
|
||||
@ -700,7 +639,7 @@ bool ImageManager::file_load_image(Image *img,
|
||||
}
|
||||
|
||||
/* Disable alpha if requested by the user. */
|
||||
if (img->alpha_type == IMAGE_ALPHA_IGNORE) {
|
||||
if (img->key.alpha_type == IMAGE_ALPHA_IGNORE) {
|
||||
for (size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++, i--) {
|
||||
pixels[i * 4 + 3] = one;
|
||||
}
|
||||
@ -747,7 +686,7 @@ bool ImageManager::file_load_image(Image *img,
|
||||
while (max_size * scale_factor > texture_limit) {
|
||||
scale_factor *= 0.5f;
|
||||
}
|
||||
VLOG(1) << "Scaling image " << img->filename << " by a factor of " << scale_factor << ".";
|
||||
VLOG(1) << "Scaling image " << img->key.filename << " by a factor of " << scale_factor << ".";
|
||||
vector<StorageType> scaled_pixels;
|
||||
size_t scaled_width, scaled_height, scaled_depth;
|
||||
util_image_resize_pixels(pixels_storage,
|
||||
@ -774,6 +713,13 @@ bool ImageManager::file_load_image(Image *img,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void image_set_device_memory(ImageManager::Image *img, device_memory *mem)
|
||||
{
|
||||
img->mem = mem;
|
||||
mem->interpolation = img->key.interpolation;
|
||||
mem->extension = img->key.extension;
|
||||
}
|
||||
|
||||
void ImageManager::device_load_image(
|
||||
Device *device, Scene *scene, ImageDataType type, int slot, Progress *progress)
|
||||
{
|
||||
@ -782,10 +728,10 @@ void ImageManager::device_load_image(
|
||||
|
||||
Image *img = images[type][slot];
|
||||
|
||||
if (osl_texture_system && !img->builtin_data)
|
||||
if (osl_texture_system && !img->key.builtin_data)
|
||||
return;
|
||||
|
||||
string filename = path_filename(images[type][slot]->filename);
|
||||
string filename = path_filename(images[type][slot]->key.filename);
|
||||
progress->set_status("Updating Images", "Loading " + filename);
|
||||
|
||||
const int texture_limit = scene->params.texture_limit;
|
||||
@ -817,9 +763,7 @@ void ImageManager::device_load_image(
|
||||
pixels[3] = TEX_IMAGE_MISSING_A;
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -836,9 +780,7 @@ void ImageManager::device_load_image(
|
||||
pixels[0] = TEX_IMAGE_MISSING_R;
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -858,9 +800,7 @@ void ImageManager::device_load_image(
|
||||
pixels[3] = (TEX_IMAGE_MISSING_A * 255);
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -877,9 +817,7 @@ void ImageManager::device_load_image(
|
||||
pixels[0] = (TEX_IMAGE_MISSING_R * 255);
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -899,9 +837,7 @@ void ImageManager::device_load_image(
|
||||
pixels[3] = TEX_IMAGE_MISSING_A;
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -918,9 +854,7 @@ void ImageManager::device_load_image(
|
||||
pixels[0] = (TEX_IMAGE_MISSING_R * 65535);
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -940,9 +874,7 @@ void ImageManager::device_load_image(
|
||||
pixels[3] = (TEX_IMAGE_MISSING_A * 65535);
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -959,9 +891,7 @@ void ImageManager::device_load_image(
|
||||
pixels[0] = TEX_IMAGE_MISSING_R;
|
||||
}
|
||||
|
||||
img->mem = tex_img;
|
||||
img->mem->interpolation = img->interpolation;
|
||||
img->mem->extension = img->extension;
|
||||
image_set_device_memory(img, tex_img);
|
||||
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
tex_img->copy_to_device();
|
||||
@ -974,9 +904,9 @@ void ImageManager::device_free_image(Device *, ImageDataType type, int slot)
|
||||
Image *img = images[type][slot];
|
||||
|
||||
if (img) {
|
||||
if (osl_texture_system && !img->builtin_data) {
|
||||
if (osl_texture_system && !img->key.builtin_data) {
|
||||
#ifdef WITH_OSL
|
||||
ustring filename(images[type][slot]->filename);
|
||||
ustring filename(images[type][slot]->key.filename);
|
||||
((OSL::TextureSystem *)osl_texture_system)->invalidate(filename);
|
||||
#endif
|
||||
}
|
||||
@ -1008,7 +938,7 @@ void ImageManager::device_update(Device *device, Scene *scene, Progress &progres
|
||||
device_free_image(device, (ImageDataType)type, slot);
|
||||
}
|
||||
else if (images[type][slot]->need_load) {
|
||||
if (!osl_texture_system || images[type][slot]->builtin_data)
|
||||
if (!osl_texture_system || images[type][slot]->key.builtin_data)
|
||||
pool.push(function_bind(&ImageManager::device_load_image,
|
||||
this,
|
||||
device,
|
||||
@ -1040,7 +970,7 @@ void ImageManager::device_update_slot(Device *device,
|
||||
device_free_image(device, type, slot);
|
||||
}
|
||||
else if (image->need_load) {
|
||||
if (!osl_texture_system || image->builtin_data)
|
||||
if (!osl_texture_system || image->key.builtin_data)
|
||||
device_load_image(device, scene, type, slot, progress);
|
||||
}
|
||||
}
|
||||
@ -1060,7 +990,7 @@ void ImageManager::device_load_builtin(Device *device, Scene *scene, Progress &p
|
||||
continue;
|
||||
|
||||
if (images[type][slot]->need_load) {
|
||||
if (images[type][slot]->builtin_data) {
|
||||
if (images[type][slot]->key.builtin_data) {
|
||||
pool.push(function_bind(&ImageManager::device_load_image,
|
||||
this,
|
||||
device,
|
||||
@ -1080,7 +1010,7 @@ void ImageManager::device_free_builtin(Device *device)
|
||||
{
|
||||
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
||||
for (size_t slot = 0; slot < images[type].size(); slot++) {
|
||||
if (images[type][slot] && images[type][slot]->builtin_data)
|
||||
if (images[type][slot] && images[type][slot]->key.builtin_data)
|
||||
device_free_image(device, (ImageDataType)type, slot);
|
||||
}
|
||||
}
|
||||
@ -1101,7 +1031,7 @@ void ImageManager::collect_statistics(RenderStats *stats)
|
||||
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
||||
foreach (const Image *image, images[type]) {
|
||||
stats->image.textures.add_entry(
|
||||
NamedSizeEntry(path_filename(image->filename), image->mem->memory_size()));
|
||||
NamedSizeEntry(path_filename(image->key.filename), image->mem->memory_size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,38 +72,46 @@ class ImageMetaData {
|
||||
}
|
||||
};
|
||||
|
||||
class ImageKey {
|
||||
public:
|
||||
string filename;
|
||||
void *builtin_data;
|
||||
bool animated;
|
||||
InterpolationType interpolation;
|
||||
ExtensionType extension;
|
||||
ImageAlphaType alpha_type;
|
||||
ustring colorspace;
|
||||
|
||||
ImageKey()
|
||||
: builtin_data(NULL),
|
||||
animated(false),
|
||||
interpolation(INTERPOLATION_LINEAR),
|
||||
extension(EXTENSION_CLIP),
|
||||
alpha_type(IMAGE_ALPHA_AUTO),
|
||||
colorspace(u_colorspace_raw)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const ImageKey &other) const
|
||||
{
|
||||
return (filename == other.filename && builtin_data == other.builtin_data &&
|
||||
animated == other.animated && interpolation == other.interpolation &&
|
||||
extension == other.extension && alpha_type == other.alpha_type &&
|
||||
colorspace == other.colorspace);
|
||||
}
|
||||
};
|
||||
|
||||
class ImageManager {
|
||||
public:
|
||||
explicit ImageManager(const DeviceInfo &info);
|
||||
~ImageManager();
|
||||
|
||||
int add_image(const string &filename,
|
||||
void *builtin_data,
|
||||
bool animated,
|
||||
float frame,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace,
|
||||
ImageMetaData &metadata);
|
||||
int add_image(const ImageKey &key, float frame, ImageMetaData &metadata);
|
||||
void add_image_user(int flat_slot);
|
||||
void remove_image(int flat_slot);
|
||||
void remove_image(const string &filename,
|
||||
void *builtin_data,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace);
|
||||
void tag_reload_image(const string &filename,
|
||||
void *builtin_data,
|
||||
InterpolationType interpolation,
|
||||
ExtensionType extension,
|
||||
ImageAlphaType alpha_type,
|
||||
ustring colorspace);
|
||||
bool get_image_metadata(const string &filename,
|
||||
void *builtin_data,
|
||||
ustring colorspace,
|
||||
ImageMetaData &metadata);
|
||||
void remove_image(const ImageKey &key);
|
||||
void tag_reload_image(const ImageKey &key);
|
||||
bool get_image_metadata(const ImageKey &key, ImageMetaData &metadata);
|
||||
bool get_image_metadata(int flat_slot, ImageMetaData &metadata);
|
||||
|
||||
void device_update(Device *device, Scene *scene, Progress &progress);
|
||||
@ -146,17 +154,11 @@ class ImageManager {
|
||||
builtin_image_float_pixels_cb;
|
||||
|
||||
struct Image {
|
||||
string filename;
|
||||
void *builtin_data;
|
||||
ImageKey key;
|
||||
ImageMetaData metadata;
|
||||
|
||||
ustring colorspace;
|
||||
ImageAlphaType alpha_type;
|
||||
bool need_load;
|
||||
bool animated;
|
||||
float frame;
|
||||
InterpolationType interpolation;
|
||||
ExtensionType extension;
|
||||
bool need_load;
|
||||
|
||||
string mem_name;
|
||||
device_memory *mem;
|
||||
|
@ -289,6 +289,22 @@ ShaderNode *ImageTextureNode::clone() const
|
||||
return new ImageTextureNode(*this);
|
||||
}
|
||||
|
||||
ImageKey ImageTextureNode::image_key(const int tile) const
|
||||
{
|
||||
ImageKey key;
|
||||
key.filename = filename.string();
|
||||
if (tile != 0) {
|
||||
string_replace(key.filename, "<UDIM>", string_printf("%04d", tile));
|
||||
}
|
||||
key.builtin_data = builtin_data;
|
||||
key.animated = animated;
|
||||
key.interpolation = interpolation;
|
||||
key.extension = extension;
|
||||
key.alpha_type = alpha_type;
|
||||
key.colorspace = colorspace;
|
||||
return key;
|
||||
}
|
||||
|
||||
void ImageTextureNode::cull_tiles(Scene *scene, ShaderGraph *graph)
|
||||
{
|
||||
/* Box projection computes its own UVs that always lie in the
|
||||
@ -378,19 +394,9 @@ void ImageTextureNode::compile(SVMCompiler &compiler)
|
||||
|
||||
bool have_metadata = false;
|
||||
foreach (int tile, tiles) {
|
||||
string tile_name = filename.string();
|
||||
string_replace(tile_name, "<UDIM>", string_printf("%04d", tile));
|
||||
|
||||
ImageKey key = image_key(tile);
|
||||
ImageMetaData metadata;
|
||||
int slot = image_manager->add_image(tile_name,
|
||||
builtin_data,
|
||||
animated,
|
||||
0,
|
||||
interpolation,
|
||||
extension,
|
||||
alpha_type,
|
||||
colorspace,
|
||||
metadata);
|
||||
int slot = image_manager->add_image(key, 0, metadata);
|
||||
slots.push_back(slot);
|
||||
|
||||
/* We assume that all tiles have the same metadata. */
|
||||
@ -500,21 +506,12 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
|
||||
if (slots.size() == 0) {
|
||||
ImageMetaData metadata;
|
||||
if (builtin_data == NULL) {
|
||||
string tile_name = filename.string();
|
||||
string_replace(tile_name, "<UDIM>", "1001");
|
||||
image_manager->get_image_metadata(tile_name, NULL, colorspace, metadata);
|
||||
ImageKey key = image_key(1001);
|
||||
image_manager->get_image_metadata(key, metadata);
|
||||
slots.push_back(-1);
|
||||
}
|
||||
else {
|
||||
int slot = image_manager->add_image(filename.string(),
|
||||
builtin_data,
|
||||
animated,
|
||||
0,
|
||||
interpolation,
|
||||
extension,
|
||||
alpha_type,
|
||||
colorspace,
|
||||
metadata);
|
||||
int slot = image_manager->add_image(image_key(), 0, metadata);
|
||||
slots.push_back(slot);
|
||||
}
|
||||
is_float = metadata.is_float;
|
||||
@ -602,6 +599,19 @@ ShaderNode *EnvironmentTextureNode::clone() const
|
||||
return new EnvironmentTextureNode(*this);
|
||||
}
|
||||
|
||||
ImageKey EnvironmentTextureNode::image_key() const
|
||||
{
|
||||
ImageKey key;
|
||||
key.filename = filename.string();
|
||||
key.builtin_data = builtin_data;
|
||||
key.animated = animated;
|
||||
key.interpolation = interpolation;
|
||||
key.extension = EXTENSION_REPEAT;
|
||||
key.alpha_type = alpha_type;
|
||||
key.colorspace = colorspace;
|
||||
return key;
|
||||
}
|
||||
|
||||
void EnvironmentTextureNode::attributes(Shader *shader, AttributeRequestSet *attributes)
|
||||
{
|
||||
#ifdef WITH_PTEX
|
||||
@ -624,15 +634,7 @@ void EnvironmentTextureNode::compile(SVMCompiler &compiler)
|
||||
image_manager = compiler.scene->image_manager;
|
||||
if (slots.empty()) {
|
||||
ImageMetaData metadata;
|
||||
int slot = image_manager->add_image(filename.string(),
|
||||
builtin_data,
|
||||
animated,
|
||||
0,
|
||||
interpolation,
|
||||
EXTENSION_REPEAT,
|
||||
alpha_type,
|
||||
colorspace,
|
||||
metadata);
|
||||
int slot = image_manager->add_image(image_key(), 0, metadata);
|
||||
slots.push_back(slot);
|
||||
is_float = metadata.is_float;
|
||||
compress_as_srgb = metadata.compress_as_srgb;
|
||||
@ -682,19 +684,11 @@ void EnvironmentTextureNode::compile(OSLCompiler &compiler)
|
||||
if (slots.empty()) {
|
||||
ImageMetaData metadata;
|
||||
if (builtin_data == NULL) {
|
||||
image_manager->get_image_metadata(filename.string(), NULL, colorspace, metadata);
|
||||
image_manager->get_image_metadata(image_key(), metadata);
|
||||
slots.push_back(-1);
|
||||
}
|
||||
else {
|
||||
int slot = image_manager->add_image(filename.string(),
|
||||
builtin_data,
|
||||
animated,
|
||||
0,
|
||||
interpolation,
|
||||
EXTENSION_REPEAT,
|
||||
alpha_type,
|
||||
colorspace,
|
||||
metadata);
|
||||
int slot = image_manager->add_image(image_key(), 0, metadata);
|
||||
slots.push_back(slot);
|
||||
}
|
||||
is_float = metadata.is_float;
|
||||
@ -1754,12 +1748,7 @@ PointDensityTextureNode::PointDensityTextureNode() : ShaderNode(node_type)
|
||||
PointDensityTextureNode::~PointDensityTextureNode()
|
||||
{
|
||||
if (image_manager) {
|
||||
image_manager->remove_image(filename.string(),
|
||||
builtin_data,
|
||||
interpolation,
|
||||
EXTENSION_CLIP,
|
||||
IMAGE_ALPHA_AUTO,
|
||||
ustring());
|
||||
image_manager->remove_image(image_key());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1786,18 +1775,19 @@ void PointDensityTextureNode::add_image()
|
||||
{
|
||||
if (slot == -1) {
|
||||
ImageMetaData metadata;
|
||||
slot = image_manager->add_image(filename.string(),
|
||||
builtin_data,
|
||||
false,
|
||||
0,
|
||||
interpolation,
|
||||
EXTENSION_CLIP,
|
||||
IMAGE_ALPHA_AUTO,
|
||||
u_colorspace_raw,
|
||||
metadata);
|
||||
slot = image_manager->add_image(image_key(), 0, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
ImageKey PointDensityTextureNode::image_key() const
|
||||
{
|
||||
ImageKey key;
|
||||
key.filename = filename.string();
|
||||
key.builtin_data = builtin_data;
|
||||
key.interpolation = interpolation;
|
||||
return key;
|
||||
}
|
||||
|
||||
void PointDensityTextureNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
ShaderInput *vector_in = input("Vector");
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define __NODES_H__
|
||||
|
||||
#include "render/graph.h"
|
||||
#include "render/image.h"
|
||||
#include "graph/node.h"
|
||||
|
||||
#include "util/util_array.h"
|
||||
@ -102,6 +103,8 @@ class ImageTextureNode : public ImageSlotTextureNode {
|
||||
animated == image_node.animated;
|
||||
}
|
||||
|
||||
ImageKey image_key(const int tile = 0) const;
|
||||
|
||||
/* Parameters. */
|
||||
ustring filename;
|
||||
void *builtin_data;
|
||||
@ -145,6 +148,8 @@ class EnvironmentTextureNode : public ImageSlotTextureNode {
|
||||
animated == env_node.animated;
|
||||
}
|
||||
|
||||
ImageKey image_key() const;
|
||||
|
||||
/* Parameters. */
|
||||
ustring filename;
|
||||
void *builtin_data;
|
||||
@ -367,6 +372,8 @@ class PointDensityTextureNode : public ShaderNode {
|
||||
|
||||
void add_image();
|
||||
|
||||
ImageKey image_key() const;
|
||||
|
||||
/* Parameters. */
|
||||
ustring filename;
|
||||
NodeTexVoxelSpace space;
|
||||
|
Loading…
Reference in New Issue
Block a user