Commit: cd724f7bd52f15ac9a336f0705b6231ef439184a Author: Brecht Van Lommel Date: Thu Feb 20 00:52:50 2020 +0100 Branches: new-object-types https://developer.blender.org/rBcd724f7bd52f15ac9a336f0705b6231ef439184a
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 635405e42c7..aed46425423 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -634,6 +634,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 @@ -676,21 +684,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)) { @@ -698,6 +695,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 || @@ -725,19 +728,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)) { @@ -888,12 +882,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 bdcd25d08f2..c296ce187a3 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. @@ -123,19 +118,14 @@ static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *s mesh->attributes.add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); VoxelAttribute *volume_data = attr->data_voxel(); ImageMetaData metadata; - const bool animated = false; const float frame = b_volume.grids.frame(); + ImageKey key; + key.filename = name.c_str(); + key.builtin_data = b_volume.ptr.data; + volume_data->manager = scene->image_manager; - volume_data->slot = scene->image_manager->add_image(name.c_str(), - b_volume.ptr.data, - animated, - frame, - INTERPOLATION_LINEAR, - EXTENSION_CLIP, - IMAGE_ALPHA_AUTO, - u_colorspace_raw, - metadata); + volume_data->slot = scene->image_manager->add_image(key, frame, metadata); /* TODO: support each grid having own transform. */ /* TODO: support full transform instead of only using boundbox. */ 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 @@ 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