Commit: d675cf20a13ac09a55ce04d6a30105eaf87f5ebe Author: Brecht Van Lommel Date: Thu Feb 20 00:52:50 2020 +0100 Branches: master https://developer.blender.org/rBd675cf20a13ac09a55ce04d6a30105eaf87f5ebe
Cleanup: add ImageKey to avoid longer argument lists and duplicated code =================================================================== M intern/cycles/blender/blender_shader.cpp M intern/cycles/blender/blender_volume.cpp M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/nodes.cpp M intern/cycles/render/nodes.h =================================================================== diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 5a70126e012..6709e90c3d3 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -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; diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp index ae70e60d60e..47259d4945c 100644 --- a/intern/cycles/blender/blender_volume.cpp +++ b/intern/cycles/blender/blender_volume.cpp @@ -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. diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index 212a867f9cd..e5fb2fcaf3d 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -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 ( @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs