Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-08-25 01:40:18 +0300
committerHans Goudey <h.goudey@me.com>2021-08-25 01:40:18 +0300
commit137a5e162c2435662dbb299ff49771e7d2e7598f (patch)
treea40ebf526c1a320c7a9fa0c8456dfe2ffd4db6a6
parentaad18a005026cfaa19c45f2477318c6e06303eae (diff)
parent5ef3afd87c54b47614254d95c9b2e9a17c60f76e (diff)
Merge branch 'master' into refactor-idprop-ui-data
-rw-r--r--CMakeLists.txt3
-rwxr-xr-xbuild_files/build_environment/install_deps.sh2
-rw-r--r--build_files/cmake/Modules/FindZstd.cmake66
-rw-r--r--build_files/cmake/platform/platform_apple.cmake16
-rw-r--r--build_files/cmake/platform/platform_unix.cmake1
-rw-r--r--build_files/cmake/platform/platform_win32.cmake3
-rw-r--r--build_files/config/pipeline_config.yaml4
-rw-r--r--doc/python_api/requirements.txt12
-rw-r--r--doc/python_api/sphinx_doc_gen.py6
-rw-r--r--extern/audaspace/bindings/C/AUD_Special.cpp4
-rw-r--r--extern/audaspace/bindings/C/AUD_Types.h1
-rw-r--r--extern/audaspace/bindings/python/setup.py.in2
-rw-r--r--extern/audaspace/include/IReader.h6
-rw-r--r--extern/audaspace/include/fx/VolumeReader.h2
-rw-r--r--extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp80
-rw-r--r--extern/audaspace/plugins/ffmpeg/FFMPEGReader.h17
-rw-r--r--extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp19
-rw-r--r--extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h2
-rw-r--r--extern/audaspace/src/fx/VolumeReader.cpp2
-rw-r--r--intern/cycles/blender/CMakeLists.txt10
-rw-r--r--intern/cycles/blender/addon/__init__.py1
-rw-r--r--intern/cycles/blender/addon/properties.py8
-rw-r--r--intern/cycles/blender/blender_mesh.cpp21
-rw-r--r--intern/cycles/blender/blender_object.cpp110
-rw-r--r--intern/cycles/blender/blender_particles.cpp2
-rw-r--r--intern/cycles/blender/blender_python.cpp107
-rw-r--r--intern/cycles/blender/blender_shader.cpp103
-rw-r--r--intern/cycles/blender/blender_sync.cpp1
-rw-r--r--intern/cycles/blender/blender_sync.h5
-rw-r--r--intern/cycles/blender/blender_util.h49
-rw-r--r--intern/cycles/kernel/closure/bsdf_principled_diffuse.h6
-rw-r--r--intern/cycles/kernel/geom/geom_triangle.h21
-rw-r--r--intern/cycles/kernel/shaders/node_texture_coordinate.osl4
-rw-r--r--intern/cycles/kernel/svm/svm_attribute.h48
-rw-r--r--intern/cycles/kernel/svm/svm_tex_coord.h8
-rw-r--r--intern/cycles/render/alembic.cpp154
-rw-r--r--intern/cycles/render/alembic.h39
-rw-r--r--intern/cycles/render/alembic_read.cpp16
-rw-r--r--intern/cycles/render/geometry.cpp20
-rw-r--r--intern/cycles/render/graph.cpp4
-rw-r--r--intern/cycles/render/nodes.cpp20
-rw-r--r--intern/cycles/render/shader.h8
-rw-r--r--intern/ghost/GHOST_IEvent.h6
-rw-r--r--intern/ghost/GHOST_Types.h9
-rw-r--r--intern/ghost/intern/GHOST_ContextD3D.cpp15
-rw-r--r--intern/ghost/intern/GHOST_ContextD3D.h8
-rw-r--r--intern/ghost/intern/GHOST_IXrGraphicsBinding.h1
-rw-r--r--intern/ghost/intern/GHOST_ImeWin32.cpp199
-rw-r--r--intern/ghost/intern/GHOST_ImeWin32.h35
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.mm2
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp2
-rw-r--r--intern/ghost/intern/GHOST_XrGraphicsBinding.cpp103
-rw-r--r--intern/ghost/intern/GHOST_XrSession.cpp1
-rw-r--r--intern/ghost/intern/GHOST_XrSwapchain.cpp12
-rw-r--r--intern/ghost/intern/GHOST_XrSwapchain.h4
-rw-r--r--intern/guardedalloc/intern/mallocn_guarded_impl.c2
-rw-r--r--make.bat2
m---------release/datafiles/locale0
-rw-r--r--release/datafiles/preview.blendbin1453009 -> 1471916 bytes
m---------release/scripts/addons0
m---------release/scripts/addons_contrib0
-rw-r--r--release/scripts/modules/bpy_types.py19
-rw-r--r--release/scripts/presets/keyconfig/keymap_data/blender_default.py24
-rw-r--r--release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py5
-rw-r--r--release/scripts/startup/bl_ui/properties_object.py25
-rw-r--r--release/scripts/startup/bl_ui/properties_paint_common.py17
-rw-r--r--release/scripts/startup/bl_ui/space_filebrowser.py6
-rw-r--r--release/scripts/startup/bl_ui/space_outliner.py2
-rw-r--r--release/scripts/startup/bl_ui/space_text.py5
-rw-r--r--release/scripts/startup/bl_ui/space_userpref.py8
-rw-r--r--release/scripts/startup/nodeitems_builtins.py1
-rw-r--r--source/blender/blenfont/BLF_api.h51
-rw-r--r--source/blender/blenfont/intern/blf.c93
-rw-r--r--source/blender/blenfont/intern/blf_default.c8
-rw-r--r--source/blender/blenfont/intern/blf_font.c950
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c61
-rw-r--r--source/blender/blenfont/intern/blf_internal.h43
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h40
-rw-r--r--source/blender/blenkernel/BKE_blender_version.h2
-rw-r--r--source/blender/blenkernel/BKE_cachefile.h5
-rw-r--r--source/blender/blenkernel/BKE_collection.h2
-rw-r--r--source/blender/blenkernel/BKE_constraint.h22
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h2
-rw-r--r--source/blender/blenkernel/BKE_gpencil_geom.h3
-rw-r--r--source/blender/blenkernel/BKE_image.h6
-rw-r--r--source/blender/blenkernel/BKE_key.h2
-rw-r--r--source/blender/blenkernel/BKE_lib_id.h12
-rw-r--r--source/blender/blenkernel/BKE_mesh.h53
-rw-r--r--source/blender/blenkernel/BKE_modifier.h6
-rw-r--r--source/blender/blenkernel/BKE_node.h17
-rw-r--r--source/blender/blenkernel/BKE_object.h5
-rw-r--r--source/blender/blenkernel/BKE_particle.h5
-rw-r--r--source/blender/blenkernel/BKE_scene.h4
-rw-r--r--source/blender/blenkernel/BKE_screen.h2
-rw-r--r--source/blender/blenkernel/BKE_sound.h9
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.cc36
-rw-r--r--source/blender/blenkernel/intern/action.c21
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c2
-rw-r--r--source/blender/blenkernel/intern/armature.c31
-rw-r--r--source/blender/blenkernel/intern/blendfile.c4
-rw-r--r--source/blender/blenkernel/intern/brush.c73
-rw-r--r--source/blender/blenkernel/intern/bvhutils.cc3
-rw-r--r--source/blender/blenkernel/intern/cachefile.c47
-rw-r--r--source/blender/blenkernel/intern/camera.c26
-rw-r--r--source/blender/blenkernel/intern/cloth.c5
-rw-r--r--source/blender/blenkernel/intern/collection.c29
-rw-r--r--source/blender/blenkernel/intern/constraint.c110
-rw-r--r--source/blender/blenkernel/intern/curve.c93
-rw-r--r--source/blender/blenkernel/intern/customdata.c2
-rw-r--r--source/blender/blenkernel/intern/data_transfer.c6
-rw-r--r--source/blender/blenkernel/intern/displist.cc2
-rw-r--r--source/blender/blenkernel/intern/font.c124
-rw-r--r--source/blender/blenkernel/intern/geometry_set_instances.cc4
-rw-r--r--source/blender/blenkernel/intern/gpencil.c78
-rw-r--r--source/blender/blenkernel/intern/gpencil_geom.cc283
-rw-r--r--source/blender/blenkernel/intern/hair.c49
-rw-r--r--source/blender/blenkernel/intern/icons.cc2
-rw-r--r--source/blender/blenkernel/intern/image.c146
-rw-r--r--source/blender/blenkernel/intern/image_gpu.c3
-rw-r--r--source/blender/blenkernel/intern/image_save.c19
-rw-r--r--source/blender/blenkernel/intern/key.c54
-rw-r--r--source/blender/blenkernel/intern/lattice.c33
-rw-r--r--source/blender/blenkernel/intern/layer.c54
-rw-r--r--source/blender/blenkernel/intern/lib_id.c27
-rw-r--r--source/blender/blenkernel/intern/lib_id_delete.c35
-rw-r--r--source/blender/blenkernel/intern/lib_override.c2
-rw-r--r--source/blender/blenkernel/intern/lib_query.c4
-rw-r--r--source/blender/blenkernel/intern/light.c31
-rw-r--r--source/blender/blenkernel/intern/lightprobe.c15
-rw-r--r--source/blender/blenkernel/intern/linestyle.c35
-rw-r--r--source/blender/blenkernel/intern/mask.c57
-rw-r--r--source/blender/blenkernel/intern/mask_rasterize.c4
-rw-r--r--source/blender/blenkernel/intern/material.c40
-rw-r--r--source/blender/blenkernel/intern/mball.c43
-rw-r--r--source/blender/blenkernel/intern/mesh.c509
-rw-r--r--source/blender/blenkernel/intern/mesh_convert.c67
-rw-r--r--source/blender/blenkernel/intern/mesh_mirror.c17
-rw-r--r--source/blender/blenkernel/intern/mesh_normals.cc565
-rw-r--r--source/blender/blenkernel/intern/mesh_remap.c12
-rw-r--r--source/blender/blenkernel/intern/modifier.c4
-rw-r--r--source/blender/blenkernel/intern/movieclip.c45
-rw-r--r--source/blender/blenkernel/intern/node.cc24
-rw-r--r--source/blender/blenkernel/intern/object.c121
-rw-r--r--source/blender/blenkernel/intern/ocean.c10
-rw-r--r--source/blender/blenkernel/intern/ocean_spectrum.c2
-rw-r--r--source/blender/blenkernel/intern/paint.c22
-rw-r--r--source/blender/blenkernel/intern/particle.c99
-rw-r--r--source/blender/blenkernel/intern/particle_system.c1
-rw-r--r--source/blender/blenkernel/intern/pointcloud.cc41
-rw-r--r--source/blender/blenkernel/intern/scene.c29
-rw-r--r--source/blender/blenkernel/intern/screen.c20
-rw-r--r--source/blender/blenkernel/intern/simulation.cc29
-rw-r--r--source/blender/blenkernel/intern/softbody.c4
-rw-r--r--source/blender/blenkernel/intern/sound.c48
-rw-r--r--source/blender/blenkernel/intern/speaker.c15
-rw-r--r--source/blender/blenkernel/intern/spline_base.cc2
-rw-r--r--source/blender/blenkernel/intern/text.c11
-rw-r--r--source/blender/blenkernel/intern/texture.c33
-rw-r--r--source/blender/blenkernel/intern/volume.cc31
-rw-r--r--source/blender/blenkernel/intern/world.c29
-rw-r--r--source/blender/blenkernel/intern/writeffmpeg.c42
-rw-r--r--source/blender/blenlib/BLI_fileops.h21
-rw-r--r--source/blender/blenlib/BLI_filereader.h81
-rw-r--r--source/blender/blenlib/BLI_index_mask.hh27
-rw-r--r--source/blender/blenlib/BLI_math_base.h5
-rw-r--r--source/blender/blenlib/BLI_string_utf8.h10
-rw-r--r--source/blender/blenlib/CMakeLists.txt7
-rw-r--r--source/blender/blenlib/intern/fileops.c243
-rw-r--r--source/blender/blenlib/intern/filereader_file.c80
-rw-r--r--source/blender/blenlib/intern/filereader_gzip.c108
-rw-r--r--source/blender/blenlib/intern/filereader_memory.c145
-rw-r--r--source/blender/blenlib/intern/filereader_zstd.c335
-rw-r--r--source/blender/blenlib/intern/freetypefont.c2
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c20
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c11
-rw-r--r--source/blender/blenlib/intern/string_utf8.c79
-rw-r--r--source/blender/blenlib/tests/BLI_array_store_test.cc11
-rw-r--r--source/blender/blenlib/tests/BLI_string_utf8_test.cc115
-rw-r--r--source/blender/blenloader/BLO_readfile.h1
-rw-r--r--source/blender/blenloader/BLO_undofile.h14
-rw-r--r--source/blender/blenloader/CMakeLists.txt2
-rw-r--r--source/blender/blenloader/intern/readfile.c458
-rw-r--r--source/blender/blenloader/intern/readfile.h32
-rw-r--r--source/blender/blenloader/intern/undofile.c95
-rw-r--r--source/blender/blenloader/intern/versioning_250.c3
-rw-r--r--source/blender/blenloader/intern/versioning_300.c67
-rw-r--r--source/blender/blenloader/intern/versioning_legacy.c3
-rw-r--r--source/blender/blenloader/intern/versioning_userdef.c7
-rw-r--r--source/blender/blenloader/intern/writefile.c317
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_normals.c7
-rw-r--r--source/blender/bmesh/operators/bmo_removedoubles.c1
-rw-r--r--source/blender/compositor/CMakeLists.txt6
-rw-r--r--source/blender/compositor/COM_defines.h10
-rw-r--r--source/blender/compositor/intern/COM_BufferOperation.cc13
-rw-r--r--source/blender/compositor/intern/COM_BufferOperation.h1
-rw-r--r--source/blender/compositor/intern/COM_CompositorContext.h6
-rw-r--r--source/blender/compositor/intern/COM_ConstantFolder.cc4
-rw-r--r--source/blender/compositor/intern/COM_Debug.cc16
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.cc69
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.h104
-rw-r--r--source/blender/compositor/intern/COM_NodeGraph.cc9
-rw-r--r--source/blender/compositor/intern/COM_NodeGraph.h4
-rw-r--r--source/blender/compositor/intern/COM_NodeOperation.cc6
-rw-r--r--source/blender/compositor/intern/COM_NodeOperation.h11
-rw-r--r--source/blender/compositor/intern/COM_TiledExecutionModel.cc2
-rw-r--r--source/blender/compositor/nodes/COM_CryptomatteNode.cc4
-rw-r--r--source/blender/compositor/nodes/COM_RotateNode.cc25
-rw-r--r--source/blender/compositor/nodes/COM_Stabilize2dNode.cc100
-rw-r--r--source/blender/compositor/nodes/COM_TransformNode.cc61
-rw-r--r--source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc30
-rw-r--r--source/blender/compositor/operations/COM_AlphaOverKeyOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc27
-rw-r--r--source/blender/compositor/operations/COM_AlphaOverMixedOperation.h2
-rw-r--r--source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc29
-rw-r--r--source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_BilateralBlurOperation.cc86
-rw-r--r--source/blender/compositor/operations/COM_BilateralBlurOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_BlurBaseOperation.cc95
-rw-r--r--source/blender/compositor/operations/COM_BlurBaseOperation.h22
-rw-r--r--source/blender/compositor/operations/COM_BokehBlurOperation.cc178
-rw-r--r--source/blender/compositor/operations/COM_BokehBlurOperation.h12
-rw-r--r--source/blender/compositor/operations/COM_BokehImageOperation.cc25
-rw-r--r--source/blender/compositor/operations/COM_BokehImageOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ChangeHSVOperation.cc23
-rw-r--r--source/blender/compositor/operations/COM_ChangeHSVOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ChannelMatteOperation.cc34
-rw-r--r--source/blender/compositor/operations/COM_ChannelMatteOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ChromaMatteOperation.cc55
-rw-r--r--source/blender/compositor/operations/COM_ChromaMatteOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ColorCurveOperation.cc53
-rw-r--r--source/blender/compositor/operations/COM_ColorCurveOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ColorMatteOperation.cc37
-rw-r--r--source/blender/compositor/operations/COM_ColorMatteOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ColorRampOperation.cc10
-rw-r--r--source/blender/compositor/operations/COM_ColorRampOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ColorSpillOperation.cc33
-rw-r--r--source/blender/compositor/operations/COM_ColorSpillOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_CompositorOperation.cc16
-rw-r--r--source/blender/compositor/operations/COM_CompositorOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_ConstantOperation.cc17
-rw-r--r--source/blender/compositor/operations/COM_ConstantOperation.h16
-rw-r--r--source/blender/compositor/operations/COM_ConvertOperation.cc164
-rw-r--r--source/blender/compositor/operations/COM_ConvertOperation.h68
-rw-r--r--source/blender/compositor/operations/COM_CropOperation.cc45
-rw-r--r--source/blender/compositor/operations/COM_CropOperation.h13
-rw-r--r--source/blender/compositor/operations/COM_CryptomatteOperation.cc30
-rw-r--r--source/blender/compositor/operations/COM_CryptomatteOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_CurveBaseOperation.cc1
-rw-r--r--source/blender/compositor/operations/COM_CurveBaseOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_DifferenceMatteOperation.cc41
-rw-r--r--source/blender/compositor/operations/COM_DifferenceMatteOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_DilateErodeOperation.cc2
-rw-r--r--source/blender/compositor/operations/COM_DisplaceOperation.cc95
-rw-r--r--source/blender/compositor/operations/COM_DisplaceOperation.h22
-rw-r--r--source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc52
-rw-r--r--source/blender/compositor/operations/COM_DisplaceSimpleOperation.h9
-rw-r--r--source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc42
-rw-r--r--source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h10
-rw-r--r--source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cc2
-rw-r--r--source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h2
-rw-r--r--source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc106
-rw-r--r--source/blender/compositor/operations/COM_FastGaussianBlurOperation.h21
-rw-r--r--source/blender/compositor/operations/COM_FlipOperation.cc38
-rw-r--r--source/blender/compositor/operations/COM_FlipOperation.h9
-rw-r--r--source/blender/compositor/operations/COM_GammaCorrectOperation.cc57
-rw-r--r--source/blender/compositor/operations/COM_GammaCorrectOperation.h14
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc168
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h62
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc13
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h23
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc15
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h23
-rw-r--r--source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc154
-rw-r--r--source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h50
-rw-r--r--source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc213
-rw-r--r--source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h18
-rw-r--r--source/blender/compositor/operations/COM_GaussianXBlurOperation.cc15
-rw-r--r--source/blender/compositor/operations/COM_GaussianXBlurOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_GaussianYBlurOperation.cc13
-rw-r--r--source/blender/compositor/operations/COM_GaussianYBlurOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc27
-rw-r--r--source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_InvertOperation.cc28
-rw-r--r--source/blender/compositor/operations/COM_InvertOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_KeyingBlurOperation.cc63
-rw-r--r--source/blender/compositor/operations/COM_KeyingBlurOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_KeyingClipOperation.cc85
-rw-r--r--source/blender/compositor/operations/COM_KeyingClipOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_KeyingDespillOperation.cc29
-rw-r--r--source/blender/compositor/operations/COM_KeyingDespillOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_KeyingOperation.cc45
-rw-r--r--source/blender/compositor/operations/COM_KeyingOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_KeyingScreenOperation.cc95
-rw-r--r--source/blender/compositor/operations/COM_KeyingScreenOperation.h12
-rw-r--r--source/blender/compositor/operations/COM_LuminanceMatteOperation.cc36
-rw-r--r--source/blender/compositor/operations/COM_LuminanceMatteOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_MapUVOperation.cc97
-rw-r--r--source/blender/compositor/operations/COM_MapUVOperation.h21
-rw-r--r--source/blender/compositor/operations/COM_MaskOperation.cc37
-rw-r--r--source/blender/compositor/operations/COM_MaskOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.cc322
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.h154
-rw-r--r--source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc19
-rw-r--r--source/blender/compositor/operations/COM_MovieClipAttributeOperation.h9
-rw-r--r--source/blender/compositor/operations/COM_MovieDistortionOperation.cc47
-rw-r--r--source/blender/compositor/operations/COM_MovieDistortionOperation.h9
-rw-r--r--source/blender/compositor/operations/COM_OutputFileOperation.cc33
-rw-r--r--source/blender/compositor/operations/COM_OutputFileOperation.h14
-rw-r--r--source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc99
-rw-r--r--source/blender/compositor/operations/COM_PlaneCornerPinOperation.h7
-rw-r--r--source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc115
-rw-r--r--source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h16
-rw-r--r--source/blender/compositor/operations/COM_PlaneTrackOperation.cc26
-rw-r--r--source/blender/compositor/operations/COM_PlaneTrackOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc54
-rw-r--r--source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_RotateOperation.cc86
-rw-r--r--source/blender/compositor/operations/COM_RotateOperation.h37
-rw-r--r--source/blender/compositor/operations/COM_ScaleOperation.cc13
-rw-r--r--source/blender/compositor/operations/COM_ScaleOperation.h9
-rw-r--r--source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc189
-rw-r--r--source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h13
-rw-r--r--source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc12
-rw-r--r--source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc13
-rw-r--r--source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_SetColorOperation.cc10
-rw-r--r--source/blender/compositor/operations/COM_SetColorOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_SetValueOperation.cc10
-rw-r--r--source/blender/compositor/operations/COM_SetValueOperation.h3
-rw-r--r--source/blender/compositor/operations/COM_SplitOperation.cc13
-rw-r--r--source/blender/compositor/operations/COM_SplitOperation.h8
-rw-r--r--source/blender/compositor/operations/COM_SunBeamsOperation.cc53
-rw-r--r--source/blender/compositor/operations/COM_SunBeamsOperation.h12
-rw-r--r--source/blender/compositor/operations/COM_TonemapOperation.cc124
-rw-r--r--source/blender/compositor/operations/COM_TonemapOperation.h16
-rw-r--r--source/blender/compositor/operations/COM_TrackPositionOperation.cc26
-rw-r--r--source/blender/compositor/operations/COM_TrackPositionOperation.h11
-rw-r--r--source/blender/compositor/operations/COM_TransformOperation.cc156
-rw-r--r--source/blender/compositor/operations/COM_TransformOperation.h87
-rw-r--r--source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc161
-rw-r--r--source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h17
-rw-r--r--source/blender/compositor/operations/COM_VectorCurveOperation.cc10
-rw-r--r--source/blender/compositor/operations/COM_VectorCurveOperation.h4
-rw-r--r--source/blender/compositor/operations/COM_ZCombineOperation.cc70
-rw-r--r--source/blender/compositor/operations/COM_ZCombineOperation.h20
-rw-r--r--source/blender/datatoc/datatoc.c9
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.cc3
-rw-r--r--source/blender/draw/engines/eevee/eevee_lookdev.c2
-rw-r--r--source/blender/draw/engines/image/image_engine.c65
-rw-r--r--source/blender/draw/engines/overlay/overlay_engine.c28
-rw-r--r--source/blender/draw/engines/overlay/overlay_extra.c8
-rw-r--r--source/blender/draw/engines/overlay/overlay_paint.c27
-rw-r--r--source/blender/draw/engines/overlay/overlay_private.h2
-rw-r--r--source/blender/draw/engines/overlay/overlay_shader.c13
-rw-r--r--source/blender/draw/engines/overlay/shaders/paint_weight_frag.glsl23
-rw-r--r--source/blender/draw/engines/overlay/shaders/paint_weight_vert.glsl15
-rw-r--r--source/blender/draw/engines/select/select_debug_engine.c2
-rw-r--r--source/blender/draw/intern/draw_cache_extract.h178
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh.cc53
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh_render_data.c53
-rw-r--r--source/blender/draw/intern/draw_cache_impl_mesh.c693
-rw-r--r--source/blender/draw/intern/draw_manager_texture.c24
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh.c6
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh.h8
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc8
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc12
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc22
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_edituv_data.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_nor.cc4
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc4
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_orco.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc4
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc8
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_skin_roots.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc4
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc2
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc2
-rw-r--r--source/blender/draw/tests/shaders_test.cc3
-rw-r--r--source/blender/editors/animation/anim_ipo_utils.c22
-rw-r--r--source/blender/editors/animation/keyframes_draw.c747
-rw-r--r--source/blender/editors/animation/keyframes_keylist.cc5
-rw-r--r--source/blender/editors/asset/intern/asset_ops.cc2
-rw-r--r--source/blender/editors/curve/editfont.c4
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c85
-rw-r--r--source/blender/editors/gpencil/gpencil_convert.c25
-rw-r--r--source/blender/editors/gpencil/gpencil_fill.c3
-rw-r--r--source/blender/editors/gpencil/gpencil_interpolate.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_mesh.c3
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c54
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c9
-rw-r--r--source/blender/editors/gpencil/gpencil_undo.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c2
-rw-r--r--source/blender/editors/include/ED_keyframes_draw.h41
-rw-r--r--source/blender/editors/include/ED_node.h5
-rw-r--r--source/blender/editors/include/ED_transform.h1
-rw-r--r--source/blender/editors/include/UI_resources.h2
-rw-r--r--source/blender/editors/include/UI_view2d.h17
-rw-r--r--source/blender/editors/interface/interface_align.c2
-rw-r--r--source/blender/editors/interface/interface_context_menu.c10
-rw-r--r--source/blender/editors/interface/interface_draw.c4
-rw-r--r--source/blender/editors/interface/interface_handlers.c21
-rw-r--r--source/blender/editors/interface/interface_icons.c17
-rw-r--r--source/blender/editors/interface/interface_intern.h2
-rw-r--r--source/blender/editors/interface/interface_panel.c8
-rw-r--r--source/blender/editors/interface/interface_query.c7
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c3
-rw-r--r--source/blender/editors/interface/interface_style.c45
-rw-r--r--source/blender/editors/interface/interface_templates.c131
-rw-r--r--source/blender/editors/interface/interface_widgets.c53
-rw-r--r--source/blender/editors/interface/resources.c2
-rw-r--r--source/blender/editors/interface/view2d_edge_pan.c54
-rw-r--r--source/blender/editors/io/io_alembic.c10
-rw-r--r--source/blender/editors/mesh/editmesh_knife.c41
-rw-r--r--source/blender/editors/mesh/editmesh_knife_project.c46
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c198
-rw-r--r--source/blender/editors/mesh/editmesh_undo.c4
-rw-r--r--source/blender/editors/mesh/mesh_data.c11
-rw-r--r--source/blender/editors/mesh/mesh_intern.h5
-rw-r--r--source/blender/editors/object/object_add.c23
-rw-r--r--source/blender/editors/object/object_constraint.c324
-rw-r--r--source/blender/editors/object/object_intern.h3
-rw-r--r--source/blender/editors/object/object_modifier.c2
-rw-r--r--source/blender/editors/object/object_ops.c3
-rw-r--r--source/blender/editors/object/object_relations.c24
-rw-r--r--source/blender/editors/object/object_vgroup.c2
-rw-r--r--source/blender/editors/physics/particle_edit.c2
-rw-r--r--source/blender/editors/physics/particle_object.c3
-rw-r--r--source/blender/editors/render/render_opengl.c2
-rw-r--r--source/blender/editors/render/render_preview.c92
-rw-r--r--source/blender/editors/render/render_update.c34
-rw-r--r--source/blender/editors/screen/screen_draw.c2
-rw-r--r--source/blender/editors/screen/screen_edit.c2
-rw-r--r--source/blender/editors/space_action/action_data.c14
-rw-r--r--source/blender/editors/space_action/action_draw.c40
-rw-r--r--source/blender/editors/space_buttons/buttons_ops.c12
-rw-r--r--source/blender/editors/space_buttons/space_buttons.c3
-rw-r--r--source/blender/editors/space_clip/clip_editor.c1
-rw-r--r--source/blender/editors/space_console/console_ops.c6
-rw-r--r--source/blender/editors/space_file/file_ops.c49
-rw-r--r--source/blender/editors/space_file/filesel.c14
-rw-r--r--source/blender/editors/space_file/space_file.c26
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c2
-rw-r--r--source/blender/editors/space_image/image_edit.c10
-rw-r--r--source/blender/editors/space_image/image_ops.c39
-rw-r--r--source/blender/editors/space_image/image_sequence.c36
-rw-r--r--source/blender/editors/space_info/info_ops.c2
-rw-r--r--source/blender/editors/space_nla/nla_channels.c3
-rw-r--r--source/blender/editors/space_nla/nla_draw.c19
-rw-r--r--source/blender/editors/space_nla/nla_edit.c4
-rw-r--r--source/blender/editors/space_node/drawnode.cc22
-rw-r--r--source/blender/editors/space_node/node_draw.cc4
-rw-r--r--source/blender/editors/space_node/node_geometry_attribute_search.cc1
-rw-r--r--source/blender/editors/space_node/node_relationships.cc13
-rw-r--r--source/blender/editors/space_outliner/outliner_collections.c2
-rw-r--r--source/blender/editors/space_outliner/outliner_edit.c2
-rw-r--r--source/blender/editors/space_outliner/outliner_tools.c79
-rw-r--r--source/blender/editors/space_script/script_edit.c7
-rw-r--r--source/blender/editors/space_sequencer/sequencer_add.c38
-rw-r--r--source/blender/editors/space_sequencer/sequencer_draw.c329
-rw-r--r--source/blender/editors/space_sequencer/sequencer_edit.c11
-rw-r--r--source/blender/editors/space_sequencer/space_sequencer.c2
-rw-r--r--source/blender/editors/space_text/text_ops.c7
-rw-r--r--source/blender/editors/space_view3d/view3d_buttons.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_ruler.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_project.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c6
-rw-r--r--source/blender/editors/transform/CMakeLists.txt1
-rw-r--r--source/blender/editors/transform/transform.c7
-rw-r--r--source/blender/editors/transform/transform.h3
-rw-r--r--source/blender/editors/transform/transform_convert.c20
-rw-r--r--source/blender/editors/transform/transform_convert.h2
-rw-r--r--source/blender/editors/transform/transform_convert_action.c75
-rw-r--r--source/blender/editors/transform/transform_convert_armature.c4
-rw-r--r--source/blender/editors/transform/transform_convert_graph.c62
-rw-r--r--source/blender/editors/transform/transform_convert_nla.c73
-rw-r--r--source/blender/editors/transform/transform_convert_node.c38
-rw-r--r--source/blender/editors/transform/transform_convert_object.c2
-rw-r--r--source/blender/editors/transform/transform_convert_sequencer.c15
-rw-r--r--source/blender/editors/transform/transform_generics.c6
-rw-r--r--source/blender/editors/transform/transform_mode.c100
-rw-r--r--source/blender/editors/transform/transform_mode.h3
-rw-r--r--source/blender/editors/transform/transform_mode_align.c2
-rw-r--r--source/blender/editors/transform/transform_mode_baketime.c4
-rw-r--r--source/blender/editors/transform/transform_mode_bbone_resize.c4
-rw-r--r--source/blender/editors/transform/transform_mode_bend.c4
-rw-r--r--source/blender/editors/transform/transform_mode_boneenvelope.c4
-rw-r--r--source/blender/editors/transform/transform_mode_boneroll.c4
-rw-r--r--source/blender/editors/transform/transform_mode_curveshrinkfatten.c4
-rw-r--r--source/blender/editors/transform/transform_mode_edge_bevelweight.c4
-rw-r--r--source/blender/editors/transform/transform_mode_edge_crease.c4
-rw-r--r--source/blender/editors/transform/transform_mode_edge_rotate_normal.c3
-rw-r--r--source/blender/editors/transform/transform_mode_edge_slide.c4
-rw-r--r--source/blender/editors/transform/transform_mode_gpopacity.c4
-rw-r--r--source/blender/editors/transform/transform_mode_gpshrinkfatten.c4
-rw-r--r--source/blender/editors/transform/transform_mode_maskshrinkfatten.c4
-rw-r--r--source/blender/editors/transform/transform_mode_mirror.c2
-rw-r--r--source/blender/editors/transform/transform_mode_push_pull.c4
-rw-r--r--source/blender/editors/transform/transform_mode_rotate.c4
-rw-r--r--source/blender/editors/transform/transform_mode_shear.c4
-rw-r--r--source/blender/editors/transform/transform_mode_shrink_fatten.c4
-rw-r--r--source/blender/editors/transform/transform_mode_skin_resize.c4
-rw-r--r--source/blender/editors/transform/transform_mode_tilt.c4
-rw-r--r--source/blender/editors/transform/transform_mode_timescale.c7
-rw-r--r--source/blender/editors/transform/transform_mode_timeslide.c2
-rw-r--r--source/blender/editors/transform/transform_mode_timetranslate.c37
-rw-r--r--source/blender/editors/transform/transform_mode_tosphere.c4
-rw-r--r--source/blender/editors/transform/transform_mode_trackball.c4
-rw-r--r--source/blender/editors/transform/transform_mode_translate.c20
-rw-r--r--source/blender/editors/transform/transform_ops.c8
-rw-r--r--source/blender/editors/transform/transform_snap.c54
-rw-r--r--source/blender/editors/transform/transform_snap.h18
-rw-r--r--source/blender/editors/transform/transform_snap_animation.c159
-rw-r--r--source/blender/editors/util/CMakeLists.txt1
-rw-r--r--source/blender/editors/util/numinput.c2
-rw-r--r--source/blender/functions/CMakeLists.txt7
-rw-r--r--source/blender/functions/FN_generic_vector_array.hh2
-rw-r--r--source/blender/functions/FN_generic_virtual_array.hh2
-rw-r--r--source/blender/functions/FN_multi_function_network.hh536
-rw-r--r--source/blender/functions/FN_multi_function_network_evaluation.hh62
-rw-r--r--source/blender/functions/FN_multi_function_network_optimization.hh29
-rw-r--r--source/blender/functions/FN_multi_function_params.hh11
-rw-r--r--source/blender/functions/FN_multi_function_signature.hh15
-rw-r--r--source/blender/functions/intern/generic_vector_array.cc9
-rw-r--r--source/blender/functions/intern/multi_function_network.cc330
-rw-r--r--source/blender/functions/intern/multi_function_network_evaluation.cc1083
-rw-r--r--source/blender/functions/intern/multi_function_network_optimization.cc501
-rw-r--r--source/blender/functions/tests/FN_multi_function_network_test.cc280
-rw-r--r--source/blender/functions/tests/FN_multi_function_test.cc92
-rw-r--r--source/blender/functions/tests/FN_multi_function_test_common.hh174
-rw-r--r--source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h2
-rw-r--r--source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c4
-rw-r--r--source/blender/gpu/GPU_framebuffer.h2
-rw-r--r--source/blender/gpu/GPU_matrix.h6
-rw-r--r--source/blender/gpu/GPU_texture.h21
-rw-r--r--source/blender/gpu/intern/gpu_framebuffer.cc5
-rw-r--r--source/blender/gpu/intern/gpu_material.c1
-rw-r--r--source/blender/gpu/intern/gpu_matrix.cc122
-rw-r--r--source/blender/gpu/intern/gpu_texture.cc36
-rw-r--r--source/blender/gpu/tests/gpu_shader_test.cc3
-rw-r--r--source/blender/imbuf/IMB_imbuf.h5
-rw-r--r--source/blender/imbuf/intern/IMB_anim.h1
-rw-r--r--source/blender/imbuf/intern/anim_movie.c159
-rw-r--r--source/blender/imbuf/intern/indexer.c2
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp2
-rw-r--r--source/blender/io/alembic/ABC_alembic.h1
-rw-r--r--source/blender/io/alembic/intern/abc_reader_curves.cc2
-rw-r--r--source/blender/io/alembic/intern/abc_reader_mesh.cc4
-rw-r--r--source/blender/io/alembic/intern/abc_reader_object.cc4
-rw-r--r--source/blender/io/alembic/intern/abc_reader_object.h2
-rw-r--r--source/blender/io/alembic/intern/abc_reader_points.cc2
-rw-r--r--source/blender/io/alembic/intern/alembic_capi.cc2
-rw-r--r--source/blender/io/collada/AnimationImporter.cpp2
-rw-r--r--source/blender/io/collada/collada_internal.cpp2
-rw-r--r--source/blender/io/usd/intern/usd_capi_export.cc2
-rw-r--r--source/blender/makesdna/DNA_ID.h23
-rw-r--r--source/blender/makesdna/DNA_cachefile_defaults.h2
-rw-r--r--source/blender/makesdna/DNA_cachefile_types.h19
-rw-r--r--source/blender/makesdna/DNA_gpencil_types.h1
-rw-r--r--source/blender/makesdna/DNA_mesh_types.h1
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h25
-rw-r--r--source/blender/makesdna/DNA_node_types.h7
-rw-r--r--source/blender/makesdna/DNA_object_types.h3
-rw-r--r--source/blender/makesdna/DNA_sequence_types.h4
-rw-r--r--source/blender/makesdna/DNA_sound_types.h1
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h5
-rw-r--r--source/blender/makesdna/intern/makesdna.c69
-rw-r--r--source/blender/makesrna/RNA_access.h11
-rw-r--r--source/blender/makesrna/RNA_enum_items.h240
-rw-r--r--source/blender/makesrna/RNA_enum_types.h212
-rw-r--r--source/blender/makesrna/intern/CMakeLists.txt1
-rw-r--r--source/blender/makesrna/intern/makesrna.c93
-rw-r--r--source/blender/makesrna/intern/rna_access.c52
-rw-r--r--source/blender/makesrna/intern/rna_access_compare_override.c16
-rw-r--r--source/blender/makesrna/intern/rna_armature.c8
-rw-r--r--source/blender/makesrna/intern/rna_cachefile.c34
-rw-r--r--source/blender/makesrna/intern/rna_color.c6
-rw-r--r--source/blender/makesrna/intern/rna_constraint.c6
-rw-r--r--source/blender/makesrna/intern/rna_curveprofile.c27
-rw-r--r--source/blender/makesrna/intern/rna_image.c9
-rw-r--r--source/blender/makesrna/intern/rna_light.c1
-rw-r--r--source/blender/makesrna/intern/rna_linestyle.c1
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c2
-rw-r--r--source/blender/makesrna/intern/rna_material.c3
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c2
-rw-r--r--source/blender/makesrna/intern/rna_modifier.c85
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c51
-rw-r--r--source/blender/makesrna/intern/rna_object.c8
-rw-r--r--source/blender/makesrna/intern/rna_particle.c10
-rw-r--r--source/blender/makesrna/intern/rna_render.c6
-rw-r--r--source/blender/makesrna/intern/rna_scene.c12
-rw-r--r--source/blender/makesrna/intern/rna_sequencer.c8
-rw-r--r--source/blender/makesrna/intern/rna_sequencer_api.c31
-rw-r--r--source/blender/makesrna/intern/rna_simulation.c1
-rw-r--r--source/blender/makesrna/intern/rna_space.c17
-rw-r--r--source/blender/makesrna/intern/rna_speaker.c70
-rw-r--r--source/blender/makesrna/intern/rna_text.c3
-rw-r--r--source/blender/makesrna/intern/rna_texture.c1
-rw-r--r--source/blender/makesrna/intern/rna_ui.c4
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c24
-rw-r--r--source/blender/makesrna/intern/rna_wm.c28
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c2
-rw-r--r--source/blender/makesrna/intern/rna_wm_gizmo.c22
-rw-r--r--source/blender/makesrna/intern/rna_world.c3
-rw-r--r--source/blender/modifiers/intern/MOD_build.c4
-rw-r--r--source/blender/modifiers/intern/MOD_cloth.c4
-rw-r--r--source/blender/modifiers/intern/MOD_collision.c4
-rw-r--r--source/blender/modifiers/intern/MOD_displace.c4
-rw-r--r--source/blender/modifiers/intern/MOD_dynamicpaint.c4
-rw-r--r--source/blender/modifiers/intern/MOD_explode.c4
-rw-r--r--source/blender/modifiers/intern/MOD_fluid.c4
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache.c4
-rw-r--r--source/blender/modifiers/intern/MOD_meshsequencecache.c57
-rw-r--r--source/blender/modifiers/intern/MOD_nodes.cc5
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.cc2
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.hh6
-rw-r--r--source/blender/modifiers/intern/MOD_normal_edit.c16
-rw-r--r--source/blender/modifiers/intern/MOD_softbody.c4
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_extrude.c53
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_nonmanifold.c11
-rw-r--r--source/blender/modifiers/intern/MOD_subsurf.c9
-rw-r--r--source/blender/modifiers/intern/MOD_surface.c4
-rw-r--r--source/blender/modifiers/intern/MOD_uvproject.c2
-rw-r--r--source/blender/modifiers/intern/MOD_volume_displace.cc4
-rw-r--r--source/blender/modifiers/intern/MOD_warp.c4
-rw-r--r--source/blender/modifiers/intern/MOD_wave.c4
-rw-r--r--source/blender/modifiers/intern/MOD_weighted_normal.c4
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgedit.c4
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgmix.c4
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c4
-rw-r--r--source/blender/nodes/CMakeLists.txt6
-rw-r--r--source/blender/nodes/NOD_multi_function.hh130
-rw-r--r--source/blender/nodes/NOD_node_tree_multi_function.hh390
-rw-r--r--source/blender/nodes/NOD_static_types.h2
-rw-r--r--source/blender/nodes/composite/node_composite_tree.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_idMask.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_math.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_premulkey.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c4
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c4
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c4
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c4
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_setalpha.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_switchview.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_valToRgb.c4
-rw-r--r--source/blender/nodes/function/node_function_util.hh2
-rw-r--r--source/blender/nodes/function/nodes/node_fn_boolean_math.cc21
-rw-r--r--source/blender/nodes/function/nodes/node_fn_float_compare.cc27
-rw-r--r--source/blender/nodes/function/nodes/node_fn_float_to_int.cc21
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_string.cc12
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_vector.cc10
-rw-r--r--source/blender/nodes/function/nodes/node_fn_random_float.cc9
-rw-r--r--source/blender/nodes/geometry/node_geometry_tree.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_raycast.cc152
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc45
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_switch.cc2
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc1
-rw-r--r--source/blender/nodes/intern/node_multi_function.cc (renamed from source/blender/nodes/NOD_type_callbacks.hh)32
-rw-r--r--source/blender/nodes/intern/node_socket.cc1
-rw-r--r--source/blender/nodes/intern/node_tree_multi_function.cc409
-rw-r--r--source/blender/nodes/intern/type_callbacks.cc60
-rw-r--r--source/blender/nodes/shader/node_shader_tree.c3
-rw-r--r--source/blender/nodes/shader/node_shader_util.h2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_blackbody.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_clamp.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_curves.cc14
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_map_range.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.cc69
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mixRgb.cc58
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc12
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc12
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_squeeze.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_valToRgb.cc11
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_value.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_math.cc28
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc37
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_wavelength.c2
-rw-r--r--source/blender/nodes/texture/node_texture_tree.c2
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_distance.c2
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_math.c2
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_valToNor.c2
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_valToRgb.c4
-rw-r--r--source/blender/python/generic/blf_py_api.c1
-rw-r--r--source/blender/python/gpu/gpu_py_buffer.c6
-rw-r--r--source/blender/python/gpu/gpu_py_capabilities.c162
-rw-r--r--source/blender/python/gpu/gpu_py_offscreen.c2
-rw-r--r--source/blender/python/gpu/gpu_py_platform.c36
-rw-r--r--source/blender/python/gpu/gpu_py_shader.c45
-rw-r--r--source/blender/python/intern/bpy.c3
-rw-r--r--source/blender/python/intern/bpy_app_icons.c6
-rw-r--r--source/blender/python/intern/bpy_interface.c9
-rw-r--r--source/blender/python/intern/bpy_rna.c63
-rw-r--r--source/blender/python/intern/bpy_rna.h1
-rw-r--r--source/blender/python/intern/bpy_rna_array.c2
-rw-r--r--source/blender/python/mathutils/mathutils_geometry.c2
-rw-r--r--source/blender/render/RE_engine.h7
-rw-r--r--source/blender/render/RE_pipeline.h2
-rw-r--r--source/blender/render/intern/engine.c24
-rw-r--r--source/blender/render/intern/pipeline.c1
-rw-r--r--source/blender/render/intern/render_result.c65
-rw-r--r--source/blender/render/intern/render_result.h2
-rw-r--r--source/blender/sequencer/CMakeLists.txt1
-rw-r--r--source/blender/sequencer/SEQ_add.h6
-rw-r--r--source/blender/sequencer/SEQ_edit.h3
-rw-r--r--source/blender/sequencer/SEQ_iterator.h1
-rw-r--r--source/blender/sequencer/SEQ_relations.h3
-rw-r--r--source/blender/sequencer/intern/effects.c212
-rw-r--r--source/blender/sequencer/intern/effects.h4
-rw-r--r--source/blender/sequencer/intern/image_cache.c32
-rw-r--r--source/blender/sequencer/intern/iterator.c8
-rw-r--r--source/blender/sequencer/intern/prefetch.c122
-rw-r--r--source/blender/sequencer/intern/render.c2
-rw-r--r--source/blender/sequencer/intern/sound.c7
-rw-r--r--source/blender/sequencer/intern/strip_add.c50
-rw-r--r--source/blender/sequencer/intern/strip_edit.c126
-rw-r--r--source/blender/sequencer/intern/strip_relations.c26
-rw-r--r--source/blender/sequencer/intern/strip_time.c4
-rw-r--r--source/blender/sequencer/intern/strip_transform.c10
-rw-r--r--source/blender/sequencer/intern/utils.c21
-rw-r--r--source/blender/sequencer/intern/utils.h4
-rw-r--r--source/blender/windowmanager/CMakeLists.txt4
-rw-r--r--source/blender/windowmanager/WM_types.h9
-rw-r--r--source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c8
-rw-r--r--source/blender/windowmanager/intern/wm.c1
-rw-r--r--source/blender/windowmanager/intern/wm_draw.c160
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c4
-rw-r--r--source/blender/windowmanager/intern/wm_files.c245
-rw-r--r--source/blender/windowmanager/intern/wm_files_link.c83
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c124
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c9
-rw-r--r--source/blender/windowmanager/wm_files.h47
-rw-r--r--source/blender/windowmanager/xr/intern/wm_xr_session.c26
-rw-r--r--source/creator/CMakeLists.txt5
m---------source/tools0
-rw-r--r--tests/performance/api/environment.py2
-rw-r--r--tests/python/CMakeLists.txt7
754 files changed, 16653 insertions, 11503 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2868324bf46..47712f0ac1e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1598,6 +1598,9 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
+ # Using C++20 features while having C++17 as the project language isn't allowed by MSVC.
+ ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_CXX20_DESIGNATOR -Wc++20-designator)
+
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
diff --git a/build_files/build_environment/install_deps.sh b/build_files/build_environment/install_deps.sh
index ff4aad79bb6..ecaff307885 100755
--- a/build_files/build_environment/install_deps.sh
+++ b/build_files/build_environment/install_deps.sh
@@ -1019,7 +1019,7 @@ PRINT ""
PYTHON_SOURCE=( "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz" )
_boost_version_nodots=`echo "$BOOST_VERSION" | sed -r 's/\./_/g'`
-BOOST_SOURCE=( "https://dl.bintray.com/boostorg/release/$BOOST_VERSION/source/boost_$_boost_version_nodots.tar.bz2" )
+BOOST_SOURCE=( "https://boostorg.jfrog.io/artifactory/main/release/$BOOST_VERSION/source/boost_$_boost_version_nodots.tar.bz2" )
BOOST_BUILD_MODULES="--with-system --with-filesystem --with-thread --with-regex --with-locale --with-date_time --with-wave --with-iostreams --with-python --with-program_options --with-serialization --with-atomic"
TBB_SOURCE=( "https://github.com/oneapi-src/oneTBB/archive/$TBB_VERSION$TBB_VERSION_UPDATE.tar.gz" )
diff --git a/build_files/cmake/Modules/FindZstd.cmake b/build_files/cmake/Modules/FindZstd.cmake
new file mode 100644
index 00000000000..84606d01f44
--- /dev/null
+++ b/build_files/cmake/Modules/FindZstd.cmake
@@ -0,0 +1,66 @@
+# - Find Zstd library
+# Find the native Zstd includes and library
+# This module defines
+# ZSTD_INCLUDE_DIRS, where to find zstd.h, Set when
+# ZSTD_INCLUDE_DIR is found.
+# ZSTD_LIBRARIES, libraries to link against to use Zstd.
+# ZSTD_ROOT_DIR, The base directory to search for Zstd.
+# This can also be an environment variable.
+# ZSTD_FOUND, If false, do not try to use Zstd.
+#
+# also defined, but not for general use are
+# ZSTD_LIBRARY, where to find the Zstd library.
+
+#=============================================================================
+# Copyright 2019 Blender Foundation.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+# If ZSTD_ROOT_DIR was defined in the environment, use it.
+IF(NOT ZSTD_ROOT_DIR AND NOT $ENV{ZSTD_ROOT_DIR} STREQUAL "")
+ SET(ZSTD_ROOT_DIR $ENV{ZSTD_ROOT_DIR})
+ENDIF()
+
+SET(_zstd_SEARCH_DIRS
+ ${ZSTD_ROOT_DIR}
+)
+
+FIND_PATH(ZSTD_INCLUDE_DIR
+ NAMES
+ zstd.h
+ HINTS
+ ${_zstd_SEARCH_DIRS}
+ PATH_SUFFIXES
+ include
+)
+
+FIND_LIBRARY(ZSTD_LIBRARY
+ NAMES
+ zstd
+ HINTS
+ ${_zstd_SEARCH_DIRS}
+ PATH_SUFFIXES
+ lib64 lib
+ )
+
+# handle the QUIETLY and REQUIRED arguments and set ZSTD_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Zstd DEFAULT_MSG
+ ZSTD_LIBRARY ZSTD_INCLUDE_DIR)
+
+IF(ZSTD_FOUND)
+ SET(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
+ SET(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
+ENDIF()
+
+MARK_AS_ADVANCED(
+ ZSTD_INCLUDE_DIR
+ ZSTD_LIBRARY
+)
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index a130d265dff..2bfdc84ec2a 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -441,6 +441,9 @@ if(WITH_HARU)
endif()
endif()
+set(ZSTD_ROOT_DIR ${LIBDIR}/zstd)
+find_package(Zstd REQUIRED)
+
if(EXISTS ${LIBDIR})
without_system_libs_end()
endif()
@@ -500,17 +503,10 @@ endif()
# makesdna, tests, etc.), we add an rpath to the OpenMP library dir through
# CMAKE_BUILD_RPATH. This avoids having to make many copies of the dylib next to each binary.
#
-# For the installed Blender executable, CMAKE_INSTALL_RPATH will be used
-# to locate the dylibs at @executable_path, next to the Blender executable.
-#
-# For the installed Python module, CMAKE_INSTALL_RPATH is modified to find the
-# dylib in an adjacent folder.
+# For the installed Python module and installed Blender executable, CMAKE_INSTALL_RPATH
+# is modified to find the dylib in an adjacent folder. Install step puts the libraries there.
set(CMAKE_SKIP_BUILD_RPATH FALSE)
list(APPEND CMAKE_BUILD_RPATH "${OpenMP_LIBRARY_DIR}")
set(CMAKE_SKIP_INSTALL_RPATH FALSE)
-list(APPEND CMAKE_INSTALL_RPATH "@executable_path")
-
-if(WITH_PYTHON_MODULE)
- list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../Resources/${BLENDER_VERSION}/lib")
-endif()
+list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../Resources/${BLENDER_VERSION}/lib")
diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index 7f62399ac4f..fc0c37e4c8b 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -99,6 +99,7 @@ endif()
find_package_wrapper(JPEG REQUIRED)
find_package_wrapper(PNG REQUIRED)
find_package_wrapper(ZLIB REQUIRED)
+find_package_wrapper(Zstd REQUIRED)
find_package_wrapper(Freetype REQUIRED)
if(WITH_PYTHON)
diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index 3773aaaffed..d44ef691d1b 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -873,3 +873,6 @@ if(WITH_HARU)
set(WITH_HARU OFF)
endif()
endif()
+
+set(ZSTD_INCLUDE_DIRS ${LIBDIR}/zstd/include)
+set(ZSTD_LIBRARIES ${LIBDIR}/zstd/lib/zstd_static.lib)
diff --git a/build_files/config/pipeline_config.yaml b/build_files/config/pipeline_config.yaml
index 611df59caec..5d1a24a30f1 100644
--- a/build_files/config/pipeline_config.yaml
+++ b/build_files/config/pipeline_config.yaml
@@ -51,9 +51,9 @@ buildbot:
gcc:
version: '9.0.0'
cuda10:
- version: '10.1.0'
+ version: '10.1.243'
cuda11:
- version: '11.4.0'
+ version: '11.4.1'
optix:
version: '7.1.0'
cmake:
diff --git a/doc/python_api/requirements.txt b/doc/python_api/requirements.txt
index a854d2a267b..b5a9d15bf7b 100644
--- a/doc/python_api/requirements.txt
+++ b/doc/python_api/requirements.txt
@@ -1,13 +1,13 @@
-sphinx==3.5.4
+sphinx==4.1.1
# Sphinx dependencies that are important
-Jinja2==2.11.3
-Pygments==2.9.0
-docutils==0.16
+Jinja2==3.0.1
+Pygments==2.10.0
+docutils==0.17.1
snowballstemmer==2.1.0
babel==2.9.1
-requests==2.25.1
+requests==2.26.0
# Only needed to match the theme used for the official documentation.
# Without this theme, the default theme will be used.
-sphinx_rtd_theme==0.5.2
+sphinx_rtd_theme==1.0.0rc1
diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py
index d6c1d7b51b8..48cbb5f197c 100644
--- a/doc/python_api/sphinx_doc_gen.py
+++ b/doc/python_api/sphinx_doc_gen.py
@@ -254,6 +254,8 @@ else:
"gpu.shader",
"gpu.state",
"gpu.texture",
+ "gpu.platform",
+ "gpu.capabilities",
"gpu_extras",
"idprop.types",
"mathutils",
@@ -1047,7 +1049,7 @@ context_type_map = {
"annotation_data": ("GreasePencil", False),
"annotation_data_owner": ("ID", False),
"armature": ("Armature", False),
- "asset_library": ("AssetLibraryReference", False),
+ "asset_library_ref": ("AssetLibraryReference", False),
"bone": ("Bone", False),
"brush": ("Brush", False),
"camera": ("Camera", False),
@@ -2000,6 +2002,8 @@ def write_rst_importable_modules(basepath):
"gpu.shader": "GPU Shader Utilities",
"gpu.state": "GPU State Utilities",
"gpu.texture": "GPU Texture Utilities",
+ "gpu.platform": "GPU Platform Utilities",
+ "gpu.capabilities": "GPU Capabilities Utilities",
"bmesh": "BMesh Module",
"bmesh.ops": "BMesh Operators",
"bmesh.types": "BMesh Types",
diff --git a/extern/audaspace/bindings/C/AUD_Special.cpp b/extern/audaspace/bindings/C/AUD_Special.cpp
index ac876a01eb3..5cc33525d1d 100644
--- a/extern/audaspace/bindings/C/AUD_Special.cpp
+++ b/extern/audaspace/bindings/C/AUD_Special.cpp
@@ -86,6 +86,7 @@ AUD_API AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
info.specs.channels = AUD_CHANNELS_INVALID;
info.specs.rate = AUD_RATE_INVALID;
info.length = 0.0f;
+ info.start_offset = 0.0f;
try
{
@@ -95,6 +96,7 @@ AUD_API AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
{
info.specs = convSpecToC(reader->getSpecs());
info.length = reader->getLength() / (float) info.specs.rate;
+ info.start_offset = reader->getStartOffset();
}
}
catch(Exception&)
@@ -245,7 +247,7 @@ AUD_API int AUD_readSound(AUD_Sound* sound, float* buffer, int length, int sampl
buffer[i * 3] = min;
buffer[i * 3 + 1] = max;
- buffer[i * 3 + 2] = sqrt(power) / len;
+ buffer[i * 3 + 2] = sqrt(power / len); // RMS
if(overallmax < max)
overallmax = max;
diff --git a/extern/audaspace/bindings/C/AUD_Types.h b/extern/audaspace/bindings/C/AUD_Types.h
index 75e4ffae18c..c6a96d30d3f 100644
--- a/extern/audaspace/bindings/C/AUD_Types.h
+++ b/extern/audaspace/bindings/C/AUD_Types.h
@@ -176,4 +176,5 @@ typedef struct
{
AUD_Specs specs;
float length;
+ double start_offset;
} AUD_SoundInfo;
diff --git a/extern/audaspace/bindings/python/setup.py.in b/extern/audaspace/bindings/python/setup.py.in
index add1a2d1475..5ad1a37db3a 100644
--- a/extern/audaspace/bindings/python/setup.py.in
+++ b/extern/audaspace/bindings/python/setup.py.in
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
import sys
import os
diff --git a/extern/audaspace/include/IReader.h b/extern/audaspace/include/IReader.h
index c29900ca579..f6070b0f23b 100644
--- a/extern/audaspace/include/IReader.h
+++ b/extern/audaspace/include/IReader.h
@@ -71,6 +71,12 @@ public:
virtual int getPosition() const=0;
/**
+ * Returns the start offset the sound should have to line up with related sources.
+ * \return The required start offset in seconds.
+ */
+ virtual double getStartOffset() const { return 0.0;}
+
+ /**
* Returns the specification of the reader.
* \return The Specs structure.
*/
diff --git a/extern/audaspace/include/fx/VolumeReader.h b/extern/audaspace/include/fx/VolumeReader.h
index 13b6845e931..f7169f4c78b 100644
--- a/extern/audaspace/include/fx/VolumeReader.h
+++ b/extern/audaspace/include/fx/VolumeReader.h
@@ -67,4 +67,4 @@ public:
virtual void read(int& length, bool& eos, sample_t* buffer);
};
-AUD_NAMESPACE_END \ No newline at end of file
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp b/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
index b46f65eddbf..afdc7fcfcc6 100644
--- a/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
+++ b/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
@@ -68,7 +68,7 @@ int FFMPEGReader::decode(AVPacket& packet, Buffer& buffer)
for(int i = 0; i < m_frame->nb_samples; i++)
{
std::memcpy(((data_t*)buffer.getBuffer()) + buf_pos + ((m_codecCtx->channels * i) + channel) * single_size,
- m_frame->data[channel] + i * single_size, single_size);
+ m_frame->data[channel] + i * single_size, single_size);
}
}
}
@@ -109,7 +109,7 @@ int FFMPEGReader::decode(AVPacket& packet, Buffer& buffer)
for(int i = 0; i < m_frame->nb_samples; i++)
{
std::memcpy(((data_t*)buffer.getBuffer()) + buf_pos + ((m_codecCtx->channels * i) + channel) * single_size,
- m_frame->data[channel] + i * single_size, single_size);
+ m_frame->data[channel] + i * single_size, single_size);
}
}
}
@@ -126,7 +126,10 @@ int FFMPEGReader::decode(AVPacket& packet, Buffer& buffer)
void FFMPEGReader::init()
{
m_position = 0;
+ m_start_offset = 0.0f;
m_pkgbuf_left = 0;
+ m_st_time = 0;
+ m_duration = 0;
if(avformat_find_stream_info(m_formatCtx, nullptr) < 0)
AUD_THROW(FileException, "File couldn't be read, ffmpeg couldn't find the stream info.");
@@ -134,15 +137,41 @@ void FFMPEGReader::init()
// find audio stream and codec
m_stream = -1;
+ double dur_sec = 0;
+
for(unsigned int i = 0; i < m_formatCtx->nb_streams; i++)
{
#ifdef FFMPEG_OLD_CODE
- if((m_formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ if(m_formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
#else
- if((m_formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+ if(m_formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
#endif
- && (m_stream < 0))
{
+ AVStream *audio_stream = m_formatCtx->streams[i];
+ double audio_timebase = av_q2d(audio_stream->time_base);
+
+ if (audio_stream->start_time != AV_NOPTS_VALUE)
+ {
+ m_st_time = audio_stream->start_time;
+ }
+
+ int64_t ctx_start_time = 0;
+ if (m_formatCtx->start_time != AV_NOPTS_VALUE) {
+ ctx_start_time = m_formatCtx->start_time;
+ }
+
+ m_start_offset = m_st_time * audio_timebase - (double)ctx_start_time / AV_TIME_BASE;
+
+ if(audio_stream->duration != AV_NOPTS_VALUE)
+ {
+ dur_sec = audio_stream->duration * audio_timebase;
+ }
+ else
+ {
+ /* If the audio starts after the stream start time, subract this from the total duration. */
+ dur_sec = (double)m_formatCtx->duration / AV_TIME_BASE - m_start_offset;
+ }
+
m_stream=i;
break;
}
@@ -213,6 +242,7 @@ void FFMPEGReader::init()
}
m_specs.rate = (SampleRate) m_codecCtx->sample_rate;
+ m_duration = lround(dur_sec * m_codecCtx->sample_rate);
}
FFMPEGReader::FFMPEGReader(std::string filename) :
@@ -338,21 +368,17 @@ void FFMPEGReader::seek(int position)
{
if(position >= 0)
{
- uint64_t st_time = m_formatCtx->start_time;
- uint64_t seek_pos = ((uint64_t)position) * ((uint64_t)AV_TIME_BASE) / ((uint64_t)m_specs.rate);
+ double pts_time_base =
+ av_q2d(m_formatCtx->streams[m_stream]->time_base);
- if(st_time != AV_NOPTS_VALUE) {
- seek_pos += st_time;
- }
+ uint64_t seek_pts = (((uint64_t)position) / ((uint64_t)m_specs.rate)) / pts_time_base;
- double pts_time_base =
- av_q2d(m_formatCtx->streams[m_stream]->time_base);
- uint64_t pts_st_time =
- ((st_time != AV_NOPTS_VALUE) ? st_time : 0)
- / pts_time_base / (uint64_t) AV_TIME_BASE;
+ if(m_st_time != AV_NOPTS_VALUE) {
+ seek_pts += m_st_time;
+ }
// a value < 0 tells us that seeking failed
- if(av_seek_frame(m_formatCtx, -1, seek_pos,
+ if(av_seek_frame(m_formatCtx, m_stream, seek_pts,
AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY) >= 0)
{
avcodec_flush_buffers(m_codecCtx);
@@ -374,7 +400,7 @@ void FFMPEGReader::seek(int position)
if(packet.pts != AV_NOPTS_VALUE)
{
// calculate real position, and read to frame!
- m_position = (packet.pts - pts_st_time) * pts_time_base * m_specs.rate;
+ m_position = (packet.pts - m_st_time) * pts_time_base * m_specs.rate;
if(m_position < position)
{
@@ -405,8 +431,7 @@ void FFMPEGReader::seek(int position)
int FFMPEGReader::getLength() const
{
// return approximated remaning size
- return (int)((m_formatCtx->duration * m_codecCtx->sample_rate)
- / AV_TIME_BASE)-m_position;
+ return m_duration - m_position;
}
int FFMPEGReader::getPosition() const
@@ -414,6 +439,11 @@ int FFMPEGReader::getPosition() const
return m_position;
}
+double FFMPEGReader::getStartOffset() const
+{
+ return m_start_offset;
+}
+
Specs FFMPEGReader::getSpecs() const
{
return m_specs.specs;
@@ -450,11 +480,13 @@ void FFMPEGReader::read(int& length, bool& eos, sample_t* buffer)
// decode the package
pkgbuf_pos = decode(packet, m_pkgbuf);
- // copy to output buffer
- data_size = std::min(pkgbuf_pos, left * sample_size);
- m_convert((data_t*) buf, (data_t*) m_pkgbuf.getBuffer(), data_size / AUD_FORMAT_SIZE(m_specs.format));
- buf += data_size / AUD_FORMAT_SIZE(m_specs.format);
- left -= data_size / sample_size;
+ if (packet.pts >= m_st_time) {
+ // copy to output buffer
+ data_size = std::min(pkgbuf_pos, left * sample_size);
+ m_convert((data_t*) buf, (data_t*) m_pkgbuf.getBuffer(), data_size / AUD_FORMAT_SIZE(m_specs.format));
+ buf += data_size / AUD_FORMAT_SIZE(m_specs.format);
+ left -= data_size / sample_size;
+ }
}
av_packet_unref(&packet);
}
diff --git a/extern/audaspace/plugins/ffmpeg/FFMPEGReader.h b/extern/audaspace/plugins/ffmpeg/FFMPEGReader.h
index f62436ac83b..d613457c220 100644
--- a/extern/audaspace/plugins/ffmpeg/FFMPEGReader.h
+++ b/extern/audaspace/plugins/ffmpeg/FFMPEGReader.h
@@ -55,6 +55,22 @@ private:
int m_position;
/**
+ * The start offset in seconds relative to the media container start time.
+ * IE how much the sound should be delayed to be kept in sync with the rest of the containter streams.
+ */
+ double m_start_offset;
+
+ /**
+ * The start time pts of the stream. All packets before this timestamp shouldn't be played back (only decoded).
+ */
+ int64_t m_st_time;
+
+ /**
+ * The duration of the audio stream in samples.
+ */
+ int64_t m_duration;
+
+ /**
* The specification of the audio data.
*/
DeviceSpecs m_specs;
@@ -182,6 +198,7 @@ public:
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
+ virtual double getStartOffset() const;
virtual Specs getSpecs() const;
virtual void read(int& length, bool& eos, sample_t* buffer);
};
diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp
index cbfb5e96e6c..bf3fad82620 100644
--- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp
+++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp
@@ -32,17 +32,24 @@ void PulseAudioDevice::PulseAudio_state_callback(pa_context *context, void *data
device->m_state = AUD_pa_context_get_state(context);
}
-void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t num_bytes, void *data)
+void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t total_bytes, void *data)
{
PulseAudioDevice* device = (PulseAudioDevice*)data;
void* buffer;
- AUD_pa_stream_begin_write(stream, &buffer, &num_bytes);
+ while(total_bytes > 0)
+ {
+ size_t num_bytes = total_bytes;
+
+ AUD_pa_stream_begin_write(stream, &buffer, &num_bytes);
+
+ device->mix((data_t*)buffer, num_bytes / AUD_DEVICE_SAMPLE_SIZE(device->m_specs));
- device->mix((data_t*)buffer, num_bytes / AUD_DEVICE_SAMPLE_SIZE(device->m_specs));
+ AUD_pa_stream_write(stream, buffer, num_bytes, nullptr, 0, PA_SEEK_RELATIVE);
- AUD_pa_stream_write(stream, buffer, num_bytes, nullptr, 0, PA_SEEK_RELATIVE);
+ total_bytes -= num_bytes;
+ }
}
void PulseAudioDevice::PulseAudio_underflow(pa_stream *stream, void *data)
@@ -96,7 +103,6 @@ void PulseAudioDevice::runMixingThread()
PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buffersize) :
m_state(PA_CONTEXT_UNCONNECTED),
- m_buffersize(buffersize),
m_underflows(0)
{
m_mainloop = AUD_pa_mainloop_new();
@@ -187,6 +193,9 @@ PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buff
AUD_pa_stream_set_write_callback(m_stream, PulseAudio_request, this);
AUD_pa_stream_set_underflow_callback(m_stream, PulseAudio_underflow, this);
+ buffersize *= AUD_DEVICE_SAMPLE_SIZE(m_specs);
+ m_buffersize = buffersize;
+
pa_buffer_attr buffer_attr;
buffer_attr.fragsize = -1U;
diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h
index be34cc9032b..45b813a5755 100644
--- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h
+++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h
@@ -59,7 +59,7 @@ private:
* \param num_bytes The length in bytes to be supplied.
* \param data The PulseAudio device.
*/
- AUD_LOCAL static void PulseAudio_request(pa_stream* stream, size_t num_bytes, void* data);
+ AUD_LOCAL static void PulseAudio_request(pa_stream* stream, size_t total_bytes, void* data);
/**
* Reports an underflow from the PulseAudio server.
diff --git a/extern/audaspace/src/fx/VolumeReader.cpp b/extern/audaspace/src/fx/VolumeReader.cpp
index ac1d4882a87..627acbac9ef 100644
--- a/extern/audaspace/src/fx/VolumeReader.cpp
+++ b/extern/audaspace/src/fx/VolumeReader.cpp
@@ -57,4 +57,4 @@ void VolumeReader::read(int& length, bool& eos, sample_t* buffer)
buffer[i] = buffer[i] * m_volumeStorage->getVolume();
}
-AUD_NAMESPACE_END \ No newline at end of file
+AUD_NAMESPACE_END
diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index 2d48563d8a6..ee5c6157338 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -115,6 +115,16 @@ if(WITH_OPENVDB)
)
endif()
+if(WITH_ALEMBIC)
+ add_definitions(-DWITH_ALEMBIC)
+ list(APPEND INC_SYS
+ ${ALEMBIC_INCLUDE_DIRS}
+ )
+ list(APPEND LIB
+ ${ALEMBIC_LIBRARIES}
+ )
+endif()
+
if(WITH_OPENIMAGEDENOISE)
add_definitions(-DWITH_OPENIMAGEDENOISE)
list(APPEND INC_SYS
diff --git a/intern/cycles/blender/addon/__init__.py b/intern/cycles/blender/addon/__init__.py
index 10b95133912..f728050a3cf 100644
--- a/intern/cycles/blender/addon/__init__.py
+++ b/intern/cycles/blender/addon/__init__.py
@@ -61,6 +61,7 @@ class CyclesRender(bpy.types.RenderEngine):
bl_use_save_buffers = True
bl_use_spherical_stereo = True
bl_use_custom_freestyle = True
+ bl_use_alembic_procedural = True
def __init__(self):
self.session = None
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 124223635d1..0c3af3fabeb 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -227,6 +227,11 @@ def update_render_passes(self, context):
view_layer.update_render_passes()
+def update_render_engine(self, context):
+ scene = context.scene
+ scene.update_render_engine()
+
+
class CyclesRenderSettings(bpy.types.PropertyGroup):
device: EnumProperty(
@@ -240,6 +245,7 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
description="Feature set to use for rendering",
items=enum_feature_set,
default='SUPPORTED',
+ update=update_render_engine,
)
shading_system: BoolProperty(
name="Open Shading Language",
@@ -402,7 +408,7 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
adaptive_threshold: FloatProperty(
name="Adaptive Sampling Threshold",
- description="Noise level step to stop sampling at, lower values reduce noise the cost of render time. Zero for automatic setting based on number of AA samples",
+ description="Noise level step to stop sampling at, lower values reduce noise at the cost of render time. Zero for automatic setting based on number of AA samples",
min=0.0, max=1.0,
default=0.0,
precision=4,
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index ecadc78cbbf..ebba6981502 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -1038,23 +1038,6 @@ static void create_subd_mesh(Scene *scene,
/* Sync */
-static BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob)
-{
- if (b_ob.modifiers.length() > 0) {
- BL::Modifier b_mod = b_ob.modifiers[b_ob.modifiers.length() - 1];
-
- if (b_mod.type() == BL::Modifier::type_MESH_SEQUENCE_CACHE) {
- BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(b_mod);
-
- if (MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
- return mesh_cache;
- }
- }
- }
-
- return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
-}
-
/* Check whether some of "built-in" motion-related attributes are needed to be exported (includes
* things like velocity from cache modifier, fluid simulation).
*
@@ -1095,7 +1078,7 @@ static void sync_mesh_cached_velocities(BL::Object &b_ob, Scene *scene, Mesh *me
return;
}
- BL::MeshSequenceCacheModifier b_mesh_cache = object_mesh_cache_find(b_ob);
+ BL::MeshSequenceCacheModifier b_mesh_cache = object_mesh_cache_find(b_ob, true, nullptr);
if (!b_mesh_cache) {
return;
@@ -1258,7 +1241,7 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph,
}
/* Cached motion blur already exported. */
- BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob);
+ BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob, true, nullptr);
if (mesh_cache) {
return;
}
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 4711e0cbe76..a7eae421b55 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include "render/alembic.h"
#include "render/camera.h"
#include "render/graph.h"
#include "render/integrator.h"
@@ -484,6 +485,71 @@ bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance
/* Object Loop */
+void BlenderSync::sync_procedural(BL::Object &b_ob,
+ BL::MeshSequenceCacheModifier &b_mesh_cache,
+ bool has_subdivision_modifier)
+{
+#ifdef WITH_ALEMBIC
+ BL::CacheFile cache_file = b_mesh_cache.cache_file();
+ void *cache_file_key = cache_file.ptr.data;
+
+ AlembicProcedural *procedural = static_cast<AlembicProcedural *>(
+ procedural_map.find(cache_file_key));
+
+ if (procedural == nullptr) {
+ procedural = scene->create_node<AlembicProcedural>();
+ procedural_map.add(cache_file_key, procedural);
+ }
+ else {
+ procedural_map.used(procedural);
+ }
+
+ float current_frame = b_scene.frame_current();
+ if (cache_file.override_frame()) {
+ current_frame = cache_file.frame();
+ }
+
+ if (!cache_file.override_frame()) {
+ procedural->set_start_frame(b_scene.frame_start());
+ procedural->set_end_frame(b_scene.frame_end());
+ }
+
+ procedural->set_frame(current_frame);
+ procedural->set_frame_rate(b_scene.render().fps() / b_scene.render().fps_base());
+ procedural->set_frame_offset(cache_file.frame_offset());
+
+ string absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
+ procedural->set_filepath(ustring(absolute_path));
+
+ procedural->set_scale(cache_file.scale());
+
+ procedural->set_use_prefetch(cache_file.use_prefetch());
+ procedural->set_prefetch_cache_size(cache_file.prefetch_cache_size());
+
+ /* create or update existing AlembicObjects */
+ ustring object_path = ustring(b_mesh_cache.object_path());
+
+ AlembicObject *abc_object = procedural->get_or_create_object(object_path);
+
+ array<Node *> used_shaders = find_used_shaders(b_ob);
+ abc_object->set_used_shaders(used_shaders);
+
+ PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");
+ const float subd_dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
+ abc_object->set_subd_dicing_rate(subd_dicing_rate);
+ abc_object->set_subd_max_level(max_subdivisions);
+
+ abc_object->set_ignore_subdivision(!has_subdivision_modifier);
+
+ if (abc_object->is_modified() || procedural->is_modified()) {
+ procedural->tag_update(scene);
+ }
+#else
+ (void)b_ob;
+ (void)b_mesh_cache;
+#endif
+}
+
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
float motion_time)
@@ -499,6 +565,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
light_map.pre_sync();
geometry_map.pre_sync();
object_map.pre_sync();
+ procedural_map.pre_sync();
particle_system_map.pre_sync();
motion_times.clear();
}
@@ -539,15 +606,39 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
/* Object itself. */
if (b_instance.show_self()) {
- sync_object(b_depsgraph,
- b_view_layer,
- b_instance,
- motion_time,
- false,
- show_lights,
- culling,
- &use_portal,
- sync_hair ? NULL : &geom_task_pool);
+#ifdef WITH_ALEMBIC
+ bool use_procedural = false;
+ bool has_subdivision_modifier = false;
+ BL::MeshSequenceCacheModifier b_mesh_cache(PointerRNA_NULL);
+
+ /* Experimental as Blender does not have good support for procedurals at the moment, also
+ * only available in preview renders since currently do not have a good cache policy, the
+ * data being loaded at once for all the frames. */
+ if (experimental && b_v3d) {
+ b_mesh_cache = object_mesh_cache_find(b_ob, false, &has_subdivision_modifier);
+ use_procedural = b_mesh_cache && b_mesh_cache.cache_file().use_render_procedural();
+ }
+
+ if (use_procedural) {
+ /* Skip in the motion case, as generating motion blur data will be handled in the
+ * procedural. */
+ if (!motion) {
+ sync_procedural(b_ob, b_mesh_cache, has_subdivision_modifier);
+ }
+ }
+ else
+#endif
+ {
+ sync_object(b_depsgraph,
+ b_view_layer,
+ b_instance,
+ motion_time,
+ false,
+ show_lights,
+ culling,
+ &use_portal,
+ sync_hair ? NULL : &geom_task_pool);
+ }
}
/* Particle hair as separate object. */
@@ -580,6 +671,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
object_map.post_sync();
geometry_map.post_sync();
particle_system_map.post_sync();
+ procedural_map.post_sync();
}
if (motion)
diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp
index ae43dae4dc1..206ee24a093 100644
--- a/intern/cycles/blender/blender_particles.cpp
+++ b/intern/cycles/blender/blender_particles.cpp
@@ -71,7 +71,7 @@ bool BlenderSync::sync_dupli_particle(BL::Object &b_ob,
Particle pa;
pa.index = persistent_id[0];
- pa.age = b_scene.frame_current() - b_pa.birth_time();
+ pa.age = b_scene.frame_current_final() - b_pa.birth_time();
pa.lifetime = b_pa.lifetime();
pa.location = get_float3(b_pa.location());
pa.rotation = get_float4(b_pa.rotation());
diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp
index fd145effde7..6e06b6a468f 100644
--- a/intern/cycles/blender/blender_python.cpp
+++ b/intern/cycles/blender/blender_python.cpp
@@ -487,6 +487,24 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
if (param->varlenarray || param->isstruct || param->type.arraylen > 1)
continue;
+ /* Read metadata. */
+ bool is_bool_param = false;
+ ustring param_label = param->name;
+
+ for (const OSL::OSLQuery::Parameter &metadata : param->metadata) {
+ if (metadata.type == TypeDesc::STRING) {
+ if (metadata.name == "widget") {
+ /* Boolean socket. */
+ if (metadata.sdefault[0] == "boolean" || metadata.sdefault[0] == "checkBox") {
+ is_bool_param = true;
+ }
+ }
+ else if (metadata.name == "label") {
+ /* Socket label. */
+ param_label = metadata.sdefault[0];
+ }
+ }
+ }
/* determine socket type */
string socket_type;
BL::NodeSocket::type_enum data_type = BL::NodeSocket::type_VALUE;
@@ -494,6 +512,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
float default_float = 0.0f;
int default_int = 0;
string default_string = "";
+ bool default_boolean = false;
if (param->isclosure) {
socket_type = "NodeSocketShader";
@@ -523,10 +542,19 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
}
else if (param->type.aggregate == TypeDesc::SCALAR) {
if (param->type.basetype == TypeDesc::INT) {
- socket_type = "NodeSocketInt";
- data_type = BL::NodeSocket::type_INT;
- if (param->validdefault)
- default_int = param->idefault[0];
+ if (is_bool_param) {
+ socket_type = "NodeSocketBool";
+ data_type = BL::NodeSocket::type_BOOLEAN;
+ if (param->validdefault) {
+ default_boolean = (bool)param->idefault[0];
+ }
+ }
+ else {
+ socket_type = "NodeSocketInt";
+ data_type = BL::NodeSocket::type_INT;
+ if (param->validdefault)
+ default_int = param->idefault[0];
+ }
}
else if (param->type.basetype == TypeDesc::FLOAT) {
socket_type = "NodeSocketFloat";
@@ -546,33 +574,57 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
else
continue;
- /* find socket socket */
- BL::NodeSocket b_sock(PointerRNA_NULL);
+ /* Update existing socket. */
+ bool found_existing = false;
if (param->isoutput) {
- b_sock = b_node.outputs[param->name.string()];
- /* remove if type no longer matches */
- if (b_sock && b_sock.bl_idname() != socket_type) {
- b_node.outputs.remove(b_data, b_sock);
- b_sock = BL::NodeSocket(PointerRNA_NULL);
+ for (BL::NodeSocket &b_sock : b_node.outputs) {
+ if (b_sock.identifier() == param->name) {
+ if (b_sock.bl_idname() != socket_type) {
+ /* Remove if type no longer matches. */
+ b_node.outputs.remove(b_data, b_sock);
+ }
+ else {
+ /* Reuse and update label. */
+ if (b_sock.name() != param_label) {
+ b_sock.name(param_label.string());
+ }
+ used_sockets.insert(b_sock.ptr.data);
+ found_existing = true;
+ }
+ break;
+ }
}
}
else {
- b_sock = b_node.inputs[param->name.string()];
- /* remove if type no longer matches */
- if (b_sock && b_sock.bl_idname() != socket_type) {
- b_node.inputs.remove(b_data, b_sock);
- b_sock = BL::NodeSocket(PointerRNA_NULL);
+ for (BL::NodeSocket &b_sock : b_node.inputs) {
+ if (b_sock.identifier() == param->name) {
+ if (b_sock.bl_idname() != socket_type) {
+ /* Remove if type no longer matches. */
+ b_node.inputs.remove(b_data, b_sock);
+ }
+ else {
+ /* Reuse and update label. */
+ if (b_sock.name() != param_label) {
+ b_sock.name(param_label.string());
+ }
+ used_sockets.insert(b_sock.ptr.data);
+ found_existing = true;
+ }
+ break;
+ }
}
}
- if (!b_sock) {
- /* create new socket */
- if (param->isoutput)
- b_sock = b_node.outputs.create(
- b_data, socket_type.c_str(), param->name.c_str(), param->name.c_str());
- else
- b_sock = b_node.inputs.create(
- b_data, socket_type.c_str(), param->name.c_str(), param->name.c_str());
+ if (!found_existing) {
+ /* Create new socket. */
+ BL::NodeSocket b_sock = (param->isoutput) ? b_node.outputs.create(b_data,
+ socket_type.c_str(),
+ param_label.c_str(),
+ param->name.c_str()) :
+ b_node.inputs.create(b_data,
+ socket_type.c_str(),
+ param_label.c_str(),
+ param->name.c_str());
/* set default value */
if (data_type == BL::NodeSocket::type_VALUE) {
@@ -590,9 +642,12 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
else if (data_type == BL::NodeSocket::type_STRING) {
set_string(b_sock.ptr, "default_value", default_string);
}
- }
+ else if (data_type == BL::NodeSocket::type_BOOLEAN) {
+ set_boolean(b_sock.ptr, "default_value", default_boolean);
+ }
- used_sockets.insert(b_sock.ptr.data);
+ used_sockets.insert(b_sock.ptr.data);
+ }
}
/* remove unused parameters */
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 7f129310736..de7b2761d00 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -149,7 +149,7 @@ BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_r
static BL::NodeSocket get_node_output(BL::Node &b_node, const string &name)
{
for (BL::NodeSocket &b_out : b_node.outputs) {
- if (b_out.name() == name) {
+ if (b_out.identifier() == name) {
return b_out;
}
}
@@ -215,7 +215,12 @@ static void set_default_value(ShaderInput *input,
break;
}
case SocketType::INT: {
- node->set(socket, get_int(b_sock.ptr, "default_value"));
+ if (b_sock.type() == BL::NodeSocket::type_BOOLEAN) {
+ node->set(socket, get_boolean(b_sock.ptr, "default_value"));
+ }
+ else {
+ node->set(socket, get_int(b_sock.ptr, "default_value"));
+ }
break;
}
case SocketType::COLOR: {
@@ -1002,71 +1007,59 @@ static bool node_use_modified_socket_name(ShaderNode *node)
return true;
}
-static ShaderInput *node_find_input_by_name(ShaderNode *node,
- BL::Node &b_node,
- BL::NodeSocket &b_socket)
+static ShaderInput *node_find_input_by_name(ShaderNode *node, BL::NodeSocket &b_socket)
{
- string name = b_socket.name();
+ string name = b_socket.identifier();
+ ShaderInput *input = node->input(name.c_str());
- if (node_use_modified_socket_name(node)) {
- bool found = false;
- int counter = 0, total = 0;
-
- for (BL::NodeSocket &b_input : b_node.inputs) {
- if (b_input.name() == name) {
- if (!found) {
- counter++;
- }
- total++;
+ if (!input && node_use_modified_socket_name(node)) {
+ /* Different internal name for shader. */
+ if (string_startswith(name, "Shader")) {
+ string_replace(name, "Shader", "Closure");
+ }
+ input = node->input(name.c_str());
+
+ if (!input) {
+ /* Different internal numbering of two sockets with same name.
+ * Note that the Blender convention for unique socket names changed
+ * from . to _ at some point, so we check both to handle old files. */
+ if (string_endswith(name, "_001")) {
+ string_replace(name, "_001", "2");
+ }
+ else if (string_endswith(name, ".001")) {
+ string_replace(name, ".001", "2");
+ }
+ else if (string_endswith(name, "_002")) {
+ string_replace(name, "_002", "3");
+ }
+ else if (string_endswith(name, ".002")) {
+ string_replace(name, ".002", "3");
+ }
+ else {
+ name += "1";
}
- if (b_input.ptr.data == b_socket.ptr.data)
- found = true;
+ input = node->input(name.c_str());
}
-
- /* rename if needed */
- if (name == "Shader")
- name = "Closure";
-
- if (total > 1)
- name = string_printf("%s%d", name.c_str(), counter);
}
- return node->input(name.c_str());
+ return input;
}
-static ShaderOutput *node_find_output_by_name(ShaderNode *node,
- BL::Node &b_node,
- BL::NodeSocket &b_socket)
+static ShaderOutput *node_find_output_by_name(ShaderNode *node, BL::NodeSocket &b_socket)
{
- string name = b_socket.name();
-
- if (node_use_modified_socket_name(node)) {
- bool found = false;
- int counter = 0, total = 0;
-
- for (BL::NodeSocket &b_output : b_node.outputs) {
- if (b_output.name() == name) {
- if (!found) {
- counter++;
- }
- total++;
- }
+ string name = b_socket.identifier();
+ ShaderOutput *output = node->output(name.c_str());
- if (b_output.ptr.data == b_socket.ptr.data) {
- found = true;
- }
- }
-
- /* rename if needed */
- if (name == "Shader")
+ if (!output && node_use_modified_socket_name(node)) {
+ /* Different internal name for shader. */
+ if (name == "Shader") {
name = "Closure";
-
- if (total > 1)
- name = string_printf("%s%d", name.c_str(), counter);
+ output = node->output(name.c_str());
+ }
}
- return node->output(name.c_str());
+ return output;
}
static void add_nodes(Scene *scene,
@@ -1209,7 +1202,7 @@ static void add_nodes(Scene *scene,
if (node) {
/* map node sockets for linking */
for (BL::NodeSocket &b_input : b_node.inputs) {
- ShaderInput *input = node_find_input_by_name(node, b_node, b_input);
+ ShaderInput *input = node_find_input_by_name(node, b_input);
if (!input) {
/* XXX should not happen, report error? */
continue;
@@ -1219,7 +1212,7 @@ static void add_nodes(Scene *scene,
set_default_value(input, b_input, b_data, b_ntree);
}
for (BL::NodeSocket &b_output : b_node.outputs) {
- ShaderOutput *output = node_find_output_by_name(node, b_node, b_output);
+ ShaderOutput *output = node_find_output_by_name(node, b_output);
if (!output) {
/* XXX should not happen, report error? */
continue;
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 298353203ad..26d64b7bf85 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -59,6 +59,7 @@ BlenderSync::BlenderSync(BL::RenderEngine &b_engine,
b_scene(b_scene),
shader_map(scene),
object_map(scene),
+ procedural_map(scene),
geometry_map(scene),
light_map(scene),
particle_system_map(scene),
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 949482b1f9c..44322dda6b9 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -151,6 +151,10 @@ class BlenderSync {
TaskPool *geom_task_pool);
void sync_object_motion_init(BL::Object &b_parent, BL::Object &b_ob, Object *object);
+ void sync_procedural(BL::Object &b_ob,
+ BL::MeshSequenceCacheModifier &b_mesh_cache,
+ bool has_subdivision);
+
bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
/* Volume */
@@ -221,6 +225,7 @@ class BlenderSync {
id_map<void *, Shader> shader_map;
id_map<ObjectKey, Object> object_map;
+ id_map<void *, Procedural> procedural_map;
id_map<GeometryKey, Geometry> geometry_map;
id_map<ObjectKey, Light> light_map;
id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 2b2188b023d..f6824f31b7b 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -145,7 +145,7 @@ static inline void curvemapping_minmax(/*const*/ BL::CurveMapping &cumap,
float *min_x,
float *max_x)
{
- /* const int num_curves = cumap.curves.length(); */ /* Gives linking error so far. */
+ // const int num_curves = cumap.curves.length(); /* Gives linking error so far. */
const int num_curves = rgb_curve ? 4 : 3;
*min_x = FLT_MAX;
*max_x = -FLT_MAX;
@@ -246,7 +246,11 @@ static inline string image_user_file_path(BL::ImageUser &iuser,
string filepath_str = string(filepath);
if (load_tiled && ima.source() == BL::Image::source_TILED) {
- string_replace(filepath_str, "1001", "<UDIM>");
+ string udim;
+ if (ima.tiles.length() > 0) {
+ udim = to_string(ima.tiles[0].number());
+ }
+ string_replace(filepath_str, udim, "<UDIM>");
}
return filepath_str;
}
@@ -420,7 +424,7 @@ static inline void set_enum(PointerRNA &ptr, const char *name, const string &ide
static inline string get_string(PointerRNA &ptr, const char *name)
{
char cstrbuf[1024];
- char *cstr = RNA_string_get_alloc(&ptr, name, cstrbuf, sizeof(cstrbuf));
+ char *cstr = RNA_string_get_alloc(&ptr, name, cstrbuf, sizeof(cstrbuf), NULL);
string str(cstr);
if (cstr != cstrbuf)
MEM_freeN(cstr);
@@ -568,6 +572,45 @@ static inline BL::FluidDomainSettings object_fluid_gas_domain_find(BL::Object &b
return BL::FluidDomainSettings(PointerRNA_NULL);
}
+static inline BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob,
+ bool check_velocity,
+ bool *has_subdivision_modifier)
+{
+ for (int i = b_ob.modifiers.length() - 1; i >= 0; --i) {
+ BL::Modifier b_mod = b_ob.modifiers[i];
+
+ if (b_mod.type() == BL::Modifier::type_MESH_SEQUENCE_CACHE) {
+ BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(b_mod);
+
+ if (check_velocity) {
+ if (!MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+ }
+ }
+
+ return mesh_cache;
+ }
+
+ /* Skip possible particles system modifiers as they do not modify the geometry. */
+ if (b_mod.type() == BL::Modifier::type_PARTICLE_SYSTEM) {
+ continue;
+ }
+
+ /* Only skip the subsurf modifier if we are not checking for the mesh sequence cache modifier
+ * for motion blur. */
+ if (b_mod.type() == BL::Modifier::type_SUBSURF && !check_velocity) {
+ if (has_subdivision_modifier) {
+ *has_subdivision_modifier = true;
+ }
+ continue;
+ }
+
+ break;
+ }
+
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
static inline Mesh::SubdivisionType object_subdivision_type(BL::Object &b_ob,
bool preview,
bool experimental)
diff --git a/intern/cycles/kernel/closure/bsdf_principled_diffuse.h b/intern/cycles/kernel/closure/bsdf_principled_diffuse.h
index 43646aaeb5b..d5d012068ff 100644
--- a/intern/cycles/kernel/closure/bsdf_principled_diffuse.h
+++ b/intern/cycles/kernel/closure/bsdf_principled_diffuse.h
@@ -36,10 +36,10 @@ static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledDiffuseBsdf),
ccl_device float3 calculate_principled_diffuse_brdf(
const PrincipledDiffuseBsdf *bsdf, float3 N, float3 V, float3 L, float3 H, float *pdf)
{
- float NdotL = max(dot(N, L), 0.0f);
- float NdotV = max(dot(N, V), 0.0f);
+ float NdotL = dot(N, L);
+ float NdotV = dot(N, V);
- if (NdotL < 0 || NdotV < 0) {
+ if (NdotL <= 0 || NdotV <= 0) {
*pdf = 0.0f;
return make_float3(0.0f, 0.0f, 0.0f);
}
diff --git a/intern/cycles/kernel/geom/geom_triangle.h b/intern/cycles/kernel/geom/geom_triangle.h
index 208338a934b..ff7909ca425 100644
--- a/intern/cycles/kernel/geom/geom_triangle.h
+++ b/intern/cycles/kernel/geom/geom_triangle.h
@@ -107,6 +107,27 @@ triangle_smooth_normal(KernelGlobals *kg, float3 Ng, int prim, float u, float v)
return is_zero(N) ? Ng : N;
}
+ccl_device_inline float3 triangle_smooth_normal_unnormalized(
+ KernelGlobals *kg, ShaderData *sd, float3 Ng, int prim, float u, float v)
+{
+ /* load triangle vertices */
+ const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
+ float3 n0 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.x));
+ float3 n1 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.y));
+ float3 n2 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.z));
+
+ /* ensure that the normals are in object space */
+ if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) {
+ object_inverse_normal_transform(kg, sd, &n0);
+ object_inverse_normal_transform(kg, sd, &n1);
+ object_inverse_normal_transform(kg, sd, &n2);
+ }
+
+ float3 N = (1.0f - u - v) * n2 + u * n0 + v * n1;
+
+ return is_zero(N) ? Ng : N;
+}
+
/* Ray differentials on triangle */
ccl_device_inline void triangle_dPdudv(KernelGlobals *kg,
diff --git a/intern/cycles/kernel/shaders/node_texture_coordinate.osl b/intern/cycles/kernel/shaders/node_texture_coordinate.osl
index ac05e984af2..9cdb925dbfa 100644
--- a/intern/cycles/kernel/shaders/node_texture_coordinate.osl
+++ b/intern/cycles/kernel/shaders/node_texture_coordinate.osl
@@ -58,7 +58,9 @@ shader node_texture_coordinate(
getattribute("geom:uv", UV);
}
else {
- getattribute("geom:generated", Generated);
+ if (!getattribute("geom:generated", Generated)) {
+ Generated = transform("object", P);
+ }
getattribute("geom:uv", UV);
}
diff --git a/intern/cycles/kernel/svm/svm_attribute.h b/intern/cycles/kernel/svm/svm_attribute.h
index f598bfb8f8f..62740824ad1 100644
--- a/intern/cycles/kernel/svm/svm_attribute.h
+++ b/intern/cycles/kernel/svm/svm_attribute.h
@@ -72,6 +72,22 @@ ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, u
}
#endif
+ if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
+ /* No generated attribute, fall back to object coordinates. */
+ float3 f = sd->P;
+ object_inverse_position_transform(kg, sd, &f);
+ if (type == NODE_ATTR_OUTPUT_FLOAT) {
+ stack_store_float(stack, out_offset, average(f));
+ }
+ else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
+ stack_store_float3(stack, out_offset, f);
+ }
+ else {
+ stack_store_float(stack, out_offset, 1.0f);
+ }
+ return;
+ }
+
/* Surface. */
if (desc.type == NODE_ATTR_FLOAT) {
float f = primitive_surface_attribute_float(kg, sd, desc, NULL, NULL);
@@ -145,6 +161,22 @@ ccl_device void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float *
}
#endif
+ if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
+ /* No generated attribute, fall back to object coordinates. */
+ float3 f = sd->P + sd->dP.dx;
+ object_inverse_position_transform(kg, sd, &f);
+ if (type == NODE_ATTR_OUTPUT_FLOAT) {
+ stack_store_float(stack, out_offset, average(f));
+ }
+ else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
+ stack_store_float3(stack, out_offset, f);
+ }
+ else {
+ stack_store_float(stack, out_offset, 1.0f);
+ }
+ return;
+ }
+
/* Surface */
if (desc.type == NODE_ATTR_FLOAT) {
float dx;
@@ -222,6 +254,22 @@ ccl_device void svm_node_attr_bump_dy(KernelGlobals *kg, ShaderData *sd, float *
}
#endif
+ if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
+ /* No generated attribute, fall back to object coordinates. */
+ float3 f = sd->P + sd->dP.dy;
+ object_inverse_position_transform(kg, sd, &f);
+ if (type == NODE_ATTR_OUTPUT_FLOAT) {
+ stack_store_float(stack, out_offset, average(f));
+ }
+ else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
+ stack_store_float3(stack, out_offset, f);
+ }
+ else {
+ stack_store_float(stack, out_offset, 1.0f);
+ }
+ return;
+ }
+
/* Surface */
if (desc.type == NODE_ATTR_FLOAT) {
float dy;
diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h
index fc46bb584be..46600551cc4 100644
--- a/intern/cycles/kernel/svm/svm_tex_coord.h
+++ b/intern/cycles/kernel/svm/svm_tex_coord.h
@@ -267,7 +267,7 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
if (space == NODE_NORMAL_MAP_TANGENT) {
/* tangent space */
- if (sd->object == OBJECT_NONE) {
+ if (sd->object == OBJECT_NONE || (sd->type & PRIMITIVE_ALL_TRIANGLE) == 0) {
/* Fallback to unperturbed normal. */
stack_store_float3(stack, normal_offset, sd->N);
return;
@@ -276,10 +276,8 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
/* first try to get tangent attribute */
const AttributeDescriptor attr = find_attribute(kg, sd, node.z);
const AttributeDescriptor attr_sign = find_attribute(kg, sd, node.w);
- const AttributeDescriptor attr_normal = find_attribute(kg, sd, ATTR_STD_VERTEX_NORMAL);
- if (attr.offset == ATTR_STD_NOT_FOUND || attr_sign.offset == ATTR_STD_NOT_FOUND ||
- attr_normal.offset == ATTR_STD_NOT_FOUND) {
+ if (attr.offset == ATTR_STD_NOT_FOUND || attr_sign.offset == ATTR_STD_NOT_FOUND) {
/* Fallback to unperturbed normal. */
stack_store_float3(stack, normal_offset, sd->N);
return;
@@ -291,7 +289,7 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
float3 normal;
if (sd->shader & SHADER_SMOOTH_NORMAL) {
- normal = primitive_surface_attribute_float3(kg, sd, attr_normal, NULL, NULL);
+ normal = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v);
}
else {
normal = sd->Ng;
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
index 6713531c9b0..69bc0712674 100644
--- a/intern/cycles/render/alembic.cpp
+++ b/intern/cycles/render/alembic.cpp
@@ -25,6 +25,7 @@
#include "render/shader.h"
#include "util/util_foreach.h"
+#include "util/util_logging.h"
#include "util/util_progress.h"
#include "util/util_transform.h"
#include "util/util_vector.h"
@@ -211,6 +212,35 @@ void CachedData::set_time_sampling(TimeSampling time_sampling)
}
}
+size_t CachedData::memory_used() const
+{
+ size_t mem_used = 0;
+
+ mem_used += curve_first_key.memory_used();
+ mem_used += curve_keys.memory_used();
+ mem_used += curve_radius.memory_used();
+ mem_used += curve_shader.memory_used();
+ mem_used += num_ngons.memory_used();
+ mem_used += shader.memory_used();
+ mem_used += subd_creases_edge.memory_used();
+ mem_used += subd_creases_weight.memory_used();
+ mem_used += subd_face_corners.memory_used();
+ mem_used += subd_num_corners.memory_used();
+ mem_used += subd_ptex_offset.memory_used();
+ mem_used += subd_smooth.memory_used();
+ mem_used += subd_start_corner.memory_used();
+ mem_used += transforms.memory_used();
+ mem_used += triangles.memory_used();
+ mem_used += uv_loops.memory_used();
+ mem_used += vertices.memory_used();
+
+ for (const CachedAttribute &attr : attributes) {
+ mem_used += attr.data.memory_used();
+ }
+
+ return mem_used;
+}
+
static M44d convert_yup_zup(const M44d &mtx, float scale_mult)
{
V3d scale, shear, rotation, translation;
@@ -385,6 +415,8 @@ NODE_DEFINE(AlembicObject)
SOCKET_STRING(path, "Alembic Path", ustring());
SOCKET_NODE_ARRAY(used_shaders, "Used Shaders", Shader::get_node_type());
+ SOCKET_BOOLEAN(ignore_subdivision, "Ignore Subdivision", true);
+
SOCKET_INT(subd_max_level, "Max Subdivision Level", 1);
SOCKET_FLOAT(subd_dicing_rate, "Subdivision Dicing Rate", 1.0f);
@@ -470,6 +502,33 @@ void AlembicObject::load_data_in_cache(CachedData &cached_data,
cached_data.clear();
+ if (this->get_ignore_subdivision()) {
+ PolyMeshSchemaData data;
+ data.topology_variance = schema.getTopologyVariance();
+ data.time_sampling = schema.getTimeSampling();
+ data.positions = schema.getPositionsProperty();
+ data.face_counts = schema.getFaceCountsProperty();
+ data.face_indices = schema.getFaceIndicesProperty();
+ data.num_samples = schema.getNumSamples();
+ data.velocities = schema.getVelocitiesProperty();
+ data.shader_face_sets = parse_face_sets_for_shader_assignment(schema, get_used_shaders());
+
+ read_geometry_data(proc, cached_data, data, progress);
+
+ if (progress.get_cancel()) {
+ return;
+ }
+
+ /* Use the schema as the base compound property to also be able to look for top level
+ * properties. */
+ read_attributes(
+ proc, cached_data, schema, schema.getUVsParam(), get_requested_attributes(), progress);
+
+ cached_data.invalidate_last_loaded_time(true);
+ data_loaded = true;
+ return;
+ }
+
SubDSchemaData data;
data.time_sampling = schema.getTimeSampling();
data.num_samples = schema.getNumSamples();
@@ -677,6 +736,9 @@ NODE_DEFINE(AlembicProcedural)
SOCKET_NODE_ARRAY(objects, "Objects", AlembicObject::get_node_type());
+ SOCKET_BOOLEAN(use_prefetch, "Use Prefetch", true);
+ SOCKET_INT(prefetch_cache_size, "Prefetch Cache Size", 4096);
+
return type;
}
@@ -781,6 +843,43 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress)
const chrono_t frame_time = (chrono_t)((frame - frame_offset) / frame_rate);
+ /* Clear the subdivision caches as the data is stored differently. */
+ for (Node *node : objects) {
+ AlembicObject *object = static_cast<AlembicObject *>(node);
+
+ if (object->schema_type != AlembicObject::SUBD) {
+ continue;
+ }
+
+ if (object->ignore_subdivision_is_modified()) {
+ object->clear_cache();
+ }
+ }
+
+ if (use_prefetch_is_modified()) {
+ if (!use_prefetch) {
+ for (Node *node : objects) {
+ AlembicObject *object = static_cast<AlembicObject *>(node);
+ object->clear_cache();
+ }
+ }
+ }
+
+ if (prefetch_cache_size_is_modified()) {
+ /* Check whether the current memory usage fits in the new requested size,
+ * abort the render if it is any higher. */
+ size_t memory_used = 0ul;
+ for (Node *node : objects) {
+ AlembicObject *object = static_cast<AlembicObject *>(node);
+ memory_used += object->get_cached_data().memory_used();
+ }
+
+ if (memory_used > get_prefetch_cache_size_in_bytes()) {
+ progress.set_error("Error: Alembic Procedural memory limit reached");
+ return;
+ }
+ }
+
build_caches(progress);
foreach (Node *node, objects) {
@@ -959,14 +1058,6 @@ void AlembicProcedural::read_mesh(AlembicObject *abc_object, Abc::chrono_t frame
update_attributes(mesh->attributes, cached_data, frame_time);
- /* we don't yet support arbitrary attributes, for now add vertex
- * coordinates as generated coordinates if requested */
- if (mesh->need_attribute(scene_, ATTR_STD_GENERATED)) {
- Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED);
- memcpy(
- attr->data_float3(), mesh->get_verts().data(), sizeof(float3) * mesh->get_verts().size());
- }
-
if (mesh->is_modified()) {
bool need_rebuild = mesh->triangles_is_modified();
mesh->tag_update(scene_, need_rebuild);
@@ -975,13 +1066,13 @@ void AlembicProcedural::read_mesh(AlembicObject *abc_object, Abc::chrono_t frame
void AlembicProcedural::read_subd(AlembicObject *abc_object, Abc::chrono_t frame_time)
{
- CachedData &cached_data = abc_object->get_cached_data();
-
- if (abc_object->subd_max_level_is_modified() || abc_object->subd_dicing_rate_is_modified()) {
- /* need to reset the current data is something changed */
- cached_data.invalidate_last_loaded_time();
+ if (abc_object->get_ignore_subdivision()) {
+ read_mesh(abc_object, frame_time);
+ return;
}
+ CachedData &cached_data = abc_object->get_cached_data();
+
/* Update sockets. */
Object *object = abc_object->get_object();
@@ -996,6 +1087,11 @@ void AlembicProcedural::read_subd(AlembicObject *abc_object, Abc::chrono_t frame
return;
}
+ if (abc_object->subd_max_level_is_modified() || abc_object->subd_dicing_rate_is_modified()) {
+ /* need to reset the current data is something changed */
+ cached_data.invalidate_last_loaded_time();
+ }
+
Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
/* Make sure shader ids are also updated. */
@@ -1053,14 +1149,6 @@ void AlembicProcedural::read_subd(AlembicObject *abc_object, Abc::chrono_t frame
update_attributes(mesh->subd_attributes, cached_data, frame_time);
- /* we don't yet support arbitrary attributes, for now add vertex
- * coordinates as generated coordinates if requested */
- if (mesh->need_attribute(scene_, ATTR_STD_GENERATED)) {
- Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED);
- memcpy(
- attr->data_float3(), mesh->get_verts().data(), sizeof(float3) * mesh->get_verts().size());
- }
-
if (mesh->is_modified()) {
bool need_rebuild = (mesh->triangles_is_modified()) ||
(mesh->subd_num_corners_is_modified()) ||
@@ -1110,17 +1198,6 @@ void AlembicProcedural::read_curves(AlembicObject *abc_object, Abc::chrono_t fra
update_attributes(hair->attributes, cached_data, frame_time);
- /* we don't yet support arbitrary attributes, for now add first keys as generated coordinates if
- * requested */
- if (hair->need_attribute(scene_, ATTR_STD_GENERATED)) {
- Attribute *attr_generated = hair->attributes.add(ATTR_STD_GENERATED);
- float3 *generated = attr_generated->data_float3();
-
- for (size_t i = 0; i < hair->num_curves(); i++) {
- generated[i] = hair->get_curve_keys()[hair->get_curve(i).first_key];
- }
- }
-
const bool rebuild = (hair->curve_keys_is_modified() || hair->curve_radius_is_modified());
hair->tag_update(scene_, rebuild);
}
@@ -1280,6 +1357,8 @@ void AlembicProcedural::walk_hierarchy(
void AlembicProcedural::build_caches(Progress &progress)
{
+ size_t memory_used = 0;
+
for (Node *node : objects) {
AlembicObject *object = static_cast<AlembicObject *>(node);
@@ -1333,7 +1412,18 @@ void AlembicProcedural::build_caches(Progress &progress)
if (scale_is_modified() || object->get_cached_data().transforms.size() == 0) {
object->setup_transform_cache(object->get_cached_data(), scale);
}
+
+ memory_used += object->get_cached_data().memory_used();
+
+ if (use_prefetch) {
+ if (memory_used > get_prefetch_cache_size_in_bytes()) {
+ progress.set_error("Error: Alembic Procedural memory limit reached");
+ return;
+ }
+ }
}
+
+ VLOG(1) << "AlembicProcedural memory usage : " << string_human_readable_size(memory_used);
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/alembic.h b/intern/cycles/render/alembic.h
index 61c0e40fe4a..8e166a5ab04 100644
--- a/intern/cycles/render/alembic.h
+++ b/intern/cycles/render/alembic.h
@@ -272,6 +272,21 @@ template<typename T> class DataStore {
node->set(*socket, value);
}
+ size_t memory_used() const
+ {
+ if constexpr (is_array<T>::value) {
+ size_t mem_used = 0;
+
+ for (const T &array : data) {
+ mem_used += array.size() * sizeof(array[0]);
+ }
+
+ return mem_used;
+ }
+
+ return data.size() * sizeof(T);
+ }
+
private:
const TimeIndexPair &get_index_for_time(double time) const
{
@@ -332,6 +347,8 @@ struct CachedData {
void invalidate_last_loaded_time(bool attributes_only = false);
void set_time_sampling(Alembic::AbcCoreAbstract::TimeSampling time_sampling);
+
+ size_t memory_used() const;
};
/* Representation of an Alembic object for the AlembicProcedural.
@@ -353,6 +370,10 @@ class AlembicObject : public Node {
/* Shaders used for rendering. */
NODE_SOCKET_API_ARRAY(array<Node *>, used_shaders)
+ /* Treat this subdivision object as a regular polygon mesh, so no subdivision will be performed.
+ */
+ NODE_SOCKET_API(bool, ignore_subdivision)
+
/* Maximum number of subdivisions for ISubD objects. */
NODE_SOCKET_API(int, subd_max_level)
@@ -416,6 +437,11 @@ class AlembicObject : public Node {
return cached_data_.is_constant();
}
+ void clear_cache()
+ {
+ cached_data_.clear();
+ }
+
Object *object = nullptr;
bool data_loaded = false;
@@ -473,6 +499,13 @@ class AlembicProcedural : public Procedural {
* software. */
NODE_SOCKET_API(float, scale)
+ /* Cache controls */
+ NODE_SOCKET_API(bool, use_prefetch)
+
+ /* Memory limit for the cache, if the data does not fit within this limit, rendering is aborted.
+ */
+ NODE_SOCKET_API(int, prefetch_cache_size)
+
AlembicProcedural();
~AlembicProcedural();
@@ -522,6 +555,12 @@ class AlembicProcedural : public Procedural {
void read_subd(AlembicObject *abc_object, Alembic::AbcGeom::Abc::chrono_t frame_time);
void build_caches(Progress &progress);
+
+ size_t get_prefetch_cache_size_in_bytes() const
+ {
+ /* prefetch_cache_size is in megabytes, so convert to bytes. */
+ return static_cast<size_t>(prefetch_cache_size) * 1024 * 1024;
+ }
};
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/alembic_read.cpp b/intern/cycles/render/alembic_read.cpp
index c53ec668938..b105af63b44 100644
--- a/intern/cycles/render/alembic_read.cpp
+++ b/intern/cycles/render/alembic_read.cpp
@@ -44,9 +44,19 @@ static set<chrono_t> get_relevant_sample_times(AlembicProcedural *proc,
return result;
}
- // load the data for the entire animation
- const double start_frame = static_cast<double>(proc->get_start_frame());
- const double end_frame = static_cast<double>(proc->get_end_frame());
+ double start_frame;
+ double end_frame;
+
+ if (proc->get_use_prefetch()) {
+ // load the data for the entire animation
+ start_frame = static_cast<double>(proc->get_start_frame());
+ end_frame = static_cast<double>(proc->get_end_frame());
+ }
+ else {
+ // load the data for the current frame
+ start_frame = static_cast<double>(proc->get_frame());
+ end_frame = start_frame;
+ }
const double frame_rate = static_cast<double>(proc->get_frame_rate());
const double start_time = start_frame / frame_rate;
diff --git a/intern/cycles/render/geometry.cpp b/intern/cycles/render/geometry.cpp
index 6d084e82576..7ec1d2d9abb 100644
--- a/intern/cycles/render/geometry.cpp
+++ b/intern/cycles/render/geometry.cpp
@@ -788,6 +788,11 @@ void GeometryManager::device_update_attributes(Device *device,
foreach (AttributeRequest &req, attributes.requests) {
Attribute *attr = geom->attributes.find(req);
+ /* Vertex normals are stored in DeviceScene.tri_vnormal. */
+ if (attr && attr->std == ATTR_STD_VERTEX_NORMAL) {
+ continue;
+ }
+
update_attribute_element_size(geom,
attr,
ATTR_PRIM_GEOMETRY,
@@ -800,6 +805,11 @@ void GeometryManager::device_update_attributes(Device *device,
Mesh *mesh = static_cast<Mesh *>(geom);
Attribute *subd_attr = mesh->subd_attributes.find(req);
+ /* Vertex normals are stored in DeviceScene.tri_vnormal. */
+ if (subd_attr && subd_attr->std == ATTR_STD_VERTEX_NORMAL) {
+ continue;
+ }
+
update_attribute_element_size(mesh,
subd_attr,
ATTR_PRIM_SUBD,
@@ -854,6 +864,11 @@ void GeometryManager::device_update_attributes(Device *device,
Attribute *attr = geom->attributes.find(req);
if (attr) {
+ /* Vertex normals are stored in DeviceScene.tri_vnormal. */
+ if (attr->std == ATTR_STD_VERTEX_NORMAL) {
+ continue;
+ }
+
/* force a copy if we need to reallocate all the data */
attr->modified |= attributes_need_realloc[Attribute::kernel_type(*attr)];
}
@@ -877,6 +892,11 @@ void GeometryManager::device_update_attributes(Device *device,
Attribute *subd_attr = mesh->subd_attributes.find(req);
if (subd_attr) {
+ /* Vertex normals are stored in DeviceScene.tri_vnormal. */
+ if (subd_attr->std == ATTR_STD_VERTEX_NORMAL) {
+ continue;
+ }
+
/* force a copy if we need to reallocate all the data */
subd_attr->modified |= attributes_need_realloc[Attribute::kernel_type(*subd_attr)];
}
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index cdaa878e830..e9da48b624d 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -158,13 +158,13 @@ void ShaderNode::attributes(Shader *shader, AttributeRequestSet *attributes)
foreach (ShaderInput *input, inputs) {
if (!input->link) {
if (input->flags() & SocketType::LINK_TEXTURE_GENERATED) {
- if (shader->has_surface)
+ if (shader->has_surface_link())
attributes->add(ATTR_STD_GENERATED);
if (shader->has_volume)
attributes->add(ATTR_STD_GENERATED_TRANSFORM);
}
else if (input->flags() & SocketType::LINK_TEXTURE_UV) {
- if (shader->has_surface)
+ if (shader->has_surface_link())
attributes->add(ATTR_STD_UV);
}
}
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 42cba342bf8..795166bcf4c 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -350,7 +350,7 @@ void ImageTextureNode::attributes(Shader *shader, AttributeRequestSet *attribute
#ifdef WITH_PTEX
/* todo: avoid loading other texture coordinates when using ptex,
* and hide texture coordinate socket in the UI */
- if (shader->has_surface && string_endswith(filename, ".ptx")) {
+ if (shader->has_surface_link() && string_endswith(filename, ".ptx")) {
/* ptex */
attributes->add(ATTR_STD_PTEX_FACE_ID);
attributes->add(ATTR_STD_PTEX_UV);
@@ -552,7 +552,7 @@ ImageParams EnvironmentTextureNode::image_params() const
void EnvironmentTextureNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
#ifdef WITH_PTEX
- if (shader->has_surface && string_endswith(filename, ".ptx")) {
+ if (shader->has_surface_link() && string_endswith(filename, ".ptx")) {
/* ptex */
attributes->add(ATTR_STD_PTEX_FACE_ID);
attributes->add(ATTR_STD_PTEX_UV);
@@ -2319,7 +2319,7 @@ AnisotropicBsdfNode::AnisotropicBsdfNode() : BsdfNode(get_node_type())
void AnisotropicBsdfNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface) {
+ if (shader->has_surface_link()) {
ShaderInput *tangent_in = input("Tangent");
if (!tangent_in->link)
@@ -2843,7 +2843,7 @@ bool PrincipledBsdfNode::has_surface_bssrdf()
void PrincipledBsdfNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface) {
+ if (shader->has_surface_link()) {
ShaderInput *tangent_in = input("Tangent");
if (!tangent_in->link)
@@ -3684,7 +3684,7 @@ GeometryNode::GeometryNode() : ShaderNode(get_node_type())
void GeometryNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface) {
+ if (shader->has_surface_link()) {
if (!output("Tangent")->links.empty()) {
attributes->add(ATTR_STD_GENERATED);
}
@@ -3830,7 +3830,7 @@ TextureCoordinateNode::TextureCoordinateNode() : ShaderNode(get_node_type())
void TextureCoordinateNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface) {
+ if (shader->has_surface_link()) {
if (!from_dupli) {
if (!output("Generated")->links.empty())
attributes->add(ATTR_STD_GENERATED);
@@ -4388,7 +4388,7 @@ HairInfoNode::HairInfoNode() : ShaderNode(get_node_type())
void HairInfoNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface) {
+ if (shader->has_surface_link()) {
ShaderOutput *intercept_out = output("Intercept");
if (!intercept_out->links.empty())
@@ -6744,7 +6744,7 @@ NormalMapNode::NormalMapNode() : ShaderNode(get_node_type())
void NormalMapNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) {
+ if (shader->has_surface_link() && space == NODE_NORMAL_MAP_TANGENT) {
if (attribute.empty()) {
attributes->add(ATTR_STD_UV_TANGENT);
attributes->add(ATTR_STD_UV_TANGENT_SIGN);
@@ -6838,7 +6838,7 @@ TangentNode::TangentNode() : ShaderNode(get_node_type())
void TangentNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface) {
+ if (shader->has_surface_link()) {
if (direction_type == NODE_TANGENT_UVMAP) {
if (attribute.empty())
attributes->add(ATTR_STD_UV_TANGENT);
@@ -7021,7 +7021,7 @@ void VectorDisplacementNode::constant_fold(const ConstantFolder &folder)
void VectorDisplacementNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
- if (shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) {
+ if (shader->has_surface_link() && space == NODE_NORMAL_MAP_TANGENT) {
if (attribute.empty()) {
attributes->add(ATTR_STD_UV_TANGENT);
attributes->add(ATTR_STD_UV_TANGENT_SIGN);
diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h
index 50c8bed4669..c65cac351a4 100644
--- a/intern/cycles/render/shader.h
+++ b/intern/cycles/render/shader.h
@@ -154,6 +154,14 @@ class Shader : public Node {
void tag_update(Scene *scene);
void tag_used(Scene *scene);
+ /* Return true when either of the surface or displacement socket of the output node is linked.
+ * This should be used to ensure that surface attributes are also requested even when only the
+ * displacement socket is linked. */
+ bool has_surface_link() const
+ {
+ return has_surface || has_displacement;
+ }
+
bool need_update_geometry() const;
};
diff --git a/intern/ghost/GHOST_IEvent.h b/intern/ghost/GHOST_IEvent.h
index bcccd536ebd..239eea21088 100644
--- a/intern/ghost/GHOST_IEvent.h
+++ b/intern/ghost/GHOST_IEvent.h
@@ -32,10 +32,10 @@ class GHOST_IWindow;
/**
* Interface class for events received from GHOST.
* You should not need to inherit this class. The system will pass these events
- * to the GHOST_IEventConsumer::processEvent() method of event consumers.<br>
- * Use the getType() method to retrieve the type of event and the getData()
+ * to the #GHOST_IEventConsumer::processEvent() method of event consumers.<br>
+ * Use the #getType() method to retrieve the type of event and the #getData()
* method to get the event data out. Using the event type you can cast the
- * event data to the correct event dat structure.
+ * event data to the correct event data structure.
* \see GHOST_IEventConsumer#processEvent
* \see GHOST_TEventType
*/
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index fb19b9535ad..e46f712cb64 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -669,6 +669,14 @@ typedef struct {
void *exit_customdata;
} GHOST_XrSessionBeginInfo;
+/** Texture format for XR swapchain. */
+typedef enum GHOST_TXrSwapchainFormat {
+ GHOST_kXrSwapchainFormatRGBA8,
+ GHOST_kXrSwapchainFormatRGBA16,
+ GHOST_kXrSwapchainFormatRGBA16F,
+ GHOST_kXrSwapchainFormatRGB10_A2,
+} GHOST_TXrSwapchainFormat;
+
typedef struct GHOST_XrDrawViewInfo {
int ofsx, ofsy;
int width, height;
@@ -681,6 +689,7 @@ typedef struct GHOST_XrDrawViewInfo {
float angle_up, angle_down;
} fov;
+ GHOST_TXrSwapchainFormat swapchain_format;
/** Set if the buffer should be submitted with a SRGB transfer applied. */
char expects_srgb_buffer;
diff --git a/intern/ghost/intern/GHOST_ContextD3D.cpp b/intern/ghost/intern/GHOST_ContextD3D.cpp
index ad948578d53..73f6c12e100 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.cpp
+++ b/intern/ghost/intern/GHOST_ContextD3D.cpp
@@ -132,6 +132,7 @@ class GHOST_SharedOpenGLResource {
ID3D11DeviceContext *device_ctx,
unsigned int width,
unsigned int height,
+ DXGI_FORMAT format,
ID3D11RenderTargetView *render_target = nullptr)
: m_device(device), m_device_ctx(device_ctx), m_cur_width(width), m_cur_height(height)
{
@@ -144,7 +145,7 @@ class GHOST_SharedOpenGLResource {
texDesc.Width = width;
texDesc.Height = height;
- texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ texDesc.Format = format;
texDesc.SampleDesc.Count = 1;
texDesc.ArraySize = 1;
texDesc.MipLevels = 1;
@@ -321,7 +322,10 @@ class GHOST_SharedOpenGLResource {
};
GHOST_SharedOpenGLResource *GHOST_ContextD3D::createSharedOpenGLResource(
- unsigned int width, unsigned int height, ID3D11RenderTargetView *render_target)
+ unsigned int width,
+ unsigned int height,
+ DXGI_FORMAT format,
+ ID3D11RenderTargetView *render_target)
{
if (!(WGL_NV_DX_interop && WGL_NV_DX_interop2)) {
fprintf(stderr,
@@ -330,14 +334,15 @@ GHOST_SharedOpenGLResource *GHOST_ContextD3D::createSharedOpenGLResource(
return nullptr;
}
GHOST_SharedOpenGLResource *shared_res = new GHOST_SharedOpenGLResource(
- m_device, m_device_ctx, width, height, render_target);
+ m_device, m_device_ctx, width, height, format, render_target);
return shared_res;
}
GHOST_SharedOpenGLResource *GHOST_ContextD3D::createSharedOpenGLResource(unsigned int width,
- unsigned int height)
+ unsigned int height,
+ DXGI_FORMAT format)
{
- return createSharedOpenGLResource(width, height, nullptr);
+ return createSharedOpenGLResource(width, height, format, nullptr);
}
void GHOST_ContextD3D::disposeSharedOpenGLResource(GHOST_SharedOpenGLResource *shared_res)
diff --git a/intern/ghost/intern/GHOST_ContextD3D.h b/intern/ghost/intern/GHOST_ContextD3D.h
index 8b9537ca439..c18c9d3c286 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.h
+++ b/intern/ghost/intern/GHOST_ContextD3D.h
@@ -106,9 +106,13 @@ class GHOST_ContextD3D : public GHOST_Context {
}
class GHOST_SharedOpenGLResource *createSharedOpenGLResource(
- unsigned int width, unsigned int height, ID3D11RenderTargetView *render_target);
+ unsigned int width,
+ unsigned int height,
+ DXGI_FORMAT format,
+ ID3D11RenderTargetView *render_target);
class GHOST_SharedOpenGLResource *createSharedOpenGLResource(unsigned int width,
- unsigned int height);
+ unsigned int height,
+ DXGI_FORMAT format);
void disposeSharedOpenGLResource(class GHOST_SharedOpenGLResource *shared_res);
GHOST_TSuccess blitFromOpenGLContext(class GHOST_SharedOpenGLResource *shared_res,
unsigned int width,
diff --git a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
index a7339158dc4..bfdf0cac633 100644
--- a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
+++ b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
@@ -60,6 +60,7 @@ class GHOST_IXrGraphicsBinding {
std::string *r_requirement_info) const = 0;
virtual void initFromGhostContext(class GHOST_Context &ghost_ctx) = 0;
virtual std::optional<int64_t> chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
+ GHOST_TXrSwapchainFormat &r_format,
bool &r_is_rgb_format) const = 0;
virtual std::vector<XrSwapchainImageBaseHeader *> createSwapchainImages(
uint32_t image_count) = 0;
diff --git a/intern/ghost/intern/GHOST_ImeWin32.cpp b/intern/ghost/intern/GHOST_ImeWin32.cpp
index 343f4d68078..47b5f5688df 100644
--- a/intern/ghost/intern/GHOST_ImeWin32.cpp
+++ b/intern/ghost/intern/GHOST_ImeWin32.cpp
@@ -30,9 +30,15 @@
# include "GHOST_WindowWin32.h"
# include "utfconv.h"
+/* ISO_639-1 2-Letter Abbreviations. */
+# define IMELANG_ENGLISH "en"
+# define IMELANG_CHINESE "zh"
+# define IMELANG_JAPANESE "ja"
+# define IMELANG_KOREAN "ko"
+
GHOST_ImeWin32::GHOST_ImeWin32()
: is_composing_(false),
- input_language_id_(LANG_USER_DEFAULT),
+ language_(IMELANG_ENGLISH),
conversion_modes_(IME_CMODE_ALPHANUMERIC),
sentence_mode_(IME_SMODE_NONE),
system_caret_(false),
@@ -48,16 +54,21 @@ GHOST_ImeWin32::~GHOST_ImeWin32()
void GHOST_ImeWin32::UpdateInputLanguage()
{
- /**
- * Store the current input language.
- */
- HKL input_locale = ::GetKeyboardLayout(0);
- input_language_id_ = LOWORD(input_locale);
+ /* Get the current input locale full name. */
+ WCHAR locale[LOCALE_NAME_MAX_LENGTH];
+ LCIDToLocaleName(
+ MAKELCID(LOWORD(::GetKeyboardLayout(0)), SORT_DEFAULT), locale, LOCALE_NAME_MAX_LENGTH, 0);
+ /* Get the 2-letter ISO-63901 abbreviation of the input locale name. */
+ WCHAR language_u16[W32_ISO639_LEN];
+ GetLocaleInfoEx(locale, LOCALE_SISO639LANGNAME, language_u16, W32_ISO639_LEN);
+ /* Store this as a UTF-8 string. */
+ WideCharToMultiByte(
+ CP_UTF8, 0, language_u16, W32_ISO639_LEN, language_, W32_ISO639_LEN, NULL, NULL);
}
-WORD GHOST_ImeWin32::GetInputLanguage()
+BOOL GHOST_ImeWin32::IsLanguage(const char name[W32_ISO639_LEN])
{
- return input_language_id_;
+ return (strcmp(name, language_) == 0);
}
void GHOST_ImeWin32::UpdateConversionStatus(HWND window_handle)
@@ -92,21 +103,11 @@ bool GHOST_ImeWin32::IsImeKeyEvent(char ascii)
if ((ascii >= 'A' && ascii <= 'Z') || (ascii >= 'a' && ascii <= 'z')) {
return true;
}
- switch (PRIMARYLANGID(GetInputLanguage())) {
- /* In Japanese, all symbolic characters are also processed by IME. */
- case LANG_JAPANESE: {
- if (ascii >= ' ' && ascii <= '~') {
- return true;
- }
- break;
- }
- /* In Chinese, some symbolic characters are also processed by IME. */
- case LANG_CHINESE: {
- if (ascii && strchr("!\"$'(),.:;<>?[\\]^_`", ascii)) {
- return true;
- }
- break;
- }
+ if (IsLanguage(IMELANG_JAPANESE) && (ascii >= ' ' && ascii <= '~')) {
+ return true;
+ }
+ else if (IsLanguage(IMELANG_CHINESE) && ascii && strchr("!\"$'(),.:;<>?[\\]^_`", ascii)) {
+ return true;
}
}
return false;
@@ -126,13 +127,8 @@ void GHOST_ImeWin32::CreateImeWindow(HWND window_handle)
* Since some third-party Japanese IME also uses ::GetCaretPos() to determine
* their window position, we also create a caret for Japanese IMEs.
*/
- if (PRIMARYLANGID(input_language_id_) == LANG_CHINESE ||
- PRIMARYLANGID(input_language_id_) == LANG_JAPANESE) {
- if (!system_caret_) {
- if (::CreateCaret(window_handle, NULL, 1, 1)) {
- system_caret_ = true;
- }
- }
+ if (!system_caret_ && (IsLanguage(IMELANG_CHINESE) || IsLanguage(IMELANG_JAPANESE))) {
+ system_caret_ = ::CreateCaret(window_handle, NULL, 1, 1);
}
/* Restore the positions of the IME windows. */
UpdateImeWindow(window_handle);
@@ -185,16 +181,9 @@ void GHOST_ImeWin32::MoveImeWindow(HWND window_handle, HIMC imm_context)
CANDIDATEFORM candidate_position = {0, CFS_CANDIDATEPOS, {x, y}, {0, 0, 0, 0}};
::ImmSetCandidateWindow(imm_context, &candidate_position);
if (system_caret_) {
- switch (PRIMARYLANGID(input_language_id_)) {
- case LANG_JAPANESE:
- ::SetCaretPos(x, y + caret_rect_.getHeight());
- break;
- default:
- ::SetCaretPos(x, y);
- break;
- }
+ ::SetCaretPos(x, y);
}
- if (PRIMARYLANGID(input_language_id_) == LANG_KOREAN) {
+ if (IsLanguage(IMELANG_KOREAN)) {
/**
* Chinese IMEs and Japanese IMEs require the upper-left corner of
* the caret to move the position of their candidate windows.
@@ -284,83 +273,79 @@ void GHOST_ImeWin32::GetCaret(HIMC imm_context, LPARAM lparam, ImeComposition *c
*/
int target_start = -1;
int target_end = -1;
- switch (PRIMARYLANGID(input_language_id_)) {
- case LANG_KOREAN:
- if (lparam & CS_NOMOVECARET) {
- target_start = 0;
- target_end = 1;
+ if (IsLanguage(IMELANG_KOREAN)) {
+ if (lparam & CS_NOMOVECARET) {
+ target_start = 0;
+ target_end = 1;
+ }
+ }
+ else if (IsLanguage(IMELANG_CHINESE)) {
+ int clause_size = ImmGetCompositionStringW(imm_context, GCS_COMPCLAUSE, NULL, 0);
+ if (clause_size) {
+ static std::vector<unsigned long> clauses;
+ clause_size = clause_size / sizeof(clauses[0]);
+ clauses.resize(clause_size);
+ ImmGetCompositionStringW(
+ imm_context, GCS_COMPCLAUSE, &clauses[0], sizeof(clauses[0]) * clause_size);
+ if (composition->cursor_position == composition->ime_string.size()) {
+ target_start = clauses[clause_size - 2];
+ target_end = clauses[clause_size - 1];
}
- break;
- case LANG_CHINESE: {
- int clause_size = ImmGetCompositionStringW(imm_context, GCS_COMPCLAUSE, NULL, 0);
- if (clause_size) {
- static std::vector<unsigned long> clauses;
- clause_size = clause_size / sizeof(clauses[0]);
- clauses.resize(clause_size);
- ImmGetCompositionStringW(
- imm_context, GCS_COMPCLAUSE, &clauses[0], sizeof(clauses[0]) * clause_size);
- if (composition->cursor_position == composition->ime_string.size()) {
- target_start = clauses[clause_size - 2];
- target_end = clauses[clause_size - 1];
- }
- else {
- for (int i = 0; i < clause_size - 1; i++) {
- if (clauses[i] == composition->cursor_position) {
- target_start = clauses[i];
- target_end = clauses[i + 1];
- break;
- }
+ else {
+ for (int i = 0; i < clause_size - 1; i++) {
+ if (clauses[i] == composition->cursor_position) {
+ target_start = clauses[i];
+ target_end = clauses[i + 1];
+ break;
}
}
}
- else {
- if (composition->cursor_position != -1) {
- target_start = composition->cursor_position;
- target_end = composition->ime_string.size();
- }
+ }
+ else {
+ if (composition->cursor_position != -1) {
+ target_start = composition->cursor_position;
+ target_end = composition->ime_string.size();
}
- break;
}
- case LANG_JAPANESE:
-
- /**
- * For Japanese IMEs, the robustest way to retrieve the caret
- * is scanning the attribute of the latest composition string and
- * retrieving the beginning and the end of the target clause, i.e.
- * a clause being converted.
- */
- if (lparam & GCS_COMPATTR) {
- int attribute_size = ::ImmGetCompositionStringW(imm_context, GCS_COMPATTR, NULL, 0);
- if (attribute_size > 0) {
- char *attribute_data = new char[attribute_size];
- if (attribute_data) {
- ::ImmGetCompositionStringW(imm_context, GCS_COMPATTR, attribute_data, attribute_size);
- for (target_start = 0; target_start < attribute_size; ++target_start) {
- if (IsTargetAttribute(attribute_data[target_start]))
- break;
- }
- for (target_end = target_start; target_end < attribute_size; ++target_end) {
- if (!IsTargetAttribute(attribute_data[target_end]))
- break;
- }
- if (target_start == attribute_size) {
- /**
- * This composition clause does not contain any target clauses,
- * i.e. this clauses is an input clause.
- * We treat whole this clause as a target clause.
- */
- target_end = target_start;
- target_start = 0;
- }
- if (target_start != -1 && target_start < attribute_size &&
- attribute_data[target_start] == ATTR_TARGET_NOTCONVERTED) {
- composition->cursor_position = target_start;
- }
+ }
+ else if (IsLanguage(IMELANG_JAPANESE)) {
+ /**
+ * For Japanese IMEs, the robustest way to retrieve the caret
+ * is scanning the attribute of the latest composition string and
+ * retrieving the beginning and the end of the target clause, i.e.
+ * a clause being converted.
+ */
+ if (lparam & GCS_COMPATTR) {
+ int attribute_size = ::ImmGetCompositionStringW(imm_context, GCS_COMPATTR, NULL, 0);
+ if (attribute_size > 0) {
+ char *attribute_data = new char[attribute_size];
+ if (attribute_data) {
+ ::ImmGetCompositionStringW(imm_context, GCS_COMPATTR, attribute_data, attribute_size);
+ for (target_start = 0; target_start < attribute_size; ++target_start) {
+ if (IsTargetAttribute(attribute_data[target_start]))
+ break;
+ }
+ for (target_end = target_start; target_end < attribute_size; ++target_end) {
+ if (!IsTargetAttribute(attribute_data[target_end]))
+ break;
+ }
+ if (target_start == attribute_size) {
+ /**
+ * This composition clause does not contain any target clauses,
+ * i.e. this clauses is an input clause.
+ * We treat whole this clause as a target clause.
+ */
+ target_end = target_start;
+ target_start = 0;
+ }
+ if (target_start != -1 && target_start < attribute_size &&
+ attribute_data[target_start] == ATTR_TARGET_NOTCONVERTED) {
+ composition->cursor_position = target_start;
}
- delete[] attribute_data;
}
+ delete[] attribute_data;
}
- break;
+ }
}
composition->target_start = target_start;
composition->target_end = target_end;
diff --git a/intern/ghost/intern/GHOST_ImeWin32.h b/intern/ghost/intern/GHOST_ImeWin32.h
index d430a7d745d..ce0e4d64d53 100644
--- a/intern/ghost/intern/GHOST_ImeWin32.h
+++ b/intern/ghost/intern/GHOST_ImeWin32.h
@@ -36,6 +36,9 @@
# include "GHOST_Rect.h"
# include <vector>
+/* MSDN LOCALE_SISO639LANGNAME states maximum length of 9, including terminating null. */
+# define W32_ISO639_LEN 9
+
class GHOST_EventIME : public GHOST_Event {
public:
/**
@@ -146,13 +149,10 @@ class GHOST_ImeWin32 {
return is_composing_;
}
- /**
- * Retrieves the input language from Windows and update it.
- */
+ /* Retrieve the input language from Windows and store it. */
void UpdateInputLanguage();
- /* Returns the current input language id. */
- WORD GetInputLanguage();
+ BOOL IsLanguage(const char name[W32_ISO639_LEN]);
/* Saves the current conversion status. */
void UpdateConversionStatus(HWND window_handle);
@@ -345,29 +345,8 @@ class GHOST_ImeWin32 {
*/
bool is_composing_;
- /**
- * The current input Language ID retrieved from Windows, which consists of:
- * * Primary Language ID (bit 0 to bit 9), which shows a natural language
- * (English, Korean, Chinese, Japanese, etc.) and;
- * * Sub-Language ID (bit 10 to bit 15), which shows a geometrical region
- * the language is spoken (For English, United States, United Kingdom,
- * Australia, Canada, etc.)
- * The following list enumerates some examples for the Language ID:
- * * "en-US" (0x0409)
- * MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
- * * "ko-KR" (0x0412)
- * MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN);
- * * "zh-TW" (0x0404)
- * MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL);
- * * "zh-CN" (0x0804)
- * MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
- * * "ja-JP" (0x0411)
- * MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN), etc.
- * (See `winnt.h` for other available values.)
- * This Language ID is used for processing language-specific operations in
- * IME functions.
- */
- LANGID input_language_id_;
+ /* Abbreviated ISO 639-1 name of the input language, such as "en" for English. */
+ char language_[W32_ISO639_LEN];
/* Current Conversion Mode Values. Retrieved with ImmGetConversionStatus. */
DWORD conversion_modes_;
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index 2b4c3237c73..933e0c70cc8 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -1629,7 +1629,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
y_accum + (y_mouse - warped_y_mouse));
/* This is the current time that matches NSEvent timestamp. */
- m_last_warp_timestamp = mach_absolute_time() * 1e-9;
+ m_last_warp_timestamp = [[NSProcessInfo processInfo] systemUptime];
}
// Generate event
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 347067eae50..f44107ee000 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -1741,7 +1741,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
case WM_MOUSELEAVE: {
window->m_mousePresent = false;
if (window->getTabletData().Active == GHOST_kTabletModeNone) {
- processCursorEvent(window);
+ event = processCursorEvent(window);
}
GHOST_Wintab *wt = window->getWintab();
if (wt) {
diff --git a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
index dd0205ea867..936b973c97e 100644
--- a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
+++ b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
@@ -38,6 +38,7 @@
# include "GHOST_SystemWin32.h"
#endif
#include "GHOST_C-api.h"
+#include "GHOST_XrException.h"
#include "GHOST_Xr_intern.h"
#include "GHOST_IXrGraphicsBinding.h"
@@ -160,16 +161,41 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
}
std::optional<int64_t> chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
+ GHOST_TXrSwapchainFormat &r_format,
bool &r_is_srgb_format) const override
{
std::vector<int64_t> gpu_binding_formats = {
+ GL_RGB10_A2,
+ GL_RGBA16,
+ GL_RGBA16F,
GL_RGBA8,
GL_SRGB8_ALPHA8,
};
std::optional result = choose_swapchain_format_from_candidates(gpu_binding_formats,
runtime_formats);
- r_is_srgb_format = result ? (*result == GL_SRGB8_ALPHA8) : false;
+ if (result) {
+ switch (*result) {
+ case GL_RGB10_A2:
+ r_format = GHOST_kXrSwapchainFormatRGB10_A2;
+ break;
+ case GL_RGBA16:
+ r_format = GHOST_kXrSwapchainFormatRGBA16;
+ break;
+ case GL_RGBA16F:
+ r_format = GHOST_kXrSwapchainFormatRGBA16F;
+ break;
+ case GL_RGBA8:
+ case GL_SRGB8_ALPHA8:
+ r_format = GHOST_kXrSwapchainFormatRGBA8;
+ break;
+ }
+ r_is_srgb_format = (*result == GL_SRGB8_ALPHA8);
+ }
+ else {
+ r_format = GHOST_kXrSwapchainFormatRGBA8;
+ r_is_srgb_format = false;
+ }
return result;
}
@@ -228,6 +254,33 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
};
#ifdef WIN32
+static void ghost_format_to_dx_format(GHOST_TXrSwapchainFormat ghost_format,
+ bool expects_srgb_buffer,
+ DXGI_FORMAT &r_dx_format)
+{
+ r_dx_format = DXGI_FORMAT_UNKNOWN;
+
+ switch (ghost_format) {
+ case GHOST_kXrSwapchainFormatRGBA8:
+ r_dx_format = expects_srgb_buffer ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB :
+ DXGI_FORMAT_R8G8B8A8_UNORM;
+ break;
+ case GHOST_kXrSwapchainFormatRGBA16:
+ r_dx_format = DXGI_FORMAT_R16G16B16A16_UNORM;
+ break;
+ case GHOST_kXrSwapchainFormatRGBA16F:
+ r_dx_format = DXGI_FORMAT_R16G16B16A16_FLOAT;
+ break;
+ case GHOST_kXrSwapchainFormatRGB10_A2:
+ r_dx_format = DXGI_FORMAT_R10G10B10A2_UNORM;
+ break;
+ }
+
+ if (r_dx_format == DXGI_FORMAT_UNKNOWN) {
+ throw GHOST_XrException("No supported DirectX swapchain format found.");
+ }
+}
+
class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
public:
GHOST_XrGraphicsBindingD3D(GHOST_Context &ghost_ctx)
@@ -284,16 +337,48 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
}
std::optional<int64_t> chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
+ GHOST_TXrSwapchainFormat &r_format,
bool &r_is_srgb_format) const override
{
std::vector<int64_t> gpu_binding_formats = {
- DXGI_FORMAT_R8G8B8A8_UNORM,
- DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
+# if 0 /* RGB10A2 doesn't seem to work with Oculus head-sets, \
+ * so move it after RGB16AF for the time being. */
+ DXGI_FORMAT_R10G10B10A2_UNORM,
+# endif
+ DXGI_FORMAT_R16G16B16A16_UNORM,
+ DXGI_FORMAT_R16G16B16A16_FLOAT,
+# if 1
+ DXGI_FORMAT_R10G10B10A2_UNORM,
+# endif
+ DXGI_FORMAT_R8G8B8A8_UNORM,
+ DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
};
std::optional result = choose_swapchain_format_from_candidates(gpu_binding_formats,
runtime_formats);
- r_is_srgb_format = result ? (*result == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) : false;
+ if (result) {
+ switch (*result) {
+ case DXGI_FORMAT_R10G10B10A2_UNORM:
+ r_format = GHOST_kXrSwapchainFormatRGB10_A2;
+ break;
+ case DXGI_FORMAT_R16G16B16A16_UNORM:
+ r_format = GHOST_kXrSwapchainFormatRGBA16;
+ break;
+ case DXGI_FORMAT_R16G16B16A16_FLOAT:
+ r_format = GHOST_kXrSwapchainFormatRGBA16F;
+ break;
+ case DXGI_FORMAT_R8G8B8A8_UNORM:
+ case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
+ r_format = GHOST_kXrSwapchainFormatRGBA8;
+ break;
+ }
+ r_is_srgb_format = (*result == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
+ }
+ else {
+ r_format = GHOST_kXrSwapchainFormatRGBA8;
+ r_is_srgb_format = false;
+ }
+
return result;
}
@@ -334,14 +419,18 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
m_ghost_ctx->m_device->CreateRenderTargetView(d3d_swapchain_image.texture, &rtv_desc, &rtv);
if (!m_shared_resource) {
+ DXGI_FORMAT format;
+ ghost_format_to_dx_format(draw_info.swapchain_format, draw_info.expects_srgb_buffer, format);
m_shared_resource = m_ghost_ctx->createSharedOpenGLResource(
- draw_info.width, draw_info.height, rtv);
+ draw_info.width, draw_info.height, format, rtv);
}
m_ghost_ctx->blitFromOpenGLContext(m_shared_resource, draw_info.width, draw_info.height);
# else
if (!m_shared_resource) {
- m_shared_resource = m_ghost_d3d_ctx->createSharedOpenGLResource(draw_info.width,
- draw_info.height);
+ DXGI_FORMAT format;
+ ghost_format_to_dx_format(draw_info.swapchain_format, draw_info.expects_srgb_buffer, format);
+ m_shared_resource = m_ghost_d3d_ctx->createSharedOpenGLResource(
+ draw_info.width, draw_info.height, format);
}
m_ghost_d3d_ctx->blitFromOpenGLContext(m_shared_resource, draw_info.width, draw_info.height);
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index 4cab22ee676..8b0320ef358 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -422,6 +422,7 @@ void GHOST_XrSession::drawView(GHOST_XrSwapchain &swapchain,
assert(view_idx < 256);
draw_view_info.view_idx = (char)view_idx;
+ draw_view_info.swapchain_format = swapchain.getFormat();
draw_view_info.expects_srgb_buffer = swapchain.isBufferSRGB();
draw_view_info.ofsx = r_proj_layer_view.subImage.imageRect.offset.x;
draw_view_info.ofsy = r_proj_layer_view.subImage.imageRect.offset.y;
diff --git a/intern/ghost/intern/GHOST_XrSwapchain.cpp b/intern/ghost/intern/GHOST_XrSwapchain.cpp
index 9973d99cc37..f89b7227ab1 100644
--- a/intern/ghost/intern/GHOST_XrSwapchain.cpp
+++ b/intern/ghost/intern/GHOST_XrSwapchain.cpp
@@ -67,8 +67,8 @@ GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_IXrGraphicsBinding &gpu_binding,
"Failed to get swapchain image formats.");
assert(swapchain_formats.size() == format_count);
- std::optional chosen_format = gpu_binding.chooseSwapchainFormat(swapchain_formats,
- m_is_srgb_buffer);
+ std::optional chosen_format = gpu_binding.chooseSwapchainFormat(
+ swapchain_formats, m_format, m_is_srgb_buffer);
if (!chosen_format) {
throw GHOST_XrException(
"Error: No format matching OpenXR runtime supported swapchain formats found.");
@@ -97,6 +97,7 @@ GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_XrSwapchain &&other)
: m_oxr(std::move(other.m_oxr)),
m_image_width(other.m_image_width),
m_image_height(other.m_image_height),
+ m_format(other.m_format),
m_is_srgb_buffer(other.m_is_srgb_buffer)
{
/* Prevent xrDestroySwapchain call for the moved out item. */
@@ -134,7 +135,12 @@ void GHOST_XrSwapchain::updateCompositionLayerProjectViewSubImage(XrSwapchainSub
r_sub_image.imageRect.extent = {m_image_width, m_image_height};
}
-bool GHOST_XrSwapchain::isBufferSRGB()
+GHOST_TXrSwapchainFormat GHOST_XrSwapchain::getFormat() const
+{
+ return m_format;
+}
+
+bool GHOST_XrSwapchain::isBufferSRGB() const
{
return m_is_srgb_buffer;
}
diff --git a/intern/ghost/intern/GHOST_XrSwapchain.h b/intern/ghost/intern/GHOST_XrSwapchain.h
index 33a1c17b993..0c6592e2db6 100644
--- a/intern/ghost/intern/GHOST_XrSwapchain.h
+++ b/intern/ghost/intern/GHOST_XrSwapchain.h
@@ -37,10 +37,12 @@ class GHOST_XrSwapchain {
void updateCompositionLayerProjectViewSubImage(XrSwapchainSubImage &r_sub_image);
- bool isBufferSRGB();
+ GHOST_TXrSwapchainFormat getFormat() const;
+ bool isBufferSRGB() const;
private:
std::unique_ptr<OpenXRSwapchainData> m_oxr; /* Could use stack, but PImpl is preferable. */
int32_t m_image_width, m_image_height;
+ GHOST_TXrSwapchainFormat m_format;
bool m_is_srgb_buffer = false;
};
diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index a7c3dc0951e..98a8553a3eb 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -871,7 +871,7 @@ void MEM_guarded_freeN(void *vmemh)
if (memh == NULL) {
MemorY_ErroR("free", "attempt to free NULL pointer");
- /* print_error(err_stream, "%d\n", (memh+4000)->tag1); */
+ // print_error(err_stream, "%d\n", (memh+4000)->tag1);
return;
}
diff --git a/make.bat b/make.bat
index 0fda7594e25..e94f7637512 100644
--- a/make.bat
+++ b/make.bat
@@ -14,7 +14,7 @@ call "%BLENDER_DIR%\build_files\windows\parse_arguments.cmd" %*
if errorlevel 1 goto EOF
REM if it is one of the convenience targets and BLENDER_BIN is set
-REM skip compiler detection
+REM skip compiler detection
if "%ICONS%%ICONS_GEOM%%DOC_PY%" == "1" (
if EXIST "%BLENDER_BIN%" (
goto convenience_targets
diff --git a/release/datafiles/locale b/release/datafiles/locale
-Subproject 62e82958a760dad775d9b3387d7fb535fd6de4c
+Subproject 8a05b618f031582c006c6f62b9e60619ab3eef8
diff --git a/release/datafiles/preview.blend b/release/datafiles/preview.blend
index f92f68ad029..e342cb85158 100644
--- a/release/datafiles/preview.blend
+++ b/release/datafiles/preview.blend
Binary files differ
diff --git a/release/scripts/addons b/release/scripts/addons
-Subproject 4475cbd11a636382d57571e0f5dfeff1f90bd6b
+Subproject 67f1fbca1482d9d9362a4001332e785c3fd5d23
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
-Subproject 788441f2930465bbfba8f0797b12dcef1d46694
+Subproject ef6ef414d22c2578fad99327743b925ab640a99
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index d60165f760c..8a1615ad99f 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -477,29 +477,34 @@ class Mesh(bpy_types.ID):
face_lengths = tuple(map(len, faces))
- self.vertices.add(len(vertices))
- self.edges.add(len(edges))
+ # NOTE: check non-empty lists by length because of how `numpy` handles truth tests, see: T90268.
+ vertices_len = len(vertices)
+ edges_len = len(edges)
+ faces_len = len(faces)
+
+ self.vertices.add(vertices_len)
+ self.edges.add(edges_len)
self.loops.add(sum(face_lengths))
- self.polygons.add(len(faces))
+ self.polygons.add(faces_len)
self.vertices.foreach_set("co", tuple(chain.from_iterable(vertices)))
self.edges.foreach_set("vertices", tuple(chain.from_iterable(edges)))
vertex_indices = tuple(chain.from_iterable(faces))
- loop_starts = tuple(islice(chain([0], accumulate(face_lengths)), len(faces)))
+ loop_starts = tuple(islice(chain([0], accumulate(face_lengths)), faces_len))
self.polygons.foreach_set("loop_total", face_lengths)
self.polygons.foreach_set("loop_start", loop_starts)
self.polygons.foreach_set("vertices", vertex_indices)
- if edges or faces:
+ if edges_len or faces_len:
self.update(
# Needed to either:
# - Calculate edges that don't exist for polygons.
# - Assign edges to polygon loops.
- calc_edges=bool(faces),
+ calc_edges=bool(faces_len),
# Flag loose edges.
- calc_edges_loose=bool(edges),
+ calc_edges_loose=bool(edges_len),
)
@property
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index eda9c6e9792..55f60329a97 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -775,6 +775,8 @@ def km_property_editor(_params):
# Constraint panels
("constraint.delete", {"type": 'X', "value": 'PRESS'}, {"properties": [("report", True)]}),
("constraint.delete", {"type": 'DEL', "value": 'PRESS'}, {"properties": [("report", True)]}),
+ ("constraint.copy", {"type": 'D', "value": 'PRESS', "shift": True}, None),
+ ("constraint.apply", {"type": 'A', "value": 'PRESS', "ctrl": True}, {"properties": [("report", True)]}),
])
return keymap
@@ -1907,19 +1909,19 @@ def km_node_editor(params):
("node.clipboard_paste", {"type": 'V', "value": 'PRESS', "ctrl": True}, None),
("node.viewer_border", {"type": 'B', "value": 'PRESS', "ctrl": True}, None),
("node.clear_viewer_border", {"type": 'B', "value": 'PRESS', "ctrl": True, "alt": True}, None),
- ("node.translate_attach", {"type": 'G', "value": 'PRESS'}, None),
- ("node.translate_attach", {"type": 'EVT_TWEAK_L', "value": 'ANY'}, None),
- ("node.translate_attach", {"type": params.select_tweak, "value": 'ANY'}, None),
- ("transform.translate", {"type": 'G', "value": 'PRESS'}, None),
+ ("node.translate_attach", {"type": 'G', "value": 'PRESS'}, {"properties": [("TRANSFORM_OT_translate", [("view2d_edge_pan", True)])]}),
+ ("node.translate_attach", {"type": 'EVT_TWEAK_L', "value": 'ANY'}, {"properties": [("TRANSFORM_OT_translate", [("view2d_edge_pan", True)])]}),
+ ("node.translate_attach", {"type": params.select_tweak, "value": 'ANY'}, {"properties": [("TRANSFORM_OT_translate", [("view2d_edge_pan", True)])]}),
+ ("transform.translate", {"type": 'G', "value": 'PRESS'}, {"properties": [("view2d_edge_pan", True)]}),
("transform.translate", {"type": 'EVT_TWEAK_L', "value": 'ANY'},
- {"properties": [("release_confirm", True)]}),
+ {"properties": [("release_confirm", True), ("view2d_edge_pan", True)]}),
("transform.translate", {"type": params.select_tweak, "value": 'ANY'},
- {"properties": [("release_confirm", True)]}),
+ {"properties": [("release_confirm", True), ("view2d_edge_pan", True)]}),
("transform.rotate", {"type": 'R', "value": 'PRESS'}, None),
("transform.resize", {"type": 'S', "value": 'PRESS'}, None),
- ("node.move_detach_links", {"type": 'D', "value": 'PRESS', "alt": True}, None),
- ("node.move_detach_links_release", {"type": params.action_tweak, "value": 'ANY', "alt": True}, None),
- ("node.move_detach_links", {"type": params.select_tweak, "value": 'ANY', "alt": True}, None),
+ ("node.move_detach_links", {"type": 'D', "value": 'PRESS', "alt": True}, {"properties": [("TRANSFORM_OT_translate", [("view2d_edge_pan", True)])]}),
+ ("node.move_detach_links_release", {"type": params.action_tweak, "value": 'ANY', "alt": True}, {"properties": [("NODE_OT_translate_attach", [("TRANSFORM_OT_translate", [("view2d_edge_pan", True)])])]}),
+ ("node.move_detach_links", {"type": params.select_tweak, "value": 'ANY', "alt": True}, {"properties": [("TRANSFORM_OT_translate", [("view2d_edge_pan", True)])]}),
("wm.context_toggle", {"type": 'TAB', "value": 'PRESS', "shift": True},
{"properties": [("data_path", 'tool_settings.use_snap')]}),
("wm.context_menu_enum", {"type": 'TAB', "value": 'PRESS', "shift": True, "ctrl": True},
@@ -1999,6 +2001,10 @@ def km_file_browser(params):
{"properties": [("increment", -10)]}),
("file.filenum", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True},
{"properties": [("increment", -100)]}),
+
+ # Select file under cursor before spawning the context menu.
+ ("file.select", {"type": 'RIGHTMOUSE', "value": 'PRESS'},
+ {"properties": [("open", False), ("only_activate_if_selected", params.select_mouse == 'LEFTMOUSE'), ("pass_through", True)]}),
*_template_items_context_menu("FILEBROWSER_MT_context_menu", params.context_menu_event),
*_template_items_context_menu("ASSETBROWSER_MT_context_menu", params.context_menu_event),
])
diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index 8e46e9c06df..dba94d71a43 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -465,6 +465,7 @@ def km_property_editor(params):
# Constraint panels
("constraint.delete", {"type": 'BACK_SPACE', "value": 'PRESS'}, {"properties": [("report", True)]}),
("constraint.delete", {"type": 'DEL', "value": 'PRESS'}, {"properties": [("report", True)]}),
+ ("constraint.copy", {"type": 'D', "value": 'PRESS', "ctrl": True}, None),
])
return keymap
@@ -1248,6 +1249,10 @@ def km_file_browser(params):
{"properties": [("increment", -10)]}),
("file.filenum", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True},
{"properties": [("increment", -100)]}),
+
+ # Select file under cursor before spawning the context menu.
+ ("file.select", {"type": 'RIGHTMOUSE', "value": 'PRESS'},
+ {"properties": [("open", False), ("only_activate_if_selected", True), ("pass_through", True)]}),
*_template_items_context_menu("FILEBROWSER_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
*_template_items_context_menu("ASSETBROWSER_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
])
diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 46a16a70dca..52af4fafd09 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -216,6 +216,7 @@ class OBJECT_PT_display(ObjectButtonsPanel, Panel):
obj = context.object
obj_type = obj.type
is_geometry = (obj_type in {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT', 'VOLUME', 'HAIR', 'POINTCLOUD'})
+ has_bounds = (is_geometry or obj_type in {'LATTICE', 'ARMATURE'})
is_wire = (obj_type in {'CAMERA', 'EMPTY'})
is_empty_image = (obj_type == 'EMPTY' and obj.empty_display_type == 'IMAGE')
is_dupli = (obj.instance_type != 'NONE')
@@ -247,21 +248,27 @@ class OBJECT_PT_display(ObjectButtonsPanel, Panel):
# Only useful with object having faces/materials...
col.prop(obj, "color")
- col = layout.column(align=False, heading="Bounds")
- col.use_property_decorate = False
- row = col.row(align=True)
- sub = row.row(align=True)
- sub.prop(obj, "show_bounds", text="")
- sub = sub.row(align=True)
- sub.active = obj.show_bounds or (obj.display_type == 'BOUNDS')
- sub.prop(obj, "display_bounds_type", text="")
- row.prop_decorator(obj, "display_bounds_type")
+ if has_bounds:
+ col = layout.column(align=False, heading="Bounds")
+ col.use_property_decorate = False
+ row = col.row(align=True)
+ sub = row.row(align=True)
+ sub.prop(obj, "show_bounds", text="")
+ sub = sub.row(align=True)
+ sub.active = obj.show_bounds or (obj.display_type == 'BOUNDS')
+ sub.prop(obj, "display_bounds_type", text="")
+ row.prop_decorator(obj, "display_bounds_type")
class OBJECT_PT_instancing(ObjectButtonsPanel, Panel):
bl_label = "Instancing"
bl_options = {'DEFAULT_CLOSED'}
+ @classmethod
+ def poll(cls, context):
+ ob = context.object
+ return (ob.type in {'MESH', 'EMPTY', 'POINTCLOUD'})
+
def draw(self, context):
layout = self.layout
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index ad963396022..c038f5f906a 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -1141,14 +1141,15 @@ def brush_basic__draw_color_selector(context, layout, brush, gp_settings, props)
if not gp_settings.use_material_pin:
ma = context.object.active_material
icon_id = 0
- if ma and ma.id_data.preview:
- icon_id = ma.id_data.preview.icon_id
- txt_ma = ma.name
- maxw = 25
- if len(txt_ma) > maxw:
- txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:]
- else:
- txt_ma = ""
+ txt_ma = ""
+ if ma:
+ ma.id_data.preview_ensure()
+ if ma.id_data.preview:
+ icon_id = ma.id_data.preview.icon_id
+ txt_ma = ma.name
+ maxw = 25
+ if len(txt_ma) > maxw:
+ txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:]
sub = row.row()
sub.ui_units_x = 8
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 00ac69595c7..aea2b76e07b 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -195,7 +195,7 @@ class FILEBROWSER_PT_filter(FileBrowserPanel, Panel):
sub = row.column(align=True)
- if context.preferences.experimental.use_asset_browser:
+ if context.preferences.experimental.use_extended_asset_browser:
sub.prop(params, "use_filter_asset_only")
filter_id = params.filter_id
@@ -653,6 +653,10 @@ class ASSETBROWSER_PT_navigation_bar(asset_utils.AssetBrowserPanel, Panel):
bl_region_type = 'TOOLS'
bl_options = {'HIDE_HEADER'}
+ @classmethod
+ def poll(cls, context):
+ return context.preferences.experimental.use_extended_asset_browser
+
def draw(self, context):
layout = self.layout
diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index 0a4f419362d..febd064147f 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -315,7 +315,7 @@ class OUTLINER_MT_asset(Menu):
@classmethod
def poll(cls, context):
- return context.preferences.experimental.use_asset_browser
+ return context.preferences.experimental.use_extended_asset_browser
def draw(self, context):
layout = self.layout
diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py
index 93ab12e8462..811e7fd41c5 100644
--- a/release/scripts/startup/bl_ui/space_text.py
+++ b/release/scripts/startup/bl_ui/space_text.py
@@ -268,10 +268,7 @@ class TEXT_MT_text(Menu):
layout.operator("text.make_internal")
layout.separator()
- row = layout.row()
- row.active = text.name.endswith(".py")
- row.prop(text, "use_module")
- row = layout.row()
+ layout.prop(text, "use_module")
layout.prop(st, "use_live_edit")
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 91bd5f04b9d..708701c4804 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -997,7 +997,6 @@ class USERPREF_PT_theme_text_style(ThemePanel, CenterAlignMixIn, Panel):
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
col = flow.column()
- col.row().prop(font_style, "font_kerning_style", expand=True)
col.prop(font_style, "points")
col = flow.column(align=True)
@@ -1366,11 +1365,6 @@ class USERPREF_PT_saveload_autorun(FilePathsPanel, Panel):
class USERPREF_PT_file_paths_asset_libraries(FilePathsPanel, Panel):
bl_label = "Asset Libraries"
- @classmethod
- def poll(cls, context):
- prefs = context.preferences
- return prefs.experimental.use_asset_browser
-
def draw(self, context):
layout = self.layout
layout.use_property_split = False
@@ -2258,7 +2252,7 @@ class USERPREF_PT_experimental_new_features(ExperimentalPanel, Panel):
context, (
({"property": "use_sculpt_vertex_colors"}, "T71947"),
({"property": "use_sculpt_tools_tilt"}, "T82877"),
- ({"property": "use_asset_browser"}, ("project/profile/124/", "Milestone 1")),
+ ({"property": "use_extended_asset_browser"}, ("project/view/130/", "Project Page")),
({"property": "use_override_templates"}, ("T73318", "Milestone 4")),
),
)
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 9c67ab1e57f..6f9b222571c 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -495,6 +495,7 @@ geometry_node_categories = [
NodeItem("GeometryNodeAttributeTransfer"),
]),
GeometryNodeCategory("GEO_COLOR", "Color", items=[
+ NodeItem("ShaderNodeMixRGB"),
NodeItem("ShaderNodeRGBCurve"),
NodeItem("ShaderNodeValToRGB"),
NodeItem("ShaderNodeSeparateRGB"),
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index 7e92f79a523..4de7e704a7e 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -98,13 +98,13 @@ void BLF_batch_draw_flush(void);
void BLF_batch_draw_end(void);
/* Draw the string using the current font. */
-void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+void BLF_draw_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
ATTR_NONNULL(2);
-void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
-void BLF_draw_ascii_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2);
+void BLF_draw_ascii_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
ATTR_NONNULL(2);
-void BLF_draw_ascii(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
-int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) ATTR_NONNULL(2);
+void BLF_draw_ascii(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2);
+int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2);
typedef bool (*BLF_GlyphBoundsFn)(const char *str,
const size_t str_step_ofs,
@@ -116,43 +116,45 @@ typedef bool (*BLF_GlyphBoundsFn)(const char *str,
void BLF_boundbox_foreach_glyph_ex(int fontid,
const char *str,
- size_t len,
+ size_t str_len,
BLF_GlyphBoundsFn user_fn,
void *user_data,
struct ResultBLF *r_info) ATTR_NONNULL(2);
void BLF_boundbox_foreach_glyph(int fontid,
const char *str,
- size_t len,
+ size_t str_len,
BLF_GlyphBoundsFn user_fn,
void *user_data) ATTR_NONNULL(2);
/* Get the string byte offset that fits within a given width */
-size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width, float *r_width)
- ATTR_NONNULL(2);
+size_t BLF_width_to_strlen(
+ int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_NONNULL(2);
/* Same as BLF_width_to_strlen but search from the string end */
-size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width, float *r_width)
- ATTR_NONNULL(2);
+size_t BLF_width_to_rstrlen(
+ int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_NONNULL(2);
/* This function return the bounding box of the string
* and are not multiplied by the aspect.
*/
void BLF_boundbox_ex(int fontid,
const char *str,
- size_t len,
+ size_t str_len,
struct rctf *box,
struct ResultBLF *r_info) ATTR_NONNULL(2);
-void BLF_boundbox(int fontid, const char *str, size_t len, struct rctf *box) ATTR_NONNULL();
+void BLF_boundbox(int fontid, const char *str, size_t str_len, struct rctf *box) ATTR_NONNULL();
/* The next both function return the width and height
* of the string, using the current font and both value
* are multiplied by the aspect of the font.
*/
-float BLF_width_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+float BLF_width_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
-float BLF_width(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-float BLF_height_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+float BLF_width(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT
+ ATTR_NONNULL();
+float BLF_height_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
-float BLF_height(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+float BLF_height(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT
+ ATTR_NONNULL();
/* Return dimensions of the font without any sample text. */
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT;
@@ -163,8 +165,8 @@ float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
/* The following function return the width and height of the string, but
* just in one call, so avoid extra freetype2 stuff.
*/
-void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height)
- ATTR_NONNULL();
+void BLF_width_and_height(
+ int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL();
/* For fixed width fonts only, returns the width of a
* character.
@@ -221,9 +223,9 @@ void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2);
/* Draw the string into the buffer, this function draw in both buffer,
* float and unsigned char _BUT_ it's not necessary set both buffer, NULL is valid here.
*/
-void BLF_draw_buffer_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+void BLF_draw_buffer_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
ATTR_NONNULL(2);
-void BLF_draw_buffer(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
+void BLF_draw_buffer(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2);
/* Add a path to the font dir paths. */
void BLF_dir_add(const char *path) ATTR_NONNULL();
@@ -254,8 +256,9 @@ void BLF_default_dpi(int dpi);
void BLF_default_set(int fontid);
int BLF_default(void); /* get default font ID so we can pass it to other functions */
/* Draw the string using the default font, size and dpi. */
-void BLF_draw_default(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
-void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
+void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL();
+void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t str_len)
+ ATTR_NONNULL();
/* Set size and DPI, and return default font ID. */
int BLF_set_default(void);
@@ -271,7 +274,7 @@ void BLF_state_print(int fontid);
#define BLF_ROTATION (1 << 0)
#define BLF_CLIPPING (1 << 1)
#define BLF_SHADOW (1 << 2)
-#define BLF_KERNING_DEFAULT (1 << 3)
+// #define BLF_FLAG_UNUSED_3 (1 << 3) /* dirty */
#define BLF_MATRIX (1 << 4)
#define BLF_ASPECT (1 << 5)
#define BLF_WORD_WRAP (1 << 6)
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 9168e7aa19c..86d67c80fd4 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -108,7 +108,6 @@ void BLF_cache_clear(void)
FontBLF *font = global_font[i];
if (font) {
blf_glyph_cache_clear(font);
- blf_kerning_cache_clear(font);
}
}
}
@@ -522,7 +521,7 @@ static void blf_draw_gl__end(FontBLF *font)
}
}
-void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+void BLF_draw_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
@@ -531,27 +530,27 @@ void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_in
if (font) {
blf_draw_gl__start(font);
if (font->flags & BLF_WORD_WRAP) {
- blf_font_draw__wrap(font, str, len, r_info);
+ blf_font_draw__wrap(font, str, str_len, r_info);
}
else {
- blf_font_draw(font, str, len, r_info);
+ blf_font_draw(font, str, str_len, r_info);
}
blf_draw_gl__end(font);
}
}
-void BLF_draw(int fontid, const char *str, size_t len)
+void BLF_draw(int fontid, const char *str, const size_t str_len)
{
- if (len == 0 || str[0] == '\0') {
+ if (str_len == 0 || str[0] == '\0') {
return;
}
/* Avoid bgl usage to corrupt BLF drawing. */
GPU_bgl_end();
- BLF_draw_ex(fontid, str, len, NULL);
+ BLF_draw_ex(fontid, str, str_len, NULL);
}
-void BLF_draw_ascii_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+void BLF_draw_ascii_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
@@ -561,27 +560,27 @@ void BLF_draw_ascii_ex(int fontid, const char *str, size_t len, struct ResultBLF
blf_draw_gl__start(font);
if (font->flags & BLF_WORD_WRAP) {
/* Use non-ASCII draw function for word-wrap. */
- blf_font_draw__wrap(font, str, len, r_info);
+ blf_font_draw__wrap(font, str, str_len, r_info);
}
else {
- blf_font_draw_ascii(font, str, len, r_info);
+ blf_font_draw_ascii(font, str, str_len, r_info);
}
blf_draw_gl__end(font);
}
}
-void BLF_draw_ascii(int fontid, const char *str, size_t len)
+void BLF_draw_ascii(int fontid, const char *str, const size_t str_len)
{
- if (len == 0 || str[0] == '\0') {
+ if (str_len == 0 || str[0] == '\0') {
return;
}
- BLF_draw_ascii_ex(fontid, str, len, NULL);
+ BLF_draw_ascii_ex(fontid, str, str_len, NULL);
}
-int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
+int BLF_draw_mono(int fontid, const char *str, const size_t str_len, int cwidth)
{
- if (len == 0 || str[0] == '\0') {
+ if (str_len == 0 || str[0] == '\0') {
return 0;
}
@@ -590,7 +589,7 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
if (font) {
blf_draw_gl__start(font);
- columns = blf_font_draw_mono(font, str, len, cwidth);
+ columns = blf_font_draw_mono(font, str, str_len, cwidth);
blf_draw_gl__end(font);
}
@@ -607,7 +606,7 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
*/
void BLF_boundbox_foreach_glyph_ex(int fontid,
const char *str,
- size_t len,
+ size_t str_len,
BLF_GlyphBoundsFn user_fn,
void *user_data,
struct ResultBLF *r_info)
@@ -622,25 +621,26 @@ void BLF_boundbox_foreach_glyph_ex(int fontid,
BLI_assert(0);
}
else {
- blf_font_boundbox_foreach_glyph(font, str, len, user_fn, user_data, r_info);
+ blf_font_boundbox_foreach_glyph(font, str, str_len, user_fn, user_data, r_info);
}
}
}
void BLF_boundbox_foreach_glyph(
- int fontid, const char *str, size_t len, BLF_GlyphBoundsFn user_fn, void *user_data)
+ int fontid, const char *str, const size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data)
{
- BLF_boundbox_foreach_glyph_ex(fontid, str, len, user_fn, user_data, NULL);
+ BLF_boundbox_foreach_glyph_ex(fontid, str, str_len, user_fn, user_data, NULL);
}
-size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width, float *r_width)
+size_t BLF_width_to_strlen(
+ int fontid, const char *str, const size_t str_len, float width, float *r_width)
{
FontBLF *font = blf_get(fontid);
if (font) {
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
size_t ret;
- ret = blf_font_width_to_strlen(font, str, len, width / xa, r_width);
+ ret = blf_font_width_to_strlen(font, str, str_len, width / xa, r_width);
if (r_width) {
*r_width *= xa;
}
@@ -653,14 +653,15 @@ size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width,
return 0;
}
-size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width, float *r_width)
+size_t BLF_width_to_rstrlen(
+ int fontid, const char *str, const size_t str_len, float width, float *r_width)
{
FontBLF *font = blf_get(fontid);
if (font) {
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
size_t ret;
- ret = blf_font_width_to_rstrlen(font, str, len, width / xa, r_width);
+ ret = blf_font_width_to_rstrlen(font, str, str_len, width / xa, r_width);
if (r_width) {
*r_width *= xa;
}
@@ -674,7 +675,7 @@ size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width
}
void BLF_boundbox_ex(
- int fontid, const char *str, size_t len, rctf *r_box, struct ResultBLF *r_info)
+ int fontid, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
@@ -682,47 +683,48 @@ void BLF_boundbox_ex(
if (font) {
if (font->flags & BLF_WORD_WRAP) {
- blf_font_boundbox__wrap(font, str, len, r_box, r_info);
+ blf_font_boundbox__wrap(font, str, str_len, r_box, r_info);
}
else {
- blf_font_boundbox(font, str, len, r_box, r_info);
+ blf_font_boundbox(font, str, str_len, r_box, r_info);
}
}
}
-void BLF_boundbox(int fontid, const char *str, size_t len, rctf *r_box)
+void BLF_boundbox(int fontid, const char *str, const size_t str_len, rctf *r_box)
{
- BLF_boundbox_ex(fontid, str, len, r_box, NULL);
+ BLF_boundbox_ex(fontid, str, str_len, r_box, NULL);
}
-void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height)
+void BLF_width_and_height(
+ int fontid, const char *str, const size_t str_len, float *r_width, float *r_height)
{
FontBLF *font = blf_get(fontid);
if (font) {
- blf_font_width_and_height(font, str, len, r_width, r_height, NULL);
+ blf_font_width_and_height(font, str, str_len, r_width, r_height, NULL);
}
else {
*r_width = *r_height = 0.0f;
}
}
-float BLF_width_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+float BLF_width_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
BLF_RESULT_CHECK_INIT(r_info);
if (font) {
- return blf_font_width(font, str, len, r_info);
+ return blf_font_width(font, str, str_len, r_info);
}
return 0.0f;
}
-float BLF_width(int fontid, const char *str, size_t len)
+float BLF_width(int fontid, const char *str, const size_t str_len)
{
- return BLF_width_ex(fontid, str, len, NULL);
+ return BLF_width_ex(fontid, str, str_len, NULL);
}
float BLF_fixed_width(int fontid)
@@ -736,22 +738,22 @@ float BLF_fixed_width(int fontid)
return 0.0f;
}
-float BLF_height_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+float BLF_height_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
BLF_RESULT_CHECK_INIT(r_info);
if (font) {
- return blf_font_height(font, str, len, r_info);
+ return blf_font_height(font, str, str_len, r_info);
}
return 0.0f;
}
-float BLF_height(int fontid, const char *str, size_t len)
+float BLF_height(int fontid, const char *str, const size_t str_len)
{
- return BLF_height_ex(fontid, str, len, NULL);
+ return BLF_height_ex(fontid, str, str_len, NULL);
}
int BLF_height_max(int fontid)
@@ -895,24 +897,27 @@ void blf_draw_buffer__end(void)
{
}
-void BLF_draw_buffer_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
+void BLF_draw_buffer_ex(int fontid,
+ const char *str,
+ const size_t str_len,
+ struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
if (font && (font->buf_info.fbuf || font->buf_info.cbuf)) {
blf_draw_buffer__start(font);
if (font->flags & BLF_WORD_WRAP) {
- blf_font_draw_buffer__wrap(font, str, len, r_info);
+ blf_font_draw_buffer__wrap(font, str, str_len, r_info);
}
else {
- blf_font_draw_buffer(font, str, len, r_info);
+ blf_font_draw_buffer(font, str, str_len, r_info);
}
blf_draw_buffer__end();
}
}
-void BLF_draw_buffer(int fontid, const char *str, size_t len)
+void BLF_draw_buffer(int fontid, const char *str, const size_t str_len)
{
- BLF_draw_buffer_ex(fontid, str, len, NULL);
+ BLF_draw_buffer_ex(fontid, str, str_len, NULL);
}
char *BLF_display_name_from_file(const char *filename)
diff --git a/source/blender/blenfont/intern/blf_default.c b/source/blender/blenfont/intern/blf_default.c
index 7bbc865128d..1b458e8aaef 100644
--- a/source/blender/blenfont/intern/blf_default.c
+++ b/source/blender/blenfont/intern/blf_default.c
@@ -68,23 +68,23 @@ int BLF_set_default(void)
return global_font_default;
}
-void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
+void BLF_draw_default(float x, float y, float z, const char *str, const size_t str_len)
{
ASSERT_DEFAULT_SET;
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
- BLF_draw(global_font_default, str, len);
+ BLF_draw(global_font_default, str, str_len);
}
/* same as above but call 'BLF_draw_ascii' */
-void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len)
+void BLF_draw_default_ascii(float x, float y, float z, const char *str, const size_t str_len)
{
ASSERT_DEFAULT_SET;
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
- BLF_draw_ascii(global_font_default, str, len); /* XXX, use real length */
+ BLF_draw_ascii(global_font_default, str, str_len); /* XXX, use real length */
}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 6e2be4a8353..5ad48aa08d4 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -72,6 +72,38 @@ static SpinLock ft_lib_mutex;
static SpinLock blf_glyph_cache_mutex;
/* -------------------------------------------------------------------- */
+/** \name FreeType Utilities (Internal)
+ * \{ */
+
+/**
+ * Convert a FreeType 26.6 value representing an unscaled design size to pixels.
+ * This is an exact copy of the scaling done inside FT_Get_Kerning when called
+ * with #FT_KERNING_DEFAULT, including arbitrary resizing for small fonts.
+ */
+static int blf_unscaled_F26Dot6_to_pixels(FontBLF *font, FT_Pos value)
+{
+ /* Scale value by font size using integer-optimized multiplication. */
+ FT_Long scaled = FT_MulFix(value, font->face->size->metrics.x_scale);
+
+ /* FreeType states that this '25' has been determined heuristically. */
+ if (font->face->size->metrics.x_ppem < 25) {
+ scaled = FT_MulDiv(scaled, font->face->size->metrics.x_ppem, 25);
+ }
+
+ /* Copies of internal FreeType macros needed here. */
+#define FT_PIX_FLOOR(x) ((x) & ~63)
+#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
+
+ /* Round to even 64ths, then divide by 64. */
+ return (int)FT_PIX_ROUND(scaled) >> 6;
+
+#undef FT_PIX_FLOOR
+#undef FT_PIX_ROUND
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Glyph Batching
* \{ */
@@ -257,156 +289,83 @@ static void blf_batch_draw_end(void)
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Glyph Stepping Utilities (Internal)
+ * \{ */
-int blf_font_init(void)
-{
- memset(&g_batch, 0, sizeof(g_batch));
- BLI_spin_init(&ft_lib_mutex);
- BLI_spin_init(&blf_glyph_cache_mutex);
- return FT_Init_FreeType(&ft_lib);
-}
-
-void blf_font_exit(void)
-{
- FT_Done_FreeType(ft_lib);
- BLI_spin_end(&ft_lib_mutex);
- BLI_spin_end(&blf_glyph_cache_mutex);
- blf_batch_draw_exit();
-}
+/* Fast path for runs of ASCII characters. Given that common UTF-8
+ * input will consist of an overwhelming majority of ASCII
+ * characters.
+ */
-void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
+BLI_INLINE GlyphBLF *blf_utf8_next_fast(
+ FontBLF *font, GlyphCacheBLF *gc, const char *str, size_t str_len, size_t *i_p, uint *r_c)
{
- GlyphCacheBLF *gc;
- FT_Error err;
-
- blf_glyph_cache_acquire(font);
-
- gc = blf_glyph_cache_find(font, size, dpi);
- if (gc) {
- /* Optimization: do not call FT_Set_Char_Size if size did not change. */
- if (font->size == size && font->dpi == dpi) {
- blf_glyph_cache_release(font);
- return;
+ GlyphBLF *g;
+ if ((*r_c = str[*i_p]) < GLYPH_ASCII_TABLE_SIZE) {
+ g = (gc->glyph_ascii_table)[*r_c];
+ if (UNLIKELY(g == NULL)) {
+ g = blf_glyph_add(font, gc, FT_Get_Char_Index(font->face, *r_c), *r_c);
+ gc->glyph_ascii_table[*r_c] = g;
}
+ (*i_p)++;
}
-
- err = FT_Set_Char_Size(font->face, 0, ((FT_F26Dot6)(size)) * 64, dpi, dpi);
- if (err) {
- /* FIXME: here we can go through the fixed size and choice a close one */
- printf("The current font don't support the size, %u and dpi, %u\n", size, dpi);
-
- blf_glyph_cache_release(font);
- return;
+ else if ((*r_c = BLI_str_utf8_as_unicode_step(str, str_len, i_p)) != BLI_UTF8_ERR) {
+ g = blf_glyph_search(gc, *r_c);
+ if (UNLIKELY(g == NULL)) {
+ g = blf_glyph_add(font, gc, FT_Get_Char_Index(font->face, *r_c), *r_c);
+ }
}
-
- font->size = size;
- font->dpi = dpi;
-
- if (!gc) {
- blf_glyph_cache_new(font);
+ else {
+ g = NULL;
}
- blf_glyph_cache_release(font);
+ return g;
}
-static GlyphBLF **blf_font_ensure_ascii_table(FontBLF *font, GlyphCacheBLF *gc)
+BLI_INLINE void blf_kerning_step_fast(FontBLF *font,
+ const GlyphBLF *g_prev,
+ const GlyphBLF *g,
+ const uint c_prev,
+ const uint c,
+ int *pen_x_p)
{
- GlyphBLF **glyph_ascii_table;
-
- glyph_ascii_table = gc->glyph_ascii_table;
-
- /* build ascii on demand */
- if (glyph_ascii_table['0'] == NULL) {
- GlyphBLF *g;
- for (uint i = 0; i < 256; i++) {
- g = blf_glyph_search(gc, i);
- if (!g) {
- FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
- g = blf_glyph_add(font, gc, glyph_index, i);
- }
- glyph_ascii_table[i] = g;
- }
+ if (!FT_HAS_KERNING(font->face) || g_prev == NULL) {
+ return;
}
- return glyph_ascii_table;
-}
+ FT_Vector delta = {KERNING_ENTRY_UNSET};
-static void blf_font_ensure_ascii_kerning(FontBLF *font,
- GlyphCacheBLF *gc,
- const FT_UInt kern_mode)
-{
- KerningCacheBLF *kc = font->kerning_cache;
+ /* Get unscaled kerning value from our cache if ASCII. */
+ if ((c_prev < KERNING_CACHE_TABLE_SIZE) && (c < GLYPH_ASCII_TABLE_SIZE)) {
+ delta.x = font->kerning_cache->ascii_table[c][c_prev];
+ }
- font->kerning_mode = kern_mode;
+ /* If not ASCII or not found in cache, ask FreeType for kerning. */
+ if (UNLIKELY(delta.x == KERNING_ENTRY_UNSET)) {
+ /* Note that this function sets delta values to zero on any error. */
+ FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNSCALED, &delta);
+ }
- if (!kc || kc->mode != kern_mode) {
- font->kerning_cache = kc = blf_kerning_cache_find(font);
- if (!kc) {
- font->kerning_cache = kc = blf_kerning_cache_new(font, gc);
- }
+ /* If ASCII we save this value to our cache for quicker access next time. */
+ if ((c_prev < KERNING_CACHE_TABLE_SIZE) && (c < GLYPH_ASCII_TABLE_SIZE)) {
+ font->kerning_cache->ascii_table[c][c_prev] = (int)delta.x;
+ }
+
+ if (delta.x != 0) {
+ /* Convert unscaled design units to pixels and move pen. */
+ *pen_x_p += blf_unscaled_F26Dot6_to_pixels(font, delta.x);
}
}
-/* Fast path for runs of ASCII characters. Given that common UTF-8
- * input will consist of an overwhelming majority of ASCII
- * characters.
- */
+/** \} */
-/* NOTE: `blf_font_ensure_ascii_table(font, gc);` must be called before this macro. */
-
-#define BLF_UTF8_NEXT_FAST(_font, _gc, _g, _str, _i, _c, _glyph_ascii_table) \
- if (((_c) = (_str)[_i]) < 0x80) { \
- _g = (_glyph_ascii_table)[_c]; \
- _i++; \
- } \
- else if ((_c = BLI_str_utf8_as_unicode_step(_str, &(_i))) != BLI_UTF8_ERR) { \
- if ((_g = blf_glyph_search(_gc, _c)) == NULL) { \
- _g = blf_glyph_add(_font, _gc, FT_Get_Char_Index((_font)->face, _c), _c); \
- } \
- } \
- else { \
- _g = NULL; \
- } \
- (void)0
-
-#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \
- const bool _has_kerning = FT_HAS_KERNING((_font)->face) != 0; \
- const FT_UInt _kern_mode = (_has_kerning == 0) ? 0 : \
- (((_font)->flags & BLF_KERNING_DEFAULT) ? \
- ft_kerning_default : \
- (FT_UInt)FT_KERNING_UNFITTED)
-
-/* NOTE: `blf_font_ensure_ascii_kerning(font, gc, kern_mode);` must be called before this macro. */
-
-#define BLF_KERNING_STEP_FAST(_font, _kern_mode, _g_prev, _g, _c_prev, _c, _pen_x) \
- { \
- if (_g_prev) { \
- FT_Vector _delta; \
- if (_c_prev < 0x80 && _c < 0x80) { \
- _pen_x += (_font)->kerning_cache->table[_c][_c_prev]; \
- } \
- else if (FT_Get_Kerning((_font)->face, (_g_prev)->idx, (_g)->idx, _kern_mode, &(_delta)) == \
- 0) { \
- _pen_x += (int)_delta.x >> 6; \
- } \
- } \
- } \
- (void)0
-
-#define BLF_KERNING_STEP(_font, _kern_mode, _g_prev, _g, _delta, _pen_x) \
- { \
- if (_g_prev) { \
- _delta.x = _delta.y = 0; \
- if (FT_Get_Kerning((_font)->face, (_g_prev)->idx, (_g)->idx, _kern_mode, &(_delta)) == 0) { \
- _pen_x += (int)_delta.x >> 6; \
- } \
- } \
- } \
- (void)0
+/* -------------------------------------------------------------------- */
+/** \name Text Drawing: GPU
+ * \{ */
static void blf_font_draw_ex(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
- size_t len,
+ const size_t str_len,
struct ResultBLF *r_info,
int pen_y)
{
@@ -415,21 +374,15 @@ static void blf_font_draw_ex(FontBLF *font,
int pen_x = 0;
size_t i = 0;
- if (len == 0) {
+ if (str_len == 0) {
/* early output, don't do any IMM OpenGL. */
return;
}
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
-
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
-
blf_batch_draw_begin(font);
- while ((i < len) && str[i]) {
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
+ while ((i < str_len) && str[i]) {
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
@@ -437,9 +390,7 @@ static void blf_font_draw_ex(FontBLF *font,
if (UNLIKELY(g == NULL)) {
continue;
}
- if (has_kerning) {
- BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
- }
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, gc, g, (float)pen_x, (float)pen_y);
@@ -456,38 +407,36 @@ static void blf_font_draw_ex(FontBLF *font,
r_info->width = pen_x;
}
}
-void blf_font_draw(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+void blf_font_draw(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
{
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_draw_ex(font, gc, str, len, r_info, 0);
+ blf_font_draw_ex(font, gc, str, str_len, r_info, 0);
blf_glyph_cache_release(font);
}
/* faster version of blf_font_draw, ascii only for view dimensions */
static void blf_font_draw_ascii_ex(
- FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info, int pen_y)
+ FontBLF *font, const char *str, size_t str_len, struct ResultBLF *r_info, int pen_y)
{
unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev = NULL;
int pen_x = 0;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
-
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
blf_batch_draw_begin(font);
- while ((c = *(str++)) && len--) {
- BLI_assert(c < 128);
- if ((g = glyph_ascii_table[c]) == NULL) {
- continue;
- }
- if (has_kerning) {
- BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
+ while ((c = *(str++)) && str_len--) {
+ BLI_assert(c < GLYPH_ASCII_TABLE_SIZE);
+ g = gc->glyph_ascii_table[c];
+ if (UNLIKELY(g == NULL)) {
+ g = blf_glyph_add(font, gc, FT_Get_Char_Index((font)->face, c), c);
+ gc->glyph_ascii_table[c] = g;
+ if (UNLIKELY(g == NULL)) {
+ continue;
+ }
}
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, gc, g, (float)pen_x, (float)pen_y);
@@ -507,13 +456,16 @@ static void blf_font_draw_ascii_ex(
blf_glyph_cache_release(font);
}
-void blf_font_draw_ascii(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+void blf_font_draw_ascii(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ struct ResultBLF *r_info)
{
- blf_font_draw_ascii_ex(font, str, len, r_info, 0);
+ blf_font_draw_ascii_ex(font, str, str_len, r_info, 0);
}
/* use fixed column width, but an utf8 character may occupy multiple columns */
-int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
+int blf_font_draw_mono(FontBLF *font, const char *str, const size_t str_len, int cwidth)
{
unsigned int c;
GlyphBLF *g;
@@ -522,12 +474,11 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
size_t i = 0;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
blf_batch_draw_begin(font);
- while ((i < len) && str[i]) {
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
+ while ((i < str_len) && str[i]) {
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
@@ -554,11 +505,17 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
return columns;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Text Drawing: Buffer
+ * \{ */
+
/* Sanity checks are done by BLF_draw_buffer() */
static void blf_font_draw_buffer_ex(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
- size_t len,
+ const size_t str_len,
struct ResultBLF *r_info,
int pen_y)
{
@@ -568,8 +525,6 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
int pen_y_basis = (int)font->pos[1] + pen_y;
size_t i = 0;
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
-
/* buffer specific vars */
FontBufInfoBLF *buf_info = &font->buf_info;
const float *b_col_float = buf_info->col_float;
@@ -577,14 +532,10 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
int chx, chy;
int y, x;
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
-
/* another buffer specific call for color conversion */
- while ((i < len) && str[i]) {
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
+ while ((i < str_len) && str[i]) {
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
@@ -592,9 +543,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
if (UNLIKELY(g == NULL)) {
continue;
}
- if (has_kerning) {
- BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
- }
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x);
chx = pen_x + ((int)g->pos[0]);
chy = pen_y_basis + g->dims[1];
@@ -700,16 +649,27 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
}
}
-void blf_font_draw_buffer(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+void blf_font_draw_buffer(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ struct ResultBLF *r_info)
{
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_draw_buffer_ex(font, gc, str, len, r_info, 0);
+ blf_font_draw_buffer_ex(font, gc, str, str_len, r_info, 0);
blf_glyph_cache_release(font);
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Text Evaluation: Width to Sting Length
+ *
+ * Use to implement exported functions:
+ * - #BLF_width_to_strlen
+ * - #BLF_width_to_rstrlen
+ * \{ */
+
static bool blf_font_width_to_strlen_glyph_process(FontBLF *font,
- const bool has_kerning,
- const FT_UInt kern_mode,
const uint c_prev,
const uint c,
GlyphBLF *g_prev,
@@ -723,9 +683,7 @@ static bool blf_font_width_to_strlen_glyph_process(FontBLF *font,
if (UNLIKELY(g == NULL)) {
return false; /* continue the calling loop. */
}
- if (has_kerning) {
- BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, *pen_x);
- }
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, pen_x);
*pen_x += g->advance_i;
@@ -733,7 +691,7 @@ static bool blf_font_width_to_strlen_glyph_process(FontBLF *font,
}
size_t blf_font_width_to_strlen(
- FontBLF *font, const char *str, size_t len, float width, float *r_width)
+ FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
{
unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev;
@@ -741,21 +699,13 @@ size_t blf_font_width_to_strlen(
size_t i, i_prev;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
const int width_i = (int)width;
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
- if (has_kerning) {
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
- }
-
- for (i_prev = i = 0, width_new = pen_x = 0, g_prev = NULL, c_prev = 0; (i < len) && str[i];
+ for (i_prev = i = 0, width_new = pen_x = 0, g_prev = NULL, c_prev = 0; (i < str_len) && str[i];
i_prev = i, width_new = pen_x, c_prev = c, g_prev = g) {
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
- if (blf_font_width_to_strlen_glyph_process(
- font, has_kerning, kern_mode, c_prev, c, g_prev, g, &pen_x, width_i)) {
+ if (blf_font_width_to_strlen_glyph_process(font, c_prev, c, g_prev, g, &pen_x, width_i)) {
break;
}
}
@@ -769,7 +719,7 @@ size_t blf_font_width_to_strlen(
}
size_t blf_font_width_to_rstrlen(
- FontBLF *font, const char *str, size_t len, float width, float *r_width)
+ FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
{
unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev;
@@ -778,23 +728,16 @@ size_t blf_font_width_to_rstrlen(
char *s, *s_prev;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
const int width_i = (int)width;
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
- if (has_kerning) {
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
- }
-
- i = BLI_strnlen(str, len);
+ i = BLI_strnlen(str, str_len);
s = BLI_str_find_prev_char_utf8(str, &str[i]);
i = (size_t)((s != NULL) ? s - str : 0);
s_prev = BLI_str_find_prev_char_utf8(str, s);
i_prev = (size_t)((s_prev != NULL) ? s_prev - str : 0);
i_tmp = i;
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i_tmp, c, glyph_ascii_table);
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i_tmp, &c);
for (width_new = pen_x = 0; (s != NULL);
i = i_prev, s = s_prev, c = c_prev, g = g_prev, g_prev = NULL, width_new = pen_x) {
s_prev = BLI_str_find_prev_char_utf8(str, s);
@@ -802,12 +745,11 @@ size_t blf_font_width_to_rstrlen(
if (s_prev != NULL) {
i_tmp = i_prev;
- BLF_UTF8_NEXT_FAST(font, gc, g_prev, str, i_tmp, c_prev, glyph_ascii_table);
+ g_prev = blf_utf8_next_fast(font, gc, str, str_len, &i_tmp, &c_prev);
BLI_assert(i_tmp == i);
}
- if (blf_font_width_to_strlen_glyph_process(
- font, has_kerning, kern_mode, c_prev, c, g_prev, g, &pen_x, width_i)) {
+ if (blf_font_width_to_strlen_glyph_process(font, c_prev, c, g_prev, g, &pen_x, width_i)) {
break;
}
}
@@ -820,10 +762,16 @@ size_t blf_font_width_to_rstrlen(
return i;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Text Evaluation: Glyph Bound Box with Callback
+ * \{ */
+
static void blf_font_boundbox_ex(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
- size_t len,
+ const size_t str_len,
rctf *box,
struct ResultBLF *r_info,
int pen_y)
@@ -832,22 +780,15 @@ static void blf_font_boundbox_ex(FontBLF *font,
GlyphBLF *g, *g_prev = NULL;
int pen_x = 0;
size_t i = 0;
-
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
-
rctf gbox;
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
box->xmin = 32000.0f;
box->xmax = -32000.0f;
box->ymin = 32000.0f;
box->ymax = -32000.0f;
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
-
- while ((i < len) && str[i]) {
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
+ while ((i < str_len) && str[i]) {
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
@@ -855,9 +796,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
if (UNLIKELY(g == NULL)) {
continue;
}
- if (has_kerning) {
- BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
- }
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x);
gbox.xmin = (float)pen_x;
gbox.xmax = (float)pen_x + g->advance;
@@ -896,15 +835,178 @@ static void blf_font_boundbox_ex(FontBLF *font,
}
}
void blf_font_boundbox(
- FontBLF *font, const char *str, size_t len, rctf *r_box, struct ResultBLF *r_info)
+ FontBLF *font, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
+{
+ GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
+ blf_font_boundbox_ex(font, gc, str, str_len, r_box, r_info, 0);
+ blf_glyph_cache_release(font);
+}
+
+void blf_font_width_and_height(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ float *r_width,
+ float *r_height,
+ struct ResultBLF *r_info)
+{
+ float xa, ya;
+ rctf box;
+
+ if (font->flags & BLF_ASPECT) {
+ xa = font->aspect[0];
+ ya = font->aspect[1];
+ }
+ else {
+ xa = 1.0f;
+ ya = 1.0f;
+ }
+
+ if (font->flags & BLF_WORD_WRAP) {
+ blf_font_boundbox__wrap(font, str, str_len, &box, r_info);
+ }
+ else {
+ blf_font_boundbox(font, str, str_len, &box, r_info);
+ }
+ *r_width = (BLI_rctf_size_x(&box) * xa);
+ *r_height = (BLI_rctf_size_y(&box) * ya);
+}
+
+float blf_font_width(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ struct ResultBLF *r_info)
+{
+ float xa;
+ rctf box;
+
+ if (font->flags & BLF_ASPECT) {
+ xa = font->aspect[0];
+ }
+ else {
+ xa = 1.0f;
+ }
+
+ if (font->flags & BLF_WORD_WRAP) {
+ blf_font_boundbox__wrap(font, str, str_len, &box, r_info);
+ }
+ else {
+ blf_font_boundbox(font, str, str_len, &box, r_info);
+ }
+ return BLI_rctf_size_x(&box) * xa;
+}
+
+float blf_font_height(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ struct ResultBLF *r_info)
+{
+ float ya;
+ rctf box;
+
+ if (font->flags & BLF_ASPECT) {
+ ya = font->aspect[1];
+ }
+ else {
+ ya = 1.0f;
+ }
+
+ if (font->flags & BLF_WORD_WRAP) {
+ blf_font_boundbox__wrap(font, str, str_len, &box, r_info);
+ }
+ else {
+ blf_font_boundbox(font, str, str_len, &box, r_info);
+ }
+ return BLI_rctf_size_y(&box) * ya;
+}
+
+float blf_font_fixed_width(FontBLF *font)
{
+ const unsigned int c = ' ';
+
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_boundbox_ex(font, gc, str, len, r_box, r_info, 0);
+ GlyphBLF *g = blf_glyph_search(gc, c);
+ if (!g) {
+ g = blf_glyph_add(font, gc, FT_Get_Char_Index(font->face, c), c);
+
+ /* if we don't find the glyph. */
+ if (!g) {
+ blf_glyph_cache_release(font);
+ return 0.0f;
+ }
+ }
+
blf_glyph_cache_release(font);
+ return g->advance;
}
+static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
+ GlyphCacheBLF *gc,
+ const char *str,
+ const size_t str_len,
+ BLF_GlyphBoundsFn user_fn,
+ void *user_data,
+ struct ResultBLF *r_info,
+ int pen_y)
+{
+ unsigned int c, c_prev = BLI_UTF8_ERR;
+ GlyphBLF *g, *g_prev = NULL;
+ int pen_x = 0;
+ size_t i = 0, i_curr;
+ rcti gbox;
+
+ if (str_len == 0) {
+ /* early output. */
+ return;
+ }
+
+ while ((i < str_len) && str[i]) {
+ i_curr = i;
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
+
+ if (UNLIKELY(c == BLI_UTF8_ERR)) {
+ break;
+ }
+ if (UNLIKELY(g == NULL)) {
+ continue;
+ }
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x);
+
+ gbox.xmin = pen_x;
+ gbox.xmax = gbox.xmin + MIN2(g->advance_i, g->dims[0]);
+ gbox.ymin = pen_y;
+ gbox.ymax = gbox.ymin - g->dims[1];
+
+ pen_x += g->advance_i;
+
+ if (user_fn(str, i_curr, &gbox, g->advance_i, &g->box, g->pos, user_data) == false) {
+ break;
+ }
+
+ g_prev = g;
+ c_prev = c;
+ }
+
+ if (r_info) {
+ r_info->lines = 1;
+ r_info->width = pen_x;
+ }
+}
+void blf_font_boundbox_foreach_glyph(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ BLF_GlyphBoundsFn user_fn,
+ void *user_data,
+ struct ResultBLF *r_info)
+{
+ GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
+ blf_font_boundbox_foreach_glyph_ex(font, gc, str, str_len, user_fn, user_data, r_info, 0);
+ blf_glyph_cache_release(font);
+}
+
+/** \} */
+
/* -------------------------------------------------------------------- */
-/** \name Word-Wrap Support
+/** \name Text Evaluation: Word-Wrap with Callback
* \{ */
/**
@@ -918,42 +1020,38 @@ void blf_font_boundbox(
*/
static void blf_font_wrap_apply(FontBLF *font,
const char *str,
- size_t len,
+ const size_t str_len,
struct ResultBLF *r_info,
void (*callback)(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
- size_t len,
+ const size_t str_len,
int pen_y,
void *userdata),
void *userdata)
{
- unsigned int c;
+ unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev = NULL;
- FT_Vector delta;
int pen_x = 0, pen_y = 0;
size_t i = 0;
int lines = 0;
int pen_x_next = 0;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
-
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
struct WordWrapVars {
int wrap_width;
size_t start, last[2];
} wrap = {font->wrap_width != -1 ? font->wrap_width : INT_MAX, 0, {0, 0}};
- // printf("%s wrapping (%d, %d) `%s`:\n", __func__, len, strlen(str), str);
- while ((i < len) && str[i]) {
+ // printf("%s wrapping (%d, %d) `%s`:\n", __func__, str_len, strlen(str), str);
+ while ((i < str_len) && str[i]) {
/* wrap vars */
size_t i_curr = i;
bool do_draw = false;
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
+ g = blf_utf8_next_fast(font, gc, str, str_len, &i, &c);
if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
@@ -961,9 +1059,7 @@ static void blf_font_wrap_apply(FontBLF *font,
if (UNLIKELY(g == NULL)) {
continue;
}
- if (has_kerning) {
- BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- }
+ blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x);
/**
* Implementation Detail (utf8).
@@ -977,7 +1073,7 @@ static void blf_font_wrap_apply(FontBLF *font,
if (UNLIKELY((pen_x_next >= wrap.wrap_width) && (wrap.start != wrap.last[0]))) {
do_draw = true;
}
- else if (UNLIKELY(((i < len) && str[i]) == 0)) {
+ else if (UNLIKELY(((i < str_len) && str[i]) == 0)) {
/* need check here for trailing newline, else we draw it */
wrap.last[0] = i + ((g->c != '\n') ? 1 : 0);
wrap.last[1] = i;
@@ -1003,12 +1099,14 @@ static void blf_font_wrap_apply(FontBLF *font,
pen_x = 0;
pen_y -= gc->glyph_height_max;
g_prev = NULL;
+ c_prev = BLI_UTF8_ERR;
lines += 1;
continue;
}
pen_x = pen_x_next;
g_prev = g;
+ c_prev = c;
}
// printf("done! lines: %d, width, %d\n", lines, pen_x_next);
@@ -1026,276 +1124,179 @@ static void blf_font_wrap_apply(FontBLF *font,
static void blf_font_draw__wrap_cb(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
- size_t len,
+ const size_t str_len,
int pen_y,
void *UNUSED(userdata))
{
- blf_font_draw_ex(font, gc, str, len, NULL, pen_y);
+ blf_font_draw_ex(font, gc, str, str_len, NULL, pen_y);
}
-void blf_font_draw__wrap(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+void blf_font_draw__wrap(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ struct ResultBLF *r_info)
{
- blf_font_wrap_apply(font, str, len, r_info, blf_font_draw__wrap_cb, NULL);
+ blf_font_wrap_apply(font, str, str_len, r_info, blf_font_draw__wrap_cb, NULL);
}
/* blf_font_boundbox__wrap */
-static void blf_font_boundbox_wrap_cb(
- FontBLF *font, GlyphCacheBLF *gc, const char *str, size_t len, int pen_y, void *userdata)
+static void blf_font_boundbox_wrap_cb(FontBLF *font,
+ GlyphCacheBLF *gc,
+ const char *str,
+ const size_t str_len,
+ int pen_y,
+ void *userdata)
{
rctf *box = userdata;
rctf box_single;
- blf_font_boundbox_ex(font, gc, str, len, &box_single, NULL, pen_y);
+ blf_font_boundbox_ex(font, gc, str, str_len, &box_single, NULL, pen_y);
BLI_rctf_union(box, &box_single);
}
void blf_font_boundbox__wrap(
- FontBLF *font, const char *str, size_t len, rctf *box, struct ResultBLF *r_info)
+ FontBLF *font, const char *str, const size_t str_len, rctf *box, struct ResultBLF *r_info)
{
box->xmin = 32000.0f;
box->xmax = -32000.0f;
box->ymin = 32000.0f;
box->ymax = -32000.0f;
- blf_font_wrap_apply(font, str, len, r_info, blf_font_boundbox_wrap_cb, box);
+ blf_font_wrap_apply(font, str, str_len, r_info, blf_font_boundbox_wrap_cb, box);
}
/* blf_font_draw_buffer__wrap */
static void blf_font_draw_buffer__wrap_cb(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
- size_t len,
+ const size_t str_len,
int pen_y,
void *UNUSED(userdata))
{
- blf_font_draw_buffer_ex(font, gc, str, len, NULL, pen_y);
+ blf_font_draw_buffer_ex(font, gc, str, str_len, NULL, pen_y);
}
void blf_font_draw_buffer__wrap(FontBLF *font,
const char *str,
- size_t len,
+ const size_t str_len,
struct ResultBLF *r_info)
{
- blf_font_wrap_apply(font, str, len, r_info, blf_font_draw_buffer__wrap_cb, NULL);
+ blf_font_wrap_apply(font, str, str_len, r_info, blf_font_draw_buffer__wrap_cb, NULL);
}
/** \} */
-void blf_font_width_and_height(FontBLF *font,
- const char *str,
- size_t len,
- float *r_width,
- float *r_height,
- struct ResultBLF *r_info)
+/* -------------------------------------------------------------------- */
+/** \name Text Evaluation: Count Missing Characters
+ * \{ */
+
+int blf_font_count_missing_chars(FontBLF *font,
+ const char *str,
+ const size_t str_len,
+ int *r_tot_chars)
{
- float xa, ya;
- rctf box;
+ int missing = 0;
+ size_t i = 0;
- if (font->flags & BLF_ASPECT) {
- xa = font->aspect[0];
- ya = font->aspect[1];
- }
- else {
- xa = 1.0f;
- ya = 1.0f;
- }
+ *r_tot_chars = 0;
+ while (i < str_len) {
+ unsigned int c;
- if (font->flags & BLF_WORD_WRAP) {
- blf_font_boundbox__wrap(font, str, len, &box, r_info);
- }
- else {
- blf_font_boundbox(font, str, len, &box, r_info);
+ if ((c = str[i]) < GLYPH_ASCII_TABLE_SIZE) {
+ i++;
+ }
+ else if ((c = BLI_str_utf8_as_unicode_step(str, str_len, &i)) != BLI_UTF8_ERR) {
+ if (FT_Get_Char_Index((font)->face, c) == 0) {
+ missing++;
+ }
+ }
+ (*r_tot_chars)++;
}
- *r_width = (BLI_rctf_size_x(&box) * xa);
- *r_height = (BLI_rctf_size_y(&box) * ya);
+ return missing;
}
-float blf_font_width(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
-{
- float xa;
- rctf box;
-
- if (font->flags & BLF_ASPECT) {
- xa = font->aspect[0];
- }
- else {
- xa = 1.0f;
- }
+/** \} */
- if (font->flags & BLF_WORD_WRAP) {
- blf_font_boundbox__wrap(font, str, len, &box, r_info);
- }
- else {
- blf_font_boundbox(font, str, len, &box, r_info);
- }
- return BLI_rctf_size_x(&box) * xa;
-}
+/* -------------------------------------------------------------------- */
+/** \name Font Query: Attributes
+ * \{ */
-float blf_font_height(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+int blf_font_height_max(FontBLF *font)
{
- float ya;
- rctf box;
+ int height_max;
- if (font->flags & BLF_ASPECT) {
- ya = font->aspect[1];
- }
- else {
- ya = 1.0f;
- }
+ GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
+ height_max = gc->glyph_height_max;
- if (font->flags & BLF_WORD_WRAP) {
- blf_font_boundbox__wrap(font, str, len, &box, r_info);
- }
- else {
- blf_font_boundbox(font, str, len, &box, r_info);
- }
- return BLI_rctf_size_y(&box) * ya;
+ blf_glyph_cache_release(font);
+ return height_max;
}
-float blf_font_fixed_width(FontBLF *font)
+int blf_font_width_max(FontBLF *font)
{
- const unsigned int c = ' ';
+ int width_max;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_ensure_ascii_table(font, gc);
-
- GlyphBLF *g = blf_glyph_search(gc, c);
- if (!g) {
- g = blf_glyph_add(font, gc, FT_Get_Char_Index(font->face, c), c);
-
- /* if we don't find the glyph. */
- if (!g) {
- blf_glyph_cache_release(font);
- return 0.0f;
- }
- }
+ width_max = gc->glyph_width_max;
blf_glyph_cache_release(font);
- return g->advance;
+ return width_max;
}
-/* -------------------------------------------------------------------- */
-/** \name Glyph Bound Box with Callback
- * \{ */
-
-static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
- GlyphCacheBLF *gc,
- const char *str,
- size_t len,
- BLF_GlyphBoundsFn user_fn,
- void *user_data,
- struct ResultBLF *r_info,
- int pen_y)
+float blf_font_descender(FontBLF *font)
{
- unsigned int c, c_prev = BLI_UTF8_ERR;
- GlyphBLF *g, *g_prev = NULL;
- int pen_x = 0;
- size_t i = 0, i_curr;
- rcti gbox;
-
- if (len == 0) {
- /* early output. */
- return;
- }
-
- GlyphBLF **glyph_ascii_table = blf_font_ensure_ascii_table(font, gc);
-
- BLF_KERNING_VARS(font, has_kerning, kern_mode);
-
- blf_font_ensure_ascii_kerning(font, gc, kern_mode);
-
- while ((i < len) && str[i]) {
- i_curr = i;
- BLF_UTF8_NEXT_FAST(font, gc, g, str, i, c, glyph_ascii_table);
-
- if (UNLIKELY(c == BLI_UTF8_ERR)) {
- break;
- }
- if (UNLIKELY(g == NULL)) {
- continue;
- }
- if (has_kerning) {
- BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
- }
+ float descender;
- gbox.xmin = pen_x;
- gbox.xmax = gbox.xmin + MIN2(g->advance_i, g->dims[0]);
- gbox.ymin = pen_y;
- gbox.ymax = gbox.ymin - g->dims[1];
+ GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
+ descender = gc->descender;
- pen_x += g->advance_i;
+ blf_glyph_cache_release(font);
+ return descender;
+}
- if (user_fn(str, i_curr, &gbox, g->advance_i, &g->box, g->pos, user_data) == false) {
- break;
- }
+float blf_font_ascender(FontBLF *font)
+{
+ float ascender;
- g_prev = g;
- c_prev = c;
- }
+ GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
+ ascender = gc->ascender;
- if (r_info) {
- r_info->lines = 1;
- r_info->width = pen_x;
- }
+ blf_glyph_cache_release(font);
+ return ascender;
}
-void blf_font_boundbox_foreach_glyph(FontBLF *font,
- const char *str,
- size_t len,
- BLF_GlyphBoundsFn user_fn,
- void *user_data,
- struct ResultBLF *r_info)
+
+char *blf_display_name(FontBLF *font)
{
- GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_boundbox_foreach_glyph_ex(font, gc, str, len, user_fn, user_data, r_info, 0);
- blf_glyph_cache_release(font);
+ if (!font->face->family_name) {
+ return NULL;
+ }
+ return BLI_sprintfN("%s %s", font->face->family_name, font->face->style_name);
}
/** \} */
-int blf_font_count_missing_chars(FontBLF *font,
- const char *str,
- const size_t len,
- int *r_tot_chars)
-{
- int missing = 0;
- size_t i = 0;
-
- *r_tot_chars = 0;
- while (i < len) {
- unsigned int c;
+/* -------------------------------------------------------------------- */
+/** \name Font Subsystem Init/Exit
+ * \{ */
- if ((c = str[i]) < 0x80) {
- i++;
- }
- else if ((c = BLI_str_utf8_as_unicode_step(str, &i)) != BLI_UTF8_ERR) {
- if (FT_Get_Char_Index((font)->face, c) == 0) {
- missing++;
- }
- }
- (*r_tot_chars)++;
- }
- return missing;
+int blf_font_init(void)
+{
+ memset(&g_batch, 0, sizeof(g_batch));
+ BLI_spin_init(&ft_lib_mutex);
+ BLI_spin_init(&blf_glyph_cache_mutex);
+ return FT_Init_FreeType(&ft_lib);
}
-void blf_font_free(FontBLF *font)
+void blf_font_exit(void)
{
- BLI_spin_lock(&blf_glyph_cache_mutex);
- GlyphCacheBLF *gc;
-
- while ((gc = BLI_pophead(&font->cache))) {
- blf_glyph_cache_free(gc);
- }
-
- blf_kerning_cache_clear(font);
+ FT_Done_FreeType(ft_lib);
+ BLI_spin_end(&ft_lib_mutex);
+ BLI_spin_end(&blf_glyph_cache_mutex);
+ blf_batch_draw_exit();
+}
- FT_Done_Face(font->face);
- if (font->filename) {
- MEM_freeN(font->filename);
- }
- if (font->name) {
- MEM_freeN(font->name);
- }
- MEM_freeN(font);
+/** \} */
- BLI_spin_unlock(&blf_glyph_cache_mutex);
-}
+/* -------------------------------------------------------------------- */
+/** \name Font New/Free
+ * \{ */
static void blf_font_fill(FontBLF *font)
{
@@ -1324,7 +1325,6 @@ static void blf_font_fill(FontBLF *font)
font->dpi = 0;
font->size = 0;
BLI_listbase_clear(&font->cache);
- BLI_listbase_clear(&font->kerning_caches);
font->kerning_cache = NULL;
#if BLF_BLUR_ENABLE
font->blur = 0;
@@ -1385,6 +1385,17 @@ FontBLF *blf_font_new(const char *name, const char *filename)
font->name = BLI_strdup(name);
font->filename = BLI_strdup(filename);
blf_font_fill(font);
+
+ if (FT_HAS_KERNING(font->face)) {
+ /* Create kerning cache table and fill with value indicating "unset". */
+ font->kerning_cache = MEM_mallocN(sizeof(KerningCacheBLF), __func__);
+ for (uint i = 0; i < KERNING_CACHE_TABLE_SIZE; i++) {
+ for (uint j = 0; j < KERNING_CACHE_TABLE_SIZE; j++) {
+ font->kerning_cache->ascii_table[i][j] = KERNING_ENTRY_UNSET;
+ }
+ }
+ }
+
return font;
}
@@ -1424,58 +1435,61 @@ FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int m
return font;
}
-int blf_font_height_max(FontBLF *font)
+void blf_font_free(FontBLF *font)
{
- int height_max;
-
- GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_ensure_ascii_table(font, gc);
- height_max = gc->glyph_height_max;
+ BLI_spin_lock(&blf_glyph_cache_mutex);
+ GlyphCacheBLF *gc;
- blf_glyph_cache_release(font);
- return height_max;
-}
+ while ((gc = BLI_pophead(&font->cache))) {
+ blf_glyph_cache_free(gc);
+ }
-int blf_font_width_max(FontBLF *font)
-{
- int width_max;
+ if (font->kerning_cache) {
+ MEM_freeN(font->kerning_cache);
+ }
- GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_ensure_ascii_table(font, gc);
- width_max = gc->glyph_width_max;
+ FT_Done_Face(font->face);
+ if (font->filename) {
+ MEM_freeN(font->filename);
+ }
+ if (font->name) {
+ MEM_freeN(font->name);
+ }
+ MEM_freeN(font);
- blf_glyph_cache_release(font);
- return width_max;
+ BLI_spin_unlock(&blf_glyph_cache_mutex);
}
-float blf_font_descender(FontBLF *font)
-{
- float descender;
-
- GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_ensure_ascii_table(font, gc);
- descender = gc->descender;
+/** \} */
- blf_glyph_cache_release(font);
- return descender;
-}
+/* -------------------------------------------------------------------- */
+/** \name Font Configure
+ * \{ */
-float blf_font_ascender(FontBLF *font)
+void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
{
- float ascender;
+ blf_glyph_cache_acquire(font);
- GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
- blf_font_ensure_ascii_table(font, gc);
- ascender = gc->ascender;
+ GlyphCacheBLF *gc = blf_glyph_cache_find(font, size, dpi);
+ if (gc && (font->size == size && font->dpi == dpi)) {
+ /* Optimization: do not call FT_Set_Char_Size if size did not change. */
+ }
+ else {
+ const FT_Error err = FT_Set_Char_Size(font->face, 0, ((FT_F26Dot6)(size)) * 64, dpi, dpi);
+ if (err) {
+ /* FIXME: here we can go through the fixed size and choice a close one */
+ printf("The current font don't support the size, %u and dpi, %u\n", size, dpi);
+ }
+ else {
+ font->size = size;
+ font->dpi = dpi;
+ if (gc == NULL) {
+ blf_glyph_cache_new(font);
+ }
+ }
+ }
blf_glyph_cache_release(font);
- return ascender;
}
-char *blf_display_name(FontBLF *font)
-{
- if (!font->face->family_name) {
- return NULL;
- }
- return BLI_sprintfN("%s %s", font->face->family_name, font->face->style_name);
-}
+/** \} */
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 3f01501fda4..6cdf5fc5996 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -55,64 +55,6 @@
#include "BLI_math_vector.h"
#include "BLI_strict_flags.h"
-KerningCacheBLF *blf_kerning_cache_find(FontBLF *font)
-{
- KerningCacheBLF *p;
-
- p = (KerningCacheBLF *)font->kerning_caches.first;
- while (p) {
- if (p->mode == font->kerning_mode) {
- return p;
- }
- p = p->next;
- }
- return NULL;
-}
-
-/* Create a new glyph cache for the current kerning mode. */
-KerningCacheBLF *blf_kerning_cache_new(FontBLF *font, GlyphCacheBLF *gc)
-{
- KerningCacheBLF *kc;
-
- kc = (KerningCacheBLF *)MEM_callocN(sizeof(KerningCacheBLF), "blf_kerning_cache_new");
- kc->next = NULL;
- kc->prev = NULL;
- kc->mode = font->kerning_mode;
-
- unsigned int i, j;
- for (i = 0; i < 0x80; i++) {
- for (j = 0; j < 0x80; j++) {
- GlyphBLF *g = blf_glyph_search(gc, i);
- if (!g) {
- FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
- g = blf_glyph_add(font, gc, glyph_index, i);
- }
- /* Can fail on certain fonts */
- GlyphBLF *g_prev = blf_glyph_search(gc, j);
-
- FT_Vector delta = {
- .x = 0,
- .y = 0,
- };
- if (g && g_prev && FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) {
- kc->table[i][j] = (int)delta.x >> 6;
- }
- else {
- kc->table[i][j] = 0;
- }
- }
- }
-
- BLI_addhead(&font->kerning_caches, kc);
- return kc;
-}
-
-void blf_kerning_cache_clear(FontBLF *font)
-{
- font->kerning_cache = NULL;
- BLI_freelistN(&font->kerning_caches);
-}
-
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, unsigned int size, unsigned int dpi)
{
GlyphCacheBLF *p;
@@ -144,8 +86,6 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
memset(gc->bucket, 0, sizeof(gc->bucket));
- gc->glyphs_len_max = (int)font->face->num_glyphs;
- gc->glyphs_len_free = (int)font->face->num_glyphs;
gc->ascender = ((float)font->face->size->metrics.ascender) / 64.0f;
gc->descender = ((float)font->face->size->metrics.descender) / 64.0f;
@@ -514,7 +454,6 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
memcpy(&gc->bitmap_result[gc->bitmap_len], g->bitmap, (size_t)buff_size);
gc->bitmap_len = bitmap_len;
- gc->glyphs_len_free--;
g->glyph_cache = gc;
}
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 35a6d019eac..6fd5e8b7503 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -53,46 +53,55 @@ struct FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem
void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
void blf_font_size(struct FontBLF *font, unsigned int size, unsigned int dpi);
-void blf_font_draw(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
+void blf_font_draw(struct FontBLF *font,
+ const char *str,
+ size_t str_len,
+ struct ResultBLF *r_info);
void blf_font_draw__wrap(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
struct ResultBLF *r_info);
void blf_font_draw_ascii(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
struct ResultBLF *r_info);
-int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth);
+int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t str_len, int cwidth);
void blf_font_draw_buffer(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
struct ResultBLF *r_info);
void blf_font_draw_buffer__wrap(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
struct ResultBLF *r_info);
size_t blf_font_width_to_strlen(
- struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
+ struct FontBLF *font, const char *str, size_t str_len, float width, float *r_width);
size_t blf_font_width_to_rstrlen(
- struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
+ struct FontBLF *font, const char *str, size_t str_len, float width, float *r_width);
void blf_font_boundbox(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
struct rctf *r_box,
struct ResultBLF *r_info);
void blf_font_boundbox__wrap(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
struct rctf *r_box,
struct ResultBLF *r_info);
void blf_font_width_and_height(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
float *r_width,
float *r_height,
struct ResultBLF *r_info);
-float blf_font_width(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
-float blf_font_height(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
+float blf_font_width(struct FontBLF *font,
+ const char *str,
+ size_t str_len,
+ struct ResultBLF *r_info);
+float blf_font_height(struct FontBLF *font,
+ const char *str,
+ size_t str_len,
+ struct ResultBLF *r_info);
float blf_font_fixed_width(struct FontBLF *font);
int blf_font_height_max(struct FontBLF *font);
int blf_font_width_max(struct FontBLF *font);
@@ -103,7 +112,7 @@ char *blf_display_name(struct FontBLF *font);
void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
const char *str,
- size_t len,
+ size_t str_len,
bool (*user_fn)(const char *str,
const size_t str_step_ofs,
const struct rcti *glyph_step_bounds,
@@ -116,15 +125,11 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
int blf_font_count_missing_chars(struct FontBLF *font,
const char *str,
- const size_t len,
+ const size_t str_len,
int *r_tot_chars);
void blf_font_free(struct FontBLF *font);
-struct KerningCacheBLF *blf_kerning_cache_find(struct FontBLF *font);
-struct KerningCacheBLF *blf_kerning_cache_new(struct FontBLF *font, struct GlyphCacheBLF *gc);
-void blf_kerning_cache_clear(struct FontBLF *font);
-
struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font,
unsigned int size,
unsigned int dpi);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 36bb8769306..38d7d7b6e21 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -28,6 +28,15 @@
#define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
+/* Number of characters in GlyphCacheBLF.glyph_ascii_table. */
+#define GLYPH_ASCII_TABLE_SIZE 128
+
+/* Number of characters in KerningCacheBLF.table. */
+#define KERNING_CACHE_TABLE_SIZE 128
+
+/* A value in the kerning cache that indicates it is not yet set. */
+#define KERNING_ENTRY_UNSET INT_MAX
+
typedef struct BatchBLF {
struct FontBLF *font; /* can only batch glyph from the same font */
struct GPUBatch *batch;
@@ -44,14 +53,11 @@ typedef struct BatchBLF {
extern BatchBLF g_batch;
typedef struct KerningCacheBLF {
- struct KerningCacheBLF *next, *prev;
-
- /* kerning mode. */
- FT_UInt mode;
-
- /* only cache a ascii glyph pairs. Only store the x
- * offset we are interested in, instead of the full FT_Vector. */
- int table[0x80][0x80];
+ /**
+ * Cache a ascii glyph pairs. Only store the x offset we are interested in,
+ * instead of the full #FT_Vector since it's not used for drawing at the moment.
+ */
+ int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE];
} KerningCacheBLF;
typedef struct GlyphCacheBLF {
@@ -71,7 +77,7 @@ typedef struct GlyphCacheBLF {
ListBase bucket[257];
/* fast ascii lookup */
- struct GlyphBLF *glyph_ascii_table[256];
+ struct GlyphBLF *glyph_ascii_table[GLYPH_ASCII_TABLE_SIZE];
/* texture array, to draw the glyphs. */
GPUTexture *texture;
@@ -84,12 +90,6 @@ typedef struct GlyphCacheBLF {
int glyph_width_max;
int glyph_height_max;
- /* number of glyphs in the font. */
- int glyphs_len_max;
-
- /* number of glyphs not yet loaded (decreases every glyph loaded). */
- int glyphs_len_free;
-
/* ascender and descender value. */
float ascender;
float descender;
@@ -99,7 +99,7 @@ typedef struct GlyphBLF {
struct GlyphBLF *next;
struct GlyphBLF *prev;
- /* and the character, as UTF8 */
+ /* and the character, as UTF-32 */
unsigned int c;
/* freetype2 index, to speed-up the search. */
@@ -225,10 +225,7 @@ typedef struct FontBLF {
*/
ListBase cache;
- /* list of kerning cache for this font. */
- ListBase kerning_caches;
-
- /* current kerning cache for this font and kerning mode. */
+ /* Cache of unscaled kerning values. Will be NULL if font does not have kerning. */
KerningCacheBLF *kerning_cache;
/* freetype2 lib handle. */
@@ -240,9 +237,6 @@ typedef struct FontBLF {
/* freetype2 face. */
FT_Face face;
- /* freetype kerning */
- FT_UInt kerning_mode;
-
/* data for buffer usage (drawing into a texture buffer) */
FontBufInfoBLF buf_info;
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 5ef56fab9cb..4ed4225c836 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 17
+#define BLENDER_FILE_SUBVERSION 18
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index a6b2aa8540a..836597f95da 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -32,6 +32,7 @@ struct CacheReader;
struct Depsgraph;
struct Main;
struct Object;
+struct Scene;
void BKE_cachefiles_init(void);
void BKE_cachefiles_exit(void);
@@ -60,6 +61,10 @@ void BKE_cachefile_reader_open(struct CacheFile *cache_file,
const char *object_path);
void BKE_cachefile_reader_free(struct CacheFile *cache_file, struct CacheReader **reader);
+bool BKE_cache_file_uses_render_procedural(const struct CacheFile *cache_file,
+ struct Scene *scene,
+ const int dag_eval_mode);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index 8b8d0f7b107..2c7143be60e 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -65,7 +65,7 @@ void BKE_collection_add_from_collection(struct Main *bmain,
struct Scene *scene,
struct Collection *collection_src,
struct Collection *collection_dst);
-void BKE_collection_free(struct Collection *collection);
+void BKE_collection_free_data(struct Collection *collection);
bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy);
struct Collection *BKE_collection_duplicate(struct Main *bmain,
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index 575df93a9fc..784b395dfa5 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -192,6 +192,28 @@ bool BKE_constraint_remove_ex(ListBase *list,
bool clear_dep);
bool BKE_constraint_remove(ListBase *list, struct bConstraint *con);
+bool BKE_constraint_apply_for_object(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ struct bConstraint *con);
+bool BKE_constraint_apply_and_remove_for_object(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ ListBase /*bConstraint*/ *constraints,
+ struct Object *ob,
+ struct bConstraint *con);
+
+bool BKE_constraint_apply_for_pose(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ struct bPoseChannel *pchan,
+ struct bConstraint *con);
+bool BKE_constraint_apply_and_remove_for_pose(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ ListBase /*bConstraint*/ *constraints,
+ struct Object *ob,
+ struct bConstraint *con,
+ struct bPoseChannel *pchan);
+
void BKE_constraint_panel_expand(struct bConstraint *con);
/* Constraints + Proxies function prototypes */
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 92e70b41e7b..b58317f4815 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -93,7 +93,7 @@ void BKE_gpencil_free_stroke(struct bGPDstroke *gps);
bool BKE_gpencil_free_strokes(struct bGPDframe *gpf);
void BKE_gpencil_free_frames(struct bGPDlayer *gpl);
void BKE_gpencil_free_layers(struct ListBase *list);
-void BKE_gpencil_free(struct bGPdata *gpd, bool free_all);
+void BKE_gpencil_free_data(struct bGPdata *gpd, bool free_all);
void BKE_gpencil_eval_delete(struct bGPdata *gpd_eval);
void BKE_gpencil_free_layer_masks(struct bGPDlayer *gpl);
void BKE_gpencil_tag(struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index c1ccae7a437..29e3a74b1b2 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -169,7 +169,8 @@ bool BKE_gpencil_convert_mesh(struct Main *bmain,
const float matrix[4][4],
const int frame_offset,
const bool use_seams,
- const bool use_faces);
+ const bool use_faces,
+ const bool use_vgroups);
void BKE_gpencil_stroke_uniform_subdivide(struct bGPdata *gpd,
struct bGPDstroke *gps,
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index d298e5dcf6d..b62ad3ad24a 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -45,7 +45,7 @@ struct StampData;
struct anim;
#define IMA_MAX_SPACE 64
-#define IMA_UDIM_MAX 1999
+#define IMA_UDIM_MAX 2000
void BKE_images_init(void);
void BKE_images_exit(void);
@@ -56,7 +56,7 @@ void BKE_image_free_buffers(struct Image *image);
void BKE_image_free_buffers_ex(struct Image *image, bool do_lock);
void BKE_image_free_gputextures(struct Image *ima);
/* call from library */
-void BKE_image_free(struct Image *image);
+void BKE_image_free_data(struct Image *image);
typedef void(StampCallback)(void *data, const char *propname, char *propvalue, int len);
@@ -308,6 +308,8 @@ void BKE_image_get_tile_label(struct Image *ima,
struct ImageTile *BKE_image_add_tile(struct Image *ima, int tile_number, const char *label);
bool BKE_image_remove_tile(struct Image *ima, struct ImageTile *tile);
+void BKE_image_reassign_tile(struct Image *ima, struct ImageTile *tile, int new_tile_number);
+void BKE_image_sort_tiles(struct Image *ima);
bool BKE_image_fill_tile(struct Image *ima,
struct ImageTile *tile,
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 70d65e02246..cb4fc607703 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -36,7 +36,7 @@ struct Object;
extern "C" {
#endif
-void BKE_key_free(struct Key *key);
+void BKE_key_free_data(struct Key *key);
void BKE_key_free_nolib(struct Key *key);
struct Key *BKE_key_add(struct Main *bmain, struct ID *id);
void BKE_key_sort(struct Key *key);
diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index fac5dc8c010..a50faedcc3c 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -152,8 +152,6 @@ void BKE_libblock_copy_ex(struct Main *bmain,
const int orig_flag);
void *BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL();
-/* Special version: used by data-block localization. */
-void *BKE_libblock_copy_for_localize(const struct ID *id);
void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
void BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
@@ -168,8 +166,14 @@ struct ID *BKE_libblock_find_name(struct Main *bmain,
*/
typedef enum eLibIDDuplicateFlags {
/** This call to a duplicate function is part of another call for some parent ID.
- * Therefore, this sub-process should not clear `newid` pointers, nor handle remapping itself. */
+ * Therefore, this sub-process should not clear `newid` pointers, nor handle remapping itself.
+ * NOTE: In some cases (like Object one), the duplicate function may be called on the root ID
+ * with this flag set, as remapping and/or other similar tasks need to be handled by the caller.
+ */
LIB_ID_DUPLICATE_IS_SUBPROCESS = 1 << 0,
+ /** This call is performed on a 'root' ID, and should therefore perform some decisions regarding
+ * sub-IDs (dependencies), check for linked vs. locale data, etc. */
+ LIB_ID_DUPLICATE_IS_ROOT_ID = 1 << 1,
} eLibIDDuplicateFlags;
/* lib_remap.c (keep here since they're general functions) */
@@ -201,6 +205,8 @@ enum {
void BKE_libblock_free_datablock(struct ID *id, const int flag) ATTR_NONNULL();
void BKE_libblock_free_data(struct ID *id, const bool do_id_user) ATTR_NONNULL();
+void BKE_libblock_free_data_py(struct ID *id);
+
void BKE_id_free_ex(struct Main *bmain, void *idv, int flag, const bool use_flag_from_idtag);
void BKE_id_free(struct Main *bmain, void *idv);
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index ef1384c804b..dbcefb8b6d5 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -95,7 +95,7 @@ void BKE_mesh_looptri_get_real_edges(const struct Mesh *mesh,
const struct MLoopTri *looptri,
int r_edges[3]);
-void BKE_mesh_free(struct Mesh *me);
+void BKE_mesh_free_data_for_undo(struct Mesh *me);
void BKE_mesh_clear_geometry(struct Mesh *me);
struct Mesh *BKE_mesh_add(struct Main *bmain, const char *name);
void BKE_mesh_copy_parameters_for_eval(struct Mesh *me_dst, const struct Mesh *me_src);
@@ -143,11 +143,6 @@ int BKE_mesh_mface_index_validate(struct MFace *mface,
struct Mesh *BKE_mesh_from_object(struct Object *ob);
void BKE_mesh_assign_object(struct Main *bmain, struct Object *ob, struct Mesh *me);
void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
-void BKE_mesh_from_nurbs_displist(struct Main *bmain,
- struct Object *ob,
- struct ListBase *dispbase,
- const char *obdata_name,
- bool temporary);
void BKE_mesh_to_curve_nurblist(const struct Mesh *me,
struct ListBase *nurblist,
const int edge_users_test);
@@ -281,39 +276,21 @@ void BKE_mesh_recalc_looptri_with_normals(const struct MLoop *mloop,
/* *** mesh_normals.cc *** */
void BKE_mesh_normals_tag_dirty(struct Mesh *mesh);
-void BKE_mesh_calc_normals_mapping_simple(struct Mesh *me);
-void BKE_mesh_calc_normals_mapping(struct MVert *mverts,
- int numVerts,
- const struct MLoop *mloop,
- const struct MPoly *mpolys,
- int numLoops,
- int numPolys,
- float (*r_polyNors)[3],
- const struct MFace *mfaces,
- int numFaces,
- const int *origIndexFace,
- float (*r_faceNors)[3]);
-void BKE_mesh_calc_normals_mapping_ex(struct MVert *mverts,
- int numVerts,
- const struct MLoop *mloop,
- const struct MPoly *mpolys,
- int numLoops,
- int numPolys,
- float (*r_polyNors)[3],
- const struct MFace *mfaces,
- int numFaces,
- const int *origIndexFace,
- float (*r_faceNors)[3],
- const bool only_face_normals);
-void BKE_mesh_calc_normals_poly(struct MVert *mverts,
- float (*r_vertnors)[3],
- int numVerts,
+void BKE_mesh_calc_normals_poly(const struct MVert *mvert,
+ int mvert_len,
const struct MLoop *mloop,
- const struct MPoly *mpolys,
- int numLoops,
- int numPolys,
- float (*r_polyNors)[3],
- const bool only_face_normals);
+ int mloop_len,
+ const struct MPoly *mpoly,
+ int mpoly_len,
+ float (*r_poly_normals)[3]);
+void BKE_mesh_calc_normals_poly_and_vertex(struct MVert *mvert,
+ int mvert_len,
+ const struct MLoop *mloop,
+ int mloop_len,
+ const struct MPoly *mpolys,
+ int mpoly_len,
+ float (*r_poly_normals)[3],
+ float (*r_vert_normals)[3]);
void BKE_mesh_calc_normals(struct Mesh *me);
void BKE_mesh_ensure_normals(struct Mesh *me);
void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 0b4e1191956..8be563e4c96 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -319,8 +319,10 @@ typedef struct ModifierTypeInfo {
* changes.
*
* This function is optional (assumes false if not present).
+ *
+ * The dag_eval_mode should be of type eEvaluationMode.
*/
- bool (*dependsOnTime)(struct ModifierData *md);
+ bool (*dependsOnTime)(struct Scene *scene, struct ModifierData *md, const int dag_eval_mode);
/**
* True when a deform modifier uses normals, the requiredDataMask
@@ -425,7 +427,7 @@ void BKE_modifier_copydata(struct ModifierData *md, struct ModifierData *target)
void BKE_modifier_copydata_ex(struct ModifierData *md,
struct ModifierData *target,
const int flag);
-bool BKE_modifier_depends_ontime(struct ModifierData *md);
+bool BKE_modifier_depends_ontime(struct Scene *scene, struct ModifierData *md, int dag_eval_mode);
bool BKE_modifier_supports_mapping(struct ModifierData *md);
bool BKE_modifier_supports_cage(struct Scene *scene, struct ModifierData *md);
bool BKE_modifier_couldbe_cage(struct Scene *scene, struct ModifierData *md);
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index caa7ab6de0a..06528cd213c 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -111,8 +111,7 @@ typedef struct bNodeSocketTemplate {
#ifdef __cplusplus
namespace blender {
namespace nodes {
-class SocketMFNetworkBuilder;
-class NodeMFNetworkBuilder;
+class NodeMultiFunctionBuilder;
class GeoNodeExecParams;
} // namespace nodes
namespace fn {
@@ -121,18 +120,16 @@ class MFDataType;
} // namespace fn
} // namespace blender
-using NodeExpandInMFNetworkFunction = void (*)(blender::nodes::NodeMFNetworkBuilder &builder);
+using NodeMultiFunctionBuildFunction = void (*)(blender::nodes::NodeMultiFunctionBuilder &builder);
using NodeGeometryExecFunction = void (*)(blender::nodes::GeoNodeExecParams params);
using SocketGetCPPTypeFunction = const blender::fn::CPPType *(*)();
using SocketGetCPPValueFunction = void (*)(const struct bNodeSocket &socket, void *r_value);
using SocketGetGeometryNodesCPPTypeFunction = const blender::fn::CPPType *(*)();
using SocketGetGeometryNodesCPPValueFunction = void (*)(const struct bNodeSocket &socket,
void *r_value);
-using SocketExpandInMFNetworkFunction = void (*)(blender::nodes::SocketMFNetworkBuilder &builder);
#else
-typedef void *NodeExpandInMFNetworkFunction;
-typedef void *SocketExpandInMFNetworkFunction;
+typedef void *NodeMultiFunctionBuildFunction;
typedef void *NodeGeometryExecFunction;
typedef void *SocketGetCPPTypeFunction;
typedef void *SocketGetGeometryNodesCPPTypeFunction;
@@ -196,8 +193,6 @@ typedef struct bNodeSocketType {
/* Callback to free the socket type. */
void (*free_self)(struct bNodeSocketType *stype);
- /* Expands the socket into a multi-function node that outputs the socket value. */
- SocketExpandInMFNetworkFunction expand_in_mf_network;
/* Return the CPPType of this socket. */
SocketGetCPPTypeFunction get_base_cpp_type;
/* Get the value of this socket in a generic way. */
@@ -332,8 +327,8 @@ typedef struct bNodeType {
/* gpu */
NodeGPUExecFunction gpu_fn;
- /* Expands the bNode into nodes in a multi-function network, which will be evaluated later on. */
- NodeExpandInMFNetworkFunction expand_in_mf_network;
+ /* Build a multi-function for this node. */
+ NodeMultiFunctionBuildFunction build_multi_function;
/* Execute a geometry node. */
NodeGeometryExecFunction geometry_node_execute;
@@ -351,7 +346,7 @@ typedef struct bNodeType {
#define NODE_CLASS_OP_FILTER 5
#define NODE_CLASS_GROUP 6
// #define NODE_CLASS_FILE 7
-#define NODE_CLASS_CONVERTOR 8
+#define NODE_CLASS_CONVERTER 8
#define NODE_CLASS_MATTE 9
#define NODE_CLASS_DISTORT 10
// #define NODE_CLASS_OP_DYNAMIC 11 /* deprecated */
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 4724e6dfab6..a823602e341 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -401,7 +401,10 @@ void BKE_object_groups_clear(struct Main *bmain, struct Scene *scene, struct Obj
struct KDTree_3d *BKE_object_as_kdtree(struct Object *ob, int *r_tot);
-bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md);
+bool BKE_object_modifier_use_time(struct Scene *scene,
+ struct Object *ob,
+ struct ModifierData *md,
+ int dag_eval_mode);
bool BKE_object_modifier_update_subframe(struct Depsgraph *depsgraph,
struct Scene *scene,
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index e5b547d2557..78a6e47ec48 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -368,7 +368,10 @@ struct ModifierData *object_copy_particle_system(struct Main *bmain,
struct Scene *scene,
struct Object *ob,
const struct ParticleSystem *psys_orig);
-void object_remove_particle_system(struct Main *bmain, struct Scene *scene, struct Object *ob);
+void object_remove_particle_system(struct Main *bmain,
+ struct Scene *scene,
+ struct Object *ob,
+ struct ParticleSystem *psys);
struct ParticleSettings *BKE_particlesettings_add(struct Main *bmain, const char *name);
void psys_reset(struct ParticleSystem *psys, int mode);
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 6d58e165ea3..83ce5e72794 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -174,6 +174,10 @@ bool BKE_scene_uses_blender_eevee(const struct Scene *scene);
bool BKE_scene_uses_blender_workbench(const struct Scene *scene);
bool BKE_scene_uses_cycles(const struct Scene *scene);
+/* Return whether the Cycles experimental feature is enabled. It is invalid to call without first
+ * ensuring that Cycles is the active render engine (e.g. with BKE_scene_uses_cycles). */
+bool BKE_scene_uses_cycles_experimental_features(struct Scene *scene);
+
void BKE_scene_copy_data_eevee(struct Scene *sce_dst, const struct Scene *sce_src);
void BKE_scene_disable_color_management(struct Scene *scene);
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 0b08bbfeff5..6f341a12b82 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -473,7 +473,7 @@ void BKE_screen_view3d_shading_init(struct View3DShading *shading);
/* screen */
void BKE_screen_foreach_id_screen_area(struct LibraryForeachIDData *data, struct ScrArea *area);
-void BKE_screen_free(struct bScreen *screen);
+void BKE_screen_free_data(struct bScreen *screen);
void BKE_screen_area_map_free(struct ScrAreaMap *area_map) ATTR_NONNULL();
struct ScrEdge *BKE_screen_find_edge(const struct bScreen *screen,
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index 57ce33a239f..4b257b3b8ab 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -97,6 +97,7 @@ typedef struct SoundInfo {
eSoundChannels channels;
} specs;
float length;
+ double start_offset;
} SoundInfo;
/* Get information about given sound. Returns truth on success., false if sound can not be loaded
@@ -139,8 +140,12 @@ void BKE_sound_remove_scene_sound(struct Scene *scene, void *handle);
void BKE_sound_mute_scene_sound(void *handle, char mute);
-void BKE_sound_move_scene_sound(
- struct Scene *scene, void *handle, int startframe, int endframe, int frameskip);
+void BKE_sound_move_scene_sound(struct Scene *scene,
+ void *handle,
+ int startframe,
+ int endframe,
+ int frameskip,
+ double audio_offset);
void BKE_sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence);
void BKE_sound_update_scene_sound(void *handle, struct bSound *sound);
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index ba8cf8debe9..59e81938e79 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -360,7 +360,7 @@ void DM_init(DerivedMesh *dm,
dm->needsFree = 1;
dm->dirty = (DMDirtyFlag)0;
- /* Don't use CustomData_reset(...); because we don't want to touch custom-data. */
+ /* Don't use #CustomData_reset because we don't want to touch custom-data. */
copy_vn_i(dm->vertData.typemap, CD_NUMTYPES, -1);
copy_vn_i(dm->edgeData.typemap, CD_NUMTYPES, -1);
copy_vn_i(dm->faceData.typemap, CD_NUMTYPES, -1);
@@ -816,15 +816,14 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) {
float(*polynors)[3] = (float(*)[3])CustomData_add_layer(
&mesh_final->pdata, CD_NORMAL, CD_CALLOC, nullptr, mesh_final->totpoly);
- BKE_mesh_calc_normals_poly(mesh_final->mvert,
- nullptr,
- mesh_final->totvert,
- mesh_final->mloop,
- mesh_final->mpoly,
- mesh_final->totloop,
- mesh_final->totpoly,
- polynors,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(mesh_final->mvert,
+ mesh_final->totvert,
+ mesh_final->mloop,
+ mesh_final->totloop,
+ mesh_final->mpoly,
+ mesh_final->totpoly,
+ polynors,
+ nullptr);
}
}
@@ -1536,15 +1535,14 @@ static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) {
float(*polynors)[3] = (float(*)[3])CustomData_add_layer(
&mesh_final->pdata, CD_NORMAL, CD_CALLOC, nullptr, mesh_final->totpoly);
- BKE_mesh_calc_normals_poly(mesh_final->mvert,
- nullptr,
- mesh_final->totvert,
- mesh_final->mloop,
- mesh_final->mpoly,
- mesh_final->totloop,
- mesh_final->totpoly,
- polynors,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(mesh_final->mvert,
+ mesh_final->totvert,
+ mesh_final->mloop,
+ mesh_final->totloop,
+ mesh_final->mpoly,
+ mesh_final->totpoly,
+ polynors,
+ nullptr);
}
}
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index d55f023d209..981815f400a 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -186,22 +186,21 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data)
static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bAction *act = (bAction *)id;
- if (act->id.us > 0 || BLO_write_is_undo(writer)) {
- BLO_write_id_struct(writer, bAction, id_address, &act->id);
- BKE_id_blend_write(writer, &act->id);
- BKE_fcurve_blend_write(writer, &act->curves);
+ BLO_write_id_struct(writer, bAction, id_address, &act->id);
+ BKE_id_blend_write(writer, &act->id);
- LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
- BLO_write_struct(writer, bActionGroup, grp);
- }
+ BKE_fcurve_blend_write(writer, &act->curves);
- LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
- BLO_write_struct(writer, TimeMarker, marker);
- }
+ LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
+ BLO_write_struct(writer, bActionGroup, grp);
+ }
- BKE_previewimg_blend_write(writer, act->preview);
+ LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
+ BLO_write_struct(writer, TimeMarker, marker);
}
+
+ BKE_previewimg_blend_write(writer, act->preview);
}
static void action_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 10a865880f2..92b0db5b214 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -2671,7 +2671,7 @@ static void animsys_create_action_track_strip(const AnimData *adt,
static bool is_nlatrack_evaluatable(const AnimData *adt, const NlaTrack *nlt)
{
/* Skip disabled tracks unless it contains the tweaked strip. */
- const bool contains_tweak_strip = (adt->flag & ADT_NLA_EDIT_ON) &&
+ const bool contains_tweak_strip = (adt->flag & ADT_NLA_EDIT_ON) && adt->act_track &&
(nlt->index == adt->act_track->index);
if ((nlt->flag & NLATRACK_DISABLED) && !contains_tweak_strip) {
return false;
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 1f02b084534..87320c88b1b 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -212,25 +212,24 @@ static void write_bone(BlendWriter *writer, Bone *bone)
static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bArmature *arm = (bArmature *)id;
- if (arm->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- arm->bonehash = NULL;
- arm->edbo = NULL;
- /* Must always be cleared (armatures don't have their own edit-data). */
- arm->needs_flush_to_id = 0;
- arm->act_edbone = NULL;
- BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
- BKE_id_blend_write(writer, &arm->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ arm->bonehash = NULL;
+ arm->edbo = NULL;
+ /* Must always be cleared (armatures don't have their own edit-data). */
+ arm->needs_flush_to_id = 0;
+ arm->act_edbone = NULL;
- if (arm->adt) {
- BKE_animdata_blend_write(writer, arm->adt);
- }
+ BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
+ BKE_id_blend_write(writer, &arm->id);
- /* Direct data */
- LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
- write_bone(writer, bone);
- }
+ if (arm->adt) {
+ BKE_animdata_blend_write(writer, arm->adt);
+ }
+
+ /* Direct data */
+ LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
+ write_bone(writer, bone);
}
}
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 61827be08e5..1c5d8804280 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -660,10 +660,6 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
BKE_studiolight_default(userdef->light_param, userdef->light_ambient);
BKE_preferences_asset_library_default_add(userdef);
- /* Enable asset browser features by default for alpha testing.
- * BLO_sanitize_experimental_features_userpref_blend() will disable it again for non-alpha
- * builds. */
- userdef->experimental.use_asset_browser = true;
return userdef;
}
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 3418e37642c..7b81187be21 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -202,48 +202,47 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Brush *brush = (Brush *)id;
- if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
- BLO_write_id_struct(writer, Brush, id_address, &brush->id);
- BKE_id_blend_write(writer, &brush->id);
- if (brush->curve) {
- BKE_curvemapping_blend_write(writer, brush->curve);
- }
+ BLO_write_id_struct(writer, Brush, id_address, &brush->id);
+ BKE_id_blend_write(writer, &brush->id);
- if (brush->gpencil_settings) {
- BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
+ if (brush->curve) {
+ BKE_curvemapping_blend_write(writer, brush->curve);
+ }
- if (brush->gpencil_settings->curve_sensitivity) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity);
- }
- if (brush->gpencil_settings->curve_strength) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength);
- }
- if (brush->gpencil_settings->curve_jitter) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter);
- }
- if (brush->gpencil_settings->curve_rand_pressure) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure);
- }
- if (brush->gpencil_settings->curve_rand_strength) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength);
- }
- if (brush->gpencil_settings->curve_rand_uv) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv);
- }
- if (brush->gpencil_settings->curve_rand_hue) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue);
- }
- if (brush->gpencil_settings->curve_rand_saturation) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation);
- }
- if (brush->gpencil_settings->curve_rand_value) {
- BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value);
- }
+ if (brush->gpencil_settings) {
+ BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
+
+ if (brush->gpencil_settings->curve_sensitivity) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity);
}
- if (brush->gradient) {
- BLO_write_struct(writer, ColorBand, brush->gradient);
+ if (brush->gpencil_settings->curve_strength) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength);
}
+ if (brush->gpencil_settings->curve_jitter) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter);
+ }
+ if (brush->gpencil_settings->curve_rand_pressure) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure);
+ }
+ if (brush->gpencil_settings->curve_rand_strength) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength);
+ }
+ if (brush->gpencil_settings->curve_rand_uv) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv);
+ }
+ if (brush->gpencil_settings->curve_rand_hue) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue);
+ }
+ if (brush->gpencil_settings->curve_rand_saturation) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation);
+ }
+ if (brush->gpencil_settings->curve_rand_value) {
+ BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value);
+ }
+ }
+ if (brush->gradient) {
+ BLO_write_struct(writer, ColorBand, brush->gradient);
}
}
diff --git a/source/blender/blenkernel/intern/bvhutils.cc b/source/blender/blenkernel/intern/bvhutils.cc
index 164f921c7ac..707201207d9 100644
--- a/source/blender/blenkernel/intern/bvhutils.cc
+++ b/source/blender/blenkernel/intern/bvhutils.cc
@@ -1254,11 +1254,10 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data,
bool in_cache = bvhcache_find(
bvh_cache_p, bvh_cache_type, &tree, &lock_started, mesh_eval_mutex);
BVHCache *bvh_cache = *bvh_cache_p;
- bvhtree_balance(tree, true);
-
if (in_cache == false) {
tree = bvhtree_from_editmesh_looptri_create_tree(
epsilon, tree_type, axis, em, looptri_mask, looptri_num_active);
+ bvhtree_balance(tree, true);
/* Save on cache for later use */
// printf("BVHTree built and saved on cache\n");
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 75180de94d8..87b1584d422 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -49,6 +49,8 @@
#include "DEG_depsgraph_query.h"
+#include "RE_engine.h"
+
#include "BLO_read_write.h"
#ifdef WITH_ALEMBIC
@@ -95,19 +97,18 @@ static void cache_file_free_data(ID *id)
static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
CacheFile *cache_file = (CacheFile *)id;
- if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- BLI_listbase_clear(&cache_file->object_paths);
- cache_file->handle = NULL;
- memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
- cache_file->handle_readers = NULL;
- BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
- BKE_id_blend_write(writer, &cache_file->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ BLI_listbase_clear(&cache_file->object_paths);
+ cache_file->handle = NULL;
+ memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
+ cache_file->handle_readers = NULL;
+
+ BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
+ BKE_id_blend_write(writer, &cache_file->id);
- if (cache_file->adt) {
- BKE_animdata_blend_write(writer, cache_file->adt);
- }
+ if (cache_file->adt) {
+ BKE_animdata_blend_write(writer, cache_file->adt);
}
}
@@ -367,7 +368,7 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file
#endif
if (DEG_is_active(depsgraph)) {
- /* Flush object paths back to original datablock for UI. */
+ /* Flush object paths back to original data-block for UI. */
CacheFile *cache_file_orig = (CacheFile *)DEG_get_original_id(&cache_file->id);
BLI_freelistN(&cache_file_orig->object_paths);
BLI_duplicatelist(&cache_file_orig->object_paths, &cache_file->object_paths);
@@ -409,3 +410,25 @@ float BKE_cachefile_time_offset(const CacheFile *cache_file, const float time, c
const float frame = (cache_file->override_frame ? cache_file->frame : time);
return cache_file->is_sequence ? frame : frame / fps - time_offset;
}
+
+/**
+ * Determine whether the #CacheFile should use a render engine procedural. If so, data is not read
+ * from the file and bounding boxes are used to represent the objects in the Scene.
+ * Render engines will receive the bounding box as a placeholder but can instead
+ * load the data directly if they support it.
+ */
+bool BKE_cache_file_uses_render_procedural(const CacheFile *cache_file,
+ Scene *scene,
+ const int dag_eval_mode)
+{
+ RenderEngineType *render_engine_type = RE_engines_find(scene->r.engine);
+
+ if (cache_file->type != CACHEFILE_TYPE_ALEMBIC ||
+ !RE_engine_supports_alembic_procedural(render_engine_type, scene)) {
+ return false;
+ }
+
+ /* The render time procedural is only enabled during viewport rendering. */
+ const bool is_final_render = (eEvaluationMode)dag_eval_mode == DAG_EVAL_RENDER;
+ return cache_file->use_render_procedural && !is_final_render;
+}
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 5172b067eba..b77855f8f95 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -92,11 +92,6 @@ static void camera_copy_data(Main *UNUSED(bmain),
BLI_duplicatelist(&cam_dst->bg_images, &cam_src->bg_images);
}
-static void camera_make_local(Main *bmain, ID *id, const int flags)
-{
- BKE_lib_id_make_local_generic(bmain, id, flags);
-}
-
/** Free (or release) any data used by this camera (does not free the camera itself). */
static void camera_free_data(ID *id)
{
@@ -122,18 +117,17 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Camera *cam = (Camera *)id;
- if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, Camera, id_address, &cam->id);
- BKE_id_blend_write(writer, &cam->id);
- if (cam->adt) {
- BKE_animdata_blend_write(writer, cam->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Camera, id_address, &cam->id);
+ BKE_id_blend_write(writer, &cam->id);
- LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
- BLO_write_struct(writer, CameraBGImage, bgpic);
- }
+ if (cam->adt) {
+ BKE_animdata_blend_write(writer, cam->adt);
+ }
+
+ LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
+ BLO_write_struct(writer, CameraBGImage, bgpic);
}
}
@@ -193,7 +187,7 @@ IDTypeInfo IDType_ID_CA = {
.init_data = camera_init_data,
.copy_data = camera_copy_data,
.free_data = camera_free_data,
- .make_local = camera_make_local,
+ .make_local = NULL,
.foreach_id = camera_foreach_id,
.foreach_cache = NULL,
.owner_get = NULL,
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index f5ff936e18b..080a7c90c46 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -42,6 +42,7 @@
#include "BKE_cloth.h"
#include "BKE_effect.h"
#include "BKE_global.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_modifier.h"
@@ -1574,7 +1575,7 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
BLI_edgeset_free(existing_vert_pairs);
free_bvhtree_from_mesh(&treedata);
if (tmp_mesh) {
- BKE_mesh_free(tmp_mesh);
+ BKE_id_free(NULL, &tmp_mesh->id);
}
return false;
}
@@ -1583,7 +1584,7 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
BLI_edgeset_free(existing_vert_pairs);
free_bvhtree_from_mesh(&treedata);
if (tmp_mesh) {
- BKE_mesh_free(tmp_mesh);
+ BKE_id_free(NULL, &tmp_mesh->id);
}
BLI_rng_free(rng);
}
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index dbcd80fe065..2d172f23428 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -214,20 +214,19 @@ void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collectio
static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Collection *collection = (Collection *)id;
- if (collection->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
- collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
- collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
- collection->tag = 0;
- BLI_listbase_clear(&collection->object_cache);
- BLI_listbase_clear(&collection->object_cache_instanced);
- BLI_listbase_clear(&collection->parents);
- /* write LibData */
- BLO_write_id_struct(writer, Collection, id_address, &collection->id);
+ /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
+ collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
+ collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
+ collection->tag = 0;
+ BLI_listbase_clear(&collection->object_cache);
+ BLI_listbase_clear(&collection->object_cache_instanced);
+ BLI_listbase_clear(&collection->parents);
- BKE_collection_blend_write_nolib(writer, collection);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Collection, id_address, &collection->id);
+
+ BKE_collection_blend_write_nolib(writer, collection);
}
#ifdef USE_COLLECTION_COMPAT_28
@@ -508,7 +507,7 @@ void BKE_collection_add_from_collection(Main *bmain,
* \{ */
/** Free (or release) any data used by this collection (does not free the collection itself). */
-void BKE_collection_free(Collection *collection)
+void BKE_collection_free_data(Collection *collection)
{
BKE_libblock_free_data(&collection->id, false);
collection_free_data(&collection->id);
@@ -693,14 +692,18 @@ Collection *BKE_collection_duplicate(Main *bmain,
eLibIDDuplicateFlags duplicate_options)
{
const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
+ const bool is_root_id = (duplicate_options & LIB_ID_DUPLICATE_IS_ROOT_ID) != 0;
if (!is_subprocess) {
BKE_main_id_newptr_and_tag_clear(bmain);
+ }
+ if (is_root_id) {
/* In case root duplicated ID is linked, assume we want to get a local copy of it and duplicate
* all expected linked data. */
if (ID_IS_LINKED(collection)) {
duplicate_flags |= USER_DUP_LINKED_ID;
}
+ duplicate_options &= ~LIB_ID_DUPLICATE_IS_ROOT_ID;
}
Collection *collection_new = collection_duplicate_recursive(
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 0da29ded13d..30aa22387d0 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -5430,6 +5430,11 @@ static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBa
return;
}
+ /* Do not process data if using a render time procedural. */
+ if (BKE_cache_file_uses_render_procedural(cache_file, scene, DEG_get_mode(cob->depsgraph))) {
+ return;
+ }
+
const float frame = DEG_get_ctime(cob->depsgraph);
const float time = BKE_cachefile_time_offset(cache_file, frame, FPS);
@@ -5677,6 +5682,111 @@ bool BKE_constraint_remove_ex(ListBase *list, Object *ob, bConstraint *con, bool
return false;
}
+/* Apply the specified constraint in the given constraint stack */
+bool BKE_constraint_apply_for_object(Depsgraph *depsgraph,
+ Scene *scene,
+ Object *ob,
+ bConstraint *con)
+{
+ if (!con) {
+ return false;
+ }
+
+ const float ctime = BKE_scene_frame_get(scene);
+
+ bConstraint *new_con = BKE_constraint_duplicate_ex(con, 0, !ID_IS_LINKED(ob));
+ ListBase single_con = {new_con, new_con};
+
+ bConstraintOb *cob = BKE_constraints_make_evalob(
+ depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
+ /* Undo the effect of the current constraint stack evaluation. */
+ mul_m4_m4m4(cob->matrix, ob->constinv, cob->matrix);
+
+ /* Evaluate single constraint. */
+ BKE_constraints_solve(depsgraph, &single_con, cob, ctime);
+ /* Copy transforms back. This will leave the object in a bad state
+ * as ob->constinv will be wrong until next evaluation. */
+ BKE_constraints_clear_evalob(cob);
+
+ /* Free the copied constraint. */
+ BKE_constraint_free_data(new_con);
+ BLI_freelinkN(&single_con, new_con);
+
+ /* Apply transform from matrix. */
+ BKE_object_apply_mat4(ob, ob->obmat, true, true);
+
+ return true;
+}
+
+bool BKE_constraint_apply_and_remove_for_object(Depsgraph *depsgraph,
+ Scene *scene,
+ ListBase /*bConstraint*/ *constraints,
+ Object *ob,
+ bConstraint *con)
+{
+ if (!BKE_constraint_apply_for_object(depsgraph, scene, ob, con)) {
+ return false;
+ }
+
+ return BKE_constraint_remove_ex(constraints, ob, con, true);
+}
+
+bool BKE_constraint_apply_for_pose(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
+{
+ if (!con) {
+ return false;
+ }
+
+ const float ctime = BKE_scene_frame_get(scene);
+
+ bConstraint *new_con = BKE_constraint_duplicate_ex(con, 0, !ID_IS_LINKED(ob));
+ ListBase single_con;
+ single_con.first = new_con;
+ single_con.last = new_con;
+
+ float vec[3];
+ copy_v3_v3(vec, pchan->pose_mat[3]);
+
+ bConstraintOb *cob = BKE_constraints_make_evalob(
+ depsgraph, scene, ob, pchan, CONSTRAINT_OBTYPE_BONE);
+ /* Undo the effects of currently applied constraints. */
+ mul_m4_m4m4(cob->matrix, pchan->constinv, cob->matrix);
+ /* Evaluate single constraint. */
+ BKE_constraints_solve(depsgraph, &single_con, cob, ctime);
+ BKE_constraints_clear_evalob(cob);
+
+ /* Free the copied constraint. */
+ BKE_constraint_free_data(new_con);
+ BLI_freelinkN(&single_con, new_con);
+
+ /* Prevent constraints breaking a chain. */
+ if (pchan->bone->flag & BONE_CONNECTED) {
+ copy_v3_v3(pchan->pose_mat[3], vec);
+ }
+
+ /* Apply transform from matrix. */
+ float mat[4][4];
+ BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, mat);
+ BKE_pchan_apply_mat4(pchan, mat, true);
+
+ return true;
+}
+
+bool BKE_constraint_apply_and_remove_for_pose(Depsgraph *depsgraph,
+ Scene *scene,
+ ListBase /*bConstraint*/ *constraints,
+ Object *ob,
+ bConstraint *con,
+ bPoseChannel *pchan)
+{
+ if (!BKE_constraint_apply_for_pose(depsgraph, scene, ob, pchan, con)) {
+ return false;
+ }
+
+ return BKE_constraint_remove_ex(constraints, ob, con, true);
+}
+
void BKE_constraint_panel_expand(bConstraint *con)
{
con->ui_expand_flag |= UI_PANEL_DATA_EXPAND_ROOT;
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 49c81d793c3..397838e6904 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -146,51 +146,50 @@ static void curve_foreach_id(ID *id, LibraryForeachIDData *data)
static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Curve *cu = (Curve *)id;
- if (cu->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- cu->editnurb = NULL;
- cu->editfont = NULL;
- cu->batch_cache = NULL;
- /* write LibData */
- BLO_write_id_struct(writer, Curve, id_address, &cu->id);
- BKE_id_blend_write(writer, &cu->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ cu->editnurb = NULL;
+ cu->editfont = NULL;
+ cu->batch_cache = NULL;
- /* direct data */
- BLO_write_pointer_array(writer, cu->totcol, cu->mat);
- if (cu->adt) {
- BKE_animdata_blend_write(writer, cu->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Curve, id_address, &cu->id);
+ BKE_id_blend_write(writer, &cu->id);
+
+ /* direct data */
+ BLO_write_pointer_array(writer, cu->totcol, cu->mat);
+ if (cu->adt) {
+ BKE_animdata_blend_write(writer, cu->adt);
+ }
- if (cu->vfont) {
- BLO_write_raw(writer, cu->len + 1, cu->str);
- BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo);
- BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
+ if (cu->vfont) {
+ BLO_write_raw(writer, cu->len + 1, cu->str);
+ BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo);
+ BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
+ }
+ else {
+ /* is also the order of reading */
+ LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
+ BLO_write_struct(writer, Nurb, nu);
}
- else {
- /* is also the order of reading */
- LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
- BLO_write_struct(writer, Nurb, nu);
+ LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
+ if (nu->type == CU_BEZIER) {
+ BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
}
- LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
- if (nu->type == CU_BEZIER) {
- BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
+ else {
+ BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
+ if (nu->knotsu) {
+ BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
}
- else {
- BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
- if (nu->knotsu) {
- BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
- }
- if (nu->knotsv) {
- BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
- }
+ if (nu->knotsv) {
+ BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
}
}
}
+ }
- if (cu->bevel_profile != NULL) {
- BKE_curveprofile_blend_write(writer, cu->bevel_profile);
- }
+ if (cu->bevel_profile != NULL) {
+ BKE_curveprofile_blend_write(writer, cu->bevel_profile);
}
}
@@ -638,7 +637,7 @@ void BKE_nurb_free(Nurb *nu)
MEM_freeN(nu->knotsv);
}
nu->knotsv = NULL;
- /* if (nu->trim.first) freeNurblist(&(nu->trim)); */
+ // if (nu->trim.first) freeNurblist(&(nu->trim));
MEM_freeN(nu);
}
@@ -2331,17 +2330,21 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1;
- nr = bl->nr;
- while (nr--) {
+ /* The ordinal of the point being adjusted (bevp2). First point is 1. */
- if (nr + 3 > bl->nr) { /* first time and second time, otherwise first point adjusts last */
- vec_to_quat(bevp1->quat, bevp1->dir, 5, 1);
- }
- else {
- minimum_twist_between_two_points(bevp1, bevp0);
- }
+ /* First point is the reference, don't adjust.
+ * Skip this point in the following loop. */
+ if (bl->nr > 0) {
+ vec_to_quat(bevp2->quat, bevp2->dir, 5, 1);
- bevp0 = bevp1;
+ bevp0 = bevp1; /* bevp0 is unused */
+ bevp1 = bevp2;
+ bevp2++;
+ }
+ for (nr = 1; nr < bl->nr; nr++) {
+ minimum_twist_between_two_points(bevp2, bevp1);
+
+ bevp0 = bevp1; /* bevp0 is unused */
bevp1 = bevp2;
bevp2++;
}
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index a9a8fd7410a..1a3200a9b6c 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -4246,7 +4246,7 @@ void CustomData_blend_write_prepare(CustomData *data,
CustomDataLayer *layer = &data->layers[i];
if (layer->flag & CD_FLAG_NOCOPY) { /* Layers with this flag set are not written to file. */
data->totlayer--;
- /* CLOG_WARN(&LOG, "skipping layer %p (%s)", layer, layer->name); */
+ // CLOG_WARN(&LOG, "skipping layer %p (%s)", layer, layer->name);
}
else {
if (UNLIKELY((size_t)j >= write_layers_size)) {
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 605061570b8..b83621e8b79 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -301,14 +301,12 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
}
if (dirty_nors_dst || do_poly_nors_dst) {
BKE_mesh_calc_normals_poly(verts_dst,
- NULL,
num_verts_dst,
loops_dst,
- polys_dst,
num_loops_dst,
+ polys_dst,
num_polys_dst,
- poly_nors_dst,
- true);
+ poly_nors_dst);
}
/* Cache loop nors into a temp CDLayer. */
loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL);
diff --git a/source/blender/blenkernel/intern/displist.cc b/source/blender/blenkernel/intern/displist.cc
index 99dc1db9d38..c97e07ad487 100644
--- a/source/blender/blenkernel/intern/displist.cc
+++ b/source/blender/blenkernel/intern/displist.cc
@@ -1003,7 +1003,7 @@ static void curve_calc_modifiers_post(Depsgraph *depsgraph,
modified = temp_mesh;
BKE_mesh_vert_coords_apply(modified, vertCos);
- BKE_mesh_calc_normals_mapping_simple(modified);
+ BKE_mesh_calc_normals(modified);
MEM_freeN(vertCos);
}
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 37fc14911fe..c1765967238 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -126,23 +126,22 @@ static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{
VFont *vf = (VFont *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (vf->id.us > 0 || is_undo) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- vf->data = NULL;
- vf->temp_pf = NULL;
-
- /* Do not store packed files in case this is a library override ID. */
- if (ID_IS_OVERRIDE_LIBRARY(vf) && !is_undo) {
- vf->packedfile = NULL;
- }
- /* write LibData */
- BLO_write_id_struct(writer, VFont, id_address, &vf->id);
- BKE_id_blend_write(writer, &vf->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ vf->data = NULL;
+ vf->temp_pf = NULL;
- /* direct data */
- BKE_packedfile_blend_write(writer, vf->packedfile);
+ /* Do not store packed files in case this is a library override ID. */
+ if (ID_IS_OVERRIDE_LIBRARY(vf) && !is_undo) {
+ vf->packedfile = NULL;
}
+
+ /* write LibData */
+ BLO_write_id_struct(writer, VFont, id_address, &vf->id);
+ BKE_id_blend_write(writer, &vf->id);
+
+ /* direct data */
+ BKE_packedfile_blend_write(writer, vf->packedfile);
}
static void vfont_blend_read_data(BlendDataReader *reader, ID *id)
@@ -715,6 +714,13 @@ typedef struct VFontToCurveIter {
float max;
} bisect;
bool ok;
+ /**
+ * Wrap words that extends beyond the text-box width (enabled by default).
+ *
+ * Currently only disabled when scale-to-fit is enabled,
+ * so floating-point error doesn't cause unexpected wrapping, see T89241.
+ */
+ bool word_wrap;
int status;
} VFontToCurveIter;
@@ -777,6 +783,7 @@ static bool vfont_to_curve(Object *ob,
char32_t ascii;
bool ok = false;
const float font_size = cu->fsize * iter_data->scale_to_fit;
+ const bool word_wrap = iter_data->word_wrap;
const float xof_scale = cu->xof / font_size;
const float yof_scale = cu->yof / font_size;
int last_line = -1;
@@ -947,43 +954,59 @@ static bool vfont_to_curve(Object *ob,
twidth = char_width(cu, che, info);
- /* Calculate positions */
- if ((tb_scale.w != 0.0f) && (ct->dobreak == 0) &&
- (((xof - tb_scale.x) + twidth) > xof_scale + tb_scale.w)) {
- // CLOG_WARN(&LOG, "linewidth exceeded: %c%c%c...", mem[i], mem[i+1], mem[i+2]);
- for (j = i; j && (mem[j] != '\n') && (chartransdata[j].dobreak == 0); j--) {
- bool dobreak = false;
- if (ELEM(mem[j], ' ', '-')) {
- ct -= (i - (j - 1));
- cnr -= (i - (j - 1));
- if (mem[j] == ' ') {
- wsnr--;
+ /* Calculate positions. */
+
+ if ((tb_scale.w != 0.0f) && (ct->dobreak == 0)) { /* May need wrapping. */
+ const float x_available = xof_scale + tb_scale.w;
+ const float x_used = (xof - tb_scale.x) + twidth;
+
+ if (word_wrap == false) {
+ /* When scale to fit is used, don't do any wrapping.
+ *
+ * Floating precision error can cause the text to be slightly larger.
+ * Assert this is a small value as large values indicate incorrect
+ * calculations with scale-to-fit which shouldn't be ignored. See T89241. */
+ if (x_used > x_available) {
+ BLI_assert_msg(compare_ff_relative(x_used, x_available, FLT_EPSILON, 64),
+ "VFontToCurveIter.scale_to_fit not set correctly!");
+ }
+ }
+ else if (x_used > x_available) {
+ // CLOG_WARN(&LOG, "linewidth exceeded: %c%c%c...", mem[i], mem[i+1], mem[i+2]);
+ for (j = i; j && (mem[j] != '\n') && (chartransdata[j].dobreak == 0); j--) {
+ bool dobreak = false;
+ if (ELEM(mem[j], ' ', '-')) {
+ ct -= (i - (j - 1));
+ cnr -= (i - (j - 1));
+ if (mem[j] == ' ') {
+ wsnr--;
+ }
+ if (mem[j] == '-') {
+ wsnr++;
+ }
+ i = j - 1;
+ xof = ct->xof;
+ ct[1].dobreak = 1;
+ custrinfo[i + 1].flag |= CU_CHINFO_WRAP;
+ dobreak = true;
}
- if (mem[j] == '-') {
- wsnr++;
+ else if (chartransdata[j].dobreak) {
+ // CLOG_WARN(&LOG, "word too long: %c%c%c...", mem[j], mem[j+1], mem[j+2]);
+ ct->dobreak = 1;
+ custrinfo[i + 1].flag |= CU_CHINFO_WRAP;
+ ct -= 1;
+ cnr -= 1;
+ i--;
+ xof = ct->xof;
+ dobreak = true;
}
- i = j - 1;
- xof = ct->xof;
- ct[1].dobreak = 1;
- custrinfo[i + 1].flag |= CU_CHINFO_WRAP;
- dobreak = true;
- }
- else if (chartransdata[j].dobreak) {
- // CLOG_WARN(&LOG, "word too long: %c%c%c...", mem[j], mem[j+1], mem[j+2]);
- ct->dobreak = 1;
- custrinfo[i + 1].flag |= CU_CHINFO_WRAP;
- ct -= 1;
- cnr -= 1;
- i--;
- xof = ct->xof;
- dobreak = true;
- }
- if (dobreak) {
- if (tb_scale.h == 0.0f) {
- /* NOTE: If underlined text is truncated away, the extra space is also truncated. */
- custrinfo[i + 1].flag |= CU_CHINFO_OVERFLOW;
+ if (dobreak) {
+ if (tb_scale.h == 0.0f) {
+ /* NOTE: If underlined text is truncated away, the extra space is also truncated. */
+ custrinfo[i + 1].flag |= CU_CHINFO_OVERFLOW;
+ }
+ goto makebreak;
}
- goto makebreak;
}
}
}
@@ -1545,6 +1568,7 @@ static bool vfont_to_curve(Object *ob,
const float total_text_height = lnr * linedist;
iter_data->scale_to_fit = tb_scale.h / total_text_height;
iter_data->status = VFONT_TO_CURVE_SCALE_ONCE;
+ iter_data->word_wrap = false;
}
}
else if (tb_scale.h == 0.0f) {
@@ -1552,10 +1576,10 @@ static bool vfont_to_curve(Object *ob,
if (longest_line_length > tb_scale.w) {
/* We make sure longest line before it broke can fit here. */
float scale_to_fit = tb_scale.w / longest_line_length;
- scale_to_fit -= FLT_EPSILON;
iter_data->scale_to_fit = scale_to_fit;
iter_data->status = VFONT_TO_CURVE_SCALE_ONCE;
+ iter_data->word_wrap = false;
}
}
}
@@ -1616,6 +1640,7 @@ static bool vfont_to_curve(Object *ob,
else {
iter_data->scale_to_fit = iter_data->bisect.min;
iter_data->status = VFONT_TO_CURVE_SCALE_ONCE;
+ iter_data->word_wrap = false;
}
}
}
@@ -1685,6 +1710,7 @@ bool BKE_vfont_to_curve_ex(Object *ob,
VFontToCurveIter data = {
.iteraction = cu->totbox * FONT_TO_CURVE_SCALE_ITERATIONS,
.scale_to_fit = 1.0f,
+ .word_wrap = true,
.ok = true,
.status = VFONT_TO_CURVE_INIT,
};
diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index 90a97264c8f..32a65ab47bf 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -491,6 +491,10 @@ static Mesh *join_mesh_topology_and_builtin_attributes(Span<GeometryInstanceGrou
}
}
+ /* A possible optimization is to only tag the normals dirty when there are transforms that change
+ * normals. */
+ BKE_mesh_normals_tag_dirty(new_mesh);
+
return new_mesh;
}
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 38397f8f307..9062fd2d39c 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -131,7 +131,7 @@ static void greasepencil_free_data(ID *id)
{
/* Really not ideal, but for now will do... In theory custom behaviors like not freeing cache
* should be handled through specific API, and not be part of the generic one. */
- BKE_gpencil_free((bGPdata *)id, true);
+ BKE_gpencil_free_data((bGPdata *)id, true);
}
static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data)
@@ -150,47 +150,46 @@ static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data)
static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bGPdata *gpd = (bGPdata *)id;
- if (gpd->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
- /* XXX not sure why the whole run-time data is not cleared in reading code,
- * for now mimicking it here. */
- gpd->runtime.sbuffer = NULL;
- gpd->runtime.sbuffer_used = 0;
- gpd->runtime.sbuffer_size = 0;
- gpd->runtime.tot_cp_points = 0;
- /* write gpd data block to file */
- BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id);
- BKE_id_blend_write(writer, &gpd->id);
+ /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
+ /* XXX not sure why the whole run-time data is not cleared in reading code,
+ * for now mimicking it here. */
+ gpd->runtime.sbuffer = NULL;
+ gpd->runtime.sbuffer_used = 0;
+ gpd->runtime.sbuffer_size = 0;
+ gpd->runtime.tot_cp_points = 0;
- if (gpd->adt) {
- BKE_animdata_blend_write(writer, gpd->adt);
- }
+ /* write gpd data block to file */
+ BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id);
+ BKE_id_blend_write(writer, &gpd->id);
- BKE_defbase_blend_write(writer, &gpd->vertex_group_names);
+ if (gpd->adt) {
+ BKE_animdata_blend_write(writer, gpd->adt);
+ }
- BLO_write_pointer_array(writer, gpd->totcol, gpd->mat);
+ BKE_defbase_blend_write(writer, &gpd->vertex_group_names);
- /* write grease-pencil layers to file */
- BLO_write_struct_list(writer, bGPDlayer, &gpd->layers);
- LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
- /* Write mask list. */
- BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers);
- /* write this layer's frames to file */
- BLO_write_struct_list(writer, bGPDframe, &gpl->frames);
- LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
- /* write strokes */
- BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes);
- LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
- BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points);
- BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
- BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert);
- if (gps->editcurve != NULL) {
- bGPDcurve *gpc = gps->editcurve;
- BLO_write_struct(writer, bGPDcurve, gpc);
- BLO_write_struct_array(
- writer, bGPDcurve_point, gpc->tot_curve_points, gpc->curve_points);
- }
+ BLO_write_pointer_array(writer, gpd->totcol, gpd->mat);
+
+ /* write grease-pencil layers to file */
+ BLO_write_struct_list(writer, bGPDlayer, &gpd->layers);
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ /* Write mask list. */
+ BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers);
+ /* write this layer's frames to file */
+ BLO_write_struct_list(writer, bGPDframe, &gpl->frames);
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ /* write strokes */
+ BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes);
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points);
+ BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
+ BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert);
+ if (gps->editcurve != NULL) {
+ bGPDcurve *gpc = gps->editcurve;
+ BLO_write_struct(writer, bGPDcurve, gpc);
+ BLO_write_struct_array(
+ writer, bGPDcurve_point, gpc->tot_curve_points, gpc->curve_points);
}
}
}
@@ -496,7 +495,7 @@ void BKE_gpencil_free_layers(ListBase *list)
}
/** Free (or release) any data used by this grease pencil (does not free the gpencil itself). */
-void BKE_gpencil_free(bGPdata *gpd, bool free_all)
+void BKE_gpencil_free_data(bGPdata *gpd, bool free_all)
{
/* free layers */
BKE_gpencil_free_layers(&gpd->layers);
@@ -519,8 +518,9 @@ void BKE_gpencil_free(bGPdata *gpd, bool free_all)
*/
void BKE_gpencil_eval_delete(bGPdata *gpd_eval)
{
- BKE_gpencil_free(gpd_eval, true);
+ BKE_gpencil_free_data(gpd_eval, true);
BKE_libblock_free_data(&gpd_eval->id, false);
+ BLI_assert(!gpd_eval->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(gpd_eval);
}
diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc
index f8a07939096..5bca20ecd44 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.cc
+++ b/source/blender/blenkernel/intern/gpencil_geom.cc
@@ -31,6 +31,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_array_utils.h"
#include "BLI_blenlib.h"
#include "BLI_float3.hh"
#include "BLI_ghash.h"
@@ -619,7 +620,10 @@ bool BKE_gpencil_stroke_trim_points(bGPDstroke *gps, const int index_from, const
}
if (new_count == 1) {
- BKE_gpencil_free_stroke_weights(gps);
+ if (gps->dvert) {
+ BKE_gpencil_free_stroke_weights(gps);
+ MEM_freeN(gps->dvert);
+ }
MEM_freeN(gps->points);
gps->points = nullptr;
gps->dvert = nullptr;
@@ -627,27 +631,24 @@ bool BKE_gpencil_stroke_trim_points(bGPDstroke *gps, const int index_from, const
return false;
}
- new_pt = (bGPDspoint *)MEM_callocN(sizeof(bGPDspoint) * new_count, "gp_stroke_points_trimmed");
-
- for (int i = 0; i < new_count; i++) {
- memcpy(&new_pt[i], &pt[i + index_from], sizeof(bGPDspoint));
- }
+ new_pt = (bGPDspoint *)MEM_mallocN(sizeof(bGPDspoint) * new_count, "gp_stroke_points_trimmed");
+ memcpy(new_pt, &pt[index_from], sizeof(bGPDspoint) * new_count);
if (gps->dvert) {
- new_dv = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * new_count,
+ new_dv = (MDeformVert *)MEM_mallocN(sizeof(MDeformVert) * new_count,
"gp_stroke_dverts_trimmed");
for (int i = 0; i < new_count; i++) {
dv = &gps->dvert[i + index_from];
new_dv[i].flag = dv->flag;
new_dv[i].totweight = dv->totweight;
- new_dv[i].dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+ new_dv[i].dw = (MDeformWeight *)MEM_mallocN(sizeof(MDeformWeight) * dv->totweight,
"gp_stroke_dverts_dw_trimmed");
for (int j = 0; j < dv->totweight; j++) {
new_dv[i].dw[j].weight = dv->dw[j].weight;
new_dv[i].dw[j].def_nr = dv->dw[j].def_nr;
}
- BKE_defvert_clear(dv);
}
+ BKE_gpencil_free_stroke_weights(gps);
MEM_freeN(gps->dvert);
gps->dvert = new_dv;
}
@@ -691,25 +692,21 @@ bool BKE_gpencil_stroke_split(bGPdata *gpd,
gpf, gps, gps->mat_nr, new_count, gps->thickness);
new_pt = new_gps->points; /* Allocated from above. */
-
- for (int i = 0; i < new_count; i++) {
- memcpy(&new_pt[i], &pt[i + before_index], sizeof(bGPDspoint));
- }
+ memcpy(new_pt, &pt[before_index], sizeof(bGPDspoint) * new_count);
if (gps->dvert) {
- new_dv = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * new_count,
+ new_dv = (MDeformVert *)MEM_mallocN(sizeof(MDeformVert) * new_count,
"gp_stroke_dverts_remaining(MDeformVert)");
for (int i = 0; i < new_count; i++) {
dv = &gps->dvert[i + before_index];
new_dv[i].flag = dv->flag;
new_dv[i].totweight = dv->totweight;
- new_dv[i].dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+ new_dv[i].dw = (MDeformWeight *)MEM_mallocN(sizeof(MDeformWeight) * dv->totweight,
"gp_stroke_dverts_dw_remaining(MDeformWeight)");
for (int j = 0; j < dv->totweight; j++) {
new_dv[i].dw[j].weight = dv->dw[j].weight;
new_dv[i].dw[j].def_nr = dv->dw[j].def_nr;
}
- BKE_defvert_clear(dv);
}
new_gps->dvert = new_dv;
}
@@ -2269,7 +2266,8 @@ static void gpencil_generate_edgeloops(Object *ob,
const int thickness,
const float offset,
const float matrix[4][4],
- const bool use_seams)
+ const bool use_seams,
+ const bool use_vgroups)
{
Mesh *me = (Mesh *)ob->data;
if (me->totedge == 0) {
@@ -2278,9 +2276,9 @@ static void gpencil_generate_edgeloops(Object *ob,
/* Arrays for all edge vertices (forward and backward) that form a edge loop.
* This is reused for each edge-loop to create gpencil stroke. */
- uint *stroke = (uint *)MEM_callocN(sizeof(uint) * me->totedge * 2, __func__);
- uint *stroke_fw = (uint *)MEM_callocN(sizeof(uint) * me->totedge, __func__);
- uint *stroke_bw = (uint *)MEM_callocN(sizeof(uint) * me->totedge, __func__);
+ uint *stroke = (uint *)MEM_mallocN(sizeof(uint) * me->totedge * 2, __func__);
+ uint *stroke_fw = (uint *)MEM_mallocN(sizeof(uint) * me->totedge, __func__);
+ uint *stroke_bw = (uint *)MEM_mallocN(sizeof(uint) * me->totedge, __func__);
/* Create array with all edges. */
GpEdge *gp_edges = (GpEdge *)MEM_callocN(sizeof(GpEdge) * me->totedge, __func__);
@@ -2311,11 +2309,6 @@ static void gpencil_generate_edgeloops(Object *ob,
bool pending = true;
int e = 0;
while (pending) {
- /* Clear arrays of stroke. */
- memset(stroke_fw, 0, sizeof(uint) * me->totedge);
- memset(stroke_bw, 0, sizeof(uint) * me->totedge);
- memset(stroke, 0, sizeof(uint) * me->totedge * 2);
-
gped = &gp_edges[e];
/* Look first unused edge. */
if (gped->flag != 0) {
@@ -2330,7 +2323,7 @@ static void gpencil_generate_edgeloops(Object *ob,
stroke_bw[0] = e;
gped->flag = 1;
- /* Hash used to avoid loop over same vertice. */
+ /* Hash used to avoid loop over same vertices. */
GHash *v_table = BLI_ghash_int_new(__func__);
/* Look forward edges. */
int totedges = gpencil_walk_edge(v_table, gp_edges, me->totedge, stroke_fw, e, angle, false);
@@ -2354,38 +2347,41 @@ static void gpencil_generate_edgeloops(Object *ob,
bGPDstroke *gps_stroke = BKE_gpencil_stroke_add(
gpf_stroke, MAX2(stroke_mat_index, 0), array_len + 1, thickness * thickness, false);
+ /* Create dvert data. */
+ MDeformVert *me_dvert = me->dvert;
+ if (use_vgroups && me_dvert) {
+ gps_stroke->dvert = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * (array_len + 1),
+ "gp_stroke_dverts");
+ }
+
/* Create first segment. */
float fpt[3];
- uint v = stroke[0];
- gped = &gp_edges[v];
- bGPDspoint *pt = &gps_stroke->points[0];
- mul_v3_v3fl(fpt, gped->n1, offset);
- add_v3_v3v3(&pt->x, gped->v1_co, fpt);
- mul_m4_v3(matrix, &pt->x);
-
- pt->pressure = 1.0f;
- pt->strength = 1.0f;
-
- pt = &gps_stroke->points[1];
- mul_v3_v3fl(fpt, gped->n2, offset);
- add_v3_v3v3(&pt->x, gped->v2_co, fpt);
- mul_m4_v3(matrix, &pt->x);
-
- pt->pressure = 1.0f;
- pt->strength = 1.0f;
-
- /* Add next segments. */
- for (int i = 1; i < array_len; i++) {
- v = stroke[i];
- gped = &gp_edges[v];
-
- pt = &gps_stroke->points[i + 1];
- mul_v3_v3fl(fpt, gped->n2, offset);
- add_v3_v3v3(&pt->x, gped->v2_co, fpt);
+ for (int i = 0; i < array_len + 1; i++) {
+ int vertex_index = i == 0 ? gp_edges[stroke[0]].v1 : gp_edges[stroke[i - 1]].v2;
+ MVert *mv = &me->mvert[vertex_index];
+
+ /* Add segment. */
+ bGPDspoint *pt = &gps_stroke->points[i];
+ normal_short_to_float_v3(fpt, mv->no);
+ mul_v3_v3fl(fpt, fpt, offset);
+ add_v3_v3v3(&pt->x, mv->co, fpt);
mul_m4_v3(matrix, &pt->x);
pt->pressure = 1.0f;
pt->strength = 1.0f;
+
+ /* Copy vertex groups from mesh. Assuming they already exist in the same order. */
+ if (use_vgroups && me_dvert) {
+ MDeformVert *dv = &gps_stroke->dvert[i];
+ MDeformVert *src_dv = &me_dvert[vertex_index];
+ dv->totweight = src_dv->totweight;
+ dv->dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+ "gp_stroke_dverts_dw");
+ for (int j = 0; j < dv->totweight; j++) {
+ dv->dw[j].weight = src_dv->dw[j].weight;
+ dv->dw[j].def_nr = src_dv->dw[j].def_nr;
+ }
+ }
}
BKE_gpencil_stroke_geometry_update(gpd, gps_stroke);
@@ -2488,7 +2484,8 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
const float matrix[4][4],
const int frame_offset,
const bool use_seams,
- const bool use_faces)
+ const bool use_faces,
+ const bool use_vgroups)
{
if (ELEM(nullptr, ob_gp, ob_mesh) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == nullptr)) {
return false;
@@ -2505,83 +2502,105 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
char element_name[200];
/* Need at least an edge. */
- if (me_eval->totvert < 2) {
+ if (me_eval->totedge < 1) {
return false;
}
+ /* Create matching vertex groups. */
+ BKE_defgroup_copy_list(&gpd->vertex_group_names, &me_eval->vertex_group_names);
+ gpd->vertex_group_active_index = me_eval->vertex_group_active_index;
+
const float default_colors[2][4] = {{0.0f, 0.0f, 0.0f, 1.0f}, {0.7f, 0.7f, 0.7f, 1.0f}};
- /* Create stroke material. */
+ /* Lookup existing stroke material on gp object. */
make_element_name(ob_mesh->id.name + 2, "Stroke", 64, element_name);
int stroke_mat_index = gpencil_material_find_index_by_name(ob_gp, element_name);
if (stroke_mat_index == -1) {
+ /* Create new default stroke material as there is no existing material. */
gpencil_add_material(
bmain, ob_gp, element_name, default_colors[0], true, false, &stroke_mat_index);
}
/* Export faces as filled strokes. */
- if (use_faces) {
-
+ if (use_faces && mpoly_len > 0) {
/* Read all polygons and create fill for each. */
- if (mpoly_len > 0) {
- make_element_name(ob_mesh->id.name + 2, "Fills", 128, element_name);
- /* Create Layer and Frame. */
- bGPDlayer *gpl_fill = BKE_gpencil_layer_named_get(gpd, element_name);
- if (gpl_fill == nullptr) {
- gpl_fill = BKE_gpencil_layer_addnew(gpd, element_name, true, false);
- }
- bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get(
- gpl_fill, CFRA + frame_offset, GP_GETFRAME_ADD_NEW);
- int i;
- for (i = 0; i < mpoly_len; i++) {
- const MPoly *mp = &mpoly[i];
-
- /* Find material. */
- int mat_idx = 0;
- Material *ma = BKE_object_material_get(ob_mesh, mp->mat_nr + 1);
- make_element_name(
- ob_mesh->id.name + 2, (ma != nullptr) ? ma->id.name + 2 : "Fill", 64, element_name);
- mat_idx = BKE_gpencil_material_find_index_by_name_prefix(ob_gp, element_name);
- if (mat_idx == -1) {
- float color[4];
- if (ma != nullptr) {
- copy_v3_v3(color, &ma->r);
- color[3] = 1.0f;
- }
- else {
- copy_v4_v4(color, default_colors[1]);
- }
- gpencil_add_material(bmain, ob_gp, element_name, color, false, true, &mat_idx);
+ make_element_name(ob_mesh->id.name + 2, "Fills", 128, element_name);
+ /* Create Layer and Frame. */
+ bGPDlayer *gpl_fill = BKE_gpencil_layer_named_get(gpd, element_name);
+ if (gpl_fill == nullptr) {
+ gpl_fill = BKE_gpencil_layer_addnew(gpd, element_name, true, false);
+ }
+ bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get(
+ gpl_fill, CFRA + frame_offset, GP_GETFRAME_ADD_NEW);
+ int i;
+ for (i = 0; i < mpoly_len; i++) {
+ const MPoly *mp = &mpoly[i];
+
+ /* Find material. */
+ int mat_idx = 0;
+ Material *ma = BKE_object_material_get(ob_mesh, mp->mat_nr + 1);
+ make_element_name(
+ ob_mesh->id.name + 2, (ma != nullptr) ? ma->id.name + 2 : "Fill", 64, element_name);
+ mat_idx = BKE_gpencil_material_find_index_by_name_prefix(ob_gp, element_name);
+ if (mat_idx == -1) {
+ float color[4];
+ if (ma != nullptr) {
+ copy_v3_v3(color, &ma->r);
+ color[3] = 1.0f;
}
+ else {
+ copy_v4_v4(color, default_colors[1]);
+ }
+ gpencil_add_material(bmain, ob_gp, element_name, color, false, true, &mat_idx);
+ }
- bGPDstroke *gps_fill = BKE_gpencil_stroke_add(gpf_fill, mat_idx, mp->totloop, 10, false);
- gps_fill->flag |= GP_STROKE_CYCLIC;
+ bGPDstroke *gps_fill = BKE_gpencil_stroke_add(gpf_fill, mat_idx, mp->totloop, 10, false);
+ gps_fill->flag |= GP_STROKE_CYCLIC;
- /* Add points to strokes. */
- for (int j = 0; j < mp->totloop; j++) {
- const MLoop *ml = &mloop[mp->loopstart + j];
- const MVert *mv = &me_eval->mvert[ml->v];
+ /* Create dvert data. */
+ MDeformVert *me_dvert = me_eval->dvert;
+ if (use_vgroups && me_dvert) {
+ gps_fill->dvert = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * mp->totloop,
+ "gp_fill_dverts");
+ }
- bGPDspoint *pt = &gps_fill->points[j];
- copy_v3_v3(&pt->x, mv->co);
- mul_m4_v3(matrix, &pt->x);
- pt->pressure = 1.0f;
- pt->strength = 1.0f;
- }
- /* If has only 3 points subdivide. */
- if (mp->totloop == 3) {
- BKE_gpencil_stroke_subdivide(gpd, gps_fill, 1, GP_SUBDIV_SIMPLE);
+ /* Add points to strokes. */
+ for (int j = 0; j < mp->totloop; j++) {
+ const MLoop *ml = &mloop[mp->loopstart + j];
+ const MVert *mv = &me_eval->mvert[ml->v];
+
+ bGPDspoint *pt = &gps_fill->points[j];
+ copy_v3_v3(&pt->x, mv->co);
+ mul_m4_v3(matrix, &pt->x);
+ pt->pressure = 1.0f;
+ pt->strength = 1.0f;
+
+ /* Copy vertex groups from mesh. Assuming they already exist in the same order. */
+ if (use_vgroups && me_dvert) {
+ MDeformVert *dv = &gps_fill->dvert[j];
+ MDeformVert *src_dv = &me_dvert[ml->v];
+ dv->totweight = src_dv->totweight;
+ dv->dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+ "gp_fill_dverts_dw");
+ for (int k = 0; k < dv->totweight; k++) {
+ dv->dw[k].weight = src_dv->dw[k].weight;
+ dv->dw[k].def_nr = src_dv->dw[k].def_nr;
+ }
}
-
- BKE_gpencil_stroke_geometry_update(gpd, gps_fill);
}
+ /* If has only 3 points subdivide. */
+ if (mp->totloop == 3) {
+ BKE_gpencil_stroke_subdivide(gpd, gps_fill, 1, GP_SUBDIV_SIMPLE);
+ }
+
+ BKE_gpencil_stroke_geometry_update(gpd, gps_fill);
}
}
/* Create stroke from edges. */
- make_element_name(ob_mesh->id.name + 2, "Lines", 128, element_name);
/* Create Layer and Frame. */
+ make_element_name(ob_mesh->id.name + 2, "Lines", 128, element_name);
bGPDlayer *gpl_stroke = BKE_gpencil_layer_named_get(gpd, element_name);
if (gpl_stroke == nullptr) {
gpl_stroke = BKE_gpencil_layer_addnew(gpd, element_name, true, false);
@@ -2589,8 +2608,16 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
bGPDframe *gpf_stroke = BKE_gpencil_layer_frame_get(
gpl_stroke, CFRA + frame_offset, GP_GETFRAME_ADD_NEW);
- gpencil_generate_edgeloops(
- ob_eval, gpd, gpf_stroke, stroke_mat_index, angle, thickness, offset, matrix, use_seams);
+ gpencil_generate_edgeloops(ob_eval,
+ gpd,
+ gpf_stroke,
+ stroke_mat_index,
+ angle,
+ thickness,
+ offset,
+ matrix,
+ use_seams,
+ use_vgroups);
/* Tag for recalculation */
DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
@@ -2787,46 +2814,12 @@ void BKE_gpencil_stroke_set_random_color(bGPDstroke *gps)
/* Flip stroke. */
void BKE_gpencil_stroke_flip(bGPDstroke *gps)
{
- int end = gps->totpoints - 1;
+ /* Reverse points. */
+ BLI_array_reverse(gps->points, gps->totpoints);
- for (int i = 0; i < gps->totpoints / 2; i++) {
- bGPDspoint *point, *point2;
- bGPDspoint pt;
-
- /* save first point */
- point = &gps->points[i];
- pt.x = point->x;
- pt.y = point->y;
- pt.z = point->z;
- pt.flag = point->flag;
- pt.pressure = point->pressure;
- pt.strength = point->strength;
- pt.time = point->time;
- copy_v4_v4(pt.vert_color, point->vert_color);
-
- /* replace first point with last point */
- point2 = &gps->points[end];
- point->x = point2->x;
- point->y = point2->y;
- point->z = point2->z;
- point->flag = point2->flag;
- point->pressure = point2->pressure;
- point->strength = point2->strength;
- point->time = point2->time;
- copy_v4_v4(point->vert_color, point2->vert_color);
-
- /* replace last point with first saved before */
- point = &gps->points[end];
- point->x = pt.x;
- point->y = pt.y;
- point->z = pt.z;
- point->flag = pt.flag;
- point->pressure = pt.pressure;
- point->strength = pt.strength;
- point->time = pt.time;
- copy_v4_v4(point->vert_color, pt.vert_color);
-
- end--;
+ /* Reverse vertex groups if available. */
+ if (gps->dvert) {
+ BLI_array_reverse(gps->dvert, gps->totpoints);
}
}
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 2894d6daf23..af7cc0acb57 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -114,32 +114,31 @@ static void hair_foreach_id(ID *id, LibraryForeachIDData *data)
static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Hair *hair = (Hair *)id;
- if (hair->id.us > 0 || BLO_write_is_undo(writer)) {
- CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
- CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
- CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
- CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
-
- /* Write LibData */
- BLO_write_id_struct(writer, Hair, id_address, &hair->id);
- BKE_id_blend_write(writer, &hair->id);
-
- /* Direct data */
- CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id);
- CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id);
-
- BLO_write_pointer_array(writer, hair->totcol, hair->mat);
- if (hair->adt) {
- BKE_animdata_blend_write(writer, hair->adt);
- }
- /* Remove temporary data. */
- if (players && players != players_buff) {
- MEM_freeN(players);
- }
- if (clayers && clayers != clayers_buff) {
- MEM_freeN(clayers);
- }
+ CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
+ CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
+
+ /* Write LibData */
+ BLO_write_id_struct(writer, Hair, id_address, &hair->id);
+ BKE_id_blend_write(writer, &hair->id);
+
+ /* Direct data */
+ CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id);
+ CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id);
+
+ BLO_write_pointer_array(writer, hair->totcol, hair->mat);
+ if (hair->adt) {
+ BKE_animdata_blend_write(writer, hair->adt);
+ }
+
+ /* Remove temporary data. */
+ if (players && players != players_buff) {
+ MEM_freeN(players);
+ }
+ if (clayers && clayers != clayers_buff) {
+ MEM_freeN(clayers);
}
}
diff --git a/source/blender/blenkernel/intern/icons.cc b/source/blender/blenkernel/intern/icons.cc
index 12a0a1e3ae7..5a4b2448a73 100644
--- a/source/blender/blenkernel/intern/icons.cc
+++ b/source/blender/blenkernel/intern/icons.cc
@@ -1,4 +1,4 @@
-/*
+/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index f4ba1ff8b92..d87290e1eb4 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -229,12 +229,26 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{
Image *ima = (Image *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (ima->id.us > 0 || is_undo) {
- ImagePackedFile *imapf;
- BLI_assert(ima->packedfile == NULL);
+ /* Clear all data that isn't read to reduce false detection of changed image during memfile undo.
+ */
+ ima->lastused = 0;
+ ima->cache = NULL;
+ ima->gpuflag = 0;
+ BLI_listbase_clear(&ima->anims);
+ BLI_listbase_clear(&ima->gpu_refresh_areas);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 2; j++) {
+ ima->gputexture[i][j] = NULL;
+ }
+ }
+
+ ImagePackedFile *imapf;
+
+ BLI_assert(ima->packedfile == NULL);
+ if (!is_undo) {
/* Do not store packed files in case this is a library override ID. */
- if (ID_IS_OVERRIDE_LIBRARY(ima) && !is_undo) {
+ if (ID_IS_OVERRIDE_LIBRARY(ima)) {
BLI_listbase_clear(&ima->packedfiles);
}
else {
@@ -244,29 +258,29 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
ima->packedfile = imapf->packedfile;
}
}
+ }
- /* write LibData */
- BLO_write_id_struct(writer, Image, id_address, &ima->id);
- BKE_id_blend_write(writer, &ima->id);
+ /* write LibData */
+ BLO_write_id_struct(writer, Image, id_address, &ima->id);
+ BKE_id_blend_write(writer, &ima->id);
- for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
- BLO_write_struct(writer, ImagePackedFile, imapf);
- BKE_packedfile_blend_write(writer, imapf->packedfile);
- }
+ for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
+ BLO_write_struct(writer, ImagePackedFile, imapf);
+ BKE_packedfile_blend_write(writer, imapf->packedfile);
+ }
- BKE_previewimg_blend_write(writer, ima->preview);
+ BKE_previewimg_blend_write(writer, ima->preview);
- LISTBASE_FOREACH (ImageView *, iv, &ima->views) {
- BLO_write_struct(writer, ImageView, iv);
- }
- BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format);
+ LISTBASE_FOREACH (ImageView *, iv, &ima->views) {
+ BLO_write_struct(writer, ImageView, iv);
+ }
+ BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format);
- BLO_write_struct_list(writer, ImageTile, &ima->tiles);
+ BLO_write_struct_list(writer, ImageTile, &ima->tiles);
- ima->packedfile = NULL;
+ ima->packedfile = NULL;
- BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
- }
+ BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
}
static void image_blend_read_data(BlendDataReader *reader, ID *id)
@@ -300,6 +314,7 @@ static void image_blend_read_data(BlendDataReader *reader, ID *id)
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
tile->ok = IMA_OK;
}
+ ima->lastused = 0;
ima->gpuflag = 0;
BLI_listbase_clear(&ima->gpu_refresh_areas);
}
@@ -519,7 +534,7 @@ void BKE_image_free_buffers(Image *ima)
}
/** Free (or release) any data used by this image (does not free the image itself). */
-void BKE_image_free(Image *ima)
+void BKE_image_free_data(Image *ima)
{
image_free_data(&ima->id);
}
@@ -670,24 +685,27 @@ bool BKE_image_has_opengl_texture(Image *ima)
return false;
}
+static int image_get_tile_number_from_iuser(Image *ima, const ImageUser *iuser)
+{
+ BLI_assert(ima != NULL && ima->tiles.first);
+ ImageTile *tile = ima->tiles.first;
+ return (iuser && iuser->tile) ? iuser->tile : tile->tile_number;
+}
+
ImageTile *BKE_image_get_tile(Image *ima, int tile_number)
{
if (ima == NULL) {
return NULL;
}
- /* Verify valid tile range. */
- if ((tile_number != 0) && (tile_number < 1001 || tile_number > IMA_UDIM_MAX)) {
- return NULL;
- }
-
- /* Tile number 0 is a special case and refers to the first tile, typically
+ /* Tiles 0 and 1001 are a special case and refer to the first tile, typically
* coming from non-UDIM-aware code. */
if (ELEM(tile_number, 0, 1001)) {
return ima->tiles.first;
}
- if (ima->source != IMA_SRC_TILED) {
+ /* Must have a tiled image and a valid tile number at this point. */
+ if (ima->source != IMA_SRC_TILED || tile_number < 1001 || tile_number > IMA_UDIM_MAX) {
return NULL;
}
@@ -702,7 +720,7 @@ ImageTile *BKE_image_get_tile(Image *ima, int tile_number)
ImageTile *BKE_image_get_tile_from_iuser(Image *ima, const ImageUser *iuser)
{
- return BKE_image_get_tile(ima, (iuser && iuser->tile) ? iuser->tile : 1001);
+ return BKE_image_get_tile(ima, image_get_tile_number_from_iuser(ima, iuser));
}
int BKE_image_get_tile_from_pos(struct Image *ima,
@@ -1020,7 +1038,7 @@ Image *BKE_image_add_generated(Main *bmain,
int view_id;
const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
- /* STRNCPY(ima->filepath, name); */ /* don't do this, this writes in ain invalid filepath! */
+ // STRNCPY(ima->filepath, name); /* don't do this, this writes in ain invalid filepath! */
ima->gen_x = width;
ima->gen_y = height;
ima->gen_type = gen_type;
@@ -3803,8 +3821,8 @@ bool BKE_image_remove_tile(struct Image *ima, ImageTile *tile)
return false;
}
- if (tile == ima->tiles.first) {
- /* Can't remove first tile. */
+ if (BLI_listbase_is_single(&ima->tiles)) {
+ /* Can't remove the last remaining tile. */
return false;
}
@@ -3815,6 +3833,64 @@ bool BKE_image_remove_tile(struct Image *ima, ImageTile *tile)
return true;
}
+void BKE_image_reassign_tile(struct Image *ima, ImageTile *tile, int new_tile_number)
+{
+ if (ima == NULL || tile == NULL || ima->source != IMA_SRC_TILED) {
+ return;
+ }
+
+ if (new_tile_number < 1001 || new_tile_number > IMA_UDIM_MAX) {
+ return;
+ }
+
+ const int old_tile_number = tile->tile_number;
+ tile->tile_number = new_tile_number;
+
+ if (BKE_image_is_multiview(ima)) {
+ const int totviews = BLI_listbase_count(&ima->views);
+ for (int i = 0; i < totviews; i++) {
+ ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, i, old_tile_number);
+ image_remove_ibuf(ima, i, old_tile_number);
+ image_assign_ibuf(ima, ibuf, i, new_tile_number);
+ IMB_freeImBuf(ibuf);
+ }
+ }
+ else {
+ ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, 0, old_tile_number);
+ image_remove_ibuf(ima, 0, old_tile_number);
+ image_assign_ibuf(ima, ibuf, 0, new_tile_number);
+ IMB_freeImBuf(ibuf);
+ }
+
+ for (int eye = 0; eye < 2; eye++) {
+ /* Reallocate GPU tile array. */
+ if (ima->gputexture[TEXTARGET_2D_ARRAY][eye] != NULL) {
+ GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye]);
+ ima->gputexture[TEXTARGET_2D_ARRAY][eye] = NULL;
+ }
+ if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye] != NULL) {
+ GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye]);
+ ima->gputexture[TEXTARGET_TILE_MAPPING][eye] = NULL;
+ }
+ }
+}
+
+static int tile_sort_cb(const void *a, const void *b)
+{
+ const ImageTile *tile_a = a;
+ const ImageTile *tile_b = b;
+ return (tile_a->tile_number > tile_b->tile_number) ? 1 : 0;
+}
+
+void BKE_image_sort_tiles(struct Image *ima)
+{
+ if (ima == NULL || ima->source != IMA_SRC_TILED) {
+ return;
+ }
+
+ BLI_listbase_sort(&ima->tiles, tile_sort_cb);
+}
+
bool BKE_image_fill_tile(struct Image *ima,
ImageTile *tile,
int width,
@@ -4890,7 +4966,7 @@ static void image_get_entry_and_index(Image *ima, ImageUser *iuser, int *r_entry
}
}
else if (ima->source == IMA_SRC_TILED) {
- frame = (iuser && iuser->tile) ? iuser->tile : 1001;
+ frame = image_get_tile_number_from_iuser(ima, iuser);
}
*r_entry = frame;
@@ -4955,7 +5031,7 @@ static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *r_entry,
}
else if (ima->source == IMA_SRC_TILED) {
if (ELEM(ima->type, IMA_TYPE_IMAGE, IMA_TYPE_MULTILAYER)) {
- entry = (iuser && iuser->tile) ? iuser->tile : 1001;
+ entry = image_get_tile_number_from_iuser(ima, iuser);
ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry);
if ((ima->type == IMA_TYPE_IMAGE) && ibuf != NULL) {
@@ -5507,7 +5583,7 @@ void BKE_image_user_file_path(ImageUser *iuser, Image *ima, char *filepath)
index = iuser ? iuser->framenr : ima->lastframe;
}
else {
- index = (iuser && iuser->tile) ? iuser->tile : 1001;
+ index = image_get_tile_number_from_iuser(ima, iuser);
}
BLI_path_sequence_decode(filepath, head, tail, &numlen);
diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c
index bb7495437bb..d179dd40c33 100644
--- a/source/blender/blenkernel/intern/image_gpu.c
+++ b/source/blender/blenkernel/intern/image_gpu.c
@@ -108,8 +108,9 @@ static GPUTexture *gpu_texture_create_tile_mapping(Image *ima, const int multivi
float array_w = GPU_texture_width(tilearray);
float array_h = GPU_texture_height(tilearray);
+ /* Determine maximum tile number. */
+ BKE_image_sort_tiles(ima);
ImageTile *last_tile = (ImageTile *)ima->tiles.last;
- /* Tiles are sorted by number. */
int max_tile = last_tile->tile_number - 1001;
/* create image */
diff --git a/source/blender/blenkernel/intern/image_save.c b/source/blender/blenkernel/intern/image_save.c
index 360bad3e786..f93ede517a9 100644
--- a/source/blender/blenkernel/intern/image_save.c
+++ b/source/blender/blenkernel/intern/image_save.c
@@ -404,11 +404,13 @@ bool BKE_image_save(
if (ima->source == IMA_SRC_TILED) {
/* Verify filepath for tiles images. */
- if (BLI_path_sequence_decode(opts->filepath, NULL, NULL, NULL) != 1001) {
+ ImageTile *first_tile = ima->tiles.first;
+ if (BLI_path_sequence_decode(opts->filepath, NULL, NULL, NULL) != first_tile->tile_number) {
BKE_reportf(reports,
RPT_ERROR,
- "When saving a tiled image, the path '%s' must contain the UDIM tag 1001",
- opts->filepath);
+ "When saving a tiled image, the path '%s' must contain the UDIM tile number %d",
+ opts->filepath,
+ first_tile->tile_number);
return false;
}
@@ -430,9 +432,14 @@ bool BKE_image_save(
BLI_path_sequence_decode(filepath, head, tail, &numlen);
/* Save all other tiles. */
- LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
- /* Tile 1001 was already saved before the loop. */
- if (tile->tile_number == 1001 || !ok) {
+ int index;
+ LISTBASE_FOREACH_INDEX (ImageTile *, tile, &ima->tiles, index) {
+ /* First tile was already saved before the loop. */
+ if (index == 0) {
+ continue;
+ }
+
+ if (!ok) {
continue;
}
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 0f8c9bad798..f79058dcf21 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -114,27 +114,26 @@ static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_add
{
Key *key = (Key *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (key->id.us > 0 || is_undo) {
- /* write LibData */
- BLO_write_id_struct(writer, Key, id_address, &key->id);
- BKE_id_blend_write(writer, &key->id);
-
- if (key->adt) {
- BKE_animdata_blend_write(writer, key->adt);
- }
-
- /* direct data */
- LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
- KeyBlock tmp_kb = *kb;
- /* Do not store actual geometry data in case this is a library override ID. */
- if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) {
- tmp_kb.totelem = 0;
- tmp_kb.data = NULL;
- }
- BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb);
- if (tmp_kb.data != NULL) {
- BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data);
- }
+
+ /* write LibData */
+ BLO_write_id_struct(writer, Key, id_address, &key->id);
+ BKE_id_blend_write(writer, &key->id);
+
+ if (key->adt) {
+ BKE_animdata_blend_write(writer, key->adt);
+ }
+
+ /* direct data */
+ LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
+ KeyBlock tmp_kb = *kb;
+ /* Do not store actual geometry data in case this is a library override ID. */
+ if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) {
+ tmp_kb.totelem = 0;
+ tmp_kb.data = NULL;
+ }
+ BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb);
+ if (tmp_kb.data != NULL) {
+ BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data);
}
}
}
@@ -246,7 +245,7 @@ typedef struct WeightsArrayCache {
} WeightsArrayCache;
/** Free (or release) any data used by this shapekey (does not free the key itself). */
-void BKE_key_free(Key *key)
+void BKE_key_free_data(Key *key)
{
shapekey_free_data(&key->id);
}
@@ -2281,15 +2280,8 @@ void BKE_keyblock_mesh_calc_normals(struct KeyBlock *kb,
r_polynors = MEM_mallocN(sizeof(float[3]) * me.totpoly, __func__);
free_polynors = true;
}
- BKE_mesh_calc_normals_poly(me.mvert,
- r_vertnors,
- me.totvert,
- me.mloop,
- me.mpoly,
- me.totloop,
- me.totpoly,
- r_polynors,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(
+ me.mvert, me.totvert, me.mloop, me.totloop, me.mpoly, me.totpoly, r_polynors, r_vertnors);
if (r_loopnors) {
short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 9875d776d33..e804f32e5a6 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -137,26 +137,25 @@ static void lattice_foreach_id(ID *id, LibraryForeachIDData *data)
static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Lattice *lt = (Lattice *)id;
- if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- lt->editlatt = NULL;
- lt->batch_cache = NULL;
-
- /* write LibData */
- BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
- BKE_id_blend_write(writer, &lt->id);
-
- /* write animdata */
- if (lt->adt) {
- BKE_animdata_blend_write(writer, lt->adt);
- }
- /* direct data */
- BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ lt->editlatt = NULL;
+ lt->batch_cache = NULL;
+
+ /* write LibData */
+ BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
+ BKE_id_blend_write(writer, &lt->id);
- BKE_defbase_blend_write(writer, &lt->vertex_group_names);
- BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
+ /* write animdata */
+ if (lt->adt) {
+ BKE_animdata_blend_write(writer, lt->adt);
}
+
+ /* direct data */
+ BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
+
+ BKE_defbase_blend_write(writer, &lt->vertex_group_names);
+ BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
}
static void lattice_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index e7d83c668c8..b489675cd74 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1174,6 +1174,52 @@ static void layer_collection_sync(ViewLayer *view_layer,
parent_local_collections_bits);
}
+#ifndef NDEBUG
+static bool view_layer_objects_base_cache_validate(ViewLayer *view_layer, LayerCollection *layer)
+{
+ bool is_valid = true;
+
+ if (layer == NULL) {
+ layer = view_layer->layer_collections.first;
+ }
+
+ /* Only check for a collection's objects if its layer is not excluded. */
+ if ((layer->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
+ LISTBASE_FOREACH (CollectionObject *, cob, &layer->collection->gobject) {
+ if (cob->ob == NULL) {
+ continue;
+ }
+ if (BLI_ghash_lookup(view_layer->object_bases_hash, cob->ob) == NULL) {
+ CLOG_FATAL(
+ &LOG,
+ "Object '%s' from collection '%s' has no entry in view layer's object bases cache",
+ cob->ob->id.name + 2,
+ layer->collection->id.name + 2);
+ is_valid = false;
+ break;
+ }
+ }
+ }
+
+ if (is_valid) {
+ LISTBASE_FOREACH (LayerCollection *, layer_child, &layer->layer_collections) {
+ if (!view_layer_objects_base_cache_validate(view_layer, layer_child)) {
+ is_valid = false;
+ break;
+ }
+ }
+ }
+
+ return is_valid;
+}
+#else
+static bool view_layer_objects_base_cache_validate(ViewLayer *UNUSED(view_layer),
+ LayerCollection *UNUSED(layer))
+{
+ return true;
+}
+#endif
+
/**
* Update view layer collection tree from collections used in the scene.
* This is used when collections are removed or added, both while editing
@@ -1240,6 +1286,12 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
}
if (base->object) {
+ /* Those asserts are commented, since they are too expensive to perform even in debug, as
+ * this layer resync function currently gets called way too often. */
+#if 0
+ BLI_assert(BLI_findindex(&new_object_bases, base) == -1);
+ BLI_assert(BLI_findptr(&new_object_bases, base->object, offsetof(Base, object)) == NULL);
+#endif
BLI_ghash_remove(view_layer->object_bases_hash, base->object, NULL, NULL);
}
}
@@ -1247,6 +1299,8 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
BLI_freelistN(&view_layer->object_bases);
view_layer->object_bases = new_object_bases;
+ view_layer_objects_base_cache_validate(view_layer, NULL);
+
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
BKE_base_eval_flags(base);
}
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 5e1027c62af..aa458bc1b27 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -153,7 +153,7 @@ static int lib_id_clear_library_data_users_update_cb(LibraryIDLinkCallbackData *
* Pull an ID out of a library (make it local). Only call this for IDs that
* don't have other library users.
*/
-static void lib_id_clear_library_data_ex(Main *bmain, ID *id)
+void BKE_lib_id_clear_library_data(Main *bmain, ID *id)
{
const bool id_in_mainlist = (id->tag & LIB_TAG_NO_MAIN) == 0 &&
(id->flag & LIB_EMBEDDED_DATA) == 0;
@@ -193,17 +193,12 @@ static void lib_id_clear_library_data_ex(Main *bmain, ID *id)
* IDs here, this is down automatically in `lib_id_expand_local_cb()`. */
Key *key = BKE_key_from_id(id);
if (key != NULL) {
- lib_id_clear_library_data_ex(bmain, &key->id);
+ BKE_lib_id_clear_library_data(bmain, &key->id);
}
DEG_relations_tag_update(bmain);
}
-void BKE_lib_id_clear_library_data(Main *bmain, ID *id)
-{
- lib_id_clear_library_data_ex(bmain, id);
-}
-
void id_lib_extern(ID *id)
{
if (id && ID_IS_LINKED(id)) {
@@ -369,7 +364,7 @@ static int lib_id_expand_local_cb(LibraryIDLinkCallbackData *cb_data)
if (*id_pointer != NULL && ID_IS_LINKED(*id_pointer)) {
BLI_assert(*id_pointer != id_self);
- lib_id_clear_library_data_ex(bmain, *id_pointer);
+ BKE_lib_id_clear_library_data(bmain, *id_pointer);
}
return IDWALK_RET_NOP;
}
@@ -429,7 +424,7 @@ void BKE_lib_id_make_local_generic(Main *bmain, ID *id, const int flags)
if (lib_local || is_local) {
if (!is_lib) {
- lib_id_clear_library_data_ex(bmain, id);
+ BKE_lib_id_clear_library_data(bmain, id);
BKE_lib_id_expand_local(bmain, id);
}
else {
@@ -1321,14 +1316,6 @@ void *BKE_libblock_copy(Main *bmain, const ID *id)
return idn;
}
-/* XXX TODO: get rid of this useless wrapper at some point... */
-void *BKE_libblock_copy_for_localize(const ID *id)
-{
- ID *idn;
- BKE_libblock_copy_ex(NULL, id, &idn, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA);
- return idn;
-}
-
/* ***************** ID ************************ */
ID *BKE_libblock_find_name(struct Main *bmain, const short type, const char *name)
{
@@ -1489,7 +1476,7 @@ static bool id_name_final_build(char *name, char *base_name, size_t base_name_le
/* Code above may have generated invalid utf-8 string, due to raw truncation.
* Ensure we get a valid one now. */
- base_name_len -= (size_t)BLI_utf8_invalid_strip(base_name, base_name_len);
+ base_name_len -= (size_t)BLI_str_utf8_invalid_strip(base_name, base_name_len);
/* Also truncate orig name, and start the whole check again. */
name[base_name_len] = '\0';
@@ -1739,7 +1726,7 @@ bool BKE_id_new_name_validate(ListBase *lb, ID *id, const char *tname, const boo
else {
/* disallow non utf8 chars,
* the interface checks for this but new ID's based on file names don't */
- BLI_utf8_invalid_strip(name, strlen(name));
+ BLI_str_utf8_invalid_strip(name, strlen(name));
}
ID *id_sorting_hint = NULL;
@@ -2022,7 +2009,7 @@ void BKE_library_make_local(Main *bmain,
* currently there are some indirect usages. So instead of making a copy that we'll likely
* get rid of later, directly make that data block local.
* Saves a tremendous amount of time with complex scenes... */
- lib_id_clear_library_data_ex(bmain, id);
+ BKE_lib_id_clear_library_data(bmain, id);
BKE_lib_id_expand_local(bmain, id);
id->tag &= ~LIB_TAG_DOIT;
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index a9407860c06..43afac5a376 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -142,14 +142,7 @@ void BKE_id_free_ex(Main *bmain, void *idv, int flag, const bool use_flag_from_i
DEG_id_type_tag(bmain, type);
}
-#ifdef WITH_PYTHON
-# ifdef WITH_PYTHON_SAFETY
- BPY_id_release(id);
-# endif
- if (id->py_instance) {
- BPY_DECREF_RNA_INVALIDATE(id->py_instance);
- }
-#endif
+ BKE_libblock_free_data_py(id);
Key *key = ((flag & LIB_ID_FREE_NO_MAIN) == 0) ? BKE_key_from_id(id) : NULL;
@@ -406,3 +399,29 @@ size_t BKE_id_multi_tagged_delete(Main *bmain)
{
return id_delete(bmain, true);
}
+
+/* -------------------------------------------------------------------- */
+/** \name Python Data Handling
+ * \{ */
+
+/**
+ * In most cases #BKE_id_free_ex handles this, when lower level functions are called directly
+ * this function will need to be called too, if Python has access to the data.
+ *
+ * ID data-blocks such as #Material.nodetree are not stored in #Main.
+ */
+void BKE_libblock_free_data_py(ID *id)
+{
+#ifdef WITH_PYTHON
+# ifdef WITH_PYTHON_SAFETY
+ BPY_id_release(id);
+# endif
+ if (id->py_instance) {
+ BPY_DECREF_RNA_INVALIDATE(id->py_instance);
+ }
+#else
+ UNUSED_VARS(id);
+#endif
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index bebc49e090d..8083585b594 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -1631,7 +1631,7 @@ static void lib_override_library_main_resync_on_library_indirect_level(
CLOG_INFO(&LOG, 2, "\tSuccess: %d", success);
if (success) {
reports->count.resynced_lib_overrides++;
- if (library_indirect_level > 0 &&
+ if (library_indirect_level > 0 && reports->do_resynced_lib_overrides_libraries_list &&
BLI_linklist_index(reports->resynced_lib_overrides_libraries, library) < 0) {
BLI_linklist_prepend(&reports->resynced_lib_overrides_libraries, library);
reports->resynced_lib_overrides_libraries_count++;
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index 977e53c8474..9400458376d 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -88,8 +88,8 @@ bool BKE_lib_query_foreachid_process(LibraryForeachIDData *data, ID **id_pp, int
/* Update the callback flags with some extra information regarding overrides: all 'loopback',
* 'internal', 'embedded' etc. ID pointers are never overridable. */
- if (cb_flag & (IDWALK_CB_INTERNAL | IDWALK_CB_EMBEDDED | IDWALK_CB_LOOPBACK |
- IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE)) {
+ if (cb_flag &
+ (IDWALK_CB_INTERNAL | IDWALK_CB_LOOPBACK | IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE)) {
cb_flag |= IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE;
}
diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c
index d91d80ac683..c2b71b85973 100644
--- a/source/blender/blenkernel/intern/light.c
+++ b/source/blender/blenkernel/intern/light.c
@@ -136,27 +136,26 @@ static void light_foreach_id(ID *id, LibraryForeachIDData *data)
static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Light *la = (Light *)id;
- if (la->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, Light, id_address, &la->id);
- BKE_id_blend_write(writer, &la->id);
- if (la->adt) {
- BKE_animdata_blend_write(writer, la->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Light, id_address, &la->id);
+ BKE_id_blend_write(writer, &la->id);
- if (la->curfalloff) {
- BKE_curvemapping_blend_write(writer, la->curfalloff);
- }
+ if (la->adt) {
+ BKE_animdata_blend_write(writer, la->adt);
+ }
- /* Node-tree is integral part of lights, no libdata. */
- if (la->nodetree) {
- BLO_write_struct(writer, bNodeTree, la->nodetree);
- ntreeBlendWrite(writer, la->nodetree);
- }
+ if (la->curfalloff) {
+ BKE_curvemapping_blend_write(writer, la->curfalloff);
+ }
- BKE_previewimg_blend_write(writer, la->preview);
+ /* Node-tree is integral part of lights, no libdata. */
+ if (la->nodetree) {
+ BLO_write_struct(writer, bNodeTree, la->nodetree);
+ ntreeBlendWrite(writer, la->nodetree);
}
+
+ BKE_previewimg_blend_write(writer, la->preview);
}
static void light_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c
index b09aed82921..15733af8ef0 100644
--- a/source/blender/blenkernel/intern/lightprobe.c
+++ b/source/blender/blenkernel/intern/lightprobe.c
@@ -60,14 +60,13 @@ static void lightprobe_foreach_id(ID *id, LibraryForeachIDData *data)
static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
LightProbe *prb = (LightProbe *)id;
- if (prb->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
- BKE_id_blend_write(writer, &prb->id);
-
- if (prb->adt) {
- BKE_animdata_blend_write(writer, prb->adt);
- }
+
+ /* write LibData */
+ BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
+ BKE_id_blend_write(writer, &prb->id);
+
+ if (prb->adt) {
+ BKE_animdata_blend_write(writer, prb->adt);
}
}
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index 26d9ab7a8c7..19030fca38b 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -457,28 +457,27 @@ static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *mo
static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
- if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) {
- BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
- BKE_id_blend_write(writer, &linestyle->id);
- if (linestyle->adt) {
- BKE_animdata_blend_write(writer, linestyle->adt);
- }
+ BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
+ BKE_id_blend_write(writer, &linestyle->id);
- write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
- write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers);
- write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers);
- write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers);
- for (int a = 0; a < MAX_MTEX; a++) {
- if (linestyle->mtex[a]) {
- BLO_write_struct(writer, MTex, linestyle->mtex[a]);
- }
- }
- if (linestyle->nodetree) {
- BLO_write_struct(writer, bNodeTree, linestyle->nodetree);
- ntreeBlendWrite(writer, linestyle->nodetree);
+ if (linestyle->adt) {
+ BKE_animdata_blend_write(writer, linestyle->adt);
+ }
+
+ write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
+ write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers);
+ write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers);
+ write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers);
+ for (int a = 0; a < MAX_MTEX; a++) {
+ if (linestyle->mtex[a]) {
+ BLO_write_struct(writer, MTex, linestyle->mtex[a]);
}
}
+ if (linestyle->nodetree) {
+ BLO_write_struct(writer, bNodeTree, linestyle->nodetree);
+ ntreeBlendWrite(writer, linestyle->nodetree);
+ }
}
static void direct_link_linestyle_color_modifier(BlendDataReader *reader,
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index f40d1db60ff..a93fcb6e8e0 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -101,48 +101,47 @@ static void mask_foreach_id(ID *id, LibraryForeachIDData *data)
static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Mask *mask = (Mask *)id;
- if (mask->id.us > 0 || BLO_write_is_undo(writer)) {
- MaskLayer *masklay;
- BLO_write_id_struct(writer, Mask, id_address, &mask->id);
- BKE_id_blend_write(writer, &mask->id);
+ MaskLayer *masklay;
- if (mask->adt) {
- BKE_animdata_blend_write(writer, mask->adt);
- }
+ BLO_write_id_struct(writer, Mask, id_address, &mask->id);
+ BKE_id_blend_write(writer, &mask->id);
- for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
- MaskSpline *spline;
- MaskLayerShape *masklay_shape;
+ if (mask->adt) {
+ BKE_animdata_blend_write(writer, mask->adt);
+ }
- BLO_write_struct(writer, MaskLayer, masklay);
+ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+ MaskSpline *spline;
+ MaskLayerShape *masklay_shape;
- for (spline = masklay->splines.first; spline; spline = spline->next) {
- int i;
+ BLO_write_struct(writer, MaskLayer, masklay);
- void *points_deform = spline->points_deform;
- spline->points_deform = NULL;
+ for (spline = masklay->splines.first; spline; spline = spline->next) {
+ int i;
- BLO_write_struct(writer, MaskSpline, spline);
- BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points);
+ void *points_deform = spline->points_deform;
+ spline->points_deform = NULL;
- spline->points_deform = points_deform;
+ BLO_write_struct(writer, MaskSpline, spline);
+ BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points);
- for (i = 0; i < spline->tot_point; i++) {
- MaskSplinePoint *point = &spline->points[i];
+ spline->points_deform = points_deform;
- if (point->tot_uw) {
- BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw);
- }
+ for (i = 0; i < spline->tot_point; i++) {
+ MaskSplinePoint *point = &spline->points[i];
+
+ if (point->tot_uw) {
+ BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw);
}
}
+ }
- for (masklay_shape = masklay->splines_shapes.first; masklay_shape;
- masklay_shape = masklay_shape->next) {
- BLO_write_struct(writer, MaskLayerShape, masklay_shape);
- BLO_write_float_array(
- writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data);
- }
+ for (masklay_shape = masklay->splines_shapes.first; masklay_shape;
+ masklay_shape = masklay_shape->next) {
+ BLO_write_struct(writer, MaskLayerShape, masklay_shape);
+ BLO_write_float_array(
+ writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data);
}
}
}
diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c
index 8acc929a089..e04e5fceec6 100644
--- a/source/blender/blenkernel/intern/mask_rasterize.c
+++ b/source/blender/blenkernel/intern/mask_rasterize.c
@@ -292,10 +292,10 @@ static void maskrasterize_spline_differentiate_point_outset(float (*diff_feather
co_curr = diff_points[k_curr];
co_next = diff_points[k_next];
- /* sub_v2_v2v2(d_prev, co_prev, co_curr); */ /* precalc */
+ // sub_v2_v2v2(d_prev, co_prev, co_curr); /* precalc */
sub_v2_v2v2(d_next, co_curr, co_next);
- /* normalize_v2(d_prev); */ /* precalc */
+ // normalize_v2(d_prev); /* precalc */
normalize_v2(d_next);
if ((do_test == false) ||
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 4f0b2a718ed..13b5bca5638 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -179,31 +179,30 @@ static void material_foreach_id(ID *id, LibraryForeachIDData *data)
static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Material *ma = (Material *)id;
- if (ma->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- ma->texpaintslot = NULL;
- BLI_listbase_clear(&ma->gpumaterial);
- /* write LibData */
- BLO_write_id_struct(writer, Material, id_address, &ma->id);
- BKE_id_blend_write(writer, &ma->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ ma->texpaintslot = NULL;
+ BLI_listbase_clear(&ma->gpumaterial);
- if (ma->adt) {
- BKE_animdata_blend_write(writer, ma->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Material, id_address, &ma->id);
+ BKE_id_blend_write(writer, &ma->id);
- /* nodetree is integral part of material, no libdata */
- if (ma->nodetree) {
- BLO_write_struct(writer, bNodeTree, ma->nodetree);
- ntreeBlendWrite(writer, ma->nodetree);
- }
+ if (ma->adt) {
+ BKE_animdata_blend_write(writer, ma->adt);
+ }
- BKE_previewimg_blend_write(writer, ma->preview);
+ /* nodetree is integral part of material, no libdata */
+ if (ma->nodetree) {
+ BLO_write_struct(writer, bNodeTree, ma->nodetree);
+ ntreeBlendWrite(writer, ma->nodetree);
+ }
- /* grease pencil settings */
- if (ma->gp_style) {
- BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
- }
+ BKE_previewimg_blend_write(writer, ma->preview);
+
+ /* grease pencil settings */
+ if (ma->gp_style) {
+ BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
}
}
@@ -1802,6 +1801,7 @@ void BKE_material_copybuf_free(void)
{
if (matcopybuf.nodetree) {
ntreeFreeLocalTree(matcopybuf.nodetree);
+ BLI_assert(!matcopybuf.nodetree->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(matcopybuf.nodetree);
matcopybuf.nodetree = NULL;
}
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index 6a2b56306d6..45cf0f17840 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -119,28 +119,27 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
MetaBall *mb = (MetaBall *)id;
- if (mb->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- BLI_listbase_clear(&mb->disp);
- mb->editelems = NULL;
- /* Must always be cleared (meta's don't have their own edit-data). */
- mb->needs_flush_to_id = 0;
- mb->lastelem = NULL;
- mb->batch_cache = NULL;
-
- /* write LibData */
- BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
- BKE_id_blend_write(writer, &mb->id);
-
- /* direct data */
- BLO_write_pointer_array(writer, mb->totcol, mb->mat);
- if (mb->adt) {
- BKE_animdata_blend_write(writer, mb->adt);
- }
- LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
- BLO_write_struct(writer, MetaElem, ml);
- }
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ BLI_listbase_clear(&mb->disp);
+ mb->editelems = NULL;
+ /* Must always be cleared (meta's don't have their own edit-data). */
+ mb->needs_flush_to_id = 0;
+ mb->lastelem = NULL;
+ mb->batch_cache = NULL;
+
+ /* write LibData */
+ BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
+ BKE_id_blend_write(writer, &mb->id);
+
+ /* direct data */
+ BLO_write_pointer_array(writer, mb->totcol, mb->mat);
+ if (mb->adt) {
+ BKE_animdata_blend_write(writer, mb->adt);
+ }
+
+ LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
+ BLO_write_struct(writer, MetaElem, ml);
}
}
@@ -289,7 +288,7 @@ void BKE_mball_texspace_calc(Object *ob)
bb = ob->runtime.bb;
/* Weird one, this. */
- /* INIT_MINMAX(min, max); */
+ // INIT_MINMAX(min, max);
(min)[0] = (min)[1] = (min)[2] = 1.0e30f;
(max)[0] = (max)[1] = (max)[2] = -1.0e30f;
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 088026ef945..e3650e03c8a 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -179,95 +179,90 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
{
Mesh *mesh = (Mesh *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (mesh->id.us > 0 || is_undo) {
- CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE];
- CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE];
- CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE];
- CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE];
- CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
-
- /* cache only - don't write */
- mesh->mface = NULL;
- mesh->totface = 0;
- memset(&mesh->fdata, 0, sizeof(mesh->fdata));
- memset(&mesh->runtime, 0, sizeof(mesh->runtime));
- flayers = flayers_buff;
-
- /* Do not store actual geometry data in case this is a library override ID. */
- if (ID_IS_OVERRIDE_LIBRARY(mesh) && !is_undo) {
- mesh->mvert = NULL;
- mesh->totvert = 0;
- memset(&mesh->vdata, 0, sizeof(mesh->vdata));
- vlayers = vlayers_buff;
-
- mesh->medge = NULL;
- mesh->totedge = 0;
- memset(&mesh->edata, 0, sizeof(mesh->edata));
- elayers = elayers_buff;
-
- mesh->mloop = NULL;
- mesh->totloop = 0;
- memset(&mesh->ldata, 0, sizeof(mesh->ldata));
- llayers = llayers_buff;
-
- mesh->mpoly = NULL;
- mesh->totpoly = 0;
- memset(&mesh->pdata, 0, sizeof(mesh->pdata));
- players = players_buff;
- }
- else {
- CustomData_blend_write_prepare(
- &mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
- CustomData_blend_write_prepare(
- &mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
- CustomData_blend_write_prepare(
- &mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
- CustomData_blend_write_prepare(
- &mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
- }
- BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
- BKE_id_blend_write(writer, &mesh->id);
+ CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
- /* direct data */
- if (mesh->adt) {
- BKE_animdata_blend_write(writer, mesh->adt);
- }
+ /* cache only - don't write */
+ mesh->mface = NULL;
+ mesh->totface = 0;
+ memset(&mesh->fdata, 0, sizeof(mesh->fdata));
+ memset(&mesh->runtime, 0, sizeof(mesh->runtime));
+ flayers = flayers_buff;
+
+ /* Do not store actual geometry data in case this is a library override ID. */
+ if (ID_IS_OVERRIDE_LIBRARY(mesh) && !is_undo) {
+ mesh->mvert = NULL;
+ mesh->totvert = 0;
+ memset(&mesh->vdata, 0, sizeof(mesh->vdata));
+ vlayers = vlayers_buff;
+
+ mesh->medge = NULL;
+ mesh->totedge = 0;
+ memset(&mesh->edata, 0, sizeof(mesh->edata));
+ elayers = elayers_buff;
+
+ mesh->mloop = NULL;
+ mesh->totloop = 0;
+ memset(&mesh->ldata, 0, sizeof(mesh->ldata));
+ llayers = llayers_buff;
+
+ mesh->mpoly = NULL;
+ mesh->totpoly = 0;
+ memset(&mesh->pdata, 0, sizeof(mesh->pdata));
+ players = players_buff;
+ }
+ else {
+ CustomData_blend_write_prepare(&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
+ CustomData_blend_write_prepare(&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
+ CustomData_blend_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
+ CustomData_blend_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
+ }
- BKE_defbase_blend_write(writer, &mesh->vertex_group_names);
+ BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
+ BKE_id_blend_write(writer, &mesh->id);
- BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
- BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
+ /* direct data */
+ if (mesh->adt) {
+ BKE_animdata_blend_write(writer, mesh->adt);
+ }
+
+ BKE_defbase_blend_write(writer, &mesh->vertex_group_names);
- CustomData_blend_write(
- writer, &mesh->vdata, vlayers, mesh->totvert, CD_MASK_MESH.vmask, &mesh->id);
- CustomData_blend_write(
- writer, &mesh->edata, elayers, mesh->totedge, CD_MASK_MESH.emask, &mesh->id);
- /* fdata is really a dummy - written so slots align */
- CustomData_blend_write(
- writer, &mesh->fdata, flayers, mesh->totface, CD_MASK_MESH.fmask, &mesh->id);
- CustomData_blend_write(
- writer, &mesh->ldata, llayers, mesh->totloop, CD_MASK_MESH.lmask, &mesh->id);
- CustomData_blend_write(
- writer, &mesh->pdata, players, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id);
+ BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
+ BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
- /* Free temporary data */
+ CustomData_blend_write(
+ writer, &mesh->vdata, vlayers, mesh->totvert, CD_MASK_MESH.vmask, &mesh->id);
+ CustomData_blend_write(
+ writer, &mesh->edata, elayers, mesh->totedge, CD_MASK_MESH.emask, &mesh->id);
+ /* fdata is really a dummy - written so slots align */
+ CustomData_blend_write(
+ writer, &mesh->fdata, flayers, mesh->totface, CD_MASK_MESH.fmask, &mesh->id);
+ CustomData_blend_write(
+ writer, &mesh->ldata, llayers, mesh->totloop, CD_MASK_MESH.lmask, &mesh->id);
+ CustomData_blend_write(
+ writer, &mesh->pdata, players, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id);
-/* Free custom-data layers, when not assigned a buffer value. */
+ /* Free temporary data */
+
+ /* Free custom-data layers, when not assigned a buffer value. */
#define CD_LAYERS_FREE(id) \
if (id && id != id##_buff) { \
MEM_freeN(id); \
} \
((void)0)
- CD_LAYERS_FREE(vlayers);
- CD_LAYERS_FREE(elayers);
- /* CD_LAYER_FREE(flayers); */ /* Never allocated. */
- CD_LAYERS_FREE(llayers);
- CD_LAYERS_FREE(players);
+ CD_LAYERS_FREE(vlayers);
+ CD_LAYERS_FREE(elayers);
+ // CD_LAYER_FREE(flayers); /* Never allocated. */
+ CD_LAYERS_FREE(llayers);
+ CD_LAYERS_FREE(players);
#undef CD_LAYERS_FREE
- }
}
static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
@@ -430,63 +425,166 @@ static int customdata_compare(
{
const float thresh_sq = thresh * thresh;
CustomDataLayer *l1, *l2;
- int i1 = 0, i2 = 0, tot, j;
+ int layer_count1 = 0, layer_count2 = 0, j;
+ const uint64_t cd_mask_non_generic = CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MPOLY |
+ CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MDEFORMVERT;
+ const uint64_t cd_mask_all_attr = CD_MASK_PROP_ALL | cd_mask_non_generic;
for (int i = 0; i < c1->totlayer; i++) {
- if (ELEM(c1->layers[i].type,
- CD_MVERT,
- CD_MEDGE,
- CD_MPOLY,
- CD_MLOOPUV,
- CD_MLOOPCOL,
- CD_MDEFORMVERT)) {
- i1++;
+ if (CD_TYPE_AS_MASK(c1->layers[i].type) & cd_mask_all_attr) {
+ layer_count1++;
}
}
for (int i = 0; i < c2->totlayer; i++) {
- if (ELEM(c2->layers[i].type,
- CD_MVERT,
- CD_MEDGE,
- CD_MPOLY,
- CD_MLOOPUV,
- CD_MLOOPCOL,
- CD_MDEFORMVERT)) {
- i2++;
+ if (CD_TYPE_AS_MASK(c2->layers[i].type) & cd_mask_all_attr) {
+ layer_count2++;
}
}
- if (i1 != i2) {
+ if (layer_count1 != layer_count2) {
return MESHCMP_CDLAYERS_MISMATCH;
}
l1 = c1->layers;
l2 = c2->layers;
- for (i1 = 0; i1 < c1->totlayer; i1++) {
+ for (int i1 = 0; i1 < c1->totlayer; i1++) {
l1 = c1->layers + i1;
- if ((CD_TYPE_AS_MASK(l1->type) & CD_MASK_PROP_ALL) == 0) {
- /* Skip non generic attribute layers. */
- continue;
- }
-
- bool found_corresponding_layer = false;
- for (i2 = 0; i2 < c2->totlayer; i2++) {
+ for (int i2 = 0; i2 < c2->totlayer; i2++) {
l2 = c2->layers + i2;
if (l1->type != l2->type || !STREQ(l1->name, l2->name)) {
continue;
}
- found_corresponding_layer = true;
/* At this point `l1` and `l2` have the same name and type, so they should be compared. */
switch (l1->type) {
+ case CD_MVERT: {
+ MVert *v1 = l1->data;
+ MVert *v2 = l2->data;
+ int vtot = m1->totvert;
+
+ for (j = 0; j < vtot; j++, v1++, v2++) {
+ for (int k = 0; k < 3; k++) {
+ if (compare_threshold_relative(v1->co[k], v2->co[k], thresh)) {
+ return MESHCMP_VERTCOMISMATCH;
+ }
+ }
+ /* I don't care about normals, let's just do coordinates. */
+ }
+ break;
+ }
+
+ /* We're order-agnostic for edges here. */
+ case CD_MEDGE: {
+ MEdge *e1 = l1->data;
+ MEdge *e2 = l2->data;
+ int etot = m1->totedge;
+ EdgeHash *eh = BLI_edgehash_new_ex(__func__, etot);
+
+ for (j = 0; j < etot; j++, e1++) {
+ BLI_edgehash_insert(eh, e1->v1, e1->v2, e1);
+ }
+
+ for (j = 0; j < etot; j++, e2++) {
+ if (!BLI_edgehash_lookup(eh, e2->v1, e2->v2)) {
+ return MESHCMP_EDGEUNKNOWN;
+ }
+ }
+ BLI_edgehash_free(eh, NULL);
+ break;
+ }
+ case CD_MPOLY: {
+ MPoly *p1 = l1->data;
+ MPoly *p2 = l2->data;
+ int ptot = m1->totpoly;
+
+ for (j = 0; j < ptot; j++, p1++, p2++) {
+ MLoop *lp1, *lp2;
+ int k;
+
+ if (p1->totloop != p2->totloop) {
+ return MESHCMP_POLYMISMATCH;
+ }
+
+ lp1 = m1->mloop + p1->loopstart;
+ lp2 = m2->mloop + p2->loopstart;
+
+ for (k = 0; k < p1->totloop; k++, lp1++, lp2++) {
+ if (lp1->v != lp2->v) {
+ return MESHCMP_POLYVERTMISMATCH;
+ }
+ }
+ }
+ break;
+ }
+ case CD_MLOOP: {
+ MLoop *lp1 = l1->data;
+ MLoop *lp2 = l2->data;
+ int ltot = m1->totloop;
+
+ for (j = 0; j < ltot; j++, lp1++, lp2++) {
+ if (lp1->v != lp2->v) {
+ return MESHCMP_LOOPMISMATCH;
+ }
+ }
+ break;
+ }
+ case CD_MLOOPUV: {
+ MLoopUV *lp1 = l1->data;
+ MLoopUV *lp2 = l2->data;
+ int ltot = m1->totloop;
+
+ for (j = 0; j < ltot; j++, lp1++, lp2++) {
+ if (len_squared_v2v2(lp1->uv, lp2->uv) > thresh_sq) {
+ return MESHCMP_LOOPUVMISMATCH;
+ }
+ }
+ break;
+ }
+ case CD_MLOOPCOL: {
+ MLoopCol *lp1 = l1->data;
+ MLoopCol *lp2 = l2->data;
+ int ltot = m1->totloop;
+
+ for (j = 0; j < ltot; j++, lp1++, lp2++) {
+ if (lp1->r != lp2->r || lp1->g != lp2->g || lp1->b != lp2->b || lp1->a != lp2->a) {
+ return MESHCMP_LOOPCOLMISMATCH;
+ }
+ }
+ break;
+ }
+ case CD_MDEFORMVERT: {
+ MDeformVert *dv1 = l1->data;
+ MDeformVert *dv2 = l2->data;
+ int dvtot = m1->totvert;
+
+ for (j = 0; j < dvtot; j++, dv1++, dv2++) {
+ int k;
+ MDeformWeight *dw1 = dv1->dw, *dw2 = dv2->dw;
+
+ if (dv1->totweight != dv2->totweight) {
+ return MESHCMP_DVERT_TOTGROUPMISMATCH;
+ }
+
+ for (k = 0; k < dv1->totweight; k++, dw1++, dw2++) {
+ if (dw1->def_nr != dw2->def_nr) {
+ return MESHCMP_DVERT_GROUPMISMATCH;
+ }
+ if (fabsf(dw1->weight - dw2->weight) > thresh) {
+ return MESHCMP_DVERT_WEIGHTMISMATCH;
+ }
+ }
+ }
+ break;
+ }
case CD_PROP_FLOAT: {
const float *l1_data = l1->data;
const float *l2_data = l2->data;
for (int i = 0; i < total_length; i++) {
- if (fabsf(l1_data[i] - l2_data[i]) > thresh) {
+ if (compare_threshold_relative(l1_data[i], l2_data[i], thresh)) {
return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
}
}
@@ -497,7 +595,10 @@ static int customdata_compare(
const float(*l2_data)[2] = l2->data;
for (int i = 0; i < total_length; i++) {
- if (len_squared_v2v2(l1_data[i], l2_data[i]) > thresh_sq) {
+ if (compare_threshold_relative(l1_data[i][0], l2_data[i][0], thresh)) {
+ return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
+ }
+ if (compare_threshold_relative(l1_data[i][1], l2_data[i][1], thresh)) {
return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
}
}
@@ -508,163 +609,55 @@ static int customdata_compare(
const float(*l2_data)[3] = l2->data;
for (int i = 0; i < total_length; i++) {
- if (len_squared_v3v3(l1_data[i], l2_data[i]) > thresh_sq) {
+ if (compare_threshold_relative(l1_data[i][0], l2_data[i][0], thresh)) {
+ return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
+ }
+ if (compare_threshold_relative(l1_data[i][1], l2_data[i][1], thresh)) {
+ return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
+ }
+ if (compare_threshold_relative(l1_data[i][2], l2_data[i][2], thresh)) {
return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
}
}
break;
}
- default: {
- int element_size = CustomData_sizeof(l1->type);
+ case CD_PROP_INT32: {
+ const int *l1_data = l1->data;
+ const int *l2_data = l2->data;
+
for (int i = 0; i < total_length; i++) {
- int offset = element_size * i;
- if (!CustomData_data_equals(l1->type,
- POINTER_OFFSET(l1->data, offset),
- POINTER_OFFSET(l2->data, offset))) {
+ if (l1_data[i] != l2_data[i]) {
return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
}
}
break;
}
- }
- }
-
- if (!found_corresponding_layer) {
- return MESHCMP_CDLAYERS_MISMATCH;
- }
- }
-
- l1 = c1->layers;
- l2 = c2->layers;
- tot = i1;
- i1 = 0;
- i2 = 0;
- for (int i = 0; i < tot; i++) {
- while (
- i1 < c1->totlayer &&
- !ELEM(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY, CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT)) {
- i1++;
- l1++;
- }
-
- while (
- i2 < c2->totlayer &&
- !ELEM(l2->type, CD_MVERT, CD_MEDGE, CD_MPOLY, CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT)) {
- i2++;
- l2++;
- }
-
- if (l1->type == CD_MVERT) {
- MVert *v1 = l1->data;
- MVert *v2 = l2->data;
- int vtot = m1->totvert;
-
- for (j = 0; j < vtot; j++, v1++, v2++) {
- if (len_squared_v3v3(v1->co, v2->co) > thresh_sq) {
- return MESHCMP_VERTCOMISMATCH;
- }
- /* I don't care about normals, let's just do coordinates. */
- }
- }
-
- /* We're order-agnostic for edges here. */
- if (l1->type == CD_MEDGE) {
- MEdge *e1 = l1->data;
- MEdge *e2 = l2->data;
- int etot = m1->totedge;
- EdgeHash *eh = BLI_edgehash_new_ex(__func__, etot);
-
- for (j = 0; j < etot; j++, e1++) {
- BLI_edgehash_insert(eh, e1->v1, e1->v2, e1);
- }
-
- for (j = 0; j < etot; j++, e2++) {
- if (!BLI_edgehash_lookup(eh, e2->v1, e2->v2)) {
- return MESHCMP_EDGEUNKNOWN;
- }
- }
- BLI_edgehash_free(eh, NULL);
- }
-
- if (l1->type == CD_MPOLY) {
- MPoly *p1 = l1->data;
- MPoly *p2 = l2->data;
- int ptot = m1->totpoly;
-
- for (j = 0; j < ptot; j++, p1++, p2++) {
- MLoop *lp1, *lp2;
- int k;
-
- if (p1->totloop != p2->totloop) {
- return MESHCMP_POLYMISMATCH;
- }
-
- lp1 = m1->mloop + p1->loopstart;
- lp2 = m2->mloop + p2->loopstart;
+ case CD_PROP_BOOL: {
+ const bool *l1_data = l1->data;
+ const bool *l2_data = l2->data;
- for (k = 0; k < p1->totloop; k++, lp1++, lp2++) {
- if (lp1->v != lp2->v) {
- return MESHCMP_POLYVERTMISMATCH;
+ for (int i = 0; i < total_length; i++) {
+ if (l1_data[i] != l2_data[i]) {
+ return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
+ }
}
+ break;
}
- }
- }
- if (l1->type == CD_MLOOP) {
- MLoop *lp1 = l1->data;
- MLoop *lp2 = l2->data;
- int ltot = m1->totloop;
-
- for (j = 0; j < ltot; j++, lp1++, lp2++) {
- if (lp1->v != lp2->v) {
- return MESHCMP_LOOPMISMATCH;
- }
- }
- }
- if (l1->type == CD_MLOOPUV) {
- MLoopUV *lp1 = l1->data;
- MLoopUV *lp2 = l2->data;
- int ltot = m1->totloop;
-
- for (j = 0; j < ltot; j++, lp1++, lp2++) {
- if (len_squared_v2v2(lp1->uv, lp2->uv) > thresh_sq) {
- return MESHCMP_LOOPUVMISMATCH;
- }
- }
- }
-
- if (l1->type == CD_MLOOPCOL) {
- MLoopCol *lp1 = l1->data;
- MLoopCol *lp2 = l2->data;
- int ltot = m1->totloop;
-
- for (j = 0; j < ltot; j++, lp1++, lp2++) {
- if (abs(lp1->r - lp2->r) > thresh || abs(lp1->g - lp2->g) > thresh ||
- abs(lp1->b - lp2->b) > thresh || abs(lp1->a - lp2->a) > thresh) {
- return MESHCMP_LOOPCOLMISMATCH;
- }
- }
- }
-
- if (l1->type == CD_MDEFORMVERT) {
- MDeformVert *dv1 = l1->data;
- MDeformVert *dv2 = l2->data;
- int dvtot = m1->totvert;
-
- for (j = 0; j < dvtot; j++, dv1++, dv2++) {
- int k;
- MDeformWeight *dw1 = dv1->dw, *dw2 = dv2->dw;
-
- if (dv1->totweight != dv2->totweight) {
- return MESHCMP_DVERT_TOTGROUPMISMATCH;
- }
+ case CD_PROP_COLOR: {
+ const MPropCol *l1_data = l1->data;
+ const MPropCol *l2_data = l2->data;
- for (k = 0; k < dv1->totweight; k++, dw1++, dw2++) {
- if (dw1->def_nr != dw2->def_nr) {
- return MESHCMP_DVERT_GROUPMISMATCH;
- }
- if (fabsf(dw1->weight - dw2->weight) > thresh) {
- return MESHCMP_DVERT_WEIGHTMISMATCH;
+ for (int i = 0; i < total_length; i++) {
+ for (j = 0; j < 4; j++) {
+ if (compare_threshold_relative(l1_data[i].color[j], l2_data[i].color[j], thresh)) {
+ return MESHCMP_ATTRIBUTE_VALUE_MISMATCH;
+ }
+ }
}
+ break;
+ }
+ default: {
+ break;
}
}
}
@@ -878,8 +871,11 @@ bool BKE_mesh_has_custom_loop_normals(Mesh *me)
return CustomData_has_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
}
-/** Free (or release) any data used by this mesh (does not free the mesh itself). */
-void BKE_mesh_free(Mesh *me)
+/**
+ * Free (or release) any data used by this mesh (does not free the mesh itself).
+ * Only use for undo, in most cases `BKE_id_free(NULL, me)` should be used.
+ */
+void BKE_mesh_free_data_for_undo(Mesh *me)
{
mesh_free_data(&me->id);
}
@@ -967,7 +963,7 @@ Mesh *BKE_mesh_new_nomain(
NULL, ID_ME, BKE_idtype_idcode_to_name(ID_ME), LIB_ID_CREATE_LOCALIZE);
BKE_libblock_init_empty(&mesh->id);
- /* Don't use CustomData_reset(...); because we don't want to touch custom-data. */
+ /* Don't use #CustomData_reset because we don't want to touch custom-data. */
copy_vn_i(mesh->vdata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->edata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->fdata.typemap, CD_NUMTYPES, -1);
@@ -1095,7 +1091,7 @@ void BKE_mesh_eval_delete(struct Mesh *mesh_eval)
{
/* Evaluated mesh may point to edit mesh, but never owns it. */
mesh_eval->edit_mesh = NULL;
- BKE_mesh_free(mesh_eval);
+ mesh_free_data(&mesh_eval->id);
BKE_libblock_free_data(&mesh_eval->id, false);
MEM_freeN(mesh_eval);
}
@@ -1915,15 +1911,14 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spac
}
else {
polynors = MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__);
- BKE_mesh_calc_normals_poly(mesh->mvert,
- NULL,
- mesh->totvert,
- mesh->mloop,
- mesh->mpoly,
- mesh->totloop,
- mesh->totpoly,
- polynors,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(mesh->mvert,
+ mesh->totvert,
+ mesh->mloop,
+ mesh->totloop,
+ mesh->mpoly,
+ mesh->totpoly,
+ polynors,
+ NULL);
free_polynors = true;
}
diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
index ca594470cba..d5524312612 100644
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@ -272,8 +272,8 @@ static int mesh_nurbs_displist_to_mdata(const Curve *cu,
}
if (totvert == 0) {
- /* error("can't convert"); */
- /* Make Sure you check ob->data is a curve */
+ /* Make Sure you check ob->data is a curve. */
+ // error("can't convert");
return -1;
}
@@ -548,11 +548,12 @@ Mesh *BKE_mesh_new_nomain_from_curve(const Object *ob)
return BKE_mesh_new_nomain_from_curve_displist(ob, &disp);
}
-/* this may fail replacing ob->data, be sure to check ob->type */
-void BKE_mesh_from_nurbs_displist(
- Main *bmain, Object *ob, ListBase *dispbase, const char *obdata_name, bool temporary)
+static void mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, const char *obdata_name)
{
- Object *ob1;
+ if (ob->runtime.data_eval && GS(((ID *)ob->runtime.data_eval)->name) != ID_ME) {
+ return;
+ }
+
Mesh *me_eval = (Mesh *)ob->runtime.data_eval;
Mesh *me;
MVert *allvert = NULL;
@@ -581,12 +582,7 @@ void BKE_mesh_from_nurbs_displist(
}
/* make mesh */
- if (bmain != NULL) {
- me = BKE_mesh_add(bmain, obdata_name);
- }
- else {
- me = BKE_id_new_nomain(ID_ME, obdata_name);
- }
+ me = BKE_id_new_nomain(ID_ME, obdata_name);
me->totvert = totvert;
me->totedge = totedge;
@@ -607,12 +603,7 @@ void BKE_mesh_from_nurbs_displist(
BKE_mesh_calc_normals(me);
}
else {
- if (bmain != NULL) {
- me = BKE_mesh_add(bmain, obdata_name);
- }
- else {
- me = BKE_id_new_nomain(ID_ME, obdata_name);
- }
+ me = BKE_id_new_nomain(ID_ME, obdata_name);
ob->runtime.data_eval = NULL;
BKE_mesh_nomain_to_mesh(me_eval, me, ob, &CD_MASK_MESH, true);
@@ -641,30 +632,10 @@ void BKE_mesh_from_nurbs_displist(
ob->data = me;
ob->type = OB_MESH;
- /* other users */
- if (bmain != NULL) {
- ob1 = bmain->objects.first;
- while (ob1) {
- if (ob1->data == cu) {
- ob1->type = OB_MESH;
-
- id_us_min((ID *)ob1->data);
- ob1->data = ob->data;
- id_us_plus((ID *)ob1->data);
- }
- ob1 = ob1->id.next;
- }
- }
-
- if (temporary) {
- /* For temporary objects in BKE_mesh_new_from_object don't remap
- * the entire scene with associated depsgraph updates, which are
- * problematic for renderers exporting data. */
- BKE_id_free(NULL, cu);
- }
- else {
- BKE_id_free_us(bmain, cu);
- }
+ /* For temporary objects in BKE_mesh_new_from_object don't remap
+ * the entire scene with associated depsgraph updates, which are
+ * problematic for renderers exporting data. */
+ BKE_id_free(NULL, cu);
}
typedef struct EdgeLink {
@@ -965,7 +936,7 @@ void BKE_pointcloud_to_mesh(Main *bmain, Depsgraph *depsgraph, Scene *UNUSED(sce
/* Create a temporary object to be used for nurbs-to-mesh conversion.
*
- * This is more complex that it should be because BKE_mesh_from_nurbs_displist() will do more than
+ * This is more complex that it should be because #mesh_from_nurbs_displist will do more than
* simply conversion and will attempt to take over ownership of evaluated result and will also
* modify the input object. */
static Object *object_for_curve_to_mesh_create(Object *object)
@@ -1063,7 +1034,7 @@ static void curve_to_mesh_eval_ensure(Object *object)
* they are only used for modifier stack, which we have explicitly disabled for all objects.
*
* TODO(sergey): This is a very fragile logic, but proper solution requires re-writing quite a
- * bit of internal functions (BKE_mesh_from_nurbs_displist, BKE_mesh_nomain_to_mesh) and also
+ * bit of internal functions (#mesh_from_nurbs_displist, BKE_mesh_nomain_to_mesh) and also
* Mesh From Curve operator.
* Brecht says hold off with that. */
Mesh *mesh_eval = NULL;
@@ -1102,10 +1073,10 @@ static Mesh *mesh_new_from_curve_type_object(Object *object)
temp_curve->editnurb = NULL;
/* Convert to mesh. */
- BKE_mesh_from_nurbs_displist(
- NULL, temp_object, &temp_object->runtime.curve_cache->disp, curve->id.name + 2, true);
+ mesh_from_nurbs_displist(
+ temp_object, &temp_object->runtime.curve_cache->disp, curve->id.name + 2);
- /* BKE_mesh_from_nurbs_displist changes the type to a mesh, check it worked. If it didn't
+ /* #mesh_from_nurbs_displist changes the type to a mesh, check it worked. If it didn't
* the curve did not have any segments or otherwise would have generated an empty mesh. */
if (temp_object->type != OB_MESH) {
BKE_id_free(NULL, temp_object->data);
@@ -1117,7 +1088,7 @@ static Mesh *mesh_new_from_curve_type_object(Object *object)
BKE_id_free(NULL, temp_object);
- /* NOTE: Materials are copied in BKE_mesh_from_nurbs_displist(). */
+ /* NOTE: Materials are copied in #mesh_from_nurbs_displist(). */
return mesh_result;
}
diff --git a/source/blender/blenkernel/intern/mesh_mirror.c b/source/blender/blenkernel/intern/mesh_mirror.c
index 9aeaa1ada52..b20d81e7b9c 100644
--- a/source/blender/blenkernel/intern/mesh_mirror.c
+++ b/source/blender/blenkernel/intern/mesh_mirror.c
@@ -393,15 +393,14 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
/* calculate custom normals into loop_normals, then mirror first half into second half */
- BKE_mesh_calc_normals_poly(result->mvert,
- NULL,
- result->totvert,
- result->mloop,
- result->mpoly,
- totloop,
- totpoly,
- poly_normals,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(result->mvert,
+ result->totvert,
+ result->mloop,
+ totloop,
+ result->mpoly,
+ totpoly,
+ poly_normals,
+ NULL);
BKE_mesh_normals_loop_split(result->mvert,
result->totvert,
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index 87b11904f90..9a761c6fa11 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -27,8 +27,6 @@
#include <climits>
-#include "CLG_log.h"
-
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
@@ -50,6 +48,8 @@
#include "BKE_global.h"
#include "BKE_mesh.h"
+#include "atomic_ops.h"
+
// #define DEBUG_TIME
#ifdef DEBUG_TIME
@@ -57,325 +57,257 @@
# include "PIL_time_utildefines.h"
#endif
-static CLG_LogRef LOG = {"bke.mesh_normals"};
-
/* -------------------------------------------------------------------- */
-/** \name Mesh Normal Calculation
+/** \name Private Utility Functions
* \{ */
-void BKE_mesh_normals_tag_dirty(Mesh *mesh)
-{
- mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
- mesh->runtime.cd_dirty_poly |= CD_MASK_NORMAL;
-}
-
/**
- * Call when there are no polygons.
+ * A thread-safe version of #add_v3_v3 that uses a spin-lock.
+ *
+ * \note Avoid using this when the chance of contention is high.
*/
-static void mesh_calc_normals_vert_fallback(MVert *mverts, int numVerts)
+static void add_v3_v3_atomic(float r[3], const float a[3])
{
- for (int i = 0; i < numVerts; i++) {
- MVert *mv = &mverts[i];
- float no[3];
+#define FLT_EQ_NONAN(_fa, _fb) (*((const uint32_t *)&_fa) == *((const uint32_t *)&_fb))
- normalize_v3_v3(no, mv->co);
- normal_float_to_short_v3(mv->no, no);
+ float virtual_lock = r[0];
+ while (true) {
+ /* This loops until following conditions are met:
+ * - `r[0]` has same value as virtual_lock (i.e. it did not change since last try).
+ * - `r[0]` was not `FLT_MAX`, i.e. it was not locked by another thread. */
+ const float test_lock = atomic_cas_float(&r[0], virtual_lock, FLT_MAX);
+ if (_ATOMIC_LIKELY(FLT_EQ_NONAN(test_lock, virtual_lock) && (test_lock != FLT_MAX))) {
+ break;
+ }
+ virtual_lock = test_lock;
}
-}
+ virtual_lock += a[0];
+ r[1] += a[1];
+ r[2] += a[2];
-/* TODO(Sybren): we can probably rename this to BKE_mesh_calc_normals_mapping(),
- * and remove the function of the same name below, as that one doesn't seem to be
- * called anywhere. */
-void BKE_mesh_calc_normals_mapping_simple(struct Mesh *mesh)
-{
- const bool only_face_normals = CustomData_is_referenced_layer(&mesh->vdata, CD_MVERT);
-
- BKE_mesh_calc_normals_mapping_ex(mesh->mvert,
- mesh->totvert,
- mesh->mloop,
- mesh->mpoly,
- mesh->totloop,
- mesh->totpoly,
- nullptr,
- mesh->mface,
- mesh->totface,
- nullptr,
- nullptr,
- only_face_normals);
-}
+ /* Second atomic operation to 'release'
+ * our lock on that vector and set its first scalar value. */
+ /* Note that we do not need to loop here, since we 'locked' `r[0]`,
+ * nobody should have changed it in the mean time. */
+ virtual_lock = atomic_cas_float(&r[0], FLT_MAX, virtual_lock);
+ BLI_assert(virtual_lock == FLT_MAX);
-/* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-nullptr
- * and vertex normals are stored in actual mverts.
- */
-void BKE_mesh_calc_normals_mapping(MVert *mverts,
- int numVerts,
- const MLoop *mloop,
- const MPoly *mpolys,
- int numLoops,
- int numPolys,
- float (*r_polyNors)[3],
- const MFace *mfaces,
- int numFaces,
- const int *origIndexFace,
- float (*r_faceNors)[3])
-{
- BKE_mesh_calc_normals_mapping_ex(mverts,
- numVerts,
- mloop,
- mpolys,
- numLoops,
- numPolys,
- r_polyNors,
- mfaces,
- numFaces,
- origIndexFace,
- r_faceNors,
- false);
+#undef FLT_EQ_NONAN
}
-/* extended version of 'BKE_mesh_calc_normals_poly' with option not to calc vertex normals */
-void BKE_mesh_calc_normals_mapping_ex(MVert *mverts,
- int numVerts,
- const MLoop *mloop,
- const MPoly *mpolys,
- int numLoops,
- int numPolys,
- float (*r_polyNors)[3],
- const MFace *mfaces,
- int numFaces,
- const int *origIndexFace,
- float (*r_faceNors)[3],
- const bool only_face_normals)
-{
- float(*pnors)[3] = r_polyNors, (*fnors)[3] = r_faceNors;
- if (numPolys == 0) {
- if (only_face_normals == false) {
- mesh_calc_normals_vert_fallback(mverts, numVerts);
- }
- return;
- }
-
- /* if we are not calculating verts and no verts were passes then we have nothing to do */
- if ((only_face_normals == true) && (r_polyNors == nullptr) && (r_faceNors == nullptr)) {
- CLOG_WARN(&LOG, "called with nothing to do");
- return;
- }
-
- if (!pnors) {
- pnors = (float(*)[3])MEM_calloc_arrayN((size_t)numPolys, sizeof(float[3]), __func__);
- }
- /* NO NEED TO ALLOC YET */
- /* if (!fnors) fnors = MEM_calloc_arrayN(numFaces, sizeof(float[3]), "face nors mesh.c"); */
+/** \} */
- if (only_face_normals == false) {
- /* vertex normals are optional, they require some extra calculations,
- * so make them optional */
- BKE_mesh_calc_normals_poly(
- mverts, nullptr, numVerts, mloop, mpolys, numLoops, numPolys, pnors, false);
- }
- else {
- /* only calc poly normals */
- const MPoly *mp = mpolys;
- for (int i = 0; i < numPolys; i++, mp++) {
- BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]);
- }
- }
+/* -------------------------------------------------------------------- */
+/** \name Public Utility Functions
+ *
+ * Related to managing normals but not directly related to calculating normals.
+ * \{ */
- if (origIndexFace &&
- /* fnors == r_faceNors */ /* NO NEED TO ALLOC YET */
- fnors != nullptr &&
- numFaces) {
- const MFace *mf = mfaces;
- for (int i = 0; i < numFaces; i++, mf++, origIndexFace++) {
- if (*origIndexFace < numPolys) {
- copy_v3_v3(fnors[i], pnors[*origIndexFace]);
- }
- else {
- /* eek, we're not corresponding to polys */
- CLOG_ERROR(&LOG, "tessellation face indices are incorrect. normals may look bad.");
- }
- }
- }
+void BKE_mesh_normals_tag_dirty(Mesh *mesh)
+{
+ mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
+ mesh->runtime.cd_dirty_poly |= CD_MASK_NORMAL;
+}
- if (pnors != r_polyNors) {
- MEM_freeN(pnors);
- }
- /* if (fnors != r_faceNors) MEM_freeN(fnors); */ /* NO NEED TO ALLOC YET */
+/** \} */
- fnors = pnors = nullptr;
-}
+/* -------------------------------------------------------------------- */
+/** \name Mesh Normal Calculation (Polygons)
+ * \{ */
-struct MeshCalcNormalsData {
- const MPoly *mpolys;
+struct MeshCalcNormalsData_Poly {
+ const MVert *mvert;
const MLoop *mloop;
- MVert *mverts;
+ const MPoly *mpoly;
+
+ /** Polygon normal output. */
float (*pnors)[3];
- float (*lnors_weighted)[3];
- float (*vnors)[3];
};
-static void mesh_calc_normals_poly_cb(void *__restrict userdata,
+static void mesh_calc_normals_poly_fn(void *__restrict userdata,
const int pidx,
const TaskParallelTLS *__restrict UNUSED(tls))
{
- MeshCalcNormalsData *data = (MeshCalcNormalsData *)userdata;
- const MPoly *mp = &data->mpolys[pidx];
+ const MeshCalcNormalsData_Poly *data = (MeshCalcNormalsData_Poly *)userdata;
+ const MPoly *mp = &data->mpoly[pidx];
+ BKE_mesh_calc_poly_normal(mp, data->mloop + mp->loopstart, data->mvert, data->pnors[pidx]);
+}
+
+void BKE_mesh_calc_normals_poly(const MVert *mvert,
+ int UNUSED(mvert_len),
+ const MLoop *mloop,
+ int UNUSED(mloop_len),
+ const MPoly *mpoly,
+ int mpoly_len,
+ float (*r_poly_normals)[3])
+{
+ TaskParallelSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.min_iter_per_thread = 1024;
- BKE_mesh_calc_poly_normal(mp, data->mloop + mp->loopstart, data->mverts, data->pnors[pidx]);
+ BLI_assert((r_poly_normals != nullptr) || (mpoly_len == 0));
+
+ MeshCalcNormalsData_Poly data = {};
+ data.mpoly = mpoly;
+ data.mloop = mloop;
+ data.mvert = mvert;
+ data.pnors = r_poly_normals;
+
+ BLI_task_parallel_range(0, mpoly_len, &data, mesh_calc_normals_poly_fn, &settings);
}
-static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata,
- const int pidx,
- const TaskParallelTLS *__restrict UNUSED(tls))
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Mesh Normal Calculation (Polygons & Vertices)
+ *
+ * Implement #BKE_mesh_calc_normals_poly_and_vertex,
+ *
+ * Take care making optimizations to this function as improvements to low-poly
+ * meshes can slow down high-poly meshes. For details on performance, see D11993.
+ * \{ */
+
+struct MeshCalcNormalsData_PolyAndVertex {
+ /** Write into vertex normals #MVert.no. */
+ MVert *mvert;
+ const MLoop *mloop;
+ const MPoly *mpoly;
+
+ /** Polygon normal output. */
+ float (*pnors)[3];
+ /** Vertex normal output (may be freed, copied into #MVert.no). */
+ float (*vnors)[3];
+};
+
+static void mesh_calc_normals_poly_and_vertex_accum_fn(
+ void *__restrict userdata, const int pidx, const TaskParallelTLS *__restrict UNUSED(tls))
{
- MeshCalcNormalsData *data = (MeshCalcNormalsData *)userdata;
- const MPoly *mp = &data->mpolys[pidx];
+ const MeshCalcNormalsData_PolyAndVertex *data = (MeshCalcNormalsData_PolyAndVertex *)userdata;
+ const MPoly *mp = &data->mpoly[pidx];
const MLoop *ml = &data->mloop[mp->loopstart];
- const MVert *mverts = data->mverts;
+ const MVert *mverts = data->mvert;
+ float(*vnors)[3] = data->vnors;
float pnor_temp[3];
float *pnor = data->pnors ? data->pnors[pidx] : pnor_temp;
- float(*lnors_weighted)[3] = data->lnors_weighted;
- const int nverts = mp->totloop;
- float(*edgevecbuf)[3] = (float(*)[3])BLI_array_alloca(edgevecbuf, (size_t)nverts);
+ const int i_end = mp->totloop - 1;
- /* Polygon Normal and edge-vector */
- /* inline version of #BKE_mesh_calc_poly_normal, also does edge-vectors */
+ /* Polygon Normal and edge-vector. */
+ /* Inline version of #BKE_mesh_calc_poly_normal, also does edge-vectors. */
{
- int i_prev = nverts - 1;
- const float *v_prev = mverts[ml[i_prev].v].co;
- const float *v_curr;
-
zero_v3(pnor);
/* Newell's Method */
- for (int i = 0; i < nverts; i++) {
- v_curr = mverts[ml[i].v].co;
- add_newell_cross_v3_v3v3(pnor, v_prev, v_curr);
-
- /* Unrelated to normalize, calculate edge-vector */
- sub_v3_v3v3(edgevecbuf[i_prev], v_prev, v_curr);
- normalize_v3(edgevecbuf[i_prev]);
- i_prev = i;
-
- v_prev = v_curr;
+ const float *v_curr = mverts[ml[i_end].v].co;
+ for (int i_next = 0; i_next <= i_end; i_next++) {
+ const float *v_next = mverts[ml[i_next].v].co;
+ add_newell_cross_v3_v3v3(pnor, v_curr, v_next);
+ v_curr = v_next;
}
if (UNLIKELY(normalize_v3(pnor) == 0.0f)) {
- pnor[2] = 1.0f; /* other axes set to 0.0 */
+ pnor[2] = 1.0f; /* Other axes set to zero. */
}
}
- /* accumulate angle weighted face normal */
- /* inline version of #accumulate_vertex_normals_poly_v3,
- * split between this threaded callback and #mesh_calc_normals_poly_accum_cb. */
+ /* Accumulate angle weighted face normal into the vertex normal. */
+ /* Inline version of #accumulate_vertex_normals_poly_v3. */
{
- const float *prev_edge = edgevecbuf[nverts - 1];
-
- for (int i = 0; i < nverts; i++) {
- const int lidx = mp->loopstart + i;
- const float *cur_edge = edgevecbuf[i];
-
- /* calculate angle between the two poly edges incident on
- * this vertex */
- const float fac = saacos(-dot_v3v3(cur_edge, prev_edge));
+ float edvec_prev[3], edvec_next[3], edvec_end[3];
+ const float *v_curr = mverts[ml[i_end].v].co;
+ sub_v3_v3v3(edvec_prev, mverts[ml[i_end - 1].v].co, v_curr);
+ normalize_v3(edvec_prev);
+ copy_v3_v3(edvec_end, edvec_prev);
+
+ for (int i_next = 0, i_curr = i_end; i_next <= i_end; i_curr = i_next++) {
+ const float *v_next = mverts[ml[i_next].v].co;
+
+ /* Skip an extra normalization by reusing the first calculated edge. */
+ if (i_next != i_end) {
+ sub_v3_v3v3(edvec_next, v_curr, v_next);
+ normalize_v3(edvec_next);
+ }
+ else {
+ copy_v3_v3(edvec_next, edvec_end);
+ }
- /* Store for later accumulation */
- mul_v3_v3fl(lnors_weighted[lidx], pnor, fac);
+ /* Calculate angle between the two poly edges incident on this vertex. */
+ const float fac = saacos(-dot_v3v3(edvec_prev, edvec_next));
+ const float vnor_add[3] = {pnor[0] * fac, pnor[1] * fac, pnor[2] * fac};
- prev_edge = cur_edge;
+ add_v3_v3_atomic(vnors[ml[i_curr].v], vnor_add);
+ v_curr = v_next;
+ copy_v3_v3(edvec_prev, edvec_next);
}
}
}
-static void mesh_calc_normals_poly_finalize_cb(void *__restrict userdata,
- const int vidx,
- const TaskParallelTLS *__restrict UNUSED(tls))
+static void mesh_calc_normals_poly_and_vertex_finalize_fn(
+ void *__restrict userdata, const int vidx, const TaskParallelTLS *__restrict UNUSED(tls))
{
- MeshCalcNormalsData *data = (MeshCalcNormalsData *)userdata;
+ MeshCalcNormalsData_PolyAndVertex *data = (MeshCalcNormalsData_PolyAndVertex *)userdata;
- MVert *mv = &data->mverts[vidx];
+ MVert *mv = &data->mvert[vidx];
float *no = data->vnors[vidx];
if (UNLIKELY(normalize_v3(no) == 0.0f)) {
- /* following Mesh convention; we use vertex coordinate itself for normal in this case */
+ /* Following Mesh convention; we use vertex coordinate itself for normal in this case. */
normalize_v3_v3(no, mv->co);
}
normal_float_to_short_v3(mv->no, no);
}
-void BKE_mesh_calc_normals_poly(MVert *mverts,
- float (*r_vertnors)[3],
- int numVerts,
- const MLoop *mloop,
- const MPoly *mpolys,
- int numLoops,
- int numPolys,
- float (*r_polynors)[3],
- const bool only_face_normals)
+void BKE_mesh_calc_normals_poly_and_vertex(MVert *mvert,
+ const int mvert_len,
+ const MLoop *mloop,
+ const int UNUSED(mloop_len),
+ const MPoly *mpoly,
+ const int mpoly_len,
+ float (*r_poly_normals)[3],
+ float (*r_vert_normals)[3])
{
- float(*pnors)[3] = r_polynors;
-
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
settings.min_iter_per_thread = 1024;
- if (only_face_normals) {
- BLI_assert((pnors != nullptr) || (numPolys == 0));
- BLI_assert(r_vertnors == nullptr);
-
- MeshCalcNormalsData data;
- data.mpolys = mpolys;
- data.mloop = mloop;
- data.mverts = mverts;
- data.pnors = pnors;
-
- BLI_task_parallel_range(0, numPolys, &data, mesh_calc_normals_poly_cb, &settings);
- return;
- }
-
- float(*vnors)[3] = r_vertnors;
- float(*lnors_weighted)[3] = (float(*)[3])MEM_malloc_arrayN(
- (size_t)numLoops, sizeof(*lnors_weighted), __func__);
+ float(*vnors)[3] = r_vert_normals;
bool free_vnors = false;
- /* first go through and calculate normals for all the polys */
+ /* First go through and calculate normals for all the polys. */
if (vnors == nullptr) {
- vnors = (float(*)[3])MEM_calloc_arrayN((size_t)numVerts, sizeof(*vnors), __func__);
+ vnors = (float(*)[3])MEM_calloc_arrayN((size_t)mvert_len, sizeof(*vnors), __func__);
free_vnors = true;
}
else {
- memset(vnors, 0, sizeof(*vnors) * (size_t)numVerts);
+ memset(vnors, 0, sizeof(*vnors) * (size_t)mvert_len);
}
- MeshCalcNormalsData data;
- data.mpolys = mpolys;
+ MeshCalcNormalsData_PolyAndVertex data = {};
+ data.mpoly = mpoly;
data.mloop = mloop;
- data.mverts = mverts;
- data.pnors = pnors;
- data.lnors_weighted = lnors_weighted;
+ data.mvert = mvert;
+ data.pnors = r_poly_normals;
data.vnors = vnors;
- /* Compute poly normals, and prepare weighted loop normals. */
- BLI_task_parallel_range(0, numPolys, &data, mesh_calc_normals_poly_prepare_cb, &settings);
+ /* Compute poly normals (`pnors`), accumulating them into vertex normals (`vnors`). */
+ BLI_task_parallel_range(
+ 0, mpoly_len, &data, mesh_calc_normals_poly_and_vertex_accum_fn, &settings);
- /* Actually accumulate weighted loop normals into vertex ones. */
- /* Unfortunately, not possible to thread that
- * (not in a reasonable, totally lock- and barrier-free fashion),
- * since several loops will point to the same vertex... */
- for (int lidx = 0; lidx < numLoops; lidx++) {
- add_v3_v3(vnors[mloop[lidx].v], data.lnors_weighted[lidx]);
- }
-
- /* Normalize and validate computed vertex normals. */
- BLI_task_parallel_range(0, numVerts, &data, mesh_calc_normals_poly_finalize_cb, &settings);
+ /* Normalize and validate computed vertex normals (`vnors`). */
+ BLI_task_parallel_range(
+ 0, mvert_len, &data, mesh_calc_normals_poly_and_vertex_finalize_fn, &settings);
if (free_vnors) {
MEM_freeN(vnors);
}
- MEM_freeN(lnors_weighted);
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Mesh Normal Calculation
+ * \{ */
+
void BKE_mesh_ensure_normals(Mesh *mesh)
{
if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) {
@@ -416,16 +348,26 @@ void BKE_mesh_ensure_normals_for_display(Mesh *mesh)
(size_t)mesh->totpoly, sizeof(*poly_nors), __func__);
}
- /* calculate poly/vert normals */
- BKE_mesh_calc_normals_poly(mesh->mvert,
- nullptr,
- mesh->totvert,
- mesh->mloop,
- mesh->mpoly,
- mesh->totloop,
- mesh->totpoly,
- poly_nors,
- !do_vert_normals);
+ /* Calculate poly/vert normals. */
+ if (do_vert_normals) {
+ BKE_mesh_calc_normals_poly_and_vertex(mesh->mvert,
+ mesh->totvert,
+ mesh->mloop,
+ mesh->totloop,
+ mesh->mpoly,
+ mesh->totpoly,
+ poly_nors,
+ nullptr);
+ }
+ else {
+ BKE_mesh_calc_normals_poly(mesh->mvert,
+ mesh->totvert,
+ mesh->mloop,
+ mesh->totloop,
+ mesh->mpoly,
+ mesh->totpoly,
+ poly_nors);
+ }
if (do_add_poly_nors_cddata) {
CustomData_add_layer(&mesh->pdata, CD_NORMAL, CD_ASSIGN, poly_nors, mesh->totpoly);
@@ -436,22 +378,23 @@ void BKE_mesh_ensure_normals_for_display(Mesh *mesh)
}
}
-/* Note that this does not update the CD_NORMAL layer,
- * but does update the normals in the CD_MVERT layer. */
+/**
+ * NOTE: this does not update the #CD_NORMAL layer,
+ * but does update the normals in the #CD_MVERT layer.
+ */
void BKE_mesh_calc_normals(Mesh *mesh)
{
#ifdef DEBUG_TIME
TIMEIT_START_AVERAGED(BKE_mesh_calc_normals);
#endif
- BKE_mesh_calc_normals_poly(mesh->mvert,
- nullptr,
- mesh->totvert,
- mesh->mloop,
- mesh->mpoly,
- mesh->totloop,
- mesh->totpoly,
- nullptr,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(mesh->mvert,
+ mesh->totvert,
+ mesh->mloop,
+ mesh->totloop,
+ mesh->mpoly,
+ mesh->totpoly,
+ nullptr,
+ nullptr);
#ifdef DEBUG_TIME
TIMEIT_END_AVERAGED(BKE_mesh_calc_normals);
#endif
@@ -494,7 +437,7 @@ void BKE_mesh_calc_normals_looptri(MVert *mverts,
mverts[vtri[2]].co);
}
- /* following Mesh convention; we use vertex coordinate itself for normal in this case */
+ /* Following Mesh convention; we use vertex coordinate itself for normal in this case. */
for (int i = 0; i < numVerts; i++) {
MVert *mv = &mverts[i];
float *no = tnorms[i];
@@ -634,11 +577,11 @@ void BKE_lnor_space_define(MLoopNorSpace *lnor_space,
BLI_stack_discard(edge_vectors);
nbr++;
}
- /* NOTE: In theory, this could be 'nbr > 2',
- * but there is one case where we only have two edges for two loops:
- * a smooth vertex with only two edges and two faces (our Monkey's nose has that, e.g.).
+ /* NOTE: In theory, this could be `nbr > 2`,
+ * but there is one case where we only have two edges for two loops:
+ * a smooth vertex with only two edges and two faces (our Monkey's nose has that, e.g.).
*/
- BLI_assert(nbr >= 2); /* This piece of code shall only be called for more than one loop... */
+ BLI_assert(nbr >= 2); /* This piece of code shall only be called for more than one loop. */
lnor_space->ref_alpha = alpha / (float)nbr;
}
else {
@@ -710,7 +653,7 @@ MINLINE float unit_short_to_float(const short val)
MINLINE short unit_float_to_short(const float val)
{
- /* Rounding... */
+ /* Rounding. */
return (short)floorf(val * (float)SHRT_MAX + 0.5f);
}
@@ -921,7 +864,7 @@ static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data,
e2l[1] = INDEX_INVALID;
/* We want to avoid tagging edges as sharp when it is already defined as such by
- * other causes than angle threshold... */
+ * other causes than angle threshold. */
if (do_sharp_edges_tag && is_angle_sharp) {
BLI_BITMAP_SET(sharp_edges, ml_curr->e, true);
}
@@ -935,7 +878,7 @@ static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data,
e2l[1] = INDEX_INVALID;
/* We want to avoid tagging edges as sharp when it is already defined as such by
- * other causes than angle threshold... */
+ * other causes than angle threshold. */
if (do_sharp_edges_tag) {
BLI_BITMAP_SET(sharp_edges, ml_curr->e, false);
}
@@ -1017,14 +960,13 @@ void BKE_mesh_loop_manifold_fan_around_vert_next(const MLoop *mloops,
const MLoop *mlfan_next;
const MPoly *mpfan_next;
- /* Warning! This is rather complex!
+ /* WARNING: This is rather complex!
* We have to find our next edge around the vertex (fan mode).
* First we find the next loop, which is either previous or next to mlfan_curr_index, depending
* whether both loops using current edge are in the same direction or not, and whether
* mlfan_curr_index actually uses the vertex we are fanning around!
* mlfan_curr_index is the index of mlfan_next here, and mlfan_next is not the real next one
- * (i.e. not the future mlfan_curr)...
- */
+ * (i.e. not the future `mlfan_curr`). */
*r_mlfan_curr_index = (e2lfan_curr[0] == *r_mlfan_curr_index) ? e2lfan_curr[1] : e2lfan_curr[0];
*r_mpfan_curr_index = loop_to_poly[*r_mlfan_curr_index];
@@ -1049,7 +991,7 @@ void BKE_mesh_loop_manifold_fan_around_vert_next(const MLoop *mloops,
*r_mlfan_vert_index = *r_mlfan_curr_index;
}
*r_mlfan_curr = &mloops[*r_mlfan_curr_index];
- /* And now we are back in sync, mlfan_curr_index is the index of mlfan_curr! Pff! */
+ /* And now we are back in sync, mlfan_curr_index is the index of `mlfan_curr`! Pff! */
}
static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopSplitTaskData *data)
@@ -1104,8 +1046,7 @@ static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopS
normalize_v3(vec_prev);
BKE_lnor_space_define(lnor_space, *lnor, vec_curr, vec_prev, nullptr);
- /* We know there is only one loop in this space,
- * no need to create a linklist in this case... */
+ /* We know there is only one loop in this space, no need to create a link-list in this case. */
BKE_lnor_space_add_loop(lnors_spacearr, lnor_space, ml_curr_index, nullptr, true);
if (clnors_data) {
@@ -1141,24 +1082,24 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
BLI_Stack *edge_vectors = data->edge_vectors;
- /* Gah... We have to fan around current vertex, until we find the other non-smooth edge,
+ /* Sigh! we have to fan around current vertex, until we find the other non-smooth edge,
* and accumulate face normals into the vertex!
* Note in case this vertex has only one sharp edges, this is a waste because the normal is the
* same as the vertex normal, but I do not see any easy way to detect that (would need to count
* number of sharp edges per vertex, I doubt the additional memory usage would be worth it,
- * especially as it should not be a common case in real-life meshes anyway).
- */
+ * especially as it should not be a common case in real-life meshes anyway). */
const uint mv_pivot_index = ml_curr->v; /* The vertex we are "fanning" around! */
const MVert *mv_pivot = &mverts[mv_pivot_index];
- /* ml_curr would be mlfan_prev if we needed that one. */
+ /* `ml_curr` would be mlfan_prev if we needed that one. */
const MEdge *me_org = &medges[ml_curr->e];
const int *e2lfan_curr;
float vec_curr[3], vec_prev[3], vec_org[3];
const MLoop *mlfan_curr;
float lnor[3] = {0.0f, 0.0f, 0.0f};
- /* mlfan_vert_index: the loop of our current edge might not be the loop of our current vertex! */
+ /* `mlfan_vert_index` the loop of our current edge might not be the loop of our current vertex!
+ */
int mlfan_curr_index, mlfan_vert_index, mpfan_curr_index;
/* We validate clnors data on the fly - cheapest way to do! */
@@ -1202,7 +1143,7 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
/* Compute edge vectors.
* NOTE: We could pre-compute those into an array, in the first iteration, instead of computing
* them twice (or more) here. However, time gained is not worth memory and time lost,
- * given the fact that this code should not be called that much in real-life meshes...
+ * given the fact that this code should not be called that much in real-life meshes.
*/
{
const MVert *mv_2 = (me_curr->v1 == mv_pivot_index) ? &mverts[me_curr->v2] :
@@ -1394,12 +1335,13 @@ static bool loop_split_generator_check_cyclic_smooth_fan(const MLoop *mloops,
const uint mv_pivot_index = ml_curr->v; /* The vertex we are "fanning" around! */
const int *e2lfan_curr;
const MLoop *mlfan_curr;
- /* mlfan_vert_index: the loop of our current edge might not be the loop of our current vertex! */
+ /* `mlfan_vert_index` the loop of our current edge might not be the loop of our current vertex!
+ */
int mlfan_curr_index, mlfan_vert_index, mpfan_curr_index;
e2lfan_curr = e2l_prev;
if (IS_EDGE_SHARP(e2lfan_curr)) {
- /* Sharp loop, so not a cyclic smooth fan... */
+ /* Sharp loop, so not a cyclic smooth fan. */
return false;
}
@@ -1430,21 +1372,21 @@ static bool loop_split_generator_check_cyclic_smooth_fan(const MLoop *mloops,
e2lfan_curr = edge_to_loops[mlfan_curr->e];
if (IS_EDGE_SHARP(e2lfan_curr)) {
- /* Sharp loop/edge, so not a cyclic smooth fan... */
+ /* Sharp loop/edge, so not a cyclic smooth fan. */
return false;
}
- /* Smooth loop/edge... */
+ /* Smooth loop/edge. */
if (BLI_BITMAP_TEST(skip_loops, mlfan_vert_index)) {
if (mlfan_vert_index == ml_curr_index) {
/* We walked around a whole cyclic smooth fan without finding any already-processed loop,
- * means we can use initial ml_curr/ml_prev edge as start for this smooth fan. */
+ * means we can use initial `ml_curr` / `ml_prev` edge as start for this smooth fan. */
return true;
}
- /* ... already checked in some previous looping, we can abort. */
+ /* Already checked in some previous looping, we can abort. */
return false;
}
- /* ... we can skip it in future, and keep checking the smooth fan. */
+ /* We can skip it in future, and keep checking the smooth fan. */
BLI_BITMAP_ENABLE(skip_loops, mlfan_vert_index);
}
}
@@ -1506,7 +1448,7 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common
const int *e2l_prev = edge_to_loops[ml_prev->e];
#if 0
- printf("Checking loop %d / edge %u / vert %u (sharp edge: %d, skiploop: %d)...",
+ printf("Checking loop %d / edge %u / vert %u (sharp edge: %d, skiploop: %d)",
ml_curr_index,
ml_curr->e,
ml_curr->v,
@@ -1610,7 +1552,7 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common
}
}
- /* Last block of data... Since it is calloc'ed and we use first nullptr item as stopper,
+ /* Last block of data. Since it is calloc'ed and we use first nullptr item as stopper,
* everything is fine. */
if (pool && data_idx) {
BLI_task_pool_push(pool, loop_split_worker, data_buff, true, nullptr);
@@ -1657,8 +1599,7 @@ void BKE_mesh_normals_loop_split(const MVert *mverts,
* since we may want to use lnors even when mesh's 'autosmooth' is disabled
* (see e.g. mesh mapping code).
* As usual, we could handle that on case-by-case basis,
- * but simpler to keep it well confined here.
- */
+ * but simpler to keep it well confined here. */
int mp_index;
for (mp_index = 0; mp_index < numPolys; mp_index++) {
@@ -1741,7 +1682,7 @@ void BKE_mesh_normals_loop_split(const MVert *mverts,
mesh_edges_sharp_tag(&common_data, check_angle, split_angle, false);
if (numLoops < LOOP_SPLIT_TASK_BLOCK_SIZE * 8) {
- /* Not enough loops to be worth the whole threading overhead... */
+ /* Not enough loops to be worth the whole threading overhead. */
loop_split_generator(nullptr, &common_data);
}
else {
@@ -1796,13 +1737,12 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
short (*r_clnors_data)[2],
const bool use_vertices)
{
- /* We *may* make that poor BKE_mesh_normals_loop_split() even more complex by making it handling
+ /* We *may* make that poor #BKE_mesh_normals_loop_split() even more complex by making it handling
* that feature too, would probably be more efficient in absolute.
* However, this function *is not* performance-critical, since it is mostly expected to be called
- * by io addons when importing custom normals, and modifier
+ * by io add-ons when importing custom normals, and modifier
* (and perhaps from some editing tools later?).
- * So better to keep some simplicity here, and just call BKE_mesh_normals_loop_split() twice!
- */
+ * So better to keep some simplicity here, and just call #BKE_mesh_normals_loop_split() twice! */
MLoopNorSpaceArray lnors_spacearr = {nullptr};
BLI_bitmap *done_loops = BLI_BITMAP_NEW((size_t)numLoops, __func__);
float(*lnors)[3] = (float(*)[3])MEM_calloc_arrayN((size_t)numLoops, sizeof(*lnors), __func__);
@@ -1854,15 +1794,13 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
* This way, next time we run BKE_mesh_normals_loop_split(), we'll get lnor spacearr/smooth fans
* matching given custom lnors.
* Note this code *will never* unsharp edges! And quite obviously,
- * when we set custom normals per vertices, running this is absolutely useless.
- */
+ * when we set custom normals per vertices, running this is absolutely useless. */
if (!use_vertices) {
for (int i = 0; i < numLoops; i++) {
if (!lnors_spacearr.lspacearr[i]) {
/* This should not happen in theory, but in some rare case (probably ugly geometry)
* we can get some nullptr loopspacearr at this point. :/
- * Maybe we should set those loops' edges as sharp?
- */
+ * Maybe we should set those loops' edges as sharp? */
BLI_BITMAP_ENABLE(done_loops, i);
if (G.debug & G_DEBUG) {
printf("WARNING! Getting invalid nullptr loop space for loop %d!\n", i);
@@ -1872,12 +1810,12 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
if (!BLI_BITMAP_TEST(done_loops, i)) {
/* Notes:
- * * In case of mono-loop smooth fan, we have nothing to do.
- * * Loops in this linklist are ordered (in reversed order compared to how they were
+ * - In case of mono-loop smooth fan, we have nothing to do.
+ * - Loops in this linklist are ordered (in reversed order compared to how they were
* discovered by BKE_mesh_normals_loop_split(), but this is not a problem).
* Which means if we find a mismatching clnor,
* we know all remaining loops will have to be in a new, different smooth fan/lnor space.
- * * In smooth fan case, we compare each clnor against a ref one,
+ * - In smooth fan case, we compare each clnor against a ref one,
* to avoid small differences adding up into a real big one in the end!
*/
if (lnors_spacearr.lspacearr[i]->flags & MLNOR_SPACE_IS_SINGLE) {
@@ -1902,8 +1840,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
/* Current normal differs too much from org one, we have to tag the edge between
* previous loop's face and current's one as sharp.
* We know those two loops do not point to the same edge,
- * since we do not allow reversed winding in a same smooth fan.
- */
+ * since we do not allow reversed winding in a same smooth fan. */
const MPoly *mp = &mpolys[loop_to_poly[lidx]];
const MLoop *mlp =
&mloops[(lidx == mp->loopstart) ? mp->loopstart + mp->totloop - 1 : lidx - 1];
@@ -1975,8 +1912,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
if (BLI_BITMAP_TEST_BOOL(done_loops, i)) {
/* Note we accumulate and average all custom normals in current smooth fan,
* to avoid getting different clnors data (tiny differences in plain custom normals can
- * give rather huge differences in computed 2D factors).
- */
+ * give rather huge differences in computed 2D factors). */
LinkNode *loops = lnors_spacearr.lspacearr[i]->loops;
if (lnors_spacearr.lspacearr[i]->flags & MLNOR_SPACE_IS_SINGLE) {
BLI_assert(POINTER_AS_INT(loops) == i);
@@ -2092,15 +2028,14 @@ static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const
bool free_polynors = false;
if (polynors == nullptr) {
polynors = (float(*)[3])MEM_mallocN(sizeof(float[3]) * (size_t)mesh->totpoly, __func__);
- BKE_mesh_calc_normals_poly(mesh->mvert,
- nullptr,
- mesh->totvert,
- mesh->mloop,
- mesh->mpoly,
- mesh->totloop,
- mesh->totpoly,
- polynors,
- false);
+ BKE_mesh_calc_normals_poly_and_vertex(mesh->mvert,
+ mesh->totvert,
+ mesh->mloop,
+ mesh->totloop,
+ mesh->mpoly,
+ mesh->totpoly,
+ polynors,
+ nullptr);
free_polynors = true;
}
diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c
index c5e8858ea12..53a31cbbc7a 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -1379,14 +1379,12 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
}
if (dirty_nors_dst || do_poly_nors_dst) {
BKE_mesh_calc_normals_poly(verts_dst,
- NULL,
numverts_dst,
loops_dst,
- polys_dst,
numloops_dst,
+ polys_dst,
numpolys_dst,
- poly_nors_dst,
- true);
+ poly_nors_dst);
}
}
if (need_lnors_dst) {
@@ -2231,14 +2229,12 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
}
if (dirty_nors_dst) {
BKE_mesh_calc_normals_poly(verts_dst,
- NULL,
numverts_dst,
loops_dst,
- polys_dst,
numloops_dst,
+ polys_dst,
numpolys_dst,
- poly_nors_dst,
- true);
+ poly_nors_dst);
}
}
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 2088c4268e6..821ca7b98b3 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -249,11 +249,11 @@ bool BKE_modifier_unique_name(ListBase *modifiers, ModifierData *md)
return false;
}
-bool BKE_modifier_depends_ontime(ModifierData *md)
+bool BKE_modifier_depends_ontime(Scene *scene, ModifierData *md, const int dag_eval_mode)
{
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
- return mti->dependsOnTime && mti->dependsOnTime(md);
+ return mti->dependsOnTime && mti->dependsOnTime(scene, md, dag_eval_mode);
}
bool BKE_modifier_supports_mapping(ModifierData *md)
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index f32b0c434c1..e507252307b 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -206,36 +206,35 @@ static void write_movieReconstruction(BlendWriter *writer,
static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
MovieClip *clip = (MovieClip *)id;
- if (clip->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- clip->anim = NULL;
- clip->tracking_context = NULL;
- clip->tracking.stats = NULL;
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object;
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ clip->anim = NULL;
+ clip->tracking_context = NULL;
+ clip->tracking.stats = NULL;
- BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
- BKE_id_blend_write(writer, &clip->id);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object;
- if (clip->adt) {
- BKE_animdata_blend_write(writer, clip->adt);
- }
+ BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
+ BKE_id_blend_write(writer, &clip->id);
+
+ if (clip->adt) {
+ BKE_animdata_blend_write(writer, clip->adt);
+ }
- write_movieTracks(writer, &tracking->tracks);
- write_moviePlaneTracks(writer, &tracking->plane_tracks);
- write_movieReconstruction(writer, &tracking->reconstruction);
+ write_movieTracks(writer, &tracking->tracks);
+ write_moviePlaneTracks(writer, &tracking->plane_tracks);
+ write_movieReconstruction(writer, &tracking->reconstruction);
- object = tracking->objects.first;
- while (object) {
- BLO_write_struct(writer, MovieTrackingObject, object);
+ object = tracking->objects.first;
+ while (object) {
+ BLO_write_struct(writer, MovieTrackingObject, object);
- write_movieTracks(writer, &object->tracks);
- write_moviePlaneTracks(writer, &object->plane_tracks);
- write_movieReconstruction(writer, &object->reconstruction);
+ write_movieTracks(writer, &object->tracks);
+ write_moviePlaneTracks(writer, &object->plane_tracks);
+ write_movieReconstruction(writer, &object->reconstruction);
- object = object->next;
- }
+ object = object->next;
}
}
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 4aec5a9e667..2a0e05a2616 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -606,19 +606,18 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bNodeTree *ntree = (bNodeTree *)id;
- if (ntree->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- ntree->init = 0; /* to set callbacks and force setting types */
- ntree->is_updating = false;
- ntree->typeinfo = nullptr;
- ntree->interface_type = nullptr;
- ntree->progress = nullptr;
- ntree->execdata = nullptr;
- BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ ntree->init = 0; /* to set callbacks and force setting types */
+ ntree->is_updating = false;
+ ntree->typeinfo = nullptr;
+ ntree->interface_type = nullptr;
+ ntree->progress = nullptr;
+ ntree->execdata = nullptr;
- ntreeBlendWrite(writer, ntree);
- }
+ BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id);
+
+ ntreeBlendWrite(writer, ntree);
}
static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock)
@@ -2364,7 +2363,7 @@ bNodeLink *nodeAddLink(
ntree->update |= NTREE_UPDATE_LINKS;
}
- if (link->tosock->flag & SOCK_MULTI_INPUT) {
+ if (link != nullptr && link->tosock->flag & SOCK_MULTI_INPUT) {
link->multi_input_socket_index = node_count_links(ntree, link->tosock) - 1;
}
@@ -3194,6 +3193,7 @@ void ntreeFreeEmbeddedTree(bNodeTree *ntree)
{
ntreeFreeTree(ntree);
BKE_libblock_free_data(&ntree->id, true);
+ BKE_libblock_free_data_py(&ntree->id);
}
void ntreeFreeLocalTree(bNodeTree *ntree)
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 23b9dca8371..6e26ed4925d 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -523,74 +523,72 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre
Object *ob = (Object *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (ob->id.us > 0 || is_undo) {
- /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
- BKE_object_runtime_reset(ob);
- if (is_undo) {
- /* For undo we stay in object mode during undo presses, so keep edit-mode disabled on save as
- * well, can help reducing false detection of changed data-blocks. */
- ob->mode &= ~OB_MODE_EDIT;
- }
+ /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
+ BKE_object_runtime_reset(ob);
- /* write LibData */
- BLO_write_id_struct(writer, Object, id_address, &ob->id);
- BKE_id_blend_write(writer, &ob->id);
+ if (is_undo) {
+ /* For undo we stay in object mode during undo presses, so keep edit-mode disabled on save as
+ * well, can help reducing false detection of changed data-blocks. */
+ ob->mode &= ~OB_MODE_EDIT;
+ }
- if (ob->adt) {
- BKE_animdata_blend_write(writer, ob->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Object, id_address, &ob->id);
+ BKE_id_blend_write(writer, &ob->id);
- /* direct data */
- BLO_write_pointer_array(writer, ob->totcol, ob->mat);
- BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits);
+ if (ob->adt) {
+ BKE_animdata_blend_write(writer, ob->adt);
+ }
- bArmature *arm = NULL;
- if (ob->type == OB_ARMATURE) {
- arm = ob->data;
- if (arm && ob->pose && arm->act_bone) {
- BLI_strncpy(
- ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
- }
+ /* direct data */
+ BLO_write_pointer_array(writer, ob->totcol, ob->mat);
+ BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits);
+
+ bArmature *arm = NULL;
+ if (ob->type == OB_ARMATURE) {
+ arm = ob->data;
+ if (arm && ob->pose && arm->act_bone) {
+ BLI_strncpy(ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
}
+ }
- BKE_pose_blend_write(writer, ob->pose, arm);
- write_fmaps(writer, &ob->fmaps);
- BKE_constraint_blend_write(writer, &ob->constraints);
- animviz_motionpath_blend_write(writer, ob->mpath);
+ BKE_pose_blend_write(writer, ob->pose, arm);
+ write_fmaps(writer, &ob->fmaps);
+ BKE_constraint_blend_write(writer, &ob->constraints);
+ animviz_motionpath_blend_write(writer, ob->mpath);
- BLO_write_struct(writer, PartDeflect, ob->pd);
- if (ob->soft) {
- /* Set deprecated pointers to prevent crashes of older Blenders */
- ob->soft->pointcache = ob->soft->shared->pointcache;
- ob->soft->ptcaches = ob->soft->shared->ptcaches;
- BLO_write_struct(writer, SoftBody, ob->soft);
- BLO_write_struct(writer, SoftBody_Shared, ob->soft->shared);
- BKE_ptcache_blend_write(writer, &(ob->soft->shared->ptcaches));
- BLO_write_struct(writer, EffectorWeights, ob->soft->effector_weights);
- }
+ BLO_write_struct(writer, PartDeflect, ob->pd);
+ if (ob->soft) {
+ /* Set deprecated pointers to prevent crashes of older Blenders */
+ ob->soft->pointcache = ob->soft->shared->pointcache;
+ ob->soft->ptcaches = ob->soft->shared->ptcaches;
+ BLO_write_struct(writer, SoftBody, ob->soft);
+ BLO_write_struct(writer, SoftBody_Shared, ob->soft->shared);
+ BKE_ptcache_blend_write(writer, &(ob->soft->shared->ptcaches));
+ BLO_write_struct(writer, EffectorWeights, ob->soft->effector_weights);
+ }
- if (ob->rigidbody_object) {
- /* TODO: if any extra data is added to handle duplis, will need separate function then */
- BLO_write_struct(writer, RigidBodyOb, ob->rigidbody_object);
- }
- if (ob->rigidbody_constraint) {
- BLO_write_struct(writer, RigidBodyCon, ob->rigidbody_constraint);
- }
+ if (ob->rigidbody_object) {
+ /* TODO: if any extra data is added to handle duplis, will need separate function then */
+ BLO_write_struct(writer, RigidBodyOb, ob->rigidbody_object);
+ }
+ if (ob->rigidbody_constraint) {
+ BLO_write_struct(writer, RigidBodyCon, ob->rigidbody_constraint);
+ }
- if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
- BLO_write_struct(writer, ImageUser, ob->iuser);
- }
+ if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
+ BLO_write_struct(writer, ImageUser, ob->iuser);
+ }
- BKE_particle_system_blend_write(writer, &ob->particlesystem);
- BKE_modifier_blend_write(writer, &ob->modifiers);
- BKE_gpencil_modifier_blend_write(writer, &ob->greasepencil_modifiers);
- BKE_shaderfx_blend_write(writer, &ob->shader_fx);
+ BKE_particle_system_blend_write(writer, &ob->particlesystem);
+ BKE_modifier_blend_write(writer, &ob->modifiers);
+ BKE_gpencil_modifier_blend_write(writer, &ob->greasepencil_modifiers);
+ BKE_shaderfx_blend_write(writer, &ob->shader_fx);
- BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
+ BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
- BKE_previewimg_blend_write(writer, ob->preview);
- }
+ BKE_previewimg_blend_write(writer, ob->preview);
}
/* XXX deprecated - old animation system */
@@ -2616,17 +2614,21 @@ void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
Object *BKE_object_duplicate(Main *bmain,
Object *ob,
eDupli_ID_Flags dupflag,
- const eLibIDDuplicateFlags duplicate_options)
+ eLibIDDuplicateFlags duplicate_options)
{
const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
+ const bool is_root_id = (duplicate_options & LIB_ID_DUPLICATE_IS_ROOT_ID) != 0;
if (!is_subprocess) {
BKE_main_id_newptr_and_tag_clear(bmain);
+ }
+ if (is_root_id) {
/* In case root duplicated ID is linked, assume we want to get a local copy of it and duplicate
* all expected linked data. */
if (ID_IS_LINKED(ob)) {
dupflag |= USER_DUP_LINKED_ID;
}
+ duplicate_options &= ~LIB_ID_DUPLICATE_IS_ROOT_ID;
}
Material ***matarar;
@@ -5411,9 +5413,12 @@ KDTree_3d *BKE_object_as_kdtree(Object *ob, int *r_tot)
return tree;
}
-bool BKE_object_modifier_use_time(Object *ob, ModifierData *md)
+bool BKE_object_modifier_use_time(Scene *scene,
+ Object *ob,
+ ModifierData *md,
+ const int dag_eval_mode)
{
- if (BKE_modifier_depends_ontime(md)) {
+ if (BKE_modifier_depends_ontime(scene, md, dag_eval_mode)) {
return true;
}
diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c
index 4d003ddc900..e9683d3b52c 100644
--- a/source/blender/blenkernel/intern/ocean.c
+++ b/source/blender/blenkernel/intern/ocean.c
@@ -530,7 +530,7 @@ static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool, void *UNUSED(t
for (j = 0; j <= o->_N / 2; j++) {
fftw_complex mul_param;
- /* init_complex(mul_param, -scale, 0); */
+ // init_complex(mul_param, -scale, 0);
init_complex(mul_param, -1, 0);
mul_complex_f(mul_param, mul_param, chop_amount);
@@ -563,7 +563,7 @@ static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool, void *UNUSED(t
for (j = 0; j <= o->_N / 2; j++) {
fftw_complex mul_param;
- /* init_complex(mul_param, -scale, 0); */
+ // init_complex(mul_param, -scale, 0);
init_complex(mul_param, -1, 0);
mul_complex_f(mul_param, mul_param, chop_amount);
@@ -596,7 +596,7 @@ static void ocean_compute_jacobian_jxz(TaskPool *__restrict pool, void *UNUSED(t
for (j = 0; j <= o->_N / 2; j++) {
fftw_complex mul_param;
- /* init_complex(mul_param, -scale, 0); */
+ // init_complex(mul_param, -scale, 0);
init_complex(mul_param, -1, 0);
mul_complex_f(mul_param, mul_param, chop_amount);
@@ -1015,7 +1015,7 @@ bool BKE_ocean_init(struct Ocean *o,
"ocean_fft_in_nz");
o->_N_x = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x");
- /* o->_N_y = (float *) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01) */
+ // o->_N_y = (float *) fftwf_malloc(o->_M * o->_N * sizeof(float)); /* (MEM01) */
o->_N_z = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z");
o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE);
@@ -1083,7 +1083,7 @@ void BKE_ocean_free_data(struct Ocean *oc)
fftw_destroy_plan(oc->_N_x_plan);
fftw_destroy_plan(oc->_N_z_plan);
MEM_freeN(oc->_N_x);
- /* fftwf_free(oc->_N_y); (MEM01) */
+ // fftwf_free(oc->_N_y); /* (MEM01) */
MEM_freeN(oc->_N_z);
}
diff --git a/source/blender/blenkernel/intern/ocean_spectrum.c b/source/blender/blenkernel/intern/ocean_spectrum.c
index 7ed70234baf..c5504b22b43 100644
--- a/source/blender/blenkernel/intern/ocean_spectrum.c
+++ b/source/blender/blenkernel/intern/ocean_spectrum.c
@@ -77,7 +77,7 @@ static float ocean_spectrum_wind_and_damp(const Ocean *oc,
float newval = val * pow(fabs(k_dot_w), oc->_wind_alignment);
/* Eliminate wavelengths smaller than cutoff. */
- /* val *= exp(-k2 * m_cutoff); */
+ // val *= exp(-k2 * m_cutoff);
/* Reduce reflected waves. */
if (k_dot_w < 0.0f) {
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index a1fa6aae1ce..d6030941c6d 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -108,14 +108,13 @@ static void palette_free_data(ID *id)
static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Palette *palette = (Palette *)id;
- if (palette->id.us > 0 || BLO_write_is_undo(writer)) {
- PaletteColor *color;
- BLO_write_id_struct(writer, Palette, id_address, &palette->id);
- BKE_id_blend_write(writer, &palette->id);
- for (color = palette->colors.first; color; color = color->next) {
- BLO_write_struct(writer, PaletteColor, color);
- }
+ PaletteColor *color;
+ BLO_write_id_struct(writer, Palette, id_address, &palette->id);
+ BKE_id_blend_write(writer, &palette->id);
+
+ for (color = palette->colors.first; color; color = color->next) {
+ BLO_write_struct(writer, PaletteColor, color);
}
}
@@ -187,12 +186,11 @@ static void paint_curve_free_data(ID *id)
static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
PaintCurve *pc = (PaintCurve *)id;
- if (pc->id.us > 0 || BLO_write_is_undo(writer)) {
- BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
- BKE_id_blend_write(writer, &pc->id);
- BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
- }
+ BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
+ BKE_id_blend_write(writer, &pc->id);
+
+ BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
}
static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index cc8a051eceb..50b0fb1c9f5 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -255,60 +255,59 @@ static void write_boid_state(BlendWriter *writer, BoidState *state)
static void particle_settings_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
ParticleSettings *part = (ParticleSettings *)id;
- if (part->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
- BKE_id_blend_write(writer, &part->id);
- if (part->adt) {
- BKE_animdata_blend_write(writer, part->adt);
- }
- BLO_write_struct(writer, PartDeflect, part->pd);
- BLO_write_struct(writer, PartDeflect, part->pd2);
- BLO_write_struct(writer, EffectorWeights, part->effector_weights);
+ /* write LibData */
+ BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
+ BKE_id_blend_write(writer, &part->id);
- if (part->clumpcurve) {
- BKE_curvemapping_blend_write(writer, part->clumpcurve);
- }
- if (part->roughcurve) {
- BKE_curvemapping_blend_write(writer, part->roughcurve);
- }
- if (part->twistcurve) {
- BKE_curvemapping_blend_write(writer, part->twistcurve);
- }
+ if (part->adt) {
+ BKE_animdata_blend_write(writer, part->adt);
+ }
+ BLO_write_struct(writer, PartDeflect, part->pd);
+ BLO_write_struct(writer, PartDeflect, part->pd2);
+ BLO_write_struct(writer, EffectorWeights, part->effector_weights);
- LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
- /* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
- if (dw->ob != NULL) {
- dw->index = 0;
- if (part->instance_collection) { /* can be NULL if lining fails or set to None */
- FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object) {
- if (object == dw->ob) {
- break;
- }
- dw->index++;
+ if (part->clumpcurve) {
+ BKE_curvemapping_blend_write(writer, part->clumpcurve);
+ }
+ if (part->roughcurve) {
+ BKE_curvemapping_blend_write(writer, part->roughcurve);
+ }
+ if (part->twistcurve) {
+ BKE_curvemapping_blend_write(writer, part->twistcurve);
+ }
+
+ LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
+ /* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
+ if (dw->ob != NULL) {
+ dw->index = 0;
+ if (part->instance_collection) { /* can be NULL if lining fails or set to None */
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object) {
+ if (object == dw->ob) {
+ break;
}
- FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
+ dw->index++;
}
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}
- BLO_write_struct(writer, ParticleDupliWeight, dw);
}
+ BLO_write_struct(writer, ParticleDupliWeight, dw);
+ }
- if (part->boids && part->phystype == PART_PHYS_BOIDS) {
- BLO_write_struct(writer, BoidSettings, part->boids);
+ if (part->boids && part->phystype == PART_PHYS_BOIDS) {
+ BLO_write_struct(writer, BoidSettings, part->boids);
- LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
- write_boid_state(writer, state);
- }
- }
- if (part->fluid && part->phystype == PART_PHYS_FLUID) {
- BLO_write_struct(writer, SPHFluidSettings, part->fluid);
+ LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
+ write_boid_state(writer, state);
}
+ }
+ if (part->fluid && part->phystype == PART_PHYS_FLUID) {
+ BLO_write_struct(writer, SPHFluidSettings, part->fluid);
+ }
- for (int a = 0; a < MAX_MTEX; a++) {
- if (part->mtex[a]) {
- BLO_write_struct(writer, MTex, part->mtex[a]);
- }
+ for (int a = 0; a < MAX_MTEX; a++) {
+ if (part->mtex[a]) {
+ BLO_write_struct(writer, MTex, part->mtex[a]);
}
}
}
@@ -3968,16 +3967,18 @@ ModifierData *object_copy_particle_system(Main *bmain,
return object_add_or_copy_particle_system(bmain, scene, ob, NULL, psys_orig);
}
-void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob)
+void object_remove_particle_system(Main *bmain,
+ Scene *UNUSED(scene),
+ Object *ob,
+ ParticleSystem *psys)
{
- ParticleSystem *psys = psys_get_current(ob);
- ParticleSystemModifierData *psmd;
- ModifierData *md;
-
- if (!psys) {
+ if (!ob || !psys) {
return;
}
+ ParticleSystemModifierData *psmd;
+ ModifierData *md;
+
/* Clear particle system in fluid modifier. */
if ((md = BKE_modifiers_findby_type(ob, eModifierType_Fluid))) {
FluidModifierData *fmd = (FluidModifierData *)md;
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index f592b0f97ea..60edb78f8ba 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4761,6 +4761,7 @@ static void particle_settings_free_local(ParticleSettings *particle_settings)
{
BKE_libblock_free_datablock(&particle_settings->id, 0);
BKE_libblock_free_data(&particle_settings->id, false);
+ BLI_assert(!particle_settings->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(particle_settings);
}
diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc
index d9a7a376e2e..837a772607f 100644
--- a/source/blender/blenkernel/intern/pointcloud.cc
+++ b/source/blender/blenkernel/intern/pointcloud.cc
@@ -112,28 +112,27 @@ static void pointcloud_foreach_id(ID *id, LibraryForeachIDData *data)
static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
PointCloud *pointcloud = (PointCloud *)id;
- if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
- CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
- CustomData_blend_write_prepare(
- &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
-
- /* Write LibData */
- BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
- BKE_id_blend_write(writer, &pointcloud->id);
-
- /* Direct data */
- CustomData_blend_write(
- writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
-
- BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
- if (pointcloud->adt) {
- BKE_animdata_blend_write(writer, pointcloud->adt);
- }
- /* Remove temporary data. */
- if (players && players != players_buff) {
- MEM_freeN(players);
- }
+ CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
+ CustomData_blend_write_prepare(
+ &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
+
+ /* Write LibData */
+ BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
+ BKE_id_blend_write(writer, &pointcloud->id);
+
+ /* Direct data */
+ CustomData_blend_write(
+ writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
+
+ BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
+ if (pointcloud->adt) {
+ BKE_animdata_blend_write(writer, pointcloud->adt);
+ }
+
+ /* Remove temporary data. */
+ if (players && players != players_buff) {
+ MEM_freeN(players);
}
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 9dab276af95..5a668746956 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -109,6 +109,8 @@
#include "RE_engine.h"
+#include "RNA_access.h"
+
#include "SEQ_edit.h"
#include "SEQ_iterator.h"
#include "SEQ_modifier.h"
@@ -445,7 +447,8 @@ static void scene_free_data(ID *id)
* for objects directly in the master collection? then other
* collections in the scene need to do it too? */
if (scene->master_collection) {
- BKE_collection_free(scene->master_collection);
+ BKE_collection_free_data(scene->master_collection);
+ BKE_libblock_free_data_py(&scene->master_collection->id);
MEM_freeN(scene->master_collection);
scene->master_collection = NULL;
}
@@ -1173,11 +1176,6 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
seq->flag |= SEQ_EFFECT_NOT_LOADED;
}
- if (seq->type == SEQ_TYPE_SPEED) {
- SpeedControlVars *s = seq->effectdata;
- s->frameMap = NULL;
- }
-
if (seq->type == SEQ_TYPE_TEXT) {
TextVars *t = seq->effectdata;
t->text_blf_id = SEQ_FONT_NOT_LOADED;
@@ -1986,9 +1984,12 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type)
if (type == SCE_COPY_FULL) {
/* Scene duplication is always root of duplication currently. */
const bool is_subprocess = false;
+ const bool is_root_id = true;
if (!is_subprocess) {
BKE_main_id_newptr_and_tag_clear(bmain);
+ }
+ if (is_root_id) {
/* In case root duplicated ID is linked, assume we want to get a local copy of it and
* duplicate all expected linked data. */
if (ID_IS_LINKED(sce)) {
@@ -2937,6 +2938,22 @@ bool BKE_scene_uses_cycles(const Scene *scene)
return STREQ(scene->r.engine, RE_engine_id_CYCLES);
}
+/* This enumeration has to match the one defined in the Cycles addon. */
+typedef enum eCyclesFeatureSet {
+ CYCLES_FEATURES_SUPPORTED = 0,
+ CYCLES_FEATURES_EXPERIMENTAL = 1,
+} eCyclesFeatureSet;
+
+/* We cannot use const as RNA_id_pointer_create is not using a const ID. */
+bool BKE_scene_uses_cycles_experimental_features(Scene *scene)
+{
+ BLI_assert(BKE_scene_uses_cycles(scene));
+ PointerRNA scene_ptr;
+ RNA_id_pointer_create(&scene->id, &scene_ptr);
+ PointerRNA cycles_ptr = RNA_pointer_get(&scene_ptr, "cycles");
+ return RNA_enum_get(&cycles_ptr, "feature_set") == CYCLES_FEATURES_EXPERIMENTAL;
+}
+
void BKE_scene_base_flag_to_objects(ViewLayer *view_layer)
{
Base *base = view_layer->object_bases.first;
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index e44c5a6b40e..065240bddbc 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -255,18 +255,16 @@ static void screen_foreach_id(ID *id, LibraryForeachIDData *data)
static void screen_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bScreen *screen = (bScreen *)id;
- /* Screens are reference counted, only saved if used by a workspace. */
- if (screen->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
- BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen);
- BKE_id_blend_write(writer, &screen->id);
- BKE_previewimg_blend_write(writer, screen->preview);
+ /* write LibData */
+ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
+ BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen);
+ BKE_id_blend_write(writer, &screen->id);
- /* direct data */
- BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
- }
+ BKE_previewimg_blend_write(writer, screen->preview);
+
+ /* direct data */
+ BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
}
/* Cannot use IDTypeInfo callback yet, because of the return value. */
@@ -730,7 +728,7 @@ void BKE_screen_area_map_free(ScrAreaMap *area_map)
}
/** Free (or release) any data used by this screen (does not free the screen itself). */
-void BKE_screen_free(bScreen *screen)
+void BKE_screen_free_data(bScreen *screen)
{
screen_free_data(&screen->id);
}
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index 216563b860d..4c97ccdf8b1 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -49,14 +49,10 @@
#include "BKE_simulation.h"
#include "NOD_geometry.h"
-#include "NOD_node_tree_multi_function.hh"
#include "BLI_map.hh"
#include "BLT_translation.h"
-#include "FN_multi_function_network_evaluation.hh"
-#include "FN_multi_function_network_optimization.hh"
-
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
@@ -114,19 +110,18 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Simulation *simulation = (Simulation *)id;
- if (simulation->id.us > 0 || BLO_write_is_undo(writer)) {
- BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
- BKE_id_blend_write(writer, &simulation->id);
-
- if (simulation->adt) {
- BKE_animdata_blend_write(writer, simulation->adt);
- }
-
- /* nodetree is integral part of simulation, no libdata */
- if (simulation->nodetree) {
- BLO_write_struct(writer, bNodeTree, simulation->nodetree);
- ntreeBlendWrite(writer, simulation->nodetree);
- }
+
+ BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
+ BKE_id_blend_write(writer, &simulation->id);
+
+ if (simulation->adt) {
+ BKE_animdata_blend_write(writer, simulation->adt);
+ }
+
+ /* nodetree is integral part of simulation, no libdata */
+ if (simulation->nodetree) {
+ BLO_write_struct(writer, bNodeTree, simulation->nodetree);
+ ntreeBlendWrite(writer, simulation->nodetree);
}
}
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 5e92be76197..fbc781f5eb9 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -2277,7 +2277,7 @@ static void softbody_calc_forces(
float fieldfactor = -1.0f, windfactor = 0.25;
int do_deflector /*, do_selfcollision */, do_springcollision, do_aero;
- /* gravity = sb->grav * sb_grav_force_scale(ob); */ /* UNUSED */
+ // gravity = sb->grav * sb_grav_force_scale(ob); /* UNUSED */
/* check conditions for various options */
do_deflector = query_external_colliders(depsgraph, sb->collision_group);
@@ -2749,7 +2749,7 @@ static void mesh_to_softbody(Object *ob)
build_bps_springlist(ob); /* scan for springs attached to bodypoints ONCE */
/* insert *other second order* springs if desired */
if (sb->secondspring > 0.0000001f) {
- /* exploits the first run of build_bps_springlist(ob); */
+ /* Exploits the first run of `build_bps_springlist(ob)`. */
add_2nd_order_springs(ob, sb->secondspring);
/* yes we need to do it again. */
build_bps_springlist(ob);
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index fcb992e1535..c61fa793367 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -137,24 +137,23 @@ static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{
bSound *sound = (bSound *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (sound->id.us > 0 || is_undo) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- sound->tags = 0;
- sound->handle = NULL;
- sound->playback_handle = NULL;
- sound->spinlock = NULL;
- /* Do not store packed files in case this is a library override ID. */
- if (ID_IS_OVERRIDE_LIBRARY(sound) && !is_undo) {
- sound->packedfile = NULL;
- }
-
- /* write LibData */
- BLO_write_id_struct(writer, bSound, id_address, &sound->id);
- BKE_id_blend_write(writer, &sound->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ sound->tags = 0;
+ sound->handle = NULL;
+ sound->playback_handle = NULL;
+ sound->spinlock = NULL;
- BKE_packedfile_blend_write(writer, sound->packedfile);
+ /* Do not store packed files in case this is a library override ID. */
+ if (ID_IS_OVERRIDE_LIBRARY(sound) && !is_undo) {
+ sound->packedfile = NULL;
}
+
+ /* write LibData */
+ BLO_write_id_struct(writer, bSound, id_address, &sound->id);
+ BKE_id_blend_write(writer, &sound->id);
+
+ BKE_packedfile_blend_write(writer, sound->packedfile);
}
static void sound_blend_read_data(BlendDataReader *reader, ID *id)
@@ -703,13 +702,13 @@ void *BKE_sound_scene_add_scene_sound(
Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip)
{
sound_verify_evaluated_id(&scene->id);
- if (sequence->scene && scene != sequence->scene) {
+ if (sequence->scene && scene != sequence->scene && sequence->sound) {
const double fps = FPS;
return AUD_Sequence_add(scene->sound_scene,
sequence->scene->sound_scene,
startframe / fps,
endframe / fps,
- frameskip / fps);
+ frameskip / fps + sequence->sound->offset_time);
}
return NULL;
}
@@ -737,7 +736,7 @@ void *BKE_sound_add_scene_sound(
sequence->sound->playback_handle,
startframe / fps,
endframe / fps,
- frameskip / fps);
+ frameskip / fps + sequence->sound->offset_time);
AUD_SequenceEntry_setMuted(handle, (sequence->flag & SEQ_MUTE) != 0);
AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0);
AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0);
@@ -765,22 +764,23 @@ void BKE_sound_mute_scene_sound(void *handle, char mute)
}
void BKE_sound_move_scene_sound(
- Scene *scene, void *handle, int startframe, int endframe, int frameskip)
+ Scene *scene, void *handle, int startframe, int endframe, int frameskip, double audio_offset)
{
sound_verify_evaluated_id(&scene->id);
const double fps = FPS;
- AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps);
+ AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps + audio_offset);
}
void BKE_sound_move_scene_sound_defaults(Scene *scene, Sequence *sequence)
{
sound_verify_evaluated_id(&scene->id);
- if (sequence->scene_sound) {
+ if (sequence->scene_sound && sequence->sound) {
BKE_sound_move_scene_sound(scene,
sequence->scene_sound,
sequence->startdisp,
sequence->enddisp,
- sequence->startofs + sequence->anim_startofs);
+ sequence->startofs + sequence->anim_startofs,
+ sequence->sound->offset_time);
}
}
@@ -1213,6 +1213,7 @@ static bool sound_info_from_playback_handle(void *playback_handle, SoundInfo *so
AUD_SoundInfo info = AUD_getInfo(playback_handle);
sound_info->specs.channels = (eSoundChannels)info.specs.channels;
sound_info->length = info.length;
+ sound_info->start_offset = info.start_offset;
return true;
}
@@ -1310,7 +1311,8 @@ void BKE_sound_move_scene_sound(Scene *UNUSED(scene),
void *UNUSED(handle),
int UNUSED(startframe),
int UNUSED(endframe),
- int UNUSED(frameskip))
+ int UNUSED(frameskip),
+ double UNUSED(audio_offset))
{
}
void BKE_sound_move_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence))
diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c
index af9b2268879..4b10522c375 100644
--- a/source/blender/blenkernel/intern/speaker.c
+++ b/source/blender/blenkernel/intern/speaker.c
@@ -56,14 +56,13 @@ static void speaker_foreach_id(ID *id, LibraryForeachIDData *data)
static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Speaker *spk = (Speaker *)id;
- if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
- BKE_id_blend_write(writer, &spk->id);
-
- if (spk->adt) {
- BKE_animdata_blend_write(writer, spk->adt);
- }
+
+ /* write LibData */
+ BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
+ BKE_id_blend_write(writer, &spk->id);
+
+ if (spk->adt) {
+ BKE_animdata_blend_write(writer, spk->adt);
}
}
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc
index dda7abea0fc..732fabc6582 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -123,7 +123,7 @@ int Spline::evaluated_edges_size() const
float Spline::length() const
{
Span<float> lengths = this->evaluated_lengths();
- return (lengths.size() == 0) ? 0 : this->evaluated_lengths().last();
+ return lengths.is_empty() ? 0.0f : this->evaluated_lengths().last();
}
int Spline::segments_size() const
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 6048e823abb..c2ab91251b6 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -171,9 +171,6 @@ static void text_free_data(ID *id)
static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
- if (id->us < 1 && !BLO_write_is_undo(writer)) {
- return;
- }
Text *text = (Text *)id;
/* NOTE: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */
@@ -311,7 +308,7 @@ int txt_extended_ascii_as_utf8(char **str)
int added = 0;
while ((*str)[i]) {
- if ((bad_char = BLI_utf8_invalid_byte(*str + i, length - i)) == -1) {
+ if ((bad_char = BLI_str_utf8_invalid_byte(*str + i, length - i)) == -1) {
break;
}
@@ -325,7 +322,7 @@ int txt_extended_ascii_as_utf8(char **str)
i = 0;
while ((*str)[i]) {
- if ((bad_char = BLI_utf8_invalid_byte((*str) + i, length - i)) == -1) {
+ if ((bad_char = BLI_str_utf8_invalid_byte((*str) + i, length - i)) == -1) {
memcpy(newstr + mi, (*str) + i, length - i + 1);
break;
}
@@ -1663,7 +1660,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
/* Read the first line (or as close as possible */
while (buffer[i] && buffer[i] != '\n') {
- txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i));
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, len, &i));
}
if (buffer[i] == '\n') {
@@ -1685,7 +1682,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
}
else {
for (j = i - l; j < i && j < len;) {
- txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j));
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, len, &j));
}
break;
}
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index beb92495d16..228e6fffdf7 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -150,28 +150,27 @@ static void texture_foreach_id(ID *id, LibraryForeachIDData *data)
static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Tex *tex = (Tex *)id;
- if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, Tex, id_address, &tex->id);
- BKE_id_blend_write(writer, &tex->id);
- if (tex->adt) {
- BKE_animdata_blend_write(writer, tex->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Tex, id_address, &tex->id);
+ BKE_id_blend_write(writer, &tex->id);
- /* direct data */
- if (tex->coba) {
- BLO_write_struct(writer, ColorBand, tex->coba);
- }
+ if (tex->adt) {
+ BKE_animdata_blend_write(writer, tex->adt);
+ }
- /* nodetree is integral part of texture, no libdata */
- if (tex->nodetree) {
- BLO_write_struct(writer, bNodeTree, tex->nodetree);
- ntreeBlendWrite(writer, tex->nodetree);
- }
+ /* direct data */
+ if (tex->coba) {
+ BLO_write_struct(writer, ColorBand, tex->coba);
+ }
- BKE_previewimg_blend_write(writer, tex->preview);
+ /* nodetree is integral part of texture, no libdata */
+ if (tex->nodetree) {
+ BLO_write_struct(writer, bNodeTree, tex->nodetree);
+ ntreeBlendWrite(writer, tex->nodetree);
}
+
+ BKE_previewimg_blend_write(writer, tex->preview);
}
static void texture_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index b28d17df814..69452d6896f 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -578,27 +578,26 @@ static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_addre
{
Volume *volume = (Volume *)id;
const bool is_undo = BLO_write_is_undo(writer);
- if (volume->id.us > 0 || is_undo) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- volume->runtime.grids = nullptr;
- /* Do not store packed files in case this is a library override ID. */
- if (ID_IS_OVERRIDE_LIBRARY(volume) && !is_undo) {
- volume->packedfile = nullptr;
- }
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ volume->runtime.grids = nullptr;
- /* write LibData */
- BLO_write_id_struct(writer, Volume, id_address, &volume->id);
- BKE_id_blend_write(writer, &volume->id);
+ /* Do not store packed files in case this is a library override ID. */
+ if (ID_IS_OVERRIDE_LIBRARY(volume) && !is_undo) {
+ volume->packedfile = nullptr;
+ }
- /* direct data */
- BLO_write_pointer_array(writer, volume->totcol, volume->mat);
- if (volume->adt) {
- BKE_animdata_blend_write(writer, volume->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, Volume, id_address, &volume->id);
+ BKE_id_blend_write(writer, &volume->id);
- BKE_packedfile_blend_write(writer, volume->packedfile);
+ /* direct data */
+ BLO_write_pointer_array(writer, volume->totcol, volume->mat);
+ if (volume->adt) {
+ BKE_animdata_blend_write(writer, volume->adt);
}
+
+ BKE_packedfile_blend_write(writer, volume->packedfile);
}
static void volume_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index e889d8af1d5..4abe1ff0f20 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -138,26 +138,25 @@ static void world_foreach_id(ID *id, LibraryForeachIDData *data)
static void world_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
World *wrld = (World *)id;
- if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- BLI_listbase_clear(&wrld->gpumaterial);
- /* write LibData */
- BLO_write_id_struct(writer, World, id_address, &wrld->id);
- BKE_id_blend_write(writer, &wrld->id);
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ BLI_listbase_clear(&wrld->gpumaterial);
- if (wrld->adt) {
- BKE_animdata_blend_write(writer, wrld->adt);
- }
+ /* write LibData */
+ BLO_write_id_struct(writer, World, id_address, &wrld->id);
+ BKE_id_blend_write(writer, &wrld->id);
- /* nodetree is integral part of world, no libdata */
- if (wrld->nodetree) {
- BLO_write_struct(writer, bNodeTree, wrld->nodetree);
- ntreeBlendWrite(writer, wrld->nodetree);
- }
+ if (wrld->adt) {
+ BKE_animdata_blend_write(writer, wrld->adt);
+ }
- BKE_previewimg_blend_write(writer, wrld->preview);
+ /* nodetree is integral part of world, no libdata */
+ if (wrld->nodetree) {
+ BLO_write_struct(writer, bNodeTree, wrld->nodetree);
+ ntreeBlendWrite(writer, wrld->nodetree);
}
+
+ BKE_previewimg_blend_write(writer, wrld->preview);
}
static void world_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index 32057709c38..a20c918c517 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -149,7 +149,6 @@ static int write_audio_frame(FFMpegContext *context)
AUD_Device_read(
context->audio_mixdown_device, context->audio_input_buffer, context->audio_input_samples);
- context->audio_time += (double)context->audio_input_samples / (double)c->sample_rate;
frame = av_frame_alloc();
frame->pts = context->audio_time / av_q2d(c->time_base);
@@ -184,7 +183,7 @@ static int write_audio_frame(FFMpegContext *context)
context->audio_input_samples * c->channels * context->audio_sample_size,
1);
- int success = 0;
+ int success = 1;
int ret = avcodec_send_frame(c, frame);
if (ret < 0) {
@@ -369,7 +368,7 @@ static int write_video_frame(FFMpegContext *context, int cfra, AVFrame *frame, R
return success;
}
-/* read and encode a frame of audio from the buffer */
+/* read and encode a frame of video from the buffer */
static AVFrame *generate_video_frame(FFMpegContext *context, const uint8_t *pixels)
{
AVCodecParameters *codec = context->video_stream->codecpar;
@@ -1226,9 +1225,8 @@ fail:
* parameter.
* </p>
*/
-static void flush_ffmpeg(FFMpegContext *context)
+static void flush_ffmpeg(AVCodecContext *c, AVStream *stream, AVFormatContext *outfile)
{
- AVCodecContext *c = context->video_codec;
AVPacket *packet = av_packet_alloc();
avcodec_send_frame(c, NULL);
@@ -1247,13 +1245,13 @@ static void flush_ffmpeg(FFMpegContext *context)
break;
}
- packet->stream_index = context->video_stream->index;
- av_packet_rescale_ts(packet, c->time_base, context->video_stream->time_base);
+ packet->stream_index = stream->index;
+ av_packet_rescale_ts(packet, c->time_base, stream->time_base);
# ifdef FFMPEG_USE_DURATION_WORKAROUND
- my_guess_pkt_duration(context->outfile, context->video_stream, packet);
+ my_guess_pkt_duration(outfile, stream, packet);
# endif
- int write_ret = av_interleaved_write_frame(context->outfile, packet);
+ int write_ret = av_interleaved_write_frame(outfile, packet);
if (write_ret != 0) {
fprintf(stderr, "Error writing delayed frame: %s\n", av_err2str(write_ret));
break;
@@ -1396,12 +1394,13 @@ static void end_ffmpeg_impl(FFMpegContext *context, int is_autosplit);
# ifdef WITH_AUDASPACE
static void write_audio_frames(FFMpegContext *context, double to_pts)
{
- int finished = 0;
+ AVCodecContext *c = context->audio_codec;
- while (context->audio_stream && !finished) {
- if ((context->audio_time >= to_pts) || (write_audio_frame(context))) {
- finished = 1;
+ while (context->audio_stream) {
+ if ((context->audio_time >= to_pts) || !write_audio_frame(context)) {
+ break;
}
+ context->audio_time += (double)context->audio_input_samples / (double)c->sample_rate;
}
}
# endif
@@ -1422,9 +1421,6 @@ int BKE_ffmpeg_append(void *context_v,
PRINT("Writing frame %i, render width=%d, render height=%d\n", frame, rectx, recty);
- /* why is this done before writing the video frame and again at end_ffmpeg? */
- // write_audio_frames(frame / (((double)rd->frs_sec) / rd->frs_sec_base));
-
if (context->video_stream) {
avframe = generate_video_frame(context, (unsigned char *)pixels);
success = (avframe && write_video_frame(context, frame - start_frame, avframe, reports));
@@ -1439,8 +1435,9 @@ int BKE_ffmpeg_append(void *context_v,
}
# ifdef WITH_AUDASPACE
- write_audio_frames(context,
- (frame - start_frame) / (((double)rd->frs_sec) / (double)rd->frs_sec_base));
+ /* Add +1 frame because we want to encode audio up until the next video frame. */
+ write_audio_frames(
+ context, (frame - start_frame + 1) / (((double)rd->frs_sec) / (double)rd->frs_sec_base));
# endif
return success;
}
@@ -1461,8 +1458,13 @@ static void end_ffmpeg_impl(FFMpegContext *context, int is_autosplit)
# endif
if (context->video_stream) {
- PRINT("Flushing delayed frames...\n");
- flush_ffmpeg(context);
+ PRINT("Flushing delayed video frames...\n");
+ flush_ffmpeg(context->video_codec, context->video_stream, context->outfile);
+ }
+
+ if (context->audio_stream) {
+ PRINT("Flushing delayed audio frames...\n");
+ flush_ffmpeg(context->audio_codec, context->audio_stream, context->outfile);
}
if (context->outfile) {
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 7cfecc798a7..906a56ce909 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -154,18 +154,17 @@ bool BLI_file_is_writable(const char *file) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL
bool BLI_file_touch(const char *file) ATTR_NONNULL();
bool BLI_file_alias_target(const char *filepath, char *r_targetpath) ATTR_WARN_UNUSED_RESULT;
-#if 0 /* UNUSED */
-int BLI_file_gzip(const char *from, const char *to) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-#endif
-char *BLI_file_ungzip_to_mem(const char *from_file, int *r_size) ATTR_WARN_UNUSED_RESULT
- ATTR_NONNULL();
-size_t BLI_gzip_mem_to_file_at_pos(void *buf,
- size_t len,
- FILE *file,
- size_t gz_stream_offset,
- int compression_level) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-size_t BLI_ungzip_file_to_mem_at_pos(void *buf, size_t len, FILE *file, size_t gz_stream_offset)
+bool BLI_file_magic_is_gzip(const char header[4]);
+
+size_t BLI_file_zstd_from_mem_at_pos(void *buf,
+ size_t len,
+ FILE *file,
+ size_t file_offset,
+ int compression_level) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+size_t BLI_file_unzstd_to_mem_at_pos(void *buf, size_t len, FILE *file, size_t file_offset)
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+bool BLI_file_magic_is_zstd(const char header[4]);
+
size_t BLI_file_descriptor_size(int file) ATTR_WARN_UNUSED_RESULT;
size_t BLI_file_size(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
diff --git a/source/blender/blenlib/BLI_filereader.h b/source/blender/blenlib/BLI_filereader.h
new file mode 100644
index 00000000000..8d1fa3d1596
--- /dev/null
+++ b/source/blender/blenlib/BLI_filereader.h
@@ -0,0 +1,81 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bli
+ * \brief Wrapper for reading from various sources (e.g. raw files, compressed files, memory...).
+ */
+
+#pragma once
+
+#ifdef WIN32
+# include "BLI_winstuff.h"
+#else
+# include <sys/types.h>
+#endif
+
+#include "BLI_compiler_attrs.h"
+#include "BLI_utildefines.h"
+
+#if defined(_MSC_VER) || defined(__APPLE__) || defined(__HAIKU__) || defined(__NetBSD__)
+typedef int64_t off64_t;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct FileReader;
+
+typedef ssize_t (*FileReaderReadFn)(struct FileReader *reader, void *buffer, size_t size);
+typedef off64_t (*FileReaderSeekFn)(struct FileReader *reader, off64_t offset, int whence);
+typedef void (*FileReaderCloseFn)(struct FileReader *reader);
+
+/* General structure for all FileReaders, implementations add custom fields at the end. */
+typedef struct FileReader {
+ FileReaderReadFn read;
+ FileReaderSeekFn seek;
+ FileReaderCloseFn close;
+
+ off64_t offset;
+} FileReader;
+
+/* Functions for opening the various types of FileReader.
+ * They either succeed and return a valid FileReader, or fail and return NULL.
+ *
+ * If a FileReader is created, it has to be cleaned up and freed by calling
+ * its close() function unless another FileReader has taken ownership - for example,
+ * Zstd and Gzip take over the base FileReader and will clean it up when their clean() is called.
+ */
+
+/* Create FileReader from raw file descriptor. */
+FileReader *BLI_filereader_new_file(int filedes) ATTR_WARN_UNUSED_RESULT;
+/* Create FileReader from raw file descriptor using memory-mapped IO. */
+FileReader *BLI_filereader_new_mmap(int filedes) ATTR_WARN_UNUSED_RESULT;
+/* Create FileReader from a region of memory. */
+FileReader *BLI_filereader_new_memory(const void *data, size_t len) ATTR_WARN_UNUSED_RESULT
+ ATTR_NONNULL();
+/* Create FileReader from applying Zstd decompression on an underlying file. */
+FileReader *BLI_filereader_new_zstd(FileReader *base) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+/* Create FileReader from applying Gzip decompression on an underlying file. */
+FileReader *BLI_filereader_new_gzip(FileReader *base) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh
index f04c0e9c80a..7a3169520ca 100644
--- a/source/blender/blenlib/BLI_index_mask.hh
+++ b/source/blender/blenlib/BLI_index_mask.hh
@@ -58,11 +58,7 @@ class IndexMask {
*/
IndexMask(Span<int64_t> indices) : indices_(indices)
{
-#ifdef DEBUG
- for (int64_t i = 1; i < indices.size(); i++) {
- BLI_assert(indices[i - 1] < indices[i]);
- }
-#endif
+ BLI_assert(IndexMask::indices_are_valid_index_mask(indices));
}
/**
@@ -94,6 +90,22 @@ class IndexMask {
{
}
+ /** Checks that the indices are non-negative and in ascending order. */
+ static bool indices_are_valid_index_mask(Span<int64_t> indices)
+ {
+ if (!indices.is_empty()) {
+ if (indices.first() < 0) {
+ return false;
+ }
+ }
+ for (int64_t i = 1; i < indices.size(); i++) {
+ if (indices[i - 1] >= indices[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
operator Span<int64_t>() const
{
return indices_;
@@ -204,6 +216,11 @@ class IndexMask {
{
return indices_.size();
}
+
+ bool is_empty() const
+ {
+ return indices_.is_empty();
+ }
};
} // namespace blender
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index e877503e835..9b54f780296 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -172,6 +172,9 @@ MINLINE size_t clamp_z(size_t value, size_t min, size_t max);
MINLINE int compare_ff(float a, float b, const float max_diff);
MINLINE int compare_ff_relative(float a, float b, const float max_diff, const int max_ulps);
+MINLINE bool compare_threshold_relative(const float value1,
+ const float value2,
+ const float thresh);
MINLINE float signf(float f);
MINLINE int signum_i_ex(float a, float eps);
@@ -196,6 +199,8 @@ MINLINE unsigned int log2_ceil_u(unsigned int x);
MINLINE int divide_round_i(int a, int b);
MINLINE int mod_i(int i, int n);
+MINLINE float round_to_even(float f);
+
MINLINE signed char round_fl_to_char(float a);
MINLINE unsigned char round_fl_to_uchar(float a);
MINLINE short round_fl_to_short(float a);
diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h
index 65d9d7863c3..b936e39731d 100644
--- a/source/blender/blenlib/BLI_string_utf8.h
+++ b/source/blender/blenlib/BLI_string_utf8.h
@@ -31,8 +31,8 @@ char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t
ATTR_NONNULL();
size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy)
ATTR_NONNULL();
-ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL();
-int BLI_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL();
+ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL();
+int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL();
/* warning, can return -1 on bad chars */
int BLI_str_utf8_size(const char *p) ATTR_NONNULL();
@@ -43,8 +43,10 @@ unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *
ATTR_NONNULL();
unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p,
size_t *__restrict index) ATTR_NONNULL();
-unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)
- ATTR_NONNULL();
+unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p,
+ size_t p_len,
+ size_t *__restrict index) ATTR_NONNULL(1, 3);
+
size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf);
size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w,
const char *__restrict src_c,
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index b6603dce378..f98d15ad08b 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -31,6 +31,7 @@ set(INC
set(INC_SYS
${ZLIB_INCLUDE_DIRS}
+ ${ZSTD_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
${GMP_INCLUDE_DIRS}
)
@@ -75,6 +76,10 @@ set(SRC
intern/endian_switch.c
intern/expr_pylike_eval.c
intern/fileops.c
+ intern/filereader_file.c
+ intern/filereader_gzip.c
+ intern/filereader_memory.c
+ intern/filereader_zstd.c
intern/fnmatch.c
intern/freetypefont.c
intern/gsqueue.c
@@ -194,6 +199,7 @@ set(SRC
BLI_enumerable_thread_specific.hh
BLI_expr_pylike_eval.h
BLI_fileops.h
+ BLI_filereader.h
BLI_fileops_types.h
BLI_float2.hh
BLI_float3.hh
@@ -323,6 +329,7 @@ set(LIB
${FREETYPE_LIBRARY}
${ZLIB_LIBRARIES}
+ ${ZSTD_LIBRARIES}
)
if(WITH_MEM_VALGRIND)
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index ac034d2b5cd..532a29b8147 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include "zlib.h"
+#include "zstd.h"
#ifdef WIN32
# include "BLI_fileops_types.h"
@@ -61,200 +62,124 @@
#include "BLI_sys_types.h" /* for intptr_t support */
#include "BLI_utildefines.h"
-#if 0 /* UNUSED */
-/* gzip the file in from and write it to "to".
- * return -1 if zlib fails, -2 if the originating file does not exist
- * NOTE: will remove the "from" file
- */
-int BLI_file_gzip(const char *from, const char *to)
+size_t BLI_file_zstd_from_mem_at_pos(
+ void *buf, size_t len, FILE *file, size_t file_offset, int compression_level)
{
- char buffer[10240];
- int file;
- int readsize = 0;
- int rval = 0, err;
- gzFile gzfile;
+ fseek(file, file_offset, SEEK_SET);
- /* level 1 is very close to 3 (the default) in terms of file size,
- * but about twice as fast, best use for speedy saving - campbell */
- gzfile = BLI_gzopen(to, "wb1");
- if (gzfile == NULL) {
- return -1;
- }
- file = BLI_open(from, O_BINARY | O_RDONLY, 0);
- if (file == -1) {
- return -2;
- }
+ ZSTD_CCtx *ctx = ZSTD_createCCtx();
+ ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionLevel, compression_level);
+
+ ZSTD_inBuffer input = {buf, len, 0};
- while (1) {
- readsize = read(file, buffer, sizeof(buffer));
+ size_t out_len = ZSTD_CStreamOutSize();
+ void *out_buf = MEM_mallocN(out_len, __func__);
+ size_t total_written = 0;
- if (readsize < 0) {
- rval = -2; /* error happened in reading */
- fprintf(stderr, "Error reading file %s: %s.\n", from, strerror(errno));
+ /* Compress block and write it out until the input has been consumed. */
+ while (input.pos < input.size) {
+ ZSTD_outBuffer output = {out_buf, out_len, 0};
+ size_t ret = ZSTD_compressStream2(ctx, &output, &input, ZSTD_e_continue);
+ if (ZSTD_isError(ret)) {
break;
}
- else if (readsize == 0) {
- break; /* done reading */
+ if (fwrite(out_buf, 1, output.pos, file) != output.pos) {
+ break;
}
+ total_written += output.pos;
+ }
- if (gzwrite(gzfile, buffer, readsize) <= 0) {
- rval = -1; /* error happened in writing */
- fprintf(stderr, "Error writing gz file %s: %s.\n", to, gzerror(gzfile, &err));
+ /* Finalize the Zstd frame. */
+ size_t ret = 1;
+ while (ret != 0) {
+ ZSTD_outBuffer output = {out_buf, out_len, 0};
+ ret = ZSTD_compressStream2(ctx, &output, &input, ZSTD_e_end);
+ if (ZSTD_isError(ret)) {
+ break;
+ }
+ if (fwrite(out_buf, 1, output.pos, file) != output.pos) {
break;
}
+ total_written += output.pos;
}
- gzclose(gzfile);
- close(file);
+ MEM_freeN(out_buf);
+ ZSTD_freeCCtx(ctx);
- return rval;
+ return ZSTD_isError(ret) ? 0 : total_written;
}
-#endif
-/* gzip the file in from_file and write it to memory to_mem, at most size bytes.
- * return the unzipped size
- */
-char *BLI_file_ungzip_to_mem(const char *from_file, int *r_size)
+size_t BLI_file_unzstd_to_mem_at_pos(void *buf, size_t len, FILE *file, size_t file_offset)
{
- gzFile gzfile;
- int readsize, size, alloc_size = 0;
- char *mem = NULL;
- const int chunk_size = 512 * 1024;
+ fseek(file, file_offset, SEEK_SET);
- size = 0;
+ ZSTD_DCtx *ctx = ZSTD_createDCtx();
- gzfile = BLI_gzopen(from_file, "rb");
- for (;;) {
- if (mem == NULL) {
- mem = MEM_callocN(chunk_size, "BLI_ungzip_to_mem");
- alloc_size = chunk_size;
- }
- else {
- mem = MEM_reallocN(mem, size + chunk_size);
- alloc_size += chunk_size;
- }
+ size_t in_len = ZSTD_DStreamInSize();
+ void *in_buf = MEM_mallocN(in_len, __func__);
+ ZSTD_inBuffer input = {in_buf, in_len, 0};
- readsize = gzread(gzfile, mem + size, chunk_size);
- if (readsize > 0) {
- size += readsize;
- }
- else {
+ ZSTD_outBuffer output = {buf, len, 0};
+
+ size_t ret = 0;
+ /* Read and decompress chunks of input data until we have enough output. */
+ while (output.pos < output.size && !ZSTD_isError(ret)) {
+ input.size = fread(in_buf, 1, in_len, file);
+ if (input.size == 0) {
break;
}
- }
- gzclose(gzfile);
+ /* Consume input data until we run out or have enough output. */
+ input.pos = 0;
+ while (input.pos < input.size && output.pos < output.size) {
+ ret = ZSTD_decompressStream(ctx, &output, &input);
- if (size == 0) {
- MEM_freeN(mem);
- mem = NULL;
- }
- else if (alloc_size != size) {
- mem = MEM_reallocN(mem, size);
+ if (ZSTD_isError(ret)) {
+ break;
+ }
+ }
}
- *r_size = size;
+ MEM_freeN(in_buf);
+ ZSTD_freeDCtx(ctx);
- return mem;
+ return ZSTD_isError(ret) ? 0 : output.pos;
}
-#define CHUNK (256 * 1024)
-
-/* gzip byte array from memory and write it to file at certain position.
- * return size of gzip stream.
- */
-size_t BLI_gzip_mem_to_file_at_pos(
- void *buf, size_t len, FILE *file, size_t gz_stream_offset, int compression_level)
+bool BLI_file_magic_is_gzip(const char header[4])
{
- int ret, flush;
- unsigned have;
- z_stream strm;
- unsigned char out[CHUNK];
-
- BLI_fseek(file, gz_stream_offset, 0);
-
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&strm, compression_level);
- if (ret != Z_OK) {
- return 0;
- }
-
- strm.avail_in = len;
- strm.next_in = (Bytef *)buf;
- flush = Z_FINISH;
-
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = deflate(&strm, flush);
- if (ret == Z_STREAM_ERROR) {
- return 0;
- }
- have = CHUNK - strm.avail_out;
- if (fwrite(out, 1, have, file) != have || ferror(file)) {
- deflateEnd(&strm);
- return 0;
- }
- } while (strm.avail_out == 0);
-
- if (strm.avail_in != 0 || ret != Z_STREAM_END) {
- return 0;
- }
-
- deflateEnd(&strm);
- return (size_t)strm.total_out;
+ /* GZIP itself starts with the magic bytes 0x1f 0x8b.
+ * The third byte indicates the compression method, which is 0x08 for DEFLATE. */
+ return header[0] == 0x1f && header[1] == 0x8b && header[2] == 0x08;
}
-/* read and decompress gzip stream from file at certain position to buffer.
- * return size of decompressed data.
- */
-size_t BLI_ungzip_file_to_mem_at_pos(void *buf, size_t len, FILE *file, size_t gz_stream_offset)
+bool BLI_file_magic_is_zstd(const char header[4])
{
- int ret;
- z_stream strm;
- size_t chunk = 256 * 1024;
- unsigned char in[CHUNK];
-
- BLI_fseek(file, gz_stream_offset, 0);
-
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm);
- if (ret != Z_OK) {
- return 0;
+ /* ZSTD files consist of concatenated frames, each either a Zstd frame or a skippable frame.
+ * Both types of frames start with a magic number: 0xFD2FB528 for Zstd frames and 0x184D2A5*
+ * for skippable frames, with the * being anything from 0 to F.
+ *
+ * To check whether a file is Zstd-compressed, we just check whether the first frame matches
+ * either. Seeking through the file until a Zstd frame is found would make things more
+ * complicated and the probability of a false positive is rather low anyways.
+ *
+ * Note that LZ4 uses a compatible format, so even though its compressed frames have a
+ * different magic number, a valid LZ4 file might also start with a skippable frame matching
+ * the second check here.
+ *
+ * For more details, see https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
+ */
+
+ uint32_t magic = *((uint32_t *)header);
+ if (magic == 0xFD2FB528) {
+ return true;
}
-
- do {
- strm.avail_in = fread(in, 1, chunk, file);
- strm.next_in = in;
- if (ferror(file)) {
- inflateEnd(&strm);
- return 0;
- }
-
- do {
- strm.avail_out = len;
- strm.next_out = (Bytef *)buf + strm.total_out;
-
- ret = inflate(&strm, Z_NO_FLUSH);
- if (ret == Z_STREAM_ERROR) {
- return 0;
- }
- } while (strm.avail_out == 0);
-
- } while (ret != Z_STREAM_END);
-
- inflateEnd(&strm);
- return (size_t)strm.total_out;
+ if ((magic >> 4) == 0x184D2A5) {
+ return true;
+ }
+ return false;
}
-#undef CHUNK
-
/**
* Returns true if the file with the specified name can be written.
* This implementation uses access(2), which makes the check according
diff --git a/source/blender/blenlib/intern/filereader_file.c b/source/blender/blenlib/intern/filereader_file.c
new file mode 100644
index 00000000000..3a833871e27
--- /dev/null
+++ b/source/blender/blenlib/intern/filereader_file.c
@@ -0,0 +1,80 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2004-2021 Blender Foundation
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bli
+ */
+
+#ifndef WIN32
+# include <unistd.h> /* for read close */
+#else
+# include "BLI_winstuff.h"
+# include "winsock2.h"
+# include <io.h> /* for open close read */
+#endif
+
+#include "BLI_blenlib.h"
+#include "BLI_filereader.h"
+
+#include "MEM_guardedalloc.h"
+
+typedef struct {
+ FileReader reader;
+
+ int filedes;
+} RawFileReader;
+
+static ssize_t file_read(FileReader *reader, void *buffer, size_t size)
+{
+ RawFileReader *rawfile = (RawFileReader *)reader;
+ ssize_t readsize = read(rawfile->filedes, buffer, size);
+
+ if (readsize >= 0) {
+ rawfile->reader.offset += readsize;
+ }
+
+ return readsize;
+}
+
+static off64_t file_seek(FileReader *reader, off64_t offset, int whence)
+{
+ RawFileReader *rawfile = (RawFileReader *)reader;
+ rawfile->reader.offset = BLI_lseek(rawfile->filedes, offset, whence);
+ return rawfile->reader.offset;
+}
+
+static void file_close(FileReader *reader)
+{
+ RawFileReader *rawfile = (RawFileReader *)reader;
+ close(rawfile->filedes);
+ MEM_freeN(rawfile);
+}
+
+FileReader *BLI_filereader_new_file(int filedes)
+{
+ RawFileReader *rawfile = MEM_callocN(sizeof(RawFileReader), __func__);
+
+ rawfile->filedes = filedes;
+
+ rawfile->reader.read = file_read;
+ rawfile->reader.seek = file_seek;
+ rawfile->reader.close = file_close;
+
+ return (FileReader *)rawfile;
+}
diff --git a/source/blender/blenlib/intern/filereader_gzip.c b/source/blender/blenlib/intern/filereader_gzip.c
new file mode 100644
index 00000000000..72eb153a8b9
--- /dev/null
+++ b/source/blender/blenlib/intern/filereader_gzip.c
@@ -0,0 +1,108 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2004-2021 Blender Foundation
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bli
+ */
+
+#include <zlib.h>
+
+#include "BLI_blenlib.h"
+#include "BLI_filereader.h"
+
+#include "MEM_guardedalloc.h"
+
+typedef struct {
+ FileReader reader;
+
+ FileReader *base;
+
+ z_stream strm;
+
+ void *in_buf;
+ size_t in_size;
+} GzipReader;
+
+static ssize_t gzip_read(FileReader *reader, void *buffer, size_t size)
+{
+ GzipReader *gzip = (GzipReader *)reader;
+
+ gzip->strm.avail_out = size;
+ gzip->strm.next_out = buffer;
+
+ while (gzip->strm.avail_out > 0) {
+ if (gzip->strm.avail_in == 0) {
+ /* Ran out of buffered input data, read some more. */
+ size_t readsize = gzip->base->read(gzip->base, gzip->in_buf, gzip->in_size);
+
+ if (readsize > 0) {
+ /* We got some data, so mark the buffer as refilled. */
+ gzip->strm.avail_in = readsize;
+ gzip->strm.next_in = gzip->in_buf;
+ }
+ else {
+ /* The underlying file is EOF, so return as much as we can. */
+ break;
+ }
+ }
+
+ int ret = inflate(&gzip->strm, Z_NO_FLUSH);
+
+ if (ret != Z_OK && ret != Z_BUF_ERROR) {
+ break;
+ }
+ }
+
+ ssize_t read_len = size - gzip->strm.avail_out;
+ gzip->reader.offset += read_len;
+ return read_len;
+}
+
+static void gzip_close(FileReader *reader)
+{
+ GzipReader *gzip = (GzipReader *)reader;
+
+ if (inflateEnd(&gzip->strm) != Z_OK) {
+ printf("close gzip stream error\n");
+ }
+ MEM_freeN((void *)gzip->in_buf);
+
+ gzip->base->close(gzip->base);
+ MEM_freeN(gzip);
+}
+
+FileReader *BLI_filereader_new_gzip(FileReader *base)
+{
+ GzipReader *gzip = MEM_callocN(sizeof(GzipReader), __func__);
+ gzip->base = base;
+
+ if (inflateInit2(&gzip->strm, 16 + MAX_WBITS) != Z_OK) {
+ MEM_freeN(gzip);
+ return NULL;
+ }
+
+ gzip->in_size = 256 * 2014;
+ gzip->in_buf = MEM_mallocN(gzip->in_size, "gzip in buf");
+
+ gzip->reader.read = gzip_read;
+ gzip->reader.seek = NULL;
+ gzip->reader.close = gzip_close;
+
+ return (FileReader *)gzip;
+}
diff --git a/source/blender/blenlib/intern/filereader_memory.c b/source/blender/blenlib/intern/filereader_memory.c
new file mode 100644
index 00000000000..150fed7d1cc
--- /dev/null
+++ b/source/blender/blenlib/intern/filereader_memory.c
@@ -0,0 +1,145 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2004-2021 Blender Foundation
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bli
+ */
+
+#include <string.h>
+
+#include "BLI_blenlib.h"
+#include "BLI_filereader.h"
+#include "BLI_mmap.h"
+
+#include "MEM_guardedalloc.h"
+
+/* This file implements both memory-backed and memory-mapped-file-backed reading. */
+typedef struct {
+ FileReader reader;
+
+ const char *data;
+ BLI_mmap_file *mmap;
+ size_t length;
+} MemoryReader;
+
+static ssize_t memory_read_raw(FileReader *reader, void *buffer, size_t size)
+{
+ MemoryReader *mem = (MemoryReader *)reader;
+
+ /* Don't read more bytes than there are available in the buffer. */
+ size_t readsize = MIN2(size, (size_t)(mem->length - mem->reader.offset));
+
+ memcpy(buffer, mem->data + mem->reader.offset, readsize);
+ mem->reader.offset += readsize;
+
+ return readsize;
+}
+
+static off64_t memory_seek(FileReader *reader, off64_t offset, int whence)
+{
+ MemoryReader *mem = (MemoryReader *)reader;
+
+ off64_t new_pos;
+ if (whence == SEEK_CUR) {
+ new_pos = mem->reader.offset + offset;
+ }
+ else if (whence == SEEK_SET) {
+ new_pos = offset;
+ }
+ else if (whence == SEEK_END) {
+ new_pos = mem->length + offset;
+ }
+ else {
+ return -1;
+ }
+
+ if (new_pos < 0 || new_pos > mem->length) {
+ return -1;
+ }
+
+ mem->reader.offset = new_pos;
+ return mem->reader.offset;
+}
+
+static void memory_close_raw(FileReader *reader)
+{
+ MEM_freeN(reader);
+}
+
+FileReader *BLI_filereader_new_memory(const void *data, size_t len)
+{
+ MemoryReader *mem = MEM_callocN(sizeof(MemoryReader), __func__);
+
+ mem->data = (const char *)data;
+ mem->length = len;
+
+ mem->reader.read = memory_read_raw;
+ mem->reader.seek = memory_seek;
+ mem->reader.close = memory_close_raw;
+
+ return (FileReader *)mem;
+}
+
+/* Memory-mapped file reading.
+ * By using `mmap()`, we can map a file so that it can be treated like normal memory,
+ * meaning that we can just read from it with `memcpy()` etc.
+ * This avoids system call overhead and can significantly speed up file loading.
+ */
+
+static ssize_t memory_read_mmap(FileReader *reader, void *buffer, size_t size)
+{
+ MemoryReader *mem = (MemoryReader *)reader;
+
+ /* Don't read more bytes than there are available in the buffer. */
+ size_t readsize = MIN2(size, (size_t)(mem->length - mem->reader.offset));
+
+ if (!BLI_mmap_read(mem->mmap, buffer, mem->reader.offset, readsize)) {
+ return 0;
+ }
+
+ mem->reader.offset += readsize;
+
+ return readsize;
+}
+
+static void memory_close_mmap(FileReader *reader)
+{
+ MemoryReader *mem = (MemoryReader *)reader;
+ BLI_mmap_free(mem->mmap);
+ MEM_freeN(mem);
+}
+
+FileReader *BLI_filereader_new_mmap(int filedes)
+{
+ BLI_mmap_file *mmap = BLI_mmap_open(filedes);
+ if (mmap == NULL) {
+ return NULL;
+ }
+
+ MemoryReader *mem = MEM_callocN(sizeof(MemoryReader), __func__);
+
+ mem->mmap = mmap;
+ mem->length = BLI_lseek(filedes, 0, SEEK_END);
+
+ mem->reader.read = memory_read_mmap;
+ mem->reader.seek = memory_seek;
+ mem->reader.close = memory_close_mmap;
+
+ return (FileReader *)mem;
+}
diff --git a/source/blender/blenlib/intern/filereader_zstd.c b/source/blender/blenlib/intern/filereader_zstd.c
new file mode 100644
index 00000000000..55ce32713d9
--- /dev/null
+++ b/source/blender/blenlib/intern/filereader_zstd.c
@@ -0,0 +1,335 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bli
+ */
+
+#include <string.h>
+#include <zstd.h>
+
+#include "BLI_blenlib.h"
+#include "BLI_endian_switch.h"
+#include "BLI_filereader.h"
+#include "BLI_math_base.h"
+
+#include "MEM_guardedalloc.h"
+
+typedef struct {
+ FileReader reader;
+
+ FileReader *base;
+
+ ZSTD_DCtx *ctx;
+ ZSTD_inBuffer in_buf;
+ size_t in_buf_max_size;
+
+ struct {
+ int num_frames;
+ size_t *compressed_ofs;
+ size_t *uncompressed_ofs;
+
+ char *cached_content;
+ int cached_frame;
+ } seek;
+} ZstdReader;
+
+static bool zstd_read_u32(FileReader *base, uint32_t *val)
+{
+ if (base->read(base, val, sizeof(uint32_t)) != sizeof(uint32_t)) {
+ return false;
+ }
+#ifdef __BIG_ENDIAN__
+ BLI_endian_switch_uint32(val);
+#endif
+ return true;
+}
+
+static bool zstd_read_seek_table(ZstdReader *zstd)
+{
+ FileReader *base = zstd->base;
+
+ /* The seek table frame is at the end of the file, so seek there
+ * and verify that there is enough data. */
+ if (base->seek(base, -4, SEEK_END) < 13) {
+ return false;
+ }
+ uint32_t magic;
+ if (!zstd_read_u32(base, &magic) || magic != 0x8F92EAB1) {
+ return false;
+ }
+
+ uint8_t flags;
+ if (base->seek(base, -5, SEEK_END) < 0 || base->read(base, &flags, 1) != 1) {
+ return false;
+ }
+ /* Bit 7 indicates check-sums. Bits 5 and 6 must be zero. */
+ bool has_checksums = (flags & 0x80);
+ if (flags & 0x60) {
+ return false;
+ }
+
+ uint32_t num_frames;
+ if (base->seek(base, -9, SEEK_END) < 0 || !zstd_read_u32(base, &num_frames)) {
+ return false;
+ }
+
+ /* Each frame has either 2 or 3 uint32_t, and after that we have
+ * num_frames, flags and magic for another 9 bytes. */
+ uint32_t expected_frame_length = num_frames * (has_checksums ? 12 : 8) + 9;
+ /* The frame starts with another magic number and its length, but these
+ * two fields are not included when counting length. */
+ off64_t frame_start_ofs = 8 + expected_frame_length;
+ /* Sanity check: Before the start of the seek table frame,
+ * there must be num_frames frames, each of which at least 8 bytes long. */
+ off64_t seek_frame_start = base->seek(base, -frame_start_ofs, SEEK_END);
+ if (seek_frame_start < num_frames * 8) {
+ return false;
+ }
+
+ if (!zstd_read_u32(base, &magic) || magic != 0x184D2A5E) {
+ return false;
+ }
+
+ uint32_t frame_length;
+ if (!zstd_read_u32(base, &frame_length) || frame_length != expected_frame_length) {
+ return false;
+ }
+
+ zstd->seek.num_frames = num_frames;
+ zstd->seek.compressed_ofs = MEM_malloc_arrayN(num_frames + 1, sizeof(size_t), __func__);
+ zstd->seek.uncompressed_ofs = MEM_malloc_arrayN(num_frames + 1, sizeof(size_t), __func__);
+
+ size_t compressed_ofs = 0;
+ size_t uncompressed_ofs = 0;
+ for (int i = 0; i < num_frames; i++) {
+ uint32_t compressed_size, uncompressed_size;
+ if (!zstd_read_u32(base, &compressed_size) || !zstd_read_u32(base, &uncompressed_size)) {
+ break;
+ }
+ if (has_checksums && base->seek(base, 4, SEEK_CUR) < 0) {
+ break;
+ }
+ zstd->seek.compressed_ofs[i] = compressed_ofs;
+ zstd->seek.uncompressed_ofs[i] = uncompressed_ofs;
+ compressed_ofs += compressed_size;
+ uncompressed_ofs += uncompressed_size;
+ }
+ zstd->seek.compressed_ofs[num_frames] = compressed_ofs;
+ zstd->seek.uncompressed_ofs[num_frames] = uncompressed_ofs;
+
+ /* Seek to the end of the previous frame for the following #BHead frame detection. */
+ if (seek_frame_start != compressed_ofs || base->seek(base, seek_frame_start, SEEK_SET) < 0) {
+ MEM_freeN(zstd->seek.compressed_ofs);
+ MEM_freeN(zstd->seek.uncompressed_ofs);
+ memset(&zstd->seek, 0, sizeof(zstd->seek));
+ return false;
+ }
+
+ zstd->seek.cached_frame = -1;
+
+ return true;
+}
+
+/* Find out which frame contains the given position in the uncompressed stream.
+ * Basically just bisection. */
+static int zstd_frame_from_pos(ZstdReader *zstd, size_t pos)
+{
+ int low = 0, high = zstd->seek.num_frames;
+
+ if (pos >= zstd->seek.uncompressed_ofs[zstd->seek.num_frames]) {
+ return -1;
+ }
+
+ while (low + 1 < high) {
+ int mid = low + ((high - low) >> 1);
+ if (zstd->seek.uncompressed_ofs[mid] <= pos) {
+ low = mid;
+ }
+ else {
+ high = mid;
+ }
+ }
+
+ return low;
+}
+
+/* Ensure that the currently loaded frame is the correct one. */
+static const char *zstd_ensure_cache(ZstdReader *zstd, int frame)
+{
+ if (zstd->seek.cached_frame == frame) {
+ /* Cached frame matches, so just return it. */
+ return zstd->seek.cached_content;
+ }
+
+ /* Cached frame doesn't match, so discard it and cache the wanted one instead. */
+ MEM_SAFE_FREE(zstd->seek.cached_content);
+
+ size_t compressed_size = zstd->seek.compressed_ofs[frame + 1] - zstd->seek.compressed_ofs[frame];
+ size_t uncompressed_size = zstd->seek.uncompressed_ofs[frame + 1] -
+ zstd->seek.uncompressed_ofs[frame];
+
+ char *uncompressed_data = MEM_mallocN(uncompressed_size, __func__);
+ char *compressed_data = MEM_mallocN(compressed_size, __func__);
+ if (zstd->base->seek(zstd->base, zstd->seek.compressed_ofs[frame], SEEK_SET) < 0 ||
+ zstd->base->read(zstd->base, compressed_data, compressed_size) < compressed_size) {
+ MEM_freeN(compressed_data);
+ MEM_freeN(uncompressed_data);
+ return NULL;
+ }
+
+ size_t res = ZSTD_decompressDCtx(
+ zstd->ctx, uncompressed_data, uncompressed_size, compressed_data, compressed_size);
+ MEM_freeN(compressed_data);
+ if (ZSTD_isError(res) || res < uncompressed_size) {
+ MEM_freeN(uncompressed_data);
+ return NULL;
+ }
+
+ zstd->seek.cached_frame = frame;
+ zstd->seek.cached_content = uncompressed_data;
+ return uncompressed_data;
+}
+
+static ssize_t zstd_read_seekable(FileReader *reader, void *buffer, size_t size)
+{
+ ZstdReader *zstd = (ZstdReader *)reader;
+
+ size_t end_offset = zstd->reader.offset + size, read_len = 0;
+ while (zstd->reader.offset < end_offset) {
+ int frame = zstd_frame_from_pos(zstd, zstd->reader.offset);
+ if (frame < 0) {
+ /* EOF is reached, so return as much as we can. */
+ break;
+ }
+
+ const char *framedata = zstd_ensure_cache(zstd, frame);
+ if (framedata == NULL) {
+ /* Error while reading the frame, so return as much as we can. */
+ break;
+ }
+
+ size_t frame_end_offset = min_zz(zstd->seek.uncompressed_ofs[frame + 1], end_offset);
+ size_t frame_read_len = frame_end_offset - zstd->reader.offset;
+
+ size_t offset_in_frame = zstd->reader.offset - zstd->seek.uncompressed_ofs[frame];
+ memcpy((char *)buffer + read_len, framedata + offset_in_frame, frame_read_len);
+ read_len += frame_read_len;
+ zstd->reader.offset = frame_end_offset;
+ }
+
+ return read_len;
+}
+
+static off64_t zstd_seek(FileReader *reader, off64_t offset, int whence)
+{
+ ZstdReader *zstd = (ZstdReader *)reader;
+ off64_t new_pos;
+ if (whence == SEEK_SET) {
+ new_pos = offset;
+ }
+ else if (whence == SEEK_END) {
+ new_pos = zstd->seek.uncompressed_ofs[zstd->seek.num_frames] + offset;
+ }
+ else {
+ new_pos = zstd->reader.offset + offset;
+ }
+
+ if (new_pos < 0 || new_pos > zstd->seek.uncompressed_ofs[zstd->seek.num_frames]) {
+ return -1;
+ }
+ zstd->reader.offset = new_pos;
+ return zstd->reader.offset;
+}
+
+static ssize_t zstd_read(FileReader *reader, void *buffer, size_t size)
+{
+ ZstdReader *zstd = (ZstdReader *)reader;
+ ZSTD_outBuffer output = {buffer, size, 0};
+
+ while (output.pos < output.size) {
+ if (zstd->in_buf.pos == zstd->in_buf.size) {
+ /* Ran out of buffered input data, read some more. */
+ zstd->in_buf.pos = 0;
+ ssize_t readsize = zstd->base->read(
+ zstd->base, (char *)zstd->in_buf.src, zstd->in_buf_max_size);
+
+ if (readsize > 0) {
+ /* We got some data, so mark the buffer as refilled. */
+ zstd->in_buf.size = readsize;
+ }
+ else {
+ /* The underlying file is EOF, so return as much as we can. */
+ break;
+ }
+ }
+
+ if (ZSTD_isError(ZSTD_decompressStream(zstd->ctx, &output, &zstd->in_buf))) {
+ break;
+ }
+ }
+
+ zstd->reader.offset += output.pos;
+ return output.pos;
+}
+
+static void zstd_close(FileReader *reader)
+{
+ ZstdReader *zstd = (ZstdReader *)reader;
+
+ ZSTD_freeDCtx(zstd->ctx);
+ if (zstd->reader.seek) {
+ MEM_freeN(zstd->seek.uncompressed_ofs);
+ MEM_freeN(zstd->seek.compressed_ofs);
+ MEM_freeN(zstd->seek.cached_content);
+ }
+ else {
+ MEM_freeN((void *)zstd->in_buf.src);
+ }
+
+ zstd->base->close(zstd->base);
+ MEM_freeN(zstd);
+}
+
+FileReader *BLI_filereader_new_zstd(FileReader *base)
+{
+ ZstdReader *zstd = MEM_callocN(sizeof(ZstdReader), __func__);
+
+ zstd->ctx = ZSTD_createDCtx();
+ zstd->base = base;
+
+ if (zstd_read_seek_table(zstd)) {
+ zstd->reader.read = zstd_read_seekable;
+ zstd->reader.seek = zstd_seek;
+ }
+ else {
+ zstd->reader.read = zstd_read;
+ zstd->reader.seek = NULL;
+
+ zstd->in_buf_max_size = ZSTD_DStreamInSize();
+ zstd->in_buf.src = MEM_mallocN(zstd->in_buf_max_size, "zstd in buf");
+ zstd->in_buf.size = zstd->in_buf_max_size;
+ /* This signals that the buffer has run out,
+ * which will make the read function refill it on the first call. */
+ zstd->in_buf.pos = zstd->in_buf_max_size;
+ }
+ zstd->reader.close = zstd_close;
+
+ return (FileReader *)zstd;
+}
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index a8b50b66f5f..e1e3aa273b5 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -302,7 +302,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
/* Get the name. */
if (face->family_name) {
BLI_snprintf(vfd->name, sizeof(vfd->name), "%s %s", face->family_name, face->style_name);
- BLI_utf8_invalid_strip(vfd->name, strlen(vfd->name));
+ BLI_str_utf8_invalid_strip(vfd->name, strlen(vfd->name));
}
/* Select a character map. */
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index a80c495ecf3..49f9faf1704 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -363,6 +363,14 @@ MINLINE signed char round_db_to_char_clamp(double a){
#undef _round_clamp_fl_impl
#undef _round_clamp_db_impl
+/**
+ * Round to closest even number, halfway cases are rounded away from zero.
+ */
+MINLINE float round_to_even(float f)
+{
+ return roundf(f * 0.5f) * 2.0f;
+}
+
/* integer division that rounds 0.5 up, particularly useful for color blending
* with integers, to avoid gradual darkening when rounding down */
MINLINE int divide_round_i(int a, int b)
@@ -648,6 +656,18 @@ MINLINE int compare_ff_relative(float a, float b, const float max_diff, const in
return ((ua.i < 0) != (ub.i < 0)) ? 0 : (abs(ua.i - ub.i) <= max_ulps) ? 1 : 0;
}
+MINLINE bool compare_threshold_relative(const float value1, const float value2, const float thresh)
+{
+ const float abs_diff = fabsf(value1 - value2);
+ /* Avoid letting the threshold get too small just because the values happen to be close to zero.
+ */
+ if (fabsf(value2) < 1) {
+ return abs_diff > thresh;
+ }
+ /* Using relative threshold in general. */
+ return abs_diff > thresh * fabsf(value2);
+}
+
MINLINE float signf(float f)
{
return (f < 0.0f) ? -1.0f : 1.0f;
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index dddefd60b1b..ddfdaffb706 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -1145,6 +1145,9 @@ MINLINE float len_v3v3(const float a[3], const float b[3])
return len_v3(d);
}
+/**
+ * \note any vectors containing `nan` will be zeroed out.
+ */
MINLINE float normalize_v2_v2_length(float r[2], const float a[2], const float unit_length)
{
float d = dot_v2v2(a, a);
@@ -1154,6 +1157,7 @@ MINLINE float normalize_v2_v2_length(float r[2], const float a[2], const float u
mul_v2_v2fl(r, a, unit_length / d);
}
else {
+ /* Either the vector is small or one of it's values contained `nan`. */
zero_v2(r);
d = 0.0f;
}
@@ -1175,17 +1179,20 @@ MINLINE float normalize_v2_length(float n[2], const float unit_length)
return normalize_v2_v2_length(n, n, unit_length);
}
+/**
+ * \note any vectors containing `nan` will be zeroed out.
+ */
MINLINE float normalize_v3_v3_length(float r[3], const float a[3], const float unit_length)
{
float d = dot_v3v3(a, a);
- /* a larger value causes normalize errors in a
- * scaled down models with camera extreme close */
+ /* A larger value causes normalize errors in a scaled down models with camera extreme close. */
if (d > 1.0e-35f) {
d = sqrtf(d);
mul_v3_v3fl(r, a, unit_length / d);
}
else {
+ /* Either the vector is small or one of it's values contained `nan`. */
zero_v3(r);
d = 0.0f;
}
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index 19ff8764259..dbde5221d7e 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -70,7 +70,7 @@ static const size_t utf8_skip_data[256] = {
*
* \return the offset of the first invalid byte.
*/
-ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length)
+ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length)
{
const unsigned char *p, *perr, *pend = (const unsigned char *)str + length;
unsigned char c;
@@ -200,14 +200,14 @@ utf8_error:
*
* \return number of stripped bytes.
*/
-int BLI_utf8_invalid_strip(char *str, size_t length)
+int BLI_str_utf8_invalid_strip(char *str, size_t length)
{
ptrdiff_t bad_char;
int tot = 0;
BLI_assert(str[length] == '\0');
- while ((bad_char = BLI_utf8_invalid_byte(str, length)) != -1) {
+ while ((bad_char = BLI_str_utf8_invalid_byte(str, length)) != -1) {
str += bad_char;
length -= (size_t)(bad_char + 1);
@@ -582,49 +582,69 @@ uint BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__r
/**
* Another variant that steps over the index.
+ *
+ * \param p: The text to step over.
+ * \param p_len: The length of `p`.
+ * \param index: Index of `p` to step over.
+ *
* \note currently this also falls back to latin1 for text drawing.
+ *
+ * \note The behavior for clipped text (where `p_len` limits decoding trailing bytes)
+ * must have the same behavior is encountering a nil byte,
+ * so functions that only use the first part of a string has matching behavior to functions
+ * that null terminate the text.
*/
-uint BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)
+uint BLI_str_utf8_as_unicode_step(const char *__restrict p,
+ const size_t p_len,
+ size_t *__restrict index)
{
int i, len;
uint mask = 0;
uint result;
- unsigned char c;
+ const char c = p[*index];
- p += *index;
- c = (unsigned char)*p;
+ BLI_assert(*index < p_len);
+ BLI_assert(c != '\0');
UTF8_COMPUTE(c, mask, len, -1);
if (UNLIKELY(len == -1)) {
- /* when called with NULL end, result will never be NULL,
- * checks for a NULL character */
- const char *p_next = BLI_str_find_next_char_utf8(p, NULL);
- /* will never return the same pointer unless '\0',
- * eternal loop is prevented */
- *index += (size_t)(p_next - p);
- return BLI_UTF8_ERR;
+ const char *p_next = BLI_str_find_next_char_utf8(p + *index, p + p_len);
+ /* #BLI_str_find_next_char_utf8 ensures the nil byte will terminate.
+ * so there is no chance this sets the index past the nil byte (assert this is the case). */
+ BLI_assert(p_next || (memchr(p + *index, '\0', p_len - *index) == NULL));
+ len = (int)((p_next ? (size_t)(p_next - p) : p_len) - *index);
+ result = BLI_UTF8_ERR;
+ }
+ else if (UNLIKELY(*index + (size_t)len > p_len)) {
+ /* A multi-byte character reads past the buffer bounds,
+ * match the behavior of encountering an byte with invalid encoding below. */
+ len = 1;
+ result = (uint)c;
}
-
- /* this is tricky since there are a few ways we can bail out of bad unicode
- * values, 3 possible solutions. */
+ else {
+ /* This is tricky since there are a few ways we can bail out of bad unicode
+ * values, 3 possible solutions. */
+ p += *index;
#if 0
- UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR);
+ UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR);
#elif 1
- /* WARNING: this is NOT part of glib, or supported by similar functions.
- * this is added for text drawing because some filepaths can have latin1
- * characters */
- UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR);
- if (result == BLI_UTF8_ERR) {
- len = 1;
- result = *p;
- }
- /* end warning! */
+ /* WARNING: this is NOT part of glib, or supported by similar functions.
+ * this is added for text drawing because some filepaths can have latin1
+ * characters */
+ UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR);
+ if (result == BLI_UTF8_ERR) {
+ len = 1;
+ result = (uint)c;
+ }
+ /* end warning! */
#else
- /* without a fallback like '?', text drawing will stop on this value */
- UTF8_GET(result, p, i, mask, len, '?');
+ /* Without a fallback like '?', text drawing will stop on this value. */
+ UTF8_GET(result, p, i, mask, len, '?');
#endif
+ }
*index += (size_t)len;
+ BLI_assert(*index <= p_len);
return result;
}
@@ -810,6 +830,7 @@ char *BLI_str_find_next_char_utf8(const char *p, const char *end)
{
if (*p) {
if (end) {
+ BLI_assert(end >= p);
for (++p; p < end && (*p & 0xc0) == 0x80; p++) {
/* do nothing */
}
diff --git a/source/blender/blenlib/tests/BLI_array_store_test.cc b/source/blender/blenlib/tests/BLI_array_store_test.cc
index 8bbd109fb81..89aeccdc105 100644
--- a/source/blender/blenlib/tests/BLI_array_store_test.cc
+++ b/source/blender/blenlib/tests/BLI_array_store_test.cc
@@ -187,17 +187,6 @@ static void testbuffer_list_state_from_data__stride_expand(ListBase *lb,
((void)0)
/* test in both directions */
-#define TESTBUFFER_STRINGS_EX(bs, ...) \
- { \
- ListBase lb; \
- TESTBUFFER_STRINGS_CREATE(&lb, __VA_ARGS__); \
-\
- testbuffer_run_tests(bs, &lb); \
-\
- testbuffer_list_free(&lb); \
- } \
- ((void)0)
-
#define TESTBUFFER_STRINGS(stride, chunk_count, ...) \
{ \
ListBase lb; \
diff --git a/source/blender/blenlib/tests/BLI_string_utf8_test.cc b/source/blender/blenlib/tests/BLI_string_utf8_test.cc
index 9ddc372e6d1..b25f2310e1e 100644
--- a/source/blender/blenlib/tests/BLI_string_utf8_test.cc
+++ b/source/blender/blenlib/tests/BLI_string_utf8_test.cc
@@ -2,6 +2,7 @@
#include "testing/testing.h"
+#include "BLI_rand.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
@@ -11,7 +12,8 @@
* quite their share of lines, they deserved their own file. */
/* -------------------------------------------------------------------- */
-/* tests */
+/** \name Test #BLI_str_utf8_invalid_strip
+ * \{ */
/* Breaking strings is confusing here, prefer over-long lines. */
/* clang-format off */
@@ -266,7 +268,7 @@ static const char *utf8_invalid_tests[][3] = {
};
/* clang-format on */
-/* BLI_utf8_invalid_strip (and indirectly, BLI_utf8_invalid_byte). */
+/* BLI_str_utf8_invalid_strip (and indirectly, BLI_str_utf8_invalid_byte). */
TEST(string, Utf8InvalidBytes)
{
for (int i = 0; utf8_invalid_tests[i][0] != nullptr; i++) {
@@ -277,10 +279,117 @@ TEST(string, Utf8InvalidBytes)
char buff[80];
memcpy(buff, tst, sizeof(buff));
- const int num_errors_found = BLI_utf8_invalid_strip(buff, sizeof(buff) - 1);
+ const int num_errors_found = BLI_str_utf8_invalid_strip(buff, sizeof(buff) - 1);
printf("[%02d] -> [%02d] \"%s\" -> \"%s\"\n", num_errors, num_errors_found, tst, buff);
EXPECT_EQ(num_errors_found, num_errors);
EXPECT_STREQ(buff, tst_stripped);
}
}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Test #BLI_str_utf8_as_unicode_step
+ * \{ */
+
+static size_t utf8_as_char32(const char *str, const char str_len, char32_t *r_result)
+{
+ size_t i = 0, result_len = 0;
+ while ((i < str_len) && (str[i] != '\0')) {
+ char32_t c = BLI_str_utf8_as_unicode_step(str, str_len, &i);
+ if (c != BLI_UTF8_ERR) {
+ r_result[result_len++] = c;
+ }
+ }
+ return i;
+}
+
+template<size_t Size, size_t SizeWithPadding>
+void utf8_as_char32_test_compare_with_pad_bytes(const char utf8_src[Size])
+{
+ char utf8_src_with_pad[SizeWithPadding] = {0};
+
+ memcpy(utf8_src_with_pad, utf8_src, Size);
+
+ char32_t unicode_dst_a[Size], unicode_dst_b[Size];
+
+ memset(unicode_dst_a, 0xff, sizeof(unicode_dst_a));
+ const size_t index_a = utf8_as_char32(utf8_src, Size, unicode_dst_a);
+
+ /* Test with padded and un-padded size,
+ * to ensure that extra available space doesn't yield a different result. */
+ for (int pass = 0; pass < 2; pass++) {
+ memset(unicode_dst_b, 0xff, sizeof(unicode_dst_b));
+ const size_t index_b = utf8_as_char32(
+ utf8_src_with_pad, pass ? Size : SizeWithPadding, unicode_dst_b);
+
+ /* Check the resulting content matches. */
+ EXPECT_EQ_ARRAY(unicode_dst_a, unicode_dst_b, Size);
+ /* Check the index of the source strings match. */
+ EXPECT_EQ(index_a, index_b);
+ }
+}
+
+template<size_t Size> void utf8_as_char32_test_compare(const char utf8_src[Size])
+{
+ /* Note that 7 is a little arbitrary,
+ * chosen since it's the maximum length of multi-byte character + 1
+ * to account for any errors that read past null bytes. */
+ utf8_as_char32_test_compare_with_pad_bytes<Size, Size + 1>(utf8_src);
+ utf8_as_char32_test_compare_with_pad_bytes<Size, Size + 7>(utf8_src);
+}
+
+template<size_t Size> void utf8_as_char32_test_at_buffer_size()
+{
+ char utf8_src[Size];
+
+ /* Test uniform bytes, also with offsets ascending & descending. */
+ for (int i = 0; i <= 0xff; i++) {
+ memset(utf8_src, i, sizeof(utf8_src));
+ utf8_as_char32_test_compare<Size>(utf8_src);
+
+ /* Offset trailing bytes up and down in steps of 1, 2, 4 .. etc. */
+ if (Size > 1) {
+ for (int mul = 1; mul < 256; mul *= 2) {
+ for (int ofs = 1; ofs < (int)Size; ofs++) {
+ utf8_src[ofs] = (char)(i + (ofs * mul));
+ }
+ utf8_as_char32_test_compare<Size>(utf8_src);
+
+ for (int ofs = 1; ofs < (int)Size; ofs++) {
+ utf8_src[ofs] = (char)(i - (ofs * mul));
+ }
+ utf8_as_char32_test_compare<Size>(utf8_src);
+ }
+ }
+ }
+
+ /* Random bytes. */
+ RNG *rng = BLI_rng_new(1);
+ for (int i = 0; i < 256; i++) {
+ BLI_rng_get_char_n(rng, utf8_src, sizeof(utf8_src));
+ utf8_as_char32_test_compare<Size>(utf8_src);
+ }
+ BLI_rng_free(rng);
+}
+
+TEST(string, Utf8AsUnicodeStep)
+{
+
+ /* Run tests at different buffer sizes. */
+ utf8_as_char32_test_at_buffer_size<1>();
+ utf8_as_char32_test_at_buffer_size<2>();
+ utf8_as_char32_test_at_buffer_size<3>();
+ utf8_as_char32_test_at_buffer_size<4>();
+ utf8_as_char32_test_at_buffer_size<5>();
+ utf8_as_char32_test_at_buffer_size<6>();
+ utf8_as_char32_test_at_buffer_size<7>();
+ utf8_as_char32_test_at_buffer_size<8>();
+ utf8_as_char32_test_at_buffer_size<9>();
+ utf8_as_char32_test_at_buffer_size<10>();
+ utf8_as_char32_test_at_buffer_size<11>();
+ utf8_as_char32_test_at_buffer_size<12>();
+}
+
+/** \} */
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index c3a33115613..dbdb181281a 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -118,6 +118,7 @@ typedef struct BlendFileReadReport {
/* Number of libraries which had overrides that needed to be resynced, and a single linked list
* of those. */
int resynced_lib_overrides_libraries_count;
+ bool do_resynced_lib_overrides_libraries_list;
struct LinkNode *resynced_lib_overrides_libraries;
} BlendFileReadReport;
diff --git a/source/blender/blenloader/BLO_undofile.h b/source/blender/blenloader/BLO_undofile.h
index fc41a6e832f..4e240e2462b 100644
--- a/source/blender/blenloader/BLO_undofile.h
+++ b/source/blender/blenloader/BLO_undofile.h
@@ -24,6 +24,8 @@
* \ingroup blenloader
*/
+#include "BLI_filereader.h"
+
struct GHash;
struct Scene;
@@ -65,6 +67,16 @@ typedef struct MemFileUndoData {
size_t undo_size;
} MemFileUndoData;
+/* FileReader-compatible wrapper for reading MemFiles */
+typedef struct {
+ FileReader reader;
+
+ MemFile *memfile;
+ int undo_direction;
+
+ bool memchunk_identical;
+} UndoReader;
+
/* actually only used writefile.c */
void BLO_memfile_write_init(MemFileWriteData *mem_data,
@@ -84,3 +96,5 @@ extern struct Main *BLO_memfile_main_get(struct MemFile *memfile,
struct Main *bmain,
struct Scene **r_scene);
extern bool BLO_memfile_write_file(struct MemFile *memfile, const char *filename);
+
+FileReader *BLO_memfile_new_filereader(MemFile *memfile, int undo_direction);
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index f5baf0dcb83..89631588ed0 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -42,7 +42,7 @@ set(INC
)
set(INC_SYS
- ${ZLIB_INCLUDE_DIRS}
+ ${ZSTD_INCLUDE_DIRS}
)
set(SRC
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index e48c305fc4b..49c3497f996 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -21,8 +21,6 @@
* \ingroup blenloader
*/
-#include "zlib.h"
-
#include <ctype.h> /* for isdigit. */
#include <fcntl.h> /* for open flags (O_BINARY, O_RDONLY). */
#include <limits.h>
@@ -71,7 +69,6 @@
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_mempool.h"
-#include "BLI_mmap.h"
#include "BLI_threads.h"
#include "PIL_time.h"
@@ -788,7 +785,7 @@ static BHeadN *get_bhead(FileData *fd)
*/
if (fd->flags & FD_FLAGS_FILE_POINTSIZE_IS_4) {
bhead4.code = DATA;
- readsize = fd->read(fd, &bhead4, sizeof(bhead4), NULL);
+ readsize = fd->file->read(fd->file, &bhead4, sizeof(bhead4));
if (readsize == sizeof(bhead4) || bhead4.code == ENDB) {
if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
@@ -811,7 +808,7 @@ static BHeadN *get_bhead(FileData *fd)
}
else {
bhead8.code = DATA;
- readsize = fd->read(fd, &bhead8, sizeof(bhead8), NULL);
+ readsize = fd->file->read(fd->file, &bhead8, sizeof(bhead8));
if (readsize == sizeof(bhead8) || bhead8.code == ENDB) {
if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
@@ -845,22 +842,22 @@ static BHeadN *get_bhead(FileData *fd)
/* pass */
}
#ifdef USE_BHEAD_READ_ON_DEMAND
- else if (fd->seek != NULL && BHEAD_USE_READ_ON_DEMAND(&bhead)) {
+ else if (fd->file->seek != NULL && BHEAD_USE_READ_ON_DEMAND(&bhead)) {
/* Delay reading bhead content. */
new_bhead = MEM_mallocN(sizeof(BHeadN), "new_bhead");
if (new_bhead) {
new_bhead->next = new_bhead->prev = NULL;
- new_bhead->file_offset = fd->file_offset;
+ new_bhead->file_offset = fd->file->offset;
new_bhead->has_data = false;
new_bhead->is_memchunk_identical = false;
new_bhead->bhead = bhead;
- off64_t seek_new = fd->seek(fd, bhead.len, SEEK_CUR);
+ off64_t seek_new = fd->file->seek(fd->file, bhead.len, SEEK_CUR);
if (seek_new == -1) {
fd->is_eof = true;
MEM_freeN(new_bhead);
new_bhead = NULL;
}
- BLI_assert(fd->file_offset == seek_new);
+ BLI_assert(fd->file->offset == seek_new);
}
else {
fd->is_eof = true;
@@ -878,14 +875,17 @@ static BHeadN *get_bhead(FileData *fd)
new_bhead->is_memchunk_identical = false;
new_bhead->bhead = bhead;
- readsize = fd->read(
- fd, new_bhead + 1, (size_t)bhead.len, &new_bhead->is_memchunk_identical);
+ readsize = fd->file->read(fd->file, new_bhead + 1, (size_t)bhead.len);
- if (readsize != (ssize_t)bhead.len) {
+ if (readsize != bhead.len) {
fd->is_eof = true;
MEM_freeN(new_bhead);
new_bhead = NULL;
}
+
+ if (fd->flags & FD_FLAGS_IS_MEMFILE) {
+ new_bhead->is_memchunk_identical = ((UndoReader *)fd->file)->memchunk_identical;
+ }
}
else {
fd->is_eof = true;
@@ -964,17 +964,19 @@ static bool blo_bhead_read_data(FileData *fd, BHead *thisblock, void *buf)
bool success = true;
BHeadN *new_bhead = BHEADN_FROM_BHEAD(thisblock);
BLI_assert(new_bhead->has_data == false && new_bhead->file_offset != 0);
- off64_t offset_backup = fd->file_offset;
- if (UNLIKELY(fd->seek(fd, new_bhead->file_offset, SEEK_SET) == -1)) {
+ off64_t offset_backup = fd->file->offset;
+ if (UNLIKELY(fd->file->seek(fd->file, new_bhead->file_offset, SEEK_SET) == -1)) {
success = false;
}
else {
- if (fd->read(fd, buf, (size_t)new_bhead->bhead.len, &new_bhead->is_memchunk_identical) !=
- (ssize_t)new_bhead->bhead.len) {
+ if (fd->file->read(fd->file, buf, (size_t)new_bhead->bhead.len) != new_bhead->bhead.len) {
success = false;
}
+ if (fd->flags & FD_FLAGS_IS_MEMFILE) {
+ new_bhead->is_memchunk_identical = ((UndoReader *)fd->file)->memchunk_identical;
+ }
}
- if (fd->seek(fd, offset_backup, SEEK_SET) == -1) {
+ if (fd->file->seek(fd->file, offset_backup, SEEK_SET) == -1) {
success = false;
}
return success;
@@ -1017,7 +1019,7 @@ static void decode_blender_header(FileData *fd)
ssize_t readsize;
/* read in the header data */
- readsize = fd->read(fd, header, sizeof(header), NULL);
+ readsize = fd->file->read(fd->file, header, sizeof(header));
if (readsize == sizeof(header) && STREQLEN(header, "BLENDER", 7) && ELEM(header[7], '_', '-') &&
ELEM(header[8], 'v', 'V') &&
@@ -1147,210 +1149,12 @@ static int *read_file_thumbnail(FileData *fd)
/** \} */
-/* -------------------------------------------------------------------- */
-/** \name File Data API
- * \{ */
-
-/* Regular file reading. */
-
-static ssize_t fd_read_data_from_file(FileData *filedata,
- void *buffer,
- size_t size,
- bool *UNUSED(r_is_memchunck_identical))
-{
- ssize_t readsize = read(filedata->filedes, buffer, size);
-
- if (readsize < 0) {
- readsize = EOF;
- }
- else {
- filedata->file_offset += readsize;
- }
-
- return readsize;
-}
-
-static off64_t fd_seek_data_from_file(FileData *filedata, off64_t offset, int whence)
-{
- filedata->file_offset = BLI_lseek(filedata->filedes, offset, whence);
- return filedata->file_offset;
-}
-
-/* GZip file reading. */
-
-static ssize_t fd_read_gzip_from_file(FileData *filedata,
- void *buffer,
- size_t size,
- bool *UNUSED(r_is_memchunck_identical))
-{
- BLI_assert(size <= INT_MAX);
-
- ssize_t readsize = gzread(filedata->gzfiledes, buffer, (uint)size);
-
- if (readsize < 0) {
- readsize = EOF;
- }
- else {
- filedata->file_offset += readsize;
- }
-
- return readsize;
-}
-
-/* Memory reading. */
-
-static ssize_t fd_read_from_memory(FileData *filedata,
- void *buffer,
- size_t size,
- bool *UNUSED(r_is_memchunck_identical))
-{
- /* don't read more bytes than there are available in the buffer */
- ssize_t readsize = (ssize_t)MIN2(size, filedata->buffersize - (size_t)filedata->file_offset);
-
- memcpy(buffer, filedata->buffer + filedata->file_offset, (size_t)readsize);
- filedata->file_offset += readsize;
-
- return readsize;
-}
-
-/* Memory-mapped file reading.
- * By using mmap(), we can map a file so that it can be treated like normal memory,
- * meaning that we can just read from it with memcpy() etc.
- * This avoids system call overhead and can significantly speed up file loading.
- */
-
-static ssize_t fd_read_from_mmap(FileData *filedata,
- void *buffer,
- size_t size,
- bool *UNUSED(r_is_memchunck_identical))
-{
- /* don't read more bytes than there are available in the buffer */
- size_t readsize = MIN2(size, (size_t)(filedata->buffersize - filedata->file_offset));
-
- if (!BLI_mmap_read(filedata->mmap_file, buffer, filedata->file_offset, readsize)) {
- return 0;
- }
-
- filedata->file_offset += readsize;
-
- return readsize;
-}
-
-static off64_t fd_seek_from_mmap(FileData *filedata, off64_t offset, int whence)
-{
- off64_t new_pos;
- if (whence == SEEK_CUR) {
- new_pos = filedata->file_offset + offset;
- }
- else if (whence == SEEK_SET) {
- new_pos = offset;
- }
- else if (whence == SEEK_END) {
- new_pos = filedata->buffersize + offset;
- }
- else {
- return -1;
- }
-
- if (new_pos < 0 || new_pos > filedata->buffersize) {
- return -1;
- }
-
- filedata->file_offset = new_pos;
- return filedata->file_offset;
-}
-
-/* MemFile reading. */
-
-static ssize_t fd_read_from_memfile(FileData *filedata,
- void *buffer,
- size_t size,
- bool *r_is_memchunck_identical)
-{
- static size_t seek = SIZE_MAX; /* the current position */
- static size_t offset = 0; /* size of previous chunks */
- static MemFileChunk *chunk = NULL;
- size_t chunkoffset, readsize, totread;
-
- if (r_is_memchunck_identical != NULL) {
- *r_is_memchunck_identical = true;
- }
-
- if (size == 0) {
- return 0;
- }
-
- if (seek != (size_t)filedata->file_offset) {
- chunk = filedata->memfile->chunks.first;
- seek = 0;
-
- while (chunk) {
- if (seek + chunk->size > (size_t)filedata->file_offset) {
- break;
- }
- seek += chunk->size;
- chunk = chunk->next;
- }
- offset = seek;
- seek = (size_t)filedata->file_offset;
- }
-
- if (chunk) {
- totread = 0;
-
- do {
- /* first check if it's on the end if current chunk */
- if (seek - offset == chunk->size) {
- offset += chunk->size;
- chunk = chunk->next;
- }
-
- /* debug, should never happen */
- if (chunk == NULL) {
- CLOG_ERROR(&LOG, "Illegal read, got a NULL chunk");
- return 0;
- }
-
- chunkoffset = seek - offset;
- readsize = size - totread;
-
- /* data can be spread over multiple chunks, so clamp size
- * to within this chunk, and then it will read further in
- * the next chunk */
- if (chunkoffset + readsize > chunk->size) {
- readsize = chunk->size - chunkoffset;
- }
-
- memcpy(POINTER_OFFSET(buffer, totread), chunk->buf + chunkoffset, readsize);
- totread += readsize;
- filedata->file_offset += readsize;
- seek += readsize;
- if (r_is_memchunck_identical != NULL) {
- /* `is_identical` of current chunk represents whether it changed compared to previous undo
- * step. this is fine in redo case, but not in undo case, where we need an extra flag
- * defined when saving the next (future) step after the one we want to restore, as we are
- * supposed to 'come from' that future undo step, and not the one before current one. */
- *r_is_memchunck_identical &= filedata->undo_direction == STEP_REDO ?
- chunk->is_identical :
- chunk->is_identical_future;
- }
- } while (totread < size);
-
- return (ssize_t)totread;
- }
-
- return 0;
-}
-
static FileData *filedata_new(BlendFileReadReport *reports)
{
BLI_assert(reports != NULL);
FileData *fd = MEM_callocN(sizeof(FileData), "FileData");
- fd->filedes = -1;
- fd->gzfiledes = NULL;
-
fd->memsdna = DNA_sdna_current_get();
fd->datamap = oldnewmap_new();
@@ -1387,78 +1191,66 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports)
static FileData *blo_filedata_from_file_descriptor(const char *filepath,
BlendFileReadReport *reports,
- int file)
+ int filedes)
{
- FileDataReadFn *read_fn = NULL;
- FileDataSeekFn *seek_fn = NULL; /* Optional. */
- size_t buffersize = 0;
- BLI_mmap_file *mmap_file = NULL;
-
- gzFile gzfile = (gzFile)Z_NULL;
-
char header[7];
+ FileReader *rawfile = BLI_filereader_new_file(filedes);
+ FileReader *file = NULL;
- /* Regular file. */
errno = 0;
- if (read(file, header, sizeof(header)) != sizeof(header)) {
+ /* If opening the file failed or we can't read the header, give up. */
+ if (rawfile == NULL || rawfile->read(rawfile, header, sizeof(header)) != sizeof(header)) {
BKE_reportf(reports->reports,
RPT_WARNING,
"Unable to read '%s': %s",
filepath,
errno ? strerror(errno) : TIP_("insufficient content"));
+ if (rawfile) {
+ rawfile->close(rawfile);
+ }
+ else {
+ close(filedes);
+ }
return NULL;
}
- /* Regular file. */
- if (memcmp(header, "BLENDER", sizeof(header)) == 0) {
- read_fn = fd_read_data_from_file;
- seek_fn = fd_seek_data_from_file;
+ /* Rewind the file after reading the header. */
+ rawfile->seek(rawfile, 0, SEEK_SET);
- mmap_file = BLI_mmap_open(file);
- if (mmap_file != NULL) {
- read_fn = fd_read_from_mmap;
- seek_fn = fd_seek_from_mmap;
- buffersize = BLI_lseek(file, 0, SEEK_END);
+ /* Check if we have a regular file. */
+ if (memcmp(header, "BLENDER", sizeof(header)) == 0) {
+ /* Try opening the file with memory-mapped IO. */
+ file = BLI_filereader_new_mmap(filedes);
+ if (file == NULL) {
+ /* mmap failed, so just keep using rawfile. */
+ file = rawfile;
+ rawfile = NULL;
}
}
-
- BLI_lseek(file, 0, SEEK_SET);
-
- /* Gzip file. */
- errno = 0;
- if ((read_fn == NULL) &&
- /* Check header magic. */
- (header[0] == 0x1f && header[1] == 0x8b)) {
- gzfile = BLI_gzopen(filepath, "rb");
- if (gzfile == (gzFile)Z_NULL) {
- BKE_reportf(reports->reports,
- RPT_WARNING,
- "Unable to open '%s': %s",
- filepath,
- errno ? strerror(errno) : TIP_("unknown error reading file"));
- return NULL;
+ else if (BLI_file_magic_is_gzip(header)) {
+ file = BLI_filereader_new_gzip(rawfile);
+ if (file != NULL) {
+ rawfile = NULL; /* The Gzip FileReader takes ownership of `rawfile`. */
+ }
+ }
+ else if (BLI_file_magic_is_zstd(header)) {
+ file = BLI_filereader_new_zstd(rawfile);
+ if (file != NULL) {
+ rawfile = NULL; /* The Zstd FileReader takes ownership of `rawfile`. */
}
-
- /* 'seek_fn' is too slow for gzip, don't set it. */
- read_fn = fd_read_gzip_from_file;
- /* Caller must close. */
- file = -1;
}
- if (read_fn == NULL) {
+ /* Clean up `rawfile` if it wasn't taken over. */
+ if (rawfile != NULL) {
+ rawfile->close(rawfile);
+ }
+ if (file == NULL) {
BKE_reportf(reports->reports, RPT_WARNING, "Unrecognized file format '%s'", filepath);
return NULL;
}
FileData *fd = filedata_new(reports);
-
- fd->filedes = file;
- fd->gzfiledes = gzfile;
-
- fd->read = read_fn;
- fd->seek = seek_fn;
- fd->mmap_file = mmap_file;
- fd->buffersize = buffersize;
+ fd->file = file;
return fd;
}
@@ -1475,11 +1267,7 @@ static FileData *blo_filedata_from_file_open(const char *filepath, BlendFileRead
errno ? strerror(errno) : TIP_("unknown error reading file"));
return NULL;
}
- FileData *fd = blo_filedata_from_file_descriptor(filepath, reports, file);
- if ((fd == NULL) || (fd->filedes == -1)) {
- close(file);
- }
- return fd;
+ return blo_filedata_from_file_descriptor(filepath, reports, file);
}
/* cannot be called with relative paths anymore! */
@@ -1513,50 +1301,6 @@ static FileData *blo_filedata_from_file_minimal(const char *filepath)
return NULL;
}
-static ssize_t fd_read_gzip_from_memory(FileData *filedata,
- void *buffer,
- size_t size,
- bool *UNUSED(r_is_memchunck_identical))
-{
- int err;
-
- filedata->strm.next_out = (Bytef *)buffer;
- filedata->strm.avail_out = (uint)size;
-
- /* Inflate another chunk. */
- err = inflate(&filedata->strm, Z_SYNC_FLUSH);
-
- if (err == Z_STREAM_END) {
- return 0;
- }
- if (err != Z_OK) {
- CLOG_ERROR(&LOG, "ZLib error (code %d)", err);
- return 0;
- }
-
- filedata->file_offset += size;
-
- return (ssize_t)size;
-}
-
-static int fd_read_gzip_from_memory_init(FileData *fd)
-{
-
- fd->strm.next_in = (Bytef *)fd->buffer;
- fd->strm.avail_in = fd->buffersize;
- fd->strm.total_out = 0;
- fd->strm.zalloc = Z_NULL;
- fd->strm.zfree = Z_NULL;
-
- if (inflateInit2(&fd->strm, (16 + MAX_WBITS)) != Z_OK) {
- return 0;
- }
-
- fd->read = fd_read_gzip_from_memory;
-
- return 1;
-}
-
FileData *blo_filedata_from_memory(const void *mem, int memsize, BlendFileReadReport *reports)
{
if (!mem || memsize < SIZEOFBLENDERHEADER) {
@@ -1565,24 +1309,24 @@ FileData *blo_filedata_from_memory(const void *mem, int memsize, BlendFileReadRe
return NULL;
}
- FileData *fd = filedata_new(reports);
- const char *cp = mem;
-
- fd->buffer = mem;
- fd->buffersize = memsize;
+ FileReader *mem_file = BLI_filereader_new_memory(mem, memsize);
+ FileReader *file = mem_file;
- /* test if gzip */
- if (cp[0] == 0x1f && cp[1] == 0x8b) {
- if (0 == fd_read_gzip_from_memory_init(fd)) {
- blo_filedata_free(fd);
- return NULL;
- }
+ if (BLI_file_magic_is_gzip(mem)) {
+ file = BLI_filereader_new_gzip(mem_file);
}
- else {
- fd->read = fd_read_from_memory;
+ else if (BLI_file_magic_is_zstd(mem)) {
+ file = BLI_filereader_new_zstd(mem_file);
}
- fd->flags |= FD_FLAGS_NOT_MY_BUFFER;
+ if (file == NULL) {
+ /* Compression initialization failed. */
+ mem_file->close(mem_file);
+ return NULL;
+ }
+
+ FileData *fd = filedata_new(reports);
+ fd->file = file;
return blo_decode_and_check(fd, reports->reports);
}
@@ -1597,11 +1341,9 @@ FileData *blo_filedata_from_memfile(MemFile *memfile,
}
FileData *fd = filedata_new(reports);
- fd->memfile = memfile;
+ fd->file = BLO_memfile_new_filereader(memfile, params->undo_direction);
fd->undo_direction = params->undo_direction;
-
- fd->read = fd_read_from_memfile;
- fd->flags |= FD_FLAGS_NOT_MY_BUFFER;
+ fd->flags |= FD_FLAGS_IS_MEMFILE;
return blo_decode_and_check(fd, reports->reports);
}
@@ -1609,30 +1351,7 @@ FileData *blo_filedata_from_memfile(MemFile *memfile,
void blo_filedata_free(FileData *fd)
{
if (fd) {
- if (fd->filedes != -1) {
- close(fd->filedes);
- }
-
- if (fd->gzfiledes != NULL) {
- gzclose(fd->gzfiledes);
- }
-
- if (fd->strm.next_in) {
- int err = inflateEnd(&fd->strm);
- if (err != Z_OK) {
- CLOG_ERROR(&LOG, "Close gzip stream error (code %d)", err);
- }
- }
-
- if (fd->buffer && !(fd->flags & FD_FLAGS_NOT_MY_BUFFER)) {
- MEM_freeN((void *)fd->buffer);
- fd->buffer = NULL;
- }
-
- if (fd->mmap_file) {
- BLI_mmap_free(fd->mmap_file);
- fd->mmap_file = NULL;
- }
+ fd->file->close(fd->file);
/* Free all BHeadN data blocks */
#ifndef NDEBUG
@@ -1640,7 +1359,7 @@ void blo_filedata_free(FileData *fd)
#else
/* Sanity check we're not keeping memory we don't need. */
LISTBASE_FOREACH_MUTABLE (BHeadN *, new_bhead, &fd->bhead_list) {
- if (fd->seek != NULL && BHEAD_USE_READ_ON_DEMAND(&new_bhead->bhead)) {
+ if (fd->file->seek != NULL && BHEAD_USE_READ_ON_DEMAND(&new_bhead->bhead)) {
BLI_assert(new_bhead->has_data == 0);
}
MEM_freeN(new_bhead);
@@ -2096,7 +1815,7 @@ static void blo_cache_storage_entry_clear_in_old(ID *UNUSED(id),
void blo_cache_storage_init(FileData *fd, Main *bmain)
{
- if (fd->memfile != NULL) {
+ if (fd->flags & FD_FLAGS_IS_MEMFILE) {
BLI_assert(fd->cache_storage == NULL);
fd->cache_storage = MEM_mallocN(sizeof(*fd->cache_storage), __func__);
fd->cache_storage->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
@@ -2261,7 +1980,7 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
* undo since DNA must match. */
static const void *peek_struct_undo(FileData *fd, BHead *bhead)
{
- BLI_assert(fd->memfile != NULL);
+ BLI_assert(fd->flags & FD_FLAGS_IS_MEMFILE);
UNUSED_VARS_NDEBUG(fd);
return (bhead->len) ? (const void *)(bhead + 1) : NULL;
}
@@ -3679,7 +3398,7 @@ static BHead *read_libblock(FileData *fd,
* When datablocks are changed but still exist, we restore them at the old
* address and inherit recalc flags for the dependency graph. */
ID *id_old = NULL;
- if (fd->memfile != NULL) {
+ if (fd->flags & FD_FLAGS_IS_MEMFILE) {
if (read_libblock_undo_restore(fd, main, bhead, tag, &id_old)) {
if (r_id) {
*r_id = id_old;
@@ -3980,13 +3699,14 @@ static void lib_link_all(FileData *fd, Main *bmain)
continue;
}
- if (fd->memfile != NULL && GS(id->name) == ID_WM) {
+ if ((fd->flags & FD_FLAGS_IS_MEMFILE) && GS(id->name) == ID_WM) {
/* No load UI for undo memfiles.
* Only WM currently, SCR needs it still (see below), and so does WS? */
continue;
}
- if (fd->memfile != NULL && do_partial_undo && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) != 0) {
+ if ((fd->flags & FD_FLAGS_IS_MEMFILE) && do_partial_undo &&
+ (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) != 0) {
/* This ID has been re-used from 'old' bmain. Since it was therefore unchanged across
* current undo step, and old IDs re-use their old memory address, we do not need to liblink
* it at all. */
@@ -4165,7 +3885,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
BlendFileData *bfd;
ListBase mainlist = {NULL, NULL};
- if (fd->memfile != NULL) {
+ if (fd->flags & FD_FLAGS_IS_MEMFILE) {
CLOG_INFO(&LOG_UNDO, 2, "UNDO: read step");
}
@@ -4256,7 +3976,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
}
/* do before read_libraries, but skip undo case */
- if (fd->memfile == NULL) {
+ if ((fd->flags & FD_FLAGS_IS_MEMFILE) == 0) {
if ((fd->skip_flags & BLO_READ_SKIP_DATA) == 0) {
do_versions(fd, NULL, bfd->main);
}
@@ -4278,7 +3998,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
fd->reports->duration.libraries = PIL_check_seconds_timer() - fd->reports->duration.libraries;
/* Skip in undo case. */
- if (fd->memfile == NULL) {
+ if ((fd->flags & FD_FLAGS_IS_MEMFILE) == 0) {
/* Note that we can't recompute user-counts at this point in undo case, we play too much with
* IDs from different memory realms, and Main database is not in a fully valid state yet.
*/
@@ -4311,7 +4031,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
/* Now that all our data-blocks are loaded,
* we can re-generate overrides from their references. */
- if (fd->memfile == NULL) {
+ if ((fd->flags & FD_FLAGS_IS_MEMFILE) == 0) {
/* Do not apply in undo case! */
fd->reports->duration.lib_overrides = PIL_check_seconds_timer();
@@ -4391,7 +4111,7 @@ static void sort_bhead_old_map(FileData *fd)
static BHead *find_previous_lib(FileData *fd, BHead *bhead)
{
/* Skip library data-blocks in undo, see comment in read_libblock. */
- if (fd->memfile) {
+ if (fd->flags & FD_FLAGS_IS_MEMFILE) {
return NULL;
}
@@ -5850,7 +5570,7 @@ void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
bool BLO_read_data_is_undo(BlendDataReader *reader)
{
- return reader->fd->memfile != NULL;
+ return (reader->fd->flags & FD_FLAGS_IS_MEMFILE);
}
void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr)
@@ -5870,7 +5590,7 @@ BlendFileReadReport *BLO_read_data_reports(BlendDataReader *reader)
bool BLO_read_lib_is_undo(BlendLibReader *reader)
{
- return reader->fd->memfile != NULL;
+ return (reader->fd->flags & FD_FLAGS_IS_MEMFILE);
}
Main *BLO_read_lib_get_main(BlendLibReader *reader)
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index b04043f9641..beeed8e45ae 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -28,10 +28,10 @@
# include "BLI_winstuff.h"
#endif
+#include "BLI_filereader.h"
#include "DNA_sdna_types.h"
#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h" /* for ReportType */
-#include "zlib.h"
struct BLI_mmap_file;
struct BLOCacheStorage;
@@ -50,7 +50,7 @@ enum eFileDataFlag {
FD_FLAGS_FILE_POINTSIZE_IS_4 = 1 << 1,
FD_FLAGS_POINTSIZE_DIFFERS = 1 << 2,
FD_FLAGS_FILE_OK = 1 << 3,
- FD_FLAGS_NOT_MY_BUFFER = 1 << 4,
+ FD_FLAGS_IS_MEMFILE = 1 << 4,
/* XXX Unused in practice (checked once but never set). */
FD_FLAGS_NOT_MY_LIBMAP = 1 << 5,
};
@@ -60,44 +60,18 @@ enum eFileDataFlag {
# pragma GCC poison off_t
#endif
-#if defined(_MSC_VER) || defined(__APPLE__) || defined(__HAIKU__) || defined(__NetBSD__)
-typedef int64_t off64_t;
-#endif
-
-typedef ssize_t(FileDataReadFn)(struct FileData *filedata,
- void *buffer,
- size_t size,
- bool *r_is_memchunk_identical);
-typedef off64_t(FileDataSeekFn)(struct FileData *filedata, off64_t offset, int whence);
-
typedef struct FileData {
/** Linked list of BHeadN's. */
ListBase bhead_list;
enum eFileDataFlag flags;
bool is_eof;
- size_t buffersize;
- off64_t file_offset;
- FileDataReadFn *read;
- FileDataSeekFn *seek;
+ FileReader *file;
- /** Regular file reading. */
- int filedes;
-
- /** Variables needed for reading from memory / stream / memory-mapped files. */
- const char *buffer;
- struct BLI_mmap_file *mmap_file;
- /** Variables needed for reading from memfile (undo). */
- struct MemFile *memfile;
/** Whether we are undoing (< 0) or redoing (> 0), used to choose which 'unchanged' flag to use
* to detect unchanged data from memfile. */
int undo_direction; /* eUndoStepDir */
- /** Variables needed for reading from file. */
- gzFile gzfiledes;
- /** Gzip stream for memory decompression. */
- z_stream strm;
-
/** Now only in use for library appending. */
char relabase[FILE_MAX];
diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c
index 2eeeac2e8d7..62072cf7df5 100644
--- a/source/blender/blenloader/intern/undofile.c
+++ b/source/blender/blenloader/intern/undofile.c
@@ -48,6 +48,7 @@
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_undo_system.h"
/* keep last */
#include "BLI_strict_flags.h"
@@ -273,3 +274,97 @@ bool BLO_memfile_write_file(struct MemFile *memfile, const char *filename)
}
return true;
}
+
+static ssize_t undo_read(FileReader *reader, void *buffer, size_t size)
+{
+ UndoReader *undo = (UndoReader *)reader;
+
+ static size_t seek = SIZE_MAX; /* The current position. */
+ static size_t offset = 0; /* Size of previous chunks. */
+ static MemFileChunk *chunk = NULL;
+ size_t chunkoffset, readsize, totread;
+
+ undo->memchunk_identical = true;
+
+ if (size == 0) {
+ return 0;
+ }
+
+ if (seek != (size_t)undo->reader.offset) {
+ chunk = undo->memfile->chunks.first;
+ seek = 0;
+
+ while (chunk) {
+ if (seek + chunk->size > (size_t)undo->reader.offset) {
+ break;
+ }
+ seek += chunk->size;
+ chunk = chunk->next;
+ }
+ offset = seek;
+ seek = (size_t)undo->reader.offset;
+ }
+
+ if (chunk) {
+ totread = 0;
+
+ do {
+ /* First check if it's on the end if current chunk. */
+ if (seek - offset == chunk->size) {
+ offset += chunk->size;
+ chunk = chunk->next;
+ }
+
+ /* Debug, should never happen. */
+ if (chunk == NULL) {
+ printf("illegal read, chunk zero\n");
+ return 0;
+ }
+
+ chunkoffset = seek - offset;
+ readsize = size - totread;
+
+ /* Data can be spread over multiple chunks, so clamp size
+ * to within this chunk, and then it will read further in
+ * the next chunk. */
+ if (chunkoffset + readsize > chunk->size) {
+ readsize = chunk->size - chunkoffset;
+ }
+
+ memcpy(POINTER_OFFSET(buffer, totread), chunk->buf + chunkoffset, readsize);
+ totread += readsize;
+ undo->reader.offset += (off64_t)readsize;
+ seek += readsize;
+
+ /* `is_identical` of current chunk represents whether it changed compared to previous undo
+ * step. this is fine in redo case, but not in undo case, where we need an extra flag
+ * defined when saving the next (future) step after the one we want to restore, as we are
+ * supposed to 'come from' that future undo step, and not the one before current one. */
+ undo->memchunk_identical &= undo->undo_direction == STEP_REDO ? chunk->is_identical :
+ chunk->is_identical_future;
+ } while (totread < size);
+
+ return (ssize_t)totread;
+ }
+
+ return 0;
+}
+
+static void undo_close(FileReader *reader)
+{
+ MEM_freeN(reader);
+}
+
+FileReader *BLO_memfile_new_filereader(MemFile *memfile, int undo_direction)
+{
+ UndoReader *undo = MEM_callocN(sizeof(UndoReader), __func__);
+
+ undo->memfile = memfile;
+ undo->undo_direction = undo_direction;
+
+ undo->reader.read = undo_read;
+ undo->reader.seek = NULL;
+ undo->reader.close = undo_close;
+
+ return (FileReader *)undo;
+}
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index e56c1995363..436645c2241 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -23,8 +23,7 @@
#else
# include "BLI_winstuff.h"
# include "winsock2.h"
-# include <io.h> /* for open close read */
-# include <zlib.h> /* odd include order-issue */
+# include <io.h> /* for open close read */
#endif
/* allow readfile to use deprecated functionality */
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index a9816ede88b..5b9cdc8c44f 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -26,6 +26,7 @@
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
+#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -979,18 +980,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
- /**
- * Versioning code until next subversion bump goes here.
- *
- * \note Be sure to check when bumping the version:
- * - "versioning_userdef.c", #blo_do_versions_userdef
- * - "versioning_userdef.c", #do_versions_theme
- *
- * \note Keep this message at the bottom of the function.
- */
- {
- /* Keep this block, even when empty. */
-
+ if (!MAIN_VERSION_ATLEAST(bmain, 300, 18)) {
if (!DNA_struct_elem_find(
fd->filesdna, "WorkSpace", "AssetLibraryReference", "asset_library_ref")) {
LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
@@ -1016,5 +1006,58 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
+
+ /* Previously, only text ending with `.py` would run, apply this logic
+ * to existing files so text that happens to have the "Register" enabled
+ * doesn't suddenly start running code on startup that was previously ignored. */
+ LISTBASE_FOREACH (Text *, text, &bmain->texts) {
+ if ((text->flags & TXT_ISSCRIPT) && !BLI_path_extension_check(text->id.name + 2, ".py")) {
+ text->flags &= ~TXT_ISSCRIPT;
+ }
+ }
+ }
+
+ /**
+ * Versioning code until next subversion bump goes here.
+ *
+ * \note Be sure to check when bumping the version:
+ * - "versioning_userdef.c", #blo_do_versions_userdef
+ * - "versioning_userdef.c", #do_versions_theme
+ *
+ * \note Keep this message at the bottom of the function.
+ */
+ {
+ /* Keep this block, even when empty. */
+
+ /* Add node storage for subdivision surface node. */
+ FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
+ if (ntree->type == NTREE_GEOMETRY) {
+ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+ if (node->type == GEO_NODE_SUBDIVISION_SURFACE) {
+ if (node->storage == NULL) {
+ NodeGeometrySubdivisionSurface *data = MEM_callocN(
+ sizeof(NodeGeometrySubdivisionSurface), __func__);
+ data->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES;
+ data->boundary_smooth = SUBSURF_BOUNDARY_SMOOTH_ALL;
+ node->storage = data;
+ }
+ }
+ }
+ }
+ }
+ FOREACH_NODETREE_END;
+
+ /* Disable Fade Inactive Overlay by default as it is redundant after introducing flash on mode
+ * transfer. */
+ for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+ LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ v3d->overlay.flag &= ~V3D_OVERLAY_FADE_INACTIVE;
+ }
+ }
+ }
+ }
}
}
diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c
index 81371e1c1ed..6ba27b6ee9e 100644
--- a/source/blender/blenloader/intern/versioning_legacy.c
+++ b/source/blender/blenloader/intern/versioning_legacy.c
@@ -28,8 +28,7 @@
#else
# include "BLI_winstuff.h"
# include "winsock2.h"
-# include <io.h> /* for open close read */
-# include <zlib.h> /* odd include order-issue */
+# include <io.h> /* for open close read */
#endif
/* allow readfile to use deprecated functionality */
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index c409f0a71fc..0042ff29dc2 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -873,13 +873,6 @@ void blo_do_versions_userdef(UserDef *userdef)
}
}
- if (!USER_VERSION_ATLEAST(293, 2)) {
- /* Enable asset browser features by default for alpha testing.
- * BLO_sanitize_experimental_features_userpref_blend() will disable it again for non-alpha
- * builds. */
- userdef->experimental.use_asset_browser = true;
- }
-
if (!USER_VERSION_ATLEAST(293, 12)) {
if (userdef->gizmo_size_navigate_v3d == 0) {
userdef->gizmo_size_navigate_v3d = 80;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 225548f3832..90d58514eb5 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -83,7 +83,6 @@
# include "BLI_winstuff.h"
# include "winsock2.h"
# include <io.h>
-# include <zlib.h> /* odd include order-issue */
#else
# include <unistd.h> /* FreeBSD, for write() and close(). */
#endif
@@ -101,7 +100,12 @@
#include "BLI_bitmap.h"
#include "BLI_blenlib.h"
#include "BLI_endian_defines.h"
+#include "BLI_endian_switch.h"
+#include "BLI_link_utils.h"
+#include "BLI_linklist.h"
+#include "BLI_math_base.h"
#include "BLI_mempool.h"
+#include "BLI_threads.h"
#include "MEM_guardedalloc.h" /* MEM_freeN */
#include "BKE_blender_version.h"
@@ -129,14 +133,21 @@
#include <errno.h>
+#include <zstd.h>
+
/* Make preferences read-only. */
#define U (*((const UserDef *)&U))
/* ********* my write, buffered writing with minimum size chunks ************ */
/* Use optimal allocation since blocks of this size are kept in memory for undo. */
-#define MYWRITE_BUFFER_SIZE (MEM_SIZE_OPTIMAL(1 << 17)) /* 128kb */
-#define MYWRITE_MAX_CHUNK (MEM_SIZE_OPTIMAL(1 << 15)) /* ~32kb */
+#define MEM_BUFFER_SIZE (MEM_SIZE_OPTIMAL(1 << 17)) /* 128kb */
+#define MEM_CHUNK_SIZE (MEM_SIZE_OPTIMAL(1 << 15)) /* ~32kb */
+
+#define ZSTD_BUFFER_SIZE (1 << 21) /* 2mb */
+#define ZSTD_CHUNK_SIZE (1 << 20) /* 1mb */
+
+#define ZSTD_COMPRESSION_LEVEL 3
/** Use if we want to store how many bytes have been written to the file. */
// #define USE_WRITE_DATA_LEN
@@ -147,9 +158,16 @@
typedef enum {
WW_WRAP_NONE = 1,
- WW_WRAP_ZLIB,
+ WW_WRAP_ZSTD,
} eWriteWrapType;
+typedef struct ZstdFrame {
+ struct ZstdFrame *next, *prev;
+
+ uint32_t compressed_size;
+ uint32_t uncompressed_size;
+} ZstdFrame;
+
typedef struct WriteWrap WriteWrap;
struct WriteWrap {
/* callbacks */
@@ -161,15 +179,23 @@ struct WriteWrap {
bool use_buf;
/* internal */
- union {
- int file_handle;
- gzFile gz_handle;
- } _user_data;
+ int file_handle;
+ struct {
+ ListBase threadpool;
+ ListBase tasks;
+ ThreadMutex mutex;
+ ThreadCondition condition;
+ int next_frame;
+ int num_frames;
+
+ int level;
+ ListBase frames;
+
+ bool write_error;
+ } zstd;
};
/* none */
-#define FILE_HANDLE(ww) (ww)->_user_data.file_handle
-
static bool ww_open_none(WriteWrap *ww, const char *filepath)
{
int file;
@@ -177,7 +203,7 @@ static bool ww_open_none(WriteWrap *ww, const char *filepath)
file = BLI_open(filepath, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file != -1) {
- FILE_HANDLE(ww) = file;
+ ww->file_handle = file;
return true;
}
@@ -185,39 +211,170 @@ static bool ww_open_none(WriteWrap *ww, const char *filepath)
}
static bool ww_close_none(WriteWrap *ww)
{
- return (close(FILE_HANDLE(ww)) != -1);
+ return (close(ww->file_handle) != -1);
}
static size_t ww_write_none(WriteWrap *ww, const char *buf, size_t buf_len)
{
- return write(FILE_HANDLE(ww), buf, buf_len);
+ return write(ww->file_handle, buf, buf_len);
}
-#undef FILE_HANDLE
-/* zlib */
-#define FILE_HANDLE(ww) (ww)->_user_data.gz_handle
+/* zstd */
-static bool ww_open_zlib(WriteWrap *ww, const char *filepath)
+typedef struct {
+ struct ZstdWriteBlockTask *next, *prev;
+ void *data;
+ size_t size;
+ int frame_number;
+ WriteWrap *ww;
+} ZstdWriteBlockTask;
+
+static void *zstd_write_task(void *userdata)
{
- gzFile file;
+ ZstdWriteBlockTask *task = userdata;
+ WriteWrap *ww = task->ww;
- file = BLI_gzopen(filepath, "wb1");
+ size_t out_buf_len = ZSTD_compressBound(task->size);
+ void *out_buf = MEM_mallocN(out_buf_len, "Zstd out buffer");
+ size_t out_size = ZSTD_compress(
+ out_buf, out_buf_len, task->data, task->size, ZSTD_COMPRESSION_LEVEL);
- if (file != Z_NULL) {
- FILE_HANDLE(ww) = file;
- return true;
+ MEM_freeN(task->data);
+
+ BLI_mutex_lock(&ww->zstd.mutex);
+
+ while (ww->zstd.next_frame != task->frame_number) {
+ BLI_condition_wait(&ww->zstd.condition, &ww->zstd.mutex);
}
- return false;
+ if (ZSTD_isError(out_size)) {
+ ww->zstd.write_error = true;
+ }
+ else {
+ if (ww_write_none(ww, out_buf, out_size) == out_size) {
+ ZstdFrame *frameinfo = MEM_mallocN(sizeof(ZstdFrame), "zstd frameinfo");
+ frameinfo->uncompressed_size = task->size;
+ frameinfo->compressed_size = out_size;
+ BLI_addtail(&ww->zstd.frames, frameinfo);
+ }
+ else {
+ ww->zstd.write_error = true;
+ }
+ }
+
+ ww->zstd.next_frame++;
+
+ BLI_mutex_unlock(&ww->zstd.mutex);
+ BLI_condition_notify_all(&ww->zstd.condition);
+
+ MEM_freeN(out_buf);
+ return NULL;
+}
+
+static bool ww_open_zstd(WriteWrap *ww, const char *filepath)
+{
+ if (!ww_open_none(ww, filepath)) {
+ return false;
+ }
+
+ /* Leave one thread open for the main writing logic, unless we only have one HW thread. */
+ int num_threads = max_ii(1, BLI_system_thread_count() - 1);
+ BLI_threadpool_init(&ww->zstd.threadpool, zstd_write_task, num_threads);
+ BLI_mutex_init(&ww->zstd.mutex);
+ BLI_condition_init(&ww->zstd.condition);
+
+ return true;
+}
+
+static void zstd_write_u32_le(WriteWrap *ww, uint32_t val)
+{
+#ifdef __BIG_ENDIAN__
+ BLI_endian_switch_uint32(&val);
+#endif
+ ww_write_none(ww, (char *)&val, sizeof(uint32_t));
}
-static bool ww_close_zlib(WriteWrap *ww)
+
+/* In order to implement efficient seeking when reading the .blend, we append
+ * a skippable frame that encodes information about the other frames present
+ * in the file.
+ * The format here follows the upstream spec for seekable files:
+ * https://github.com/facebook/zstd/blob/master/contrib/seekable_format/zstd_seekable_compression_format.md
+ * If this information is not present in a file (e.g. if it was compressed
+ * with external tools), it can still be opened in Blender, but seeking will
+ * not be supported, so more memory might be needed. */
+static void zstd_write_seekable_frames(WriteWrap *ww)
{
- return (gzclose(FILE_HANDLE(ww)) == Z_OK);
+ /* Write seek table header (magic number and frame size). */
+ zstd_write_u32_le(ww, 0x184D2A5E);
+
+ /* The actual frame number might not match ww->zstd.num_frames if there was a write error. */
+ const uint32_t num_frames = BLI_listbase_count(&ww->zstd.frames);
+ /* Each frame consists of two u32, so 8 bytes each.
+ * After the frames, a footer containing two u32 and one byte (9 bytes total) is written. */
+ const uint32_t frame_size = num_frames * 8 + 9;
+ zstd_write_u32_le(ww, frame_size);
+
+ /* Write seek table entries. */
+ LISTBASE_FOREACH (ZstdFrame *, frame, &ww->zstd.frames) {
+ zstd_write_u32_le(ww, frame->compressed_size);
+ zstd_write_u32_le(ww, frame->uncompressed_size);
+ }
+
+ /* Write seek table footer (number of frames, option flags and second magic number). */
+ zstd_write_u32_le(ww, num_frames);
+ const char flags = 0; /* We don't store checksums for each frame. */
+ ww_write_none(ww, &flags, 1);
+ zstd_write_u32_le(ww, 0x8F92EAB1);
}
-static size_t ww_write_zlib(WriteWrap *ww, const char *buf, size_t buf_len)
+
+static bool ww_close_zstd(WriteWrap *ww)
{
- return gzwrite(FILE_HANDLE(ww), buf, buf_len);
+ BLI_threadpool_end(&ww->zstd.threadpool);
+ BLI_freelistN(&ww->zstd.tasks);
+
+ BLI_mutex_end(&ww->zstd.mutex);
+ BLI_condition_end(&ww->zstd.condition);
+
+ zstd_write_seekable_frames(ww);
+ BLI_freelistN(&ww->zstd.frames);
+
+ return ww_close_none(ww) && !ww->zstd.write_error;
+}
+
+static size_t ww_write_zstd(WriteWrap *ww, const char *buf, size_t buf_len)
+{
+ if (ww->zstd.write_error) {
+ return 0;
+ }
+
+ ZstdWriteBlockTask *task = MEM_mallocN(sizeof(ZstdWriteBlockTask), __func__);
+ task->data = MEM_mallocN(buf_len, __func__);
+ memcpy(task->data, buf, buf_len);
+ task->size = buf_len;
+ task->frame_number = ww->zstd.num_frames++;
+ task->ww = ww;
+
+ BLI_mutex_lock(&ww->zstd.mutex);
+ BLI_addtail(&ww->zstd.tasks, task);
+
+ /* If there's a free worker thread, just push the block into that thread.
+ * Otherwise, we wait for the earliest thread to finish.
+ * We look up the earliest thread while holding the mutex, but release it
+ * before joining the thread to prevent a deadlock. */
+ ZstdWriteBlockTask *first_task = ww->zstd.tasks.first;
+ BLI_mutex_unlock(&ww->zstd.mutex);
+ if (!BLI_available_threads(&ww->zstd.threadpool)) {
+ BLI_threadpool_remove(&ww->zstd.threadpool, first_task);
+
+ /* If the task list was empty before we pushed our task, there should
+ * always be a free thread. */
+ BLI_assert(first_task != task);
+ BLI_remlink(&ww->zstd.tasks, first_task);
+ MEM_freeN(first_task);
+ }
+ BLI_threadpool_insert(&ww->zstd.threadpool, task);
+
+ return buf_len;
}
-#undef FILE_HANDLE
/* --- end compression types --- */
@@ -226,11 +383,11 @@ static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
memset(r_ww, 0, sizeof(*r_ww));
switch (ww_type) {
- case WW_WRAP_ZLIB: {
- r_ww->open = ww_open_zlib;
- r_ww->close = ww_close_zlib;
- r_ww->write = ww_write_zlib;
- r_ww->use_buf = false;
+ case WW_WRAP_ZSTD: {
+ r_ww->open = ww_open_zstd;
+ r_ww->close = ww_close_zstd;
+ r_ww->write = ww_write_zstd;
+ r_ww->use_buf = true;
break;
}
default: {
@@ -252,10 +409,17 @@ static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
typedef struct {
const struct SDNA *sdna;
- /** Use for file and memory writing (fixed size of #MYWRITE_BUFFER_SIZE). */
- uchar *buf;
- /** Number of bytes used in #WriteData.buf (flushed when exceeded). */
- size_t buf_used_len;
+ struct {
+ /** Use for file and memory writing (size stored in max_size). */
+ uchar *buf;
+ /** Number of bytes used in #WriteData.buf (flushed when exceeded). */
+ size_t used_len;
+
+ /** Maximum size of the buffer. */
+ size_t max_size;
+ /** Threshold above which writes get their own chunk. */
+ size_t chunk_size;
+ } buffer;
#ifdef USE_WRITE_DATA_LEN
/** Total number of bytes written. */
@@ -271,7 +435,7 @@ typedef struct {
bool use_memfile;
/**
- * Wrap writing, so we can use zlib or
+ * Wrap writing, so we can use zstd or
* other compression types later, see: G_FILE_COMPRESS
* Will be NULL for UNDO.
*/
@@ -291,7 +455,15 @@ static WriteData *writedata_new(WriteWrap *ww)
wd->ww = ww;
if ((ww == NULL) || (ww->use_buf)) {
- wd->buf = MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf");
+ if (ww == NULL) {
+ wd->buffer.max_size = MEM_BUFFER_SIZE;
+ wd->buffer.chunk_size = MEM_CHUNK_SIZE;
+ }
+ else {
+ wd->buffer.max_size = ZSTD_BUFFER_SIZE;
+ wd->buffer.chunk_size = ZSTD_CHUNK_SIZE;
+ }
+ wd->buffer.buf = MEM_mallocN(wd->buffer.max_size, "wd->buffer.buf");
}
return wd;
@@ -325,8 +497,8 @@ static void writedata_do_write(WriteData *wd, const void *mem, size_t memlen)
static void writedata_free(WriteData *wd)
{
- if (wd->buf) {
- MEM_freeN(wd->buf);
+ if (wd->buffer.buf) {
+ MEM_freeN(wd->buffer.buf);
}
MEM_freeN(wd);
}
@@ -343,9 +515,9 @@ static void writedata_free(WriteData *wd)
*/
static void mywrite_flush(WriteData *wd)
{
- if (wd->buf_used_len != 0) {
- writedata_do_write(wd, wd->buf, wd->buf_used_len);
- wd->buf_used_len = 0;
+ if (wd->buffer.used_len != 0) {
+ writedata_do_write(wd, wd->buffer.buf, wd->buffer.used_len);
+ wd->buffer.used_len = 0;
}
}
@@ -369,20 +541,20 @@ static void mywrite(WriteData *wd, const void *adr, size_t len)
wd->write_len += len;
#endif
- if (wd->buf == NULL) {
+ if (wd->buffer.buf == NULL) {
writedata_do_write(wd, adr, len);
}
else {
/* if we have a single big chunk, write existing data in
* buffer and write out big chunk in smaller pieces */
- if (len > MYWRITE_MAX_CHUNK) {
- if (wd->buf_used_len != 0) {
- writedata_do_write(wd, wd->buf, wd->buf_used_len);
- wd->buf_used_len = 0;
+ if (len > wd->buffer.chunk_size) {
+ if (wd->buffer.used_len != 0) {
+ writedata_do_write(wd, wd->buffer.buf, wd->buffer.used_len);
+ wd->buffer.used_len = 0;
}
do {
- size_t writelen = MIN2(len, MYWRITE_MAX_CHUNK);
+ size_t writelen = MIN2(len, wd->buffer.chunk_size);
writedata_do_write(wd, adr, writelen);
adr = (const char *)adr + writelen;
len -= writelen;
@@ -392,14 +564,14 @@ static void mywrite(WriteData *wd, const void *adr, size_t len)
}
/* if data would overflow buffer, write out the buffer */
- if (len + wd->buf_used_len > MYWRITE_BUFFER_SIZE - 1) {
- writedata_do_write(wd, wd->buf, wd->buf_used_len);
- wd->buf_used_len = 0;
+ if (len + wd->buffer.used_len > wd->buffer.max_size - 1) {
+ writedata_do_write(wd, wd->buffer.buf, wd->buffer.used_len);
+ wd->buffer.used_len = 0;
}
/* append data at end of buffer */
- memcpy(&wd->buf[wd->buf_used_len], adr, len);
- wd->buf_used_len += len;
+ memcpy(&wd->buffer.buf[wd->buffer.used_len], adr, len);
+ wd->buffer.used_len += len;
}
}
@@ -430,9 +602,9 @@ static WriteData *mywrite_begin(WriteWrap *ww, MemFile *compare, MemFile *curren
*/
static bool mywrite_end(WriteData *wd)
{
- if (wd->buf_used_len != 0) {
- writedata_do_write(wd, wd->buf, wd->buf_used_len);
- wd->buf_used_len = 0;
+ if (wd->buffer.used_len != 0) {
+ writedata_do_write(wd, wd->buffer.buf, wd->buffer.used_len);
+ wd->buffer.used_len = 0;
}
if (wd->use_memfile) {
@@ -982,6 +1154,14 @@ static bool write_file_handle(Main *mainvar,
BLI_assert(
(id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
+ /* We only write unused IDs in undo case.
+ * NOTE: All Scenes, WindowManagers and WorkSpaces should always be written to disk, so
+ * their usercount should never be NULL currently. */
+ if (id->us == 0 && !wd->use_memfile) {
+ BLI_assert(!ELEM(GS(id->name), ID_SCE, ID_WM, ID_WS));
+ continue;
+ }
+
const bool do_override = !ELEM(override_storage, NULL, bmain) &&
ID_IS_OVERRIDE_LIBRARY_REAL(id);
@@ -1015,12 +1195,23 @@ static bool write_file_handle(Main *mainvar,
memcpy(id_buffer, id, idtype_struct_size);
+ /* Clear runtime data to reduce false detection of changed data in undo/redo context. */
((ID *)id_buffer)->tag = 0;
+ ((ID *)id_buffer)->us = 0;
+ ((ID *)id_buffer)->icon_id = 0;
/* Those listbase data change every time we add/remove an ID, and also often when
* renaming one (due to re-sorting). This avoids generating a lot of false 'is changed'
* detections between undo steps. */
((ID *)id_buffer)->prev = NULL;
((ID *)id_buffer)->next = NULL;
+ /* Those runtime pointers should never be set during writing stage, but just in case clear
+ * them too. */
+ ((ID *)id_buffer)->orig_id = NULL;
+ ((ID *)id_buffer)->newid = NULL;
+ /* Even though in theory we could be able to preserve this python instance across undo even
+ * when we need to re-read the ID into its original address, this is currently cleared in
+ * #direct_link_id_common in `readfile.c` anyway, */
+ ((ID *)id_buffer)->py_instance = NULL;
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
if (id_type->blend_write != NULL) {
@@ -1131,7 +1322,6 @@ bool BLO_write_file(Main *mainvar,
ReportList *reports)
{
char tempname[FILE_MAX + 1];
- eWriteWrapType ww_type;
WriteWrap ww;
eBLO_WritePathRemap remap_mode = params->remap_mode;
@@ -1153,14 +1343,7 @@ bool BLO_write_file(Main *mainvar,
/* open temporary file, so we preserve the original in case we crash */
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
- if (write_flags & G_FILE_COMPRESS) {
- ww_type = WW_WRAP_ZLIB;
- }
- else {
- ww_type = WW_WRAP_NONE;
- }
-
- ww_handle_init(ww_type, &ww);
+ ww_handle_init((write_flags & G_FILE_COMPRESS) ? WW_WRAP_ZSTD : WW_WRAP_NONE, &ww);
if (ww.open(&ww, tempname) == false) {
BKE_reportf(
diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.c b/source/blender/bmesh/intern/bmesh_mesh_normals.c
index a5e41b74ee1..186c85abe58 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_normals.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_normals.c
@@ -85,10 +85,9 @@ BLI_INLINE void bm_vert_calc_normals_accum_loop(const BMLoop *l_iter,
dotprod = -dotprod;
}
const float fac = saacos(-dotprod);
- /* NAN detection, otherwise this is a degenerated case, ignore that vertex in this case. */
- if (fac == fac) {
- madd_v3_v3fl(v_no, f_no, fac);
- }
+ /* Shouldn't happen as normalizing edge-vectors cause degenerate values to be zeroed out. */
+ BLI_assert(!isnan(fac));
+ madd_v3_v3fl(v_no, f_no, fac);
}
static void bm_vert_calc_normals_impl(BMVert *v)
diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c
index 8cc0bfadbda..57760900d45 100644
--- a/source/blender/bmesh/operators/bmo_removedoubles.c
+++ b/source/blender/bmesh/operators/bmo_removedoubles.c
@@ -327,7 +327,6 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
}
#define VERT_KEEP 8
-#define VERT_IN 32
#define EDGE_MARK 1
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index ee287c65fe9..8ddcf11602a 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -328,10 +328,14 @@ set(SRC
operations/COM_FastGaussianBlurOperation.h
operations/COM_GammaCorrectOperation.cc
operations/COM_GammaCorrectOperation.h
+ operations/COM_GaussianAlphaBlurBaseOperation.cc
+ operations/COM_GaussianAlphaBlurBaseOperation.h
operations/COM_GaussianAlphaXBlurOperation.cc
operations/COM_GaussianAlphaXBlurOperation.h
operations/COM_GaussianAlphaYBlurOperation.cc
operations/COM_GaussianAlphaYBlurOperation.h
+ operations/COM_GaussianBlurBaseOperation.cc
+ operations/COM_GaussianBlurBaseOperation.h
operations/COM_GaussianBokehBlurOperation.cc
operations/COM_GaussianBokehBlurOperation.h
operations/COM_GaussianXBlurOperation.cc
@@ -515,6 +519,8 @@ set(SRC
operations/COM_ScaleOperation.h
operations/COM_ScreenLensDistortionOperation.cc
operations/COM_ScreenLensDistortionOperation.h
+ operations/COM_TransformOperation.cc
+ operations/COM_TransformOperation.h
operations/COM_TranslateOperation.cc
operations/COM_TranslateOperation.h
operations/COM_WrapOperation.cc
diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h
index 900f29db44c..e270eeb3386 100644
--- a/source/blender/compositor/COM_defines.h
+++ b/source/blender/compositor/COM_defines.h
@@ -33,6 +33,8 @@ enum class eExecutionModel {
FullFrame
};
+enum class eDimension { X, Y };
+
/**
* \brief possible data types for sockets
* \ingroup Model
@@ -62,12 +64,18 @@ constexpr int COM_data_type_num_channels(const DataType datatype)
}
}
+constexpr int COM_data_type_bytes_len(DataType data_type)
+{
+ return COM_data_type_num_channels(data_type) * sizeof(float);
+}
+
constexpr int COM_DATA_TYPE_VALUE_CHANNELS = COM_data_type_num_channels(DataType::Value);
constexpr int COM_DATA_TYPE_VECTOR_CHANNELS = COM_data_type_num_channels(DataType::Vector);
constexpr int COM_DATA_TYPE_COLOR_CHANNELS = COM_data_type_num_channels(DataType::Color);
constexpr float COM_COLOR_TRANSPARENT[4] = {0.0f, 0.0f, 0.0f, 0.0f};
constexpr float COM_VECTOR_ZERO[3] = {0.0f, 0.0f, 0.0f};
+constexpr float COM_COLOR_BLACK[4] = {0.0f, 0.0f, 0.0f, 1.0f};
constexpr float COM_VALUE_ZERO[1] = {0.0f};
constexpr float COM_VALUE_ONE[1] = {1.0f};
@@ -113,6 +121,8 @@ constexpr float COM_PREVIEW_SIZE = 140.f;
constexpr float COM_RULE_OF_THIRDS_DIVIDER = 100.0f;
constexpr float COM_BLUR_BOKEH_PIXELS = 512;
+constexpr rcti COM_SINGLE_ELEM_AREA = {0, 1, 0, 1};
+
constexpr IndexRange XRange(const rcti &area)
{
return IndexRange(area.xmin, area.xmax - area.xmin);
diff --git a/source/blender/compositor/intern/COM_BufferOperation.cc b/source/blender/compositor/intern/COM_BufferOperation.cc
index 90c97f2a9c7..cafdff89c8e 100644
--- a/source/blender/compositor/intern/COM_BufferOperation.cc
+++ b/source/blender/compositor/intern/COM_BufferOperation.cc
@@ -32,6 +32,7 @@ BufferOperation::BufferOperation(MemoryBuffer *buffer, DataType data_type)
setResolution(resolution);
addOutputSocket(data_type);
flags.is_constant_operation = buffer_->is_a_single_elem();
+ flags.is_fullframe_operation = false;
}
const float *BufferOperation::get_constant_elem()
@@ -40,20 +41,32 @@ const float *BufferOperation::get_constant_elem()
return buffer_->getBuffer();
}
+void BufferOperation::initExecution()
+{
+ if (buffer_->is_a_single_elem()) {
+ initMutex();
+ }
+}
+
void *BufferOperation::initializeTileData(rcti * /*rect*/)
{
if (buffer_->is_a_single_elem() == false) {
return buffer_;
}
+ lockMutex();
if (!inflated_buffer_) {
inflated_buffer_ = buffer_->inflate();
}
+ unlockMutex();
return inflated_buffer_;
}
void BufferOperation::deinitExecution()
{
+ if (buffer_->is_a_single_elem()) {
+ deinitMutex();
+ }
delete inflated_buffer_;
}
diff --git a/source/blender/compositor/intern/COM_BufferOperation.h b/source/blender/compositor/intern/COM_BufferOperation.h
index 705264c37b7..b4cbc0a56b6 100644
--- a/source/blender/compositor/intern/COM_BufferOperation.h
+++ b/source/blender/compositor/intern/COM_BufferOperation.h
@@ -32,6 +32,7 @@ class BufferOperation : public ConstantOperation {
const float *get_constant_elem() override;
void *initializeTileData(rcti *rect) override;
+ void initExecution() override;
void deinitExecution() override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
void executePixelFiltered(float output[4], float x, float y, float dx[2], float dy[2]) override;
diff --git a/source/blender/compositor/intern/COM_CompositorContext.h b/source/blender/compositor/intern/COM_CompositorContext.h
index 403ec62e359..c6e83f93777 100644
--- a/source/blender/compositor/intern/COM_CompositorContext.h
+++ b/source/blender/compositor/intern/COM_CompositorContext.h
@@ -239,6 +239,12 @@ class CompositorContext {
this->m_hasActiveOpenCLDevices = hasAvtiveOpenCLDevices;
}
+ /** Whether it has a view with a specific name and not the default one. */
+ bool has_explicit_view() const
+ {
+ return m_viewName && m_viewName[0] != '\0';
+ }
+
/**
* \brief get the active rendering view
*/
diff --git a/source/blender/compositor/intern/COM_ConstantFolder.cc b/source/blender/compositor/intern/COM_ConstantFolder.cc
index 5b48ff8fc08..445a9ce7433 100644
--- a/source/blender/compositor/intern/COM_ConstantFolder.cc
+++ b/source/blender/compositor/intern/COM_ConstantFolder.cc
@@ -44,7 +44,9 @@ static bool is_constant_foldable(NodeOperation *operation)
{
if (operation->get_flags().can_be_constant && !operation->get_flags().is_constant_operation) {
for (int i = 0; i < operation->getNumberOfInputSockets(); i++) {
- if (!operation->get_input_operation(i)->get_flags().is_constant_operation) {
+ NodeOperation *input = operation->get_input_operation(i);
+ if (!input->get_flags().is_constant_operation ||
+ !static_cast<ConstantOperation *>(input)->can_get_constant_elem()) {
return false;
}
}
diff --git a/source/blender/compositor/intern/COM_Debug.cc b/source/blender/compositor/intern/COM_Debug.cc
index 5443974cbb0..a0333cf96cf 100644
--- a/source/blender/compositor/intern/COM_Debug.cc
+++ b/source/blender/compositor/intern/COM_Debug.cc
@@ -178,21 +178,27 @@ int DebugInfo::graphviz_operation(const ExecutionSystem *system,
}
len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "<OUT_%p>", socket);
switch (socket->getDataType()) {
- case DataType::Value:
- if (typeid(*operation) == typeid(SetValueOperation)) {
- const float value = ((SetValueOperation *)operation)->getValue();
+ case DataType::Value: {
+ ConstantOperation *constant = operation->get_flags().is_constant_operation ?
+ static_cast<ConstantOperation *>(operation) :
+ nullptr;
+ if (constant && constant->can_get_constant_elem()) {
+ const float value = *constant->get_constant_elem();
len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "Value\\n%12.4g", value);
}
else {
len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "Value");
}
break;
- case DataType::Vector:
+ }
+ case DataType::Vector: {
len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "Vector");
break;
- case DataType::Color:
+ }
+ case DataType::Color: {
len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "Color");
break;
+ }
}
}
len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "}");
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc
index 6b954072a9a..1fbf502fea6 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cc
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc
@@ -245,7 +245,9 @@ void MemoryBuffer::copy_from(const MemoryBuffer *src,
void MemoryBuffer::copy_from(const uchar *src, const rcti &area)
{
- copy_from(src, area, 0, this->get_num_channels(), this->get_num_channels(), 0);
+ const int elem_stride = this->get_num_channels();
+ const int row_stride = elem_stride * getWidth();
+ copy_from(src, area, 0, this->get_num_channels(), elem_stride, row_stride, 0);
}
void MemoryBuffer::copy_from(const uchar *src,
@@ -253,10 +255,18 @@ void MemoryBuffer::copy_from(const uchar *src,
const int channel_offset,
const int elem_size,
const int elem_stride,
+ const int row_stride,
const int to_channel_offset)
{
- copy_from(
- src, area, channel_offset, elem_size, elem_stride, area.xmin, area.ymin, to_channel_offset);
+ copy_from(src,
+ area,
+ channel_offset,
+ elem_size,
+ elem_stride,
+ row_stride,
+ area.xmin,
+ area.ymin,
+ to_channel_offset);
}
void MemoryBuffer::copy_from(const uchar *src,
@@ -264,6 +274,7 @@ void MemoryBuffer::copy_from(const uchar *src,
const int channel_offset,
const int elem_size,
const int elem_stride,
+ const int row_stride,
const int to_x,
const int to_y,
const int to_channel_offset)
@@ -273,10 +284,9 @@ void MemoryBuffer::copy_from(const uchar *src,
const int width = BLI_rcti_size_x(&area);
const int height = BLI_rcti_size_y(&area);
- const int src_row_stride = width * elem_stride;
- const uchar *const src_start = src + area.ymin * src_row_stride + channel_offset;
+ const uchar *const src_start = src + area.ymin * row_stride + channel_offset;
for (int y = 0; y < height; y++) {
- const uchar *from_elem = src_start + y * src_row_stride;
+ const uchar *from_elem = src_start + y * row_stride + area.xmin * elem_stride;
float *to_elem = &this->get_value(to_x, to_y + y, to_channel_offset);
const float *row_end = to_elem + width * this->elem_stride;
while (to_elem < row_end) {
@@ -346,7 +356,16 @@ void MemoryBuffer::copy_from(const ImBuf *src,
else if (src->rect) {
const uchar *uc_buf = (uchar *)src->rect;
const int elem_stride = src->channels;
- copy_from(uc_buf, area, channel_offset, elem_size, elem_stride, to_x, to_y, to_channel_offset);
+ const int row_stride = elem_stride * src->x;
+ copy_from(uc_buf,
+ area,
+ channel_offset,
+ elem_size,
+ elem_stride,
+ row_stride,
+ to_x,
+ to_y,
+ to_channel_offset);
if (ensure_linear_space) {
colorspace_to_scene_linear(this, area, src->rect_colorspace);
}
@@ -405,12 +424,48 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4])
}
}
+static void read_ewa_elem(void *userdata, int x, int y, float result[4])
+{
+ const MemoryBuffer *buffer = static_cast<const MemoryBuffer *>(userdata);
+ buffer->read_elem_checked(x, y, result);
+}
+
+void MemoryBuffer::read_elem_filtered(
+ const float x, const float y, float dx[2], float dy[2], float *out) const
+{
+ BLI_assert(this->m_datatype == DataType::Color);
+
+ const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}};
+
+ float inv_width = 1.0f / (float)this->getWidth(), inv_height = 1.0f / (float)this->getHeight();
+ /* TODO(sergey): Render pipeline uses normalized coordinates and derivatives,
+ * but compositor uses pixel space. For now let's just divide the values and
+ * switch compositor to normalized space for EWA later.
+ */
+ float uv_normal[2] = {get_relative_x(x) * inv_width, get_relative_y(y) * inv_height};
+ float du_normal[2] = {deriv[0][0] * inv_width, deriv[0][1] * inv_height};
+ float dv_normal[2] = {deriv[1][0] * inv_width, deriv[1][1] * inv_height};
+
+ BLI_ewa_filter(this->getWidth(),
+ this->getHeight(),
+ false,
+ true,
+ uv_normal,
+ du_normal,
+ dv_normal,
+ read_ewa_elem,
+ const_cast<MemoryBuffer *>(this),
+ out);
+}
+
+/* TODO(manzanilla): to be removed with tiled implementation. */
static void read_ewa_pixel_sampled(void *userdata, int x, int y, float result[4])
{
MemoryBuffer *buffer = (MemoryBuffer *)userdata;
buffer->read(result, x, y);
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
void MemoryBuffer::readEWA(float *result, const float uv[2], const float derivatives[2][2])
{
if (m_is_a_single_elem) {
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index ae12c444dc1..f3e15c2a495 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -191,23 +191,96 @@ class MemoryBuffer {
void read_elem(int x, int y, float *out) const
{
- memcpy(out, get_elem(x, y), m_num_channels * sizeof(float));
+ memcpy(out, get_elem(x, y), get_elem_bytes_len());
+ }
+
+ void read_elem_checked(int x, int y, float *out) const
+ {
+ if (x < m_rect.xmin || x >= m_rect.xmax || y < m_rect.ymin || y >= m_rect.ymax) {
+ clear_elem(out);
+ }
+ else {
+ read_elem(x, y, out);
+ }
+ }
+
+ void read_elem_checked(float x, float y, float *out) const
+ {
+ if (x < m_rect.xmin || x >= m_rect.xmax || y < m_rect.ymin || y >= m_rect.ymax) {
+ clear_elem(out);
+ }
+ else {
+ read_elem(x, y, out);
+ }
+ }
+
+ void read_elem_bilinear(float x, float y, float *out) const
+ {
+ /* Only clear past +/-1 borders to be able to smooth edges. */
+ if (x <= m_rect.xmin - 1.0f || x >= m_rect.xmax || y <= m_rect.ymin - 1.0f ||
+ y >= m_rect.ymax) {
+ clear_elem(out);
+ return;
+ }
+
+ if (m_is_a_single_elem) {
+ if (x >= m_rect.xmin && x < m_rect.xmax - 1.0f && y >= m_rect.ymin &&
+ y < m_rect.ymax - 1.0f) {
+ memcpy(out, m_buffer, get_elem_bytes_len());
+ return;
+ }
+
+ /* Do sampling at borders to smooth edges. */
+ const float last_x = getWidth() - 1.0f;
+ const float rel_x = get_relative_x(x);
+ float single_x = 0.0f;
+ if (rel_x < 0.0f) {
+ single_x = rel_x;
+ }
+ else if (rel_x > last_x) {
+ single_x = rel_x - last_x;
+ }
+
+ const float last_y = getHeight() - 1.0f;
+ const float rel_y = get_relative_y(y);
+ float single_y = 0.0f;
+ if (rel_y < 0.0f) {
+ single_y = rel_y;
+ }
+ else if (rel_y > last_y) {
+ single_y = rel_y - last_y;
+ }
+
+ BLI_bilinear_interpolation_fl(m_buffer, out, 1, 1, m_num_channels, single_x, single_y);
+ return;
+ }
+
+ BLI_bilinear_interpolation_fl(m_buffer,
+ out,
+ getWidth(),
+ getHeight(),
+ m_num_channels,
+ get_relative_x(x),
+ get_relative_y(y));
}
void read_elem_sampled(float x, float y, PixelSampler sampler, float *out) const
{
switch (sampler) {
case PixelSampler::Nearest:
- this->read_elem(x, y, out);
+ read_elem_checked(x, y, out);
break;
case PixelSampler::Bilinear:
case PixelSampler::Bicubic:
/* No bicubic. Current implementation produces fuzzy results. */
- this->readBilinear(out, x, y);
+ read_elem_bilinear(x, y, out);
break;
}
}
+ void read_elem_filtered(
+ const float x, const float y, float dx[2], float dy[2], float *out) const;
+
/**
* Get channel value at given coordinates.
*/
@@ -260,6 +333,11 @@ class MemoryBuffer {
return this->m_num_channels;
}
+ uint8_t get_elem_bytes_len() const
+ {
+ return this->m_num_channels * sizeof(float);
+ }
+
/**
* Get all buffer elements as a range with no offsets.
*/
@@ -398,6 +476,8 @@ class MemoryBuffer {
y = y + m_rect.ymin;
}
+ /* TODO(manzanilla): to be removed with tiled implementation. For applying #MemoryBufferExtend
+ * use #wrap_pixel. */
inline void read(float *result,
int x,
int y,
@@ -420,6 +500,7 @@ class MemoryBuffer {
}
}
+ /* TODO(manzanilla): to be removed with tiled implementation. */
inline void readNoCheck(float *result,
int x,
int y,
@@ -502,12 +583,14 @@ class MemoryBuffer {
int channel_offset,
int elem_size,
int elem_stride,
+ int row_stride,
int to_channel_offset);
void copy_from(const uchar *src,
const rcti &area,
int channel_offset,
int elem_size,
int elem_stride,
+ int row_stride,
int to_x,
int to_y,
int to_channel_offset);
@@ -577,6 +660,21 @@ class MemoryBuffer {
return get_memory_width() * get_memory_height();
}
+ void clear_elem(float *out) const
+ {
+ memset(out, 0, this->m_num_channels * sizeof(float));
+ }
+
+ template<typename T> T get_relative_x(T x) const
+ {
+ return x - m_rect.xmin;
+ }
+
+ template<typename T> T get_relative_y(T y) const
+ {
+ return y - m_rect.ymin;
+ }
+
void copy_single_elem_from(const MemoryBuffer *src,
int channel_offset,
int elem_size,
diff --git a/source/blender/compositor/intern/COM_NodeGraph.cc b/source/blender/compositor/intern/COM_NodeGraph.cc
index 205fbcc0440..1872fbcf656 100644
--- a/source/blender/compositor/intern/COM_NodeGraph.cc
+++ b/source/blender/compositor/intern/COM_NodeGraph.cc
@@ -248,7 +248,9 @@ void NodeGraph::add_proxies_group_inputs(bNode *b_node, bNode *b_node_io)
}
}
-void NodeGraph::add_proxies_group_outputs(bNode *b_node, bNode *b_node_io, bool use_buffer)
+void NodeGraph::add_proxies_group_outputs(const CompositorContext &context,
+ bNode *b_node,
+ bNode *b_node_io)
{
bNodeTree *b_group_tree = (bNodeTree *)b_node->id;
BLI_assert(b_group_tree); /* should have been checked in advance */
@@ -261,7 +263,8 @@ void NodeGraph::add_proxies_group_outputs(bNode *b_node, bNode *b_node_io, bool
b_sock_io = b_sock_io->next) {
bNodeSocket *b_sock_group = find_b_node_output(b_node, b_sock_io->identifier);
if (b_sock_group) {
- if (use_buffer) {
+ if (context.isGroupnodeBufferEnabled() &&
+ context.get_execution_model() == eExecutionModel::Tiled) {
SocketBufferNode *buffer = new SocketBufferNode(b_node_io, b_sock_io, b_sock_group);
add_node(buffer, b_group_tree, key, is_active_group);
}
@@ -297,7 +300,7 @@ void NodeGraph::add_proxies_group(const CompositorContext &context,
}
if (b_node_io->type == NODE_GROUP_OUTPUT && (b_node_io->flag & NODE_DO_OUTPUT)) {
- add_proxies_group_outputs(b_node, b_node_io, context.isGroupnodeBufferEnabled());
+ add_proxies_group_outputs(context, b_node, b_node_io);
}
}
diff --git a/source/blender/compositor/intern/COM_NodeGraph.h b/source/blender/compositor/intern/COM_NodeGraph.h
index 7fa01593e1e..dfcc6c2fcf9 100644
--- a/source/blender/compositor/intern/COM_NodeGraph.h
+++ b/source/blender/compositor/intern/COM_NodeGraph.h
@@ -107,7 +107,9 @@ class NodeGraph {
bool is_active_group);
void add_proxies_group_inputs(bNode *b_node, bNode *b_node_io);
- void add_proxies_group_outputs(bNode *b_node, bNode *b_node_io, bool use_buffer);
+ void add_proxies_group_outputs(const CompositorContext &context,
+ bNode *b_node,
+ bNode *b_node_io);
void add_proxies_group(const CompositorContext &context, bNode *b_node, bNodeInstanceKey key);
void add_proxies_reroute(bNodeTree *b_ntree,
diff --git a/source/blender/compositor/intern/COM_NodeOperation.cc b/source/blender/compositor/intern/COM_NodeOperation.cc
index 575e8446abe..1b87cdf72fb 100644
--- a/source/blender/compositor/intern/COM_NodeOperation.cc
+++ b/source/blender/compositor/intern/COM_NodeOperation.cc
@@ -82,8 +82,12 @@ void NodeOperation::determineResolution(unsigned int resolution[2],
input.determineResolution(resolution, preferredResolution);
used_resolution_index = m_resolutionInputSocketIndex;
}
- unsigned int temp2[2] = {resolution[0], resolution[1]};
+ if (modify_determined_resolution_fn_) {
+ modify_determined_resolution_fn_(resolution);
+ }
+
+ unsigned int temp2[2] = {resolution[0], resolution[1]};
unsigned int temp[2];
for (unsigned int index = 0; index < m_inputs.size(); index++) {
if (index == used_resolution_index) {
diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h
index 934007d25ce..b402dc7f174 100644
--- a/source/blender/compositor/intern/COM_NodeOperation.h
+++ b/source/blender/compositor/intern/COM_NodeOperation.h
@@ -287,6 +287,8 @@ class NodeOperation {
*/
unsigned int m_resolutionInputSocketIndex;
+ std::function<void(unsigned int resolution[2])> modify_determined_resolution_fn_;
+
/**
* \brief mutex reference for very special node initializations
* \note only use when you really know what you are doing.
@@ -518,6 +520,15 @@ class NodeOperation {
void setResolutionInputSocketIndex(unsigned int index);
/**
+ * Set a custom function to modify determined resolution from main input just before setting it
+ * as preferred resolution for the other inputs.
+ */
+ void set_determined_resolution_modifier(std::function<void(unsigned int resolution[2])> fn)
+ {
+ modify_determined_resolution_fn_ = fn;
+ }
+
+ /**
* \brief get the render priority of this node.
* \note only applicable for output operations like ViewerOperation
* \return eCompositorPriority
diff --git a/source/blender/compositor/intern/COM_TiledExecutionModel.cc b/source/blender/compositor/intern/COM_TiledExecutionModel.cc
index d025ce53330..a081b80349d 100644
--- a/source/blender/compositor/intern/COM_TiledExecutionModel.cc
+++ b/source/blender/compositor/intern/COM_TiledExecutionModel.cc
@@ -45,7 +45,7 @@ TiledExecutionModel::TiledExecutionModel(CompositorContext &context,
group->determineResolution(resolution);
if (border_.use_render_border) {
- const rctf *render_border = border_.viewer_border;
+ const rctf *render_border = border_.render_border;
group->setRenderBorder(
render_border->xmin, render_border->xmax, render_border->ymin, render_border->ymax);
}
diff --git a/source/blender/compositor/nodes/COM_CryptomatteNode.cc b/source/blender/compositor/nodes/COM_CryptomatteNode.cc
index 4032a655633..5835f051ce3 100644
--- a/source/blender/compositor/nodes/COM_CryptomatteNode.cc
+++ b/source/blender/compositor/nodes/COM_CryptomatteNode.cc
@@ -124,6 +124,10 @@ void CryptomatteNode::input_operations_from_render_source(
RenderLayer *render_layer = RE_GetRenderLayer(render_result, view_layer->name);
if (render_layer) {
LISTBASE_FOREACH (RenderPass *, render_pass, &render_layer->passes) {
+ if (context.has_explicit_view() && !STREQ(render_pass->view, context.getViewName())) {
+ continue;
+ }
+
const std::string combined_name = combined_layer_pass_name(render_layer, render_pass);
if (blender::StringRef(combined_name).startswith(prefix)) {
RenderLayersProg *op = new RenderLayersProg(
diff --git a/source/blender/compositor/nodes/COM_RotateNode.cc b/source/blender/compositor/nodes/COM_RotateNode.cc
index af5baa733dc..c2fd8ed5594 100644
--- a/source/blender/compositor/nodes/COM_RotateNode.cc
+++ b/source/blender/compositor/nodes/COM_RotateNode.cc
@@ -30,20 +30,31 @@ RotateNode::RotateNode(bNode *editorNode) : Node(editorNode)
}
void RotateNode::convertToOperations(NodeConverter &converter,
- const CompositorContext & /*context*/) const
+ const CompositorContext &context) const
{
NodeInput *inputSocket = this->getInputSocket(0);
NodeInput *inputDegreeSocket = this->getInputSocket(1);
NodeOutput *outputSocket = this->getOutputSocket(0);
RotateOperation *operation = new RotateOperation();
- SetSamplerOperation *sampler = new SetSamplerOperation();
- sampler->setSampler((PixelSampler)this->getbNode()->custom1);
-
- converter.addOperation(sampler);
converter.addOperation(operation);
- converter.addLink(sampler->getOutputSocket(), operation->getInputSocket(0));
- converter.mapInputSocket(inputSocket, sampler->getInputSocket(0));
+ PixelSampler sampler = (PixelSampler)this->getbNode()->custom1;
+ switch (context.get_execution_model()) {
+ case eExecutionModel::Tiled: {
+ SetSamplerOperation *sampler_op = new SetSamplerOperation();
+ sampler_op->setSampler(sampler);
+ converter.addOperation(sampler_op);
+ converter.addLink(sampler_op->getOutputSocket(), operation->getInputSocket(0));
+ converter.mapInputSocket(inputSocket, sampler_op->getInputSocket(0));
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ operation->set_sampler(sampler);
+ converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
+ break;
+ }
+ }
+
converter.mapInputSocket(inputDegreeSocket, operation->getInputSocket(1));
converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
}
diff --git a/source/blender/compositor/nodes/COM_Stabilize2dNode.cc b/source/blender/compositor/nodes/COM_Stabilize2dNode.cc
index 0262f653d1a..7b2388bebca 100644
--- a/source/blender/compositor/nodes/COM_Stabilize2dNode.cc
+++ b/source/blender/compositor/nodes/COM_Stabilize2dNode.cc
@@ -22,6 +22,7 @@
#include "COM_RotateOperation.h"
#include "COM_ScaleOperation.h"
#include "COM_SetSamplerOperation.h"
+#include "COM_TransformOperation.h"
#include "COM_TranslateOperation.h"
#include "BKE_tracking.h"
@@ -42,18 +43,12 @@ void Stabilize2dNode::convertToOperations(NodeConverter &converter,
NodeInput *imageInput = this->getInputSocket(0);
MovieClip *clip = (MovieClip *)editorNode->id;
bool invert = (editorNode->custom2 & CMP_NODEFLAG_STABILIZE_INVERSE) != 0;
+ const PixelSampler sampler = (PixelSampler)editorNode->custom1;
- ScaleRelativeOperation *scaleOperation = new ScaleRelativeOperation();
- scaleOperation->setSampler((PixelSampler)editorNode->custom1);
- RotateOperation *rotateOperation = new RotateOperation();
- rotateOperation->setDoDegree2RadConversion(false);
- TranslateOperation *translateOperation = new TranslateOperation();
MovieClipAttributeOperation *scaleAttribute = new MovieClipAttributeOperation();
MovieClipAttributeOperation *angleAttribute = new MovieClipAttributeOperation();
MovieClipAttributeOperation *xAttribute = new MovieClipAttributeOperation();
MovieClipAttributeOperation *yAttribute = new MovieClipAttributeOperation();
- SetSamplerOperation *psoperation = new SetSamplerOperation();
- psoperation->setSampler((PixelSampler)editorNode->custom1);
scaleAttribute->setAttribute(MCA_SCALE);
scaleAttribute->setFramenumber(context.getFramenumber());
@@ -79,38 +74,67 @@ void Stabilize2dNode::convertToOperations(NodeConverter &converter,
converter.addOperation(angleAttribute);
converter.addOperation(xAttribute);
converter.addOperation(yAttribute);
- converter.addOperation(scaleOperation);
- converter.addOperation(translateOperation);
- converter.addOperation(rotateOperation);
- converter.addOperation(psoperation);
- converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(1));
- converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(2));
-
- converter.addLink(angleAttribute->getOutputSocket(), rotateOperation->getInputSocket(1));
-
- converter.addLink(xAttribute->getOutputSocket(), translateOperation->getInputSocket(1));
- converter.addLink(yAttribute->getOutputSocket(), translateOperation->getInputSocket(2));
-
- converter.mapOutputSocket(getOutputSocket(), psoperation->getOutputSocket());
-
- if (invert) {
- // Translate -> Rotate -> Scale.
- converter.mapInputSocket(imageInput, translateOperation->getInputSocket(0));
-
- converter.addLink(translateOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
- converter.addLink(rotateOperation->getOutputSocket(), scaleOperation->getInputSocket(0));
-
- converter.addLink(scaleOperation->getOutputSocket(), psoperation->getInputSocket(0));
- }
- else {
- // Scale -> Rotate -> Translate.
- converter.mapInputSocket(imageInput, scaleOperation->getInputSocket(0));
-
- converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
- converter.addLink(rotateOperation->getOutputSocket(), translateOperation->getInputSocket(0));
-
- converter.addLink(translateOperation->getOutputSocket(), psoperation->getInputSocket(0));
+ switch (context.get_execution_model()) {
+ case eExecutionModel::Tiled: {
+ ScaleRelativeOperation *scaleOperation = new ScaleRelativeOperation();
+ scaleOperation->setSampler(sampler);
+ RotateOperation *rotateOperation = new RotateOperation();
+ rotateOperation->setDoDegree2RadConversion(false);
+ TranslateOperation *translateOperation = new TranslateOperation();
+ SetSamplerOperation *psoperation = new SetSamplerOperation();
+ psoperation->setSampler(sampler);
+
+ converter.addOperation(scaleOperation);
+ converter.addOperation(translateOperation);
+ converter.addOperation(rotateOperation);
+ converter.addOperation(psoperation);
+
+ converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(1));
+ converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(2));
+
+ converter.addLink(angleAttribute->getOutputSocket(), rotateOperation->getInputSocket(1));
+
+ converter.addLink(xAttribute->getOutputSocket(), translateOperation->getInputSocket(1));
+ converter.addLink(yAttribute->getOutputSocket(), translateOperation->getInputSocket(2));
+
+ converter.mapOutputSocket(getOutputSocket(), psoperation->getOutputSocket());
+
+ if (invert) {
+ // Translate -> Rotate -> Scale.
+ converter.mapInputSocket(imageInput, translateOperation->getInputSocket(0));
+
+ converter.addLink(translateOperation->getOutputSocket(),
+ rotateOperation->getInputSocket(0));
+ converter.addLink(rotateOperation->getOutputSocket(), scaleOperation->getInputSocket(0));
+
+ converter.addLink(scaleOperation->getOutputSocket(), psoperation->getInputSocket(0));
+ }
+ else {
+ // Scale -> Rotate -> Translate.
+ converter.mapInputSocket(imageInput, scaleOperation->getInputSocket(0));
+
+ converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
+ converter.addLink(rotateOperation->getOutputSocket(),
+ translateOperation->getInputSocket(0));
+
+ converter.addLink(translateOperation->getOutputSocket(), psoperation->getInputSocket(0));
+ }
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ TransformOperation *transform_op = new TransformOperation();
+ transform_op->set_sampler(sampler);
+ transform_op->set_convert_rotate_degree_to_rad(false);
+ transform_op->set_invert(invert);
+ converter.addOperation(transform_op);
+ converter.mapInputSocket(imageInput, transform_op->getInputSocket(0));
+ converter.addLink(xAttribute->getOutputSocket(), transform_op->getInputSocket(1));
+ converter.addLink(yAttribute->getOutputSocket(), transform_op->getInputSocket(2));
+ converter.addLink(angleAttribute->getOutputSocket(), transform_op->getInputSocket(3));
+ converter.addLink(scaleAttribute->getOutputSocket(), transform_op->getInputSocket(4));
+ converter.mapOutputSocket(getOutputSocket(), transform_op->getOutputSocket());
+ }
}
}
diff --git a/source/blender/compositor/nodes/COM_TransformNode.cc b/source/blender/compositor/nodes/COM_TransformNode.cc
index e1deaf616a4..d2fb7b54633 100644
--- a/source/blender/compositor/nodes/COM_TransformNode.cc
+++ b/source/blender/compositor/nodes/COM_TransformNode.cc
@@ -22,6 +22,7 @@
#include "COM_ScaleOperation.h"
#include "COM_SetSamplerOperation.h"
#include "COM_SetValueOperation.h"
+#include "COM_TransformOperation.h"
#include "COM_TranslateOperation.h"
namespace blender::compositor {
@@ -32,7 +33,7 @@ TransformNode::TransformNode(bNode *editorNode) : Node(editorNode)
}
void TransformNode::convertToOperations(NodeConverter &converter,
- const CompositorContext & /*context*/) const
+ const CompositorContext &context) const
{
NodeInput *imageInput = this->getInputSocket(0);
NodeInput *xInput = this->getInputSocket(1);
@@ -40,33 +41,51 @@ void TransformNode::convertToOperations(NodeConverter &converter,
NodeInput *angleInput = this->getInputSocket(3);
NodeInput *scaleInput = this->getInputSocket(4);
- ScaleRelativeOperation *scaleOperation = new ScaleRelativeOperation();
- converter.addOperation(scaleOperation);
+ switch (context.get_execution_model()) {
+ case eExecutionModel::Tiled: {
+ ScaleRelativeOperation *scaleOperation = new ScaleRelativeOperation();
+ converter.addOperation(scaleOperation);
- RotateOperation *rotateOperation = new RotateOperation();
- rotateOperation->setDoDegree2RadConversion(false);
- converter.addOperation(rotateOperation);
+ RotateOperation *rotateOperation = new RotateOperation();
+ rotateOperation->setDoDegree2RadConversion(false);
+ converter.addOperation(rotateOperation);
- TranslateOperation *translateOperation = new TranslateOperation();
- converter.addOperation(translateOperation);
+ TranslateOperation *translateOperation = new TranslateOperation();
+ converter.addOperation(translateOperation);
- SetSamplerOperation *sampler = new SetSamplerOperation();
- sampler->setSampler((PixelSampler)this->getbNode()->custom1);
- converter.addOperation(sampler);
+ SetSamplerOperation *sampler = new SetSamplerOperation();
+ sampler->setSampler((PixelSampler)this->getbNode()->custom1);
+ converter.addOperation(sampler);
- converter.mapInputSocket(imageInput, sampler->getInputSocket(0));
- converter.addLink(sampler->getOutputSocket(), scaleOperation->getInputSocket(0));
- converter.mapInputSocket(scaleInput, scaleOperation->getInputSocket(1));
- converter.mapInputSocket(scaleInput, scaleOperation->getInputSocket(2)); // xscale = yscale
+ converter.mapInputSocket(imageInput, sampler->getInputSocket(0));
+ converter.addLink(sampler->getOutputSocket(), scaleOperation->getInputSocket(0));
+ converter.mapInputSocket(scaleInput, scaleOperation->getInputSocket(1));
+ converter.mapInputSocket(scaleInput, scaleOperation->getInputSocket(2)); // xscale = yscale
- converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
- converter.mapInputSocket(angleInput, rotateOperation->getInputSocket(1));
+ converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
+ converter.mapInputSocket(angleInput, rotateOperation->getInputSocket(1));
- converter.addLink(rotateOperation->getOutputSocket(), translateOperation->getInputSocket(0));
- converter.mapInputSocket(xInput, translateOperation->getInputSocket(1));
- converter.mapInputSocket(yInput, translateOperation->getInputSocket(2));
+ converter.addLink(rotateOperation->getOutputSocket(), translateOperation->getInputSocket(0));
+ converter.mapInputSocket(xInput, translateOperation->getInputSocket(1));
+ converter.mapInputSocket(yInput, translateOperation->getInputSocket(2));
- converter.mapOutputSocket(getOutputSocket(), translateOperation->getOutputSocket());
+ converter.mapOutputSocket(getOutputSocket(), translateOperation->getOutputSocket());
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ TransformOperation *op = new TransformOperation();
+ op->set_sampler((PixelSampler)this->getbNode()->custom1);
+ converter.addOperation(op);
+
+ converter.mapInputSocket(imageInput, op->getInputSocket(0));
+ converter.mapInputSocket(xInput, op->getInputSocket(1));
+ converter.mapInputSocket(yInput, op->getInputSocket(2));
+ converter.mapInputSocket(angleInput, op->getInputSocket(3));
+ converter.mapInputSocket(scaleInput, op->getInputSocket(4));
+ converter.mapOutputSocket(getOutputSocket(), op->getOutputSocket());
+ break;
+ }
+ }
}
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
index 0c656753a51..30e7fab4027 100644
--- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
+++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
@@ -20,6 +20,11 @@
namespace blender::compositor {
+AlphaOverKeyOperation::AlphaOverKeyOperation()
+{
+ this->flags.can_be_constant = true;
+}
+
void AlphaOverKeyOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -50,4 +55,29 @@ void AlphaOverKeyOperation::executePixelSampled(float output[4],
}
}
+void AlphaOverKeyOperation::update_memory_buffer_row(PixelCursor &p)
+{
+ for (; p.out < p.row_end; p.next()) {
+ const float *color1 = p.color1;
+ const float *over_color = p.color2;
+ const float value = *p.value;
+
+ if (over_color[3] <= 0.0f) {
+ copy_v4_v4(p.out, color1);
+ }
+ else if (value == 1.0f && over_color[3] >= 1.0f) {
+ copy_v4_v4(p.out, over_color);
+ }
+ else {
+ const float premul = value * over_color[3];
+ const float mul = 1.0f - premul;
+
+ p.out[0] = (mul * color1[0]) + premul * over_color[0];
+ p.out[1] = (mul * color1[1]) + premul * over_color[1];
+ p.out[2] = (mul * color1[2]) + premul * over_color[2];
+ p.out[3] = (mul * color1[3]) + value * over_color[3];
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
index 83713d18971..960fbc98fe9 100644
--- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
+++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
@@ -28,10 +28,14 @@ namespace blender::compositor {
*/
class AlphaOverKeyOperation : public MixBaseOperation {
public:
+ AlphaOverKeyOperation();
+
/**
* The inner loop of this operation.
*/
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_row(PixelCursor &p) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
index c68c79d2263..0cc179ea209 100644
--- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
+++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
@@ -23,6 +23,7 @@ namespace blender::compositor {
AlphaOverMixedOperation::AlphaOverMixedOperation()
{
this->m_x = 0.0f;
+ this->flags.can_be_constant = true;
}
void AlphaOverMixedOperation::executePixelSampled(float output[4],
@@ -56,4 +57,30 @@ void AlphaOverMixedOperation::executePixelSampled(float output[4],
}
}
+void AlphaOverMixedOperation::update_memory_buffer_row(PixelCursor &p)
+{
+ for (; p.out < p.row_end; p.next()) {
+ const float *color1 = p.color1;
+ const float *over_color = p.color2;
+ const float value = *p.value;
+
+ if (over_color[3] <= 0.0f) {
+ copy_v4_v4(p.out, color1);
+ }
+ else if (value == 1.0f && over_color[3] >= 1.0f) {
+ copy_v4_v4(p.out, over_color);
+ }
+ else {
+ const float addfac = 1.0f - this->m_x + over_color[3] * this->m_x;
+ const float premul = value * addfac;
+ const float mul = 1.0f - value * over_color[3];
+
+ p.out[0] = (mul * color1[0]) + premul * over_color[0];
+ p.out[1] = (mul * color1[1]) + premul * over_color[1];
+ p.out[2] = (mul * color1[2]) + premul * over_color[2];
+ p.out[3] = (mul * color1[3]) + value * over_color[3];
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
index e2b3af84162..2b88cd5f421 100644
--- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
+++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
@@ -45,6 +45,8 @@ class AlphaOverMixedOperation : public MixBaseOperation {
{
this->m_x = x;
}
+
+ void update_memory_buffer_row(PixelCursor &p) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
index 3dd4607e273..a57e8c7f8a3 100644
--- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
+++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
@@ -20,6 +20,11 @@
namespace blender::compositor {
+AlphaOverPremultiplyOperation::AlphaOverPremultiplyOperation()
+{
+ this->flags.can_be_constant = true;
+}
+
void AlphaOverPremultiplyOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -50,4 +55,28 @@ void AlphaOverPremultiplyOperation::executePixelSampled(float output[4],
}
}
+void AlphaOverPremultiplyOperation::update_memory_buffer_row(PixelCursor &p)
+{
+ for (; p.out < p.row_end; p.next()) {
+ const float *color1 = p.color1;
+ const float *over_color = p.color2;
+ const float value = *p.value;
+
+ if (over_color[3] <= 0.0f) {
+ copy_v4_v4(p.out, color1);
+ }
+ else if (value == 1.0f && over_color[3] >= 1.0f) {
+ copy_v4_v4(p.out, over_color);
+ }
+ else {
+ const float mul = 1.0f - value * over_color[3];
+
+ p.out[0] = (mul * color1[0]) + value * over_color[0];
+ p.out[1] = (mul * color1[1]) + value * over_color[1];
+ p.out[2] = (mul * color1[2]) + value * over_color[2];
+ p.out[3] = (mul * color1[3]) + value * over_color[3];
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
index f1d4b668fce..701bc07cc27 100644
--- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
+++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
@@ -28,10 +28,14 @@ namespace blender::compositor {
*/
class AlphaOverPremultiplyOperation : public MixBaseOperation {
public:
+ AlphaOverPremultiplyOperation();
+
/**
* The inner loop of this operation.
*/
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_row(PixelCursor &p) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_BilateralBlurOperation.cc b/source/blender/compositor/operations/COM_BilateralBlurOperation.cc
index 64448e2ae95..0c1bb688d4e 100644
--- a/source/blender/compositor/operations/COM_BilateralBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_BilateralBlurOperation.cc
@@ -38,7 +38,6 @@ void BilateralBlurOperation::initExecution()
{
this->m_inputColorProgram = getInputSocketReader(0);
this->m_inputDeterminatorProgram = getInputSocketReader(1);
- this->m_space = this->m_data->sigma_space + this->m_data->iter;
QualityStepHelper::initExecution(COM_QH_INCREASE);
}
@@ -115,4 +114,89 @@ bool BilateralBlurOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void BilateralBlurOperation::get_area_of_interest(const int UNUSED(input_idx),
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ const int add = ceil(this->m_space) + 1;
+
+ r_input_area.xmax = output_area.xmax + (add);
+ r_input_area.xmin = output_area.xmin - (add);
+ r_input_area.ymax = output_area.ymax + (add);
+ r_input_area.ymin = output_area.ymin - (add);
+}
+
+struct PixelCursor {
+ MemoryBuffer *input_determinator;
+ MemoryBuffer *input_color;
+ int step;
+ float sigma_color;
+ const float *determ_reference_color;
+ float temp_color[4];
+ float *out;
+ int min_x, max_x;
+ int min_y, max_y;
+};
+
+static void blur_pixel(PixelCursor &p)
+{
+ float blur_divider = 0.0f;
+ zero_v4(p.out);
+
+ /* TODO(sergey): This isn't really good bilateral filter, it should be
+ * using gaussian bell for weights. Also sigma_color doesn't seem to be
+ * used correct at all.
+ */
+ for (int yi = p.min_y; yi < p.max_y; yi += p.step) {
+ for (int xi = p.min_x; xi < p.max_x; xi += p.step) {
+ p.input_determinator->read(p.temp_color, xi, yi);
+ /* Do not take the alpha channel into account. */
+ const float delta_color = (fabsf(p.determ_reference_color[0] - p.temp_color[0]) +
+ fabsf(p.determ_reference_color[1] - p.temp_color[1]) +
+ fabsf(p.determ_reference_color[2] - p.temp_color[2]));
+ if (delta_color < p.sigma_color) {
+ /* Add this to the blur. */
+ p.input_color->read(p.temp_color, xi, yi);
+ add_v4_v4(p.out, p.temp_color);
+ blur_divider += 1.0f;
+ }
+ }
+ }
+
+ if (blur_divider > 0.0f) {
+ mul_v4_fl(p.out, 1.0f / blur_divider);
+ }
+ else {
+ copy_v4_v4(p.out, COM_COLOR_BLACK);
+ }
+}
+
+void BilateralBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ PixelCursor p = {};
+ p.step = QualityStepHelper::getStep();
+ p.sigma_color = this->m_data->sigma_color;
+ p.input_color = inputs[0];
+ p.input_determinator = inputs[1];
+ const float space = this->m_space;
+ for (int y = area.ymin; y < area.ymax; y++) {
+ p.out = output->get_elem(area.xmin, y);
+ /* This will be used as the reference color for the determinator. */
+ p.determ_reference_color = p.input_determinator->get_elem(area.xmin, y);
+ p.min_y = floor(y - space);
+ p.max_y = ceil(y + space);
+ for (int x = area.xmin; x < area.xmax; x++) {
+ p.min_x = floor(x - space);
+ p.max_x = ceil(x + space);
+
+ blur_pixel(p);
+
+ p.determ_reference_color += p.input_determinator->elem_stride;
+ p.out += output->elem_stride;
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_BilateralBlurOperation.h b/source/blender/compositor/operations/COM_BilateralBlurOperation.h
index c56cef35050..517c5292827 100644
--- a/source/blender/compositor/operations/COM_BilateralBlurOperation.h
+++ b/source/blender/compositor/operations/COM_BilateralBlurOperation.h
@@ -18,12 +18,12 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "COM_QualityStepHelper.h"
namespace blender::compositor {
-class BilateralBlurOperation : public NodeOperation, public QualityStepHelper {
+class BilateralBlurOperation : public MultiThreadedOperation, public QualityStepHelper {
private:
SocketReader *m_inputColorProgram;
SocketReader *m_inputDeterminatorProgram;
@@ -55,7 +55,14 @@ class BilateralBlurOperation : public NodeOperation, public QualityStepHelper {
void setData(NodeBilateralBlurData *data)
{
this->m_data = data;
+ this->m_space = data->sigma_space + data->iter;
}
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.cc b/source/blender/compositor/operations/COM_BlurBaseOperation.cc
index 8b73624ca79..058b422c4a5 100644
--- a/source/blender/compositor/operations/COM_BlurBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_BlurBaseOperation.cc
@@ -17,6 +17,8 @@
*/
#include "COM_BlurBaseOperation.h"
+#include "COM_ConstantOperation.h"
+
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
@@ -36,11 +38,15 @@ BlurBaseOperation::BlurBaseOperation(DataType data_type)
this->m_size = 1.0f;
this->m_sizeavailable = false;
this->m_extend_bounds = false;
+ use_variable_size_ = false;
}
-void BlurBaseOperation::initExecution()
+
+void BlurBaseOperation::init_data()
{
- this->m_inputProgram = this->getInputSocketReader(0);
- this->m_inputSize = this->getInputSocketReader(1);
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ updateSize();
+ }
+
this->m_data.image_in_width = this->getWidth();
this->m_data.image_in_height = this->getHeight();
if (this->m_data.relative) {
@@ -61,6 +67,12 @@ void BlurBaseOperation::initExecution()
this->m_data.sizex = round_fl_to_int(this->m_data.percentx * 0.01f * sizex);
this->m_data.sizey = round_fl_to_int(this->m_data.percenty * 0.01f * sizey);
}
+}
+
+void BlurBaseOperation::initExecution()
+{
+ this->m_inputProgram = this->getInputSocketReader(0);
+ this->m_inputSize = this->getInputSocketReader(1);
QualityStepHelper::initExecution(COM_QH_MULTIPLY);
}
@@ -165,23 +177,82 @@ void BlurBaseOperation::setData(const NodeBlurData *data)
memcpy(&m_data, data, sizeof(NodeBlurData));
}
+int BlurBaseOperation::get_blur_size(eDimension dim) const
+{
+ switch (dim) {
+ case eDimension::X:
+ return m_data.sizex;
+ case eDimension::Y:
+ return m_data.sizey;
+ }
+ return -1;
+}
+
void BlurBaseOperation::updateSize()
{
- if (!this->m_sizeavailable) {
- float result[4];
- this->getInputSocketReader(1)->readSampled(result, 0, 0, PixelSampler::Nearest);
- this->m_size = result[0];
- this->m_sizeavailable = true;
+ if (this->m_sizeavailable || use_variable_size_) {
+ return;
}
+
+ switch (execution_model_) {
+ case eExecutionModel::Tiled: {
+ float result[4];
+ this->getInputSocketReader(1)->readSampled(result, 0, 0, PixelSampler::Nearest);
+ this->m_size = result[0];
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ NodeOperation *size_input = get_input_operation(SIZE_INPUT_INDEX);
+ if (size_input->get_flags().is_constant_operation) {
+ m_size = *static_cast<ConstantOperation *>(size_input)->get_constant_elem();
+ } /* Else use default. */
+ break;
+ }
+ }
+ this->m_sizeavailable = true;
}
void BlurBaseOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
- NodeOperation::determineResolution(resolution, preferredResolution);
- if (this->m_extend_bounds) {
- resolution[0] += 2 * this->m_size * m_data.sizex;
- resolution[1] += 2 * this->m_size * m_data.sizey;
+ if (!m_extend_bounds) {
+ NodeOperation::determineResolution(resolution, preferredResolution);
+ return;
+ }
+
+ switch (execution_model_) {
+ case eExecutionModel::Tiled: {
+ NodeOperation::determineResolution(resolution, preferredResolution);
+ resolution[0] += 2 * m_size * m_data.sizex;
+ resolution[1] += 2 * m_size * m_data.sizey;
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ /* Setting a modifier ensures all non main inputs have extended bounds as preferred
+ * resolution, avoiding unnecessary resolution conversions that would hide constant
+ * operations. */
+ set_determined_resolution_modifier([=](unsigned int res[2]) {
+ /* Rounding to even prevents jiggling in backdrop while switching size values. */
+ res[0] += round_to_even(2 * m_size * m_data.sizex);
+ res[1] += round_to_even(2 * m_size * m_data.sizey);
+ });
+ NodeOperation::determineResolution(resolution, preferredResolution);
+ break;
+ }
+ }
+}
+
+void BlurBaseOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case 0:
+ r_input_area = output_area;
+ break;
+ case 1:
+ r_input_area = use_variable_size_ ? output_area : COM_SINGLE_ELEM_AREA;
+ break;
}
}
diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.h b/source/blender/compositor/operations/COM_BlurBaseOperation.h
index 7937ebd69dc..78b1e919aa6 100644
--- a/source/blender/compositor/operations/COM_BlurBaseOperation.h
+++ b/source/blender/compositor/operations/COM_BlurBaseOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "COM_QualityStepHelper.h"
#define MAX_GAUSSTAB_RADIUS 30000
@@ -27,10 +27,16 @@
namespace blender::compositor {
-class BlurBaseOperation : public NodeOperation, public QualityStepHelper {
+class BlurBaseOperation : public MultiThreadedOperation, public QualityStepHelper {
private:
+ bool m_extend_bounds;
+
+ protected:
+ static constexpr int IMAGE_INPUT_INDEX = 0;
+ static constexpr int SIZE_INPUT_INDEX = 1;
+
protected:
- BlurBaseOperation(DataType data_type);
+ BlurBaseOperation(DataType data_type8);
float *make_gausstab(float rad, int size);
#ifdef BLI_HAVE_SSE2
__m128 *convert_gausstab_sse(const float *gausstab, int size);
@@ -49,9 +55,11 @@ class BlurBaseOperation : public NodeOperation, public QualityStepHelper {
float m_size;
bool m_sizeavailable;
- bool m_extend_bounds;
+ /* Flags for inheriting classes. */
+ bool use_variable_size_;
public:
+ virtual void init_data() override;
/**
* Initialize the execution
*/
@@ -75,8 +83,14 @@ class BlurBaseOperation : public NodeOperation, public QualityStepHelper {
this->m_extend_bounds = extend_bounds;
}
+ int get_blur_size(eDimension dim) const;
+
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
+
+ virtual void get_area_of_interest(int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cc b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
index 3f98732b403..f2a43b7dbca 100644
--- a/source/blender/compositor/operations/COM_BokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
@@ -17,6 +17,8 @@
*/
#include "COM_BokehBlurOperation.h"
+#include "COM_ConstantOperation.h"
+
#include "BLI_math.h"
#include "COM_OpenCLDevice.h"
@@ -24,6 +26,11 @@
namespace blender::compositor {
+constexpr int IMAGE_INPUT_INDEX = 0;
+constexpr int BOKEH_INPUT_INDEX = 1;
+constexpr int BOUNDING_BOX_INPUT_INDEX = 2;
+constexpr int SIZE_INPUT_INDEX = 3;
+
BokehBlurOperation::BokehBlurOperation()
{
this->addInputSocket(DataType::Color);
@@ -44,6 +51,23 @@ BokehBlurOperation::BokehBlurOperation()
this->m_extend_bounds = false;
}
+void BokehBlurOperation::init_data()
+{
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ updateSize();
+ }
+
+ NodeOperation *bokeh = get_input_operation(BOKEH_INPUT_INDEX);
+ const int width = bokeh->getWidth();
+ const int height = bokeh->getHeight();
+
+ const float dimension = MIN2(width, height);
+
+ m_bokehMidX = width / 2.0f;
+ m_bokehMidY = height / 2.0f;
+ m_bokehDimension = dimension / 2.0f;
+}
+
void *BokehBlurOperation::initializeTileData(rcti * /*rect*/)
{
lockMutex();
@@ -58,18 +82,11 @@ void *BokehBlurOperation::initializeTileData(rcti * /*rect*/)
void BokehBlurOperation::initExecution()
{
initMutex();
+
this->m_inputProgram = getInputSocketReader(0);
this->m_inputBokehProgram = getInputSocketReader(1);
this->m_inputBoundingBoxReader = getInputSocketReader(2);
- int width = this->m_inputBokehProgram->getWidth();
- int height = this->m_inputBokehProgram->getHeight();
-
- float dimension = MIN2(width, height);
-
- this->m_bokehMidX = width / 2.0f;
- this->m_bokehMidY = height / 2.0f;
- this->m_bokehDimension = dimension / 2.0f;
QualityStepHelper::initExecution(COM_QH_INCREASE);
}
@@ -225,23 +242,146 @@ void BokehBlurOperation::executeOpenCL(OpenCLDevice *device,
void BokehBlurOperation::updateSize()
{
- if (!this->m_sizeavailable) {
- float result[4];
- this->getInputSocketReader(3)->readSampled(result, 0, 0, PixelSampler::Nearest);
- this->m_size = result[0];
- CLAMP(this->m_size, 0.0f, 10.0f);
- this->m_sizeavailable = true;
+ if (this->m_sizeavailable) {
+ return;
}
+
+ switch (execution_model_) {
+ case eExecutionModel::Tiled: {
+ float result[4];
+ this->getInputSocketReader(3)->readSampled(result, 0, 0, PixelSampler::Nearest);
+ this->m_size = result[0];
+ CLAMP(this->m_size, 0.0f, 10.0f);
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ NodeOperation *size_input = get_input_operation(SIZE_INPUT_INDEX);
+ if (size_input->get_flags().is_constant_operation) {
+ m_size = *static_cast<ConstantOperation *>(size_input)->get_constant_elem();
+ CLAMP(m_size, 0.0f, 10.0f);
+ } /* Else use default. */
+ break;
+ }
+ }
+ this->m_sizeavailable = true;
}
void BokehBlurOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
- NodeOperation::determineResolution(resolution, preferredResolution);
- if (this->m_extend_bounds) {
- const float max_dim = MAX2(resolution[0], resolution[1]);
- resolution[0] += 2 * this->m_size * max_dim / 100.0f;
- resolution[1] += 2 * this->m_size * max_dim / 100.0f;
+ if (!m_extend_bounds) {
+ NodeOperation::determineResolution(resolution, preferredResolution);
+ return;
+ }
+
+ switch (execution_model_) {
+ case eExecutionModel::Tiled: {
+ NodeOperation::determineResolution(resolution, preferredResolution);
+ const float max_dim = MAX2(resolution[0], resolution[1]);
+ resolution[0] += 2 * this->m_size * max_dim / 100.0f;
+ resolution[1] += 2 * this->m_size * max_dim / 100.0f;
+ break;
+ }
+ case eExecutionModel::FullFrame: {
+ set_determined_resolution_modifier([=](unsigned int res[2]) {
+ const float max_dim = MAX2(res[0], res[1]);
+ /* Rounding to even prevents image jiggling in backdrop while switching size values. */
+ float add_size = round_to_even(2 * this->m_size * max_dim / 100.0f);
+ res[0] += add_size;
+ res[1] += add_size;
+ });
+ NodeOperation::determineResolution(resolution, preferredResolution);
+ break;
+ }
+ }
+}
+
+void BokehBlurOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case IMAGE_INPUT_INDEX: {
+ const float max_dim = MAX2(this->getWidth(), this->getHeight());
+ const float add_size = m_size * max_dim / 100.0f;
+ r_input_area.xmin = output_area.xmin - add_size;
+ r_input_area.xmax = output_area.xmax + add_size;
+ r_input_area.ymin = output_area.ymin - add_size;
+ r_input_area.ymax = output_area.ymax + add_size;
+ break;
+ }
+ case BOKEH_INPUT_INDEX: {
+ NodeOperation *bokeh_input = getInputOperation(BOKEH_INPUT_INDEX);
+ r_input_area.xmin = 0;
+ r_input_area.xmax = bokeh_input->getWidth();
+ r_input_area.ymin = 0;
+ r_input_area.ymax = bokeh_input->getHeight();
+ break;
+ }
+ case BOUNDING_BOX_INPUT_INDEX:
+ r_input_area = output_area;
+ break;
+ case SIZE_INPUT_INDEX: {
+ r_input_area = COM_SINGLE_ELEM_AREA;
+ break;
+ }
+ }
+}
+
+void BokehBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const float max_dim = MAX2(this->getWidth(), this->getHeight());
+ const int pixel_size = m_size * max_dim / 100.0f;
+ const float m = m_bokehDimension / pixel_size;
+
+ const MemoryBuffer *image_input = inputs[IMAGE_INPUT_INDEX];
+ const MemoryBuffer *bokeh_input = inputs[BOKEH_INPUT_INDEX];
+ MemoryBuffer *bounding_input = inputs[BOUNDING_BOX_INPUT_INDEX];
+ BuffersIterator<float> it = output->iterate_with({bounding_input}, area);
+ const rcti &image_rect = image_input->get_rect();
+ for (; !it.is_end(); ++it) {
+ const int x = it.x;
+ const int y = it.y;
+ const float bounding_box = *it.in(0);
+ if (bounding_box <= 0.0f) {
+ image_input->read_elem(x, y, it.out);
+ continue;
+ }
+
+ float color_accum[4] = {0};
+ float multiplier_accum[4] = {0};
+ if (pixel_size < 2) {
+ image_input->read_elem(x, y, color_accum);
+ multiplier_accum[0] = 1.0f;
+ multiplier_accum[1] = 1.0f;
+ multiplier_accum[2] = 1.0f;
+ multiplier_accum[3] = 1.0f;
+ }
+ const int miny = MAX2(y - pixel_size, image_rect.ymin);
+ const int maxy = MIN2(y + pixel_size, image_rect.ymax);
+ const int minx = MAX2(x - pixel_size, image_rect.xmin);
+ const int maxx = MIN2(x + pixel_size, image_rect.xmax);
+ const int step = getStep();
+ const int elem_stride = image_input->elem_stride * step;
+ const int row_stride = image_input->row_stride * step;
+ const float *row_color = image_input->get_elem(minx, miny);
+ for (int ny = miny; ny < maxy; ny += step, row_color += row_stride) {
+ const float *color = row_color;
+ const float v = m_bokehMidY - (ny - y) * m;
+ for (int nx = minx; nx < maxx; nx += step, color += elem_stride) {
+ const float u = m_bokehMidX - (nx - x) * m;
+ float bokeh[4];
+ bokeh_input->read_elem_checked(u, v, bokeh);
+ madd_v4_v4v4(color_accum, bokeh, color);
+ add_v4_v4(multiplier_accum, bokeh);
+ }
+ }
+ it.out[0] = color_accum[0] * (1.0f / multiplier_accum[0]);
+ it.out[1] = color_accum[1] * (1.0f / multiplier_accum[1]);
+ it.out[2] = color_accum[2] * (1.0f / multiplier_accum[2]);
+ it.out[3] = color_accum[3] * (1.0f / multiplier_accum[3]);
}
}
diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.h b/source/blender/compositor/operations/COM_BokehBlurOperation.h
index 3ce06adb5d6..59c14305393 100644
--- a/source/blender/compositor/operations/COM_BokehBlurOperation.h
+++ b/source/blender/compositor/operations/COM_BokehBlurOperation.h
@@ -18,12 +18,12 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "COM_QualityStepHelper.h"
namespace blender::compositor {
-class BokehBlurOperation : public NodeOperation, public QualityStepHelper {
+class BokehBlurOperation : public MultiThreadedOperation, public QualityStepHelper {
private:
SocketReader *m_inputProgram;
SocketReader *m_inputBokehProgram;
@@ -31,6 +31,7 @@ class BokehBlurOperation : public NodeOperation, public QualityStepHelper {
void updateSize();
float m_size;
bool m_sizeavailable;
+
float m_bokehMidX;
float m_bokehMidY;
float m_bokehDimension;
@@ -39,6 +40,8 @@ class BokehBlurOperation : public NodeOperation, public QualityStepHelper {
public:
BokehBlurOperation();
+ void init_data() override;
+
void *initializeTileData(rcti *rect) override;
/**
* The inner loop of this operation.
@@ -79,6 +82,11 @@ class BokehBlurOperation : public NodeOperation, public QualityStepHelper {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.cc b/source/blender/compositor/operations/COM_BokehImageOperation.cc
index 63f283b6acc..bd5b25b5af8 100644
--- a/source/blender/compositor/operations/COM_BokehImageOperation.cc
+++ b/source/blender/compositor/operations/COM_BokehImageOperation.cc
@@ -110,6 +110,31 @@ void BokehImageOperation::executePixelSampled(float output[4],
output[3] = (insideBokehMax + insideBokehMed + insideBokehMin) / 3.0f;
}
+void BokehImageOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> UNUSED(inputs))
+{
+ const float shift = this->m_data->lensshift;
+ const float shift2 = shift / 2.0f;
+ const float distance = this->m_circularDistance;
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ const float insideBokehMax = isInsideBokeh(distance, it.x, it.y);
+ const float insideBokehMed = isInsideBokeh(distance - fabsf(shift2 * distance), it.x, it.y);
+ const float insideBokehMin = isInsideBokeh(distance - fabsf(shift * distance), it.x, it.y);
+ if (shift < 0) {
+ it.out[0] = insideBokehMax;
+ it.out[1] = insideBokehMed;
+ it.out[2] = insideBokehMin;
+ }
+ else {
+ it.out[0] = insideBokehMin;
+ it.out[1] = insideBokehMed;
+ it.out[2] = insideBokehMax;
+ }
+ it.out[3] = (insideBokehMax + insideBokehMed + insideBokehMin) / 3.0f;
+ }
+}
+
void BokehImageOperation::deinitExecution()
{
if (this->m_deleteData) {
diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.h b/source/blender/compositor/operations/COM_BokehImageOperation.h
index 2e0bc8a34dc..2527233fabd 100644
--- a/source/blender/compositor/operations/COM_BokehImageOperation.h
+++ b/source/blender/compositor/operations/COM_BokehImageOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -49,7 +49,7 @@ namespace blender::compositor {
* With a simple compare it can be detected if the evaluated pixel is between the outer and inner
*edge.
*/
-class BokehImageOperation : public NodeOperation {
+class BokehImageOperation : public MultiThreadedOperation {
private:
/**
* \brief Settings of the bokeh image
@@ -151,6 +151,10 @@ class BokehImageOperation : public NodeOperation {
{
this->m_deleteData = true;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.cc b/source/blender/compositor/operations/COM_ChangeHSVOperation.cc
index eee007ce9e6..1e3e7806968 100644
--- a/source/blender/compositor/operations/COM_ChangeHSVOperation.cc
+++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.cc
@@ -28,6 +28,7 @@ ChangeHSVOperation::ChangeHSVOperation()
this->addInputSocket(DataType::Value);
this->addOutputSocket(DataType::Color);
this->m_inputOperation = nullptr;
+ this->flags.can_be_constant = true;
}
void ChangeHSVOperation::initExecution()
@@ -71,4 +72,26 @@ void ChangeHSVOperation::executePixelSampled(float output[4],
output[3] = inputColor1[3];
}
+void ChangeHSVOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color = it.in(0);
+ const float hue = *it.in(1);
+ it.out[0] = color[0] + (hue - 0.5f);
+ if (it.out[0] > 1.0f) {
+ it.out[0] -= 1.0f;
+ }
+ else if (it.out[0] < 0.0f) {
+ it.out[0] += 1.0f;
+ }
+ const float saturation = *it.in(2);
+ const float value = *it.in(3);
+ it.out[1] = color[1] * saturation;
+ it.out[2] = color[2] * value;
+ it.out[3] = color[3];
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.h b/source/blender/compositor/operations/COM_ChangeHSVOperation.h
index d38b4be3efe..e7bc3274f25 100644
--- a/source/blender/compositor/operations/COM_ChangeHSVOperation.h
+++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class ChangeHSVOperation : public NodeOperation {
+class ChangeHSVOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputOperation;
SocketReader *m_hueOperation;
@@ -46,6 +46,10 @@ class ChangeHSVOperation : public NodeOperation {
* The inner loop of this operation.
*/
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
index ec4331dc231..65742d0cfcc 100644
--- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
@@ -27,6 +27,7 @@ ChannelMatteOperation::ChannelMatteOperation()
addOutputSocket(DataType::Value);
this->m_inputImageProgram = nullptr;
+ flags.can_be_constant = true;
}
void ChannelMatteOperation::initExecution()
@@ -121,4 +122,37 @@ void ChannelMatteOperation::executePixelSampled(float output[4],
output[0] = MIN2(alpha, inColor[3]);
}
+void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color = it.in(0);
+
+ /* Matte operation. */
+ float alpha = color[this->m_ids[0]] - MAX2(color[this->m_ids[1]], color[this->m_ids[2]]);
+
+ /* Flip because 0.0 is transparent, not 1.0. */
+ alpha = 1.0f - alpha;
+
+ /* Test range. */
+ if (alpha > m_limit_max) {
+ alpha = color[3]; /* Whatever it was prior. */
+ }
+ else if (alpha < m_limit_min) {
+ alpha = 0.0f;
+ }
+ else { /* Blend. */
+ alpha = (alpha - m_limit_min) / m_limit_range;
+ }
+
+ /* Store matte(alpha) value in [0] to go with
+ * COM_SetAlphaMultiplyOperation and the Value output.
+ */
+
+ /* Don't make something that was more transparent less transparent. */
+ *it.out = MIN2(alpha, color[3]);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.h b/source/blender/compositor/operations/COM_ChannelMatteOperation.h
index 6e9dcccd36e..ba50105dd3b 100644
--- a/source/blender/compositor/operations/COM_ChannelMatteOperation.h
+++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class ChannelMatteOperation : public NodeOperation {
+class ChannelMatteOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputImageProgram;
@@ -71,6 +71,10 @@ class ChannelMatteOperation : public NodeOperation {
this->m_limit_channel = nodeChroma->channel;
this->m_matte_channel = custom2;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.cc b/source/blender/compositor/operations/COM_ChromaMatteOperation.cc
index b7fec5f07e5..0784f266b19 100644
--- a/source/blender/compositor/operations/COM_ChromaMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.cc
@@ -29,6 +29,7 @@ ChromaMatteOperation::ChromaMatteOperation()
this->m_inputImageProgram = nullptr;
this->m_inputKeyProgram = nullptr;
+ flags.can_be_constant = true;
}
void ChromaMatteOperation::initExecution()
@@ -110,4 +111,58 @@ void ChromaMatteOperation::executePixelSampled(float output[4],
}
}
+void ChromaMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const float acceptance = this->m_settings->t1; /* In radians. */
+ const float cutoff = this->m_settings->t2; /* In radians. */
+ const float gain = this->m_settings->fstrength;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *in_image = it.in(0);
+ const float *in_key = it.in(1);
+
+ /* Store matte(alpha) value in [0] to go with
+ * #COM_SetAlphaMultiplyOperation and the Value output. */
+
+ /* Algorithm from book "Video Demystified", does not include the spill reduction part. */
+ /* Find theta, the angle that the color space should be rotated based on key. */
+
+ /* Rescale to `-1.0..1.0`. */
+ // const float image_Y = (in_image[0] * 2.0f) - 1.0f; // UNUSED
+ const float image_cb = (in_image[1] * 2.0f) - 1.0f;
+ const float image_cr = (in_image[2] * 2.0f) - 1.0f;
+
+ // const float key_Y = (in_key[0] * 2.0f) - 1.0f; // UNUSED
+ const float key_cb = (in_key[1] * 2.0f) - 1.0f;
+ const float key_cr = (in_key[2] * 2.0f) - 1.0f;
+
+ const float theta = atan2(key_cr, key_cb);
+
+ /* Rotate the cb and cr into x/z space. */
+ const float x_angle = image_cb * cosf(theta) + image_cr * sinf(theta);
+ const float z_angle = image_cr * cosf(theta) - image_cb * sinf(theta);
+
+ /* If within the acceptance angle. */
+ /* If kfg is <0 then the pixel is outside of the key color. */
+ const float kfg = x_angle - (fabsf(z_angle) / tanf(acceptance / 2.0f));
+
+ if (kfg > 0.0f) { /* Found a pixel that is within key color. */
+ const float beta = atan2(z_angle, x_angle);
+ float alpha = 1.0f - (kfg / gain);
+
+ /* Ff beta is within the cutoff angle. */
+ if (fabsf(beta) < (cutoff / 2.0f)) {
+ alpha = 0.0f;
+ }
+
+ /* Don't make something that was more transparent less transparent. */
+ it.out[0] = alpha < in_image[3] ? alpha : in_image[3];
+ }
+ else { /* Pixel is outside key color. */
+ it.out[0] = in_image[3]; /* Make pixel just as transparent as it was before. */
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.h b/source/blender/compositor/operations/COM_ChromaMatteOperation.h
index 48c3a785011..065349910a7 100644
--- a/source/blender/compositor/operations/COM_ChromaMatteOperation.h
+++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class ChromaMatteOperation : public NodeOperation {
+class ChromaMatteOperation : public MultiThreadedOperation {
private:
NodeChroma *m_settings;
SocketReader *m_inputImageProgram;
@@ -50,6 +50,10 @@ class ChromaMatteOperation : public NodeOperation {
{
this->m_settings = nodeChroma;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.cc b/source/blender/compositor/operations/COM_ColorCurveOperation.cc
index cb0565a81a2..1b7ad0ea608 100644
--- a/source/blender/compositor/operations/COM_ColorCurveOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorCurveOperation.cc
@@ -98,6 +98,36 @@ void ColorCurveOperation::deinitExecution()
this->m_inputWhiteProgram = nullptr;
}
+void ColorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ CurveMapping *cumap = this->m_curveMapping;
+ float bwmul[3];
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ /* Local versions of `cumap->black` and `cumap->white`. */
+ const float *black = it.in(2);
+ const float *white = it.in(3);
+ /* Get a local `bwmul` value, it's not threadsafe using `cumap->bwmul` and others. */
+ BKE_curvemapping_set_black_white_ex(black, white, bwmul);
+
+ const float fac = *it.in(0);
+ const float *image = it.in(1);
+ if (fac >= 1.0f) {
+ BKE_curvemapping_evaluate_premulRGBF_ex(cumap, it.out, image, black, bwmul);
+ }
+ else if (fac <= 0.0f) {
+ copy_v3_v3(it.out, image);
+ }
+ else {
+ float col[4];
+ BKE_curvemapping_evaluate_premulRGBF_ex(cumap, col, image, black, bwmul);
+ interp_v3_v3v3(it.out, image, col, fac);
+ }
+ it.out[3] = image[3];
+ }
+}
+
// Constant level curve mapping
ConstantLevelColorCurveOperation::ConstantLevelColorCurveOperation()
@@ -154,4 +184,27 @@ void ConstantLevelColorCurveOperation::deinitExecution()
this->m_inputImageProgram = nullptr;
}
+void ConstantLevelColorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ CurveMapping *cumap = this->m_curveMapping;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float fac = *it.in(0);
+ const float *image = it.in(1);
+ if (fac >= 1.0f) {
+ BKE_curvemapping_evaluate_premulRGBF(cumap, it.out, image);
+ }
+ else if (fac <= 0.0f) {
+ copy_v3_v3(it.out, image);
+ }
+ else {
+ float col[4];
+ BKE_curvemapping_evaluate_premulRGBF(cumap, col, image);
+ interp_v3_v3v3(it.out, image, col, fac);
+ }
+ it.out[3] = image[3];
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.h b/source/blender/compositor/operations/COM_ColorCurveOperation.h
index 6fc7759b8d2..d8271e56d1d 100644
--- a/source/blender/compositor/operations/COM_ColorCurveOperation.h
+++ b/source/blender/compositor/operations/COM_ColorCurveOperation.h
@@ -51,6 +51,10 @@ class ColorCurveOperation : public CurveBaseOperation {
* Deinitialize the execution
*/
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
class ConstantLevelColorCurveOperation : public CurveBaseOperation {
@@ -89,6 +93,10 @@ class ConstantLevelColorCurveOperation : public CurveBaseOperation {
{
copy_v3_v3(this->m_white, white);
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.cc b/source/blender/compositor/operations/COM_ColorMatteOperation.cc
index ddfbf415d9c..dec6571f217 100644
--- a/source/blender/compositor/operations/COM_ColorMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorMatteOperation.cc
@@ -29,6 +29,7 @@ ColorMatteOperation::ColorMatteOperation()
this->m_inputImageProgram = nullptr;
this->m_inputKeyProgram = nullptr;
+ flags.can_be_constant = true;
}
void ColorMatteOperation::initExecution()
@@ -82,4 +83,40 @@ void ColorMatteOperation::executePixelSampled(float output[4],
}
}
+void ColorMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const float hue = m_settings->t1;
+ const float sat = m_settings->t2;
+ const float val = m_settings->t3;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *in_color = it.in(0);
+ const float *in_key = it.in(1);
+
+ /* Store matte(alpha) value in [0] to go with
+ * COM_SetAlphaMultiplyOperation and the Value output.
+ */
+
+ float h_wrap;
+ if (
+ /* Do hue last because it needs to wrap, and does some more checks. */
+
+ /* #sat */ (fabsf(in_color[1] - in_key[1]) < sat) &&
+ /* #val */ (fabsf(in_color[2] - in_key[2]) < val) &&
+
+ /* Multiply by 2 because it wraps on both sides of the hue,
+ * otherwise 0.5 would key all hue's. */
+
+ /* #hue */
+ ((h_wrap = 2.0f * fabsf(in_color[0] - in_key[0])) < hue || (2.0f - h_wrap) < hue)) {
+ it.out[0] = 0.0f; /* Make transparent. */
+ }
+
+ else { /* Pixel is outside key color. */
+ it.out[0] = in_color[3]; /* Make pixel just as transparent as it was before. */
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.h b/source/blender/compositor/operations/COM_ColorMatteOperation.h
index 439a3b0741d..49d06e62e65 100644
--- a/source/blender/compositor/operations/COM_ColorMatteOperation.h
+++ b/source/blender/compositor/operations/COM_ColorMatteOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class ColorMatteOperation : public NodeOperation {
+class ColorMatteOperation : public MultiThreadedOperation {
private:
NodeChroma *m_settings;
SocketReader *m_inputImageProgram;
@@ -50,6 +50,10 @@ class ColorMatteOperation : public NodeOperation {
{
this->m_settings = nodeChroma;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorRampOperation.cc b/source/blender/compositor/operations/COM_ColorRampOperation.cc
index 0ee65a6529e..6c1b23ea731 100644
--- a/source/blender/compositor/operations/COM_ColorRampOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorRampOperation.cc
@@ -29,6 +29,7 @@ ColorRampOperation::ColorRampOperation()
this->m_inputProgram = nullptr;
this->m_colorBand = nullptr;
+ this->flags.can_be_constant = true;
}
void ColorRampOperation::initExecution()
{
@@ -51,4 +52,13 @@ void ColorRampOperation::deinitExecution()
this->m_inputProgram = nullptr;
}
+void ColorRampOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ BKE_colorband_evaluate(m_colorBand, *it.in(0), it.out);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorRampOperation.h b/source/blender/compositor/operations/COM_ColorRampOperation.h
index d32af9bea24..ab64b9928fd 100644
--- a/source/blender/compositor/operations/COM_ColorRampOperation.h
+++ b/source/blender/compositor/operations/COM_ColorRampOperation.h
@@ -18,12 +18,12 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_texture_types.h"
namespace blender::compositor {
-class ColorRampOperation : public NodeOperation {
+class ColorRampOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -53,6 +53,10 @@ class ColorRampOperation : public NodeOperation {
{
this->m_colorBand = colorBand;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.cc b/source/blender/compositor/operations/COM_ColorSpillOperation.cc
index 7dc7e2775fc..4b0e0520b75 100644
--- a/source/blender/compositor/operations/COM_ColorSpillOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorSpillOperation.cc
@@ -32,6 +32,7 @@ ColorSpillOperation::ColorSpillOperation()
this->m_inputFacReader = nullptr;
this->m_spillChannel = 1; // GREEN
this->m_spillMethod = 0;
+ flags.can_be_constant = true;
}
void ColorSpillOperation::initExecution()
@@ -118,4 +119,36 @@ void ColorSpillOperation::executePixelSampled(float output[4],
}
}
+void ColorSpillOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color = it.in(0);
+ const float factor = MIN2(1.0f, *it.in(1));
+
+ float map;
+ switch (m_spillMethod) {
+ case 0: /* simple */
+ map = factor *
+ (color[m_spillChannel] - (m_settings->limscale * color[m_settings->limchan]));
+ break;
+ default: /* average */
+ map = factor * (color[m_spillChannel] -
+ (m_settings->limscale * AVG(color[m_channel2], color[m_channel3])));
+ break;
+ }
+
+ if (map > 0.0f) {
+ it.out[0] = color[0] + m_rmut * (m_settings->uspillr * map);
+ it.out[1] = color[1] + m_gmut * (m_settings->uspillg * map);
+ it.out[2] = color[2] + m_bmut * (m_settings->uspillb * map);
+ it.out[3] = color[3];
+ }
+ else {
+ copy_v4_v4(it.out, color);
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.h b/source/blender/compositor/operations/COM_ColorSpillOperation.h
index 9b82e720527..6a5e688c160 100644
--- a/source/blender/compositor/operations/COM_ColorSpillOperation.h
+++ b/source/blender/compositor/operations/COM_ColorSpillOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class ColorSpillOperation : public NodeOperation {
+class ColorSpillOperation : public MultiThreadedOperation {
protected:
NodeColorspill *m_settings;
SocketReader *m_inputImageReader;
@@ -65,6 +65,10 @@ class ColorSpillOperation : public NodeOperation {
}
float calculateMapValue(float fac, float *input);
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cc b/source/blender/compositor/operations/COM_CompositorOperation.cc
index 94d41b28f5d..8752d764107 100644
--- a/source/blender/compositor/operations/COM_CompositorOperation.cc
+++ b/source/blender/compositor/operations/COM_CompositorOperation.cc
@@ -220,6 +220,22 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/)
}
}
+void CompositorOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output),
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ if (!m_outputBuffer) {
+ return;
+ }
+ MemoryBuffer output_buf(m_outputBuffer, COM_DATA_TYPE_COLOR_CHANNELS, getWidth(), getHeight());
+ output_buf.copy_from(inputs[0], area);
+ if (this->m_useAlphaInput) {
+ output_buf.copy_from(inputs[1], area, 0, COM_DATA_TYPE_VALUE_CHANNELS, 3);
+ }
+ MemoryBuffer depth_buf(m_depthBuffer, COM_DATA_TYPE_VALUE_CHANNELS, getWidth(), getHeight());
+ depth_buf.copy_from(inputs[2], area);
+}
+
void CompositorOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h
index 65988c86cc5..66367ec8bae 100644
--- a/source/blender/compositor/operations/COM_CompositorOperation.h
+++ b/source/blender/compositor/operations/COM_CompositorOperation.h
@@ -20,7 +20,7 @@
#include "BLI_rect.h"
#include "BLI_string.h"
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
struct Scene;
@@ -29,7 +29,7 @@ namespace blender::compositor {
/**
* \brief Compositor output operation
*/
-class CompositorOperation : public NodeOperation {
+class CompositorOperation : public MultiThreadedOperation {
private:
const struct Scene *m_scene;
/**
@@ -125,6 +125,10 @@ class CompositorOperation : public NodeOperation {
{
this->m_active = active;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ConstantOperation.cc b/source/blender/compositor/operations/COM_ConstantOperation.cc
index f905edbde76..33d51cca432 100644
--- a/source/blender/compositor/operations/COM_ConstantOperation.cc
+++ b/source/blender/compositor/operations/COM_ConstantOperation.cc
@@ -22,7 +22,24 @@ namespace blender::compositor {
ConstantOperation::ConstantOperation()
{
+ needs_resolution_to_get_constant_ = false;
flags.is_constant_operation = true;
+ flags.is_fullframe_operation = true;
+}
+
+bool ConstantOperation::can_get_constant_elem() const
+{
+ return !needs_resolution_to_get_constant_ || this->flags.is_resolution_set;
+}
+
+void ConstantOperation::update_memory_buffer(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> UNUSED(inputs))
+{
+ BLI_assert(output->is_a_single_elem());
+ const float *constant = get_constant_elem();
+ float *out = output->get_elem(area.xmin, area.ymin);
+ memcpy(out, constant, output->get_elem_bytes_len());
}
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ConstantOperation.h b/source/blender/compositor/operations/COM_ConstantOperation.h
index 2709efeebd8..31b8d30254b 100644
--- a/source/blender/compositor/operations/COM_ConstantOperation.h
+++ b/source/blender/compositor/operations/COM_ConstantOperation.h
@@ -22,15 +22,27 @@
namespace blender::compositor {
+/* TODO(manzanilla): After removing tiled implementation, implement a default #determineResolution
+ * for all constant operations and make all initialization and deinitilization methods final. */
/**
- * Base class for primitive constant operations (Color/Vector/Value). The rest of operations that
- * can be constant are evaluated into primitives during constant folding.
+ * Base class for operations that are always constant. Operations that can be constant only when
+ * all their inputs are so, are evaluated into primitive constants (Color/Vector/Value) during
+ * constant folding.
*/
class ConstantOperation : public NodeOperation {
+ protected:
+ bool needs_resolution_to_get_constant_;
+
public:
ConstantOperation();
+ /** May require resolution to be already determined. */
virtual const float *get_constant_elem() = 0;
+ bool can_get_constant_elem() const;
+
+ void update_memory_buffer(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) final;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ConvertOperation.cc b/source/blender/compositor/operations/COM_ConvertOperation.cc
index 384936533c7..d377903efea 100644
--- a/source/blender/compositor/operations/COM_ConvertOperation.cc
+++ b/source/blender/compositor/operations/COM_ConvertOperation.cc
@@ -27,6 +27,7 @@ namespace blender::compositor {
ConvertBaseOperation::ConvertBaseOperation()
{
this->m_inputOperation = nullptr;
+ this->flags.can_be_constant = true;
}
void ConvertBaseOperation::initExecution()
@@ -39,6 +40,14 @@ void ConvertBaseOperation::deinitExecution()
this->m_inputOperation = nullptr;
}
+void ConvertBaseOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ BuffersIterator<float> it = output->iterate_with(inputs, area);
+ update_memory_buffer_partial(it);
+}
+
/* ******** Value to Color ******** */
ConvertValueToColorOperation::ConvertValueToColorOperation() : ConvertBaseOperation()
@@ -58,6 +67,14 @@ void ConvertValueToColorOperation::executePixelSampled(float output[4],
output[3] = 1.0f;
}
+void ConvertValueToColorOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ it.out[0] = it.out[1] = it.out[2] = *it.in(0);
+ it.out[3] = 1.0f;
+ }
+}
+
/* ******** Color to Value ******** */
ConvertColorToValueOperation::ConvertColorToValueOperation() : ConvertBaseOperation()
@@ -76,6 +93,14 @@ void ConvertColorToValueOperation::executePixelSampled(float output[4],
output[0] = (inputColor[0] + inputColor[1] + inputColor[2]) / 3.0f;
}
+void ConvertColorToValueOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ it.out[0] = (in[0] + in[1] + in[2]) / 3.0f;
+ }
+}
+
/* ******** Color to BW ******** */
ConvertColorToBWOperation::ConvertColorToBWOperation() : ConvertBaseOperation()
@@ -94,6 +119,13 @@ void ConvertColorToBWOperation::executePixelSampled(float output[4],
output[0] = IMB_colormanagement_get_luminance(inputColor);
}
+void ConvertColorToBWOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ it.out[0] = IMB_colormanagement_get_luminance(it.in(0));
+ }
+}
+
/* ******** Color to Vector ******** */
ConvertColorToVectorOperation::ConvertColorToVectorOperation() : ConvertBaseOperation()
@@ -112,6 +144,13 @@ void ConvertColorToVectorOperation::executePixelSampled(float output[4],
copy_v3_v3(output, color);
}
+void ConvertColorToVectorOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ copy_v3_v3(it.out, it.in(0));
+ }
+}
+
/* ******** Value to Vector ******** */
ConvertValueToVectorOperation::ConvertValueToVectorOperation() : ConvertBaseOperation()
@@ -130,6 +169,13 @@ void ConvertValueToVectorOperation::executePixelSampled(float output[4],
output[0] = output[1] = output[2] = value;
}
+void ConvertValueToVectorOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ it.out[0] = it.out[1] = it.out[2] = *it.in(0);
+ }
+}
+
/* ******** Vector to Color ******** */
ConvertVectorToColorOperation::ConvertVectorToColorOperation() : ConvertBaseOperation()
@@ -147,6 +193,14 @@ void ConvertVectorToColorOperation::executePixelSampled(float output[4],
output[3] = 1.0f;
}
+void ConvertVectorToColorOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ copy_v3_v3(it.out, it.in(0));
+ it.out[3] = 1.0f;
+ }
+}
+
/* ******** Vector to Value ******** */
ConvertVectorToValueOperation::ConvertVectorToValueOperation() : ConvertBaseOperation()
@@ -165,6 +219,14 @@ void ConvertVectorToValueOperation::executePixelSampled(float output[4],
output[0] = (input[0] + input[1] + input[2]) / 3.0f;
}
+void ConvertVectorToValueOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ it.out[0] = (in[0] + in[1] + in[2]) / 3.0f;
+ }
+}
+
/* ******** RGB to YCC ******** */
ConvertRGBToYCCOperation::ConvertRGBToYCCOperation() : ConvertBaseOperation()
@@ -207,6 +269,18 @@ void ConvertRGBToYCCOperation::executePixelSampled(float output[4],
output[3] = inputColor[3];
}
+void ConvertRGBToYCCOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ rgb_to_ycc(in[0], in[1], in[2], &it.out[0], &it.out[1], &it.out[2], this->m_mode);
+
+ /* Normalize for viewing (#rgb_to_ycc returns 0-255 values). */
+ mul_v3_fl(it.out, 1.0f / 255.0f);
+ it.out[3] = in[3];
+ }
+}
+
/* ******** YCC to RGB ******** */
ConvertYCCToRGBOperation::ConvertYCCToRGBOperation() : ConvertBaseOperation()
@@ -253,6 +327,22 @@ void ConvertYCCToRGBOperation::executePixelSampled(float output[4],
output[3] = inputColor[3];
}
+void ConvertYCCToRGBOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ /* Multiply by 255 to un-normalize (#ycc_to_rgb needs input values in 0-255 range). */
+ ycc_to_rgb(in[0] * 255.0f,
+ in[1] * 255.0f,
+ in[2] * 255.0f,
+ &it.out[0],
+ &it.out[1],
+ &it.out[2],
+ this->m_mode);
+ it.out[3] = in[3];
+ }
+}
+
/* ******** RGB to YUV ******** */
ConvertRGBToYUVOperation::ConvertRGBToYUVOperation() : ConvertBaseOperation()
@@ -278,6 +368,15 @@ void ConvertRGBToYUVOperation::executePixelSampled(float output[4],
output[3] = inputColor[3];
}
+void ConvertRGBToYUVOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ rgb_to_yuv(in[0], in[1], in[2], &it.out[0], &it.out[1], &it.out[2], BLI_YUV_ITU_BT709);
+ it.out[3] = in[3];
+ }
+}
+
/* ******** YUV to RGB ******** */
ConvertYUVToRGBOperation::ConvertYUVToRGBOperation() : ConvertBaseOperation()
@@ -303,6 +402,15 @@ void ConvertYUVToRGBOperation::executePixelSampled(float output[4],
output[3] = inputColor[3];
}
+void ConvertYUVToRGBOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ yuv_to_rgb(in[0], in[1], in[2], &it.out[0], &it.out[1], &it.out[2], BLI_YUV_ITU_BT709);
+ it.out[3] = in[3];
+ }
+}
+
/* ******** RGB to HSV ******** */
ConvertRGBToHSVOperation::ConvertRGBToHSVOperation() : ConvertBaseOperation()
@@ -322,6 +430,15 @@ void ConvertRGBToHSVOperation::executePixelSampled(float output[4],
output[3] = inputColor[3];
}
+void ConvertRGBToHSVOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ rgb_to_hsv_v(in, it.out);
+ it.out[3] = in[3];
+ }
+}
+
/* ******** HSV to RGB ******** */
ConvertHSVToRGBOperation::ConvertHSVToRGBOperation() : ConvertBaseOperation()
@@ -344,6 +461,18 @@ void ConvertHSVToRGBOperation::executePixelSampled(float output[4],
output[3] = inputColor[3];
}
+void ConvertHSVToRGBOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float *in = it.in(0);
+ hsv_to_rgb_v(in, it.out);
+ it.out[0] = max_ff(it.out[0], 0.0f);
+ it.out[1] = max_ff(it.out[1], 0.0f);
+ it.out[2] = max_ff(it.out[2], 0.0f);
+ it.out[3] = in[3];
+ }
+}
+
/* ******** Premul to Straight ******** */
ConvertPremulToStraightOperation::ConvertPremulToStraightOperation() : ConvertBaseOperation()
@@ -363,6 +492,13 @@ void ConvertPremulToStraightOperation::executePixelSampled(float output[4],
copy_v4_v4(output, converted);
}
+void ConvertPremulToStraightOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ copy_v4_v4(it.out, ColorSceneLinear4f<eAlpha::Premultiplied>(it.in(0)).unpremultiply_alpha());
+ }
+}
+
/* ******** Straight to Premul ******** */
ConvertStraightToPremulOperation::ConvertStraightToPremulOperation() : ConvertBaseOperation()
@@ -382,6 +518,13 @@ void ConvertStraightToPremulOperation::executePixelSampled(float output[4],
copy_v4_v4(output, converted);
}
+void ConvertStraightToPremulOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ copy_v4_v4(it.out, ColorSceneLinear4f<eAlpha::Straight>(it.in(0)).premultiply_alpha());
+ }
+}
+
/* ******** Separate Channels ******** */
SeparateChannelOperation::SeparateChannelOperation()
@@ -410,6 +553,15 @@ void SeparateChannelOperation::executePixelSampled(float output[4],
output[0] = input[this->m_channel];
}
+void SeparateChannelOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ it.out[0] = it.in(0)[this->m_channel];
+ }
+}
+
/* ******** Combine Channels ******** */
CombineChannelsOperation::CombineChannelsOperation()
@@ -466,4 +618,16 @@ void CombineChannelsOperation::executePixelSampled(float output[4],
}
}
+void CombineChannelsOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ it.out[0] = *it.in(0);
+ it.out[1] = *it.in(1);
+ it.out[2] = *it.in(2);
+ it.out[3] = *it.in(3);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ConvertOperation.h b/source/blender/compositor/operations/COM_ConvertOperation.h
index 7a726e35c7c..0334959ae7e 100644
--- a/source/blender/compositor/operations/COM_ConvertOperation.h
+++ b/source/blender/compositor/operations/COM_ConvertOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class ConvertBaseOperation : public NodeOperation {
+class ConvertBaseOperation : public MultiThreadedOperation {
protected:
SocketReader *m_inputOperation;
@@ -31,6 +31,13 @@ class ConvertBaseOperation : public NodeOperation {
void initExecution() override;
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) final;
+
+ protected:
+ virtual void update_memory_buffer_partial(BuffersIterator<float> &it) = 0;
};
class ConvertValueToColorOperation : public ConvertBaseOperation {
@@ -38,6 +45,9 @@ class ConvertValueToColorOperation : public ConvertBaseOperation {
ConvertValueToColorOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertColorToValueOperation : public ConvertBaseOperation {
@@ -45,6 +55,9 @@ class ConvertColorToValueOperation : public ConvertBaseOperation {
ConvertColorToValueOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertColorToBWOperation : public ConvertBaseOperation {
@@ -52,6 +65,9 @@ class ConvertColorToBWOperation : public ConvertBaseOperation {
ConvertColorToBWOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertColorToVectorOperation : public ConvertBaseOperation {
@@ -59,6 +75,9 @@ class ConvertColorToVectorOperation : public ConvertBaseOperation {
ConvertColorToVectorOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertValueToVectorOperation : public ConvertBaseOperation {
@@ -66,6 +85,9 @@ class ConvertValueToVectorOperation : public ConvertBaseOperation {
ConvertValueToVectorOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertVectorToColorOperation : public ConvertBaseOperation {
@@ -73,6 +95,9 @@ class ConvertVectorToColorOperation : public ConvertBaseOperation {
ConvertVectorToColorOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertVectorToValueOperation : public ConvertBaseOperation {
@@ -80,6 +105,9 @@ class ConvertVectorToValueOperation : public ConvertBaseOperation {
ConvertVectorToValueOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertRGBToYCCOperation : public ConvertBaseOperation {
@@ -94,6 +122,9 @@ class ConvertRGBToYCCOperation : public ConvertBaseOperation {
/** Set the YCC mode */
void setMode(int mode);
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertYCCToRGBOperation : public ConvertBaseOperation {
@@ -108,6 +139,9 @@ class ConvertYCCToRGBOperation : public ConvertBaseOperation {
/** Set the YCC mode */
void setMode(int mode);
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertRGBToYUVOperation : public ConvertBaseOperation {
@@ -115,6 +149,9 @@ class ConvertRGBToYUVOperation : public ConvertBaseOperation {
ConvertRGBToYUVOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertYUVToRGBOperation : public ConvertBaseOperation {
@@ -122,6 +159,9 @@ class ConvertYUVToRGBOperation : public ConvertBaseOperation {
ConvertYUVToRGBOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertRGBToHSVOperation : public ConvertBaseOperation {
@@ -129,6 +169,9 @@ class ConvertRGBToHSVOperation : public ConvertBaseOperation {
ConvertRGBToHSVOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertHSVToRGBOperation : public ConvertBaseOperation {
@@ -136,6 +179,9 @@ class ConvertHSVToRGBOperation : public ConvertBaseOperation {
ConvertHSVToRGBOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertPremulToStraightOperation : public ConvertBaseOperation {
@@ -143,6 +189,9 @@ class ConvertPremulToStraightOperation : public ConvertBaseOperation {
ConvertPremulToStraightOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class ConvertStraightToPremulOperation : public ConvertBaseOperation {
@@ -150,9 +199,12 @@ class ConvertStraightToPremulOperation : public ConvertBaseOperation {
ConvertStraightToPremulOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
-class SeparateChannelOperation : public NodeOperation {
+class SeparateChannelOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputOperation;
int m_channel;
@@ -168,9 +220,13 @@ class SeparateChannelOperation : public NodeOperation {
{
this->m_channel = channel;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
-class CombineChannelsOperation : public NodeOperation {
+class CombineChannelsOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputChannel1Operation;
SocketReader *m_inputChannel2Operation;
@@ -183,6 +239,10 @@ class CombineChannelsOperation : public NodeOperation {
void initExecution() override;
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_CropOperation.cc b/source/blender/compositor/operations/COM_CropOperation.cc
index f12d93bc8d3..12833660fcb 100644
--- a/source/blender/compositor/operations/COM_CropOperation.cc
+++ b/source/blender/compositor/operations/COM_CropOperation.cc
@@ -95,6 +95,22 @@ void CropOperation::executePixelSampled(float output[4], float x, float y, Pixel
}
}
+void CropOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ rcti crop_area;
+ BLI_rcti_init(&crop_area, m_xmin, m_xmax, m_ymin, m_ymax);
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ if (BLI_rcti_isect_pt(&crop_area, it.x, it.y)) {
+ copy_v4_v4(it.out, it.in(0));
+ }
+ else {
+ zero_v4(it.out);
+ }
+ }
+}
+
CropImageOperation::CropImageOperation() : CropBaseOperation()
{
/* pass */
@@ -114,6 +130,18 @@ bool CropImageOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void CropImageOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ BLI_assert(input_idx == 0);
+ UNUSED_VARS_NDEBUG(input_idx);
+ r_input_area.xmax = output_area.xmax + this->m_xmin;
+ r_input_area.xmin = output_area.xmin + this->m_xmin;
+ r_input_area.ymax = output_area.ymax + this->m_ymin;
+ r_input_area.ymin = output_area.ymin + this->m_ymin;
+}
+
void CropImageOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
@@ -136,4 +164,21 @@ void CropImageOperation::executePixelSampled(float output[4],
}
}
+void CropImageOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ rcti op_area;
+ BLI_rcti_init(&op_area, 0, getWidth(), 0, getHeight());
+ const MemoryBuffer *input = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ if (BLI_rcti_isect_pt(&op_area, it.x, it.y)) {
+ input->read_elem_checked(it.x + this->m_xmin, it.y + this->m_ymin, it.out);
+ }
+ else {
+ zero_v4(it.out);
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_CropOperation.h b/source/blender/compositor/operations/COM_CropOperation.h
index acdff79a77c..57caa4e5834 100644
--- a/source/blender/compositor/operations/COM_CropOperation.h
+++ b/source/blender/compositor/operations/COM_CropOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class CropBaseOperation : public NodeOperation {
+class CropBaseOperation : public MultiThreadedOperation {
protected:
SocketReader *m_inputOperation;
NodeTwoXYs *m_settings;
@@ -53,6 +53,10 @@ class CropOperation : public CropBaseOperation {
public:
CropOperation();
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
class CropImageOperation : public CropBaseOperation {
@@ -65,6 +69,11 @@ class CropImageOperation : public CropBaseOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.cc b/source/blender/compositor/operations/COM_CryptomatteOperation.cc
index 1a86fadad76..02e7c5607d8 100644
--- a/source/blender/compositor/operations/COM_CryptomatteOperation.cc
+++ b/source/blender/compositor/operations/COM_CryptomatteOperation.cc
@@ -71,4 +71,34 @@ void CryptomatteOperation::executePixel(float output[4], int x, int y, void *dat
}
}
+void CryptomatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ zero_v4(it.out);
+ for (int i = 0; i < it.get_num_inputs(); i++) {
+ const float *input = it.in(i);
+ if (i == 0) {
+ /* Write the front-most object as false color for picking. */
+ it.out[0] = input[0];
+ uint32_t m3hash;
+ ::memcpy(&m3hash, &input[0], sizeof(uint32_t));
+ /* Since the red channel is likely to be out of display range,
+ * setting green and blue gives more meaningful images. */
+ it.out[1] = ((float)(m3hash << 8) / (float)UINT32_MAX);
+ it.out[2] = ((float)(m3hash << 16) / (float)UINT32_MAX);
+ }
+ for (const float hash : m_objectIndex) {
+ if (input[0] == hash) {
+ it.out[3] += input[1];
+ }
+ if (input[2] == hash) {
+ it.out[3] += input[3];
+ }
+ }
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.h b/source/blender/compositor/operations/COM_CryptomatteOperation.h
index 1b91358d228..f1bf4cdf624 100644
--- a/source/blender/compositor/operations/COM_CryptomatteOperation.h
+++ b/source/blender/compositor/operations/COM_CryptomatteOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class CryptomatteOperation : public NodeOperation {
+class CryptomatteOperation : public MultiThreadedOperation {
private:
Vector<float> m_objectIndex;
@@ -35,6 +35,10 @@ class CryptomatteOperation : public NodeOperation {
void executePixel(float output[4], int x, int y, void *data) override;
void addObjectIndex(float objectIndex);
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_CurveBaseOperation.cc b/source/blender/compositor/operations/COM_CurveBaseOperation.cc
index 8f655964570..3c4b27aa4cf 100644
--- a/source/blender/compositor/operations/COM_CurveBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_CurveBaseOperation.cc
@@ -25,6 +25,7 @@ namespace blender::compositor {
CurveBaseOperation::CurveBaseOperation()
{
this->m_curveMapping = nullptr;
+ this->flags.can_be_constant = true;
}
CurveBaseOperation::~CurveBaseOperation()
diff --git a/source/blender/compositor/operations/COM_CurveBaseOperation.h b/source/blender/compositor/operations/COM_CurveBaseOperation.h
index fff0f3168ba..da665e7ea60 100644
--- a/source/blender/compositor/operations/COM_CurveBaseOperation.h
+++ b/source/blender/compositor/operations/COM_CurveBaseOperation.h
@@ -18,12 +18,12 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_color_types.h"
namespace blender::compositor {
-class CurveBaseOperation : public NodeOperation {
+class CurveBaseOperation : public MultiThreadedOperation {
protected:
/**
* Cached reference to the inputProgram
diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc
index 0acdfc1651f..31714b03b06 100644
--- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc
@@ -29,6 +29,7 @@ DifferenceMatteOperation::DifferenceMatteOperation()
this->m_inputImage1Program = nullptr;
this->m_inputImage2Program = nullptr;
+ flags.can_be_constant = true;
}
void DifferenceMatteOperation::initExecution()
@@ -86,4 +87,44 @@ void DifferenceMatteOperation::executePixelSampled(float output[4],
}
}
+void DifferenceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color1 = it.in(0);
+ const float *color2 = it.in(1);
+
+ float difference = (fabsf(color2[0] - color1[0]) + fabsf(color2[1] - color1[1]) +
+ fabsf(color2[2] - color1[2]));
+
+ /* Average together the distances. */
+ difference = difference / 3.0f;
+
+ const float tolerance = m_settings->t1;
+ const float falloff = m_settings->t2;
+
+ /* Make 100% transparent. */
+ if (difference <= tolerance) {
+ it.out[0] = 0.0f;
+ }
+ /* In the falloff region, make partially transparent. */
+ else if (difference <= falloff + tolerance) {
+ difference = difference - tolerance;
+ const float alpha = difference / falloff;
+ /* Only change if more transparent than before. */
+ if (alpha < color1[3]) {
+ it.out[0] = alpha;
+ }
+ else { /* Leave as before. */
+ it.out[0] = color1[3];
+ }
+ }
+ else {
+ /* Foreground object. */
+ it.out[0] = color1[3];
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h
index d3963fee1c1..0a86535d946 100644
--- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h
+++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class DifferenceMatteOperation : public NodeOperation {
+class DifferenceMatteOperation : public MultiThreadedOperation {
private:
NodeChroma *m_settings;
SocketReader *m_inputImage1Program;
@@ -50,6 +50,10 @@ class DifferenceMatteOperation : public NodeOperation {
{
this->m_settings = nodeChroma;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cc b/source/blender/compositor/operations/COM_DilateErodeOperation.cc
index c67a35b686c..a27148f967d 100644
--- a/source/blender/compositor/operations/COM_DilateErodeOperation.cc
+++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cc
@@ -500,7 +500,7 @@ void *ErodeStepOperation::initializeTileData(rcti *rect)
int bwidth = rect->xmax - rect->xmin;
int bheight = rect->ymax - rect->ymin;
- /* NOTE: Cache buffer has original tilesize width, but new height.
+ /* NOTE: Cache buffer has original tile-size width, but new height.
* We have to calculate the additional rows in the first pass,
* to have valid data available for the second pass. */
tile_info *result = create_cache(rect->xmin, rect->xmax, ymin, ymax);
diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.cc b/source/blender/compositor/operations/COM_DisplaceOperation.cc
index 9f3f5cfe489..a4c01fda7ca 100644
--- a/source/blender/compositor/operations/COM_DisplaceOperation.cc
+++ b/source/blender/compositor/operations/COM_DisplaceOperation.cc
@@ -32,20 +32,30 @@ DisplaceOperation::DisplaceOperation()
this->flags.complex = true;
this->m_inputColorProgram = nullptr;
- this->m_inputVectorProgram = nullptr;
- this->m_inputScaleXProgram = nullptr;
- this->m_inputScaleYProgram = nullptr;
}
void DisplaceOperation::initExecution()
{
this->m_inputColorProgram = this->getInputSocketReader(0);
- this->m_inputVectorProgram = this->getInputSocketReader(1);
- this->m_inputScaleXProgram = this->getInputSocketReader(2);
- this->m_inputScaleYProgram = this->getInputSocketReader(3);
+ NodeOperation *vector = this->getInputSocketReader(1);
+ NodeOperation *scale_x = this->getInputSocketReader(2);
+ NodeOperation *scale_y = this->getInputSocketReader(3);
+ if (execution_model_ == eExecutionModel::Tiled) {
+ vector_read_fn_ = [=](float x, float y, float *out) {
+ vector->readSampled(out, x, y, PixelSampler::Bilinear);
+ };
+ scale_x_read_fn_ = [=](float x, float y, float *out) {
+ scale_x->readSampled(out, x, y, PixelSampler::Nearest);
+ };
+ scale_y_read_fn_ = [=](float x, float y, float *out) {
+ scale_y->readSampled(out, x, y, PixelSampler::Nearest);
+ };
+ }
this->m_width_x4 = this->getWidth() * 4;
this->m_height_x4 = this->getHeight() * 4;
+ input_vector_width_ = vector->getWidth();
+ input_vector_height_ = vector->getHeight();
}
void DisplaceOperation::executePixelSampled(float output[4],
@@ -69,8 +79,8 @@ void DisplaceOperation::executePixelSampled(float output[4],
bool DisplaceOperation::read_displacement(
float x, float y, float xscale, float yscale, const float origin[2], float &r_u, float &r_v)
{
- float width = m_inputVectorProgram->getWidth();
- float height = m_inputVectorProgram->getHeight();
+ float width = input_vector_width_;
+ float height = input_vector_height_;
if (x < 0.0f || x >= width || y < 0.0f || y >= height) {
r_u = 0.0f;
r_v = 0.0f;
@@ -78,7 +88,7 @@ bool DisplaceOperation::read_displacement(
}
float col[4];
- m_inputVectorProgram->readSampled(col, x, y, PixelSampler::Bilinear);
+ vector_read_fn_(x, y, col);
r_u = origin[0] - col[0] * xscale;
r_v = origin[1] - col[1] * yscale;
return true;
@@ -90,9 +100,9 @@ void DisplaceOperation::pixelTransform(const float xy[2], float r_uv[2], float r
float uv[2]; /* temporary variables for derivative estimation */
int num;
- m_inputScaleXProgram->readSampled(col, xy[0], xy[1], PixelSampler::Nearest);
+ scale_x_read_fn_(xy[0], xy[1], col);
float xs = col[0];
- m_inputScaleYProgram->readSampled(col, xy[0], xy[1], PixelSampler::Nearest);
+ scale_y_read_fn_(xy[0], xy[1], col);
float ys = col[0];
/* clamp x and y displacement to triple image resolution -
* to prevent hangs from huge values mistakenly plugged in eg. z buffers */
@@ -146,9 +156,9 @@ void DisplaceOperation::pixelTransform(const float xy[2], float r_uv[2], float r
void DisplaceOperation::deinitExecution()
{
this->m_inputColorProgram = nullptr;
- this->m_inputVectorProgram = nullptr;
- this->m_inputScaleXProgram = nullptr;
- this->m_inputScaleYProgram = nullptr;
+ vector_read_fn_ = nullptr;
+ scale_x_read_fn_ = nullptr;
+ scale_y_read_fn_ = nullptr;
}
bool DisplaceOperation::determineDependingAreaOfInterest(rcti *input,
@@ -195,4 +205,61 @@ bool DisplaceOperation::determineDependingAreaOfInterest(rcti *input,
return false;
}
+void DisplaceOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case 0: {
+ r_input_area.xmin = 0;
+ r_input_area.ymin = 0;
+ r_input_area.xmax = getInputOperation(input_idx)->getWidth();
+ r_input_area.ymax = getInputOperation(input_idx)->getHeight();
+ break;
+ }
+ case 1: {
+ r_input_area = output_area;
+ expand_area_for_sampler(r_input_area, PixelSampler::Bilinear);
+ break;
+ }
+ default: {
+ r_input_area = output_area;
+ break;
+ }
+ }
+}
+
+void DisplaceOperation::update_memory_buffer_started(MemoryBuffer *UNUSED(output),
+ const rcti &UNUSED(area),
+ Span<MemoryBuffer *> inputs)
+{
+ MemoryBuffer *vector = inputs[1];
+ MemoryBuffer *scale_x = inputs[2];
+ MemoryBuffer *scale_y = inputs[3];
+ vector_read_fn_ = [=](float x, float y, float *out) { vector->read_elem_bilinear(x, y, out); };
+ scale_x_read_fn_ = [=](float x, float y, float *out) { scale_x->read_elem_checked(x, y, out); };
+ scale_y_read_fn_ = [=](float x, float y, float *out) { scale_y->read_elem_checked(x, y, out); };
+}
+
+void DisplaceOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_color = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ const float xy[2] = {(float)it.x, (float)it.y};
+ float uv[2];
+ float deriv[2][2];
+
+ pixelTransform(xy, uv, deriv);
+ if (is_zero_v2(deriv[0]) && is_zero_v2(deriv[1])) {
+ input_color->read_elem_bilinear(uv[0], uv[1], it.out);
+ }
+ else {
+ /* EWA filtering (without nearest it gets blurry with NO distortion). */
+ input_color->read_elem_filtered(uv[0], uv[1], deriv[0], deriv[1], it.out);
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.h b/source/blender/compositor/operations/COM_DisplaceOperation.h
index fd82692f687..5be914ab672 100644
--- a/source/blender/compositor/operations/COM_DisplaceOperation.h
+++ b/source/blender/compositor/operations/COM_DisplaceOperation.h
@@ -18,23 +18,27 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class DisplaceOperation : public NodeOperation {
+class DisplaceOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
*/
SocketReader *m_inputColorProgram;
- SocketReader *m_inputVectorProgram;
- SocketReader *m_inputScaleXProgram;
- SocketReader *m_inputScaleYProgram;
float m_width_x4;
float m_height_x4;
+ int input_vector_width_;
+ int input_vector_height_;
+
+ std::function<void(float x, float y, float *out)> vector_read_fn_;
+ std::function<void(float x, float y, float *out)> scale_x_read_fn_;
+ std::function<void(float x, float y, float *out)> scale_y_read_fn_;
+
public:
DisplaceOperation();
@@ -62,6 +66,14 @@ class DisplaceOperation : public NodeOperation {
*/
void deinitExecution() override;
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_started(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
private:
bool read_displacement(
float x, float y, float xscale, float yscale, const float origin[2], float &r_u, float &r_v);
diff --git a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc
index f4b77f5d32c..e1c531bd49e 100644
--- a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc
+++ b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc
@@ -132,4 +132,56 @@ bool DisplaceSimpleOperation::determineDependingAreaOfInterest(rcti *input,
return false;
}
+void DisplaceSimpleOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case 0: {
+ r_input_area.xmin = 0;
+ r_input_area.ymin = 0;
+ r_input_area.xmax = getInputOperation(input_idx)->getWidth();
+ r_input_area.ymax = getInputOperation(input_idx)->getHeight();
+ break;
+ }
+ default: {
+ r_input_area = output_area;
+ break;
+ }
+ }
+}
+
+void DisplaceSimpleOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const float width = this->getWidth();
+ const float height = this->getHeight();
+ const MemoryBuffer *input_color = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with(inputs.drop_front(1), area); !it.is_end();
+ ++it) {
+ float scale_x = *it.in(1);
+ float scale_y = *it.in(2);
+
+ /* Clamp x and y displacement to triple image resolution -
+ * to prevent hangs from huge values mistakenly plugged in eg. z buffers. */
+ CLAMP(scale_x, -m_width_x4, m_width_x4);
+ CLAMP(scale_y, -m_height_x4, m_height_x4);
+
+ /* Main displacement in pixel space. */
+ const float *vector = it.in(0);
+ const float p_dx = vector[0] * scale_x;
+ const float p_dy = vector[1] * scale_y;
+
+ /* Displaced pixel in uv coords, for image sampling. */
+ /* Clamp nodes to avoid glitches. */
+ float u = it.x - p_dx + 0.5f;
+ float v = it.y - p_dy + 0.5f;
+ CLAMP(u, 0.0f, width - 1.0f);
+ CLAMP(v, 0.0f, height - 1.0f);
+
+ input_color->read_elem_checked(u, v, it.out);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h
index 15e6fcd0523..99f52155466 100644
--- a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h
+++ b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class DisplaceSimpleOperation : public NodeOperation {
+class DisplaceSimpleOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -59,6 +59,11 @@ class DisplaceSimpleOperation : public NodeOperation {
* Deinitialize the execution
*/
void deinitExecution() override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc
index 1b3403cbb29..8155ff769a0 100644
--- a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc
@@ -29,6 +29,7 @@ DistanceRGBMatteOperation::DistanceRGBMatteOperation()
this->m_inputImageProgram = nullptr;
this->m_inputKeyProgram = nullptr;
+ flags.can_be_constant = true;
}
void DistanceRGBMatteOperation::initExecution()
@@ -43,7 +44,7 @@ void DistanceRGBMatteOperation::deinitExecution()
this->m_inputKeyProgram = nullptr;
}
-float DistanceRGBMatteOperation::calculateDistance(float key[4], float image[4])
+float DistanceRGBMatteOperation::calculateDistance(const float key[4], const float image[4])
{
return len_v3v3(key, image);
}
@@ -93,4 +94,43 @@ void DistanceRGBMatteOperation::executePixelSampled(float output[4],
}
}
+void DistanceRGBMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *in_image = it.in(0);
+ const float *in_key = it.in(1);
+
+ float distance = this->calculateDistance(in_key, in_image);
+ const float tolerance = this->m_settings->t1;
+ const float falloff = this->m_settings->t2;
+
+ /* Store matte(alpha) value in [0] to go with
+ * COM_SetAlphaMultiplyOperation and the Value output.
+ */
+
+ /* Make 100% transparent. */
+ if (distance < tolerance) {
+ it.out[0] = 0.0f;
+ }
+ /* In the falloff region, make partially transparent. */
+ else if (distance < falloff + tolerance) {
+ distance = distance - tolerance;
+ const float alpha = distance / falloff;
+ /* Only change if more transparent than before. */
+ if (alpha < in_image[3]) {
+ it.out[0] = alpha;
+ }
+ else { /* Leave as before. */
+ it.out[0] = in_image[3];
+ }
+ }
+ else {
+ /* Leave as before. */
+ it.out[0] = in_image[3];
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h
index 6fe603233b7..ba6682214ae 100644
--- a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h
+++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,13 +26,13 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class DistanceRGBMatteOperation : public NodeOperation {
+class DistanceRGBMatteOperation : public MultiThreadedOperation {
protected:
NodeChroma *m_settings;
SocketReader *m_inputImageProgram;
SocketReader *m_inputKeyProgram;
- virtual float calculateDistance(float key[4], float image[4]);
+ virtual float calculateDistance(const float key[4], const float image[4]);
public:
/**
@@ -52,6 +52,10 @@ class DistanceRGBMatteOperation : public NodeOperation {
{
this->m_settings = nodeChroma;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cc b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cc
index 597545dd706..50e473ea5b3 100644
--- a/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.cc
@@ -21,7 +21,7 @@
namespace blender::compositor {
-float DistanceYCCMatteOperation::calculateDistance(float key[4], float image[4])
+float DistanceYCCMatteOperation::calculateDistance(const float key[4], const float image[4])
{
/* only measure the second 2 values */
return len_v2v2(key + 1, image + 1);
diff --git a/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h
index a87e885e5d8..0e178fddc39 100644
--- a/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h
+++ b/source/blender/compositor/operations/COM_DistanceYCCMatteOperation.h
@@ -29,7 +29,7 @@ namespace blender::compositor {
*/
class DistanceYCCMatteOperation : public DistanceRGBMatteOperation {
protected:
- float calculateDistance(float key[4], float image[4]) override;
+ float calculateDistance(const float key[4], const float image[4]) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
index 3804e6ec646..e0fc45811cb 100644
--- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
@@ -62,6 +62,13 @@ bool FastGaussianBlurOperation::determineDependingAreaOfInterest(
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void FastGaussianBlurOperation::init_data()
+{
+ BlurBaseOperation::init_data();
+ this->m_sx = this->m_data.sizex * this->m_size / 2.0f;
+ this->m_sy = this->m_data.sizey * this->m_size / 2.0f;
+}
+
void FastGaussianBlurOperation::initExecution()
{
BlurBaseOperation::initExecution();
@@ -117,6 +124,7 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src,
unsigned int chan,
unsigned int xy)
{
+ BLI_assert(!src->is_a_single_elem());
double q, q2, sc, cf[4], tsM[9], tsu[3], tsv[3];
double *X, *Y, *W;
const unsigned int src_width = src->getWidth();
@@ -257,6 +265,64 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src,
#undef YVV
}
+void FastGaussianBlurOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case IMAGE_INPUT_INDEX:
+ r_input_area.xmin = 0;
+ r_input_area.xmax = getWidth();
+ r_input_area.ymin = 0;
+ r_input_area.ymax = getHeight();
+ break;
+ default:
+ BlurBaseOperation::get_area_of_interest(input_idx, output_area, r_input_area);
+ return;
+ }
+}
+
+void FastGaussianBlurOperation::update_memory_buffer_started(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ /* TODO(manzanilla): Add a render test and make #IIR_gauss multi-threaded with support for
+ * an output buffer. */
+ const MemoryBuffer *input = inputs[IMAGE_INPUT_INDEX];
+ MemoryBuffer *image = nullptr;
+ const bool is_full_output = BLI_rcti_compare(&output->get_rect(), &area);
+ if (is_full_output) {
+ image = output;
+ }
+ else {
+ image = new MemoryBuffer(getOutputSocket()->getDataType(), area);
+ }
+ image->copy_from(input, area);
+
+ if ((this->m_sx == this->m_sy) && (this->m_sx > 0.0f)) {
+ for (const int c : IndexRange(COM_DATA_TYPE_COLOR_CHANNELS)) {
+ IIR_gauss(image, this->m_sx, c, 3);
+ }
+ }
+ else {
+ if (this->m_sx > 0.0f) {
+ for (const int c : IndexRange(COM_DATA_TYPE_COLOR_CHANNELS)) {
+ IIR_gauss(image, this->m_sx, c, 1);
+ }
+ }
+ if (this->m_sy > 0.0f) {
+ for (const int c : IndexRange(COM_DATA_TYPE_COLOR_CHANNELS)) {
+ IIR_gauss(image, this->m_sy, c, 2);
+ }
+ }
+ }
+
+ if (!is_full_output) {
+ output->copy_from(image, area);
+ delete image;
+ }
+}
+
FastGaussianBlurValueOperation::FastGaussianBlurValueOperation()
{
this->addInputSocket(DataType::Value);
@@ -341,4 +407,44 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
return this->m_iirgaus;
}
+void FastGaussianBlurValueOperation::get_area_of_interest(const int UNUSED(input_idx),
+ const rcti &UNUSED(output_area),
+ rcti &r_input_area)
+{
+ r_input_area.xmin = 0;
+ r_input_area.xmax = getWidth();
+ r_input_area.ymin = 0;
+ r_input_area.ymax = getHeight();
+}
+
+void FastGaussianBlurValueOperation::update_memory_buffer_started(MemoryBuffer *UNUSED(output),
+ const rcti &UNUSED(area),
+ Span<MemoryBuffer *> inputs)
+{
+ if (m_iirgaus == nullptr) {
+ const MemoryBuffer *image = inputs[0];
+ MemoryBuffer *gauss = new MemoryBuffer(*image);
+ FastGaussianBlurOperation::IIR_gauss(gauss, m_sigma, 0, 3);
+ m_iirgaus = gauss;
+ }
+}
+
+void FastGaussianBlurValueOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ MemoryBuffer *image = inputs[0];
+ BuffersIterator<float> it = output->iterate_with({image, m_iirgaus}, area);
+ if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) {
+ for (; !it.is_end(); ++it) {
+ *it.out = MIN2(*it.in(0), *it.in(1));
+ }
+ }
+ else if (this->m_overlay == FAST_GAUSS_OVERLAY_MAX) {
+ for (; !it.is_end(); ++it) {
+ *it.out = MAX2(*it.in(0), *it.in(1));
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h
index c25afe6c4a4..f42fc76a119 100644
--- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h
+++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h
@@ -38,8 +38,19 @@ class FastGaussianBlurOperation : public BlurBaseOperation {
static void IIR_gauss(MemoryBuffer *src, float sigma, unsigned int channel, unsigned int xy);
void *initializeTileData(rcti *rect) override;
+ void init_data() override;
void deinitExecution() override;
void initExecution() override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_started(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+ void update_memory_buffer_partial(MemoryBuffer *UNUSED(output),
+ const rcti &UNUSED(area),
+ Span<MemoryBuffer *> UNUSED(inputs)) override
+ {
+ }
};
enum {
@@ -48,7 +59,7 @@ enum {
FAST_GAUSS_OVERLAY_MAX = 1,
};
-class FastGaussianBlurValueOperation : public NodeOperation {
+class FastGaussianBlurValueOperation : public MultiThreadedOperation {
private:
float m_sigma;
MemoryBuffer *m_iirgaus;
@@ -80,6 +91,14 @@ class FastGaussianBlurValueOperation : public NodeOperation {
{
this->m_overlay = overlay;
}
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_started(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_FlipOperation.cc b/source/blender/compositor/operations/COM_FlipOperation.cc
index 8afbec4ddbe..d0dc6c0b570 100644
--- a/source/blender/compositor/operations/COM_FlipOperation.cc
+++ b/source/blender/compositor/operations/COM_FlipOperation.cc
@@ -75,4 +75,42 @@ bool FlipOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void FlipOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ BLI_assert(input_idx == 0);
+ UNUSED_VARS_NDEBUG(input_idx);
+ if (this->m_flipX) {
+ const int w = (int)this->getWidth() - 1;
+ r_input_area.xmax = (w - output_area.xmin) + 1;
+ r_input_area.xmin = (w - output_area.xmax) - 1;
+ }
+ else {
+ r_input_area.xmin = output_area.xmin;
+ r_input_area.xmax = output_area.xmax;
+ }
+ if (this->m_flipY) {
+ const int h = (int)this->getHeight() - 1;
+ r_input_area.ymax = (h - output_area.ymin) + 1;
+ r_input_area.ymin = (h - output_area.ymax) - 1;
+ }
+ else {
+ r_input_area.ymin = output_area.ymin;
+ r_input_area.ymax = output_area.ymax;
+ }
+}
+
+void FlipOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_img = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ const int nx = this->m_flipX ? ((int)this->getWidth() - 1) - it.x : it.x;
+ const int ny = this->m_flipY ? ((int)this->getHeight() - 1) - it.y : it.y;
+ input_img->read_elem(nx, ny, it.out);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_FlipOperation.h b/source/blender/compositor/operations/COM_FlipOperation.h
index f26d587fde6..dba7f82c341 100644
--- a/source/blender/compositor/operations/COM_FlipOperation.h
+++ b/source/blender/compositor/operations/COM_FlipOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class FlipOperation : public NodeOperation {
+class FlipOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputOperation;
bool m_flipX;
@@ -45,6 +45,11 @@ class FlipOperation : public NodeOperation {
{
this->m_flipY = flipY;
}
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.cc b/source/blender/compositor/operations/COM_GammaCorrectOperation.cc
index 16b79fddd06..1bff3b965c6 100644
--- a/source/blender/compositor/operations/COM_GammaCorrectOperation.cc
+++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.cc
@@ -26,6 +26,7 @@ GammaCorrectOperation::GammaCorrectOperation()
this->addInputSocket(DataType::Color);
this->addOutputSocket(DataType::Color);
this->m_inputProgram = nullptr;
+ flags.can_be_constant = true;
}
void GammaCorrectOperation::initExecution()
{
@@ -58,6 +59,34 @@ void GammaCorrectOperation::executePixelSampled(float output[4],
}
}
+void GammaCorrectOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ float color[4];
+ input->read_elem(it.x, it.y, color);
+ if (color[3] > 0.0f) {
+ color[0] /= color[3];
+ color[1] /= color[3];
+ color[2] /= color[3];
+ }
+
+ /* Check for negative to avoid nan's. */
+ it.out[0] = color[0] > 0.0f ? color[0] * color[0] : 0.0f;
+ it.out[1] = color[1] > 0.0f ? color[1] * color[1] : 0.0f;
+ it.out[2] = color[2] > 0.0f ? color[2] * color[2] : 0.0f;
+ it.out[3] = color[3];
+
+ if (color[3] > 0.0f) {
+ it.out[0] *= color[3];
+ it.out[1] *= color[3];
+ it.out[2] *= color[3];
+ }
+ }
+}
+
void GammaCorrectOperation::deinitExecution()
{
this->m_inputProgram = nullptr;
@@ -68,6 +97,7 @@ GammaUncorrectOperation::GammaUncorrectOperation()
this->addInputSocket(DataType::Color);
this->addOutputSocket(DataType::Color);
this->m_inputProgram = nullptr;
+ flags.can_be_constant = true;
}
void GammaUncorrectOperation::initExecution()
{
@@ -100,6 +130,33 @@ void GammaUncorrectOperation::executePixelSampled(float output[4],
}
}
+void GammaUncorrectOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ float color[4];
+ input->read_elem(it.x, it.y, color);
+ if (color[3] > 0.0f) {
+ color[0] /= color[3];
+ color[1] /= color[3];
+ color[2] /= color[3];
+ }
+
+ it.out[0] = color[0] > 0.0f ? sqrtf(color[0]) : 0.0f;
+ it.out[1] = color[1] > 0.0f ? sqrtf(color[1]) : 0.0f;
+ it.out[2] = color[2] > 0.0f ? sqrtf(color[2]) : 0.0f;
+ it.out[3] = color[3];
+
+ if (color[3] > 0.0f) {
+ it.out[0] *= color[3];
+ it.out[1] *= color[3];
+ it.out[2] *= color[3];
+ }
+ }
+}
+
void GammaUncorrectOperation::deinitExecution()
{
this->m_inputProgram = nullptr;
diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.h b/source/blender/compositor/operations/COM_GammaCorrectOperation.h
index ac3d45b94b1..2a9fde70e87 100644
--- a/source/blender/compositor/operations/COM_GammaCorrectOperation.h
+++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class GammaCorrectOperation : public NodeOperation {
+class GammaCorrectOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -46,9 +46,13 @@ class GammaCorrectOperation : public NodeOperation {
* Deinitialize the execution
*/
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
-class GammaUncorrectOperation : public NodeOperation {
+class GammaUncorrectOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -72,6 +76,10 @@ class GammaUncorrectOperation : public NodeOperation {
* Deinitialize the execution
*/
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc
new file mode 100644
index 00000000000..9bdc652b466
--- /dev/null
+++ b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc
@@ -0,0 +1,168 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#include "COM_GaussianAlphaBlurBaseOperation.h"
+
+namespace blender::compositor {
+
+GaussianAlphaBlurBaseOperation::GaussianAlphaBlurBaseOperation(eDimension dim)
+ : BlurBaseOperation(DataType::Value)
+{
+ this->m_gausstab = nullptr;
+ this->m_filtersize = 0;
+ this->m_falloff = -1; /* Intentionally invalid, so we can detect uninitialized values. */
+ dimension_ = dim;
+}
+
+void GaussianAlphaBlurBaseOperation::init_data()
+{
+ BlurBaseOperation::init_data();
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ rad_ = max_ff(m_size * this->get_blur_size(dimension_), 0.0f);
+ rad_ = min_ff(rad_, MAX_GAUSSTAB_RADIUS);
+ m_filtersize = min_ii(ceil(rad_), MAX_GAUSSTAB_RADIUS);
+ }
+}
+
+void GaussianAlphaBlurBaseOperation::initExecution()
+{
+ BlurBaseOperation::initExecution();
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ m_gausstab = BlurBaseOperation::make_gausstab(rad_, m_filtersize);
+ m_distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad_, m_filtersize, m_falloff);
+ }
+}
+
+void GaussianAlphaBlurBaseOperation::deinitExecution()
+{
+ BlurBaseOperation::deinitExecution();
+
+ if (this->m_gausstab) {
+ MEM_freeN(this->m_gausstab);
+ this->m_gausstab = nullptr;
+ }
+
+ if (this->m_distbuf_inv) {
+ MEM_freeN(this->m_distbuf_inv);
+ this->m_distbuf_inv = nullptr;
+ }
+}
+
+void GaussianAlphaBlurBaseOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx != IMAGE_INPUT_INDEX) {
+ BlurBaseOperation::get_area_of_interest(input_idx, output_area, r_input_area);
+ return;
+ }
+
+ r_input_area = output_area;
+ switch (dimension_) {
+ case eDimension::X:
+ r_input_area.xmin = output_area.xmin - m_filtersize - 1;
+ r_input_area.xmax = output_area.xmax + m_filtersize + 1;
+ break;
+ case eDimension::Y:
+ r_input_area.ymin = output_area.ymin - m_filtersize - 1;
+ r_input_area.ymax = output_area.ymax + m_filtersize + 1;
+ break;
+ }
+}
+
+BLI_INLINE float finv_test(const float f, const bool test)
+{
+ return (LIKELY(test == false)) ? f : 1.0f - f;
+}
+
+void GaussianAlphaBlurBaseOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ MemoryBuffer *input = inputs[IMAGE_INPUT_INDEX];
+ const rcti &input_rect = input->get_rect();
+ BuffersIterator<float> it = output->iterate_with({input}, area);
+
+ int min_input_coord = -1;
+ int max_input_coord = -1;
+ int elem_stride = -1;
+ std::function<int()> get_current_coord;
+ switch (dimension_) {
+ case eDimension::X:
+ min_input_coord = input_rect.xmin;
+ max_input_coord = input_rect.xmax;
+ get_current_coord = [&] { return it.x; };
+ elem_stride = input->elem_stride;
+ break;
+ case eDimension::Y:
+ min_input_coord = input_rect.ymin;
+ max_input_coord = input_rect.ymax;
+ get_current_coord = [&] { return it.y; };
+ elem_stride = input->row_stride;
+ break;
+ }
+
+ for (; !it.is_end(); ++it) {
+ const int coord = get_current_coord();
+ const int coord_min = max_ii(coord - m_filtersize, min_input_coord);
+ const int coord_max = min_ii(coord + m_filtersize + 1, max_input_coord);
+
+ /* *** This is the main part which is different to #GaussianBlurBaseOperation. *** */
+ /* Gauss. */
+ float alpha_accum = 0.0f;
+ float multiplier_accum = 0.0f;
+
+ /* Dilate. */
+ const bool do_invert = m_do_subtract;
+ /* Init with the current color to avoid unneeded lookups. */
+ float value_max = finv_test(*it.in(0), do_invert);
+ float distfacinv_max = 1.0f; /* 0 to 1 */
+
+ const int step = QualityStepHelper::getStep();
+ const float *in = it.in(0) + ((intptr_t)coord_min - coord) * elem_stride;
+ const int in_stride = elem_stride * step;
+ int index = (coord_min - coord) + m_filtersize;
+ const int index_end = index + (coord_max - coord_min);
+ for (; index < index_end; in += in_stride, index += step) {
+ float value = finv_test(*in, do_invert);
+
+ /* Gauss. */
+ float multiplier = m_gausstab[index];
+ alpha_accum += value * multiplier;
+ multiplier_accum += multiplier;
+
+ /* Dilate - find most extreme color. */
+ if (value > value_max) {
+ multiplier = m_distbuf_inv[index];
+ value *= multiplier;
+ if (value > value_max) {
+ value_max = value;
+ distfacinv_max = multiplier;
+ }
+ }
+ }
+
+ /* Blend between the max value and gauss blue - gives nice feather. */
+ const float value_blur = alpha_accum / multiplier_accum;
+ const float value_final = (value_max * distfacinv_max) +
+ (value_blur * (1.0f - distfacinv_max));
+ *it.out = finv_test(value_final, do_invert);
+ }
+}
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h
new file mode 100644
index 00000000000..d7ca975ca0a
--- /dev/null
+++ b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h
@@ -0,0 +1,62 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#pragma once
+
+#include "COM_BlurBaseOperation.h"
+
+namespace blender::compositor {
+
+class GaussianAlphaBlurBaseOperation : public BlurBaseOperation {
+ protected:
+ float *m_gausstab;
+ float *m_distbuf_inv;
+ int m_falloff; /* Falloff for #distbuf_inv. */
+ bool m_do_subtract;
+ int m_filtersize;
+ float rad_;
+ eDimension dimension_;
+
+ public:
+ GaussianAlphaBlurBaseOperation(eDimension dim);
+
+ virtual void init_data() override;
+ virtual void initExecution() override;
+ virtual void deinitExecution() override;
+
+ void get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) final;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) final;
+
+ /**
+ * Set subtract for Dilate/Erode functionality
+ */
+ void setSubtract(bool subtract)
+ {
+ this->m_do_subtract = subtract;
+ }
+ void setFalloff(int falloff)
+ {
+ this->m_falloff = falloff;
+ }
+};
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc
index 7ca5dc4ca76..6710ed3cf5b 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc
@@ -24,11 +24,9 @@
namespace blender::compositor {
-GaussianAlphaXBlurOperation::GaussianAlphaXBlurOperation() : BlurBaseOperation(DataType::Value)
+GaussianAlphaXBlurOperation::GaussianAlphaXBlurOperation()
+ : GaussianAlphaBlurBaseOperation(eDimension::X)
{
- this->m_gausstab = nullptr;
- this->m_filtersize = 0;
- this->m_falloff = -1; /* intentionally invalid, so we can detect uninitialized values */
}
void *GaussianAlphaXBlurOperation::initializeTileData(rcti * /*rect*/)
@@ -44,12 +42,11 @@ void *GaussianAlphaXBlurOperation::initializeTileData(rcti * /*rect*/)
void GaussianAlphaXBlurOperation::initExecution()
{
- /* Until we support size input - comment this. */
- // BlurBaseOperation::initExecution();
+ GaussianAlphaBlurBaseOperation::initExecution();
initMutex();
- if (this->m_sizeavailable) {
+ if (this->m_sizeavailable && execution_model_ == eExecutionModel::Tiled) {
float rad = max_ff(m_size * m_data.sizex, 0.0f);
m_filtersize = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS);
@@ -144,7 +141,7 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
void GaussianAlphaXBlurOperation::deinitExecution()
{
- BlurBaseOperation::deinitExecution();
+ GaussianAlphaBlurBaseOperation::deinitExecution();
if (this->m_gausstab) {
MEM_freeN(this->m_gausstab);
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
index 949956fae04..2a44c639665 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
@@ -18,18 +18,13 @@
#pragma once
-#include "COM_BlurBaseOperation.h"
-#include "COM_NodeOperation.h"
+#include "COM_GaussianAlphaBlurBaseOperation.h"
namespace blender::compositor {
-class GaussianAlphaXBlurOperation : public BlurBaseOperation {
+/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */
+class GaussianAlphaXBlurOperation : public GaussianAlphaBlurBaseOperation {
private:
- float *m_gausstab;
- float *m_distbuf_inv;
- int m_falloff; /* falloff for distbuf_inv */
- bool m_do_subtract;
- int m_filtersize;
void updateGauss();
public:
@@ -54,18 +49,6 @@ class GaussianAlphaXBlurOperation : public BlurBaseOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
-
- /**
- * Set subtract for Dilate/Erode functionality
- */
- void setSubtract(bool subtract)
- {
- this->m_do_subtract = subtract;
- }
- void setFalloff(int falloff)
- {
- this->m_falloff = falloff;
- }
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc
index d2385a972dd..09aeddb6573 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc
@@ -24,11 +24,9 @@
namespace blender::compositor {
-GaussianAlphaYBlurOperation::GaussianAlphaYBlurOperation() : BlurBaseOperation(DataType::Value)
+GaussianAlphaYBlurOperation::GaussianAlphaYBlurOperation()
+ : GaussianAlphaBlurBaseOperation(eDimension::Y)
{
- this->m_gausstab = nullptr;
- this->m_filtersize = 0;
- this->m_falloff = -1; /* intentionally invalid, so we can detect uninitialized values */
}
void *GaussianAlphaYBlurOperation::initializeTileData(rcti * /*rect*/)
@@ -42,14 +40,14 @@ void *GaussianAlphaYBlurOperation::initializeTileData(rcti * /*rect*/)
return buffer;
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
void GaussianAlphaYBlurOperation::initExecution()
{
- /* Until we support size input - comment this. */
- // BlurBaseOperation::initExecution();
+ GaussianAlphaBlurBaseOperation::initExecution();
initMutex();
- if (this->m_sizeavailable) {
+ if (this->m_sizeavailable && execution_model_ == eExecutionModel::Tiled) {
float rad = max_ff(m_size * m_data.sizey, 0.0f);
m_filtersize = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS);
@@ -58,6 +56,7 @@ void GaussianAlphaYBlurOperation::initExecution()
}
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
void GaussianAlphaYBlurOperation::updateGauss()
{
if (this->m_gausstab == nullptr) {
@@ -143,7 +142,7 @@ void GaussianAlphaYBlurOperation::executePixel(float output[4], int x, int y, vo
void GaussianAlphaYBlurOperation::deinitExecution()
{
- BlurBaseOperation::deinitExecution();
+ GaussianAlphaBlurBaseOperation::deinitExecution();
if (this->m_gausstab) {
MEM_freeN(this->m_gausstab);
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
index d25770386c4..ef01f7e0f92 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
@@ -18,18 +18,13 @@
#pragma once
-#include "COM_BlurBaseOperation.h"
-#include "COM_NodeOperation.h"
+#include "COM_GaussianAlphaBlurBaseOperation.h"
namespace blender::compositor {
-class GaussianAlphaYBlurOperation : public BlurBaseOperation {
+/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */
+class GaussianAlphaYBlurOperation : public GaussianAlphaBlurBaseOperation {
private:
- float *m_gausstab;
- float *m_distbuf_inv;
- bool m_do_subtract;
- int m_falloff;
- int m_filtersize;
void updateGauss();
public:
@@ -54,18 +49,6 @@ class GaussianAlphaYBlurOperation : public BlurBaseOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
-
- /**
- * Set subtract for Dilate/Erode functionality
- */
- void setSubtract(bool subtract)
- {
- this->m_do_subtract = subtract;
- }
- void setFalloff(int falloff)
- {
- this->m_falloff = falloff;
- }
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc
new file mode 100644
index 00000000000..959f599fab4
--- /dev/null
+++ b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc
@@ -0,0 +1,154 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#include "COM_GaussianBlurBaseOperation.h"
+
+namespace blender::compositor {
+
+GaussianBlurBaseOperation::GaussianBlurBaseOperation(eDimension dim)
+ : BlurBaseOperation(DataType::Color)
+{
+ m_gausstab = nullptr;
+#ifdef BLI_HAVE_SSE2
+ m_gausstab_sse = nullptr;
+#endif
+ m_filtersize = 0;
+ rad_ = 0.0f;
+ dimension_ = dim;
+}
+
+void GaussianBlurBaseOperation::init_data()
+{
+ BlurBaseOperation::init_data();
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ rad_ = max_ff(m_size * this->get_blur_size(dimension_), 0.0f);
+ rad_ = min_ff(rad_, MAX_GAUSSTAB_RADIUS);
+ m_filtersize = min_ii(ceil(rad_), MAX_GAUSSTAB_RADIUS);
+ }
+}
+
+void GaussianBlurBaseOperation::initExecution()
+{
+ BlurBaseOperation::initExecution();
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ m_gausstab = BlurBaseOperation::make_gausstab(rad_, m_filtersize);
+#ifdef BLI_HAVE_SSE2
+ m_gausstab_sse = BlurBaseOperation::convert_gausstab_sse(m_gausstab, m_filtersize);
+#endif
+ }
+}
+
+void GaussianBlurBaseOperation::deinitExecution()
+{
+ BlurBaseOperation::deinitExecution();
+
+ if (m_gausstab) {
+ MEM_freeN(m_gausstab);
+ m_gausstab = nullptr;
+ }
+#ifdef BLI_HAVE_SSE2
+ if (m_gausstab_sse) {
+ MEM_freeN(m_gausstab_sse);
+ m_gausstab_sse = nullptr;
+ }
+#endif
+}
+
+void GaussianBlurBaseOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx != IMAGE_INPUT_INDEX) {
+ BlurBaseOperation::get_area_of_interest(input_idx, output_area, r_input_area);
+ return;
+ }
+
+ r_input_area = output_area;
+ switch (dimension_) {
+ case eDimension::X:
+ r_input_area.xmin = output_area.xmin - m_filtersize - 1;
+ r_input_area.xmax = output_area.xmax + m_filtersize + 1;
+ break;
+ case eDimension::Y:
+ r_input_area.ymin = output_area.ymin - m_filtersize - 1;
+ r_input_area.ymax = output_area.ymax + m_filtersize + 1;
+ break;
+ }
+}
+
+void GaussianBlurBaseOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ MemoryBuffer *input = inputs[IMAGE_INPUT_INDEX];
+ const rcti &input_rect = input->get_rect();
+ BuffersIterator<float> it = output->iterate_with({input}, area);
+
+ int min_input_coord = -1;
+ int max_input_coord = -1;
+ int elem_stride = -1;
+ std::function<int()> get_current_coord;
+ switch (dimension_) {
+ case eDimension::X:
+ min_input_coord = input_rect.xmin;
+ max_input_coord = input_rect.xmax;
+ elem_stride = input->elem_stride;
+ get_current_coord = [&] { return it.x; };
+ break;
+ case eDimension::Y:
+ min_input_coord = input_rect.ymin;
+ max_input_coord = input_rect.ymax;
+ elem_stride = input->row_stride;
+ get_current_coord = [&] { return it.y; };
+ break;
+ }
+
+ for (; !it.is_end(); ++it) {
+ const int coord = get_current_coord();
+ const int coord_min = max_ii(coord - m_filtersize, min_input_coord);
+ const int coord_max = min_ii(coord + m_filtersize + 1, max_input_coord);
+
+ float ATTR_ALIGN(16) color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ float multiplier_accum = 0.0f;
+
+ const int step = QualityStepHelper::getStep();
+ const float *in = it.in(0) + ((intptr_t)coord_min - coord) * elem_stride;
+ const int in_stride = elem_stride * step;
+ int gauss_idx = (coord_min - coord) + m_filtersize;
+ const int gauss_end = gauss_idx + (coord_max - coord_min);
+#ifdef BLI_HAVE_SSE2
+ __m128 accum_r = _mm_load_ps(color_accum);
+ for (; gauss_idx < gauss_end; in += in_stride, gauss_idx += step) {
+ __m128 reg_a = _mm_load_ps(in);
+ reg_a = _mm_mul_ps(reg_a, m_gausstab_sse[gauss_idx]);
+ accum_r = _mm_add_ps(accum_r, reg_a);
+ multiplier_accum += m_gausstab[gauss_idx];
+ }
+ _mm_store_ps(color_accum, accum_r);
+#else
+ for (; gauss_idx < gauss_end; in += in_stride, gauss_idx += step) {
+ const float multiplier = m_gausstab[gauss_idx];
+ madd_v4_v4fl(color_accum, in, multiplier);
+ multiplier_accum += multiplier;
+ }
+#endif
+ mul_v4_v4fl(it.out, color_accum, 1.0f / multiplier_accum);
+ }
+}
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h
new file mode 100644
index 00000000000..c0b27078a24
--- /dev/null
+++ b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h
@@ -0,0 +1,50 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#pragma once
+
+#include "COM_BlurBaseOperation.h"
+
+namespace blender::compositor {
+
+class GaussianBlurBaseOperation : public BlurBaseOperation {
+ protected:
+ float *m_gausstab;
+#ifdef BLI_HAVE_SSE2
+ __m128 *m_gausstab_sse;
+#endif
+ int m_filtersize;
+ float rad_;
+ eDimension dimension_;
+
+ public:
+ GaussianBlurBaseOperation(eDimension dim);
+
+ virtual void init_data() override;
+ virtual void initExecution() override;
+ virtual void deinitExecution() override;
+
+ void get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) override;
+ virtual void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+};
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
index b2c65ff2c96..aafc269abac 100644
--- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
@@ -40,6 +40,27 @@ void *GaussianBokehBlurOperation::initializeTileData(rcti * /*rect*/)
return buffer;
}
+void GaussianBokehBlurOperation::init_data()
+{
+ BlurBaseOperation::init_data();
+ const float width = this->getWidth();
+ const float height = this->getHeight();
+
+ if (!this->m_sizeavailable) {
+ updateSize();
+ }
+
+ radxf_ = this->m_size * (float)this->m_data.sizex;
+ CLAMP(radxf_, 0.0f, width / 2.0f);
+
+ /* Vertical. */
+ radyf_ = this->m_size * (float)this->m_data.sizey;
+ CLAMP(radyf_, 0.0f, height / 2.0f);
+
+ this->m_radx = ceil(radxf_);
+ this->m_rady = ceil(radyf_);
+}
+
void GaussianBokehBlurOperation::initExecution()
{
BlurBaseOperation::initExecution();
@@ -54,39 +75,17 @@ void GaussianBokehBlurOperation::initExecution()
void GaussianBokehBlurOperation::updateGauss()
{
if (this->m_gausstab == nullptr) {
- float radxf;
- float radyf;
- int n;
- float *dgauss;
- float *ddgauss;
- int j, i;
- const float width = this->getWidth();
- const float height = this->getHeight();
- if (!this->m_sizeavailable) {
- updateSize();
- }
- radxf = this->m_size * (float)this->m_data.sizex;
- CLAMP(radxf, 0.0f, width / 2.0f);
-
- /* vertical */
- radyf = this->m_size * (float)this->m_data.sizey;
- CLAMP(radyf, 0.0f, height / 2.0f);
-
- this->m_radx = ceil(radxf);
- this->m_rady = ceil(radyf);
-
int ddwidth = 2 * this->m_radx + 1;
int ddheight = 2 * this->m_rady + 1;
- n = ddwidth * ddheight;
-
+ int n = ddwidth * ddheight;
/* create a full filter image */
- ddgauss = (float *)MEM_mallocN(sizeof(float) * n, __func__);
- dgauss = ddgauss;
+ float *ddgauss = (float *)MEM_mallocN(sizeof(float) * n, __func__);
+ float *dgauss = ddgauss;
float sum = 0.0f;
- float facx = (radxf > 0.0f ? 1.0f / radxf : 0.0f);
- float facy = (radyf > 0.0f ? 1.0f / radyf : 0.0f);
- for (j = -this->m_rady; j <= this->m_rady; j++) {
- for (i = -this->m_radx; i <= this->m_radx; i++, dgauss++) {
+ float facx = (radxf_ > 0.0f ? 1.0f / radxf_ : 0.0f);
+ float facy = (radyf_ > 0.0f ? 1.0f / radyf_ : 0.0f);
+ for (int j = -this->m_rady; j <= this->m_rady; j++) {
+ for (int i = -this->m_radx; i <= this->m_radx; i++, dgauss++) {
float fj = (float)j * facy;
float fi = (float)i * facx;
float dist = sqrt(fj * fj + fi * fi);
@@ -99,7 +98,7 @@ void GaussianBokehBlurOperation::updateGauss()
if (sum > 0.0f) {
/* normalize */
float norm = 1.0f / sum;
- for (j = n - 1; j >= 0; j--) {
+ for (int j = n - 1; j >= 0; j--) {
ddgauss[j] *= norm;
}
}
@@ -196,23 +195,69 @@ bool GaussianBokehBlurOperation::determineDependingAreaOfInterest(
return BlurBaseOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void GaussianBokehBlurOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx != IMAGE_INPUT_INDEX) {
+ BlurBaseOperation::get_area_of_interest(input_idx, output_area, r_input_area);
+ return;
+ }
+
+ r_input_area.xmax = output_area.xmax + m_radx;
+ r_input_area.xmin = output_area.xmin - m_radx;
+ r_input_area.ymax = output_area.ymax + m_rady;
+ r_input_area.ymin = output_area.ymin - m_rady;
+}
+
+void GaussianBokehBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input = inputs[IMAGE_INPUT_INDEX];
+ BuffersIterator<float> it = output->iterate_with({}, area);
+ const rcti &input_rect = input->get_rect();
+ for (; !it.is_end(); ++it) {
+ const int x = it.x;
+ const int y = it.y;
+
+ const int ymin = max_ii(y - this->m_rady, input_rect.ymin);
+ const int ymax = min_ii(y + this->m_rady + 1, input_rect.ymax);
+ const int xmin = max_ii(x - this->m_radx, input_rect.xmin);
+ const int xmax = min_ii(x + this->m_radx + 1, input_rect.xmax);
+
+ float tempColor[4] = {0};
+ float multiplier_accum = 0;
+ const int step = QualityStepHelper::getStep();
+ const int elem_step = step * input->elem_stride;
+ const int add_const = (xmin - x + this->m_radx);
+ const int mul_const = (this->m_radx * 2 + 1);
+ for (int ny = ymin; ny < ymax; ny += step) {
+ const float *color = input->get_elem(xmin, ny);
+ int gauss_index = ((ny - y) + this->m_rady) * mul_const + add_const;
+ const int gauss_end = gauss_index + (xmax - xmin);
+ for (; gauss_index < gauss_end; gauss_index += step, color += elem_step) {
+ const float multiplier = this->m_gausstab[gauss_index];
+ madd_v4_v4fl(tempColor, color, multiplier);
+ multiplier_accum += multiplier;
+ }
+ }
+
+ mul_v4_v4fl(it.out, tempColor, 1.0f / multiplier_accum);
+ }
+}
+
// reference image
GaussianBlurReferenceOperation::GaussianBlurReferenceOperation()
: BlurBaseOperation(DataType::Color)
{
this->m_maintabs = nullptr;
+ use_variable_size_ = true;
}
-void *GaussianBlurReferenceOperation::initializeTileData(rcti * /*rect*/)
-{
- void *buffer = getInputOperation(0)->initializeTileData(nullptr);
- return buffer;
-}
-
-void GaussianBlurReferenceOperation::initExecution()
+void GaussianBlurReferenceOperation::init_data()
{
- BlurBaseOperation::initExecution();
- // setup gaustab
+ /* Setup variables for gausstab and area of interest. */
this->m_data.image_in_width = this->getWidth();
this->m_data.image_in_height = this->getHeight();
if (this->m_data.relative) {
@@ -232,7 +277,7 @@ void GaussianBlurReferenceOperation::initExecution()
}
}
- /* horizontal */
+ /* Horizontal. */
m_filtersizex = (float)this->m_data.sizex;
int imgx = getWidth() / 2;
if (m_filtersizex > imgx) {
@@ -243,7 +288,7 @@ void GaussianBlurReferenceOperation::initExecution()
}
m_radx = (float)m_filtersizex;
- /* vertical */
+ /* Vertical. */
m_filtersizey = (float)this->m_data.sizey;
int imgy = getHeight() / 2;
if (m_filtersizey > imgy) {
@@ -253,6 +298,18 @@ void GaussianBlurReferenceOperation::initExecution()
m_filtersizey = 1;
}
m_rady = (float)m_filtersizey;
+}
+
+void *GaussianBlurReferenceOperation::initializeTileData(rcti * /*rect*/)
+{
+ void *buffer = getInputOperation(0)->initializeTileData(nullptr);
+ return buffer;
+}
+
+void GaussianBlurReferenceOperation::initExecution()
+{
+ BlurBaseOperation::initExecution();
+
updateGauss();
}
@@ -363,4 +420,78 @@ bool GaussianBlurReferenceOperation::determineDependingAreaOfInterest(
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void GaussianBlurReferenceOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx != IMAGE_INPUT_INDEX) {
+ BlurBaseOperation::get_area_of_interest(input_idx, output_area, r_input_area);
+ return;
+ }
+
+ const int add_x = this->m_data.sizex + 2;
+ const int add_y = this->m_data.sizey + 2;
+ r_input_area.xmax = output_area.xmax + add_x;
+ r_input_area.xmin = output_area.xmin - add_x;
+ r_input_area.ymax = output_area.ymax + add_y;
+ r_input_area.ymin = output_area.ymin - add_y;
+}
+
+void GaussianBlurReferenceOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *image_input = inputs[IMAGE_INPUT_INDEX];
+ MemoryBuffer *size_input = inputs[SIZE_INPUT_INDEX];
+ for (BuffersIterator<float> it = output->iterate_with({size_input}, area); !it.is_end(); ++it) {
+ const float ref_size = *it.in(0);
+ int ref_radx = (int)(ref_size * m_radx);
+ int ref_rady = (int)(ref_size * m_rady);
+ if (ref_radx > m_filtersizex) {
+ ref_radx = m_filtersizex;
+ }
+ else if (ref_radx < 1) {
+ ref_radx = 1;
+ }
+ if (ref_rady > m_filtersizey) {
+ ref_rady = m_filtersizey;
+ }
+ else if (ref_rady < 1) {
+ ref_rady = 1;
+ }
+
+ const int x = it.x;
+ const int y = it.y;
+ if (ref_radx == 1 && ref_rady == 1) {
+ image_input->read_elem(x, y, it.out);
+ continue;
+ }
+
+ const int w = getWidth();
+ const int height = getHeight();
+ const int minxr = x - ref_radx < 0 ? -x : -ref_radx;
+ const int maxxr = x + ref_radx > w ? w - x : ref_radx;
+ const int minyr = y - ref_rady < 0 ? -y : -ref_rady;
+ const int maxyr = y + ref_rady > height ? height - y : ref_rady;
+
+ const float *gausstabx = m_maintabs[ref_radx - 1];
+ const float *gausstabcentx = gausstabx + ref_radx;
+ const float *gausstaby = m_maintabs[ref_rady - 1];
+ const float *gausstabcenty = gausstaby + ref_rady;
+
+ float gauss_sum = 0.0f;
+ float color_sum[4] = {0};
+ const float *row_color = image_input->get_elem(x + minxr, y + minyr);
+ for (int i = minyr; i < maxyr; i++, row_color += image_input->row_stride) {
+ const float *color = row_color;
+ for (int j = minxr; j < maxxr; j++, color += image_input->elem_stride) {
+ const float val = gausstabcenty[i] * gausstabcentx[j];
+ gauss_sum += val;
+ madd_v4_v4fl(color_sum, color, val);
+ }
+ }
+ mul_v4_v4fl(it.out, color_sum, 1.0f / gauss_sum);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
index 59ba3d06619..a64b5b327b0 100644
--- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
@@ -28,10 +28,13 @@ class GaussianBokehBlurOperation : public BlurBaseOperation {
private:
float *m_gausstab;
int m_radx, m_rady;
+ float radxf_;
+ float radyf_;
void updateGauss();
public:
GaussianBokehBlurOperation();
+ void init_data() override;
void initExecution() override;
void *initializeTileData(rcti *rect) override;
/**
@@ -47,6 +50,13 @@ class GaussianBokehBlurOperation : public BlurBaseOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
class GaussianBlurReferenceOperation : public BlurBaseOperation {
@@ -61,6 +71,7 @@ class GaussianBlurReferenceOperation : public BlurBaseOperation {
public:
GaussianBlurReferenceOperation();
+ void init_data() override;
void initExecution() override;
void *initializeTileData(rcti *rect) override;
/**
@@ -76,6 +87,13 @@ class GaussianBlurReferenceOperation : public BlurBaseOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc
index 4b46cfc8776..8d686265231 100644
--- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc
@@ -25,13 +25,8 @@
namespace blender::compositor {
-GaussianXBlurOperation::GaussianXBlurOperation() : BlurBaseOperation(DataType::Color)
+GaussianXBlurOperation::GaussianXBlurOperation() : GaussianBlurBaseOperation(eDimension::X)
{
- this->m_gausstab = nullptr;
-#ifdef BLI_HAVE_SSE2
- this->m_gausstab_sse = nullptr;
-#endif
- this->m_filtersize = 0;
}
void *GaussianXBlurOperation::initializeTileData(rcti * /*rect*/)
@@ -45,13 +40,14 @@ void *GaussianXBlurOperation::initializeTileData(rcti * /*rect*/)
return buffer;
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
void GaussianXBlurOperation::initExecution()
{
- BlurBaseOperation::initExecution();
+ GaussianBlurBaseOperation::initExecution();
initMutex();
- if (this->m_sizeavailable) {
+ if (this->m_sizeavailable && execution_model_ == eExecutionModel::Tiled) {
float rad = max_ff(m_size * m_data.sizex, 0.0f);
m_filtersize = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS);
@@ -63,6 +59,7 @@ void GaussianXBlurOperation::initExecution()
}
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
void GaussianXBlurOperation::updateGauss()
{
if (this->m_gausstab == nullptr) {
@@ -158,7 +155,7 @@ void GaussianXBlurOperation::executeOpenCL(OpenCLDevice *device,
void GaussianXBlurOperation::deinitExecution()
{
- BlurBaseOperation::deinitExecution();
+ GaussianBlurBaseOperation::deinitExecution();
if (this->m_gausstab) {
MEM_freeN(this->m_gausstab);
diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianXBlurOperation.h
index 15277f0a42d..e09e57bad67 100644
--- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianXBlurOperation.h
@@ -18,18 +18,13 @@
#pragma once
-#include "COM_BlurBaseOperation.h"
-#include "COM_NodeOperation.h"
+#include "COM_GaussianBlurBaseOperation.h"
namespace blender::compositor {
-class GaussianXBlurOperation : public BlurBaseOperation {
+/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */
+class GaussianXBlurOperation : public GaussianBlurBaseOperation {
private:
- float *m_gausstab;
-#ifdef BLI_HAVE_SSE2
- __m128 *m_gausstab_sse;
-#endif
- int m_filtersize;
void updateGauss();
public:
diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc
index 590ac5faa6a..32d469a0ae4 100644
--- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc
@@ -25,13 +25,8 @@
namespace blender::compositor {
-GaussianYBlurOperation::GaussianYBlurOperation() : BlurBaseOperation(DataType::Color)
+GaussianYBlurOperation::GaussianYBlurOperation() : GaussianBlurBaseOperation(eDimension::Y)
{
- this->m_gausstab = nullptr;
-#ifdef BLI_HAVE_SSE2
- this->m_gausstab_sse = nullptr;
-#endif
- this->m_filtersize = 0;
}
void *GaussianYBlurOperation::initializeTileData(rcti * /*rect*/)
@@ -47,11 +42,11 @@ void *GaussianYBlurOperation::initializeTileData(rcti * /*rect*/)
void GaussianYBlurOperation::initExecution()
{
- BlurBaseOperation::initExecution();
+ GaussianBlurBaseOperation::initExecution();
initMutex();
- if (this->m_sizeavailable) {
+ if (this->m_sizeavailable && execution_model_ == eExecutionModel::Tiled) {
float rad = max_ff(m_size * m_data.sizey, 0.0f);
m_filtersize = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS);
@@ -158,7 +153,7 @@ void GaussianYBlurOperation::executeOpenCL(OpenCLDevice *device,
void GaussianYBlurOperation::deinitExecution()
{
- BlurBaseOperation::deinitExecution();
+ GaussianBlurBaseOperation::deinitExecution();
if (this->m_gausstab) {
MEM_freeN(this->m_gausstab);
diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianYBlurOperation.h
index 56d40849ba4..bb33f8b74cb 100644
--- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianYBlurOperation.h
@@ -18,18 +18,13 @@
#pragma once
-#include "COM_BlurBaseOperation.h"
-#include "COM_NodeOperation.h"
+#include "COM_GaussianBlurBaseOperation.h"
namespace blender::compositor {
-class GaussianYBlurOperation : public BlurBaseOperation {
+/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */
+class GaussianYBlurOperation : public GaussianBlurBaseOperation {
private:
- float *m_gausstab;
-#ifdef BLI_HAVE_SSE2
- __m128 *m_gausstab_sse;
-#endif
- int m_filtersize;
void updateGauss();
public:
diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc
index e341a88ff71..5ae868c5964 100644
--- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc
+++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc
@@ -73,4 +73,31 @@ void HueSaturationValueCorrectOperation::deinitExecution()
this->m_inputProgram = nullptr;
}
+void HueSaturationValueCorrectOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ float hsv[4];
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ copy_v4_v4(hsv, it.in(0));
+
+ /* Adjust hue, scaling returned default 0.5 up to 1. */
+ float f = BKE_curvemapping_evaluateF(this->m_curveMapping, 0, hsv[0]);
+ hsv[0] += f - 0.5f;
+
+ /* Adjust saturation, scaling returned default 0.5 up to 1. */
+ f = BKE_curvemapping_evaluateF(this->m_curveMapping, 1, hsv[0]);
+ hsv[1] *= (f * 2.0f);
+
+ /* Adjust value, scaling returned default 0.5 up to 1. */
+ f = BKE_curvemapping_evaluateF(this->m_curveMapping, 2, hsv[0]);
+ hsv[2] *= (f * 2.0f);
+
+ hsv[0] = hsv[0] - floorf(hsv[0]); /* Mod 1.0. */
+ CLAMP(hsv[1], 0.0f, 1.0f);
+
+ copy_v4_v4(it.out, hsv);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h
index 703b2894bdb..6c1b66aba1f 100644
--- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h
+++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h
@@ -47,6 +47,10 @@ class HueSaturationValueCorrectOperation : public CurveBaseOperation {
* Deinitialize the execution
*/
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_InvertOperation.cc b/source/blender/compositor/operations/COM_InvertOperation.cc
index 339e40a5d1f..4f71a1d0d1d 100644
--- a/source/blender/compositor/operations/COM_InvertOperation.cc
+++ b/source/blender/compositor/operations/COM_InvertOperation.cc
@@ -30,6 +30,7 @@ InvertOperation::InvertOperation()
this->m_color = true;
this->m_alpha = false;
setResolutionInputSocketIndex(1);
+ this->flags.can_be_constant = true;
}
void InvertOperation::initExecution()
{
@@ -70,4 +71,31 @@ void InvertOperation::deinitExecution()
this->m_inputColorProgram = nullptr;
}
+void InvertOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float value = *it.in(0);
+ const float inverted_value = 1.0f - value;
+ const float *color = it.in(1);
+
+ if (this->m_color) {
+ it.out[0] = (1.0f - color[0]) * value + color[0] * inverted_value;
+ it.out[1] = (1.0f - color[1]) * value + color[1] * inverted_value;
+ it.out[2] = (1.0f - color[2]) * value + color[2] * inverted_value;
+ }
+ else {
+ copy_v3_v3(it.out, color);
+ }
+
+ if (this->m_alpha) {
+ it.out[3] = (1.0f - color[3]) * value + color[3] * inverted_value;
+ }
+ else {
+ it.out[3] = color[3];
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_InvertOperation.h b/source/blender/compositor/operations/COM_InvertOperation.h
index 17e5eb95f3e..a084bf5d559 100644
--- a/source/blender/compositor/operations/COM_InvertOperation.h
+++ b/source/blender/compositor/operations/COM_InvertOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class InvertOperation : public NodeOperation {
+class InvertOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -59,6 +59,10 @@ class InvertOperation : public NodeOperation {
{
this->m_alpha = alpha;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.cc b/source/blender/compositor/operations/COM_KeyingBlurOperation.cc
index 994b00cd3f4..d5ebd5e9df7 100644
--- a/source/blender/compositor/operations/COM_KeyingBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.cc
@@ -96,4 +96,67 @@ bool KeyingBlurOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void KeyingBlurOperation::get_area_of_interest(const int UNUSED(input_idx),
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (m_axis) {
+ case BLUR_AXIS_X:
+ r_input_area.xmin = output_area.xmin - m_size;
+ r_input_area.ymin = output_area.ymin;
+ r_input_area.xmax = output_area.xmax + m_size;
+ r_input_area.ymax = output_area.ymax;
+ break;
+ case BLUR_AXIS_Y:
+ r_input_area.xmin = output_area.xmin;
+ r_input_area.ymin = output_area.ymin - m_size;
+ r_input_area.xmax = output_area.xmax;
+ r_input_area.ymax = output_area.ymax + m_size;
+ break;
+ default:
+ BLI_assert_msg(0, "Unknown axis");
+ break;
+ }
+}
+
+void KeyingBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input = inputs[0];
+ BuffersIterator<float> it = output->iterate_with(inputs, area);
+
+ int coord_max;
+ int elem_stride;
+ std::function<int()> get_current_coord;
+ switch (m_axis) {
+ case BLUR_AXIS_X:
+ get_current_coord = [&] { return it.x; };
+ coord_max = this->getWidth();
+ elem_stride = input->elem_stride;
+ break;
+ case BLUR_AXIS_Y:
+ get_current_coord = [&] { return it.y; };
+ coord_max = this->getHeight();
+ elem_stride = input->row_stride;
+ break;
+ }
+
+ for (; !it.is_end(); ++it) {
+ const int coord = get_current_coord();
+ const int start_coord = MAX2(0, coord - m_size + 1);
+ const int end_coord = MIN2(coord_max, coord + m_size);
+ const int count = end_coord - start_coord;
+
+ float sum = 0.0f;
+ const float *start = it.in(0) + (start_coord - coord) * elem_stride;
+ const float *end = start + count * elem_stride;
+ for (const float *elem = start; elem < end; elem += elem_stride) {
+ sum += *elem;
+ }
+
+ *it.out = sum / count;
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.h b/source/blender/compositor/operations/COM_KeyingBlurOperation.h
index b055d7713f1..b290b905e63 100644
--- a/source/blender/compositor/operations/COM_KeyingBlurOperation.h
+++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.h
@@ -18,14 +18,14 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
/**
* Class with implementation of blurring for keying node
*/
-class KeyingBlurOperation : public NodeOperation {
+class KeyingBlurOperation : public MultiThreadedOperation {
protected:
int m_size;
int m_axis;
@@ -54,6 +54,13 @@ class KeyingBlurOperation : public NodeOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.cc b/source/blender/compositor/operations/COM_KeyingClipOperation.cc
index 4029be4e077..817c920ed91 100644
--- a/source/blender/compositor/operations/COM_KeyingClipOperation.cc
+++ b/source/blender/compositor/operations/COM_KeyingClipOperation.cc
@@ -130,4 +130,89 @@ bool KeyingClipOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void KeyingClipOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ BLI_assert(input_idx == 0);
+ UNUSED_VARS_NDEBUG(input_idx);
+ r_input_area.xmin = output_area.xmin - m_kernelRadius;
+ r_input_area.xmax = output_area.xmax + m_kernelRadius;
+ r_input_area.ymin = output_area.ymin - m_kernelRadius;
+ r_input_area.ymax = output_area.ymax + m_kernelRadius;
+}
+
+void KeyingClipOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input = inputs[0];
+ BuffersIterator<float> it = output->iterate_with(inputs, area);
+
+ const int delta = m_kernelRadius;
+ const float tolerance = m_kernelTolerance;
+ const int width = this->getWidth();
+ const int height = this->getHeight();
+ const int row_stride = input->row_stride;
+ const int elem_stride = input->elem_stride;
+ for (; !it.is_end(); ++it) {
+ const int x = it.x;
+ const int y = it.y;
+
+ const int start_x = MAX2(0, x - delta + 1);
+ const int start_y = MAX2(0, y - delta + 1);
+ const int end_x = MIN2(x + delta, width);
+ const int end_y = MIN2(y + delta, height);
+ const int x_len = end_x - start_x;
+ const int y_len = end_y - start_y;
+
+ const int total_count = x_len * y_len - 1;
+ const int threshold_count = ceil((float)total_count * 0.9f);
+ bool ok = false;
+ if (delta == 0) {
+ ok = true;
+ }
+
+ const float *main_elem = it.in(0);
+ const float value = *main_elem;
+ const float *row = input->get_elem(start_x, start_y);
+ const float *end_row = row + y_len * row_stride;
+ int count = 0;
+ for (; ok == false && row < end_row; row += row_stride) {
+ const float *end_elem = row + x_len * elem_stride;
+ for (const float *elem = row; ok == false && elem < end_elem; elem += elem_stride) {
+ if (UNLIKELY(elem == main_elem)) {
+ continue;
+ }
+
+ const float current_value = *elem;
+ if (fabsf(current_value - value) < tolerance) {
+ count++;
+ if (count >= threshold_count) {
+ ok = true;
+ }
+ }
+ }
+ }
+
+ if (m_isEdgeMatte) {
+ *it.out = ok ? 0.0f : 1.0f;
+ }
+ else {
+ if (!ok) {
+ *it.out = value;
+ }
+ else if (value < m_clipBlack) {
+ *it.out = 0.0f;
+ }
+ else if (value >= m_clipWhite) {
+ *it.out = 1.0f;
+ }
+ else {
+ *it.out = (value - m_clipBlack) / (m_clipWhite - m_clipBlack);
+ }
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.h b/source/blender/compositor/operations/COM_KeyingClipOperation.h
index 0a21fb48c99..1a17d591781 100644
--- a/source/blender/compositor/operations/COM_KeyingClipOperation.h
+++ b/source/blender/compositor/operations/COM_KeyingClipOperation.h
@@ -18,14 +18,14 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
/**
* Class with implementation of black/white clipping for keying node
*/
-class KeyingClipOperation : public NodeOperation {
+class KeyingClipOperation : public MultiThreadedOperation {
protected:
float m_clipBlack;
float m_clipWhite;
@@ -68,6 +68,13 @@ class KeyingClipOperation : public NodeOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingDespillOperation.cc b/source/blender/compositor/operations/COM_KeyingDespillOperation.cc
index d31a88cb91e..620b767e584 100644
--- a/source/blender/compositor/operations/COM_KeyingDespillOperation.cc
+++ b/source/blender/compositor/operations/COM_KeyingDespillOperation.cc
@@ -36,6 +36,7 @@ KeyingDespillOperation::KeyingDespillOperation()
this->m_pixelReader = nullptr;
this->m_screenReader = nullptr;
+ flags.can_be_constant = true;
}
void KeyingDespillOperation::initExecution()
@@ -82,4 +83,32 @@ void KeyingDespillOperation::executePixelSampled(float output[4],
}
}
+void KeyingDespillOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *pixel_color = it.in(0);
+ const float *screen_color = it.in(1);
+
+ const int screen_primary_channel = max_axis_v3(screen_color);
+ const int other_1 = (screen_primary_channel + 1) % 3;
+ const int other_2 = (screen_primary_channel + 2) % 3;
+
+ const int min_channel = MIN2(other_1, other_2);
+ const int max_channel = MAX2(other_1, other_2);
+
+ const float average_value = m_colorBalance * pixel_color[min_channel] +
+ (1.0f - m_colorBalance) * pixel_color[max_channel];
+ const float amount = (pixel_color[screen_primary_channel] - average_value);
+
+ copy_v4_v4(it.out, pixel_color);
+
+ const float amount_despill = m_despillFactor * amount;
+ if (amount_despill > 0.0f) {
+ it.out[screen_primary_channel] = pixel_color[screen_primary_channel] - amount_despill;
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingDespillOperation.h b/source/blender/compositor/operations/COM_KeyingDespillOperation.h
index 279ac60e6e9..16bed651d3a 100644
--- a/source/blender/compositor/operations/COM_KeyingDespillOperation.h
+++ b/source/blender/compositor/operations/COM_KeyingDespillOperation.h
@@ -18,14 +18,14 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
/**
* Class with implementation of keying despill node
*/
-class KeyingDespillOperation : public NodeOperation {
+class KeyingDespillOperation : public MultiThreadedOperation {
protected:
SocketReader *m_pixelReader;
SocketReader *m_screenReader;
@@ -48,6 +48,10 @@ class KeyingDespillOperation : public NodeOperation {
}
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingOperation.cc b/source/blender/compositor/operations/COM_KeyingOperation.cc
index e786e4b8219..3edb5a5d34e 100644
--- a/source/blender/compositor/operations/COM_KeyingOperation.cc
+++ b/source/blender/compositor/operations/COM_KeyingOperation.cc
@@ -110,4 +110,49 @@ void KeyingOperation::executePixelSampled(float output[4], float x, float y, Pix
}
}
+void KeyingOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *pixel_color = it.in(0);
+ const float *screen_color = it.in(1);
+
+ const int primary_channel = max_axis_v3(screen_color);
+ const float min_pixel_color = min_fff(pixel_color[0], pixel_color[1], pixel_color[2]);
+
+ if (min_pixel_color > 1.0f) {
+ /* Overexposure doesn't happen on screen itself and usually happens
+ * on light sources in the shot, this need to be checked separately
+ * because saturation and falloff calculation is based on the fact
+ * that pixels are not overexposed.
+ */
+ it.out[0] = 1.0f;
+ }
+ else {
+ const float saturation = get_pixel_saturation(pixel_color, m_screenBalance, primary_channel);
+ const float screen_saturation = get_pixel_saturation(
+ screen_color, m_screenBalance, primary_channel);
+
+ if (saturation < 0) {
+ /* Means main channel of pixel is different from screen,
+ * assume this is completely a foreground.
+ */
+ it.out[0] = 1.0f;
+ }
+ else if (saturation >= screen_saturation) {
+ /* Matched main channels and higher saturation on pixel
+ * is treated as completely background.
+ */
+ it.out[0] = 0.0f;
+ }
+ else {
+ /* Nice alpha falloff on edges. */
+ const float distance = 1.0f - saturation / screen_saturation;
+ it.out[0] = distance;
+ }
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingOperation.h b/source/blender/compositor/operations/COM_KeyingOperation.h
index 3d41ecaa0f6..e134ad54896 100644
--- a/source/blender/compositor/operations/COM_KeyingOperation.h
+++ b/source/blender/compositor/operations/COM_KeyingOperation.h
@@ -20,7 +20,7 @@
#include <string.h>
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "BLI_listbase.h"
@@ -29,7 +29,7 @@ namespace blender::compositor {
/**
* Class with implementation of keying node
*/
-class KeyingOperation : public NodeOperation {
+class KeyingOperation : public MultiThreadedOperation {
protected:
SocketReader *m_pixelReader;
SocketReader *m_screenReader;
@@ -48,6 +48,10 @@ class KeyingOperation : public NodeOperation {
}
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cc b/source/blender/compositor/operations/COM_KeyingScreenOperation.cc
index 17b613246ad..c00aafc19a2 100644
--- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cc
+++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cc
@@ -39,12 +39,21 @@ KeyingScreenOperation::KeyingScreenOperation()
this->m_framenumber = 0;
this->m_trackingObject[0] = 0;
flags.complex = true;
+ m_cachedTriangulation = nullptr;
}
void KeyingScreenOperation::initExecution()
{
initMutex();
- this->m_cachedTriangulation = nullptr;
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ BLI_assert(m_cachedTriangulation == nullptr);
+ if (m_movieClip) {
+ m_cachedTriangulation = buildVoronoiTriangulation();
+ }
+ }
+ else {
+ this->m_cachedTriangulation = nullptr;
+ }
}
void KeyingScreenOperation::deinitExecution()
@@ -226,7 +235,7 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
return triangulation;
}
-void *KeyingScreenOperation::initializeTileData(rcti *rect)
+KeyingScreenOperation::TileData *KeyingScreenOperation::triangulate(const rcti *rect)
{
TileData *tile_data;
TriangulationData *triangulation;
@@ -234,18 +243,6 @@ void *KeyingScreenOperation::initializeTileData(rcti *rect)
int chunk_size = 20;
int i;
- if (this->m_movieClip == nullptr) {
- return nullptr;
- }
-
- if (!this->m_cachedTriangulation) {
- lockMutex();
- if (this->m_cachedTriangulation == nullptr) {
- this->m_cachedTriangulation = buildVoronoiTriangulation();
- }
- unlockMutex();
- }
-
triangulation = this->m_cachedTriangulation;
if (!triangulation) {
@@ -278,6 +275,23 @@ void *KeyingScreenOperation::initializeTileData(rcti *rect)
return tile_data;
}
+void *KeyingScreenOperation::initializeTileData(rcti *rect)
+{
+ if (this->m_movieClip == nullptr) {
+ return nullptr;
+ }
+
+ if (!this->m_cachedTriangulation) {
+ lockMutex();
+ if (this->m_cachedTriangulation == nullptr) {
+ this->m_cachedTriangulation = buildVoronoiTriangulation();
+ }
+ unlockMutex();
+ }
+
+ return triangulate(rect);
+}
+
void KeyingScreenOperation::deinitializeTileData(rcti * /*rect*/, void *data)
{
TileData *tile_data = (TileData *)data;
@@ -347,4 +361,57 @@ void KeyingScreenOperation::executePixel(float output[4], int x, int y, void *da
}
}
+void KeyingScreenOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ if (m_movieClip == nullptr) {
+ output->fill(area, COM_COLOR_BLACK);
+ return;
+ }
+
+ TileData *tri_area = this->triangulate(&area);
+ BLI_assert(tri_area != nullptr);
+
+ const int *triangles = tri_area->triangles;
+ const int num_triangles = tri_area->triangles_total;
+ const TriangulationData *triangulation = m_cachedTriangulation;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ copy_v4_v4(it.out, COM_COLOR_BLACK);
+
+ const float co[2] = {(float)it.x, (float)it.y};
+ for (int i = 0; i < num_triangles; i++) {
+ const int triangle_idx = triangles[i];
+ const rcti *rect = &triangulation->triangles_AABB[triangle_idx];
+
+ if (!BLI_rcti_isect_pt(rect, it.x, it.y)) {
+ continue;
+ }
+
+ const int *triangle = triangulation->triangles[triangle_idx];
+ const VoronoiTriangulationPoint &a = triangulation->triangulated_points[triangle[0]];
+ const VoronoiTriangulationPoint &b = triangulation->triangulated_points[triangle[1]];
+ const VoronoiTriangulationPoint &c = triangulation->triangulated_points[triangle[2]];
+
+ float w[3];
+ if (!barycentric_coords_v2(a.co, b.co, c.co, co, w)) {
+ continue;
+ }
+
+ if (barycentric_inside_triangle_v2(w)) {
+ it.out[0] = a.color[0] * w[0] + b.color[0] * w[1] + c.color[0] * w[2];
+ it.out[1] = a.color[1] * w[0] + b.color[1] * w[1] + c.color[1] * w[2];
+ it.out[2] = a.color[2] * w[0] + b.color[2] * w[1] + c.color[2] * w[2];
+ break;
+ }
+ }
+ }
+
+ if (tri_area->triangles) {
+ MEM_freeN(tri_area->triangles);
+ }
+
+ MEM_freeN(tri_area);
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.h b/source/blender/compositor/operations/COM_KeyingScreenOperation.h
index 4118d229be9..0bc47dbea30 100644
--- a/source/blender/compositor/operations/COM_KeyingScreenOperation.h
+++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.h
@@ -20,7 +20,7 @@
#include <string.h>
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_movieclip_types.h"
@@ -34,7 +34,7 @@ namespace blender::compositor {
/**
* Class with implementation of green screen gradient rasterization
*/
-class KeyingScreenOperation : public NodeOperation {
+class KeyingScreenOperation : public MultiThreadedOperation {
protected:
typedef struct TriangulationData {
VoronoiTriangulationPoint *triangulated_points;
@@ -43,6 +43,7 @@ class KeyingScreenOperation : public NodeOperation {
rcti *triangles_AABB;
} TriangulationData;
+ /* TODO(manzanilla): rename to #TrianguledArea on removing tiled implementation. */
typedef struct TileData {
int *triangles;
int triangles_total;
@@ -84,6 +85,13 @@ class KeyingScreenOperation : public NodeOperation {
}
void executePixel(float output[4], int x, int y, void *data) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
+ private:
+ TileData *triangulate(const rcti *rect);
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
index 5ca16e40ce3..c642c60b912 100644
--- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
@@ -29,6 +29,7 @@ LuminanceMatteOperation::LuminanceMatteOperation()
addOutputSocket(DataType::Value);
this->m_inputImageProgram = nullptr;
+ flags.can_be_constant = true;
}
void LuminanceMatteOperation::initExecution()
@@ -78,4 +79,39 @@ void LuminanceMatteOperation::executePixelSampled(float output[4],
output[0] = min_ff(alpha, inColor[3]);
}
+void LuminanceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color = it.in(0);
+ const float luminance = IMB_colormanagement_get_luminance(color);
+
+ /* One line thread-friend algorithm:
+ * `it.out[0] = MIN2(color[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));`
+ */
+
+ /* Test range. */
+ const float high = m_settings->t1;
+ const float low = m_settings->t2;
+ float alpha;
+ if (luminance > high) {
+ alpha = 1.0f;
+ }
+ else if (luminance < low) {
+ alpha = 0.0f;
+ }
+ else { /* Blend. */
+ alpha = (luminance - low) / (high - low);
+ }
+
+ /* Store matte(alpha) value in [0] to go with
+ * COM_SetAlphaMultiplyOperation and the Value output.
+ */
+
+ /* Don't make something that was more transparent less transparent. */
+ it.out[0] = MIN2(alpha, color[3]);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h
index 035c68b9d59..aedfc715382 100644
--- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h
+++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class LuminanceMatteOperation : public NodeOperation {
+class LuminanceMatteOperation : public MultiThreadedOperation {
private:
NodeChroma *m_settings;
SocketReader *m_inputImageProgram;
@@ -49,6 +49,10 @@ class LuminanceMatteOperation : public NodeOperation {
{
this->m_settings = nodeChroma;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MapUVOperation.cc b/source/blender/compositor/operations/COM_MapUVOperation.cc
index 74e3d965d41..ad047c619f8 100644
--- a/source/blender/compositor/operations/COM_MapUVOperation.cc
+++ b/source/blender/compositor/operations/COM_MapUVOperation.cc
@@ -34,10 +34,26 @@ MapUVOperation::MapUVOperation()
this->m_inputColorProgram = nullptr;
}
+void MapUVOperation::init_data()
+{
+ NodeOperation *image_input = get_input_operation(0);
+ image_width_ = image_input->getWidth();
+ image_height_ = image_input->getHeight();
+
+ NodeOperation *uv_input = get_input_operation(1);
+ uv_width_ = uv_input->getWidth();
+ uv_height_ = uv_input->getHeight();
+}
+
void MapUVOperation::initExecution()
{
this->m_inputColorProgram = this->getInputSocketReader(0);
this->m_inputUVProgram = this->getInputSocketReader(1);
+ if (execution_model_ == eExecutionModel::Tiled) {
+ uv_input_read_fn_ = [=](float x, float y, float *out) {
+ this->m_inputUVProgram->readSampled(out, x, y, PixelSampler::Bilinear);
+ };
+ }
}
void MapUVOperation::executePixelSampled(float output[4],
@@ -81,9 +97,7 @@ void MapUVOperation::executePixelSampled(float output[4],
bool MapUVOperation::read_uv(float x, float y, float &r_u, float &r_v, float &r_alpha)
{
- float width = m_inputUVProgram->getWidth();
- float height = m_inputUVProgram->getHeight();
- if (x < 0.0f || x >= width || y < 0.0f || y >= height) {
+ if (x < 0.0f || x >= uv_width_ || y < 0.0f || y >= uv_height_) {
r_u = 0.0f;
r_v = 0.0f;
r_alpha = 0.0f;
@@ -91,9 +105,9 @@ bool MapUVOperation::read_uv(float x, float y, float &r_u, float &r_v, float &r_
}
float vector[3];
- m_inputUVProgram->readSampled(vector, x, y, PixelSampler::Bilinear);
- r_u = vector[0] * m_inputColorProgram->getWidth();
- r_v = vector[1] * m_inputColorProgram->getHeight();
+ uv_input_read_fn_(x, y, vector);
+ r_u = vector[0] * image_width_;
+ r_v = vector[1] * image_height_;
r_alpha = vector[2];
return true;
}
@@ -186,4 +200,75 @@ bool MapUVOperation::determineDependingAreaOfInterest(rcti *input,
return false;
}
+void MapUVOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case 0: {
+ r_input_area.xmin = 0;
+ r_input_area.xmax = image_width_;
+ r_input_area.ymin = 0;
+ r_input_area.ymax = image_height_;
+ break;
+ }
+ case 1: {
+ r_input_area = output_area;
+ expand_area_for_sampler(r_input_area, PixelSampler::Bilinear);
+ break;
+ }
+ }
+}
+
+void MapUVOperation::update_memory_buffer_started(MemoryBuffer *UNUSED(output),
+ const rcti &UNUSED(area),
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *uv_input = inputs[1];
+ uv_input_read_fn_ = [=](float x, float y, float *out) {
+ uv_input->read_elem_bilinear(x, y, out);
+ };
+}
+
+void MapUVOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_image = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ float xy[2] = {(float)it.x, (float)it.y};
+ float uv[2];
+ float deriv[2][2];
+ float alpha;
+ pixelTransform(xy, uv, deriv, alpha);
+ if (alpha == 0.0f) {
+ zero_v4(it.out);
+ continue;
+ }
+
+ /* EWA filtering. */
+ input_image->read_elem_filtered(uv[0], uv[1], deriv[0], deriv[1], it.out);
+
+ /* UV to alpha threshold. */
+ const float threshold = this->m_alpha * 0.05f;
+ /* XXX alpha threshold is used to fade out pixels on boundaries with invalid derivatives.
+ * this calculation is not very well defined, should be looked into if it becomes a problem ...
+ */
+ const float du = len_v2(deriv[0]);
+ const float dv = len_v2(deriv[1]);
+ const float factor = 1.0f - threshold * (du / image_width_ + dv / image_height_);
+ if (factor < 0.0f) {
+ alpha = 0.0f;
+ }
+ else {
+ alpha *= factor;
+ }
+
+ /* "premul" */
+ if (alpha < 1.0f) {
+ mul_v4_fl(it.out, alpha);
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MapUVOperation.h b/source/blender/compositor/operations/COM_MapUVOperation.h
index eb5f7d49122..65fbcb461c9 100644
--- a/source/blender/compositor/operations/COM_MapUVOperation.h
+++ b/source/blender/compositor/operations/COM_MapUVOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class MapUVOperation : public NodeOperation {
+class MapUVOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -30,8 +30,15 @@ class MapUVOperation : public NodeOperation {
SocketReader *m_inputUVProgram;
SocketReader *m_inputColorProgram;
+ int uv_width_;
+ int uv_height_;
+ int image_width_;
+ int image_height_;
+
float m_alpha;
+ std::function<void(float x, float y, float *out)> uv_input_read_fn_;
+
public:
MapUVOperation();
@@ -49,6 +56,8 @@ class MapUVOperation : public NodeOperation {
void pixelTransform(const float xy[2], float r_uv[2], float r_deriv[2][2], float &r_alpha);
+ void init_data() override;
+
/**
* Initialize the execution
*/
@@ -64,6 +73,14 @@ class MapUVOperation : public NodeOperation {
this->m_alpha = alpha;
}
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_started(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
private:
bool read_uv(float x, float y, float &r_u, float &r_v, float &r_alpha);
};
diff --git a/source/blender/compositor/operations/COM_MaskOperation.cc b/source/blender/compositor/operations/COM_MaskOperation.cc
index c7763f08e71..84992f23924 100644
--- a/source/blender/compositor/operations/COM_MaskOperation.cc
+++ b/source/blender/compositor/operations/COM_MaskOperation.cc
@@ -161,4 +161,41 @@ void MaskOperation::executePixelSampled(float output[4],
}
}
+void MaskOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> UNUSED(inputs))
+{
+ Vector<MaskRasterHandle *> handles = get_non_null_handles();
+ if (handles.size() == 0) {
+ output->fill(area, COM_VALUE_ZERO);
+ return;
+ }
+
+ float xy[2];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ xy[0] = it.x * m_maskWidthInv + m_mask_px_ofs[0];
+ xy[1] = it.y * m_maskHeightInv + m_mask_px_ofs[1];
+ *it.out = 0.0f;
+ for (MaskRasterHandle *handle : handles) {
+ *it.out += BKE_maskrasterize_handle_sample(handle, xy);
+ }
+
+ /* Until we get better falloff. */
+ *it.out /= m_rasterMaskHandleTot;
+ }
+}
+
+Vector<MaskRasterHandle *> MaskOperation::get_non_null_handles() const
+{
+ Vector<MaskRasterHandle *> handles;
+ for (int i = 0; i < m_rasterMaskHandleTot; i++) {
+ MaskRasterHandle *handle = m_rasterMaskHandles[i];
+ if (handle == nullptr) {
+ continue;
+ }
+ handles.append(handle);
+ }
+ return handles;
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h
index e8cd9c722df..81e344c0451 100644
--- a/source/blender/compositor/operations/COM_MaskOperation.h
+++ b/source/blender/compositor/operations/COM_MaskOperation.h
@@ -19,7 +19,7 @@
#pragma once
#include "BLI_listbase.h"
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_mask_types.h"
#include "IMB_imbuf_types.h"
@@ -31,7 +31,7 @@ namespace blender::compositor {
/**
* Class with implementation of mask rasterization
*/
-class MaskOperation : public NodeOperation {
+class MaskOperation : public MultiThreadedOperation {
protected:
Mask *m_mask;
@@ -98,6 +98,13 @@ class MaskOperation : public NodeOperation {
}
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
+ private:
+ Vector<MaskRasterHandle *> get_non_null_handles() const;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cc b/source/blender/compositor/operations/COM_MathBaseOperation.cc
index a94c14347fb..2256dce011b 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cc
@@ -24,6 +24,8 @@ namespace blender::compositor {
MathBaseOperation::MathBaseOperation()
{
+ /* TODO(manzanilla): after removing tiled implementation, template this class to only add needed
+ * number of inputs. */
this->addInputSocket(DataType::Value);
this->addInputSocket(DataType::Value);
this->addInputSocket(DataType::Value);
@@ -32,6 +34,7 @@ MathBaseOperation::MathBaseOperation()
this->m_inputValue2Operation = nullptr;
this->m_inputValue3Operation = nullptr;
this->m_useClamp = false;
+ this->flags.can_be_constant = true;
}
void MathBaseOperation::initExecution()
@@ -73,6 +76,14 @@ void MathBaseOperation::clampIfNeeded(float *color)
}
}
+void MathBaseOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ BuffersIterator<float> it = output->iterate_with(inputs, area);
+ update_memory_buffer_partial(it);
+}
+
void MathAddOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue1[4];
@@ -139,6 +150,14 @@ void MathDivideOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathDivideOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float divisor = *it.in(1);
+ *it.out = clamp_when_enabled((divisor == 0) ? 0 : *it.in(0) / divisor);
+ }
+}
+
void MathSineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -155,6 +174,14 @@ void MathSineOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathSineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = sin(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathCosineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -171,6 +198,14 @@ void MathCosineOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathCosineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = cos(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathTangentOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -187,6 +222,14 @@ void MathTangentOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathTangentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = tan(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathHyperbolicSineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -203,6 +246,14 @@ void MathHyperbolicSineOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathHyperbolicSineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = sinh(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathHyperbolicCosineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -219,6 +270,14 @@ void MathHyperbolicCosineOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathHyperbolicCosineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = cosh(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathHyperbolicTangentOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -235,6 +294,14 @@ void MathHyperbolicTangentOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathHyperbolicTangentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = tanh(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathArcSineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -256,6 +323,14 @@ void MathArcSineOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathArcSineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ float value1 = *it.in(0);
+ *it.out = clamp_when_enabled((value1 <= 1 && value1 >= -1) ? asin(value1) : 0.0f);
+ }
+}
+
void MathArcCosineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -277,6 +352,14 @@ void MathArcCosineOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathArcCosineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ float value1 = *it.in(0);
+ *it.out = clamp_when_enabled((value1 <= 1 && value1 >= -1) ? acos(value1) : 0.0f);
+ }
+}
+
void MathArcTangentOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -293,6 +376,14 @@ void MathArcTangentOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathArcTangentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = atan(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathPowerOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -321,6 +412,29 @@ void MathPowerOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathPowerOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value1 = *it.in(0);
+ const float value2 = *it.in(1);
+ if (value1 >= 0) {
+ *it.out = pow(value1, value2);
+ }
+ else {
+ const float y_mod_1 = fmod(value2, 1);
+ /* If input value is not nearly an integer, fall back to zero, nicer than straight rounding.
+ */
+ if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) {
+ *it.out = pow(value1, floorf(value2 + 0.5f));
+ }
+ else {
+ *it.out = 0.0f;
+ }
+ }
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathLogarithmOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -342,6 +456,21 @@ void MathLogarithmOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathLogarithmOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value1 = *it.in(0);
+ const float value2 = *it.in(1);
+ if (value1 > 0 && value2 > 0) {
+ *it.out = log(value1) / log(value2);
+ }
+ else {
+ *it.out = 0.0;
+ }
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathMinimumOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -358,6 +487,14 @@ void MathMinimumOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathMinimumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = MIN2(*it.in(0), *it.in(1));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathMaximumOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -374,6 +511,14 @@ void MathMaximumOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathMaximumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = MAX2(*it.in(0), *it.in(1));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathRoundOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -390,6 +535,14 @@ void MathRoundOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathRoundOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = round(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathLessThanOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -443,6 +596,15 @@ void MathModuloOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathModuloOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value2 = *it.in(1);
+ *it.out = (value2 == 0) ? 0 : fmod(*it.in(0), value2);
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathAbsoluteOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -457,6 +619,14 @@ void MathAbsoluteOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathAbsoluteOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = fabs(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathRadiansOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -471,6 +641,14 @@ void MathRadiansOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathRadiansOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = DEG2RADF(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathDegreesOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -485,6 +663,14 @@ void MathDegreesOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathDegreesOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = RAD2DEGF(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathArcTan2Operation::executePixelSampled(float output[4],
float x,
float y,
@@ -501,6 +687,14 @@ void MathArcTan2Operation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathArcTan2Operation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = atan2(*it.in(0), *it.in(1));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathFloorOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -515,6 +709,14 @@ void MathFloorOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathFloorOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = floor(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathCeilOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -529,6 +731,14 @@ void MathCeilOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathCeilOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = ceil(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathFractOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -543,6 +753,14 @@ void MathFractOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathFractOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value = *it.in(0);
+ *it.out = clamp_when_enabled(value - floor(value));
+ }
+}
+
void MathSqrtOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -562,6 +780,14 @@ void MathSqrtOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathSqrtOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value = *it.in(0);
+ *it.out = clamp_when_enabled(value > 0 ? sqrt(value) : 0.0f);
+ }
+}
+
void MathInverseSqrtOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -581,6 +807,14 @@ void MathInverseSqrtOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathInverseSqrtOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value = *it.in(0);
+ *it.out = clamp_when_enabled(value > 0 ? 1.0f / sqrt(value) : 0.0f);
+ }
+}
+
void MathSignOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -595,6 +829,14 @@ void MathSignOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathSignOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = compatible_signf(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathExponentOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -609,6 +851,14 @@ void MathExponentOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathExponentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = expf(*it.in(0));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathTruncOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -623,6 +873,15 @@ void MathTruncOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathTruncOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value = *it.in(0);
+ *it.out = (value >= 0.0f) ? floor(value) : ceil(value);
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathSnapOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -644,6 +903,21 @@ void MathSnapOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathSnapOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ const float value1 = *it.in(0);
+ const float value2 = *it.in(1);
+ if (value1 == 0 || value2 == 0) { /* Avoid dividing by zero. */
+ *it.out = 0.0f;
+ }
+ else {
+ *it.out = floorf(value1 / value2) * value2;
+ }
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathWrapOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -662,6 +936,14 @@ void MathWrapOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathWrapOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = wrapf(*it.in(0), *it.in(1), *it.in(2));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathPingpongOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -678,6 +960,14 @@ void MathPingpongOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathPingpongOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = pingpongf(*it.in(0), *it.in(1));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathCompareOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -697,6 +987,14 @@ void MathCompareOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathCompareOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = (fabsf(*it.in(0) - *it.in(1)) <= MAX2(*it.in(2), 1e-5f)) ? 1.0f : 0.0f;
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathMultiplyAddOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -715,6 +1013,14 @@ void MathMultiplyAddOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathMultiplyAddOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = it.in(0)[0] * it.in(1)[0] + it.in(2)[0];
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathSmoothMinOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -733,6 +1039,14 @@ void MathSmoothMinOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathSmoothMinOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = smoothminf(*it.in(0), *it.in(1), *it.in(2));
+ clamp_when_enabled(it.out);
+ }
+}
+
void MathSmoothMaxOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -751,4 +1065,12 @@ void MathSmoothMaxOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathSmoothMaxOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+ for (; !it.is_end(); ++it) {
+ *it.out = -smoothminf(-it.in(0)[0], -it.in(1)[0], it.in(2)[0]);
+ clamp_when_enabled(it.out);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h
index 08794c8db22..d2da05db68e 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.h
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class MathBaseOperation : public NodeOperation {
+class MathBaseOperation : public MultiThreadedOperation {
protected:
/**
* Prefetched reference to the inputProgram
@@ -43,8 +43,24 @@ class MathBaseOperation : public NodeOperation {
*/
MathBaseOperation();
+ /* TODO(manzanilla): to be removed with tiled implementation. */
void clampIfNeeded(float color[4]);
+ float clamp_when_enabled(float value)
+ {
+ if (this->m_useClamp) {
+ return CLAMPIS(value, 0.0f, 1.0f);
+ }
+ return value;
+ }
+
+ void clamp_when_enabled(float *out)
+ {
+ if (this->m_useClamp) {
+ CLAMP(*out, 0.0f, 1.0f);
+ }
+ }
+
public:
/**
* Initialize the execution
@@ -66,87 +82,151 @@ class MathBaseOperation : public NodeOperation {
{
this->m_useClamp = value;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) final;
+
+ protected:
+ virtual void update_memory_buffer_partial(BuffersIterator<float> &it) = 0;
};
-class MathAddOperation : public MathBaseOperation {
+template<template<typename> typename TFunctor>
+class MathFunctor2Operation : public MathBaseOperation {
+ void update_memory_buffer_partial(BuffersIterator<float> &it) final
+ {
+ TFunctor functor;
+ for (; !it.is_end(); ++it) {
+ *it.out = functor(*it.in(0), *it.in(1));
+ clamp_when_enabled(it.out);
+ }
+ }
+};
+
+class MathAddOperation : public MathFunctor2Operation<std::plus> {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
};
-class MathSubtractOperation : public MathBaseOperation {
+class MathSubtractOperation : public MathFunctor2Operation<std::minus> {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
};
-class MathMultiplyOperation : public MathBaseOperation {
+class MathMultiplyOperation : public MathFunctor2Operation<std::multiplies> {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
};
class MathDivideOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathSineOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathCosineOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathTangentOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathHyperbolicSineOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathHyperbolicCosineOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathHyperbolicTangentOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathArcSineOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathArcCosineOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathArcTangentOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathPowerOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathLogarithmOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathMinimumOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathMaximumOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathRoundOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
-class MathLessThanOperation : public MathBaseOperation {
+class MathLessThanOperation : public MathFunctor2Operation<std::less> {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
};
-class MathGreaterThanOperation : public MathBaseOperation {
+class MathGreaterThanOperation : public MathFunctor2Operation<std::greater> {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
};
@@ -154,101 +234,161 @@ class MathGreaterThanOperation : public MathBaseOperation {
class MathModuloOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathAbsoluteOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathRadiansOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathDegreesOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathArcTan2Operation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathFloorOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathCeilOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathFractOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathSqrtOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathInverseSqrtOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathSignOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathExponentOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathTruncOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathSnapOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathWrapOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathPingpongOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathCompareOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathMultiplyAddOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathSmoothMinOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
class MathSmoothMaxOperation : public MathBaseOperation {
public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ protected:
+ void update_memory_buffer_partial(BuffersIterator<float> &it) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc
index a9f187258b2..e36e93984fb 100644
--- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc
+++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc
@@ -29,10 +29,21 @@ MovieClipAttributeOperation::MovieClipAttributeOperation()
this->m_framenumber = 0;
this->m_attribute = MCA_X;
this->m_invert = false;
+ needs_resolution_to_get_constant_ = true;
+ is_value_calculated_ = false;
}
void MovieClipAttributeOperation::initExecution()
{
+ if (!is_value_calculated_) {
+ calc_value();
+ }
+}
+
+void MovieClipAttributeOperation::calc_value()
+{
+ BLI_assert(this->get_flags().is_resolution_set);
+ is_value_calculated_ = true;
if (this->m_clip == nullptr) {
return;
}
@@ -83,4 +94,12 @@ void MovieClipAttributeOperation::determineResolution(unsigned int resolution[2]
resolution[1] = preferredResolution[1];
}
+const float *MovieClipAttributeOperation::get_constant_elem()
+{
+ if (!is_value_calculated_) {
+ calc_value();
+ }
+ return &m_value;
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h
index 8507e98d08f..28c39d4dad3 100644
--- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h
+++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h
@@ -18,6 +18,7 @@
#pragma once
+#include "COM_ConstantOperation.h"
#include "COM_NodeOperation.h"
#include "DNA_movieclip_types.h"
@@ -33,13 +34,14 @@ typedef enum MovieClipAttribute {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class MovieClipAttributeOperation : public NodeOperation {
+class MovieClipAttributeOperation : public ConstantOperation {
private:
MovieClip *m_clip;
float m_value;
int m_framenumber;
bool m_invert;
MovieClipAttribute m_attribute;
+ bool is_value_calculated_;
public:
/**
@@ -56,6 +58,8 @@ class MovieClipAttributeOperation : public NodeOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
+ const float *get_constant_elem() override;
+
void setMovieClip(MovieClip *clip)
{
this->m_clip = clip;
@@ -72,6 +76,9 @@ class MovieClipAttributeOperation : public NodeOperation {
{
this->m_invert = invert;
}
+
+ private:
+ void calc_value();
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.cc b/source/blender/compositor/operations/COM_MovieDistortionOperation.cc
index c8e045ea117..d3424959061 100644
--- a/source/blender/compositor/operations/COM_MovieDistortionOperation.cc
+++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.cc
@@ -128,4 +128,51 @@ bool MovieDistortionOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void MovieDistortionOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ BLI_assert(input_idx == 0);
+ UNUSED_VARS_NDEBUG(input_idx);
+ r_input_area.xmin = output_area.xmin - m_margin[0];
+ r_input_area.ymin = output_area.ymin - m_margin[1];
+ r_input_area.xmax = output_area.xmax + m_margin[0];
+ r_input_area.ymax = output_area.ymax + m_margin[1];
+}
+
+void MovieDistortionOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_img = inputs[0];
+ if (this->m_distortion == nullptr) {
+ output->copy_from(input_img, area);
+ return;
+ }
+
+ /* `float overscan = 0.0f;` */
+ const float pixel_aspect = this->m_pixel_aspect;
+ const float w = (float)this->m_width /* `/ (1 + overscan)` */;
+ const float h = (float)this->m_height /* `/ (1 + overscan)` */;
+ const float aspx = w / (float)this->m_calibration_width;
+ const float aspy = h / (float)this->m_calibration_height;
+ float xy[2];
+ float distorted_xy[2];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ xy[0] = (it.x /* `- 0.5 * overscan * w` */) / aspx;
+ xy[1] = (it.y /* `- 0.5 * overscan * h` */) / aspy / pixel_aspect;
+
+ if (this->m_apply) {
+ BKE_tracking_distortion_undistort_v2(this->m_distortion, xy, distorted_xy);
+ }
+ else {
+ BKE_tracking_distortion_distort_v2(this->m_distortion, xy, distorted_xy);
+ }
+
+ const float u = distorted_xy[0] * aspx /* `+ 0.5 * overscan * w` */;
+ const float v = (distorted_xy[1] * aspy /* `+ 0.5 * overscan * h` */) * pixel_aspect;
+ input_img->read_elem_bilinear(u, v, it.out);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.h b/source/blender/compositor/operations/COM_MovieDistortionOperation.h
index 631a62f7ebf..69c2f9c269c 100644
--- a/source/blender/compositor/operations/COM_MovieDistortionOperation.h
+++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_movieclip_types.h"
#include "MEM_guardedalloc.h"
@@ -26,7 +26,7 @@
namespace blender::compositor {
-class MovieDistortionOperation : public NodeOperation {
+class MovieDistortionOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputOperation;
MovieClip *m_movieClip;
@@ -58,6 +58,11 @@ class MovieDistortionOperation : public NodeOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cc b/source/blender/compositor/operations/COM_OutputFileOperation.cc
index 6c5984e3414..402d29893a4 100644
--- a/source/blender/compositor/operations/COM_OutputFileOperation.cc
+++ b/source/blender/compositor/operations/COM_OutputFileOperation.cc
@@ -294,6 +294,22 @@ void OutputSingleLayerOperation::deinitExecution()
this->m_imageInput = nullptr;
}
+void OutputSingleLayerOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output),
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ if (!m_outputBuffer) {
+ return;
+ }
+
+ MemoryBuffer output_buf(m_outputBuffer,
+ COM_data_type_num_channels(this->m_datatype),
+ this->getWidth(),
+ this->getHeight());
+ const MemoryBuffer *input_image = inputs[0];
+ output_buf.copy_from(input_image, area);
+}
+
/******************************* MultiLayer *******************************/
OutputOpenExrLayer::OutputOpenExrLayer(const char *name_, DataType datatype_, bool use_layer_)
@@ -444,4 +460,21 @@ void OutputOpenExrMultiLayerOperation::deinitExecution()
}
}
+void OutputOpenExrMultiLayerOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output),
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_image = inputs[0];
+ for (int i = 0; i < this->m_layers.size(); i++) {
+ OutputOpenExrLayer &layer = this->m_layers[i];
+ if (layer.outputBuffer) {
+ MemoryBuffer output_buf(layer.outputBuffer,
+ COM_data_type_num_channels(layer.datatype),
+ this->getWidth(),
+ this->getHeight());
+ output_buf.copy_from(input_image, area);
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h
index 64ab4c06e7c..057cee0c43e 100644
--- a/source/blender/compositor/operations/COM_OutputFileOperation.h
+++ b/source/blender/compositor/operations/COM_OutputFileOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "BLI_path_util.h"
#include "BLI_rect.h"
@@ -30,7 +30,7 @@
namespace blender::compositor {
/* Writes the image to a single-layer file. */
-class OutputSingleLayerOperation : public NodeOperation {
+class OutputSingleLayerOperation : public MultiThreadedOperation {
protected:
const RenderData *m_rd;
const bNodeTree *m_tree;
@@ -70,6 +70,10 @@ class OutputSingleLayerOperation : public NodeOperation {
{
return eCompositorPriority::Low;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
/* extra info for OpenEXR layers */
@@ -86,7 +90,7 @@ struct OutputOpenExrLayer {
};
/* Writes inputs into OpenEXR multilayer channels. */
-class OutputOpenExrMultiLayerOperation : public NodeOperation {
+class OutputOpenExrMultiLayerOperation : public MultiThreadedOperation {
protected:
const Scene *m_scene;
const RenderData *m_rd;
@@ -122,6 +126,10 @@ class OutputOpenExrMultiLayerOperation : public NodeOperation {
{
return eCompositorPriority::Low;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
void add_exr_channels(void *exrhandle,
diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc
index 3577860b93d..d2a06ddd7c4 100644
--- a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc
+++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc
@@ -16,6 +16,7 @@
*/
#include "COM_PlaneCornerPinOperation.h"
+#include "COM_ConstantOperation.h"
#include "COM_ReadBufferOperation.h"
#include "MEM_guardedalloc.h"
@@ -28,6 +29,11 @@
namespace blender::compositor {
+constexpr int LOWER_LEFT_CORNER_INDEX = 0;
+constexpr int LOWER_RIGHT_CORNER_INDEX = 1;
+constexpr int UPPER_RIGHT_CORNER_INDEX = 2;
+constexpr int UPPER_LEFT_CORNER_INDEX = 3;
+
static bool check_corners(float corners[4][2])
{
int i, next, prev;
@@ -58,6 +64,7 @@ static bool check_corners(float corners[4][2])
return true;
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
static void readCornersFromSockets(rcti *rect, SocketReader *readers[4], float corners[4][2])
{
for (int i = 0; i < 4; i++) {
@@ -87,6 +94,53 @@ static void readCornersFromSockets(rcti *rect, SocketReader *readers[4], float c
}
}
+static void set_default_corner(const int corner_idx, float r_corner[2])
+{
+ BLI_assert(corner_idx >= 0 && corner_idx < 4);
+ switch (corner_idx) {
+ case LOWER_LEFT_CORNER_INDEX:
+ r_corner[0] = 0.0f;
+ r_corner[1] = 0.0f;
+ break;
+ case LOWER_RIGHT_CORNER_INDEX:
+ r_corner[0] = 1.0f;
+ r_corner[1] = 0.0f;
+ break;
+ case UPPER_RIGHT_CORNER_INDEX:
+ r_corner[0] = 1.0f;
+ r_corner[1] = 1.0f;
+ break;
+ case UPPER_LEFT_CORNER_INDEX:
+ r_corner[0] = 0.0f;
+ r_corner[1] = 1.0f;
+ break;
+ }
+}
+
+static void read_input_corners(NodeOperation *op, const int first_input_idx, float r_corners[4][2])
+{
+ for (const int i : IndexRange(4)) {
+ NodeOperation *input = op->get_input_operation(i + first_input_idx);
+ if (input->get_flags().is_constant_operation) {
+ ConstantOperation *corner_input = static_cast<ConstantOperation *>(input);
+ copy_v2_v2(r_corners[i], corner_input->get_constant_elem());
+ }
+ else {
+ set_default_corner(i, r_corners[i]);
+ }
+ }
+
+ /* Convexity check: concave corners need to be prevented, otherwise
+ * #BKE_tracking_homography_between_two_quads will freeze. */
+ if (!check_corners(r_corners)) {
+ /* Revert to default corners. There could be a more elegant solution,
+ * this prevents freezing at least. */
+ for (const int i : IndexRange(4)) {
+ set_default_corner(i, r_corners[i]);
+ }
+ }
+}
+
/* ******** PlaneCornerPinMaskOperation ******** */
PlaneCornerPinMaskOperation::PlaneCornerPinMaskOperation() : m_corners_ready(false)
@@ -103,6 +157,17 @@ PlaneCornerPinMaskOperation::PlaneCornerPinMaskOperation() : m_corners_ready(fal
flags.complex = true;
}
+void PlaneCornerPinMaskOperation::init_data()
+{
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ float corners[4][2];
+ read_input_corners(this, 0, corners);
+ calculateCorners(corners, true, 0);
+ }
+}
+
+/* TODO(manzanilla): to be removed with tiled implementation. Same for #deinitExecution and do the
+ * same on #PlaneCornerPinWarpImageOperation. */
void PlaneCornerPinMaskOperation::initExecution()
{
PlaneDistortMaskOperation::initExecution();
@@ -147,10 +212,22 @@ void *PlaneCornerPinMaskOperation::initializeTileData(rcti *rect)
void PlaneCornerPinMaskOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ /* Determine inputs resolution. */
+ PlaneDistortMaskOperation::determineResolution(resolution, preferredResolution);
+ }
resolution[0] = preferredResolution[0];
resolution[1] = preferredResolution[1];
}
+void PlaneCornerPinMaskOperation::get_area_of_interest(const int UNUSED(input_idx),
+ const rcti &UNUSED(output_area),
+ rcti &r_input_area)
+{
+ /* All corner inputs are used as constants. */
+ r_input_area = COM_SINGLE_ELEM_AREA;
+}
+
/* ******** PlaneCornerPinWarpImageOperation ******** */
PlaneCornerPinWarpImageOperation::PlaneCornerPinWarpImageOperation() : m_corners_ready(false)
@@ -161,6 +238,15 @@ PlaneCornerPinWarpImageOperation::PlaneCornerPinWarpImageOperation() : m_corners
addInputSocket(DataType::Vector);
}
+void PlaneCornerPinWarpImageOperation::init_data()
+{
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ float corners[4][2];
+ read_input_corners(this, 1, corners);
+ calculateCorners(corners, true, 0);
+ }
+}
+
void PlaneCornerPinWarpImageOperation::initExecution()
{
PlaneDistortWarpImageOperation::initExecution();
@@ -227,4 +313,17 @@ bool PlaneCornerPinWarpImageOperation::determineDependingAreaOfInterest(
#endif
}
+void PlaneCornerPinWarpImageOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx == 0) {
+ PlaneDistortWarpImageOperation::get_area_of_interest(input_idx, output_area, r_input_area);
+ }
+ else {
+ /* Corner inputs are used as constants. */
+ r_input_area = COM_SINGLE_ELEM_AREA;
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h
index 91c0cd9e16b..2831e937147 100644
--- a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h
+++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h
@@ -31,11 +31,13 @@ namespace blender::compositor {
class PlaneCornerPinMaskOperation : public PlaneDistortMaskOperation {
private:
+ /* TODO(manzanilla): to be removed with tiled implementation. */
bool m_corners_ready;
public:
PlaneCornerPinMaskOperation();
+ void init_data() override;
void initExecution() override;
void deinitExecution() override;
@@ -43,6 +45,8 @@ class PlaneCornerPinMaskOperation : public PlaneDistortMaskOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
};
class PlaneCornerPinWarpImageOperation : public PlaneDistortWarpImageOperation {
@@ -52,6 +56,7 @@ class PlaneCornerPinWarpImageOperation : public PlaneDistortWarpImageOperation {
public:
PlaneCornerPinWarpImageOperation();
+ void init_data() override;
void initExecution() override;
void deinitExecution() override;
@@ -60,6 +65,8 @@ class PlaneCornerPinWarpImageOperation : public PlaneDistortWarpImageOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc
index 4edcc206f5b..ccabb3cf11c 100644
--- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc
@@ -85,8 +85,9 @@ void PlaneDistortWarpImageOperation::calculateCorners(const float corners[4][2],
{
PlaneDistortBaseOperation::calculateCorners(corners, normalized, sample);
- const int width = this->m_pixelReader->getWidth();
- const int height = this->m_pixelReader->getHeight();
+ const NodeOperation *image = get_input_operation(0);
+ const int width = image->getWidth();
+ const int height = image->getHeight();
float frame_corners[4][2] = {
{0.0f, 0.0f}, {(float)width, 0.0f}, {(float)width, (float)height}, {0.0f, (float)height}};
MotionSample *sample_data = &this->m_samples[sample];
@@ -127,6 +128,34 @@ void PlaneDistortWarpImageOperation::executePixelSampled(float output[4],
}
}
+void PlaneDistortWarpImageOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_img = inputs[0];
+ float uv[2];
+ float deriv[2][2];
+ BuffersIterator<float> it = output->iterate_with({}, area);
+ if (this->m_motion_blur_samples == 1) {
+ for (; !it.is_end(); ++it) {
+ warpCoord(it.x, it.y, this->m_samples[0].perspectiveMatrix, uv, deriv);
+ input_img->read_elem_filtered(uv[0], uv[1], deriv[0], deriv[1], it.out);
+ }
+ }
+ else {
+ for (; !it.is_end(); ++it) {
+ zero_v4(it.out);
+ for (const int sample : IndexRange(this->m_motion_blur_samples)) {
+ float color[4];
+ warpCoord(it.x, it.y, this->m_samples[sample].perspectiveMatrix, uv, deriv);
+ input_img->read_elem_filtered(uv[0], uv[1], deriv[0], deriv[1], color);
+ add_v4_v4(it.out, color);
+ }
+ mul_v4_fl(it.out, 1.0f / (float)this->m_motion_blur_samples);
+ }
+ }
+}
+
bool PlaneDistortWarpImageOperation::determineDependingAreaOfInterest(
rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
@@ -157,6 +186,51 @@ bool PlaneDistortWarpImageOperation::determineDependingAreaOfInterest(
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void PlaneDistortWarpImageOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx != 0) {
+ r_input_area = output_area;
+ return;
+ }
+
+ /* TODO: figure out the area needed for warping and EWA filtering. */
+ r_input_area.xmin = 0;
+ r_input_area.ymin = 0;
+ r_input_area.xmax = get_input_operation(0)->getWidth();
+ r_input_area.ymax = get_input_operation(0)->getHeight();
+
+/* Old implementation but resulting coordinates are way out of input operation bounds and in some
+ * cases the area result may incorrectly cause cropping. */
+#if 0
+ float min[2], max[2];
+ INIT_MINMAX2(min, max);
+ for (int sample = 0; sample < this->m_motion_blur_samples; sample++) {
+ float UVs[4][2];
+ float deriv[2][2];
+ MotionSample *sample_data = &this->m_samples[sample];
+ /* TODO(sergey): figure out proper way to do this. */
+ warpCoord(
+ output_area.xmin - 2, output_area.ymin - 2, sample_data->perspectiveMatrix, UVs[0], deriv);
+ warpCoord(
+ output_area.xmax + 2, output_area.ymin - 2, sample_data->perspectiveMatrix, UVs[1], deriv);
+ warpCoord(
+ output_area.xmax + 2, output_area.ymax + 2, sample_data->perspectiveMatrix, UVs[2], deriv);
+ warpCoord(
+ output_area.xmin - 2, output_area.ymax + 2, sample_data->perspectiveMatrix, UVs[3], deriv);
+ for (int i = 0; i < 4; i++) {
+ minmax_v2v2_v2(min, max, UVs[i]);
+ }
+ }
+
+ r_input_area.xmin = min[0] - 1;
+ r_input_area.ymin = min[1] - 1;
+ r_input_area.xmax = max[0] + 1;
+ r_input_area.ymax = max[1] + 1;
+#endif
+}
+
/* ******** PlaneDistort Mask ******** */
PlaneDistortMaskOperation::PlaneDistortMaskOperation() : PlaneDistortBaseOperation()
@@ -219,4 +293,41 @@ void PlaneDistortMaskOperation::executePixelSampled(float output[4],
}
}
+void PlaneDistortMaskOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> UNUSED(inputs))
+{
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ int inside_count = 0;
+ for (const int motion_sample : IndexRange(this->m_motion_blur_samples)) {
+ MotionSample &sample = this->m_samples[motion_sample];
+ inside_count += get_jitter_samples_inside_count(it.x, it.y, sample);
+ }
+ *it.out = (float)inside_count / (this->m_osa * this->m_motion_blur_samples);
+ }
+}
+
+int PlaneDistortMaskOperation::get_jitter_samples_inside_count(int x,
+ int y,
+ MotionSample &sample_data)
+{
+ float point[2];
+ int inside_count = 0;
+ for (int sample = 0; sample < this->m_osa; sample++) {
+ point[0] = x + this->m_jitter[sample][0];
+ point[1] = y + this->m_jitter[sample][1];
+ if (isect_point_tri_v2(point,
+ sample_data.frameSpaceCorners[0],
+ sample_data.frameSpaceCorners[1],
+ sample_data.frameSpaceCorners[2]) ||
+ isect_point_tri_v2(point,
+ sample_data.frameSpaceCorners[0],
+ sample_data.frameSpaceCorners[2],
+ sample_data.frameSpaceCorners[3])) {
+ inside_count++;
+ }
+ }
+ return inside_count;
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
index cc6e4d00d71..3ef9c1dfab8 100644
--- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
@@ -20,7 +20,7 @@
#include <string.h>
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
@@ -32,7 +32,7 @@ namespace blender::compositor {
#define PLANE_DISTORT_MAX_SAMPLES 64
-class PlaneDistortBaseOperation : public NodeOperation {
+class PlaneDistortBaseOperation : public MultiThreadedOperation {
protected:
struct MotionSample {
float frameSpaceCorners[4][2]; /* Corners coordinates in pixel space. */
@@ -78,6 +78,11 @@ class PlaneDistortWarpImageOperation : public PlaneDistortBaseOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
class PlaneDistortMaskOperation : public PlaneDistortBaseOperation {
@@ -91,6 +96,13 @@ class PlaneDistortMaskOperation : public PlaneDistortBaseOperation {
void initExecution() override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
+ private:
+ int get_jitter_samples_inside_count(int x, int y, MotionSample &sample_data);
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_PlaneTrackOperation.cc b/source/blender/compositor/operations/COM_PlaneTrackOperation.cc
index 0884f2ad979..bf24f843ca2 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackOperation.cc
+++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.cc
@@ -101,18 +101,40 @@ void PlaneTrackCommon::determineResolution(unsigned int resolution[2],
/* ******** PlaneTrackMaskOperation ******** */
+void PlaneTrackMaskOperation::init_data()
+{
+ PlaneDistortMaskOperation::init_data();
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ PlaneTrackCommon::read_and_calculate_corners(this);
+ }
+}
+
+/* TODO(manzanilla): to be removed with tiled implementation. */
void PlaneTrackMaskOperation::initExecution()
{
PlaneDistortMaskOperation::initExecution();
- PlaneTrackCommon::read_and_calculate_corners(this);
+ if (execution_model_ == eExecutionModel::Tiled) {
+ PlaneTrackCommon::read_and_calculate_corners(this);
+ }
}
/* ******** PlaneTrackWarpImageOperation ******** */
+void PlaneTrackWarpImageOperation::init_data()
+{
+ PlaneDistortWarpImageOperation::init_data();
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ PlaneTrackCommon::read_and_calculate_corners(this);
+ }
+}
+
+/* TODO(manzanilla): to be removed with tiled implementation. */
void PlaneTrackWarpImageOperation::initExecution()
{
PlaneDistortWarpImageOperation::initExecution();
- PlaneTrackCommon::read_and_calculate_corners(this);
+ if (execution_model_ == eExecutionModel::Tiled) {
+ PlaneTrackCommon::read_and_calculate_corners(this);
+ }
}
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_PlaneTrackOperation.h b/source/blender/compositor/operations/COM_PlaneTrackOperation.h
index 3bae230aa06..d2027755162 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackOperation.h
+++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.h
@@ -73,6 +73,8 @@ class PlaneTrackMaskOperation : public PlaneDistortMaskOperation, public PlaneTr
{
}
+ void init_data() override;
+
void initExecution() override;
void determineResolution(unsigned int resolution[2],
@@ -92,6 +94,8 @@ class PlaneTrackWarpImageOperation : public PlaneDistortWarpImageOperation,
{
}
+ void init_data() override;
+
void initExecution() override;
void determineResolution(unsigned int resolution[2],
diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc
index 93702d3f0cf..fcab5dd5751 100644
--- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc
+++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc
@@ -17,6 +17,8 @@
*/
#include "COM_ProjectorLensDistortionOperation.h"
+#include "COM_ConstantOperation.h"
+
#include "BLI_math.h"
#include "BLI_utildefines.h"
@@ -32,6 +34,20 @@ ProjectorLensDistortionOperation::ProjectorLensDistortionOperation()
this->m_dispersionAvailable = false;
this->m_dispersion = 0.0f;
}
+
+void ProjectorLensDistortionOperation::init_data()
+{
+ if (execution_model_ == eExecutionModel::FullFrame) {
+ NodeOperation *dispersion_input = get_input_operation(1);
+ if (dispersion_input->get_flags().is_constant_operation) {
+ this->m_dispersion =
+ static_cast<ConstantOperation *>(dispersion_input)->get_constant_elem()[0];
+ }
+ this->m_kr = 0.25f * max_ff(min_ff(this->m_dispersion, 1.0f), 0.0f);
+ this->m_kr2 = this->m_kr * 20;
+ }
+}
+
void ProjectorLensDistortionOperation::initExecution()
{
this->initMutex();
@@ -97,6 +113,7 @@ bool ProjectorLensDistortionOperation::determineDependingAreaOfInterest(
return false;
}
+/* TODO(manzanilla): to be removed with tiled implementation. */
void ProjectorLensDistortionOperation::updateDispersion()
{
if (this->m_dispersionAvailable) {
@@ -114,4 +131,41 @@ void ProjectorLensDistortionOperation::updateDispersion()
this->unlockMutex();
}
+void ProjectorLensDistortionOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx == 1) {
+ /* Dispersion input is used as constant only. */
+ r_input_area = COM_SINGLE_ELEM_AREA;
+ return;
+ }
+
+ r_input_area.ymax = output_area.ymax;
+ r_input_area.ymin = output_area.ymin;
+ r_input_area.xmin = output_area.xmin - this->m_kr2 - 2;
+ r_input_area.xmax = output_area.xmax + this->m_kr2 + 2;
+}
+
+void ProjectorLensDistortionOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_image = inputs[0];
+ const float height = this->getHeight();
+ const float width = this->getWidth();
+ float color[4];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ const float v = (it.y + 0.5f) / height;
+ const float u = (it.x + 0.5f) / width;
+ input_image->read_elem_bilinear((u * width + this->m_kr2) - 0.5f, v * height - 0.5f, color);
+ it.out[0] = color[0];
+ input_image->read_elem(it.x, it.y, color);
+ it.out[1] = color[1];
+ input_image->read_elem_bilinear((u * width - this->m_kr2) - 0.5f, v * height - 0.5f, color);
+ it.out[2] = color[2];
+ it.out[3] = 1.0f;
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h
index bce61d3de15..7c7626bf271 100644
--- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h
+++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h
@@ -18,12 +18,12 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_node_types.h"
namespace blender::compositor {
-class ProjectorLensDistortionOperation : public NodeOperation {
+class ProjectorLensDistortionOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -31,6 +31,7 @@ class ProjectorLensDistortionOperation : public NodeOperation {
SocketReader *m_inputProgram;
float m_dispersion;
+ /* TODO(manzanilla): to be removed with tiled implementation. */
bool m_dispersionAvailable;
float m_kr, m_kr2;
@@ -43,6 +44,7 @@ class ProjectorLensDistortionOperation : public NodeOperation {
*/
void executePixel(float output[4], int x, int y, void *data) override;
+ void init_data() override;
/**
* Initialize the execution
*/
@@ -59,6 +61,11 @@ class ProjectorLensDistortionOperation : public NodeOperation {
rcti *output) override;
void updateDispersion();
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_RotateOperation.cc b/source/blender/compositor/operations/COM_RotateOperation.cc
index 4fb3d324992..e3c482c15cb 100644
--- a/source/blender/compositor/operations/COM_RotateOperation.cc
+++ b/source/blender/compositor/operations/COM_RotateOperation.cc
@@ -17,6 +17,8 @@
*/
#include "COM_RotateOperation.h"
+#include "COM_ConstantOperation.h"
+
#include "BLI_math.h"
namespace blender::compositor {
@@ -31,13 +33,50 @@ RotateOperation::RotateOperation()
this->m_degreeSocket = nullptr;
this->m_doDegree2RadConversion = false;
this->m_isDegreeSet = false;
+ sampler_ = PixelSampler::Bilinear;
+}
+
+void RotateOperation::get_area_rotation_bounds(const rcti &area,
+ const float center_x,
+ const float center_y,
+ const float sine,
+ const float cosine,
+ rcti &r_bounds)
+{
+ const float dxmin = area.xmin - center_x;
+ const float dymin = area.ymin - center_y;
+ const float dxmax = area.xmax - center_x;
+ const float dymax = area.ymax - center_y;
+
+ const float x1 = center_x + (cosine * dxmin + sine * dymin);
+ const float x2 = center_x + (cosine * dxmax + sine * dymin);
+ const float x3 = center_x + (cosine * dxmin + sine * dymax);
+ const float x4 = center_x + (cosine * dxmax + sine * dymax);
+ const float y1 = center_y + (-sine * dxmin + cosine * dymin);
+ const float y2 = center_y + (-sine * dxmax + cosine * dymin);
+ const float y3 = center_y + (-sine * dxmin + cosine * dymax);
+ const float y4 = center_y + (-sine * dxmax + cosine * dymax);
+ const float minx = MIN2(x1, MIN2(x2, MIN2(x3, x4)));
+ const float maxx = MAX2(x1, MAX2(x2, MAX2(x3, x4)));
+ const float miny = MIN2(y1, MIN2(y2, MIN2(y3, y4)));
+ const float maxy = MAX2(y1, MAX2(y2, MAX2(y3, y4)));
+
+ r_bounds.xmin = floor(minx);
+ r_bounds.xmax = ceil(maxx);
+ r_bounds.ymin = floor(miny);
+ r_bounds.ymax = ceil(maxy);
+}
+
+void RotateOperation::init_data()
+{
+ this->m_centerX = (getWidth() - 1) / 2.0;
+ this->m_centerY = (getHeight() - 1) / 2.0;
}
+
void RotateOperation::initExecution()
{
this->m_imageSocket = this->getInputSocketReader(0);
this->m_degreeSocket = this->getInputSocketReader(1);
- this->m_centerX = (getWidth() - 1) / 2.0;
- this->m_centerY = (getHeight() - 1) / 2.0;
}
void RotateOperation::deinitExecution()
@@ -50,7 +89,19 @@ inline void RotateOperation::ensureDegree()
{
if (!this->m_isDegreeSet) {
float degree[4];
- this->m_degreeSocket->readSampled(degree, 0, 0, PixelSampler::Nearest);
+ switch (execution_model_) {
+ case eExecutionModel::Tiled:
+ this->m_degreeSocket->readSampled(degree, 0, 0, PixelSampler::Nearest);
+ break;
+ case eExecutionModel::FullFrame:
+ NodeOperation *degree_op = getInputOperation(DEGREE_INPUT_INDEX);
+ const bool is_constant_degree = degree_op->get_flags().is_constant_operation;
+ degree[0] = is_constant_degree ?
+ static_cast<ConstantOperation *>(degree_op)->get_constant_elem()[0] :
+ 0.0f;
+ break;
+ }
+
double rad;
if (this->m_doDegree2RadConversion) {
rad = DEG2RAD((double)degree[0]);
@@ -108,4 +159,33 @@ bool RotateOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+void RotateOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ if (input_idx == DEGREE_INPUT_INDEX) {
+ /* Degrees input is always used as constant. */
+ r_input_area = COM_SINGLE_ELEM_AREA;
+ return;
+ }
+
+ ensureDegree();
+ get_area_rotation_bounds(output_area, m_centerX, m_centerY, m_sine, m_cosine, r_input_area);
+ expand_area_for_sampler(r_input_area, sampler_);
+}
+
+void RotateOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ ensureDegree();
+ const MemoryBuffer *input_img = inputs[IMAGE_INPUT_INDEX];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ float x = it.x;
+ float y = it.y;
+ rotate_coords(x, y, m_centerX, m_centerY, m_sine, m_cosine);
+ input_img->read_elem_sampled(x, y, sampler_, it.out);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_RotateOperation.h b/source/blender/compositor/operations/COM_RotateOperation.h
index d76507f9816..f0de699f9ce 100644
--- a/source/blender/compositor/operations/COM_RotateOperation.h
+++ b/source/blender/compositor/operations/COM_RotateOperation.h
@@ -18,12 +18,15 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class RotateOperation : public NodeOperation {
+class RotateOperation : public MultiThreadedOperation {
private:
+ constexpr static int IMAGE_INPUT_INDEX = 0;
+ constexpr static int DEGREE_INPUT_INDEX = 1;
+
SocketReader *m_imageSocket;
SocketReader *m_degreeSocket;
float m_centerX;
@@ -32,21 +35,51 @@ class RotateOperation : public NodeOperation {
float m_sine;
bool m_doDegree2RadConversion;
bool m_isDegreeSet;
+ PixelSampler sampler_;
public:
RotateOperation();
+
+ static void rotate_coords(
+ float &x, float &y, float center_x, float center_y, float sine, float cosine)
+ {
+ const float dx = x - center_x;
+ const float dy = y - center_y;
+ x = center_x + (cosine * dx + sine * dy);
+ y = center_y + (-sine * dx + cosine * dy);
+ }
+
+ static void get_area_rotation_bounds(const rcti &area,
+ const float center_x,
+ const float center_y,
+ const float sine,
+ const float cosine,
+ rcti &r_bounds);
+
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+ void init_data() override;
void initExecution() override;
void deinitExecution() override;
+
void setDoDegree2RadConversion(bool abool)
{
this->m_doDegree2RadConversion = abool;
}
+ void set_sampler(PixelSampler sampler)
+ {
+ sampler_ = sampler;
+ }
+
void ensureDegree();
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cc b/source/blender/compositor/operations/COM_ScaleOperation.cc
index 5410b2c832a..ef34bc7bee6 100644
--- a/source/blender/compositor/operations/COM_ScaleOperation.cc
+++ b/source/blender/compositor/operations/COM_ScaleOperation.cc
@@ -74,17 +74,18 @@ float ScaleOperation::get_constant_scale_y()
return get_constant_scale(2, get_relative_scale_y_factor());
}
-BLI_INLINE float scale_coord(const int coord, const float center, const float relative_scale)
+void ScaleOperation::scale_area(
+ rcti &rect, float center_x, float center_y, float scale_x, float scale_y)
{
- return center + (coord - center) / relative_scale;
+ rect.xmin = scale_coord(rect.xmin, center_x, scale_x);
+ rect.xmax = scale_coord(rect.xmax, center_x, scale_x);
+ rect.ymin = scale_coord(rect.ymin, center_y, scale_y);
+ rect.ymax = scale_coord(rect.ymax, center_y, scale_y);
}
void ScaleOperation::scale_area(rcti &rect, float scale_x, float scale_y)
{
- rect.xmin = scale_coord(rect.xmin, m_centerX, scale_x);
- rect.xmax = scale_coord(rect.xmax, m_centerX, scale_x);
- rect.ymin = scale_coord(rect.ymin, m_centerY, scale_y);
- rect.ymax = scale_coord(rect.ymax, m_centerY, scale_y);
+ scale_area(rect, m_centerX, m_centerY, scale_x, scale_y);
}
void ScaleOperation::init_data()
diff --git a/source/blender/compositor/operations/COM_ScaleOperation.h b/source/blender/compositor/operations/COM_ScaleOperation.h
index 62a2cabc8e6..65762d1ce62 100644
--- a/source/blender/compositor/operations/COM_ScaleOperation.h
+++ b/source/blender/compositor/operations/COM_ScaleOperation.h
@@ -46,6 +46,9 @@ class BaseScaleOperation : public MultiThreadedOperation {
};
class ScaleOperation : public BaseScaleOperation {
+ public:
+ static constexpr float MIN_SCALE = 0.0001f;
+
protected:
SocketReader *m_inputOperation;
SocketReader *m_inputXOperation;
@@ -57,6 +60,12 @@ class ScaleOperation : public BaseScaleOperation {
ScaleOperation();
ScaleOperation(DataType data_type);
+ static float scale_coord(const float coord, const float center, const float relative_scale)
+ {
+ return center + (coord - center) / MAX2(relative_scale, MIN_SCALE);
+ }
+ static void scale_area(rcti &rect, float center_x, float center_y, float scale_x, float scale_y);
+
void init_data() override;
void initExecution() override;
void deinitExecution() override;
diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc
index 634fe66b0dd..1f503051349 100644
--- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc
+++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc
@@ -17,6 +17,7 @@
*/
#include "COM_ScreenLensDistortionOperation.h"
+#include "COM_ConstantOperation.h"
#include "BLI_math.h"
#include "BLI_rand.h"
@@ -53,6 +54,35 @@ void ScreenLensDistortionOperation::setDispersion(float dispersion)
m_dispersion_const = true;
}
+void ScreenLensDistortionOperation::init_data()
+{
+ this->m_cx = 0.5f * (float)getWidth();
+ this->m_cy = 0.5f * (float)getHeight();
+
+ switch (execution_model_) {
+ case eExecutionModel::FullFrame: {
+ NodeOperation *distortion_op = get_input_operation(1);
+ NodeOperation *dispersion_op = get_input_operation(2);
+ if (!m_distortion_const && distortion_op->get_flags().is_constant_operation) {
+ m_distortion = static_cast<ConstantOperation *>(distortion_op)->get_constant_elem()[0];
+ }
+ if (!m_dispersion_const && distortion_op->get_flags().is_constant_operation) {
+ m_dispersion = static_cast<ConstantOperation *>(dispersion_op)->get_constant_elem()[0];
+ }
+ updateVariables(m_distortion, m_dispersion);
+ break;
+ }
+ case eExecutionModel::Tiled: {
+ /* If both are constant, init variables once. */
+ if (m_distortion_const && m_dispersion_const) {
+ updateVariables(m_distortion, m_dispersion);
+ m_variables_ready = true;
+ }
+ break;
+ }
+ }
+}
+
void ScreenLensDistortionOperation::initExecution()
{
this->m_inputProgram = this->getInputSocketReader(0);
@@ -61,15 +91,6 @@ void ScreenLensDistortionOperation::initExecution()
uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
rng_seed ^= (uint)POINTER_AS_INT(m_inputProgram);
this->m_rng = BLI_rng_new(rng_seed);
-
- this->m_cx = 0.5f * (float)getWidth();
- this->m_cy = 0.5f * (float)getHeight();
-
- /* if both are constant, init variables once */
- if (m_distortion_const && m_dispersion_const) {
- updateVariables(m_distortion, m_dispersion);
- m_variables_ready = true;
- }
}
void *ScreenLensDistortionOperation::initializeTileData(rcti * /*rect*/)
@@ -130,7 +151,7 @@ bool ScreenLensDistortionOperation::get_delta(float r_sq,
return false;
}
-void ScreenLensDistortionOperation::accumulate(MemoryBuffer *buffer,
+void ScreenLensDistortionOperation::accumulate(const MemoryBuffer *buffer,
int a,
int b,
float r_sq,
@@ -154,7 +175,14 @@ void ScreenLensDistortionOperation::accumulate(MemoryBuffer *buffer,
float xy[2];
distort_uv(uv, t, xy);
- buffer->readBilinear(color, xy[0], xy[1]);
+ switch (execution_model_) {
+ case eExecutionModel::Tiled:
+ buffer->readBilinear(color, xy[0], xy[1]);
+ break;
+ case eExecutionModel::FullFrame:
+ buffer->read_elem_bilinear(xy[0], xy[1], color);
+ break;
+ }
sum[a] += (1.0f - tz) * color[a];
sum[b] += (tz)*color[b];
@@ -354,4 +382,143 @@ void ScreenLensDistortionOperation::updateVariables(float distortion, float disp
mul_v3_v3fl(m_k4, m_k, 4.0f);
}
+void ScreenLensDistortionOperation::get_area_of_interest(const int input_idx,
+ const rcti &UNUSED(output_area),
+ rcti &r_input_area)
+{
+ if (input_idx != 0) {
+ /* Dispersion and distortion inputs are used as constants only. */
+ r_input_area = COM_SINGLE_ELEM_AREA;
+ }
+
+ /* XXX the original method of estimating the area-of-interest does not work
+ * it assumes a linear increase/decrease of mapped coordinates, which does not
+ * yield correct results for the area and leaves uninitialized buffer areas.
+ * So now just use the full image area, which may not be as efficient but works at least ...
+ */
+#if 1
+ NodeOperation *image = getInputOperation(0);
+ r_input_area.xmax = image->getWidth();
+ r_input_area.xmin = 0;
+ r_input_area.ymax = image->getHeight();
+ r_input_area.ymin = 0;
+
+#else /* Original method in tiled implementation. */
+ rcti newInput;
+ const float margin = 2;
+
+ BLI_rcti_init_minmax(&newInput);
+
+ if (m_dispersion_const && m_distortion_const) {
+ /* update from fixed distortion/dispersion */
+# define UPDATE_INPUT(x, y) \
+ { \
+ float coords[6]; \
+ determineUV(coords, x, y); \
+ newInput.xmin = min_ffff(newInput.xmin, coords[0], coords[2], coords[4]); \
+ newInput.ymin = min_ffff(newInput.ymin, coords[1], coords[3], coords[5]); \
+ newInput.xmax = max_ffff(newInput.xmax, coords[0], coords[2], coords[4]); \
+ newInput.ymax = max_ffff(newInput.ymax, coords[1], coords[3], coords[5]); \
+ } \
+ (void)0
+
+ UPDATE_INPUT(input->xmin, input->xmax);
+ UPDATE_INPUT(input->xmin, input->ymax);
+ UPDATE_INPUT(input->xmax, input->ymax);
+ UPDATE_INPUT(input->xmax, input->ymin);
+
+# undef UPDATE_INPUT
+ }
+ else {
+ /* use maximum dispersion 1.0 if not const */
+ float dispersion = m_dispersion_const ? m_dispersion : 1.0f;
+
+# define UPDATE_INPUT(x, y, distortion) \
+ { \
+ float coords[6]; \
+ updateVariables(distortion, dispersion); \
+ determineUV(coords, x, y); \
+ newInput.xmin = min_ffff(newInput.xmin, coords[0], coords[2], coords[4]); \
+ newInput.ymin = min_ffff(newInput.ymin, coords[1], coords[3], coords[5]); \
+ newInput.xmax = max_ffff(newInput.xmax, coords[0], coords[2], coords[4]); \
+ newInput.ymax = max_ffff(newInput.ymax, coords[1], coords[3], coords[5]); \
+ } \
+ (void)0
+
+ if (m_distortion_const) {
+ /* update from fixed distortion */
+ UPDATE_INPUT(input->xmin, input->xmax, m_distortion);
+ UPDATE_INPUT(input->xmin, input->ymax, m_distortion);
+ UPDATE_INPUT(input->xmax, input->ymax, m_distortion);
+ UPDATE_INPUT(input->xmax, input->ymin, m_distortion);
+ }
+ else {
+ /* update from min/max distortion (-1..1) */
+ UPDATE_INPUT(input->xmin, input->xmax, -1.0f);
+ UPDATE_INPUT(input->xmin, input->ymax, -1.0f);
+ UPDATE_INPUT(input->xmax, input->ymax, -1.0f);
+ UPDATE_INPUT(input->xmax, input->ymin, -1.0f);
+
+ UPDATE_INPUT(input->xmin, input->xmax, 1.0f);
+ UPDATE_INPUT(input->xmin, input->ymax, 1.0f);
+ UPDATE_INPUT(input->xmax, input->ymax, 1.0f);
+ UPDATE_INPUT(input->xmax, input->ymin, 1.0f);
+
+# undef UPDATE_INPUT
+ }
+ }
+
+ newInput.xmin -= margin;
+ newInput.ymin -= margin;
+ newInput.xmax += margin;
+ newInput.ymax += margin;
+
+ operation = getInputOperation(0);
+ if (operation->determineDependingAreaOfInterest(&newInput, readOperation, output)) {
+ return true;
+ }
+ return false;
+#endif
+}
+
+void ScreenLensDistortionOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_image = inputs[0];
+ for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+ float xy[2] = {(float)it.x, (float)it.y};
+ float uv[2];
+ get_uv(xy, uv);
+ const float uv_dot = len_squared_v2(uv);
+
+ float delta[3][2];
+ const bool valid_r = get_delta(uv_dot, m_k4[0], uv, delta[0]);
+ const bool valid_g = get_delta(uv_dot, m_k4[1], uv, delta[1]);
+ const bool valid_b = get_delta(uv_dot, m_k4[2], uv, delta[2]);
+ if (!(valid_r && valid_g && valid_b)) {
+ zero_v4(it.out);
+ continue;
+ }
+
+ int count[3] = {0, 0, 0};
+ float sum[4] = {0, 0, 0, 0};
+ accumulate(input_image, 0, 1, uv_dot, uv, delta, sum, count);
+ accumulate(input_image, 1, 2, uv_dot, uv, delta, sum, count);
+
+ if (count[0]) {
+ it.out[0] = 2.0f * sum[0] / (float)count[0];
+ }
+ if (count[1]) {
+ it.out[1] = 2.0f * sum[1] / (float)count[1];
+ }
+ if (count[2]) {
+ it.out[2] = 2.0f * sum[2] / (float)count[2];
+ }
+
+ /* Set alpha. */
+ it.out[3] = 1.0f;
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h
index 98872bfe142..616fc8883b0 100644
--- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h
+++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h
@@ -18,14 +18,14 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_node_types.h"
struct RNG;
namespace blender::compositor {
-class ScreenLensDistortionOperation : public NodeOperation {
+class ScreenLensDistortionOperation : public MultiThreadedOperation {
private:
/**
* Cached reference to the inputProgram
@@ -50,6 +50,8 @@ class ScreenLensDistortionOperation : public NodeOperation {
public:
ScreenLensDistortionOperation();
+ void init_data() override;
+
/**
* The inner loop of this operation.
*/
@@ -84,6 +86,11 @@ class ScreenLensDistortionOperation : public NodeOperation {
ReadBufferOperation *readOperation,
rcti *output) override;
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
private:
void determineUV(float result[6], float x, float y) const;
void updateVariables(float distortion, float dispersion);
@@ -91,7 +98,7 @@ class ScreenLensDistortionOperation : public NodeOperation {
void get_uv(const float xy[2], float uv[2]) const;
void distort_uv(const float uv[2], float t, float xy[2]) const;
bool get_delta(float r_sq, float k4, const float uv[2], float delta[2]) const;
- void accumulate(MemoryBuffer *buffer,
+ void accumulate(const MemoryBuffer *buffer,
int a,
int b,
float r_sq,
diff --git a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc
index 24edbc61d40..e4686ffa76d 100644
--- a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc
+++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc
@@ -28,6 +28,7 @@ SetAlphaMultiplyOperation::SetAlphaMultiplyOperation()
this->m_inputColor = nullptr;
this->m_inputAlpha = nullptr;
+ this->flags.can_be_constant = true;
}
void SetAlphaMultiplyOperation::initExecution()
@@ -56,4 +57,15 @@ void SetAlphaMultiplyOperation::deinitExecution()
this->m_inputAlpha = nullptr;
}
+void SetAlphaMultiplyOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color = it.in(0);
+ const float alpha = *it.in(1);
+ mul_v4_v4fl(it.out, color, alpha);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h
index b4eea659fa2..44885318901 100644
--- a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h
+++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -27,7 +27,7 @@ namespace blender::compositor {
*
* `output color.rgba = input color.rgba * input alpha`
*/
-class SetAlphaMultiplyOperation : public NodeOperation {
+class SetAlphaMultiplyOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputColor;
SocketReader *m_inputAlpha;
@@ -39,6 +39,10 @@ class SetAlphaMultiplyOperation : public NodeOperation {
void initExecution() override;
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc
index 90bfc814b09..434f5d9b63c 100644
--- a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc
+++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc
@@ -28,6 +28,7 @@ SetAlphaReplaceOperation::SetAlphaReplaceOperation()
this->m_inputColor = nullptr;
this->m_inputAlpha = nullptr;
+ this->flags.can_be_constant = true;
}
void SetAlphaReplaceOperation::initExecution()
@@ -54,4 +55,16 @@ void SetAlphaReplaceOperation::deinitExecution()
this->m_inputAlpha = nullptr;
}
+void SetAlphaReplaceOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float *color = it.in(0);
+ const float alpha = *it.in(1);
+ copy_v3_v3(it.out, color);
+ it.out[3] = alpha;
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h
index c84299b6d82..2c2d4cddf5b 100644
--- a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h
+++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class SetAlphaReplaceOperation : public NodeOperation {
+class SetAlphaReplaceOperation : public MultiThreadedOperation {
private:
SocketReader *m_inputColor;
SocketReader *m_inputAlpha;
@@ -44,6 +44,10 @@ class SetAlphaReplaceOperation : public NodeOperation {
void initExecution() override;
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetColorOperation.cc b/source/blender/compositor/operations/COM_SetColorOperation.cc
index bfe735aab15..dbe45fa60db 100644
--- a/source/blender/compositor/operations/COM_SetColorOperation.cc
+++ b/source/blender/compositor/operations/COM_SetColorOperation.cc
@@ -24,7 +24,6 @@ SetColorOperation::SetColorOperation()
{
this->addOutputSocket(DataType::Color);
flags.is_set_operation = true;
- flags.is_fullframe_operation = true;
}
void SetColorOperation::executePixelSampled(float output[4],
@@ -42,13 +41,4 @@ void SetColorOperation::determineResolution(unsigned int resolution[2],
resolution[1] = preferredResolution[1];
}
-void SetColorOperation::update_memory_buffer(MemoryBuffer *output,
- const rcti &area,
- Span<MemoryBuffer *> UNUSED(inputs))
-{
- BLI_assert(output->is_a_single_elem());
- float *out_elem = output->get_elem(area.xmin, area.ymin);
- copy_v4_v4(out_elem, m_color);
-}
-
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetColorOperation.h b/source/blender/compositor/operations/COM_SetColorOperation.h
index f4c0948ee1b..f546d5e7668 100644
--- a/source/blender/compositor/operations/COM_SetColorOperation.h
+++ b/source/blender/compositor/operations/COM_SetColorOperation.h
@@ -85,10 +85,6 @@ class SetColorOperation : public ConstantOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
-
- void update_memory_buffer(MemoryBuffer *output,
- const rcti &area,
- Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetValueOperation.cc b/source/blender/compositor/operations/COM_SetValueOperation.cc
index c12fb106afd..ef43cf64653 100644
--- a/source/blender/compositor/operations/COM_SetValueOperation.cc
+++ b/source/blender/compositor/operations/COM_SetValueOperation.cc
@@ -24,7 +24,6 @@ SetValueOperation::SetValueOperation()
{
this->addOutputSocket(DataType::Value);
flags.is_set_operation = true;
- flags.is_fullframe_operation = true;
}
void SetValueOperation::executePixelSampled(float output[4],
@@ -42,13 +41,4 @@ void SetValueOperation::determineResolution(unsigned int resolution[2],
resolution[1] = preferredResolution[1];
}
-void SetValueOperation::update_memory_buffer(MemoryBuffer *output,
- const rcti &area,
- Span<MemoryBuffer *> UNUSED(inputs))
-{
- BLI_assert(output->is_a_single_elem());
- float *out_elem = output->get_elem(area.xmin, area.ymin);
- *out_elem = m_value;
-}
-
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SetValueOperation.h b/source/blender/compositor/operations/COM_SetValueOperation.h
index f18d44d9554..726624c1c6a 100644
--- a/source/blender/compositor/operations/COM_SetValueOperation.h
+++ b/source/blender/compositor/operations/COM_SetValueOperation.h
@@ -56,9 +56,6 @@ class SetValueOperation : public ConstantOperation {
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
- void update_memory_buffer(MemoryBuffer *output,
- const rcti &area,
- Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SplitOperation.cc b/source/blender/compositor/operations/COM_SplitOperation.cc
index a4754de370d..d18ed3b8e14 100644
--- a/source/blender/compositor/operations/COM_SplitOperation.cc
+++ b/source/blender/compositor/operations/COM_SplitOperation.cc
@@ -79,4 +79,17 @@ void SplitOperation::determineResolution(unsigned int resolution[2],
NodeOperation::determineResolution(resolution, preferredResolution);
}
+void SplitOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const int percent = this->m_xSplit ? this->m_splitPercentage * this->getWidth() / 100.0f :
+ this->m_splitPercentage * this->getHeight() / 100.0f;
+ const size_t elem_bytes = COM_data_type_bytes_len(getOutputSocket()->getDataType());
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const bool is_image1 = this->m_xSplit ? it.x > percent : it.y > percent;
+ memcpy(it.out, it.in(is_image1 ? 0 : 1), elem_bytes);
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SplitOperation.h b/source/blender/compositor/operations/COM_SplitOperation.h
index 09e48821dd0..2d09d2a07dc 100644
--- a/source/blender/compositor/operations/COM_SplitOperation.h
+++ b/source/blender/compositor/operations/COM_SplitOperation.h
@@ -18,11 +18,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class SplitOperation : public NodeOperation {
+class SplitOperation : public MultiThreadedOperation {
private:
SocketReader *m_image1Input;
SocketReader *m_image2Input;
@@ -45,6 +45,10 @@ class SplitOperation : public NodeOperation {
{
this->m_xSplit = xsplit;
}
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.cc b/source/blender/compositor/operations/COM_SunBeamsOperation.cc
index bd82b6397ad..ad96e3a02ba 100644
--- a/source/blender/compositor/operations/COM_SunBeamsOperation.cc
+++ b/source/blender/compositor/operations/COM_SunBeamsOperation.cc
@@ -30,7 +30,7 @@ SunBeamsOperation::SunBeamsOperation()
this->flags.complex = true;
}
-void SunBeamsOperation::initExecution()
+void SunBeamsOperation::calc_rays_common_data()
{
/* convert to pixels */
this->m_source_px[0] = this->m_data.source[0] * this->getWidth();
@@ -38,6 +38,11 @@ void SunBeamsOperation::initExecution()
this->m_ray_length_px = this->m_data.ray_length * MAX2(this->getWidth(), this->getHeight());
}
+void SunBeamsOperation::initExecution()
+{
+ calc_rays_common_data();
+}
+
/**
* Defines a line accumulator for a specific sector,
* given by the four matrix entries that rotate from buffer space into the sector
@@ -140,7 +145,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator {
falloff_factor = dist_max > dist_min ? dr / (float)(dist_max - dist_min) : 0.0f;
- float *iter = input->getBuffer() + COM_DATA_TYPE_COLOR_CHANNELS * (x + input->getWidth() * y);
+ float *iter = input->getBuffer() + input->get_coords_offset(x, y);
return iter;
}
@@ -159,7 +164,6 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator {
float dist_max)
{
const rcti &rect = input->get_rect();
- int buffer_width = input->getWidth();
int x, y, num;
float v, dv;
float falloff_factor;
@@ -168,9 +172,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator {
zero_v4(output);
if ((int)(co[0] - source[0]) == 0 && (int)(co[1] - source[1]) == 0) {
- copy_v4_v4(output,
- input->getBuffer() + COM_DATA_TYPE_COLOR_CHANNELS *
- ((int)source[0] + input->getWidth() * (int)source[1]));
+ copy_v4_v4(output, input->get_elem(source[0], source[1]));
return;
}
@@ -210,7 +212,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator {
/* decrement u */
x -= fxu;
y -= fyu;
- buffer -= (fxu + fyu * buffer_width) * COM_DATA_TYPE_COLOR_CHANNELS;
+ buffer -= fxu * input->elem_stride + fyu * input->row_stride;
/* decrement v (in steps of dv < 1) */
v_local -= dv;
@@ -219,7 +221,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator {
x -= fxv;
y -= fyv;
- buffer -= (fxv + fyv * buffer_width) * COM_DATA_TYPE_COLOR_CHANNELS;
+ buffer -= fxv * input->elem_stride + fyv * input->row_stride;
}
}
@@ -356,4 +358,39 @@ bool SunBeamsOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&rect, readOperation, output);
}
+void SunBeamsOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ BLI_assert(input_idx == 0);
+ UNUSED_VARS(input_idx);
+ calc_rays_common_data();
+
+ r_input_area = output_area;
+ /* Enlarges the rect by moving each corner toward the source.
+ * This is the maximum distance that pixels can influence each other
+ * and gives a rect that contains all possible accumulated pixels. */
+ calc_ray_shift(&r_input_area, output_area.xmin, output_area.ymin, m_source_px, m_ray_length_px);
+ calc_ray_shift(&r_input_area, output_area.xmin, output_area.ymax, m_source_px, m_ray_length_px);
+ calc_ray_shift(&r_input_area, output_area.xmax, output_area.ymin, m_source_px, m_ray_length_px);
+ calc_ray_shift(&r_input_area, output_area.xmax, output_area.ymax, m_source_px, m_ray_length_px);
+}
+
+void SunBeamsOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ MemoryBuffer *input = inputs[0];
+ float coords[2];
+ for (int y = area.ymin; y < area.ymax; y++) {
+ coords[1] = y;
+ float *out_elem = output->get_elem(area.xmin, y);
+ for (int x = area.xmin; x < area.xmax; x++) {
+ coords[0] = x;
+ accumulate_line(input, out_elem, coords, m_source_px, 0.0f, m_ray_length_px);
+ out_elem += output->elem_stride;
+ }
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.h b/source/blender/compositor/operations/COM_SunBeamsOperation.h
index d3725021cde..71fc04453fe 100644
--- a/source/blender/compositor/operations/COM_SunBeamsOperation.h
+++ b/source/blender/compositor/operations/COM_SunBeamsOperation.h
@@ -17,11 +17,11 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
-class SunBeamsOperation : public NodeOperation {
+class SunBeamsOperation : public MultiThreadedOperation {
public:
SunBeamsOperation();
@@ -40,6 +40,14 @@ class SunBeamsOperation : public NodeOperation {
m_data = data;
}
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+
+ private:
+ void calc_rays_common_data();
+
private:
NodeSunBeams m_data;
diff --git a/source/blender/compositor/operations/COM_TonemapOperation.cc b/source/blender/compositor/operations/COM_TonemapOperation.cc
index 6bfacb0c75d..20da468eeb1 100644
--- a/source/blender/compositor/operations/COM_TonemapOperation.cc
+++ b/source/blender/compositor/operations/COM_TonemapOperation.cc
@@ -17,6 +17,8 @@
*/
#include "COM_TonemapOperation.h"
+#include "COM_ExecutionSystem.h"
+
#include "BLI_math.h"
#include "BLI_utildefines.h"
@@ -153,4 +155,126 @@ void TonemapOperation::deinitializeTileData(rcti * /*rect*/, void * /*data*/)
/* pass */
}
+void TonemapOperation::get_area_of_interest(const int input_idx,
+ const rcti &UNUSED(output_area),
+ rcti &r_input_area)
+{
+ BLI_assert(input_idx == 0);
+ NodeOperation *operation = getInputOperation(input_idx);
+ r_input_area.xmin = 0;
+ r_input_area.ymin = 0;
+ r_input_area.xmax = operation->getWidth();
+ r_input_area.ymax = operation->getHeight();
+}
+
+struct Luminance {
+ float sum;
+ float color_sum[3];
+ float log_sum;
+ float min;
+ float max;
+ int num_pixels;
+};
+
+static Luminance calc_area_luminance(const MemoryBuffer *input, const rcti &area)
+{
+ Luminance lum = {0};
+ for (const float *elem : input->get_buffer_area(area)) {
+ const float lu = IMB_colormanagement_get_luminance(elem);
+ lum.sum += lu;
+ add_v3_v3(lum.color_sum, elem);
+ lum.log_sum += logf(MAX2(lu, 0.0f) + 1e-5f);
+ lum.max = MAX2(lu, lum.max);
+ lum.min = MIN2(lu, lum.min);
+ lum.num_pixels++;
+ }
+ return lum;
+}
+
+void TonemapOperation::update_memory_buffer_started(MemoryBuffer *UNUSED(output),
+ const rcti &UNUSED(area),
+ Span<MemoryBuffer *> inputs)
+{
+ if (this->m_cachedInstance == nullptr) {
+ Luminance lum = {0};
+ const MemoryBuffer *input = inputs[0];
+ exec_system_->execute_work<Luminance>(
+ input->get_rect(),
+ [=](const rcti &split) { return calc_area_luminance(input, split); },
+ lum,
+ [](Luminance &join, const Luminance &chunk) {
+ join.sum += chunk.sum;
+ add_v3_v3(join.color_sum, chunk.color_sum);
+ join.log_sum += chunk.log_sum;
+ join.max = MAX2(join.max, chunk.max);
+ join.min = MIN2(join.min, chunk.min);
+ join.num_pixels += chunk.num_pixels;
+ });
+
+ AvgLogLum *avg = new AvgLogLum();
+ avg->lav = lum.sum / lum.num_pixels;
+ mul_v3_v3fl(avg->cav, lum.color_sum, 1.0f / lum.num_pixels);
+ const float max_log = log((double)lum.max + 1e-5);
+ const float min_log = log((double)lum.min + 1e-5);
+ const float avg_log = lum.log_sum / lum.num_pixels;
+ avg->auto_key = (max_log > min_log) ? ((max_log - avg_log) / (max_log - min_log)) : 1.0f;
+ const float al = exp((double)avg_log);
+ avg->al = (al == 0.0f) ? 0.0f : (this->m_data->key / al);
+ avg->igm = (this->m_data->gamma == 0.0f) ? 1 : (1.0f / this->m_data->gamma);
+ this->m_cachedInstance = avg;
+ }
+}
+
+void TonemapOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ AvgLogLum *avg = m_cachedInstance;
+ const float igm = avg->igm;
+ const float offset = this->m_data->offset;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ copy_v4_v4(it.out, it.in(0));
+ mul_v3_fl(it.out, avg->al);
+ float dr = it.out[0] + offset;
+ float dg = it.out[1] + offset;
+ float db = it.out[2] + offset;
+ it.out[0] /= ((dr == 0.0f) ? 1.0f : dr);
+ it.out[1] /= ((dg == 0.0f) ? 1.0f : dg);
+ it.out[2] /= ((db == 0.0f) ? 1.0f : db);
+ if (igm != 0.0f) {
+ it.out[0] = powf(MAX2(it.out[0], 0.0f), igm);
+ it.out[1] = powf(MAX2(it.out[1], 0.0f), igm);
+ it.out[2] = powf(MAX2(it.out[2], 0.0f), igm);
+ }
+ }
+}
+
+void PhotoreceptorTonemapOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ AvgLogLum *avg = m_cachedInstance;
+ NodeTonemap *ntm = this->m_data;
+ const float f = expf(-this->m_data->f);
+ const float m = (ntm->m > 0.0f) ? ntm->m : (0.3f + 0.7f * powf(avg->auto_key, 1.4f));
+ const float ic = 1.0f - ntm->c;
+ const float ia = 1.0f - ntm->a;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ copy_v4_v4(it.out, it.in(0));
+ const float L = IMB_colormanagement_get_luminance(it.out);
+ float I_l = it.out[0] + ic * (L - it.out[0]);
+ float I_g = avg->cav[0] + ic * (avg->lav - avg->cav[0]);
+ float I_a = I_l + ia * (I_g - I_l);
+ it.out[0] /= (it.out[0] + powf(f * I_a, m));
+ I_l = it.out[1] + ic * (L - it.out[1]);
+ I_g = avg->cav[1] + ic * (avg->lav - avg->cav[1]);
+ I_a = I_l + ia * (I_g - I_l);
+ it.out[1] /= (it.out[1] + powf(f * I_a, m));
+ I_l = it.out[2] + ic * (L - it.out[2]);
+ I_g = avg->cav[2] + ic * (avg->lav - avg->cav[2]);
+ I_a = I_l + ia * (I_g - I_l);
+ it.out[2] /= (it.out[2] + powf(f * I_a, m));
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_TonemapOperation.h b/source/blender/compositor/operations/COM_TonemapOperation.h
index 7ecb179504d..56b57730ec1 100644
--- a/source/blender/compositor/operations/COM_TonemapOperation.h
+++ b/source/blender/compositor/operations/COM_TonemapOperation.h
@@ -18,7 +18,7 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "DNA_node_types.h"
namespace blender::compositor {
@@ -39,7 +39,7 @@ typedef struct AvgLogLum {
* \brief base class of tonemap, implementing the simple tonemap
* \ingroup operation
*/
-class TonemapOperation : public NodeOperation {
+class TonemapOperation : public MultiThreadedOperation {
protected:
/**
* \brief Cached reference to the reader
@@ -85,6 +85,14 @@ class TonemapOperation : public NodeOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_started(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+ virtual void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
/**
@@ -99,6 +107,10 @@ class PhotoreceptorTonemapOperation : public TonemapOperation {
* The inner loop of this operation.
*/
void executePixel(float output[4], int x, int y, void *data) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cc b/source/blender/compositor/operations/COM_TrackPositionOperation.cc
index 993410e3e84..0f4be16a620 100644
--- a/source/blender/compositor/operations/COM_TrackPositionOperation.cc
+++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cc
@@ -42,14 +42,24 @@ TrackPositionOperation::TrackPositionOperation()
this->m_relativeFrame = 0;
this->m_speed_output = false;
flags.is_set_operation = true;
+ is_track_position_calculated_ = false;
}
void TrackPositionOperation::initExecution()
{
+ if (!is_track_position_calculated_) {
+ calc_track_position();
+ }
+}
+
+void TrackPositionOperation::calc_track_position()
+{
+ is_track_position_calculated_ = true;
MovieTracking *tracking = nullptr;
MovieClipUser user = {0};
MovieTrackingObject *object;
+ track_position_ = 0;
zero_v2(this->m_markerPos);
zero_v2(this->m_relativePos);
@@ -114,6 +124,14 @@ void TrackPositionOperation::initExecution()
}
}
}
+
+ track_position_ = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis];
+ if (this->m_axis == 0) {
+ track_position_ *= this->m_width;
+ }
+ else {
+ track_position_ *= this->m_height;
+ }
}
void TrackPositionOperation::executePixelSampled(float output[4],
@@ -131,6 +149,14 @@ void TrackPositionOperation::executePixelSampled(float output[4],
}
}
+const float *TrackPositionOperation::get_constant_elem()
+{
+ if (!is_track_position_calculated_) {
+ calc_track_position();
+ }
+ return &track_position_;
+}
+
void TrackPositionOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h
index b0b0a123bd6..f716bd97737 100644
--- a/source/blender/compositor/operations/COM_TrackPositionOperation.h
+++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h
@@ -20,7 +20,7 @@
#include <string.h>
-#include "COM_NodeOperation.h"
+#include "COM_ConstantOperation.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
@@ -33,7 +33,7 @@ namespace blender::compositor {
/**
* Class with implementation of green screen gradient rasterization
*/
-class TrackPositionOperation : public NodeOperation {
+class TrackPositionOperation : public ConstantOperation {
protected:
MovieClip *m_movieClip;
int m_framenumber;
@@ -47,6 +47,8 @@ class TrackPositionOperation : public NodeOperation {
int m_width, m_height;
float m_markerPos[2];
float m_relativePos[2];
+ float track_position_;
+ bool is_track_position_calculated_;
/**
* Determine the output resolution. The resolution is retrieved from the Renderer
@@ -93,6 +95,11 @@ class TrackPositionOperation : public NodeOperation {
void initExecution() override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ const float *get_constant_elem() override;
+
+ private:
+ void calc_track_position();
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_TransformOperation.cc b/source/blender/compositor/operations/COM_TransformOperation.cc
new file mode 100644
index 00000000000..2feaa0ae16d
--- /dev/null
+++ b/source/blender/compositor/operations/COM_TransformOperation.cc
@@ -0,0 +1,156 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#include "COM_TransformOperation.h"
+#include "COM_ConstantOperation.h"
+#include "COM_RotateOperation.h"
+#include "COM_ScaleOperation.h"
+
+#include "BLI_math.h"
+
+namespace blender::compositor {
+
+TransformOperation::TransformOperation()
+{
+ addInputSocket(DataType::Color);
+ addInputSocket(DataType::Value);
+ addInputSocket(DataType::Value);
+ addInputSocket(DataType::Value);
+ addInputSocket(DataType::Value);
+ addOutputSocket(DataType::Color);
+ translate_factor_x_ = 1.0f;
+ translate_factor_y_ = 1.0f;
+ convert_degree_to_rad_ = false;
+ sampler_ = PixelSampler::Bilinear;
+ invert_ = false;
+}
+
+void TransformOperation::init_data()
+{
+ /* Translation. */
+ translate_x_ = 0;
+ NodeOperation *x_op = getInputOperation(X_INPUT_INDEX);
+ if (x_op->get_flags().is_constant_operation) {
+ translate_x_ = static_cast<ConstantOperation *>(x_op)->get_constant_elem()[0] *
+ translate_factor_x_;
+ }
+ translate_y_ = 0;
+ NodeOperation *y_op = getInputOperation(Y_INPUT_INDEX);
+ if (y_op->get_flags().is_constant_operation) {
+ translate_y_ = static_cast<ConstantOperation *>(y_op)->get_constant_elem()[0] *
+ translate_factor_y_;
+ }
+
+ /* Scaling. */
+ scale_center_x_ = getWidth() / 2.0;
+ scale_center_y_ = getHeight() / 2.0;
+ constant_scale_ = 1.0f;
+ NodeOperation *scale_op = getInputOperation(SCALE_INPUT_INDEX);
+ if (scale_op->get_flags().is_constant_operation) {
+ constant_scale_ = static_cast<ConstantOperation *>(scale_op)->get_constant_elem()[0];
+ }
+
+ /* Rotation. */
+ rotate_center_x_ = (getWidth() - 1.0) / 2.0;
+ rotate_center_y_ = (getHeight() - 1.0) / 2.0;
+ NodeOperation *degree_op = getInputOperation(DEGREE_INPUT_INDEX);
+ const bool is_constant_degree = degree_op->get_flags().is_constant_operation;
+ const float degree = is_constant_degree ?
+ static_cast<ConstantOperation *>(degree_op)->get_constant_elem()[0] :
+ 0.0f;
+ const double rad = convert_degree_to_rad_ ? DEG2RAD((double)degree) : degree;
+ rotate_cosine_ = cos(rad);
+ rotate_sine_ = sin(rad);
+}
+
+void TransformOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case IMAGE_INPUT_INDEX: {
+ BLI_rcti_translate(&r_input_area, translate_x_, translate_y_);
+ ScaleOperation::scale_area(
+ r_input_area, scale_center_x_, scale_center_y_, constant_scale_, constant_scale_);
+ RotateOperation::get_area_rotation_bounds(r_input_area,
+ rotate_center_x_,
+ rotate_center_y_,
+ rotate_sine_,
+ rotate_cosine_,
+ r_input_area);
+ expand_area_for_sampler(r_input_area, sampler_);
+ break;
+ }
+ case X_INPUT_INDEX:
+ case Y_INPUT_INDEX:
+ case DEGREE_INPUT_INDEX: {
+ r_input_area = COM_SINGLE_ELEM_AREA;
+ break;
+ }
+ case SCALE_INPUT_INDEX: {
+ r_input_area = output_area;
+ break;
+ }
+ }
+}
+
+void TransformOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ const MemoryBuffer *input_img = inputs[IMAGE_INPUT_INDEX];
+ MemoryBuffer *input_scale = inputs[SCALE_INPUT_INDEX];
+ BuffersIterator<float> it = output->iterate_with({input_scale}, area);
+ if (invert_) {
+ transform_inverted(it, input_img);
+ }
+ else {
+ transform(it, input_img);
+ }
+}
+
+void TransformOperation::transform(BuffersIterator<float> &it, const MemoryBuffer *input_img)
+{
+ for (; !it.is_end(); ++it) {
+ const float scale = *it.in(0);
+ float x = it.x - translate_x_;
+ float y = it.y - translate_y_;
+ RotateOperation::rotate_coords(
+ x, y, rotate_center_x_, rotate_center_y_, rotate_sine_, rotate_cosine_);
+ x = ScaleOperation::scale_coord(x, scale_center_x_, scale);
+ y = ScaleOperation::scale_coord(y, scale_center_y_, scale);
+ input_img->read_elem_sampled(x, y, sampler_, it.out);
+ }
+}
+
+void TransformOperation::transform_inverted(BuffersIterator<float> &it,
+ const MemoryBuffer *input_img)
+{
+ for (; !it.is_end(); ++it) {
+ const float scale = *it.in(0);
+ float x = ScaleOperation::scale_coord(it.x, scale_center_x_, scale);
+ float y = ScaleOperation::scale_coord(it.y, scale_center_y_, scale);
+ RotateOperation::rotate_coords(
+ x, y, rotate_center_x_, rotate_center_y_, rotate_sine_, rotate_cosine_);
+ x -= translate_x_;
+ y -= translate_y_;
+ input_img->read_elem_sampled(x, y, sampler_, it.out);
+ }
+}
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_TransformOperation.h b/source/blender/compositor/operations/COM_TransformOperation.h
new file mode 100644
index 00000000000..480998a0207
--- /dev/null
+++ b/source/blender/compositor/operations/COM_TransformOperation.h
@@ -0,0 +1,87 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#pragma once
+
+#include "COM_MultiThreadedOperation.h"
+
+namespace blender::compositor {
+
+class TransformOperation : public MultiThreadedOperation {
+ private:
+ constexpr static int IMAGE_INPUT_INDEX = 0;
+ constexpr static int X_INPUT_INDEX = 1;
+ constexpr static int Y_INPUT_INDEX = 2;
+ constexpr static int DEGREE_INPUT_INDEX = 3;
+ constexpr static int SCALE_INPUT_INDEX = 4;
+
+ float scale_center_x_;
+ float scale_center_y_;
+ float rotate_center_x_;
+ float rotate_center_y_;
+ float rotate_cosine_;
+ float rotate_sine_;
+ float translate_x_;
+ float translate_y_;
+ float constant_scale_;
+
+ /* Set variables. */
+ PixelSampler sampler_;
+ bool convert_degree_to_rad_;
+ float translate_factor_x_;
+ float translate_factor_y_;
+ bool invert_;
+
+ public:
+ TransformOperation();
+
+ void set_translate_factor_xy(float x, float y)
+ {
+ translate_factor_x_ = x;
+ translate_factor_y_ = y;
+ }
+
+ void set_convert_rotate_degree_to_rad(bool value)
+ {
+ convert_degree_to_rad_ = value;
+ }
+
+ void set_sampler(PixelSampler sampler)
+ {
+ sampler_ = sampler;
+ }
+
+ void set_invert(bool value)
+ {
+ invert_ = value;
+ }
+
+ void init_data() override;
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+
+ private:
+ /** Translate -> Rotate -> Scale. */
+ void transform(BuffersIterator<float> &it, const MemoryBuffer *input_img);
+ /** Scale -> Rotate -> Translate. */
+ void transform_inverted(BuffersIterator<float> &it, const MemoryBuffer *input_img);
+};
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc
index 19cd5a53084..6af6f5a6244 100644
--- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc
@@ -18,6 +18,7 @@
#include "COM_VariableSizeBokehBlurOperation.h"
#include "BLI_math.h"
+#include "COM_ExecutionSystem.h"
#include "COM_OpenCLDevice.h"
#include "RE_pipeline.h"
@@ -276,6 +277,166 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(
return false;
}
+void VariableSizeBokehBlurOperation::get_area_of_interest(const int input_idx,
+ const rcti &output_area,
+ rcti &r_input_area)
+{
+ switch (input_idx) {
+ case IMAGE_INPUT_INDEX:
+ case SIZE_INPUT_INDEX: {
+ const float max_dim = MAX2(getWidth(), getHeight());
+ const float scalar = m_do_size_scale ? (max_dim / 100.0f) : 1.0f;
+ const int max_blur_scalar = m_maxBlur * scalar;
+ r_input_area.xmax = output_area.xmax + max_blur_scalar + 2;
+ r_input_area.xmin = output_area.xmin - max_blur_scalar - 2;
+ r_input_area.ymax = output_area.ymax + max_blur_scalar + 2;
+ r_input_area.ymin = output_area.ymin - max_blur_scalar - 2;
+ break;
+ }
+ case BOKEH_INPUT_INDEX: {
+ r_input_area.xmax = COM_BLUR_BOKEH_PIXELS;
+ r_input_area.xmin = 0;
+ r_input_area.ymax = COM_BLUR_BOKEH_PIXELS;
+ r_input_area.ymin = 0;
+ break;
+ }
+#ifdef COM_DEFOCUS_SEARCH
+ case DEFOCUS_INPUT_INDEX: {
+ r_input_area.xmax = (output_area.xmax / InverseSearchRadiusOperation::DIVIDER) + 1;
+ r_input_area.xmin = (output_area.xmin / InverseSearchRadiusOperation::DIVIDER) - 1;
+ r_input_area.ymax = (output_area.ymax / InverseSearchRadiusOperation::DIVIDER) + 1;
+ r_input_area.ymin = (output_area.ymin / InverseSearchRadiusOperation::DIVIDER) - 1;
+ break;
+ }
+#endif
+ }
+}
+
+struct PixelData {
+ float multiplier_accum[4];
+ float color_accum[4];
+ float threshold;
+ float scalar;
+ float size_center;
+ int max_blur_scalar;
+ int step;
+ MemoryBuffer *bokeh_input;
+ MemoryBuffer *size_input;
+ MemoryBuffer *image_input;
+ int image_width;
+ int image_height;
+};
+
+static void blur_pixel(int x, int y, PixelData &p)
+{
+ BLI_assert(p.bokeh_input->getWidth() == COM_BLUR_BOKEH_PIXELS);
+ BLI_assert(p.bokeh_input->getHeight() == COM_BLUR_BOKEH_PIXELS);
+
+#ifdef COM_DEFOCUS_SEARCH
+ float search[4];
+ inputs[DEFOCUS_INPUT_INDEX]->read_elem_checked(x / InverseSearchRadiusOperation::DIVIDER,
+ y / InverseSearchRadiusOperation::DIVIDER,
+ search);
+ const int minx = search[0];
+ const int miny = search[1];
+ const int maxx = search[2];
+ const int maxy = search[3];
+#else
+ const int minx = MAX2(x - p.max_blur_scalar, 0);
+ const int miny = MAX2(y - p.max_blur_scalar, 0);
+ const int maxx = MIN2(x + p.max_blur_scalar, p.image_width);
+ const int maxy = MIN2(y + p.max_blur_scalar, p.image_height);
+#endif
+
+ const int color_row_stride = p.image_input->row_stride * p.step;
+ const int color_elem_stride = p.image_input->elem_stride * p.step;
+ const int size_row_stride = p.size_input->row_stride * p.step;
+ const int size_elem_stride = p.size_input->elem_stride * p.step;
+ const float *row_color = p.image_input->get_elem(minx, miny);
+ const float *row_size = p.size_input->get_elem(minx, miny);
+ for (int ny = miny; ny < maxy;
+ ny += p.step, row_size += size_row_stride, row_color += color_row_stride) {
+ const float dy = ny - y;
+ const float *size_elem = row_size;
+ const float *color = row_color;
+ for (int nx = minx; nx < maxx;
+ nx += p.step, size_elem += size_elem_stride, color += color_elem_stride) {
+ if (nx == x && ny == y) {
+ continue;
+ }
+ const float size = MIN2(size_elem[0] * p.scalar, p.size_center);
+ if (size <= p.threshold) {
+ continue;
+ }
+ const float dx = nx - x;
+ if (size <= fabsf(dx) || size <= fabsf(dy)) {
+ continue;
+ }
+
+ /* XXX: There is no way to ensure bokeh input is an actual bokeh with #COM_BLUR_BOKEH_PIXELS
+ * size, anything may be connected. Use the real input size and remove asserts? */
+ const float u = (float)(COM_BLUR_BOKEH_PIXELS / 2) +
+ (dx / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1);
+ const float v = (float)(COM_BLUR_BOKEH_PIXELS / 2) +
+ (dy / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1);
+ float bokeh[4];
+ p.bokeh_input->read_elem_checked(u, v, bokeh);
+ madd_v4_v4v4(p.color_accum, bokeh, color);
+ add_v4_v4(p.multiplier_accum, bokeh);
+ }
+ }
+}
+
+void VariableSizeBokehBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ PixelData p;
+ p.bokeh_input = inputs[BOKEH_INPUT_INDEX];
+ p.size_input = inputs[SIZE_INPUT_INDEX];
+ p.image_input = inputs[IMAGE_INPUT_INDEX];
+ p.step = QualityStepHelper::getStep();
+ p.threshold = m_threshold;
+ p.image_width = this->getWidth();
+ p.image_height = this->getHeight();
+
+ rcti scalar_area;
+ this->get_area_of_interest(SIZE_INPUT_INDEX, area, scalar_area);
+ BLI_rcti_isect(&scalar_area, &p.size_input->get_rect(), &scalar_area);
+ const float max_size = p.size_input->get_max_value(scalar_area);
+
+ const float max_dim = MAX2(this->getWidth(), this->getHeight());
+ p.scalar = m_do_size_scale ? (max_dim / 100.0f) : 1.0f;
+ p.max_blur_scalar = static_cast<int>(max_size * p.scalar);
+ CLAMP(p.max_blur_scalar, 1, m_maxBlur);
+
+ for (BuffersIterator<float> it = output->iterate_with({p.image_input, p.size_input}, area);
+ !it.is_end();
+ ++it) {
+ const float *color = it.in(0);
+ const float size = *it.in(1);
+ copy_v4_v4(p.color_accum, color);
+ copy_v4_fl(p.multiplier_accum, 1.0f);
+ p.size_center = size * p.scalar;
+
+ if (p.size_center > p.threshold) {
+ blur_pixel(it.x, it.y, p);
+ }
+
+ it.out[0] = p.color_accum[0] / p.multiplier_accum[0];
+ it.out[1] = p.color_accum[1] / p.multiplier_accum[1];
+ it.out[2] = p.color_accum[2] / p.multiplier_accum[2];
+ it.out[3] = p.color_accum[3] / p.multiplier_accum[3];
+
+ /* Blend in out values over the threshold, otherwise we get sharp, ugly transitions. */
+ if ((p.size_center > p.threshold) && (p.size_center < p.threshold * 2.0f)) {
+ /* Factor from 0-1. */
+ const float fac = (p.size_center - p.threshold) / p.threshold;
+ interp_v4_v4v4(it.out, color, it.out, fac);
+ }
+ }
+}
+
#ifdef COM_DEFOCUS_SEARCH
// InverseSearchRadiusOperation
InverseSearchRadiusOperation::InverseSearchRadiusOperation()
diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h
index baeab6a646e..56b4677087b 100644
--- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h
+++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h
@@ -18,15 +18,22 @@
#pragma once
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
#include "COM_QualityStepHelper.h"
namespace blender::compositor {
//#define COM_DEFOCUS_SEARCH
-class VariableSizeBokehBlurOperation : public NodeOperation, public QualityStepHelper {
+class VariableSizeBokehBlurOperation : public MultiThreadedOperation, public QualityStepHelper {
private:
+ static constexpr int IMAGE_INPUT_INDEX = 0;
+ static constexpr int BOKEH_INPUT_INDEX = 1;
+ static constexpr int SIZE_INPUT_INDEX = 2;
+#ifdef COM_DEFOCUS_SEARCH
+ static constexpr int DEFOCUS_INPUT_INDEX = 3;
+#endif
+
int m_maxBlur;
float m_threshold;
bool m_do_size_scale; /* scale size, matching 'BokehBlurNode' */
@@ -84,8 +91,14 @@ class VariableSizeBokehBlurOperation : public NodeOperation, public QualityStepH
MemoryBuffer **inputMemoryBuffers,
std::list<cl_mem> *clMemToCleanUp,
std::list<cl_kernel> *clKernelsToCleanUp) override;
+
+ void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
+/* Currently unused. If ever used, it needs full-frame implementation. */
#ifdef COM_DEFOCUS_SEARCH
class InverseSearchRadiusOperation : public NodeOperation {
private:
diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.cc b/source/blender/compositor/operations/COM_VectorCurveOperation.cc
index 9d53ed5d8ee..c2087fd071e 100644
--- a/source/blender/compositor/operations/COM_VectorCurveOperation.cc
+++ b/source/blender/compositor/operations/COM_VectorCurveOperation.cc
@@ -53,4 +53,14 @@ void VectorCurveOperation::deinitExecution()
this->m_inputProgram = nullptr;
}
+void VectorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ CurveMapping *curve_map = this->m_curveMapping;
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ BKE_curvemapping_evaluate_premulRGBF(curve_map, it.out, it.in(0));
+ }
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.h b/source/blender/compositor/operations/COM_VectorCurveOperation.h
index 8cbb80e27c7..27b3ad69e17 100644
--- a/source/blender/compositor/operations/COM_VectorCurveOperation.h
+++ b/source/blender/compositor/operations/COM_VectorCurveOperation.h
@@ -47,6 +47,10 @@ class VectorCurveOperation : public CurveBaseOperation {
* Deinitialize the execution
*/
void deinitExecution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.cc b/source/blender/compositor/operations/COM_ZCombineOperation.cc
index 9d3ca7e736e..7050c3b2d83 100644
--- a/source/blender/compositor/operations/COM_ZCombineOperation.cc
+++ b/source/blender/compositor/operations/COM_ZCombineOperation.cc
@@ -33,6 +33,7 @@ ZCombineOperation::ZCombineOperation()
this->m_depth1Reader = nullptr;
this->m_image2Reader = nullptr;
this->m_depth2Reader = nullptr;
+ this->flags.can_be_constant = true;
}
void ZCombineOperation::initExecution()
@@ -60,6 +61,19 @@ void ZCombineOperation::executePixelSampled(float output[4],
this->m_image2Reader->readSampled(output, x, y, sampler);
}
}
+
+void ZCombineOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float depth1 = *it.in(1);
+ const float depth2 = *it.in(3);
+ const float *color = (depth1 < depth2) ? it.in(0) : it.in(2);
+ copy_v4_v4(it.out, color);
+ }
+}
+
void ZCombineAlphaOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -88,6 +102,32 @@ void ZCombineAlphaOperation::executePixelSampled(float output[4],
output[3] = MAX2(color1[3], color2[3]);
}
+void ZCombineAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float depth1 = *it.in(1);
+ const float depth2 = *it.in(3);
+ const float *color1;
+ const float *color2;
+ if (depth1 <= depth2) {
+ color1 = it.in(0);
+ color2 = it.in(2);
+ }
+ else {
+ color1 = it.in(2);
+ color2 = it.in(0);
+ }
+ const float fac = color1[3];
+ const float ifac = 1.0f - fac;
+ it.out[0] = fac * color1[0] + ifac * color2[0];
+ it.out[1] = fac * color1[1] + ifac * color2[1];
+ it.out[2] = fac * color1[2] + ifac * color2[2];
+ it.out[3] = MAX2(color1[3], color2[3]);
+ }
+}
+
void ZCombineOperation::deinitExecution()
{
this->m_image1Reader = nullptr;
@@ -132,6 +172,18 @@ void ZCombineMaskOperation::executePixelSampled(float output[4],
interp_v4_v4v4(output, color1, color2, 1.0f - mask[0]);
}
+void ZCombineMaskOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float mask = *it.in(0);
+ const float *color1 = it.in(1);
+ const float *color2 = it.in(2);
+ interp_v4_v4v4(it.out, color1, color2, 1.0f - mask);
+ }
+}
+
void ZCombineMaskAlphaOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -154,6 +206,24 @@ void ZCombineMaskAlphaOperation::executePixelSampled(float output[4],
output[3] = MAX2(color1[3], color2[3]);
}
+void ZCombineMaskAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs)
+{
+ for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+ const float mask = *it.in(0);
+ const float *color1 = it.in(1);
+ const float *color2 = it.in(2);
+ const float fac = (1.0f - mask) * (1.0f - color1[3]) + mask * color2[3];
+ const float mfac = 1.0f - fac;
+
+ it.out[0] = color1[0] * mfac + color2[0] * fac;
+ it.out[1] = color1[1] * mfac + color2[1] * fac;
+ it.out[2] = color1[2] * mfac + color2[2] * fac;
+ it.out[3] = MAX2(color1[3], color2[3]);
+ }
+}
+
void ZCombineMaskOperation::deinitExecution()
{
this->m_image1Reader = nullptr;
diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.h b/source/blender/compositor/operations/COM_ZCombineOperation.h
index d0b1aee7310..acd60b6c866 100644
--- a/source/blender/compositor/operations/COM_ZCombineOperation.h
+++ b/source/blender/compositor/operations/COM_ZCombineOperation.h
@@ -26,7 +26,7 @@ namespace blender::compositor {
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
-class ZCombineOperation : public NodeOperation {
+class ZCombineOperation : public MultiThreadedOperation {
protected:
SocketReader *m_image1Reader;
SocketReader *m_depth1Reader;
@@ -46,13 +46,21 @@ class ZCombineOperation : public NodeOperation {
* The inner loop of this operation.
*/
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
class ZCombineAlphaOperation : public ZCombineOperation {
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
-class ZCombineMaskOperation : public NodeOperation {
+class ZCombineMaskOperation : public MultiThreadedOperation {
protected:
SocketReader *m_maskReader;
SocketReader *m_image1Reader;
@@ -64,9 +72,17 @@ class ZCombineMaskOperation : public NodeOperation {
void initExecution() override;
void deinitExecution() override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
class ZCombineMaskAlphaOperation : public ZCombineMaskOperation {
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor
diff --git a/source/blender/datatoc/datatoc.c b/source/blender/datatoc/datatoc.c
index 62b4cee4af0..816353be9de 100644
--- a/source/blender/datatoc/datatoc.c
+++ b/source/blender/datatoc/datatoc.c
@@ -100,15 +100,14 @@ int main(int argc, char **argv)
fprintf(fpout, "const int datatoc_%s_size = %d;\n", argv[1], (int)size);
fprintf(fpout, "const char datatoc_%s[] = {\n", argv[1]);
while (size--) {
- /* if we want to open in an editor
- * this is nicer to avoid very long lines */
-#ifdef VERBOSE
+ /* Even though this file is generated and doesn't need new-lines,
+ * these files may be loaded by developers when looking up symbols.
+ * Avoid a very long single line that may lock-up some editors. */
if (size % 32 == 31) {
fprintf(fpout, "\n");
}
-#endif
- /* fprintf (fpout, "\\x%02x", getc(fpin)); */
+ // fprintf(fpout, "\\x%02x", getc(fpin));
fprintf(fpout, "%3d,", getc(fpin));
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 7da3d2e25f0..d88e9bc9c04 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -118,6 +118,7 @@
#include "intern/node/deg_node_operation.h"
#include "intern/node/deg_node_time.h"
+#include "intern/depsgraph.h"
#include "intern/depsgraph_relation.h"
#include "intern/depsgraph_type.h"
@@ -2095,7 +2096,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
ctx.node = reinterpret_cast<::DepsNodeHandle *>(&handle);
mti->updateDepsgraph(md, &ctx);
}
- if (BKE_object_modifier_use_time(object, md)) {
+ if (BKE_object_modifier_use_time(scene_, object, md, graph_->mode)) {
TimeSourceKey time_src_key;
add_relation(time_src_key, obdata_ubereval_key, "Time Source");
}
diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.c b/source/blender/draw/engines/eevee/eevee_lookdev.c
index f4dc553e982..879a7b08eba 100644
--- a/source/blender/draw/engines/eevee/eevee_lookdev.c
+++ b/source/blender/draw/engines/eevee/eevee_lookdev.c
@@ -246,7 +246,7 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata,
DRW_shgroup_uniform_float_copy(grp, "studioLightIntensity", shading->studiolight_intensity);
BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE);
DRW_shgroup_uniform_texture_ex(grp, "studioLight", sl->equirect_radiance_gputexture, state);
- /* Do not fadeout when doing probe rendering, only when drawing the background */
+ /* Do not fade-out when doing probe rendering, only when drawing the background. */
DRW_shgroup_uniform_float_copy(grp, "backgroundAlpha", 1.0f);
}
else {
diff --git a/source/blender/draw/engines/image/image_engine.c b/source/blender/draw/engines/image/image_engine.c
index 395d50fbc6b..b4c0ade380e 100644
--- a/source/blender/draw/engines/image/image_engine.c
+++ b/source/blender/draw/engines/image/image_engine.c
@@ -111,35 +111,52 @@ static void space_image_gpu_texture_get(Image *image,
/* Update multi-index and pass for the current eye. */
BKE_image_multilayer_index(image->rr, &sima->iuser);
}
- BKE_image_multiview_index(image, &sima->iuser);
+ else {
+ BKE_image_multiview_index(image, &sima->iuser);
+ }
- if (ibuf) {
- const int sima_flag = sima->flag & ED_space_image_get_display_channel_mask(ibuf);
- if (sima_flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
- if (ibuf->zbuf) {
- BLI_assert_msg(0, "Integer based depth buffers not supported");
- }
- else if (ibuf->zbuf_float) {
- *r_gpu_texture = GPU_texture_create_2d(
- __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->zbuf_float);
- *r_owns_texture = true;
- }
- else if (ibuf->rect_float && ibuf->channels == 1) {
- *r_gpu_texture = GPU_texture_create_2d(
- __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->rect_float);
- *r_owns_texture = true;
- }
+ if (ibuf == NULL) {
+ return;
+ }
+
+ if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
+ /* This codepath is only supposed to happen when drawing a lazily-allocatable render result.
+ * In all the other cases the `ED_space_image_acquire_buffer()` is expected to return NULL as
+ * an image buffer when it has no pixels. */
+
+ BLI_assert(image->type == IMA_TYPE_R_RESULT);
+
+ float zero[4] = {0, 0, 0, 0};
+ *r_gpu_texture = GPU_texture_create_2d(__func__, 1, 1, 0, GPU_RGBA16F, zero);
+ *r_owns_texture = true;
+ return;
+ }
+
+ const int sima_flag = sima->flag & ED_space_image_get_display_channel_mask(ibuf);
+ if (sima_flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
+ if (ibuf->zbuf) {
+ BLI_assert_msg(0, "Integer based depth buffers not supported");
}
- else if (image->source == IMA_SRC_TILED) {
- *r_gpu_texture = BKE_image_get_gpu_tiles(image, iuser, ibuf);
- *r_tex_tile_data = BKE_image_get_gpu_tilemap(image, iuser, NULL);
- *r_owns_texture = false;
+ else if (ibuf->zbuf_float) {
+ *r_gpu_texture = GPU_texture_create_2d(
+ __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->zbuf_float);
+ *r_owns_texture = true;
}
- else {
- *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf);
- *r_owns_texture = false;
+ else if (ibuf->rect_float && ibuf->channels == 1) {
+ *r_gpu_texture = GPU_texture_create_2d(
+ __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->rect_float);
+ *r_owns_texture = true;
}
}
+ else if (image->source == IMA_SRC_TILED) {
+ *r_gpu_texture = BKE_image_get_gpu_tiles(image, iuser, ibuf);
+ *r_tex_tile_data = BKE_image_get_gpu_tilemap(image, iuser, NULL);
+ *r_owns_texture = false;
+ }
+ else {
+ *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf);
+ *r_owns_texture = false;
+ }
}
static void space_node_gpu_texture_get(Image *image,
diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c
index 235104245cc..b07e86000fd 100644
--- a/source/blender/draw/engines/overlay/overlay_engine.c
+++ b/source/blender/draw/engines/overlay/overlay_engine.c
@@ -576,9 +576,20 @@ static void OVERLAY_draw_scene(void *vedata)
OVERLAY_extra_blend_draw(vedata);
OVERLAY_volume_draw(vedata);
- if (pd->ctx_mode == CTX_MODE_SCULPT) {
- /* Sculpt overlays are drawn here to avoid artifacts with wireframe opacity. */
- OVERLAY_sculpt_draw(vedata);
+ /* These overlays are drawn here to avoid artifacts with wireframe opacity. */
+ switch (pd->ctx_mode) {
+ case CTX_MODE_SCULPT:
+ OVERLAY_sculpt_draw(vedata);
+ break;
+ case CTX_MODE_EDIT_MESH:
+ case CTX_MODE_POSE:
+ case CTX_MODE_PAINT_WEIGHT:
+ case CTX_MODE_PAINT_VERTEX:
+ case CTX_MODE_PAINT_TEXTURE:
+ OVERLAY_paint_draw(vedata);
+ break;
+ default:
+ break;
}
if (DRW_state_is_fbo()) {
@@ -601,11 +612,6 @@ static void OVERLAY_draw_scene(void *vedata)
OVERLAY_xray_depth_infront_copy(vedata);
- if (pd->ctx_mode == CTX_MODE_PAINT_WEIGHT) {
- /* Fix weird case where weightpaint mode needs to draw before xray bones. */
- OVERLAY_paint_draw(vedata);
- }
-
if (DRW_state_is_fbo()) {
GPU_framebuffer_bind(fbl->overlay_in_front_fb);
}
@@ -640,7 +646,6 @@ static void OVERLAY_draw_scene(void *vedata)
switch (pd->ctx_mode) {
case CTX_MODE_EDIT_MESH:
- OVERLAY_paint_draw(vedata);
OVERLAY_edit_mesh_draw(vedata);
break;
case CTX_MODE_EDIT_SURFACE:
@@ -654,13 +659,8 @@ static void OVERLAY_draw_scene(void *vedata)
OVERLAY_edit_lattice_draw(vedata);
break;
case CTX_MODE_POSE:
- OVERLAY_paint_draw(vedata);
OVERLAY_pose_draw(vedata);
break;
- case CTX_MODE_PAINT_VERTEX:
- case CTX_MODE_PAINT_TEXTURE:
- OVERLAY_paint_draw(vedata);
- break;
case CTX_MODE_PARTICLE:
OVERLAY_edit_particle_draw(vedata);
break;
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index f5be9c846d1..04d90919a20 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -864,7 +864,6 @@ typedef union OVERLAY_CameraInstanceData {
static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb,
Scene *scene,
View3D *v3d,
- Object *camera_object,
Object *ob,
const float color[4])
{
@@ -943,7 +942,7 @@ static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb,
}
if (is_select) {
- DRW_select_load_id(camera_object->runtime.select_id | (track_index << 16));
+ DRW_select_load_id(ob->runtime.select_id | (track_index << 16));
track_index++;
}
@@ -1251,7 +1250,7 @@ void OVERLAY_camera_cache_populate(OVERLAY_Data *vedata, Object *ob)
/* Motion Tracking. */
if ((v3d->flag2 & V3D_SHOW_RECONSTRUCTION) != 0) {
- camera_view3d_reconstruction(cb, scene, v3d, camera_object, ob, color_p);
+ camera_view3d_reconstruction(cb, scene, v3d, ob, color_p);
}
/* Background images. */
@@ -1357,7 +1356,8 @@ static void OVERLAY_relationship_lines(OVERLAY_ExtraCallBuffers *cb,
}
}
}
- BKE_constraints_clear_evalob(cob);
+ /* NOTE: Don't use BKE_constraints_clear_evalob here as that will reset ob->constinv. */
+ MEM_freeN(cob);
}
}
diff --git a/source/blender/draw/engines/overlay/overlay_paint.c b/source/blender/draw/engines/overlay/overlay_paint.c
index d52640ed174..60a90616d29 100644
--- a/source/blender/draw/engines/overlay/overlay_paint.c
+++ b/source/blender/draw/engines/overlay/overlay_paint.c
@@ -92,18 +92,26 @@ void OVERLAY_paint_cache_init(OVERLAY_Data *vedata)
case CTX_MODE_PAINT_WEIGHT: {
opacity = is_edit_mode ? 1.0 : pd->overlay.weight_paint_mode_opacity;
if (opacity > 0.0f) {
- state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
- state |= pd->painting.alpha_blending ? DRW_STATE_BLEND_ALPHA : DRW_STATE_BLEND_MUL;
+ state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA;
DRW_PASS_CREATE(psl->paint_color_ps, state | pd->clipping_state);
- sh = OVERLAY_shader_paint_weight();
+ const bool do_shading = draw_ctx->v3d->shading.type != OB_WIRE;
+
+ sh = OVERLAY_shader_paint_weight(do_shading);
pd->paint_surf_grp = grp = DRW_shgroup_create(sh, psl->paint_color_ps);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_bool_copy(grp, "drawContours", draw_contours);
- DRW_shgroup_uniform_bool_copy(grp, "useAlphaBlend", pd->painting.alpha_blending);
DRW_shgroup_uniform_float_copy(grp, "opacity", opacity);
DRW_shgroup_uniform_texture(grp, "colorramp", G_draw.weight_ramp);
+ /* Arbitrary light to give a hint of the geometry behind the weights. */
+ if (do_shading) {
+ float light_dir[3];
+ copy_v3_fl3(light_dir, 0.0f, 0.5f, 0.86602f);
+ normalize_v3(light_dir);
+ DRW_shgroup_uniform_vec3_copy(grp, "light_dir", light_dir);
+ }
+
if (pd->painting.alpha_blending) {
state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
DRW_PASS_CREATE(psl->paint_depth_ps, state | pd->clipping_state);
@@ -257,17 +265,10 @@ void OVERLAY_paint_draw(OVERLAY_Data *vedata)
OVERLAY_PassList *psl = vedata->psl;
OVERLAY_FramebufferList *fbl = vedata->fbl;
- DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
if (DRW_state_is_fbo()) {
- if (pd->painting.alpha_blending) {
- GPU_framebuffer_bind(pd->painting.in_front ? fbl->overlay_in_front_fb :
- fbl->overlay_default_fb);
- }
- else {
- /* Paint overlay needs final color because of multiply blend mode. */
- GPU_framebuffer_bind(pd->painting.in_front ? dfbl->in_front_fb : dfbl->default_fb);
- }
+ GPU_framebuffer_bind(pd->painting.in_front ? fbl->overlay_in_front_fb :
+ fbl->overlay_default_fb);
}
if (psl->paint_depth_ps) {
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index 03bfaf56f24..68f60bee779 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -736,7 +736,7 @@ GPUShader *OVERLAY_shader_paint_face(void);
GPUShader *OVERLAY_shader_paint_point(void);
GPUShader *OVERLAY_shader_paint_texture(void);
GPUShader *OVERLAY_shader_paint_vertcol(void);
-GPUShader *OVERLAY_shader_paint_weight(void);
+GPUShader *OVERLAY_shader_paint_weight(bool shading);
GPUShader *OVERLAY_shader_paint_wire(void);
GPUShader *OVERLAY_shader_particle_dot(void);
GPUShader *OVERLAY_shader_particle_shape(void);
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c
index 7a7ae9a921b..edf9148c8c0 100644
--- a/source/blender/draw/engines/overlay/overlay_shader.c
+++ b/source/blender/draw/engines/overlay/overlay_shader.c
@@ -211,7 +211,7 @@ typedef struct OVERLAY_Shaders {
GPUShader *paint_point;
GPUShader *paint_texture;
GPUShader *paint_vertcol;
- GPUShader *paint_weight;
+ GPUShader *paint_weight[2];
GPUShader *paint_wire;
GPUShader *particle_dot;
GPUShader *particle_shape;
@@ -1334,13 +1334,14 @@ GPUShader *OVERLAY_shader_paint_vertcol(void)
return sh_data->paint_vertcol;
}
-GPUShader *OVERLAY_shader_paint_weight(void)
+GPUShader *OVERLAY_shader_paint_weight(const bool shading)
{
+ int index = shading ? 1 : 0;
const DRWContextState *draw_ctx = DRW_context_state_get();
const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
- if (!sh_data->paint_weight) {
- sh_data->paint_weight = GPU_shader_create_from_arrays({
+ if (!sh_data->paint_weight[index]) {
+ sh_data->paint_weight[index] = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
@@ -1349,10 +1350,10 @@ GPUShader *OVERLAY_shader_paint_weight(void)
.frag = (const char *[]){datatoc_common_globals_lib_glsl,
datatoc_paint_weight_frag_glsl,
NULL},
- .defs = (const char *[]){sh_cfg->def, NULL},
+ .defs = (const char *[]){sh_cfg->def, shading ? "#define FAKE_SHADING\n" : "", NULL},
});
}
- return sh_data->paint_weight;
+ return sh_data->paint_weight[index];
}
GPUShader *OVERLAY_shader_paint_wire(void)
diff --git a/source/blender/draw/engines/overlay/shaders/paint_weight_frag.glsl b/source/blender/draw/engines/overlay/shaders/paint_weight_frag.glsl
index 0020d76ed6a..8009713d655 100644
--- a/source/blender/draw/engines/overlay/shaders/paint_weight_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/paint_weight_frag.glsl
@@ -1,12 +1,12 @@
in vec2 weight_interp; /* (weight, alert) */
+in float color_fac;
out vec4 fragColor;
uniform float opacity = 1.0;
uniform sampler1D colorramp;
-uniform bool useAlphaBlend = false;
uniform bool drawContours = false;
float contours(float value, float steps, float width_px, float max_rel_width, float gradient)
@@ -68,6 +68,13 @@ vec4 contour_grid(float weight, float weight_gradient)
return grid * clamp((weight_gradient - flt_eps) / flt_eps, 0.0, 1.0);
}
+vec4 apply_color_fac(vec4 color_in)
+{
+ vec4 color = color_in;
+ color.rgb = max(vec3(0.005), color_in.rgb) * color_fac;
+ return color;
+}
+
void main()
{
float alert = weight_interp.y;
@@ -75,12 +82,13 @@ void main()
/* Missing vertex group alert color. Uniform in practice. */
if (alert > 1.1) {
- color = colorVertexMissingData;
+ color = apply_color_fac(colorVertexMissingData);
}
/* Weights are available */
else {
float weight = weight_interp.x;
vec4 weight_color = texture(colorramp, weight, 0);
+ weight_color = apply_color_fac(weight_color);
/* Contour display */
if (drawContours) {
@@ -93,14 +101,9 @@ void main()
}
/* Zero weight alert color. Nonlinear blend to reduce impact. */
- color = mix(weight_color, colorVertexUnreferenced, alert * alert);
+ vec4 color_unreferenced = apply_color_fac(colorVertexUnreferenced);
+ color = mix(weight_color, color_unreferenced, alert * alert);
}
- if (useAlphaBlend) {
- fragColor = vec4(color.rgb, opacity);
- }
- else {
- /* mix with 1.0 -> is like opacity when using multiply blend mode */
- fragColor = vec4(mix(vec3(1.0), color.rgb, opacity), 1.0);
- }
+ fragColor = vec4(color.rgb, opacity);
}
diff --git a/source/blender/draw/engines/overlay/shaders/paint_weight_vert.glsl b/source/blender/draw/engines/overlay/shaders/paint_weight_vert.glsl
index b3baa8c7b07..31b6dc42cf4 100644
--- a/source/blender/draw/engines/overlay/shaders/paint_weight_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/paint_weight_vert.glsl
@@ -1,8 +1,13 @@
+#ifdef FAKE_SHADING
+uniform vec3 light_dir;
+#endif
in float weight;
in vec3 pos;
+in vec3 nor;
out vec2 weight_interp; /* (weight, alert) */
+out float color_fac;
void main()
{
@@ -14,6 +19,16 @@ void main()
/* Separate actual weight and alerts for independent interpolation */
weight_interp = max(vec2(weight, -weight), 0.0);
+ /* Saturate the weight to give a hint of the geometry behind the weights. */
+#ifdef FAKE_SHADING
+ vec3 view_normal = normalize(normal_object_to_view(nor));
+ color_fac = abs(dot(view_normal, light_dir));
+ color_fac = color_fac * 0.9 + 0.1;
+
+#else
+ color_fac = 1.0;
+#endif
+
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
diff --git a/source/blender/draw/engines/select/select_debug_engine.c b/source/blender/draw/engines/select/select_debug_engine.c
index ded96be23f3..e9437c5ab92 100644
--- a/source/blender/draw/engines/select/select_debug_engine.c
+++ b/source/blender/draw/engines/select/select_debug_engine.c
@@ -19,7 +19,7 @@
/** \file
* \ingroup draw_engine
*
- * Engine for debuging the selection map drawing.
+ * Engine for debugging the selection map drawing.
*/
#include "DNA_ID.h"
diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h
index 7dc468d1a73..db96d6a774f 100644
--- a/source/blender/draw/intern/draw_cache_extract.h
+++ b/source/blender/draw/intern/draw_cache_extract.h
@@ -101,7 +101,7 @@ BLI_INLINE int mesh_render_mat_len_get(const Mesh *me)
return MAX2(1, me->totcol);
}
-typedef struct MeshBufferCache {
+typedef struct MeshBufferList {
/* Every VBO below contains at least enough
* data for every loops in the mesh (except fdots and skin roots).
* For some VBOs, it extends to (in this exact order) :
@@ -152,16 +152,91 @@ typedef struct MeshBufferCache {
GPUIndexBuf *edituv_points;
GPUIndexBuf *edituv_fdots;
} ibo;
- /* Index buffer per material. These are subranges of `ibo.tris` */
- GPUIndexBuf **tris_per_mat;
-} MeshBufferCache;
+} MeshBufferList;
+
+typedef struct MeshBatchList {
+ /* Surfaces / Render */
+ GPUBatch *surface;
+ GPUBatch *surface_weights;
+ /* Edit mode */
+ GPUBatch *edit_triangles;
+ GPUBatch *edit_vertices;
+ GPUBatch *edit_edges;
+ GPUBatch *edit_vnor;
+ GPUBatch *edit_lnor;
+ GPUBatch *edit_fdots;
+ GPUBatch *edit_mesh_analysis;
+ GPUBatch *edit_skin_roots;
+ /* Edit UVs */
+ GPUBatch *edituv_faces_stretch_area;
+ GPUBatch *edituv_faces_stretch_angle;
+ GPUBatch *edituv_faces;
+ GPUBatch *edituv_edges;
+ GPUBatch *edituv_verts;
+ GPUBatch *edituv_fdots;
+ /* Edit selection */
+ GPUBatch *edit_selection_verts;
+ GPUBatch *edit_selection_edges;
+ GPUBatch *edit_selection_faces;
+ GPUBatch *edit_selection_fdots;
+ /* Common display / Other */
+ GPUBatch *all_verts;
+ GPUBatch *all_edges;
+ GPUBatch *loose_edges;
+ GPUBatch *edge_detection;
+ GPUBatch *wire_edges; /* Individual edges with face normals. */
+ GPUBatch *wire_loops; /* Loops around faces. no edges between selected faces */
+ GPUBatch *wire_loops_uvs; /* Same as wire_loops but only has uvs. */
+ GPUBatch *sculpt_overlays;
+} MeshBatchList;
+
+#define MBC_BATCH_LEN (sizeof(MeshBatchList) / sizeof(void *))
+#define MBC_VBO_LEN (sizeof(((MeshBufferList){0}).vbo) / sizeof(void *))
+#define MBC_IBO_LEN (sizeof(((MeshBufferList){0}).ibo) / sizeof(void *))
+
+#define MBC_BATCH_INDEX(batch) (offsetof(MeshBatchList, batch) / sizeof(void *))
+
+typedef enum DRWBatchFlag {
+ MBC_SURFACE = (1u << MBC_BATCH_INDEX(surface)),
+ MBC_SURFACE_WEIGHTS = (1u << MBC_BATCH_INDEX(surface_weights)),
+ MBC_EDIT_TRIANGLES = (1u << MBC_BATCH_INDEX(edit_triangles)),
+ MBC_EDIT_VERTICES = (1u << MBC_BATCH_INDEX(edit_vertices)),
+ MBC_EDIT_EDGES = (1u << MBC_BATCH_INDEX(edit_edges)),
+ MBC_EDIT_VNOR = (1u << MBC_BATCH_INDEX(edit_vnor)),
+ MBC_EDIT_LNOR = (1u << MBC_BATCH_INDEX(edit_lnor)),
+ MBC_EDIT_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_fdots)),
+ MBC_EDIT_MESH_ANALYSIS = (1u << MBC_BATCH_INDEX(edit_mesh_analysis)),
+ MBC_SKIN_ROOTS = (1u << MBC_BATCH_INDEX(edit_skin_roots)),
+ MBC_EDITUV_FACES_STRETCH_AREA = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_area)),
+ MBC_EDITUV_FACES_STRETCH_ANGLE = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_angle)),
+ MBC_EDITUV_FACES = (1u << MBC_BATCH_INDEX(edituv_faces)),
+ MBC_EDITUV_EDGES = (1u << MBC_BATCH_INDEX(edituv_edges)),
+ MBC_EDITUV_VERTS = (1u << MBC_BATCH_INDEX(edituv_verts)),
+ MBC_EDITUV_FACEDOTS = (1u << MBC_BATCH_INDEX(edituv_fdots)),
+ MBC_EDIT_SELECTION_VERTS = (1u << MBC_BATCH_INDEX(edit_selection_verts)),
+ MBC_EDIT_SELECTION_EDGES = (1u << MBC_BATCH_INDEX(edit_selection_edges)),
+ MBC_EDIT_SELECTION_FACES = (1u << MBC_BATCH_INDEX(edit_selection_faces)),
+ MBC_EDIT_SELECTION_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_selection_fdots)),
+ MBC_ALL_VERTS = (1u << MBC_BATCH_INDEX(all_verts)),
+ MBC_ALL_EDGES = (1u << MBC_BATCH_INDEX(all_edges)),
+ MBC_LOOSE_EDGES = (1u << MBC_BATCH_INDEX(loose_edges)),
+ MBC_EDGE_DETECTION = (1u << MBC_BATCH_INDEX(edge_detection)),
+ MBC_WIRE_EDGES = (1u << MBC_BATCH_INDEX(wire_edges)),
+ MBC_WIRE_LOOPS = (1u << MBC_BATCH_INDEX(wire_loops)),
+ MBC_WIRE_LOOPS_UVS = (1u << MBC_BATCH_INDEX(wire_loops_uvs)),
+ MBC_SCULPT_OVERLAYS = (1u << MBC_BATCH_INDEX(sculpt_overlays)),
+} DRWBatchFlag;
+
+BLI_STATIC_ASSERT(MBC_BATCH_LEN < 32, "Number of batches exceeded the limit of bit fields");
/**
* Data that are kept around between extractions to reduce rebuilding time.
*
* - Loose geometry.
*/
-typedef struct MeshBufferExtractionCache {
+typedef struct MeshBufferCache {
+ MeshBufferList buff;
+
struct {
int edge_len;
int vert_len;
@@ -174,7 +249,7 @@ typedef struct MeshBufferExtractionCache {
int *mat_tri_len;
int visible_tri_len;
} poly_sorted;
-} MeshBufferExtractionCache;
+} MeshBufferCache;
#define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \
for (MeshBufferCache *mbc = &batch_cache->final; \
@@ -186,50 +261,15 @@ typedef struct MeshBufferExtractionCache {
typedef struct MeshBatchCache {
MeshBufferCache final, cage, uv_cage;
- MeshBufferExtractionCache final_extraction_cache;
- MeshBufferExtractionCache cage_extraction_cache;
- MeshBufferExtractionCache uv_cage_extraction_cache;
+ MeshBatchList batch;
- struct {
- /* Surfaces / Render */
- GPUBatch *surface;
- GPUBatch *surface_weights;
- /* Edit mode */
- GPUBatch *edit_triangles;
- GPUBatch *edit_vertices;
- GPUBatch *edit_edges;
- GPUBatch *edit_vnor;
- GPUBatch *edit_lnor;
- GPUBatch *edit_fdots;
- GPUBatch *edit_mesh_analysis;
- GPUBatch *edit_skin_roots;
- /* Edit UVs */
- GPUBatch *edituv_faces_stretch_area;
- GPUBatch *edituv_faces_stretch_angle;
- GPUBatch *edituv_faces;
- GPUBatch *edituv_edges;
- GPUBatch *edituv_verts;
- GPUBatch *edituv_fdots;
- /* Edit selection */
- GPUBatch *edit_selection_verts;
- GPUBatch *edit_selection_edges;
- GPUBatch *edit_selection_faces;
- GPUBatch *edit_selection_fdots;
- /* Common display / Other */
- GPUBatch *all_verts;
- GPUBatch *all_edges;
- GPUBatch *loose_edges;
- GPUBatch *edge_detection;
- GPUBatch *wire_edges; /* Individual edges with face normals. */
- GPUBatch *wire_loops; /* Loops around faces. no edges between selected faces */
- GPUBatch *wire_loops_uvs; /* Same as wire_loops but only has uvs. */
- GPUBatch *sculpt_overlays;
- } batch;
+ /* Index buffer per material. These are subranges of `ibo.tris` */
+ GPUIndexBuf **tris_per_mat;
GPUBatch **surface_per_mat;
- uint32_t batch_requested; /* DRWBatchFlag */
- uint32_t batch_ready; /* DRWBatchFlag */
+ DRWBatchFlag batch_requested; /* DRWBatchFlag */
+ DRWBatchFlag batch_ready; /* DRWBatchFlag */
/* settings to determine if cache is invalid */
int edge_len;
@@ -259,55 +299,13 @@ typedef struct MeshBatchCache {
bool no_loose_wire;
} MeshBatchCache;
-#define MBC_BATCH_LEN (sizeof(((MeshBatchCache){0}).batch) / sizeof(void *))
-#define MBC_VBO_LEN (sizeof(((MeshBufferCache){0}).vbo) / sizeof(void *))
-#define MBC_IBO_LEN (sizeof(((MeshBufferCache){0}).ibo) / sizeof(void *))
-
-#define MBC_BATCH_INDEX(batch_name) \
- ((offsetof(MeshBatchCache, batch_name) - offsetof(MeshBatchCache, batch)) / sizeof(void *))
-
-typedef enum DRWBatchFlag {
- MBC_SURFACE = (1u << MBC_BATCH_INDEX(batch.surface)),
- MBC_SURFACE_WEIGHTS = (1u << MBC_BATCH_INDEX(batch.surface_weights)),
- MBC_EDIT_TRIANGLES = (1u << MBC_BATCH_INDEX(batch.edit_triangles)),
- MBC_EDIT_VERTICES = (1u << MBC_BATCH_INDEX(batch.edit_vertices)),
- MBC_EDIT_EDGES = (1u << MBC_BATCH_INDEX(batch.edit_edges)),
- MBC_EDIT_VNOR = (1u << MBC_BATCH_INDEX(batch.edit_vnor)),
- MBC_EDIT_LNOR = (1u << MBC_BATCH_INDEX(batch.edit_lnor)),
- MBC_EDIT_FACEDOTS = (1u << MBC_BATCH_INDEX(batch.edit_fdots)),
- MBC_EDIT_MESH_ANALYSIS = (1u << MBC_BATCH_INDEX(batch.edit_mesh_analysis)),
- MBC_SKIN_ROOTS = (1u << MBC_BATCH_INDEX(batch.edit_skin_roots)),
- MBC_EDITUV_FACES_STRETCH_AREA = (1u << MBC_BATCH_INDEX(batch.edituv_faces_stretch_area)),
- MBC_EDITUV_FACES_STRETCH_ANGLE = (1u << MBC_BATCH_INDEX(batch.edituv_faces_stretch_angle)),
- MBC_EDITUV_FACES = (1u << MBC_BATCH_INDEX(batch.edituv_faces)),
- MBC_EDITUV_EDGES = (1u << MBC_BATCH_INDEX(batch.edituv_edges)),
- MBC_EDITUV_VERTS = (1u << MBC_BATCH_INDEX(batch.edituv_verts)),
- MBC_EDITUV_FACEDOTS = (1u << MBC_BATCH_INDEX(batch.edituv_fdots)),
- MBC_EDIT_SELECTION_VERTS = (1u << MBC_BATCH_INDEX(batch.edit_selection_verts)),
- MBC_EDIT_SELECTION_EDGES = (1u << MBC_BATCH_INDEX(batch.edit_selection_edges)),
- MBC_EDIT_SELECTION_FACES = (1u << MBC_BATCH_INDEX(batch.edit_selection_faces)),
- MBC_EDIT_SELECTION_FACEDOTS = (1u << MBC_BATCH_INDEX(batch.edit_selection_fdots)),
- MBC_ALL_VERTS = (1u << MBC_BATCH_INDEX(batch.all_verts)),
- MBC_ALL_EDGES = (1u << MBC_BATCH_INDEX(batch.all_edges)),
- MBC_LOOSE_EDGES = (1u << MBC_BATCH_INDEX(batch.loose_edges)),
- MBC_EDGE_DETECTION = (1u << MBC_BATCH_INDEX(batch.edge_detection)),
- MBC_WIRE_EDGES = (1u << MBC_BATCH_INDEX(batch.wire_edges)),
- MBC_WIRE_LOOPS = (1u << MBC_BATCH_INDEX(batch.wire_loops)),
- MBC_WIRE_LOOPS_UVS = (1u << MBC_BATCH_INDEX(batch.wire_loops_uvs)),
- MBC_SCULPT_OVERLAYS = (1u << MBC_BATCH_INDEX(batch.sculpt_overlays)),
-} DRWBatchFlag;
-
-BLI_STATIC_ASSERT(MBC_BATCH_INDEX(surface_per_mat) < 32,
- "Number of batches exceeded the limit of bit fields");
-
#define MBC_EDITUV \
(MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \
MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_WIRE_LOOPS_UVS)
void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
- MeshBatchCache *cache,
- MeshBufferCache *mbc,
- MeshBufferExtractionCache *extraction_cache,
+ MeshBatchCache *mbc,
+ MeshBufferCache *extraction_cache,
Mesh *me,
const bool is_editmode,
const bool is_paint_mode,
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.cc b/source/blender/draw/intern/draw_cache_extract_mesh.cc
index 1bc2b8a9def..06c449fe590 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.cc
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.cc
@@ -162,7 +162,7 @@ struct ExtractTaskData {
const MeshRenderData *mr = nullptr;
MeshBatchCache *cache = nullptr;
ExtractorRunDatas *extractors = nullptr;
- MeshBufferCache *mbc = nullptr;
+ MeshBufferList *mbuflist = nullptr;
eMRIterType iter_type;
bool use_threading = false;
@@ -170,9 +170,13 @@ struct ExtractTaskData {
ExtractTaskData(const MeshRenderData *mr,
struct MeshBatchCache *cache,
ExtractorRunDatas *extractors,
- MeshBufferCache *mbc,
+ MeshBufferList *mbuflist,
const bool use_threading)
- : mr(mr), cache(cache), extractors(extractors), mbc(mbc), use_threading(use_threading)
+ : mr(mr),
+ cache(cache),
+ extractors(extractors),
+ mbuflist(mbuflist),
+ use_threading(use_threading)
{
iter_type = extractors->iter_types();
};
@@ -204,13 +208,13 @@ static void extract_task_data_free(void *data)
BLI_INLINE void extract_init(const MeshRenderData *mr,
struct MeshBatchCache *cache,
ExtractorRunDatas &extractors,
- MeshBufferCache *mbc,
+ MeshBufferList *mbuflist,
void *data_stack)
{
uint32_t data_offset = 0;
for (ExtractorRunData &run_data : extractors) {
const MeshExtract *extractor = run_data.extractor;
- run_data.buffer = mesh_extract_buffer_get(extractor, mbc);
+ run_data.buffer = mesh_extract_buffer_get(extractor, mbuflist);
run_data.data_offset = data_offset;
extractor->init(mr, cache, run_data.buffer, POINTER_OFFSET(data_stack, data_offset));
data_offset += (uint32_t)extractor->data_size;
@@ -445,7 +449,7 @@ static void extract_task_range_run(void *__restrict taskdata)
settings.func_reduce = extract_task_reduce;
settings.min_iter_per_thread = MIN_RANGE_LEN;
- extract_init(data->mr, data->cache, *data->extractors, data->mbc, userdata_chunk);
+ extract_init(data->mr, data->cache, *data->extractors, data->mbuflist, userdata_chunk);
if (iter_type & MR_ITER_LOOPTRI) {
extract_task_range_run_iter(data->mr, data->extractors, MR_ITER_LOOPTRI, is_mesh, &settings);
@@ -474,10 +478,10 @@ static struct TaskNode *extract_task_node_create(struct TaskGraph *task_graph,
const MeshRenderData *mr,
MeshBatchCache *cache,
ExtractorRunDatas *extractors,
- MeshBufferCache *mbc,
+ MeshBufferList *mbuflist,
const bool use_threading)
{
- ExtractTaskData *taskdata = new ExtractTaskData(mr, cache, extractors, mbc, use_threading);
+ ExtractTaskData *taskdata = new ExtractTaskData(mr, cache, extractors, mbuflist, use_threading);
struct TaskNode *task_node = BLI_task_graph_node_create(
task_graph,
extract_task_range_run,
@@ -493,12 +497,12 @@ static struct TaskNode *extract_task_node_create(struct TaskGraph *task_graph,
* \{ */
struct MeshRenderDataUpdateTaskData {
MeshRenderData *mr = nullptr;
- MeshBufferExtractionCache *cache = nullptr;
+ MeshBufferCache *cache = nullptr;
eMRIterType iter_type;
eMRDataType data_flag;
MeshRenderDataUpdateTaskData(MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
eMRIterType iter_type,
eMRDataType data_flag)
: mr(mr), cache(cache), iter_type(iter_type), data_flag(data_flag)
@@ -538,7 +542,7 @@ static void mesh_extract_render_data_node_exec(void *__restrict task_data)
static struct TaskNode *mesh_extract_render_data_node_create(struct TaskGraph *task_graph,
MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
const eMRIterType iter_type,
const eMRDataType data_flag)
{
@@ -562,7 +566,6 @@ static struct TaskNode *mesh_extract_render_data_node_create(struct TaskGraph *t
static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
MeshBatchCache *cache,
MeshBufferCache *mbc,
- MeshBufferExtractionCache *extraction_cache,
Mesh *me,
const bool is_editmode,
@@ -613,9 +616,11 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
/* Create an array containing all the extractors that needs to be executed. */
ExtractorRunDatas extractors;
+ MeshBufferList *mbuflist = &mbc->buff;
+
#define EXTRACT_ADD_REQUESTED(type, name) \
do { \
- if (DRW_##type##_requested(mbc->type.name)) { \
+ if (DRW_##type##_requested(mbuflist->type.name)) { \
const MeshExtract *extractor = mesh_extract_override_get( \
&extract_##name, do_hq_normals, override_single_mat); \
extractors.append(extractor); \
@@ -647,19 +652,19 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
EXTRACT_ADD_REQUESTED(vbo, skin_roots);
EXTRACT_ADD_REQUESTED(ibo, tris);
- if (DRW_ibo_requested(mbc->ibo.lines_loose)) {
+ if (DRW_ibo_requested(mbuflist->ibo.lines_loose)) {
/* `ibo.lines_loose` require the `ibo.lines` buffer. */
- if (mbc->ibo.lines == nullptr) {
- DRW_ibo_request(nullptr, &mbc->ibo.lines);
+ if (mbuflist->ibo.lines == nullptr) {
+ DRW_ibo_request(nullptr, &mbuflist->ibo.lines);
}
- const MeshExtract *extractor = DRW_ibo_requested(mbc->ibo.lines) ?
+ const MeshExtract *extractor = DRW_ibo_requested(mbuflist->ibo.lines) ?
&extract_lines_with_lines_loose :
&extract_lines_loose_only;
extractors.append(extractor);
}
- else if (DRW_ibo_requested(mbc->ibo.lines)) {
+ else if (DRW_ibo_requested(mbuflist->ibo.lines)) {
const MeshExtract *extractor;
- if (mbc->ibo.lines_loose != nullptr) {
+ if (mbuflist->ibo.lines_loose != nullptr) {
/* Update `ibo.lines_loose` as it depends on `ibo.lines`. */
extractor = &extract_lines_with_lines_loose;
}
@@ -701,7 +706,7 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
eMRDataType data_flag = extractors.data_types();
struct TaskNode *task_node_mesh_render_data = mesh_extract_render_data_node_create(
- task_graph, mr, extraction_cache, iter_type, data_flag);
+ task_graph, mr, mbc, iter_type, data_flag);
/* Simple heuristic. */
const bool use_thread = (mr->loop_len + mr->loop_loose_len) > MIN_RANGE_LEN;
@@ -714,7 +719,7 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
ExtractorRunDatas *single_threaded_extractors = new ExtractorRunDatas();
single_threaded_extractors->append(extractor);
struct TaskNode *task_node = extract_task_node_create(
- task_graph, mr, cache, single_threaded_extractors, mbc, false);
+ task_graph, mr, cache, single_threaded_extractors, mbuflist, false);
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
}
@@ -725,7 +730,7 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
extractors.filter_threaded_extractors_into(*multi_threaded_extractors);
if (!multi_threaded_extractors->is_empty()) {
struct TaskNode *task_node = extract_task_node_create(
- task_graph, mr, cache, multi_threaded_extractors, mbc, true);
+ task_graph, mr, cache, multi_threaded_extractors, mbuflist, true);
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
}
@@ -738,7 +743,7 @@ static void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
/* Run all requests on the same thread. */
ExtractorRunDatas *extractors_copy = new ExtractorRunDatas(extractors);
struct TaskNode *task_node = extract_task_node_create(
- task_graph, mr, cache, extractors_copy, mbc, false);
+ task_graph, mr, cache, extractors_copy, mbuflist, false);
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
}
@@ -776,7 +781,6 @@ extern "C" {
void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
MeshBatchCache *cache,
MeshBufferCache *mbc,
- MeshBufferExtractionCache *extraction_cache,
Mesh *me,
const bool is_editmode,
@@ -793,7 +797,6 @@ void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
blender::draw::mesh_buffer_cache_create_requested(task_graph,
cache,
mbc,
- extraction_cache,
me,
is_editmode,
is_paint_mode,
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
index 27fd6ca9134..abfbeabef6b 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
@@ -45,17 +45,15 @@
* \{ */
static void mesh_render_data_lverts_bm(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
BMesh *bm);
static void mesh_render_data_ledges_bm(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
BMesh *bm);
-static void mesh_render_data_loose_geom_mesh(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache);
-static void mesh_render_data_loose_geom_build(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache);
+static void mesh_render_data_loose_geom_mesh(const MeshRenderData *mr, MeshBufferCache *cache);
+static void mesh_render_data_loose_geom_build(const MeshRenderData *mr, MeshBufferCache *cache);
-static void mesh_render_data_loose_geom_load(MeshRenderData *mr, MeshBufferExtractionCache *cache)
+static void mesh_render_data_loose_geom_load(MeshRenderData *mr, MeshBufferCache *cache)
{
mr->ledges = cache->loose_geom.edges;
mr->lverts = cache->loose_geom.verts;
@@ -65,8 +63,7 @@ static void mesh_render_data_loose_geom_load(MeshRenderData *mr, MeshBufferExtra
mr->loop_loose_len = mr->vert_loose_len + (mr->edge_loose_len * 2);
}
-static void mesh_render_data_loose_geom_ensure(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache)
+static void mesh_render_data_loose_geom_ensure(const MeshRenderData *mr, MeshBufferCache *cache)
{
/* Early exit: Are loose geometry already available.
* Only checking for loose verts as loose edges and verts are calculated at the same time. */
@@ -76,8 +73,7 @@ static void mesh_render_data_loose_geom_ensure(const MeshRenderData *mr,
mesh_render_data_loose_geom_build(mr, cache);
}
-static void mesh_render_data_loose_geom_build(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache)
+static void mesh_render_data_loose_geom_build(const MeshRenderData *mr, MeshBufferCache *cache)
{
cache->loose_geom.vert_len = 0;
cache->loose_geom.edge_len = 0;
@@ -94,8 +90,7 @@ static void mesh_render_data_loose_geom_build(const MeshRenderData *mr,
}
}
-static void mesh_render_data_loose_geom_mesh(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache)
+static void mesh_render_data_loose_geom_mesh(const MeshRenderData *mr, MeshBufferCache *cache)
{
BLI_bitmap *lvert_map = BLI_BITMAP_NEW(mr->vert_len, __func__);
@@ -128,9 +123,7 @@ static void mesh_render_data_loose_geom_mesh(const MeshRenderData *mr,
MEM_freeN(lvert_map);
}
-static void mesh_render_data_lverts_bm(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
- BMesh *bm)
+static void mesh_render_data_lverts_bm(const MeshRenderData *mr, MeshBufferCache *cache, BMesh *bm)
{
int elem_id;
BMIter iter;
@@ -147,9 +140,7 @@ static void mesh_render_data_lverts_bm(const MeshRenderData *mr,
}
}
-static void mesh_render_data_ledges_bm(const MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
- BMesh *bm)
+static void mesh_render_data_ledges_bm(const MeshRenderData *mr, MeshBufferCache *cache, BMesh *bm)
{
int elem_id;
BMIter iter;
@@ -167,7 +158,7 @@ static void mesh_render_data_ledges_bm(const MeshRenderData *mr,
}
void mesh_render_data_update_loose_geom(MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
const eMRIterType iter_type,
const eMRDataType data_flag)
{
@@ -185,16 +176,13 @@ void mesh_render_data_update_loose_geom(MeshRenderData *mr,
* Contains polygon indices sorted based on their material.
*
* \{ */
-static void mesh_render_data_polys_sorted_load(MeshRenderData *mr,
- const MeshBufferExtractionCache *cache);
-static void mesh_render_data_polys_sorted_ensure(MeshRenderData *mr,
- MeshBufferExtractionCache *cache);
-static void mesh_render_data_polys_sorted_build(MeshRenderData *mr,
- MeshBufferExtractionCache *cache);
+static void mesh_render_data_polys_sorted_load(MeshRenderData *mr, const MeshBufferCache *cache);
+static void mesh_render_data_polys_sorted_ensure(MeshRenderData *mr, MeshBufferCache *cache);
+static void mesh_render_data_polys_sorted_build(MeshRenderData *mr, MeshBufferCache *cache);
static int *mesh_render_data_mat_tri_len_build(MeshRenderData *mr);
void mesh_render_data_update_polys_sorted(MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
const eMRDataType data_flag)
{
if (data_flag & MR_DATA_POLYS_SORTED) {
@@ -203,16 +191,14 @@ void mesh_render_data_update_polys_sorted(MeshRenderData *mr,
}
}
-static void mesh_render_data_polys_sorted_load(MeshRenderData *mr,
- const MeshBufferExtractionCache *cache)
+static void mesh_render_data_polys_sorted_load(MeshRenderData *mr, const MeshBufferCache *cache)
{
mr->poly_sorted.tri_first_index = cache->poly_sorted.tri_first_index;
mr->poly_sorted.mat_tri_len = cache->poly_sorted.mat_tri_len;
mr->poly_sorted.visible_tri_len = cache->poly_sorted.visible_tri_len;
}
-static void mesh_render_data_polys_sorted_ensure(MeshRenderData *mr,
- MeshBufferExtractionCache *cache)
+static void mesh_render_data_polys_sorted_ensure(MeshRenderData *mr, MeshBufferCache *cache)
{
if (cache->poly_sorted.tri_first_index) {
return;
@@ -220,8 +206,7 @@ static void mesh_render_data_polys_sorted_ensure(MeshRenderData *mr,
mesh_render_data_polys_sorted_build(mr, cache);
}
-static void mesh_render_data_polys_sorted_build(MeshRenderData *mr,
- MeshBufferExtractionCache *cache)
+static void mesh_render_data_polys_sorted_build(MeshRenderData *mr, MeshBufferCache *cache)
{
int *tri_first_index = MEM_mallocN(sizeof(*tri_first_index) * mr->poly_len, __func__);
int *mat_tri_len = mesh_render_data_mat_tri_len_build(mr);
@@ -584,7 +569,7 @@ void mesh_render_data_free(MeshRenderData *mr)
MEM_SAFE_FREE(mr->mlooptri);
MEM_SAFE_FREE(mr->loop_normals);
- /* Loose geometry are owned by #MeshBufferExtractionCache. */
+ /* Loose geometry are owned by #MeshBufferCache. */
mr->ledges = NULL;
mr->lverts = NULL;
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 359788545e4..18664498d00 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -79,39 +79,42 @@
/* clang-format off */
-#define _BUFFER_INDEX(buff_name) ((offsetof(MeshBufferCache, buff_name) - offsetof(MeshBufferCache, vbo)) / sizeof(void *))
-
-#define _MDEPS_CREATE1(b) (1u << MBC_BATCH_INDEX(b))
-#define _MDEPS_CREATE2(b1, b2) _MDEPS_CREATE1(b1) | _MDEPS_CREATE1(b2)
-#define _MDEPS_CREATE3(b1, b2, b3) _MDEPS_CREATE2(b1, b2) | _MDEPS_CREATE1(b3)
-#define _MDEPS_CREATE4(b1, b2, b3, b4) _MDEPS_CREATE3(b1, b2, b3) | _MDEPS_CREATE1(b4)
-#define _MDEPS_CREATE5(b1, b2, b3, b4, b5) _MDEPS_CREATE4(b1, b2, b3, b4) | _MDEPS_CREATE1(b5)
-#define _MDEPS_CREATE6(b1, b2, b3, b4, b5, b6) _MDEPS_CREATE5(b1, b2, b3, b4, b5) | _MDEPS_CREATE1(b6)
-#define _MDEPS_CREATE7(b1, b2, b3, b4, b5, b6, b7) _MDEPS_CREATE6(b1, b2, b3, b4, b5, b6) | _MDEPS_CREATE1(b7)
-#define _MDEPS_CREATE8(b1, b2, b3, b4, b5, b6, b7, b8) _MDEPS_CREATE7(b1, b2, b3, b4, b5, b6, b7) | _MDEPS_CREATE1(b8)
-#define _MDEPS_CREATE9(b1, b2, b3, b4, b5, b6, b7, b8, b9) _MDEPS_CREATE8(b1, b2, b3, b4, b5, b6, b7, b8) | _MDEPS_CREATE1(b9)
-#define _MDEPS_CREATE10(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10) _MDEPS_CREATE9(b1, b2, b3, b4, b5, b6, b7, b8, b9) | _MDEPS_CREATE1(b10)
-#define _MDEPS_CREATE19(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19) _MDEPS_CREATE10(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10) | _MDEPS_CREATE9(b11, b12, b13, b14, b15, b16, b17, b18, b19)
-
-#define MDEPS_CREATE(buff_name, ...) [_BUFFER_INDEX(buff_name)] = VA_NARGS_CALL_OVERLOAD(_MDEPS_CREATE, __VA_ARGS__)
-
-#define _MDEPS_CREATE_MAP1(a) g_buffer_desps[_BUFFER_INDEX(a)]
-#define _MDEPS_CREATE_MAP2(a, b) _MDEPS_CREATE_MAP1(a) | _MDEPS_CREATE_MAP1(b)
-#define _MDEPS_CREATE_MAP3(a, b, c) _MDEPS_CREATE_MAP2(a, b) | _MDEPS_CREATE_MAP1(c)
-#define _MDEPS_CREATE_MAP4(a, b, c, d) _MDEPS_CREATE_MAP3(a, b, c) | _MDEPS_CREATE_MAP1(d)
-#define _MDEPS_CREATE_MAP5(a, b, c, d, e) _MDEPS_CREATE_MAP4(a, b, c, d) | _MDEPS_CREATE_MAP1(e)
-#define _MDEPS_CREATE_MAP6(a, b, c, d, e, f) _MDEPS_CREATE_MAP5(a, b, c, d, e) | _MDEPS_CREATE_MAP1(f)
-#define _MDEPS_CREATE_MAP7(a, b, c, d, e, f, g) _MDEPS_CREATE_MAP6(a, b, c, d, e, f) | _MDEPS_CREATE_MAP1(g)
-#define _MDEPS_CREATE_MAP8(a, b, c, d, e, f, g, h) _MDEPS_CREATE_MAP7(a, b, c, d, e, f, g) | _MDEPS_CREATE_MAP1(h)
-#define _MDEPS_CREATE_MAP9(a, b, c, d, e, f, g, h, i) _MDEPS_CREATE_MAP8(a, b, c, d, e, f, g, h) | _MDEPS_CREATE_MAP1(i)
-#define _MDEPS_CREATE_MAP10(a, b, c, d, e, f, g, h, i, j) _MDEPS_CREATE_MAP9(a, b, c, d, e, f, g, h, i) | _MDEPS_CREATE_MAP1(j)
-
-#define MDEPS_CREATE_MAP(...) VA_NARGS_CALL_OVERLOAD(_MDEPS_CREATE_MAP, __VA_ARGS__)
+#define BUFFER_INDEX(buff_name) ((offsetof(MeshBufferList, buff_name) - offsetof(MeshBufferList, vbo)) / sizeof(void *))
+#define BUFFER_LEN (sizeof(MeshBufferList) / sizeof(void *))
+
+#define _BATCH_FLAG1(b) (1u << MBC_BATCH_INDEX(b))
+#define _BATCH_FLAG2(b1, b2) _BATCH_FLAG1(b1) | _BATCH_FLAG1(b2)
+#define _BATCH_FLAG3(b1, b2, b3) _BATCH_FLAG2(b1, b2) | _BATCH_FLAG1(b3)
+#define _BATCH_FLAG4(b1, b2, b3, b4) _BATCH_FLAG3(b1, b2, b3) | _BATCH_FLAG1(b4)
+#define _BATCH_FLAG5(b1, b2, b3, b4, b5) _BATCH_FLAG4(b1, b2, b3, b4) | _BATCH_FLAG1(b5)
+#define _BATCH_FLAG6(b1, b2, b3, b4, b5, b6) _BATCH_FLAG5(b1, b2, b3, b4, b5) | _BATCH_FLAG1(b6)
+#define _BATCH_FLAG7(b1, b2, b3, b4, b5, b6, b7) _BATCH_FLAG6(b1, b2, b3, b4, b5, b6) | _BATCH_FLAG1(b7)
+#define _BATCH_FLAG8(b1, b2, b3, b4, b5, b6, b7, b8) _BATCH_FLAG7(b1, b2, b3, b4, b5, b6, b7) | _BATCH_FLAG1(b8)
+#define _BATCH_FLAG9(b1, b2, b3, b4, b5, b6, b7, b8, b9) _BATCH_FLAG8(b1, b2, b3, b4, b5, b6, b7, b8) | _BATCH_FLAG1(b9)
+#define _BATCH_FLAG10(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10) _BATCH_FLAG9(b1, b2, b3, b4, b5, b6, b7, b8, b9) | _BATCH_FLAG1(b10)
+#define _BATCH_FLAG18(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18) _BATCH_FLAG10(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10) | _BATCH_FLAG8(b11, b12, b13, b14, b15, b16, b17, b18)
+
+#define BATCH_FLAG(...) VA_NARGS_CALL_OVERLOAD(_BATCH_FLAG, __VA_ARGS__)
+
+#define _BATCH_MAP1(a) g_buffer_deps[BUFFER_INDEX(a)]
+#define _BATCH_MAP2(a, b) _BATCH_MAP1(a) | _BATCH_MAP1(b)
+#define _BATCH_MAP3(a, b, c) _BATCH_MAP2(a, b) | _BATCH_MAP1(c)
+#define _BATCH_MAP4(a, b, c, d) _BATCH_MAP3(a, b, c) | _BATCH_MAP1(d)
+#define _BATCH_MAP5(a, b, c, d, e) _BATCH_MAP4(a, b, c, d) | _BATCH_MAP1(e)
+#define _BATCH_MAP6(a, b, c, d, e, f) _BATCH_MAP5(a, b, c, d, e) | _BATCH_MAP1(f)
+#define _BATCH_MAP7(a, b, c, d, e, f, g) _BATCH_MAP6(a, b, c, d, e, f) | _BATCH_MAP1(g)
+#define _BATCH_MAP8(a, b, c, d, e, f, g, h) _BATCH_MAP7(a, b, c, d, e, f, g) | _BATCH_MAP1(h)
+#define _BATCH_MAP9(a, b, c, d, e, f, g, h, i) _BATCH_MAP8(a, b, c, d, e, f, g, h) | _BATCH_MAP1(i)
+#define _BATCH_MAP10(a, b, c, d, e, f, g, h, i, j) _BATCH_MAP9(a, b, c, d, e, f, g, h, i) | _BATCH_MAP1(j)
+
+#define BATCH_MAP(...) VA_NARGS_CALL_OVERLOAD(_BATCH_MAP, __VA_ARGS__)
#ifndef NDEBUG
-# define _MDEPS_ASSERT2(b, name) \
- g_buffer_desps_d[_BUFFER_INDEX(name)] |= _MDEPS_CREATE1(b); \
- BLI_assert(g_buffer_desps[_BUFFER_INDEX(name)] & _MDEPS_CREATE1(b))
+# define MDEPS_ASSERT_INDEX(buffer_index, batch_flag) \
+ g_buffer_deps_d[buffer_index] |= batch_flag; \
+ BLI_assert(g_buffer_deps[buffer_index] & batch_flag)
+
+# define _MDEPS_ASSERT2(b, n1) MDEPS_ASSERT_INDEX(BUFFER_INDEX(n1), b)
# define _MDEPS_ASSERT3(b, n1, n2) _MDEPS_ASSERT2(b, n1); _MDEPS_ASSERT2(b, n2)
# define _MDEPS_ASSERT4(b, n1, n2, n3) _MDEPS_ASSERT3(b, n1, n2); _MDEPS_ASSERT2(b, n3)
# define _MDEPS_ASSERT5(b, n1, n2, n3, n4) _MDEPS_ASSERT4(b, n1, n2, n3); _MDEPS_ASSERT2(b, n4)
@@ -119,103 +122,101 @@
# define _MDEPS_ASSERT7(b, n1, n2, n3, n4, n5, n6) _MDEPS_ASSERT6(b, n1, n2, n3, n4, n5); _MDEPS_ASSERT2(b, n6)
# define _MDEPS_ASSERT8(b, n1, n2, n3, n4, n5, n6, n7) _MDEPS_ASSERT7(b, n1, n2, n3, n4, n5, n6); _MDEPS_ASSERT2(b, n7)
-# define MDEPS_ASSERT(...) VA_NARGS_CALL_OVERLOAD(_MDEPS_ASSERT, __VA_ARGS__)
-# define MDEPS_ASSERT_MAP(name) BLI_assert(g_buffer_desps_d[_BUFFER_INDEX(name)] == g_buffer_desps[_BUFFER_INDEX(name)])
+# define MDEPS_ASSERT_FLAG(...) VA_NARGS_CALL_OVERLOAD(_MDEPS_ASSERT, __VA_ARGS__)
+# define MDEPS_ASSERT(batch_name, ...) MDEPS_ASSERT_FLAG(BATCH_FLAG(batch_name), __VA_ARGS__)
+# define MDEPS_ASSERT_MAP_INDEX(buff_index) BLI_assert(g_buffer_deps_d[buff_index] == g_buffer_deps[buff_index])
+# define MDEPS_ASSERT_MAP(buff_name) MDEPS_ASSERT_MAP_INDEX(BUFFER_INDEX(buff_name))
#else
-# define MDEPS_ASSERT(...)
-# define MDEPS_ASSERT_MAP(name)
+# define MDEPS_ASSERT_INDEX(buffer_index, batch_flag)
+# define MDEPS_ASSERT_FLAG(...)
+# define MDEPS_ASSERT(batch_name, ...)
+# define MDEPS_ASSERT_MAP_INDEX(buff_index)
+# define MDEPS_ASSERT_MAP(buff_name)
#endif
/* clang-format on */
-static const DRWBatchFlag g_buffer_desps[] = {
- MDEPS_CREATE(vbo.pos_nor,
- batch.surface,
- batch.surface_weights,
- batch.edit_triangles,
- batch.edit_vertices,
- batch.edit_edges,
- batch.edit_vnor,
- batch.edit_lnor,
- batch.edit_mesh_analysis,
- batch.edit_selection_verts,
- batch.edit_selection_edges,
- batch.edit_selection_faces,
- batch.all_verts,
- batch.all_edges,
- batch.loose_edges,
- batch.edge_detection,
- batch.wire_edges,
- batch.wire_loops,
- batch.sculpt_overlays,
- surface_per_mat),
- MDEPS_CREATE(vbo.lnor, batch.surface, batch.edit_lnor, batch.wire_loops, surface_per_mat),
- MDEPS_CREATE(vbo.edge_fac, batch.wire_edges),
- MDEPS_CREATE(vbo.weights, batch.surface_weights),
- MDEPS_CREATE(vbo.uv,
- batch.surface,
- batch.edituv_faces_stretch_area,
- batch.edituv_faces_stretch_angle,
- batch.edituv_faces,
- batch.edituv_edges,
- batch.edituv_verts,
- batch.wire_loops_uvs,
- surface_per_mat),
- MDEPS_CREATE(vbo.tan, surface_per_mat),
- MDEPS_CREATE(vbo.vcol, batch.surface, surface_per_mat),
- MDEPS_CREATE(vbo.sculpt_data, batch.sculpt_overlays),
- MDEPS_CREATE(vbo.orco, surface_per_mat),
- MDEPS_CREATE(vbo.edit_data, batch.edit_triangles, batch.edit_edges, batch.edit_vertices),
- MDEPS_CREATE(vbo.edituv_data,
- batch.edituv_faces,
- batch.edituv_faces_stretch_area,
- batch.edituv_faces_stretch_angle,
- batch.edituv_edges,
- batch.edituv_verts),
- MDEPS_CREATE(vbo.edituv_stretch_area, batch.edituv_faces_stretch_area),
- MDEPS_CREATE(vbo.edituv_stretch_angle, batch.edituv_faces_stretch_angle),
- MDEPS_CREATE(vbo.mesh_analysis, batch.edit_mesh_analysis),
- MDEPS_CREATE(vbo.fdots_pos, batch.edit_fdots, batch.edit_selection_fdots),
- MDEPS_CREATE(vbo.fdots_nor, batch.edit_fdots),
- MDEPS_CREATE(vbo.fdots_uv, batch.edituv_fdots),
- MDEPS_CREATE(vbo.fdots_edituv_data, batch.edituv_fdots),
- MDEPS_CREATE(vbo.skin_roots, batch.edit_skin_roots),
- MDEPS_CREATE(vbo.vert_idx, batch.edit_selection_verts),
- MDEPS_CREATE(vbo.edge_idx, batch.edit_selection_edges),
- MDEPS_CREATE(vbo.poly_idx, batch.edit_selection_faces),
- MDEPS_CREATE(vbo.fdot_idx, batch.edit_selection_fdots),
-
- MDEPS_CREATE(ibo.tris,
- batch.surface,
- batch.surface_weights,
- batch.edit_triangles,
- batch.edit_lnor,
- batch.edit_mesh_analysis,
- batch.edit_selection_faces,
- batch.sculpt_overlays),
- MDEPS_CREATE(ibo.lines,
- batch.edit_edges,
- batch.edit_selection_edges,
- batch.all_edges,
- batch.wire_edges),
- MDEPS_CREATE(ibo.lines_loose, batch.loose_edges),
- MDEPS_CREATE(ibo.points, batch.edit_vnor, batch.edit_vertices, batch.edit_selection_verts),
- MDEPS_CREATE(ibo.fdots, batch.edit_fdots, batch.edit_selection_fdots),
- MDEPS_CREATE(ibo.lines_paint_mask, batch.wire_loops),
- MDEPS_CREATE(ibo.lines_adjacency, batch.edge_detection),
- MDEPS_CREATE(ibo.edituv_tris,
- batch.edituv_faces,
- batch.edituv_faces_stretch_area,
- batch.edituv_faces_stretch_angle),
- MDEPS_CREATE(ibo.edituv_lines, batch.edituv_edges, batch.wire_loops_uvs),
- MDEPS_CREATE(ibo.edituv_points, batch.edituv_verts),
- MDEPS_CREATE(ibo.edituv_fdots, batch.edituv_fdots),
-
- MDEPS_CREATE(tris_per_mat, surface_per_mat),
+#define TRIS_PER_MAT_INDEX BUFFER_LEN
+#define SURFACE_PER_MAT_FLAG (1u << MBC_BATCH_LEN)
+
+static const DRWBatchFlag g_buffer_deps[] = {
+ [BUFFER_INDEX(vbo.pos_nor)] = BATCH_FLAG(surface,
+ surface_weights,
+ edit_triangles,
+ edit_vertices,
+ edit_edges,
+ edit_vnor,
+ edit_lnor,
+ edit_mesh_analysis,
+ edit_selection_verts,
+ edit_selection_edges,
+ edit_selection_faces,
+ all_verts,
+ all_edges,
+ loose_edges,
+ edge_detection,
+ wire_edges,
+ wire_loops,
+ sculpt_overlays) |
+ SURFACE_PER_MAT_FLAG,
+ [BUFFER_INDEX(vbo.lnor)] = BATCH_FLAG(surface, edit_lnor, wire_loops) | SURFACE_PER_MAT_FLAG,
+ [BUFFER_INDEX(vbo.edge_fac)] = BATCH_FLAG(wire_edges),
+ [BUFFER_INDEX(vbo.weights)] = BATCH_FLAG(surface_weights),
+ [BUFFER_INDEX(vbo.uv)] = BATCH_FLAG(surface,
+ edituv_faces_stretch_area,
+ edituv_faces_stretch_angle,
+ edituv_faces,
+ edituv_edges,
+ edituv_verts,
+ wire_loops_uvs) |
+ SURFACE_PER_MAT_FLAG,
+ [BUFFER_INDEX(vbo.tan)] = SURFACE_PER_MAT_FLAG,
+ [BUFFER_INDEX(vbo.vcol)] = BATCH_FLAG(surface) | SURFACE_PER_MAT_FLAG,
+ [BUFFER_INDEX(vbo.sculpt_data)] = BATCH_FLAG(sculpt_overlays),
+ [BUFFER_INDEX(vbo.orco)] = SURFACE_PER_MAT_FLAG,
+ [BUFFER_INDEX(vbo.edit_data)] = BATCH_FLAG(edit_triangles, edit_edges, edit_vertices),
+ [BUFFER_INDEX(vbo.edituv_data)] = BATCH_FLAG(edituv_faces,
+ edituv_faces_stretch_area,
+ edituv_faces_stretch_angle,
+ edituv_edges,
+ edituv_verts),
+ [BUFFER_INDEX(vbo.edituv_stretch_area)] = BATCH_FLAG(edituv_faces_stretch_area),
+ [BUFFER_INDEX(vbo.edituv_stretch_angle)] = BATCH_FLAG(edituv_faces_stretch_angle),
+ [BUFFER_INDEX(vbo.mesh_analysis)] = BATCH_FLAG(edit_mesh_analysis),
+ [BUFFER_INDEX(vbo.fdots_pos)] = BATCH_FLAG(edit_fdots, edit_selection_fdots),
+ [BUFFER_INDEX(vbo.fdots_nor)] = BATCH_FLAG(edit_fdots),
+ [BUFFER_INDEX(vbo.fdots_uv)] = BATCH_FLAG(edituv_fdots),
+ [BUFFER_INDEX(vbo.fdots_edituv_data)] = BATCH_FLAG(edituv_fdots),
+ [BUFFER_INDEX(vbo.skin_roots)] = BATCH_FLAG(edit_skin_roots),
+ [BUFFER_INDEX(vbo.vert_idx)] = BATCH_FLAG(edit_selection_verts),
+ [BUFFER_INDEX(vbo.edge_idx)] = BATCH_FLAG(edit_selection_edges),
+ [BUFFER_INDEX(vbo.poly_idx)] = BATCH_FLAG(edit_selection_faces),
+ [BUFFER_INDEX(vbo.fdot_idx)] = BATCH_FLAG(edit_selection_fdots),
+
+ [BUFFER_INDEX(ibo.tris)] = BATCH_FLAG(surface,
+ surface_weights,
+ edit_triangles,
+ edit_lnor,
+ edit_mesh_analysis,
+ edit_selection_faces,
+ sculpt_overlays),
+ [BUFFER_INDEX(ibo.lines)] = BATCH_FLAG(
+ edit_edges, edit_selection_edges, all_edges, wire_edges),
+ [BUFFER_INDEX(ibo.lines_loose)] = BATCH_FLAG(loose_edges),
+ [BUFFER_INDEX(ibo.points)] = BATCH_FLAG(edit_vnor, edit_vertices, edit_selection_verts),
+ [BUFFER_INDEX(ibo.fdots)] = BATCH_FLAG(edit_fdots, edit_selection_fdots),
+ [BUFFER_INDEX(ibo.lines_paint_mask)] = BATCH_FLAG(wire_loops),
+ [BUFFER_INDEX(ibo.lines_adjacency)] = BATCH_FLAG(edge_detection),
+ [BUFFER_INDEX(ibo.edituv_tris)] = BATCH_FLAG(
+ edituv_faces, edituv_faces_stretch_area, edituv_faces_stretch_angle),
+ [BUFFER_INDEX(ibo.edituv_lines)] = BATCH_FLAG(edituv_edges, wire_loops_uvs),
+ [BUFFER_INDEX(ibo.edituv_points)] = BATCH_FLAG(edituv_verts),
+ [BUFFER_INDEX(ibo.edituv_fdots)] = BATCH_FLAG(edituv_fdots),
+ [TRIS_PER_MAT_INDEX] = SURFACE_PER_MAT_FLAG,
};
#ifndef NDEBUG
-static DRWBatchFlag g_buffer_desps_d[sizeof(g_buffer_desps)] = {0};
+static DRWBatchFlag g_buffer_deps_d[ARRAY_SIZE(g_buffer_deps)] = {0};
#endif
static void mesh_batch_cache_discard_surface_batches(MeshBatchCache *cache);
@@ -231,7 +232,7 @@ static void mesh_batch_cache_discard_batch(MeshBatchCache *cache, const DRWBatch
}
}
- if (batch_map & (1u << MBC_BATCH_INDEX(surface_per_mat))) {
+ if (batch_map & SURFACE_PER_MAT_FLAG) {
mesh_batch_cache_discard_surface_batches(cache);
}
}
@@ -661,8 +662,7 @@ static void mesh_batch_cache_init(Mesh *me)
cache->mat_len = mesh_render_mat_len_get(me);
cache->surface_per_mat = MEM_callocN(sizeof(*cache->surface_per_mat) * cache->mat_len, __func__);
- cache->final.tris_per_mat = MEM_callocN(sizeof(*cache->final.tris_per_mat) * cache->mat_len,
- __func__);
+ cache->tris_per_mat = MEM_callocN(sizeof(*cache->tris_per_mat) * cache->mat_len, __func__);
cache->is_dirty = false;
cache->batch_ready = 0;
@@ -688,8 +688,8 @@ static void mesh_batch_cache_check_vertex_group(MeshBatchCache *cache,
const struct DRW_MeshWeightState *wstate)
{
if (!drw_mesh_weight_state_compare(&cache->weight_state, wstate)) {
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.weights);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.weights);
}
GPU_BATCH_CLEAR_SAFE(cache->batch.surface_weights);
@@ -708,6 +708,9 @@ static void mesh_batch_cache_request_surface_batches(MeshBatchCache *cache)
}
}
+/* Free batches with material-mapped looptris.
+ * NOTE: The updating of the indices buffers (#tris_per_mat) is handled in the extractors.
+ * No need to discard they here. */
static void mesh_batch_cache_discard_surface_batches(MeshBatchCache *cache)
{
GPU_BATCH_DISCARD_SAFE(cache->batch.surface);
@@ -719,41 +722,41 @@ static void mesh_batch_cache_discard_surface_batches(MeshBatchCache *cache)
static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache)
{
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.uv);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.tan);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.vcol);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.orco);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.uv);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.tan);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.vcol);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.orco);
}
- DRWBatchFlag batch_map = MDEPS_CREATE_MAP(vbo.uv, vbo.tan, vbo.vcol, vbo.orco);
+ DRWBatchFlag batch_map = BATCH_MAP(vbo.uv, vbo.tan, vbo.vcol, vbo.orco);
mesh_batch_cache_discard_batch(cache, batch_map);
mesh_cd_layers_type_clear(&cache->cd_used);
}
static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache)
{
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_stretch_angle);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_stretch_area);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.uv);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_data);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_uv);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_edituv_data);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_tris);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_lines);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_points);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_fdots);
- }
- DRWBatchFlag batch_map = MDEPS_CREATE_MAP(vbo.edituv_stretch_angle,
- vbo.edituv_stretch_area,
- vbo.uv,
- vbo.edituv_data,
- vbo.fdots_uv,
- vbo.fdots_edituv_data,
- ibo.edituv_tris,
- ibo.edituv_lines,
- ibo.edituv_points,
- ibo.edituv_fdots);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edituv_stretch_angle);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edituv_stretch_area);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.uv);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edituv_data);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_uv);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_edituv_data);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_tris);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_lines);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_points);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_fdots);
+ }
+ DRWBatchFlag batch_map = BATCH_MAP(vbo.edituv_stretch_angle,
+ vbo.edituv_stretch_area,
+ vbo.uv,
+ vbo.edituv_data,
+ vbo.fdots_uv,
+ vbo.fdots_edituv_data,
+ ibo.edituv_tris,
+ ibo.edituv_lines,
+ ibo.edituv_points,
+ ibo.edituv_fdots);
mesh_batch_cache_discard_batch(cache, batch_map);
cache->tot_area = 0.0f;
@@ -768,20 +771,20 @@ static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache)
static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache *cache)
{
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_data);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_edituv_data);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_tris);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_lines);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_points);
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_fdots);
- }
- DRWBatchFlag batch_map = MDEPS_CREATE_MAP(vbo.edituv_data,
- vbo.fdots_edituv_data,
- ibo.edituv_tris,
- ibo.edituv_lines,
- ibo.edituv_points,
- ibo.edituv_fdots);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edituv_data);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_edituv_data);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_tris);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_lines);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_points);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_fdots);
+ }
+ DRWBatchFlag batch_map = BATCH_MAP(vbo.edituv_data,
+ vbo.fdots_edituv_data,
+ ibo.edituv_tris,
+ ibo.edituv_lines,
+ ibo.edituv_points,
+ ibo.edituv_fdots);
mesh_batch_cache_discard_batch(cache, batch_map);
}
@@ -794,11 +797,11 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode)
DRWBatchFlag batch_map;
switch (mode) {
case BKE_MESH_BATCH_DIRTY_SELECT:
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edit_data);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_nor);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edit_data);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_nor);
}
- batch_map = MDEPS_CREATE_MAP(vbo.edit_data, vbo.fdots_nor);
+ batch_map = BATCH_MAP(vbo.edit_data, vbo.fdots_nor);
mesh_batch_cache_discard_batch(cache, batch_map);
/* Because visible UVs depends on edit mode selection, discard topology. */
@@ -807,12 +810,12 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode)
case BKE_MESH_BATCH_DIRTY_SELECT_PAINT:
/* Paint mode selection flag is packed inside the nor attribute.
* Note that it can be slow if auto smooth is enabled. (see T63946) */
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.lines_paint_mask);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.lnor);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.lines_paint_mask);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.pos_nor);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.lnor);
}
- batch_map = MDEPS_CREATE_MAP(ibo.lines_paint_mask, vbo.pos_nor, vbo.lnor);
+ batch_map = BATCH_MAP(ibo.lines_paint_mask, vbo.pos_nor, vbo.lnor);
mesh_batch_cache_discard_batch(cache, batch_map);
break;
case BKE_MESH_BATCH_DIRTY_ALL:
@@ -826,11 +829,11 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode)
mesh_batch_cache_discard_uvedit(cache);
break;
case BKE_MESH_BATCH_DIRTY_UVEDIT_SELECT:
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_data);
- GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_edituv_data);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edituv_data);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_edituv_data);
}
- batch_map = MDEPS_CREATE_MAP(vbo.edituv_data, vbo.fdots_edituv_data);
+ batch_map = BATCH_MAP(vbo.edituv_data, vbo.fdots_edituv_data);
mesh_batch_cache_discard_batch(cache, batch_map);
break;
default:
@@ -838,28 +841,30 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode)
}
}
-static void mesh_buffer_cache_clear(MeshBufferCache *mbufcache)
+static void mesh_buffer_list_clear(MeshBufferList *mbuflist)
{
- GPUVertBuf **vbos = (GPUVertBuf **)&mbufcache->vbo;
- GPUIndexBuf **ibos = (GPUIndexBuf **)&mbufcache->ibo;
- for (int i = 0; i < sizeof(mbufcache->vbo) / sizeof(void *); i++) {
+ GPUVertBuf **vbos = (GPUVertBuf **)&mbuflist->vbo;
+ GPUIndexBuf **ibos = (GPUIndexBuf **)&mbuflist->ibo;
+ for (int i = 0; i < sizeof(mbuflist->vbo) / sizeof(void *); i++) {
GPU_VERTBUF_DISCARD_SAFE(vbos[i]);
}
- for (int i = 0; i < sizeof(mbufcache->ibo) / sizeof(void *); i++) {
+ for (int i = 0; i < sizeof(mbuflist->ibo) / sizeof(void *); i++) {
GPU_INDEXBUF_DISCARD_SAFE(ibos[i]);
}
}
-static void mesh_buffer_extraction_cache_clear(MeshBufferExtractionCache *extraction_cache)
+static void mesh_buffer_cache_clear(MeshBufferCache *mbc)
{
- MEM_SAFE_FREE(extraction_cache->loose_geom.verts);
- MEM_SAFE_FREE(extraction_cache->loose_geom.edges);
- extraction_cache->loose_geom.edge_len = 0;
- extraction_cache->loose_geom.vert_len = 0;
+ mesh_buffer_list_clear(&mbc->buff);
+
+ MEM_SAFE_FREE(mbc->loose_geom.verts);
+ MEM_SAFE_FREE(mbc->loose_geom.edges);
+ mbc->loose_geom.edge_len = 0;
+ mbc->loose_geom.vert_len = 0;
- MEM_SAFE_FREE(extraction_cache->poly_sorted.tri_first_index);
- MEM_SAFE_FREE(extraction_cache->poly_sorted.mat_tri_len);
- extraction_cache->poly_sorted.visible_tri_len = 0;
+ MEM_SAFE_FREE(mbc->poly_sorted.tri_first_index);
+ MEM_SAFE_FREE(mbc->poly_sorted.mat_tri_len);
+ mbc->poly_sorted.visible_tri_len = 0;
}
static void mesh_batch_cache_clear(Mesh *me)
@@ -868,18 +873,14 @@ static void mesh_batch_cache_clear(Mesh *me)
if (!cache) {
return;
}
- FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) {
- mesh_buffer_cache_clear(mbufcache);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ mesh_buffer_cache_clear(mbc);
}
- mesh_buffer_extraction_cache_clear(&cache->final_extraction_cache);
- mesh_buffer_extraction_cache_clear(&cache->cage_extraction_cache);
- mesh_buffer_extraction_cache_clear(&cache->uv_cage_extraction_cache);
-
for (int i = 0; i < cache->mat_len; i++) {
- GPU_INDEXBUF_DISCARD_SAFE(cache->final.tris_per_mat[i]);
+ GPU_INDEXBUF_DISCARD_SAFE(cache->tris_per_mat[i]);
}
- MEM_SAFE_FREE(cache->final.tris_per_mat);
+ MEM_SAFE_FREE(cache->tris_per_mat);
for (int i = 0; i < sizeof(cache->batch) / sizeof(void *); i++) {
GPUBatch **batch = (GPUBatch **)&cache->batch;
@@ -1083,8 +1084,8 @@ GPUVertBuf *DRW_mesh_batch_cache_pos_vertbuf_get(Mesh *me)
/* Request surface to trigger the vbo filling. Otherwise it may do nothing. */
mesh_batch_cache_request_surface_batches(cache);
- DRW_vbo_request(NULL, &cache->final.vbo.pos_nor);
- return cache->final.vbo.pos_nor;
+ DRW_vbo_request(NULL, &cache->final.buff.vbo.pos_nor);
+ return cache->final.buff.vbo.pos_nor;
}
/** \} */
@@ -1316,22 +1317,22 @@ static void drw_mesh_batch_cache_check_available(struct TaskGraph *task_graph, M
BLI_assert(!DRW_batch_requested(((GPUBatch **)&cache->batch)[i], 0));
}
for (int i = 0; i < MBC_VBO_LEN; i++) {
- BLI_assert(!DRW_vbo_requested(((GPUVertBuf **)&cache->final.vbo)[i]));
+ BLI_assert(!DRW_vbo_requested(((GPUVertBuf **)&cache->final.buff.vbo)[i]));
}
for (int i = 0; i < MBC_IBO_LEN; i++) {
- BLI_assert(!DRW_ibo_requested(((GPUIndexBuf **)&cache->final.ibo)[i]));
+ BLI_assert(!DRW_ibo_requested(((GPUIndexBuf **)&cache->final.buff.ibo)[i]));
}
for (int i = 0; i < MBC_VBO_LEN; i++) {
- BLI_assert(!DRW_vbo_requested(((GPUVertBuf **)&cache->cage.vbo)[i]));
+ BLI_assert(!DRW_vbo_requested(((GPUVertBuf **)&cache->cage.buff.vbo)[i]));
}
for (int i = 0; i < MBC_IBO_LEN; i++) {
- BLI_assert(!DRW_ibo_requested(((GPUIndexBuf **)&cache->cage.ibo)[i]));
+ BLI_assert(!DRW_ibo_requested(((GPUIndexBuf **)&cache->cage.buff.ibo)[i]));
}
for (int i = 0; i < MBC_VBO_LEN; i++) {
- BLI_assert(!DRW_vbo_requested(((GPUVertBuf **)&cache->uv_cage.vbo)[i]));
+ BLI_assert(!DRW_vbo_requested(((GPUVertBuf **)&cache->uv_cage.buff.vbo)[i]));
}
for (int i = 0; i < MBC_IBO_LEN; i++) {
- BLI_assert(!DRW_ibo_requested(((GPUIndexBuf **)&cache->uv_cage.ibo)[i]));
+ BLI_assert(!DRW_ibo_requested(((GPUIndexBuf **)&cache->uv_cage.buff.ibo)[i]));
}
}
#endif
@@ -1414,25 +1415,25 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
* material. */
bool cd_overlap = mesh_cd_layers_type_overlap(cache->cd_used, cache->cd_needed);
if (cd_overlap == false) {
- FOREACH_MESH_BUFFER_CACHE (cache, mbuffercache) {
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
if ((cache->cd_used.uv & cache->cd_needed.uv) != cache->cd_needed.uv) {
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.uv);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.uv);
cd_uv_update = true;
}
if ((cache->cd_used.tan & cache->cd_needed.tan) != cache->cd_needed.tan ||
cache->cd_used.tan_orco != cache->cd_needed.tan_orco) {
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.tan);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.tan);
}
if (cache->cd_used.orco != cache->cd_needed.orco) {
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.orco);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.orco);
}
if (cache->cd_used.sculpt_overlays != cache->cd_needed.sculpt_overlays) {
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.sculpt_data);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.sculpt_data);
}
if (((cache->cd_used.vcol & cache->cd_needed.vcol) != cache->cd_needed.vcol) ||
((cache->cd_used.sculpt_vcol & cache->cd_needed.sculpt_vcol) !=
cache->cd_needed.sculpt_vcol)) {
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.vcol);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.vcol);
}
}
/* We can't discard batches at this point as they have been
@@ -1454,14 +1455,14 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
const bool is_uvsyncsel = ts && (ts->uv_flag & UV_SYNC_SELECTION);
if (cd_uv_update || (cache->is_uvsyncsel != is_uvsyncsel)) {
cache->is_uvsyncsel = is_uvsyncsel;
- FOREACH_MESH_BUFFER_CACHE (cache, mbuffercache) {
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.edituv_data);
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.fdots_uv);
- GPU_VERTBUF_DISCARD_SAFE(mbuffercache->vbo.fdots_edituv_data);
- GPU_INDEXBUF_DISCARD_SAFE(mbuffercache->ibo.edituv_tris);
- GPU_INDEXBUF_DISCARD_SAFE(mbuffercache->ibo.edituv_lines);
- GPU_INDEXBUF_DISCARD_SAFE(mbuffercache->ibo.edituv_points);
- GPU_INDEXBUF_DISCARD_SAFE(mbuffercache->ibo.edituv_fdots);
+ FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.edituv_data);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_uv);
+ GPU_VERTBUF_DISCARD_SAFE(mbc->buff.vbo.fdots_edituv_data);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_tris);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_lines);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_points);
+ GPU_INDEXBUF_DISCARD_SAFE(mbc->buff.ibo.edituv_fdots);
}
/* We only clear the batches as they may already have been
* referenced. */
@@ -1502,173 +1503,174 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
const bool do_uvcage = is_editmode && !me->edit_mesh->mesh_eval_final->runtime.is_original;
- MeshBufferCache *mbufcache = &cache->final;
+ MeshBufferList *mbuflist = &cache->final.buff;
/* Initialize batches and request VBO's & IBO's. */
- MDEPS_ASSERT(batch.surface, ibo.tris, vbo.lnor, vbo.pos_nor, vbo.uv, vbo.vcol);
+ MDEPS_ASSERT(surface, ibo.tris, vbo.lnor, vbo.pos_nor, vbo.uv, vbo.vcol);
if (DRW_batch_requested(cache->batch.surface, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.surface, &mbufcache->ibo.tris);
+ DRW_ibo_request(cache->batch.surface, &mbuflist->ibo.tris);
/* Order matters. First ones override latest VBO's attributes. */
- DRW_vbo_request(cache->batch.surface, &mbufcache->vbo.lnor);
- DRW_vbo_request(cache->batch.surface, &mbufcache->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.surface, &mbuflist->vbo.lnor);
+ DRW_vbo_request(cache->batch.surface, &mbuflist->vbo.pos_nor);
if (cache->cd_used.uv != 0) {
- DRW_vbo_request(cache->batch.surface, &mbufcache->vbo.uv);
+ DRW_vbo_request(cache->batch.surface, &mbuflist->vbo.uv);
}
if (cache->cd_used.vcol != 0 || cache->cd_used.sculpt_vcol != 0) {
- DRW_vbo_request(cache->batch.surface, &mbufcache->vbo.vcol);
+ DRW_vbo_request(cache->batch.surface, &mbuflist->vbo.vcol);
}
}
- MDEPS_ASSERT(batch.all_verts, vbo.pos_nor);
+ MDEPS_ASSERT(all_verts, vbo.pos_nor);
if (DRW_batch_requested(cache->batch.all_verts, GPU_PRIM_POINTS)) {
- DRW_vbo_request(cache->batch.all_verts, &mbufcache->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.all_verts, &mbuflist->vbo.pos_nor);
}
- MDEPS_ASSERT(batch.sculpt_overlays, ibo.tris, vbo.pos_nor, vbo.sculpt_data);
+ MDEPS_ASSERT(sculpt_overlays, ibo.tris, vbo.pos_nor, vbo.sculpt_data);
if (DRW_batch_requested(cache->batch.sculpt_overlays, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.sculpt_overlays, &mbufcache->ibo.tris);
- DRW_vbo_request(cache->batch.sculpt_overlays, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.sculpt_overlays, &mbufcache->vbo.sculpt_data);
+ DRW_ibo_request(cache->batch.sculpt_overlays, &mbuflist->ibo.tris);
+ DRW_vbo_request(cache->batch.sculpt_overlays, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.sculpt_overlays, &mbuflist->vbo.sculpt_data);
}
- MDEPS_ASSERT(batch.all_edges, ibo.lines, vbo.pos_nor);
+ MDEPS_ASSERT(all_edges, ibo.lines, vbo.pos_nor);
if (DRW_batch_requested(cache->batch.all_edges, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.all_edges, &mbufcache->ibo.lines);
- DRW_vbo_request(cache->batch.all_edges, &mbufcache->vbo.pos_nor);
+ DRW_ibo_request(cache->batch.all_edges, &mbuflist->ibo.lines);
+ DRW_vbo_request(cache->batch.all_edges, &mbuflist->vbo.pos_nor);
}
- MDEPS_ASSERT(batch.loose_edges, ibo.lines_loose, vbo.pos_nor);
+ MDEPS_ASSERT(loose_edges, ibo.lines_loose, vbo.pos_nor);
if (DRW_batch_requested(cache->batch.loose_edges, GPU_PRIM_LINES)) {
- DRW_ibo_request(NULL, &mbufcache->ibo.lines);
- DRW_ibo_request(cache->batch.loose_edges, &mbufcache->ibo.lines_loose);
- DRW_vbo_request(cache->batch.loose_edges, &mbufcache->vbo.pos_nor);
+ DRW_ibo_request(NULL, &mbuflist->ibo.lines);
+ DRW_ibo_request(cache->batch.loose_edges, &mbuflist->ibo.lines_loose);
+ DRW_vbo_request(cache->batch.loose_edges, &mbuflist->vbo.pos_nor);
}
- MDEPS_ASSERT(batch.edge_detection, ibo.lines_adjacency, vbo.pos_nor);
+ MDEPS_ASSERT(edge_detection, ibo.lines_adjacency, vbo.pos_nor);
if (DRW_batch_requested(cache->batch.edge_detection, GPU_PRIM_LINES_ADJ)) {
- DRW_ibo_request(cache->batch.edge_detection, &mbufcache->ibo.lines_adjacency);
- DRW_vbo_request(cache->batch.edge_detection, &mbufcache->vbo.pos_nor);
+ DRW_ibo_request(cache->batch.edge_detection, &mbuflist->ibo.lines_adjacency);
+ DRW_vbo_request(cache->batch.edge_detection, &mbuflist->vbo.pos_nor);
}
- MDEPS_ASSERT(batch.surface_weights, ibo.tris, vbo.pos_nor, vbo.weights);
+ MDEPS_ASSERT(surface_weights, ibo.tris, vbo.pos_nor, vbo.weights);
if (DRW_batch_requested(cache->batch.surface_weights, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.surface_weights, &mbufcache->ibo.tris);
- DRW_vbo_request(cache->batch.surface_weights, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.surface_weights, &mbufcache->vbo.weights);
+ DRW_ibo_request(cache->batch.surface_weights, &mbuflist->ibo.tris);
+ DRW_vbo_request(cache->batch.surface_weights, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.surface_weights, &mbuflist->vbo.weights);
}
- MDEPS_ASSERT(batch.wire_loops, ibo.lines_paint_mask, vbo.lnor, vbo.pos_nor);
+ MDEPS_ASSERT(wire_loops, ibo.lines_paint_mask, vbo.lnor, vbo.pos_nor);
if (DRW_batch_requested(cache->batch.wire_loops, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.wire_loops, &mbufcache->ibo.lines_paint_mask);
+ DRW_ibo_request(cache->batch.wire_loops, &mbuflist->ibo.lines_paint_mask);
/* Order matters. First ones override latest VBO's attributes. */
- DRW_vbo_request(cache->batch.wire_loops, &mbufcache->vbo.lnor);
- DRW_vbo_request(cache->batch.wire_loops, &mbufcache->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.wire_loops, &mbuflist->vbo.lnor);
+ DRW_vbo_request(cache->batch.wire_loops, &mbuflist->vbo.pos_nor);
}
- MDEPS_ASSERT(batch.wire_edges, ibo.lines, vbo.pos_nor, vbo.edge_fac);
+ MDEPS_ASSERT(wire_edges, ibo.lines, vbo.pos_nor, vbo.edge_fac);
if (DRW_batch_requested(cache->batch.wire_edges, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.wire_edges, &mbufcache->ibo.lines);
- DRW_vbo_request(cache->batch.wire_edges, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.wire_edges, &mbufcache->vbo.edge_fac);
+ DRW_ibo_request(cache->batch.wire_edges, &mbuflist->ibo.lines);
+ DRW_vbo_request(cache->batch.wire_edges, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.wire_edges, &mbuflist->vbo.edge_fac);
}
- MDEPS_ASSERT(batch.wire_loops_uvs, ibo.edituv_lines, vbo.uv);
+ MDEPS_ASSERT(wire_loops_uvs, ibo.edituv_lines, vbo.uv);
if (DRW_batch_requested(cache->batch.wire_loops_uvs, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.wire_loops_uvs, &mbufcache->ibo.edituv_lines);
+ DRW_ibo_request(cache->batch.wire_loops_uvs, &mbuflist->ibo.edituv_lines);
/* For paint overlay. Active layer should have been queried. */
if (cache->cd_used.uv != 0) {
- DRW_vbo_request(cache->batch.wire_loops_uvs, &mbufcache->vbo.uv);
+ DRW_vbo_request(cache->batch.wire_loops_uvs, &mbuflist->vbo.uv);
}
}
- MDEPS_ASSERT(batch.edit_mesh_analysis, ibo.tris, vbo.pos_nor, vbo.mesh_analysis);
+ MDEPS_ASSERT(edit_mesh_analysis, ibo.tris, vbo.pos_nor, vbo.mesh_analysis);
if (DRW_batch_requested(cache->batch.edit_mesh_analysis, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.edit_mesh_analysis, &mbufcache->ibo.tris);
- DRW_vbo_request(cache->batch.edit_mesh_analysis, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_mesh_analysis, &mbufcache->vbo.mesh_analysis);
+ DRW_ibo_request(cache->batch.edit_mesh_analysis, &mbuflist->ibo.tris);
+ DRW_vbo_request(cache->batch.edit_mesh_analysis, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_mesh_analysis, &mbuflist->vbo.mesh_analysis);
}
/* Per Material */
- MDEPS_ASSERT(
- surface_per_mat, tris_per_mat, vbo.lnor, vbo.pos_nor, vbo.uv, vbo.tan, vbo.vcol, vbo.orco);
+ MDEPS_ASSERT_FLAG(
+ SURFACE_PER_MAT_FLAG, vbo.lnor, vbo.pos_nor, vbo.uv, vbo.tan, vbo.vcol, vbo.orco);
+ MDEPS_ASSERT_INDEX(TRIS_PER_MAT_INDEX, SURFACE_PER_MAT_FLAG);
for (int i = 0; i < cache->mat_len; i++) {
if (DRW_batch_requested(cache->surface_per_mat[i], GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->surface_per_mat[i], &mbufcache->tris_per_mat[i]);
+ DRW_ibo_request(cache->surface_per_mat[i], &cache->tris_per_mat[i]);
/* Order matters. First ones override latest VBO's attributes. */
- DRW_vbo_request(cache->surface_per_mat[i], &mbufcache->vbo.lnor);
- DRW_vbo_request(cache->surface_per_mat[i], &mbufcache->vbo.pos_nor);
+ DRW_vbo_request(cache->surface_per_mat[i], &mbuflist->vbo.lnor);
+ DRW_vbo_request(cache->surface_per_mat[i], &mbuflist->vbo.pos_nor);
if (cache->cd_used.uv != 0) {
- DRW_vbo_request(cache->surface_per_mat[i], &mbufcache->vbo.uv);
+ DRW_vbo_request(cache->surface_per_mat[i], &mbuflist->vbo.uv);
}
if ((cache->cd_used.tan != 0) || (cache->cd_used.tan_orco != 0)) {
- DRW_vbo_request(cache->surface_per_mat[i], &mbufcache->vbo.tan);
+ DRW_vbo_request(cache->surface_per_mat[i], &mbuflist->vbo.tan);
}
if (cache->cd_used.vcol != 0 || cache->cd_used.sculpt_vcol != 0) {
- DRW_vbo_request(cache->surface_per_mat[i], &mbufcache->vbo.vcol);
+ DRW_vbo_request(cache->surface_per_mat[i], &mbuflist->vbo.vcol);
}
if (cache->cd_used.orco != 0) {
- DRW_vbo_request(cache->surface_per_mat[i], &mbufcache->vbo.orco);
+ DRW_vbo_request(cache->surface_per_mat[i], &mbuflist->vbo.orco);
}
}
}
- mbufcache = (do_cage) ? &cache->cage : &cache->final;
+ mbuflist = (do_cage) ? &cache->cage.buff : &cache->final.buff;
/* Edit Mesh */
- MDEPS_ASSERT(batch.edit_triangles, ibo.tris, vbo.pos_nor, vbo.edit_data);
+ MDEPS_ASSERT(edit_triangles, ibo.tris, vbo.pos_nor, vbo.edit_data);
if (DRW_batch_requested(cache->batch.edit_triangles, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.edit_triangles, &mbufcache->ibo.tris);
- DRW_vbo_request(cache->batch.edit_triangles, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_triangles, &mbufcache->vbo.edit_data);
+ DRW_ibo_request(cache->batch.edit_triangles, &mbuflist->ibo.tris);
+ DRW_vbo_request(cache->batch.edit_triangles, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_triangles, &mbuflist->vbo.edit_data);
}
- MDEPS_ASSERT(batch.edit_vertices, ibo.points, vbo.pos_nor, vbo.edit_data);
+ MDEPS_ASSERT(edit_vertices, ibo.points, vbo.pos_nor, vbo.edit_data);
if (DRW_batch_requested(cache->batch.edit_vertices, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edit_vertices, &mbufcache->ibo.points);
- DRW_vbo_request(cache->batch.edit_vertices, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_vertices, &mbufcache->vbo.edit_data);
+ DRW_ibo_request(cache->batch.edit_vertices, &mbuflist->ibo.points);
+ DRW_vbo_request(cache->batch.edit_vertices, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_vertices, &mbuflist->vbo.edit_data);
}
- MDEPS_ASSERT(batch.edit_edges, ibo.lines, vbo.pos_nor, vbo.edit_data);
+ MDEPS_ASSERT(edit_edges, ibo.lines, vbo.pos_nor, vbo.edit_data);
if (DRW_batch_requested(cache->batch.edit_edges, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.edit_edges, &mbufcache->ibo.lines);
- DRW_vbo_request(cache->batch.edit_edges, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_edges, &mbufcache->vbo.edit_data);
+ DRW_ibo_request(cache->batch.edit_edges, &mbuflist->ibo.lines);
+ DRW_vbo_request(cache->batch.edit_edges, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_edges, &mbuflist->vbo.edit_data);
}
- MDEPS_ASSERT(batch.edit_vnor, ibo.points, vbo.pos_nor);
+ MDEPS_ASSERT(edit_vnor, ibo.points, vbo.pos_nor);
if (DRW_batch_requested(cache->batch.edit_vnor, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edit_vnor, &mbufcache->ibo.points);
- DRW_vbo_request(cache->batch.edit_vnor, &mbufcache->vbo.pos_nor);
+ DRW_ibo_request(cache->batch.edit_vnor, &mbuflist->ibo.points);
+ DRW_vbo_request(cache->batch.edit_vnor, &mbuflist->vbo.pos_nor);
}
- MDEPS_ASSERT(batch.edit_lnor, ibo.tris, vbo.pos_nor, vbo.lnor);
+ MDEPS_ASSERT(edit_lnor, ibo.tris, vbo.pos_nor, vbo.lnor);
if (DRW_batch_requested(cache->batch.edit_lnor, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edit_lnor, &mbufcache->ibo.tris);
- DRW_vbo_request(cache->batch.edit_lnor, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_lnor, &mbufcache->vbo.lnor);
+ DRW_ibo_request(cache->batch.edit_lnor, &mbuflist->ibo.tris);
+ DRW_vbo_request(cache->batch.edit_lnor, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_lnor, &mbuflist->vbo.lnor);
}
- MDEPS_ASSERT(batch.edit_fdots, ibo.fdots, vbo.fdots_pos, vbo.fdots_nor);
+ MDEPS_ASSERT(edit_fdots, ibo.fdots, vbo.fdots_pos, vbo.fdots_nor);
if (DRW_batch_requested(cache->batch.edit_fdots, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edit_fdots, &mbufcache->ibo.fdots);
- DRW_vbo_request(cache->batch.edit_fdots, &mbufcache->vbo.fdots_pos);
- DRW_vbo_request(cache->batch.edit_fdots, &mbufcache->vbo.fdots_nor);
+ DRW_ibo_request(cache->batch.edit_fdots, &mbuflist->ibo.fdots);
+ DRW_vbo_request(cache->batch.edit_fdots, &mbuflist->vbo.fdots_pos);
+ DRW_vbo_request(cache->batch.edit_fdots, &mbuflist->vbo.fdots_nor);
}
- MDEPS_ASSERT(batch.edit_skin_roots, vbo.skin_roots);
+ MDEPS_ASSERT(edit_skin_roots, vbo.skin_roots);
if (DRW_batch_requested(cache->batch.edit_skin_roots, GPU_PRIM_POINTS)) {
- DRW_vbo_request(cache->batch.edit_skin_roots, &mbufcache->vbo.skin_roots);
+ DRW_vbo_request(cache->batch.edit_skin_roots, &mbuflist->vbo.skin_roots);
}
/* Selection */
- MDEPS_ASSERT(batch.edit_selection_verts, ibo.points, vbo.pos_nor, vbo.vert_idx);
+ MDEPS_ASSERT(edit_selection_verts, ibo.points, vbo.pos_nor, vbo.vert_idx);
if (DRW_batch_requested(cache->batch.edit_selection_verts, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edit_selection_verts, &mbufcache->ibo.points);
- DRW_vbo_request(cache->batch.edit_selection_verts, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_selection_verts, &mbufcache->vbo.vert_idx);
+ DRW_ibo_request(cache->batch.edit_selection_verts, &mbuflist->ibo.points);
+ DRW_vbo_request(cache->batch.edit_selection_verts, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_selection_verts, &mbuflist->vbo.vert_idx);
}
- MDEPS_ASSERT(batch.edit_selection_edges, ibo.lines, vbo.pos_nor, vbo.edge_idx);
+ MDEPS_ASSERT(edit_selection_edges, ibo.lines, vbo.pos_nor, vbo.edge_idx);
if (DRW_batch_requested(cache->batch.edit_selection_edges, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.edit_selection_edges, &mbufcache->ibo.lines);
- DRW_vbo_request(cache->batch.edit_selection_edges, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_selection_edges, &mbufcache->vbo.edge_idx);
+ DRW_ibo_request(cache->batch.edit_selection_edges, &mbuflist->ibo.lines);
+ DRW_vbo_request(cache->batch.edit_selection_edges, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_selection_edges, &mbuflist->vbo.edge_idx);
}
- MDEPS_ASSERT(batch.edit_selection_faces, ibo.tris, vbo.pos_nor, vbo.poly_idx);
+ MDEPS_ASSERT(edit_selection_faces, ibo.tris, vbo.pos_nor, vbo.poly_idx);
if (DRW_batch_requested(cache->batch.edit_selection_faces, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.edit_selection_faces, &mbufcache->ibo.tris);
- DRW_vbo_request(cache->batch.edit_selection_faces, &mbufcache->vbo.pos_nor);
- DRW_vbo_request(cache->batch.edit_selection_faces, &mbufcache->vbo.poly_idx);
+ DRW_ibo_request(cache->batch.edit_selection_faces, &mbuflist->ibo.tris);
+ DRW_vbo_request(cache->batch.edit_selection_faces, &mbuflist->vbo.pos_nor);
+ DRW_vbo_request(cache->batch.edit_selection_faces, &mbuflist->vbo.poly_idx);
}
- MDEPS_ASSERT(batch.edit_selection_fdots, ibo.fdots, vbo.fdots_pos, vbo.fdot_idx);
+ MDEPS_ASSERT(edit_selection_fdots, ibo.fdots, vbo.fdots_pos, vbo.fdot_idx);
if (DRW_batch_requested(cache->batch.edit_selection_fdots, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edit_selection_fdots, &mbufcache->ibo.fdots);
- DRW_vbo_request(cache->batch.edit_selection_fdots, &mbufcache->vbo.fdots_pos);
- DRW_vbo_request(cache->batch.edit_selection_fdots, &mbufcache->vbo.fdot_idx);
+ DRW_ibo_request(cache->batch.edit_selection_fdots, &mbuflist->ibo.fdots);
+ DRW_vbo_request(cache->batch.edit_selection_fdots, &mbuflist->vbo.fdots_pos);
+ DRW_vbo_request(cache->batch.edit_selection_fdots, &mbuflist->vbo.fdot_idx);
}
/**
@@ -1676,54 +1678,54 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
* but the selection code for UVs needs to support it first. So for now, only
* display the cage in all cases.
*/
- mbufcache = (do_uvcage) ? &cache->uv_cage : &cache->final;
+ mbuflist = (do_uvcage) ? &cache->uv_cage.buff : &cache->final.buff;
/* Edit UV */
- MDEPS_ASSERT(batch.edituv_faces, ibo.edituv_tris, vbo.uv, vbo.edituv_data);
+ MDEPS_ASSERT(edituv_faces, ibo.edituv_tris, vbo.uv, vbo.edituv_data);
if (DRW_batch_requested(cache->batch.edituv_faces, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.edituv_faces, &mbufcache->ibo.edituv_tris);
- DRW_vbo_request(cache->batch.edituv_faces, &mbufcache->vbo.uv);
- DRW_vbo_request(cache->batch.edituv_faces, &mbufcache->vbo.edituv_data);
+ DRW_ibo_request(cache->batch.edituv_faces, &mbuflist->ibo.edituv_tris);
+ DRW_vbo_request(cache->batch.edituv_faces, &mbuflist->vbo.uv);
+ DRW_vbo_request(cache->batch.edituv_faces, &mbuflist->vbo.edituv_data);
}
- MDEPS_ASSERT(batch.edituv_faces_stretch_area,
+ MDEPS_ASSERT(edituv_faces_stretch_area,
ibo.edituv_tris,
vbo.uv,
vbo.edituv_data,
vbo.edituv_stretch_area);
if (DRW_batch_requested(cache->batch.edituv_faces_stretch_area, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->ibo.edituv_tris);
- DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->vbo.uv);
- DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->vbo.edituv_data);
- DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->vbo.edituv_stretch_area);
+ DRW_ibo_request(cache->batch.edituv_faces_stretch_area, &mbuflist->ibo.edituv_tris);
+ DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbuflist->vbo.uv);
+ DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbuflist->vbo.edituv_data);
+ DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbuflist->vbo.edituv_stretch_area);
}
- MDEPS_ASSERT(batch.edituv_faces_stretch_angle,
+ MDEPS_ASSERT(edituv_faces_stretch_angle,
ibo.edituv_tris,
vbo.uv,
vbo.edituv_data,
vbo.edituv_stretch_angle);
if (DRW_batch_requested(cache->batch.edituv_faces_stretch_angle, GPU_PRIM_TRIS)) {
- DRW_ibo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->ibo.edituv_tris);
- DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->vbo.uv);
- DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->vbo.edituv_data);
- DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->vbo.edituv_stretch_angle);
+ DRW_ibo_request(cache->batch.edituv_faces_stretch_angle, &mbuflist->ibo.edituv_tris);
+ DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbuflist->vbo.uv);
+ DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbuflist->vbo.edituv_data);
+ DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbuflist->vbo.edituv_stretch_angle);
}
- MDEPS_ASSERT(batch.edituv_edges, ibo.edituv_lines, vbo.uv, vbo.edituv_data);
+ MDEPS_ASSERT(edituv_edges, ibo.edituv_lines, vbo.uv, vbo.edituv_data);
if (DRW_batch_requested(cache->batch.edituv_edges, GPU_PRIM_LINES)) {
- DRW_ibo_request(cache->batch.edituv_edges, &mbufcache->ibo.edituv_lines);
- DRW_vbo_request(cache->batch.edituv_edges, &mbufcache->vbo.uv);
- DRW_vbo_request(cache->batch.edituv_edges, &mbufcache->vbo.edituv_data);
+ DRW_ibo_request(cache->batch.edituv_edges, &mbuflist->ibo.edituv_lines);
+ DRW_vbo_request(cache->batch.edituv_edges, &mbuflist->vbo.uv);
+ DRW_vbo_request(cache->batch.edituv_edges, &mbuflist->vbo.edituv_data);
}
- MDEPS_ASSERT(batch.edituv_verts, ibo.edituv_points, vbo.uv, vbo.edituv_data);
+ MDEPS_ASSERT(edituv_verts, ibo.edituv_points, vbo.uv, vbo.edituv_data);
if (DRW_batch_requested(cache->batch.edituv_verts, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edituv_verts, &mbufcache->ibo.edituv_points);
- DRW_vbo_request(cache->batch.edituv_verts, &mbufcache->vbo.uv);
- DRW_vbo_request(cache->batch.edituv_verts, &mbufcache->vbo.edituv_data);
+ DRW_ibo_request(cache->batch.edituv_verts, &mbuflist->ibo.edituv_points);
+ DRW_vbo_request(cache->batch.edituv_verts, &mbuflist->vbo.uv);
+ DRW_vbo_request(cache->batch.edituv_verts, &mbuflist->vbo.edituv_data);
}
- MDEPS_ASSERT(batch.edituv_fdots, ibo.edituv_fdots, vbo.fdots_uv, vbo.fdots_edituv_data);
+ MDEPS_ASSERT(edituv_fdots, ibo.edituv_fdots, vbo.fdots_uv, vbo.fdots_edituv_data);
if (DRW_batch_requested(cache->batch.edituv_fdots, GPU_PRIM_POINTS)) {
- DRW_ibo_request(cache->batch.edituv_fdots, &mbufcache->ibo.edituv_fdots);
- DRW_vbo_request(cache->batch.edituv_fdots, &mbufcache->vbo.fdots_uv);
- DRW_vbo_request(cache->batch.edituv_fdots, &mbufcache->vbo.fdots_edituv_data);
+ DRW_ibo_request(cache->batch.edituv_fdots, &mbuflist->ibo.edituv_fdots);
+ DRW_vbo_request(cache->batch.edituv_fdots, &mbuflist->vbo.fdots_uv);
+ DRW_vbo_request(cache->batch.edituv_fdots, &mbuflist->vbo.fdots_edituv_data);
}
MDEPS_ASSERT_MAP(vbo.lnor);
@@ -1762,7 +1764,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
MDEPS_ASSERT_MAP(ibo.edituv_points);
MDEPS_ASSERT_MAP(ibo.edituv_fdots);
- MDEPS_ASSERT_MAP(tris_per_mat);
+ MDEPS_ASSERT_MAP_INDEX(TRIS_PER_MAT_INDEX);
/* Meh loose Scene const correctness here. */
const bool use_subsurf_fdots = scene ? BKE_modifiers_uses_subsurf_facedots(scene, ob) : false;
@@ -1771,7 +1773,6 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
mesh_buffer_cache_create_requested(task_graph,
cache,
&cache->uv_cage,
- &cache->uv_cage_extraction_cache,
me,
is_editmode,
is_paint_mode,
@@ -1789,7 +1790,6 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
mesh_buffer_cache_create_requested(task_graph,
cache,
&cache->cage,
- &cache->cage_extraction_cache,
me,
is_editmode,
is_paint_mode,
@@ -1806,7 +1806,6 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph,
mesh_buffer_cache_create_requested(task_graph,
cache,
&cache->final,
- &cache->final_extraction_cache,
me,
is_editmode,
is_paint_mode,
diff --git a/source/blender/draw/intern/draw_manager_texture.c b/source/blender/draw/intern/draw_manager_texture.c
index 73afdd6e1e3..99e8ba968a2 100644
--- a/source/blender/draw/intern/draw_manager_texture.c
+++ b/source/blender/draw/intern/draw_manager_texture.c
@@ -83,8 +83,8 @@ GPUTexture *DRW_texture_create_1d(int w,
DRWTextureFlag flags,
const float *fpixels)
{
- int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
- GPUTexture *tex = GPU_texture_create_1d(__func__, w, mips, format, fpixels);
+ int mip_len = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
+ GPUTexture *tex = GPU_texture_create_1d(__func__, w, mip_len, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
@@ -93,8 +93,8 @@ GPUTexture *DRW_texture_create_1d(int w,
GPUTexture *DRW_texture_create_2d(
int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
- int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
- GPUTexture *tex = GPU_texture_create_2d(__func__, w, h, mips, format, fpixels);
+ int mip_len = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
+ GPUTexture *tex = GPU_texture_create_2d(__func__, w, h, mip_len, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
@@ -103,8 +103,8 @@ GPUTexture *DRW_texture_create_2d(
GPUTexture *DRW_texture_create_2d_array(
int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
- int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
- GPUTexture *tex = GPU_texture_create_2d_array(__func__, w, h, d, mips, format, fpixels);
+ int mip_len = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
+ GPUTexture *tex = GPU_texture_create_2d_array(__func__, w, h, d, mip_len, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
@@ -113,9 +113,9 @@ GPUTexture *DRW_texture_create_2d_array(
GPUTexture *DRW_texture_create_3d(
int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
- int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
+ int mip_len = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_3d(
- __func__, w, h, d, mips, format, GPU_DATA_FLOAT, fpixels);
+ __func__, w, h, d, mip_len, format, GPU_DATA_FLOAT, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
@@ -126,8 +126,8 @@ GPUTexture *DRW_texture_create_cube(int w,
DRWTextureFlag flags,
const float *fpixels)
{
- int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
- GPUTexture *tex = GPU_texture_create_cube(__func__, w, mips, format, fpixels);
+ int mip_len = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
+ GPUTexture *tex = GPU_texture_create_cube(__func__, w, mip_len, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
@@ -135,8 +135,8 @@ GPUTexture *DRW_texture_create_cube(int w,
GPUTexture *DRW_texture_create_cube_array(
int w, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
- int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
- GPUTexture *tex = GPU_texture_create_cube_array(__func__, w, d, mips, format, fpixels);
+ int mip_len = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
+ GPUTexture *tex = GPU_texture_create_cube_array(__func__, w, d, mip_len, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.c b/source/blender/draw/intern/mesh_extractors/extract_mesh.c
index 53827dcc7d9..44de07c8594 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh.c
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.c
@@ -33,11 +33,11 @@
#include "draw_cache_impl.h"
-void *mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferCache *mbc)
+void *mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferList *mbuflist)
{
/* NOTE: POINTER_OFFSET on windows platforms casts internally to `void *`, but on GCC/CLANG to
- * `MeshBufferCache *`. What shows a different usage versus intent. */
- void **buffer_ptr = (void **)POINTER_OFFSET(mbc, extractor->mesh_buffer_offset);
+ * `MeshBufferList *`. What shows a different usage versus intent. */
+ void **buffer_ptr = (void **)POINTER_OFFSET(mbuflist, extractor->mesh_buffer_offset);
void *buffer = *buffer_ptr;
BLI_assert(buffer);
return buffer;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.h b/source/blender/draw/intern/mesh_extractors/extract_mesh.h
index f24ccf1a028..d9f397fd8b8 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh.h
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.h
@@ -232,7 +232,7 @@ typedef struct MeshExtract {
/** Used to know if the element callbacks are thread-safe and can be parallelized. */
bool use_threading;
/**
- * Offset in bytes of the buffer inside a MeshBufferCache instance. Points to a vertex or index
+ * Offset in bytes of the buffer inside a MeshBufferList instance. Points to a vertex or index
* buffer.
*/
size_t mesh_buffer_offset;
@@ -252,11 +252,11 @@ MeshRenderData *mesh_render_data_create(Mesh *me,
void mesh_render_data_free(MeshRenderData *mr);
void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_flag);
void mesh_render_data_update_loose_geom(MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
const eMRIterType iter_type,
const eMRDataType data_flag);
void mesh_render_data_update_polys_sorted(MeshRenderData *mr,
- MeshBufferExtractionCache *cache,
+ MeshBufferCache *cache,
const eMRDataType data_flag);
void mesh_render_data_update_looptris(MeshRenderData *mr,
const eMRIterType iter_type,
@@ -270,7 +270,7 @@ typedef struct EditLoopData {
uchar bweight;
} EditLoopData;
-void *mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferCache *mbc);
+void *mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferList *mbuflist);
eMRIterType mesh_extract_iter_type(const MeshExtract *ext);
const MeshExtract *mesh_extract_override_get(const MeshExtract *extractor,
const bool do_hq_normals,
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
index 5bd5f7adaa8..d06fb91411e 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
@@ -104,7 +104,7 @@ constexpr MeshExtract create_extractor_edituv_tris()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_tris);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.edituv_tris);
return extractor;
}
@@ -194,7 +194,7 @@ constexpr MeshExtract create_extractor_edituv_lines()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_lines);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.edituv_lines);
return extractor;
}
@@ -278,7 +278,7 @@ constexpr MeshExtract create_extractor_edituv_points()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_points);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.edituv_points);
return extractor;
}
@@ -374,7 +374,7 @@ constexpr MeshExtract create_extractor_edituv_fdots()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_fdots);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.edituv_fdots);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc
index 0f41702a22c..ea58e1aeed8 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc
@@ -105,7 +105,7 @@ constexpr MeshExtract create_extractor_fdots()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.fdots);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.fdots);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
index 0096da9e56f..54f5611106f 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
@@ -168,7 +168,7 @@ constexpr MeshExtract create_extractor_lines()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.lines);
return extractor;
}
@@ -180,12 +180,12 @@ constexpr MeshExtract create_extractor_lines()
static void extract_lines_loose_subbuffer(const MeshRenderData *mr, struct MeshBatchCache *cache)
{
- BLI_assert(cache->final.ibo.lines);
+ BLI_assert(cache->final.buff.ibo.lines);
/* Multiply by 2 because these are edges indices. */
const int start = mr->edge_len * 2;
const int len = mr->edge_loose_len * 2;
GPU_indexbuf_create_subrange_in_place(
- cache->final.ibo.lines_loose, cache->final.ibo.lines, start, len);
+ cache->final.buff.ibo.lines_loose, cache->final.buff.ibo.lines, start, len);
cache->no_loose_wire = (len == 0);
}
@@ -213,7 +213,7 @@ constexpr MeshExtract create_extractor_lines_with_lines_loose()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.lines);
return extractor;
}
@@ -228,7 +228,7 @@ static void extract_lines_loose_only_init(const MeshRenderData *mr,
void *buf,
void *UNUSED(tls_data))
{
- BLI_assert(buf == cache->final.ibo.lines_loose);
+ BLI_assert(buf == cache->final.buff.ibo.lines_loose);
UNUSED_VARS_NDEBUG(buf);
extract_lines_loose_subbuffer(mr, cache);
}
@@ -240,7 +240,7 @@ constexpr MeshExtract create_extractor_lines_loose_only()
extractor.data_type = MR_DATA_LOOSE_GEOM;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_loose);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.lines_loose);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc
index 7a37cf50264..522afcd44a1 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc
@@ -185,7 +185,7 @@ constexpr MeshExtract create_extractor_lines_adjacency()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_LineAdjacency_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_adjacency);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.lines_adjacency);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
index 5def7edb75a..494a43e97d1 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
@@ -114,7 +114,7 @@ constexpr MeshExtract create_extractor_lines_paint_mask()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_LinePaintMask_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_paint_mask);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.lines_paint_mask);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
index cc1a19b8d26..b801ba04162 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
@@ -169,7 +169,7 @@ constexpr MeshExtract create_extractor_points()
extractor.use_threading = true;
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(GPUIndexBufBuilder);
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.points);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.points);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
index e346177af52..54e733d3d86 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
@@ -105,20 +105,19 @@ static void extract_tris_finish(const MeshRenderData *mr,
/* Create ibo sub-ranges. Always do this to avoid error when the standard surface batch
* is created before the surfaces-per-material. */
- if (mr->use_final_mesh && cache->final.tris_per_mat) {
- MeshBufferCache *mbc_final = &cache->final;
+ if (mr->use_final_mesh && cache->tris_per_mat) {
int mat_start = 0;
for (int i = 0; i < mr->mat_len; i++) {
/* These IBOs have not been queried yet but we create them just in case they are needed
* later since they are not tracked by mesh_buffer_cache_create_requested(). */
- if (mbc_final->tris_per_mat[i] == nullptr) {
- mbc_final->tris_per_mat[i] = GPU_indexbuf_calloc();
+ if (cache->tris_per_mat[i] == nullptr) {
+ cache->tris_per_mat[i] = GPU_indexbuf_calloc();
}
const int mat_tri_len = mr->poly_sorted.mat_tri_len[i];
/* Multiply by 3 because these are triangle indices. */
const int start = mat_start * 3;
const int len = mat_tri_len * 3;
- GPU_indexbuf_create_subrange_in_place(mbc_final->tris_per_mat[i], ibo, start, len);
+ GPU_indexbuf_create_subrange_in_place(cache->tris_per_mat[i], ibo, start, len);
mat_start += mat_tri_len;
}
}
@@ -135,7 +134,7 @@ constexpr MeshExtract create_extractor_tris()
extractor.data_type = MR_DATA_LOOPTRI | MR_DATA_POLYS_SORTED;
extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.tris);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.tris);
return extractor;
}
@@ -197,17 +196,16 @@ static void extract_tris_single_mat_finish(const MeshRenderData *mr,
/* Create ibo sub-ranges. Always do this to avoid error when the standard surface batch
* is created before the surfaces-per-material. */
- if (mr->use_final_mesh && cache->final.tris_per_mat) {
- MeshBufferCache *mbc = &cache->final;
+ if (mr->use_final_mesh && cache->tris_per_mat) {
for (int i = 0; i < mr->mat_len; i++) {
/* These IBOs have not been queried yet but we create them just in case they are needed
* later since they are not tracked by mesh_buffer_cache_create_requested(). */
- if (mbc->tris_per_mat[i] == nullptr) {
- mbc->tris_per_mat[i] = GPU_indexbuf_calloc();
+ if (cache->tris_per_mat[i] == nullptr) {
+ cache->tris_per_mat[i] = GPU_indexbuf_calloc();
}
/* Multiply by 3 because these are triangle indices. */
const int len = mr->tri_len * 3;
- GPU_indexbuf_create_subrange_in_place(mbc->tris_per_mat[i], ibo, 0, len);
+ GPU_indexbuf_create_subrange_in_place(cache->tris_per_mat[i], ibo, 0, len);
}
}
}
@@ -223,7 +221,7 @@ constexpr MeshExtract create_extractor_tris_single_mat()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.tris);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, ibo.tris);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc
index 302616d4da9..2e2444a8e3d 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc
@@ -228,7 +228,7 @@ constexpr MeshExtract create_extractor_edge_fac()
extractor.data_type = MR_DATA_POLY_NOR;
extractor.data_size = sizeof(MeshExtract_EdgeFac_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.edge_fac);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.edge_fac);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
index a7efb9c8a1b..5232346e51e 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
@@ -253,7 +253,7 @@ constexpr MeshExtract create_extractor_edit_data()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(EditLoopData *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.edit_data);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.edit_data);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc
index 0378aadabd0..b8494428eed 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc
@@ -128,7 +128,7 @@ constexpr MeshExtract create_extractor_edituv_data()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_EditUVData_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.edituv_data);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.edituv_data);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
index a60c0182e89..a947d98f955 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
@@ -222,7 +222,7 @@ constexpr MeshExtract create_extractor_edituv_edituv_stretch_angle()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_StretchAngle_Data);
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.edituv_stretch_angle);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.edituv_stretch_angle);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
index d79ac493c33..3db8cd79af5 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
@@ -143,7 +143,7 @@ constexpr MeshExtract create_extractor_edituv_stretch_area()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.edituv_stretch_area);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.edituv_stretch_area);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_edituv_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_edituv_data.cc
index b7182d1b60f..28592417183 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_edituv_data.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_edituv_data.cc
@@ -89,7 +89,7 @@ constexpr MeshExtract create_extractor_fdots_edituv_data()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_EditUVFdotData_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.fdots_edituv_data);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_edituv_data);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_nor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_nor.cc
index 5e4ad54f7b6..fed66f0057d 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_nor.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_nor.cc
@@ -105,7 +105,7 @@ constexpr MeshExtract create_extractor_fdots_nor()
extractor.data_type = MR_DATA_LOOP_NOR;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.fdots_nor);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_nor);
return extractor;
}
@@ -186,7 +186,7 @@ constexpr MeshExtract create_extractor_fdots_nor_hq()
extractor.data_type = MR_DATA_LOOP_NOR;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.fdots_nor);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_nor);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc
index e765fb8a8bf..33f9180e122 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc
@@ -106,7 +106,7 @@ constexpr MeshExtract create_extractor_fdots_pos()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(float(*)[3]);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.fdots_pos);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_pos);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc
index 042a0d2debe..6fe714def30 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc
@@ -114,7 +114,7 @@ constexpr MeshExtract create_extractor_fdots_uv()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_FdotUV_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.fdots_uv);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_uv);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc
index 8344a615cbe..f9f66c27aaa 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc
@@ -116,7 +116,7 @@ constexpr MeshExtract create_extractor_lnor()
extractor.data_type = MR_DATA_LOOP_NOR;
extractor.data_size = sizeof(GPUPackedNormal *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.lnor);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.lnor);
return extractor;
}
@@ -214,7 +214,7 @@ constexpr MeshExtract create_extractor_lnor_hq()
extractor.data_type = MR_DATA_LOOP_NOR;
extractor.data_size = sizeof(gpuHQNor *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.lnor);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.lnor);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
index 075d54e268e..33a33c81bc2 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
@@ -641,7 +641,7 @@ constexpr MeshExtract create_extractor_mesh_analysis()
extractor.data_type = MR_DATA_POLY_NOR | MR_DATA_LOOPTRI;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.mesh_analysis);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.mesh_analysis);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_orco.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_orco.cc
index 269c0343e32..c5187a47892 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_orco.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_orco.cc
@@ -102,7 +102,7 @@ constexpr MeshExtract create_extractor_orco()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_Orco_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.orco);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.orco);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
index b8e5dcb613f..eb9a138590c 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
@@ -208,7 +208,7 @@ constexpr MeshExtract create_extractor_pos_nor()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_PosNor_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.pos_nor);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.pos_nor);
return extractor;
}
@@ -401,7 +401,7 @@ constexpr MeshExtract create_extractor_pos_nor_hq()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_PosNorHQ_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.pos_nor);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.pos_nor);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc
index dbb1e1f880b..fd91bc5258f 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc
@@ -128,7 +128,7 @@ constexpr MeshExtract create_extractor_sculpt_data()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.sculpt_data);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.sculpt_data);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
index cd8d46901c5..5ac30dd3be9 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
@@ -205,7 +205,7 @@ constexpr MeshExtract create_extractor_poly_idx()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(uint32_t *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.poly_idx);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.poly_idx);
return extractor;
}
@@ -220,7 +220,7 @@ constexpr MeshExtract create_extractor_edge_idx()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(uint32_t *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.edge_idx);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.edge_idx);
return extractor;
}
@@ -237,7 +237,7 @@ constexpr MeshExtract create_extractor_vert_idx()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(uint32_t *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.vert_idx);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.vert_idx);
return extractor;
}
@@ -279,7 +279,7 @@ constexpr MeshExtract create_extractor_fdot_idx()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(uint32_t *);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.fdot_idx);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdot_idx);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_skin_roots.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_skin_roots.cc
index ffca01d00dd..1847a360837 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_skin_roots.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_skin_roots.cc
@@ -80,7 +80,7 @@ constexpr MeshExtract create_extractor_skin_roots()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.skin_roots);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.skin_roots);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
index 8f36bfdf1ef..1f8776fc98e 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
@@ -226,7 +226,7 @@ constexpr MeshExtract create_extractor_tan()
extractor.data_type = MR_DATA_POLY_NOR | MR_DATA_TAN_LOOP_NOR | MR_DATA_LOOPTRI;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.tan);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.tan);
return extractor;
}
@@ -252,7 +252,7 @@ constexpr MeshExtract create_extractor_tan_hq()
extractor.data_type = MR_DATA_POLY_NOR | MR_DATA_TAN_LOOP_NOR | MR_DATA_LOOPTRI;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.tan);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.tan);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
index 013da7d674a..af279b08a59 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
@@ -123,7 +123,7 @@ constexpr MeshExtract create_extractor_uv()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.uv);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.uv);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
index d810acfb617..2c7770c8e72 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
@@ -178,7 +178,7 @@ constexpr MeshExtract create_extractor_vcol()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = 0;
extractor.use_threading = false;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.vcol);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.vcol);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc
index c547a453aeb..bdb1410a755 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc
@@ -176,7 +176,7 @@ constexpr MeshExtract create_extractor_weights()
extractor.data_type = MR_DATA_NONE;
extractor.data_size = sizeof(MeshExtract_Weight_Data);
extractor.use_threading = true;
- extractor.mesh_buffer_offset = offsetof(MeshBufferCache, vbo.weights);
+ extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.weights);
return extractor;
}
diff --git a/source/blender/draw/tests/shaders_test.cc b/source/blender/draw/tests/shaders_test.cc
index 0c7cbd4dac8..a9810b4cc77 100644
--- a/source/blender/draw/tests/shaders_test.cc
+++ b/source/blender/draw/tests/shaders_test.cc
@@ -267,7 +267,8 @@ static void test_overlay_glsl_shaders()
EXPECT_NE(OVERLAY_shader_paint_point(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_texture(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_vertcol(), nullptr);
- EXPECT_NE(OVERLAY_shader_paint_weight(), nullptr);
+ EXPECT_NE(OVERLAY_shader_paint_weight(false), nullptr);
+ EXPECT_NE(OVERLAY_shader_paint_weight(true), nullptr);
EXPECT_NE(OVERLAY_shader_paint_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_particle_dot(), nullptr);
EXPECT_NE(OVERLAY_shader_particle_shape(), nullptr);
diff --git a/source/blender/editors/animation/anim_ipo_utils.c b/source/blender/editors/animation/anim_ipo_utils.c
index 5992545bdbe..eda87cf1897 100644
--- a/source/blender/editors/animation/anim_ipo_utils.c
+++ b/source/blender/editors/animation/anim_ipo_utils.c
@@ -134,6 +134,28 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
else {
structname = RNA_struct_ui_name(ptr.type);
}
+
+ /* For the VSE, a strip's 'Transform' or 'Crop' is a nested (under Sequence) struct, but
+ * displaying the struct name alone is no meaningful information (and also cannot be
+ * filtered well), same for modifiers. So display strip name alongside as well. */
+ if (GS(ptr.owner_id->name) == ID_SCE) {
+ if (BLI_str_startswith(fcu->rna_path, "sequence_editor.sequences_all[\"")) {
+ if (strstr(fcu->rna_path, ".transform.") || strstr(fcu->rna_path, ".crop.") ||
+ strstr(fcu->rna_path, ".modifiers[")) {
+ char *stripname = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
+ const char *structname_all = BLI_sprintfN(
+ "%s : %s", stripname ? stripname : "", structname);
+ if (free_structname) {
+ MEM_freeN((void *)structname);
+ }
+ if (stripname) {
+ MEM_freeN(stripname);
+ }
+ structname = structname_all;
+ free_structname = 1;
+ }
+ }
+ }
}
/* Property Name is straightforward */
diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c
index deed79942ac..61918871b90 100644
--- a/source/blender/editors/animation/keyframes_draw.c
+++ b/source/blender/editors/animation/keyframes_draw.c
@@ -25,6 +25,8 @@
#include <float.h>
+#include "MEM_guardedalloc.h"
+
#include "BLI_dlrbTree.h"
#include "BLI_listbase.h"
#include "BLI_rect.h"
@@ -55,11 +57,7 @@ void draw_keyframe_shape(float x,
short key_type,
short mode,
float alpha,
- uint pos_id,
- uint size_id,
- uint color_id,
- uint outline_color_id,
- uint flags_id,
+ const KeyframeShaderBindings *sh_bindings,
short handle_type,
short extreme_type)
{
@@ -176,334 +174,563 @@ void draw_keyframe_shape(float x,
}
}
- immAttr1f(size_id, size);
- immAttr4ubv(color_id, fill_col);
- immAttr4ubv(outline_color_id, outline_col);
- immAttr1u(flags_id, flags);
- immVertex2f(pos_id, x, y);
+ immAttr1f(sh_bindings->size_id, size);
+ immAttr4ubv(sh_bindings->color_id, fill_col);
+ immAttr4ubv(sh_bindings->outline_color_id, outline_col);
+ immAttr1u(sh_bindings->flags_id, flags);
+ immVertex2f(sh_bindings->pos_id, x, y);
}
-static void draw_keylist(View2D *v2d,
- const struct AnimKeylist *keylist,
- float ypos,
- float yscale_fac,
- bool channelLocked,
- int saction_flag)
-{
- const float icon_sz = U.widget_unit * 0.5f * yscale_fac;
- const float half_icon_sz = 0.5f * icon_sz;
- const float smaller_sz = 0.35f * icon_sz;
- const float ipo_sz = 0.1f * icon_sz;
- const float gpencil_sz = smaller_sz * 0.8f;
- const float screenspace_margin = (0.35f * (float)UI_UNIT_X) / UI_view2d_scale_get_x(v2d);
+/* Common attributes shared between the draw calls. */
+typedef struct DrawKeylistUIData {
+ float alpha;
+ float icon_sz;
+ float half_icon_sz;
+ float smaller_sz;
+ float ipo_sz;
+ float gpencil_sz;
+ float screenspace_margin;
+ float sel_color[4];
+ float unsel_color[4];
+ float sel_mhcol[4];
+ float unsel_mhcol[4];
+ float ipo_color[4];
+ float ipo_color_mix[4];
+ /* Show interpolation and handle type? */
+ bool show_ipo;
+} DrawKeylistUIData;
+
+static void draw_keylist_ui_data_init(DrawKeylistUIData *ctx,
+ View2D *v2d,
+ float yscale_fac,
+ bool channel_locked,
+ eSAction_Flag saction_flag)
+{
/* locked channels are less strongly shown, as feedback for locked channels in DopeSheet */
/* TODO: allow this opacity factor to be themed? */
- float alpha = channelLocked ? 0.25f : 1.0f;
+ ctx->alpha = channel_locked ? 0.25f : 1.0f;
+
+ ctx->icon_sz = U.widget_unit * 0.5f * yscale_fac;
+ ctx->half_icon_sz = 0.5f * ctx->icon_sz;
+ ctx->smaller_sz = 0.35f * ctx->icon_sz;
+ ctx->ipo_sz = 0.1f * ctx->icon_sz;
+ ctx->gpencil_sz = ctx->smaller_sz * 0.8f;
+ ctx->screenspace_margin = (0.35f * (float)UI_UNIT_X) / UI_view2d_scale_get_x(v2d);
+
+ ctx->show_ipo = (saction_flag & SACTION_SHOW_INTERPOLATION) != 0;
+
+ UI_GetThemeColor4fv(TH_STRIP_SELECT, ctx->sel_color);
+ UI_GetThemeColor4fv(TH_STRIP, ctx->unsel_color);
+ UI_GetThemeColor4fv(TH_DOPESHEET_IPOLINE, ctx->ipo_color);
+
+ ctx->sel_color[3] *= ctx->alpha;
+ ctx->unsel_color[3] *= ctx->alpha;
+ ctx->ipo_color[3] *= ctx->alpha;
+
+ copy_v4_v4(ctx->sel_mhcol, ctx->sel_color);
+ ctx->sel_mhcol[3] *= 0.8f;
+ copy_v4_v4(ctx->unsel_mhcol, ctx->unsel_color);
+ ctx->unsel_mhcol[3] *= 0.8f;
+ copy_v4_v4(ctx->ipo_color_mix, ctx->ipo_color);
+ ctx->ipo_color_mix[3] *= 0.5f;
+}
- /* Show interpolation and handle type? */
- bool show_ipo = (saction_flag & SACTION_SHOW_INTERPOLATION) != 0;
- /* draw keyblocks */
- float sel_color[4], unsel_color[4];
- float sel_mhcol[4], unsel_mhcol[4];
- float ipo_color[4], ipo_color_mix[4];
-
- /* cache colors first */
- UI_GetThemeColor4fv(TH_STRIP_SELECT, sel_color);
- UI_GetThemeColor4fv(TH_STRIP, unsel_color);
- UI_GetThemeColor4fv(TH_DOPESHEET_IPOLINE, ipo_color);
-
- sel_color[3] *= alpha;
- unsel_color[3] *= alpha;
- ipo_color[3] *= alpha;
-
- copy_v4_v4(sel_mhcol, sel_color);
- sel_mhcol[3] *= 0.8f;
- copy_v4_v4(unsel_mhcol, unsel_color);
- unsel_mhcol[3] *= 0.8f;
- copy_v4_v4(ipo_color_mix, ipo_color);
- ipo_color_mix[3] *= 0.5f;
-
- const ListBase *keys = ED_keylist_listbase(keylist);
-
- LISTBASE_FOREACH (ActKeyColumn *, ab, keys) {
- /* Draw grease pencil bars between keyframes. */
- if ((ab->next != NULL) && (ab->block.flag & ACTKEYBLOCK_FLAG_GPENCIL)) {
- UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
- float size = 1.0f;
- switch (ab->next->key_type) {
- case BEZT_KEYTYPE_BREAKDOWN:
- case BEZT_KEYTYPE_MOVEHOLD:
- case BEZT_KEYTYPE_JITTER:
- size *= 0.5f;
- break;
- case BEZT_KEYTYPE_KEYFRAME:
- size *= 0.8f;
- break;
- default:
- break;
- }
- UI_draw_roundbox_4fv(
- &(const rctf){
- .xmin = ab->cfra,
- .xmax = min_ff(ab->next->cfra - (screenspace_margin * size), ab->next->cfra),
- .ymin = ypos - gpencil_sz,
- .ymax = ypos + gpencil_sz,
- },
- true,
- 0.25f * (float)UI_UNIT_X,
- (ab->block.sel) ? sel_mhcol : unsel_mhcol);
- }
- else {
- /* Draw other types. */
- UI_draw_roundbox_corner_set(UI_CNR_NONE);
-
- int valid_hold = actkeyblock_get_valid_hold(ab);
- if (valid_hold != 0) {
- if ((valid_hold & ACTKEYBLOCK_FLAG_STATIC_HOLD) == 0) {
- /* draw "moving hold" long-keyframe block - slightly smaller */
- UI_draw_roundbox_4fv(
- &(const rctf){
- .xmin = ab->cfra,
- .xmax = ab->next->cfra,
- .ymin = ypos - smaller_sz,
- .ymax = ypos + smaller_sz,
- },
- true,
- 3.0f,
- (ab->block.sel) ? sel_mhcol : unsel_mhcol);
- }
- else {
- /* draw standard long-keyframe block */
- UI_draw_roundbox_4fv(
- &(const rctf){
- .xmin = ab->cfra,
- .xmax = ab->next->cfra,
- .ymin = ypos - half_icon_sz,
- .ymax = ypos + half_icon_sz,
- },
- true,
- 3.0f,
- (ab->block.sel) ? sel_color : unsel_color);
- }
- }
- if (show_ipo && actkeyblock_is_valid(ab) && (ab->block.flag & ACTKEYBLOCK_FLAG_NON_BEZIER)) {
- /* draw an interpolation line */
- UI_draw_roundbox_4fv(
- &(const rctf){
- .xmin = ab->cfra,
- .xmax = ab->next->cfra,
- .ymin = ypos - ipo_sz,
- .ymax = ypos + ipo_sz,
- },
- true,
- 3.0f,
- (ab->block.conflict & ACTKEYBLOCK_FLAG_NON_BEZIER) ? ipo_color_mix : ipo_color);
- }
- }
+static void draw_keylist_block_gpencil(const DrawKeylistUIData *ctx,
+ const ActKeyColumn *ab,
+ float ypos)
+{
+ UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
+ float size = 1.0f;
+ switch (ab->next->key_type) {
+ case BEZT_KEYTYPE_BREAKDOWN:
+ case BEZT_KEYTYPE_MOVEHOLD:
+ case BEZT_KEYTYPE_JITTER:
+ size *= 0.5f;
+ break;
+ case BEZT_KEYTYPE_KEYFRAME:
+ size *= 0.8f;
+ break;
+ default:
+ break;
}
+ UI_draw_roundbox_4fv(
+ &(const rctf){
+ .xmin = ab->cfra,
+ .xmax = min_ff(ab->next->cfra - (ctx->screenspace_margin * size), ab->next->cfra),
+ .ymin = ypos - ctx->gpencil_sz,
+ .ymax = ypos + ctx->gpencil_sz,
+ },
+ true,
+ 0.25f * (float)UI_UNIT_X,
+ (ab->block.sel) ? ctx->sel_mhcol : ctx->unsel_mhcol);
+}
- GPU_blend(GPU_BLEND_ALPHA);
+static void draw_keylist_block_moving_hold(const DrawKeylistUIData *ctx,
+ const ActKeyColumn *ab,
+ float ypos)
+{
- /* count keys */
- uint key_len = 0;
- LISTBASE_FOREACH (ActKeyColumn *, ak, keys) {
- /* Optimization: if keyframe doesn't appear within 5 units (screenspace)
- * in visible area, don't draw.
- * This might give some improvements,
- * since we current have to flip between view/region matrices.
- */
- if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax)) {
- key_len++;
- }
- }
+ UI_draw_roundbox_4fv(
+ &(const rctf){
+ .xmin = ab->cfra,
+ .xmax = ab->next->cfra,
+ .ymin = ypos - ctx->smaller_sz,
+ .ymax = ypos + ctx->smaller_sz,
+ },
+ true,
+ 3.0f,
+ (ab->block.sel) ? ctx->sel_mhcol : ctx->unsel_mhcol);
+}
+
+static void draw_keylist_block_standard(const DrawKeylistUIData *ctx,
+ const ActKeyColumn *ab,
+ float ypos)
+{
+ UI_draw_roundbox_4fv(
+ &(const rctf){
+ .xmin = ab->cfra,
+ .xmax = ab->next->cfra,
+ .ymin = ypos - ctx->half_icon_sz,
+ .ymax = ypos + ctx->half_icon_sz,
+ },
+ true,
+ 3.0f,
+ (ab->block.sel) ? ctx->sel_color : ctx->unsel_color);
+}
+
+static void draw_keylist_block_interpolation_line(const DrawKeylistUIData *ctx,
+ const ActKeyColumn *ab,
+ float ypos)
+{
+ UI_draw_roundbox_4fv(
+ &(const rctf){
+ .xmin = ab->cfra,
+ .xmax = ab->next->cfra,
+ .ymin = ypos - ctx->ipo_sz,
+ .ymax = ypos + ctx->ipo_sz,
+ },
+ true,
+ 3.0f,
+ (ab->block.conflict & ACTKEYBLOCK_FLAG_NON_BEZIER) ? ctx->ipo_color_mix : ctx->ipo_color);
+}
+
+static void draw_keylist_block(const DrawKeylistUIData *ctx, const ActKeyColumn *ab, float ypos)
+{
- if (key_len > 0) {
- /* draw keys */
- GPUVertFormat *format = immVertexFormat();
- uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
- uint color_id = GPU_vertformat_attr_add(
- format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- uint outline_color_id = GPU_vertformat_attr_add(
- format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- uint flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
-
- GPU_program_point_size(true);
- immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
- immUniform1f("outline_scale", 1.0f);
- immUniform2f("ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
- immBegin(GPU_PRIM_POINTS, key_len);
-
- short handle_type = KEYFRAME_HANDLE_NONE, extreme_type = KEYFRAME_EXTREME_NONE;
-
- LISTBASE_FOREACH (ActKeyColumn *, ak, keys) {
- if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax)) {
- if (show_ipo) {
- handle_type = ak->handle_type;
- }
- if (saction_flag & SACTION_SHOW_EXTREMES) {
- extreme_type = ak->extreme_type;
- }
-
- draw_keyframe_shape(ak->cfra,
- ypos,
- icon_sz,
- (ak->sel & SELECT),
- ak->key_type,
- KEYFRAME_SHAPE_BOTH,
- alpha,
- pos_id,
- size_id,
- color_id,
- outline_color_id,
- flags_id,
- handle_type,
- extreme_type);
+ /* Draw grease pencil bars between keyframes. */
+ if ((ab->next != NULL) && (ab->block.flag & ACTKEYBLOCK_FLAG_GPENCIL)) {
+ draw_keylist_block_gpencil(ctx, ab, ypos);
+ }
+ else {
+ /* Draw other types. */
+ UI_draw_roundbox_corner_set(UI_CNR_NONE);
+
+ int valid_hold = actkeyblock_get_valid_hold(ab);
+ if (valid_hold != 0) {
+ if ((valid_hold & ACTKEYBLOCK_FLAG_STATIC_HOLD) == 0) {
+ /* draw "moving hold" long-keyframe block - slightly smaller */
+ draw_keylist_block_moving_hold(ctx, ab, ypos);
+ }
+ else {
+ /* draw standard long-keyframe block */
+ draw_keylist_block_standard(ctx, ab, ypos);
}
}
-
- immEnd();
- GPU_program_point_size(false);
- immUnbindProgram();
+ if (ctx->show_ipo && actkeyblock_is_valid(ab) &&
+ (ab->block.flag & ACTKEYBLOCK_FLAG_NON_BEZIER)) {
+ /* draw an interpolation line */
+ draw_keylist_block_interpolation_line(ctx, ab, ypos);
+ }
}
-
- GPU_blend(GPU_BLEND_NONE);
}
-/* *************************** Channel Drawing Funcs *************************** */
+static void draw_keylist_blocks(const DrawKeylistUIData *ctx,
+ const ListBase * /*ActKeyColumn*/ columns,
+ float ypos)
+{
+ LISTBASE_FOREACH (ActKeyColumn *, ab, columns) {
+ draw_keylist_block(ctx, ab, ypos);
+ }
+}
-void draw_summary_channel(
- View2D *v2d, bAnimContext *ac, float ypos, float yscale_fac, int saction_flag)
+static bool draw_keylist_is_visible_key(const View2D *v2d, const ActKeyColumn *ak)
{
- struct AnimKeylist *keylist = ED_keylist_create();
+ return IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax);
+}
- saction_flag &= ~SACTION_SHOW_EXTREMES;
+static void draw_keylist_keys(const DrawKeylistUIData *ctx,
+ View2D *v2d,
+ const KeyframeShaderBindings *sh_bindings,
+ const ListBase * /*ActKeyColumn*/ keys,
+ float ypos,
+ eSAction_Flag saction_flag)
+{
+ short handle_type = KEYFRAME_HANDLE_NONE, extreme_type = KEYFRAME_EXTREME_NONE;
- summary_to_keylist(ac, keylist, saction_flag);
+ LISTBASE_FOREACH (ActKeyColumn *, ak, keys) {
+ if (draw_keylist_is_visible_key(v2d, ak)) {
+ if (ctx->show_ipo) {
+ handle_type = ak->handle_type;
+ }
+ if (saction_flag & SACTION_SHOW_EXTREMES) {
+ extreme_type = ak->extreme_type;
+ }
- draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
+ draw_keyframe_shape(ak->cfra,
+ ypos,
+ ctx->icon_sz,
+ (ak->sel & SELECT),
+ ak->key_type,
+ KEYFRAME_SHAPE_BOTH,
+ ctx->alpha,
+ sh_bindings,
+ handle_type,
+ extreme_type);
+ }
+ }
+}
- ED_keylist_free(keylist);
+/* *************************** Drawing Stack *************************** */
+typedef enum eAnimKeylistDrawListElemType {
+ ANIM_KEYLIST_SUMMARY,
+ ANIM_KEYLIST_SCENE,
+ ANIM_KEYLIST_OBJECT,
+ ANIM_KEYLIST_FCURVE,
+ ANIM_KEYLIST_ACTION,
+ ANIM_KEYLIST_AGROUP,
+ ANIM_KEYLIST_GP_LAYER,
+ ANIM_KEYLIST_MASK_LAYER,
+} eAnimKeylistDrawListElemType;
+
+typedef struct AnimKeylistDrawListElem {
+ struct AnimKeylistDrawListElem *next, *prev;
+ struct AnimKeylist *keylist;
+ eAnimKeylistDrawListElemType type;
+
+ float yscale_fac;
+ float ypos;
+ eSAction_Flag saction_flag;
+ bool channel_locked;
+
+ bAnimContext *ac;
+ bDopeSheet *ads;
+ Scene *sce;
+ Object *ob;
+ AnimData *adt;
+ FCurve *fcu;
+ bAction *act;
+ bActionGroup *agrp;
+ bGPDlayer *gpl;
+ MaskLayer *masklay;
+
+} AnimKeylistDrawListElem;
+
+static void ED_keylist_draw_list_elem_build_keylist(AnimKeylistDrawListElem *elem)
+{
+ switch (elem->type) {
+ case ANIM_KEYLIST_SUMMARY: {
+ summary_to_keylist(elem->ac, elem->keylist, elem->saction_flag);
+ break;
+ }
+ case ANIM_KEYLIST_SCENE: {
+ scene_to_keylist(elem->ads, elem->sce, elem->keylist, elem->saction_flag);
+ break;
+ }
+ case ANIM_KEYLIST_OBJECT: {
+ ob_to_keylist(elem->ads, elem->ob, elem->keylist, elem->saction_flag);
+ break;
+ }
+ case ANIM_KEYLIST_FCURVE: {
+ fcurve_to_keylist(elem->adt, elem->fcu, elem->keylist, elem->saction_flag);
+ break;
+ }
+ case ANIM_KEYLIST_ACTION: {
+ action_to_keylist(elem->adt, elem->act, elem->keylist, elem->saction_flag);
+ break;
+ }
+ case ANIM_KEYLIST_AGROUP: {
+ agroup_to_keylist(elem->adt, elem->agrp, elem->keylist, elem->saction_flag);
+ break;
+ }
+ case ANIM_KEYLIST_GP_LAYER: {
+ gpl_to_keylist(elem->ads, elem->gpl, elem->keylist);
+ break;
+ }
+ case ANIM_KEYLIST_MASK_LAYER: {
+ mask_to_keylist(elem->ads, elem->masklay, elem->keylist);
+ break;
+ }
+ }
}
-void draw_scene_channel(
- View2D *v2d, bDopeSheet *ads, Scene *sce, float ypos, float yscale_fac, int saction_flag)
+static void ED_keylist_draw_list_elem_draw_blocks(AnimKeylistDrawListElem *elem, View2D *v2d)
{
- struct AnimKeylist *keylist = ED_keylist_create();
+ DrawKeylistUIData ctx;
+ draw_keylist_ui_data_init(&ctx, v2d, elem->yscale_fac, elem->channel_locked, elem->saction_flag);
- saction_flag &= ~SACTION_SHOW_EXTREMES;
+ const ListBase *keys = ED_keylist_listbase(elem->keylist);
+ draw_keylist_blocks(&ctx, keys, elem->ypos);
+}
- scene_to_keylist(ads, sce, keylist, saction_flag);
+static void ED_keylist_draw_list_elem_draw_keys(AnimKeylistDrawListElem *elem,
+ View2D *v2d,
+ const KeyframeShaderBindings *sh_bindings)
+{
+ DrawKeylistUIData ctx;
+ draw_keylist_ui_data_init(&ctx, v2d, elem->yscale_fac, elem->channel_locked, elem->saction_flag);
+ const ListBase *keys = ED_keylist_listbase(elem->keylist);
+ draw_keylist_keys(&ctx, v2d, sh_bindings, keys, elem->ypos, elem->saction_flag);
+}
- draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
+typedef struct AnimKeylistDrawList {
+ ListBase /* AnimKeylistDrawListElem*/ channels;
+} AnimKeylistDrawList;
- ED_keylist_free(keylist);
+AnimKeylistDrawList *ED_keylist_draw_list_create(void)
+{
+ return MEM_callocN(sizeof(AnimKeylistDrawList), __func__);
}
-void draw_object_channel(
- View2D *v2d, bDopeSheet *ads, Object *ob, float ypos, float yscale_fac, int saction_flag)
+static void ED_keylist_draw_list_build_keylists(AnimKeylistDrawList *draw_list)
{
- struct AnimKeylist *keylist = ED_keylist_create();
+ LISTBASE_FOREACH (AnimKeylistDrawListElem *, elem, &draw_list->channels) {
+ ED_keylist_draw_list_elem_build_keylist(elem);
+ }
+}
- saction_flag &= ~SACTION_SHOW_EXTREMES;
+static void ED_keylist_draw_list_draw_blocks(AnimKeylistDrawList *draw_list, View2D *v2d)
+{
+ LISTBASE_FOREACH (AnimKeylistDrawListElem *, elem, &draw_list->channels) {
+ ED_keylist_draw_list_elem_draw_blocks(elem, v2d);
+ }
+}
- ob_to_keylist(ads, ob, keylist, saction_flag);
+static int ED_keylist_draw_keylist_visible_key_len(const View2D *v2d,
+ const ListBase * /*ActKeyColumn*/ keys)
+{
+ /* count keys */
+ uint len = 0;
- draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
+ LISTBASE_FOREACH (ActKeyColumn *, ak, keys) {
+ /* Optimization: if keyframe doesn't appear within 5 units (screenspace)
+ * in visible area, don't draw.
+ * This might give some improvements,
+ * since we current have to flip between view/region matrices.
+ */
+ if (draw_keylist_is_visible_key(v2d, ak)) {
+ len++;
+ }
+ }
+ return len;
+}
- ED_keylist_free(keylist);
+static int ED_keylist_draw_list_visible_key_len(const AnimKeylistDrawList *draw_list,
+ const View2D *v2d)
+{
+ uint len = 0;
+ LISTBASE_FOREACH (AnimKeylistDrawListElem *, elem, &draw_list->channels) {
+ const ListBase *keys = ED_keylist_listbase(elem->keylist);
+ len += ED_keylist_draw_keylist_visible_key_len(v2d, keys);
+ }
+ return len;
}
-void draw_fcurve_channel(
- View2D *v2d, AnimData *adt, FCurve *fcu, float ypos, float yscale_fac, int saction_flag)
+static void ED_keylist_draw_list_draw_keys(AnimKeylistDrawList *draw_list, View2D *v2d)
{
- struct AnimKeylist *keylist = ED_keylist_create();
+ const int visible_key_len = ED_keylist_draw_list_visible_key_len(draw_list, v2d);
+ if (visible_key_len == 0) {
+ return;
+ }
- bool locked = (fcu->flag & FCURVE_PROTECTED) ||
- ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ||
- ((adt && adt->action) && ID_IS_LINKED(adt->action));
+ GPU_blend(GPU_BLEND_ALPHA);
- fcurve_to_keylist(adt, fcu, keylist, saction_flag);
+ GPUVertFormat *format = immVertexFormat();
+ KeyframeShaderBindings sh_bindings;
+
+ sh_bindings.pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ sh_bindings.size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+ sh_bindings.color_id = GPU_vertformat_attr_add(
+ format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ sh_bindings.outline_color_id = GPU_vertformat_attr_add(
+ format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ sh_bindings.flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
+
+ GPU_program_point_size(true);
+ immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
+ immUniform1f("outline_scale", 1.0f);
+ immUniform2f("ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
+ immBegin(GPU_PRIM_POINTS, visible_key_len);
+
+ LISTBASE_FOREACH (AnimKeylistDrawListElem *, elem, &draw_list->channels) {
+ ED_keylist_draw_list_elem_draw_keys(elem, v2d, &sh_bindings);
+ }
- draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
+ immEnd();
+ GPU_program_point_size(false);
+ immUnbindProgram();
- ED_keylist_free(keylist);
+ GPU_blend(GPU_BLEND_NONE);
}
-void draw_agroup_channel(
- View2D *v2d, AnimData *adt, bActionGroup *agrp, float ypos, float yscale_fac, int saction_flag)
+static void ED_keylist_draw_list_draw(AnimKeylistDrawList *draw_list, View2D *v2d)
{
- struct AnimKeylist *keylist = ED_keylist_create();
-
- bool locked = (agrp->flag & AGRP_PROTECTED) ||
- ((adt && adt->action) && ID_IS_LINKED(adt->action));
-
- agroup_to_keylist(adt, agrp, keylist, saction_flag);
+ ED_keylist_draw_list_draw_blocks(draw_list, v2d);
+ ED_keylist_draw_list_draw_keys(draw_list, v2d);
+}
- draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
+void ED_keylist_draw_list_flush(AnimKeylistDrawList *draw_list, View2D *v2d)
+{
+ ED_keylist_draw_list_build_keylists(draw_list);
+ ED_keylist_draw_list_draw(draw_list, v2d);
+}
- ED_keylist_free(keylist);
+void ED_keylist_draw_list_free(AnimKeylistDrawList *draw_list)
+{
+ LISTBASE_FOREACH (AnimKeylistDrawListElem *, elem, &draw_list->channels) {
+ ED_keylist_free(elem->keylist);
+ }
+ BLI_freelistN(&draw_list->channels);
+ MEM_freeN(draw_list);
}
-void draw_action_channel(
- View2D *v2d, AnimData *adt, bAction *act, float ypos, float yscale_fac, int saction_flag)
+static AnimKeylistDrawListElem *ed_keylist_draw_list_add_elem(
+ AnimKeylistDrawList *draw_list,
+ eAnimKeylistDrawListElemType elem_type,
+ float ypos,
+ float yscale_fac,
+ eSAction_Flag saction_flag)
{
- struct AnimKeylist *keylist = ED_keylist_create();
+ AnimKeylistDrawListElem *draw_elem = MEM_callocN(sizeof(AnimKeylistDrawListElem), __func__);
+ BLI_addtail(&draw_list->channels, draw_elem);
+ draw_elem->type = elem_type;
+ draw_elem->keylist = ED_keylist_create();
+ draw_elem->ypos = ypos;
+ draw_elem->yscale_fac = yscale_fac;
+ draw_elem->saction_flag = saction_flag;
+ return draw_elem;
+}
- bool locked = (act && ID_IS_LINKED(act));
+/* *************************** Channel Drawing Funcs *************************** */
+void draw_summary_channel(struct AnimKeylistDrawList *draw_list,
+ bAnimContext *ac,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
+{
saction_flag &= ~SACTION_SHOW_EXTREMES;
-
- action_to_keylist(adt, act, keylist, saction_flag);
-
- draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
-
- ED_keylist_free(keylist);
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_SUMMARY, ypos, yscale_fac, saction_flag);
+ draw_elem->ac = ac;
}
-void draw_gpencil_channel(
- View2D *v2d, bDopeSheet *ads, bGPdata *gpd, float ypos, float yscale_fac, int saction_flag)
+void draw_scene_channel(AnimKeylistDrawList *draw_list,
+ bDopeSheet *ads,
+ Scene *sce,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
{
- struct AnimKeylist *keylist = ED_keylist_create();
-
saction_flag &= ~SACTION_SHOW_EXTREMES;
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_SCENE, ypos, yscale_fac, saction_flag);
+ draw_elem->ads = ads;
+ draw_elem->sce = sce;
+}
- gpencil_to_keylist(ads, gpd, keylist, false);
-
- draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
+void draw_object_channel(AnimKeylistDrawList *draw_list,
+ bDopeSheet *ads,
+ Object *ob,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
+{
+ saction_flag &= ~SACTION_SHOW_EXTREMES;
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_OBJECT, ypos, yscale_fac, saction_flag);
+ draw_elem->ads = ads;
+ draw_elem->ob = ob;
+}
- ED_keylist_free(keylist);
+void draw_fcurve_channel(AnimKeylistDrawList *draw_list,
+ AnimData *adt,
+ FCurve *fcu,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
+{
+ const bool locked = (fcu->flag & FCURVE_PROTECTED) ||
+ ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ||
+ ((adt && adt->action) && ID_IS_LINKED(adt->action));
+
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_FCURVE, ypos, yscale_fac, saction_flag);
+ draw_elem->adt = adt;
+ draw_elem->fcu = fcu;
+ draw_elem->channel_locked = locked;
}
-void draw_gpl_channel(
- View2D *v2d, bDopeSheet *ads, bGPDlayer *gpl, float ypos, float yscale_fac, int saction_flag)
+void draw_agroup_channel(AnimKeylistDrawList *draw_list,
+ AnimData *adt,
+ bActionGroup *agrp,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
{
- struct AnimKeylist *keylist = ED_keylist_create();
+ bool locked = (agrp->flag & AGRP_PROTECTED) ||
+ ((adt && adt->action) && ID_IS_LINKED(adt->action));
- bool locked = (gpl->flag & GP_LAYER_LOCKED) != 0;
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_AGROUP, ypos, yscale_fac, saction_flag);
+ draw_elem->adt = adt;
+ draw_elem->agrp = agrp;
+ draw_elem->channel_locked = locked;
+}
- gpl_to_keylist(ads, gpl, keylist);
+void draw_action_channel(AnimKeylistDrawList *draw_list,
+ AnimData *adt,
+ bAction *act,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
+{
+ const bool locked = (act && ID_IS_LINKED(act));
+ saction_flag &= ~SACTION_SHOW_EXTREMES;
- draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_ACTION, ypos, yscale_fac, saction_flag);
+ draw_elem->adt = adt;
+ draw_elem->act = act;
+ draw_elem->channel_locked = locked;
+}
- ED_keylist_free(keylist);
+void draw_gpl_channel(AnimKeylistDrawList *draw_list,
+ bDopeSheet *ads,
+ bGPDlayer *gpl,
+ float ypos,
+ float yscale_fac,
+ int saction_flag)
+{
+ bool locked = (gpl->flag & GP_LAYER_LOCKED) != 0;
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_GP_LAYER, ypos, yscale_fac, saction_flag);
+ draw_elem->ads = ads;
+ draw_elem->gpl = gpl;
+ draw_elem->channel_locked = locked;
}
-void draw_masklay_channel(View2D *v2d,
+void draw_masklay_channel(AnimKeylistDrawList *draw_list,
bDopeSheet *ads,
MaskLayer *masklay,
float ypos,
float yscale_fac,
int saction_flag)
{
- struct AnimKeylist *keylist = ED_keylist_create();
-
bool locked = (masklay->flag & MASK_LAYERFLAG_LOCKED) != 0;
-
- mask_to_keylist(ads, masklay, keylist);
-
- draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
-
- ED_keylist_free(keylist);
+ AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
+ draw_list, ANIM_KEYLIST_MASK_LAYER, ypos, yscale_fac, saction_flag);
+ draw_elem->ads = ads;
+ draw_elem->masklay = masklay;
+ draw_elem->channel_locked = locked;
}
diff --git a/source/blender/editors/animation/keyframes_keylist.cc b/source/blender/editors/animation/keyframes_keylist.cc
index 85036efc983..f6ade11a517 100644
--- a/source/blender/editors/animation/keyframes_keylist.cc
+++ b/source/blender/editors/animation/keyframes_keylist.cc
@@ -294,7 +294,7 @@ static void nupdate_ak_bezt(void *node, void *data)
}
/* For interpolation type, select the highest value (enum is sorted). */
- ak->handle_type = MAX2(ak->handle_type, bezt_handle_type(bezt));
+ ak->handle_type = MAX2((eKeyframeHandleDrawOpts)ak->handle_type, bezt_handle_type(bezt));
/* For extremes, detect when combining different states. */
const char new_extreme = bezt_extreme_type(chain);
@@ -821,6 +821,9 @@ void agroup_to_keylist(AnimData *adt,
if (agrp) {
/* loop through F-Curves */
LISTBASE_FOREACH (FCurve *, fcu, &agrp->channels) {
+ if (fcu->grp != agrp) {
+ break;
+ }
fcurve_to_keylist(adt, fcu, keylist, saction_flag);
}
}
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index dc418a1b3d5..d69a2cae94d 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -36,7 +36,7 @@ using PointerRNAVec = blender::Vector<PointerRNA>;
static bool asset_operation_poll(bContext * /*C*/)
{
- return U.experimental.use_asset_browser;
+ return U.experimental.use_extended_asset_browser;
}
/**
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index 39fb2882e4b..b7deea5069e 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -576,7 +576,7 @@ static int paste_from_file_exec(bContext *C, wmOperator *op)
char *path;
int retval;
- path = RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
+ path = RNA_string_get_alloc(op->ptr, "filepath", NULL, 0, NULL);
retval = paste_from_file(C, op->reports, path);
MEM_freeN(path);
@@ -1627,7 +1627,7 @@ static int insert_text_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
len = BLI_strlen_utf8(inserted_utf8);
inserted_text = MEM_callocN(sizeof(char32_t) * (len + 1), "FONT_insert_text");
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 31ef094afa6..bf47704746b 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -836,10 +836,6 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
/* exit with error if no valid points from this stroke */
if (totelem == 0) {
- if (G.debug & G_DEBUG) {
- printf("Error: No valid points in stroke buffer to convert (tot=%d)\n",
- gpd->runtime.sbuffer_used);
- }
return;
}
@@ -1263,9 +1259,6 @@ static bool annotation_session_initdata(bContext *C, tGPsdata *p)
/* make sure the active view (at the starting time) is a 3d-view */
if (curarea == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: No active view for painting\n");
- }
return 0;
}
@@ -1294,11 +1287,6 @@ static bool annotation_session_initdata(bContext *C, tGPsdata *p)
if (region->regiondata == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf(
- "Error: 3D-View active region doesn't have any region data, so cannot be "
- "drawable\n");
- }
return 0;
}
break;
@@ -1325,9 +1313,6 @@ static bool annotation_session_initdata(bContext *C, tGPsdata *p)
/* check that gpencil data is allowed to be drawn */
if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil\n");
- }
return 0;
}
break;
@@ -1387,9 +1372,6 @@ static bool annotation_session_initdata(bContext *C, tGPsdata *p)
/* unsupported views */
default: {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Annotations are not supported in this editor\n");
- }
return 0;
}
}
@@ -1398,9 +1380,6 @@ static bool annotation_session_initdata(bContext *C, tGPsdata *p)
gpd_ptr = ED_annotation_data_get_pointers(C, &p->ownerPtr);
if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Current context doesn't allow for any Annotation data\n");
- }
return 0;
}
@@ -1507,7 +1486,6 @@ static void annotation_session_cleanup(tGPsdata *p)
/* free stroke buffer */
if (gpd->runtime.sbuffer) {
- // printf("\t\tGP - free sbuffer\n");
MEM_freeN(gpd->runtime.sbuffer);
gpd->runtime.sbuffer = NULL;
}
@@ -1545,9 +1523,6 @@ static void annotation_paint_initstroke(tGPsdata *p,
}
if (p->gpl->flag & GP_LAYER_LOCKED) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Cannot paint on locked layer\n");
- }
return;
}
@@ -1573,7 +1548,6 @@ static void annotation_paint_initstroke(tGPsdata *p,
if (has_layer_to_erase == false) {
p->status = GP_STATUS_CAPTURE;
- // if (G.debug & G_DEBUG)
printf("Error: Eraser will not be affecting anything (gpencil_paint_init)\n");
return;
}
@@ -1593,9 +1567,6 @@ static void annotation_paint_initstroke(tGPsdata *p,
if (p->gpf == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: No frame created (gpencil_paint_init)\n");
- }
return;
}
@@ -2063,9 +2034,6 @@ static void annotation_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgr
BKE_report(op->reports, RPT_ERROR, "Cannot paint stroke");
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Grease-Pencil Paint - Add Point Invalid\n");
- }
return;
}
@@ -2221,29 +2189,22 @@ static int annotation_draw_exec(bContext *C, wmOperator *op)
tGPsdata *p = NULL;
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- // printf("GPencil - Starting Re-Drawing\n");
-
/* try to initialize context data needed while drawing */
if (!annotation_draw_init(C, op, NULL)) {
if (op->customdata) {
MEM_freeN(op->customdata);
}
- // printf("\tGP - no valid data\n");
return OPERATOR_CANCELLED;
}
p = op->customdata;
- // printf("\tGP - Start redrawing stroke\n");
-
/* loop over the stroke RNA elements recorded (i.e. progress of mouse movement),
* setting the relevant values in context at each step, then applying
*/
RNA_BEGIN (op->ptr, itemptr, "stroke") {
float mousef[2];
- // printf("\t\tGP - stroke elem\n");
-
/* get relevant data for this point from stroke */
RNA_float_get_array(&itemptr, "mouse", mousef);
p->mval[0] = (int)mousef[0];
@@ -2277,8 +2238,6 @@ static int annotation_draw_exec(bContext *C, wmOperator *op)
}
RNA_END;
- // printf("\tGP - done\n");
-
/* cleanup */
annotation_draw_exit(C, op);
@@ -2301,18 +2260,11 @@ static int annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *ev
RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER);
}
- if (G.debug & G_DEBUG) {
- printf("GPencil - Starting Drawing\n");
- }
-
/* try to initialize context data needed while drawing */
if (!annotation_draw_init(C, op, event)) {
if (op->customdata) {
MEM_freeN(op->customdata);
}
- if (G.debug & G_DEBUG) {
- printf("\tGP - no valid data\n");
- }
return OPERATOR_CANCELLED;
}
@@ -2361,7 +2313,6 @@ static int annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *ev
/* only start drawing immediately if we're allowed to do so... */
if (RNA_boolean_get(op->ptr, "wait_for_input") == false) {
/* hotkey invoked - start drawing */
- // printf("\tGP - set first spot\n");
p->status = GP_STATUS_PAINTING;
/* handle the initial drawing - i.e. for just doing a simple dot */
@@ -2370,7 +2321,6 @@ static int annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *ev
}
else {
/* toolbar invoked - don't start drawing yet... */
- // printf("\tGP - hotkey invoked... waiting for click-drag\n");
op->flag |= OP_IS_MODAL_CURSOR_REGION;
}
@@ -2399,8 +2349,6 @@ static tGPsdata *annotation_stroke_begin(bContext *C, wmOperator *op)
p->status = GP_STATUS_ERROR;
}
- // printf("\t\tGP - start stroke\n");
-
/* we may need to set up paint env again if we're resuming */
/* XXX: watch it with the paintmode! in future,
* it'd be nice to allow changing paint-mode when in sketching-sessions */
@@ -2537,8 +2485,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
}
}
- // printf("\tGP - handle modal event...\n");
-
/* Exit painting mode (and/or end current stroke)
*
* NOTE: cannot do RIGHTMOUSE (as is standard for canceling)
@@ -2547,7 +2493,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
if (event->val == KM_PRESS &&
ELEM(event->type, EVT_RETKEY, EVT_PADENTER, EVT_ESCKEY, EVT_SPACEKEY, EVT_EKEY)) {
/* exit() ends the current stroke before cleaning up */
- // printf("\t\tGP - end of paint op + end of stroke\n");
p->status = GP_STATUS_DONE;
estate = OPERATOR_FINISHED;
}
@@ -2571,7 +2516,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
if (sketch) {
/* end stroke only, and then wait to resume painting soon */
- // printf("\t\tGP - end stroke only\n");
annotation_stroke_end(op);
/* If eraser mode is on, turn it off after the stroke finishes
@@ -2602,7 +2546,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
}
else {
- // printf("\t\tGP - end of stroke + op\n");
p->status = GP_STATUS_DONE;
estate = OPERATOR_FINISHED;
}
@@ -2619,18 +2562,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
ARegion *current_region = BKE_area_find_region_xy(
p->area, RGN_TYPE_ANY, event->x, event->y);
- if (G.debug & G_DEBUG) {
- printf("found alternative region %p (old was %p) - at %d %d (area: %d %d -> %d %d)\n",
- current_region,
- p->region,
- event->x,
- event->y,
- p->area->totrct.xmin,
- p->area->totrct.ymin,
- p->area->totrct.xmax,
- p->area->totrct.ymax);
- }
-
if (current_region) {
/* Assume that since we found the cursor in here, it is in bounds
* and that this should be the region that we begin drawing in
@@ -2642,10 +2573,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
/* Out of bounds, or invalid in some other way */
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
-
- if (G.debug & G_DEBUG) {
- printf("%s: Region under cursor is out of bounds, so cannot be drawn on\n", __func__);
- }
}
}
else if (p->region) {
@@ -2657,10 +2584,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
/* No region */
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
-
- if (G.debug & G_DEBUG) {
- printf("%s: No active region found in GP Paint session data\n", __func__);
- }
}
if (in_bounds) {
@@ -2719,7 +2642,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
}
else {
/* event handled, so just tag as running modal */
- // printf("\t\t\t\tGP - add point handled!\n");
estate = OPERATOR_RUNNING_MODAL;
}
}
@@ -2729,7 +2651,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
/* just resize the brush (local version)
* TODO: fix the hardcoded size jumps (set to make a visible difference) and hardcoded keys
*/
- // printf("\t\tGP - resize eraser\n");
switch (event->type) {
case WHEELDOWNMOUSE: /* larger */
case EVT_PADPLUSKEY:
@@ -2787,12 +2708,6 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
case OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH:
/* event doesn't need to be handled */
-#if 0
- printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n",
- event->type,
- event->type == MIDDLEMOUSE,
- event->type == MOUSEMOVE);
-#endif
break;
}
diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c
index a0a58abc02f..406a7ac77fc 100644
--- a/source/blender/editors/gpencil/gpencil_convert.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -389,9 +389,6 @@ static void gpencil_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd,
*r_tot_gaps_time = (float)(*nbr_gaps) * gtd->gap_duration;
gtd->tot_time += *r_tot_gaps_time;
- if (G.debug & G_DEBUG) {
- printf("%f, %f, %f, %d\n", gtd->tot_time, delta_time, *r_tot_gaps_time, *nbr_gaps);
- }
if (gtd->gap_randomness > 0.0f) {
BLI_rng_srandom(rng, gtd->seed);
}
@@ -464,9 +461,6 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports,
INSERTKEY_FAST);
last_valid_time = cfra;
}
- else if (G.debug & G_DEBUG) {
- printf("\t Skipping start point %d, too close from end point %d\n", i, end_stroke_idx);
- }
}
else if (i == end_stroke_idx) {
/* Always try to insert end point of a curve (should be safe enough, anyway...) */
@@ -546,13 +540,6 @@ static void gpencil_stroke_path_animation(bContext *C,
act = ED_id_action_ensure(bmain, (ID *)cu);
fcu = ED_action_fcurve_ensure(bmain, act, NULL, &ptr, "eval_time", 0);
- if (G.debug & G_DEBUG) {
- printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time);
- for (int i = 0; i < gtd->num_points; i++) {
- printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]);
- }
- }
-
if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) {
float cfra;
@@ -610,10 +597,6 @@ static void gpencil_stroke_path_animation(bContext *C,
time_range = (float)(gtd->end_frame - gtd->start_frame);
}
- if (G.debug & G_DEBUG) {
- printf("GP Stroke Path Conversion: Starting keying!\n");
- }
-
gpencil_stroke_path_animation_add_keyframes(
reports, ptr, prop, depsgraph, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time);
@@ -623,14 +606,6 @@ static void gpencil_stroke_path_animation(bContext *C,
/* As we used INSERTKEY_FAST mode, we need to recompute all curve's handles now */
calchandles_fcurve(fcu);
- if (G.debug & G_DEBUG) {
- printf("%s: \ntot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time);
- for (int i = 0; i < gtd->num_points; i++) {
- printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]);
- }
- printf("\n\n");
- }
-
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
/* send updates */
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 67e1bd5294b..0c88d678ef4 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -646,7 +646,8 @@ static bool gpencil_render_offscreen(tGPDfill *tgpf)
tgpf->sizey = (int)tgpf->region->winy;
char err_out[256] = "unknown";
- GPUOffScreen *offscreen = GPU_offscreen_create(tgpf->sizex, tgpf->sizey, true, false, err_out);
+ GPUOffScreen *offscreen = GPU_offscreen_create(
+ tgpf->sizex, tgpf->sizey, true, GPU_RGBA8, err_out);
if (offscreen == NULL) {
printf("GPencil - Fill - Unable to create fill buffer\n");
return false;
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index 8640ffa67cf..a8bd3b11bb1 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -890,9 +890,9 @@ static int gpencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent
}
case MOUSEMOVE: /* calculate new position */
{
- /* only handle mousemove if not doing numinput */
+ /* Only handle mouse-move if not doing numeric-input. */
if (has_numinput == false) {
- /* update shift based on position of mouse */
+ /* Update shift based on position of mouse. */
gpencil_mouse_update_shift(tgpi, op, event);
/* update screen */
diff --git a/source/blender/editors/gpencil/gpencil_mesh.c b/source/blender/editors/gpencil/gpencil_mesh.c
index 1882285a230..0939d53736b 100644
--- a/source/blender/editors/gpencil/gpencil_mesh.c
+++ b/source/blender/editors/gpencil/gpencil_mesh.c
@@ -316,7 +316,8 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op)
ob_eval->obmat,
frame_offset,
use_seams,
- use_faces);
+ use_faces,
+ true);
/* Reproject all un-tagged created strokes. */
if (project_type != GP_REPROJECT_KEEP) {
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 9e96c40b2db..d2dbf6ab2a6 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -976,10 +976,6 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
/* exit with error if no valid points from this stroke */
if (totelem == 0) {
- if (G.debug & G_DEBUG) {
- printf("Error: No valid points in stroke buffer to convert (tot=%d)\n",
- gpd->runtime.sbuffer_used);
- }
return;
}
@@ -1949,9 +1945,6 @@ static bool gpencil_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
/* make sure the active view (at the starting time) is a 3d-view */
if (curarea == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: No active view for painting\n");
- }
return 0;
}
@@ -1980,11 +1973,6 @@ static bool gpencil_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
if (region->regiondata == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf(
- "Error: 3D-View active region doesn't have any region data, so cannot be "
- "drawable\n");
- }
return 0;
}
@@ -2010,9 +1998,6 @@ static bool gpencil_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
/* unsupported views */
default: {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Active view not appropriate for Grease Pencil drawing\n");
- }
return 0;
}
}
@@ -2021,9 +2006,6 @@ static bool gpencil_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr);
if ((gpd_ptr == NULL) || ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Current context doesn't allow for any Grease Pencil data\n");
- }
return 0;
}
@@ -2147,9 +2129,6 @@ static void gpencil_paint_initstroke(tGPsdata *p,
if ((paintmode != GP_PAINTMODE_ERASER) && (p->gpl->flag & GP_LAYER_LOCKED)) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Cannot paint on locked layer\n");
- }
return;
}
@@ -2228,9 +2207,6 @@ static void gpencil_paint_initstroke(tGPsdata *p,
if (p->gpf == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: No frame created (gpencil_paint_init)\n");
- }
if (!IS_AUTOKEY_ON(scene)) {
BKE_report(p->reports, RPT_INFO, "No available frame for creating stroke");
}
@@ -2824,9 +2800,6 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
BKE_report(op->reports, RPT_ERROR, "Cannot paint stroke");
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG) {
- printf("Error: Grease-Pencil Paint - Add Point Invalid\n");
- }
return;
}
@@ -3198,10 +3171,6 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = (bGPdata *)ob->data;
- if (G.debug & G_DEBUG) {
- printf("GPencil - Starting Drawing\n");
- }
-
/* support for tablets eraser pen */
if (gpencil_is_tablet_eraser_active(event)) {
RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER);
@@ -3239,9 +3208,6 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
if (op->customdata) {
MEM_freeN(op->customdata);
}
- if (G.debug & G_DEBUG) {
- printf("\tGP - no valid data\n");
- }
return OPERATOR_CANCELLED;
}
@@ -3730,18 +3696,6 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
ARegion *current_region = BKE_area_find_region_xy(
p->area, RGN_TYPE_ANY, event->x, event->y);
- if (G.debug & G_DEBUG) {
- printf("found alternative region %p (old was %p) - at %d %d (area: %d %d -> %d %d)\n",
- current_region,
- p->region,
- event->x,
- event->y,
- p->area->totrct.xmin,
- p->area->totrct.ymin,
- p->area->totrct.xmax,
- p->area->totrct.ymax);
- }
-
if (current_region) {
/* Assume that since we found the cursor in here, it is in bounds
* and that this should be the region that we begin drawing in
@@ -3753,10 +3707,6 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* Out of bounds, or invalid in some other way */
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
-
- if (G.debug & G_DEBUG) {
- printf("%s: Region under cursor is out of bounds, so cannot be drawn on\n", __func__);
- }
}
}
else if (p->region) {
@@ -3768,10 +3718,6 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* No region */
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
-
- if (G.debug & G_DEBUG) {
- printf("%s: No active region found in GP Paint session data\n", __func__);
- }
}
if (in_bounds) {
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 7e6ff53de14..5ecb6d9a212 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -1830,11 +1830,6 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
else if ((event->val == KM_RELEASE) && (tgpi->flag == IN_MOVE)) {
tgpi->flag = IN_CURVE_EDIT;
}
- else {
- if (G.debug & G_DEBUG) {
- printf("GP Add Primitive Modal: LEFTMOUSE %d, Status = %d\n", event->val, tgpi->flag);
- }
- }
break;
}
case EVT_SPACEKEY: /* confirm */
@@ -1949,9 +1944,9 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
if (ELEM(tgpi->flag, IN_CURVE_EDIT)) {
break;
}
- /* only handle mousemove if not doing numinput */
+ /* Only handle mouse-move if not doing numeric-input. */
if (has_numinput == false) {
- /* update position of mouse */
+ /* Update position of mouse. */
copy_v2_v2(tgpi->end, tgpi->mval);
copy_v2_v2(tgpi->start, tgpi->origin);
if (tgpi->flag == IDLE) {
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c
index ede1d3eefaa..99b8b672327 100644
--- a/source/blender/editors/gpencil/gpencil_undo.c
+++ b/source/blender/editors/gpencil/gpencil_undo.c
@@ -125,7 +125,7 @@ static void gpencil_undo_free_node(bGPundonode *undo_node)
*/
undo_node->gpd->adt = NULL;
- BKE_gpencil_free(undo_node->gpd, false);
+ BKE_gpencil_free_data(undo_node->gpd, false);
MEM_freeN(undo_node->gpd);
}
@@ -133,8 +133,6 @@ void gpencil_undo_push(bGPdata *gpd)
{
bGPundonode *undo_node;
- // printf("\t\tGP - undo push\n");
-
if (cur_node) {
/* Remove all undone nodes from stack. */
undo_node = cur_node->next;
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index ba3d3b584d7..5cc52303cd6 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -341,7 +341,7 @@ bool ED_gpencil_has_keyframe_v3d(Scene *UNUSED(scene), Object *ob, int cfra)
return (gpl->actframe->framenum == cfra);
}
/* XXX: disabled as could be too much of a penalty */
- /* return BKE_gpencil_layer_frame_find(gpl, cfra); */
+ // return BKE_gpencil_layer_frame_find(gpl, cfra);
}
}
diff --git a/source/blender/editors/include/ED_keyframes_draw.h b/source/blender/editors/include/ED_keyframes_draw.h
index d2d22dd38dc..61e37f20b1b 100644
--- a/source/blender/editors/include/ED_keyframes_draw.h
+++ b/source/blender/editors/include/ED_keyframes_draw.h
@@ -28,6 +28,7 @@ extern "C" {
#endif
struct AnimData;
+struct AnimKeylistDrawList;
struct FCurve;
struct MaskLayer;
struct Object;
@@ -42,6 +43,14 @@ struct bGPDlayer;
/* draw simple diamond-shape keyframe */
/* caller should set up vertex format, bind GPU_SHADER_KEYFRAME_DIAMOND,
* immBegin(GPU_PRIM_POINTS, n), then call this n times */
+typedef struct KeyframeShaderBindings {
+ uint pos_id;
+ uint size_id;
+ uint color_id;
+ uint outline_color_id;
+ uint flags_id;
+} KeyframeShaderBindings;
+
void draw_keyframe_shape(float x,
float y,
float size,
@@ -49,11 +58,7 @@ void draw_keyframe_shape(float x,
short key_type,
short mode,
float alpha,
- unsigned int pos_id,
- unsigned int size_id,
- unsigned int color_id,
- unsigned int outline_color_id,
- unsigned int flags_id,
+ const KeyframeShaderBindings *sh_bindings,
short handle_type,
short extreme_type);
@@ -61,65 +66,65 @@ void draw_keyframe_shape(float x,
/* Channel Drawing ------------------ */
/* F-Curve */
-void draw_fcurve_channel(struct View2D *v2d,
+void draw_fcurve_channel(struct AnimKeylistDrawList *draw_list,
struct AnimData *adt,
struct FCurve *fcu,
float ypos,
float yscale_fac,
int saction_flag);
/* Action Group Summary */
-void draw_agroup_channel(struct View2D *v2d,
+void draw_agroup_channel(struct AnimKeylistDrawList *draw_list,
struct AnimData *adt,
struct bActionGroup *agrp,
float ypos,
float yscale_fac,
int saction_flag);
/* Action Summary */
-void draw_action_channel(struct View2D *v2d,
+void draw_action_channel(struct AnimKeylistDrawList *draw_list,
struct AnimData *adt,
struct bAction *act,
float ypos,
float yscale_fac,
int saction_flag);
/* Object Summary */
-void draw_object_channel(struct View2D *v2d,
+void draw_object_channel(struct AnimKeylistDrawList *draw_list,
struct bDopeSheet *ads,
struct Object *ob,
float ypos,
float yscale_fac,
int saction_flag);
/* Scene Summary */
-void draw_scene_channel(struct View2D *v2d,
+void draw_scene_channel(struct AnimKeylistDrawList *draw_list,
struct bDopeSheet *ads,
struct Scene *sce,
float ypos,
float yscale_fac,
int saction_flag);
/* DopeSheet Summary */
-void draw_summary_channel(
- struct View2D *v2d, struct bAnimContext *ac, float ypos, float yscale_fac, int saction_flag);
-/* Grease Pencil datablock summary */
-void draw_gpencil_channel(struct View2D *v2d,
- struct bDopeSheet *ads,
- struct bGPdata *gpd,
+void draw_summary_channel(struct AnimKeylistDrawList *draw_list,
+ struct bAnimContext *ac,
float ypos,
float yscale_fac,
int saction_flag);
/* Grease Pencil Layer */
-void draw_gpl_channel(struct View2D *v2d,
+void draw_gpl_channel(struct AnimKeylistDrawList *draw_list,
struct bDopeSheet *ads,
struct bGPDlayer *gpl,
float ypos,
float yscale_fac,
int saction_flag);
/* Mask Layer */
-void draw_masklay_channel(struct View2D *v2d,
+void draw_masklay_channel(struct AnimKeylistDrawList *draw_list,
struct bDopeSheet *ads,
struct MaskLayer *masklay,
float ypos,
float yscale_fac,
int saction_flag);
+struct AnimKeylistDrawList *ED_keylist_draw_list_create(void);
+void ED_keylist_draw_list_flush(struct AnimKeylistDrawList *draw_list, struct View2D *v2d);
+void ED_keylist_draw_list_free(struct AnimKeylistDrawList *draw_list);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index 6e4002fcc0a..1d51a3e77cf 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -53,8 +53,9 @@ typedef enum {
#define NODE_EDGE_PAN_INSIDE_PAD 2
#define NODE_EDGE_PAN_OUTSIDE_PAD 0 /* Disable clamping for node panning, use whole screen. */
#define NODE_EDGE_PAN_SPEED_RAMP 1
-#define NODE_EDGE_PAN_MAX_SPEED 40 /* In UI units per second, slower than default. */
-#define NODE_EDGE_PAN_DELAY 1.0f
+#define NODE_EDGE_PAN_MAX_SPEED 26 /* In UI units per second, slower than default. */
+#define NODE_EDGE_PAN_DELAY 0.5f
+#define NODE_EDGE_PAN_ZOOM_INFLUENCE 0.5f
/* space_node.c */
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index cb6fb0dba60..69ac48d842f 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -137,6 +137,7 @@ int BIF_countTransformOrientation(const struct bContext *C);
#define P_GPENCIL_EDIT (1 << 13)
#define P_CURSOR_EDIT (1 << 14)
#define P_CLNOR_INVALIDATE (1 << 15)
+#define P_VIEW2D_EDGE_PAN (1 << 16)
/* For properties performed when confirming the transformation. */
#define P_POST_TRANSFORM (1 << 19)
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index c99c7f681b3..dde8a637e05 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -185,7 +185,7 @@ typedef enum ThemeColorID {
TH_NODE_LAYOUT,
TH_NODE_SHADER,
TH_NODE_INTERFACE,
- TH_NODE_CONVERTOR,
+ TH_NODE_CONVERTER,
TH_NODE_GROUP,
TH_NODE_FRAME,
TH_NODE_MATTE,
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 4ee7df89487..e3c02b4c249 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -26,6 +26,7 @@
#pragma once
#include "BLI_compiler_attrs.h"
+#include "BLI_rect.h"
#ifdef __cplusplus
extern "C" {
@@ -321,6 +322,14 @@ typedef struct View2DEdgePanData {
float max_speed;
/** Delay in seconds before maximum speed is reached. */
float delay;
+ /** Influence factor for view zoom:
+ * 0 = Constant speed in UI units
+ * 1 = Constant speed in view space, UI speed slows down when zooming out
+ */
+ float zoom_influence;
+
+ /** Initial view rect. */
+ rctf initial_rect;
/** Amount to move view relative to zoom. */
float facx, facy;
@@ -338,7 +347,8 @@ void UI_view2d_edge_pan_init(struct bContext *C,
float outside_pad,
float speed_ramp,
float max_speed,
- float delay);
+ float delay,
+ float zoom_influence);
void UI_view2d_edge_pan_reset(struct View2DEdgePanData *vpd);
@@ -350,6 +360,8 @@ void UI_view2d_edge_pan_apply_event(struct bContext *C,
struct View2DEdgePanData *vpd,
const struct wmEvent *event);
+void UI_view2d_edge_pan_cancel(struct bContext *C, struct View2DEdgePanData *vpd);
+
void UI_view2d_edge_pan_operator_properties(struct wmOperatorType *ot);
void UI_view2d_edge_pan_operator_properties_ex(struct wmOperatorType *ot,
@@ -357,7 +369,8 @@ void UI_view2d_edge_pan_operator_properties_ex(struct wmOperatorType *ot,
float outside_pad,
float speed_ramp,
float max_speed,
- float delay);
+ float delay,
+ float zoom_influence);
/* Initialize panning data with operator settings. */
void UI_view2d_edge_pan_operator_init(struct bContext *C,
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c
index dbfdfbf7950..3149675ac04 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.c
@@ -343,7 +343,7 @@ static int ui_block_align_butal_cmp(const void *a, const void *b)
* stupid UI code produces widgets which have the same TOP and LEFT positions...
* We do not care really,
* because this happens when UI is way too small to be usable anyway. */
- /* BLI_assert(0); */
+ // BLI_assert(0);
return 0;
}
diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c
index d917534895d..b953d88c896 100644
--- a/source/blender/editors/interface/interface_context_menu.c
+++ b/source/blender/editors/interface/interface_context_menu.c
@@ -373,13 +373,7 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um)
BLI_assert(ui_but_is_user_menu_compatible(C, but));
char drawstr[sizeof(but->drawstr)];
- STRNCPY(drawstr, but->drawstr);
- if (but->flag & UI_BUT_HAS_SEP_CHAR) {
- char *sep = strrchr(drawstr, UI_SEP_CHAR);
- if (sep) {
- *sep = '\0';
- }
- }
+ ui_but_drawstr_without_sep_char(but, drawstr, sizeof(drawstr));
MenuType *mt = NULL;
if (but->optype) {
@@ -952,7 +946,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
}
/* If the button represents an id, it can set the "id" context pointer. */
- if (U.experimental.use_asset_browser && ED_asset_can_mark_single_from_context(C)) {
+ if (U.experimental.use_extended_asset_browser && ED_asset_can_mark_single_from_context(C)) {
ID *id = CTX_data_pointer_get_type(C, "id", &RNA_ID).data;
/* Gray out items depending on if data-block is an asset. Preferably this could be done via
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 65104885d98..ebebf69bc11 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -2281,7 +2281,7 @@ static void ui_shadowbox(const rctf *rect, uint pos, uint color, float shadsize,
immVertex2fv(pos, v3);
/* corner shape */
- /* immAttr4ub(color, 0, 0, 0, alpha); */ /* Not needed, done above in previous tri */
+ // immAttr4ub(color, 0, 0, 0, alpha); /* Not needed, done above in previous tri. */
immVertex2fv(pos, v3);
immAttr4ub(color, 0, 0, 0, 0);
immVertex2fv(pos, v4);
@@ -2293,7 +2293,7 @@ static void ui_shadowbox(const rctf *rect, uint pos, uint color, float shadsize,
immVertex2fv(pos, v3);
/* bottom quad */
- /* immAttr4ub(color, 0, 0, 0, alpha); */ /* Not needed, done above in previous tri */
+ // immAttr4ub(color, 0, 0, 0, alpha); /* Not needed, done above in previous tri. */
immVertex2fv(pos, v3);
immAttr4ub(color, 0, 0, 0, 0);
immVertex2fv(pos, v6);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6f2232fabe5..a618daec4bc 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3086,11 +3086,6 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
UI_fontstyle_set(&fstyle);
- if (fstyle.kerning == 1) {
- /* for BLF_width */
- BLF_enable(fstyle.uifont_id, BLF_KERNING_DEFAULT);
- }
-
ui_but_text_password_hide(password_str, but, false);
if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
@@ -3141,10 +3136,6 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
but->pos = glyph_data[1] + but->ofs;
}
- if (fstyle.kerning == 1) {
- BLF_disable(fstyle.uifont_id, BLF_KERNING_DEFAULT);
- }
-
ui_but_text_password_hide(password_str, but, true);
}
@@ -3359,7 +3350,7 @@ static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const in
if (pbuf) {
if (UI_but_is_utf8(but)) {
- buf_len -= BLI_utf8_invalid_strip(pbuf, (size_t)buf_len);
+ buf_len -= BLI_str_utf8_invalid_strip(pbuf, (size_t)buf_len);
}
ui_textedit_insert_buf(but, data, pbuf, buf_len);
@@ -3536,7 +3527,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
if (but) {
if (UI_but_is_utf8(but)) {
- const int strip = BLI_utf8_invalid_strip(but->editstr, strlen(but->editstr));
+ const int strip = BLI_str_utf8_invalid_strip(but->editstr, strlen(but->editstr));
/* not a file?, strip non utf-8 chars */
if (strip) {
/* won't happen often so isn't that annoying to keep it here for a while */
@@ -6034,7 +6025,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co
* the slot menu fails to switch a second time.
*
* The active state of the button could be maintained some other way
- * and remove this mousemove event.
+ * and remove this mouse-move event.
*/
WM_event_add_mousemove(data->window);
@@ -8373,7 +8364,7 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
}
}
- /* wait for mousemove to enable drag */
+ /* Wait for mouse-move to enable drag. */
if (state == BUTTON_STATE_WAIT_DRAG) {
but->flag &= ~UI_SELECT;
}
@@ -8640,9 +8631,9 @@ static void button_activate_exit(
ui_but_update(but);
}
- /* adds empty mousemove in queue for re-init handler, in case mouse is
+ /* Adds empty mouse-move in queue for re-initialize handler, in case mouse is
* still over a button. We cannot just check for this ourselves because
- * at this point the mouse may be over a button in another region */
+ * at this point the mouse may be over a button in another region. */
if (mousemove) {
WM_event_add_mousemove(CTX_wm_window(C));
}
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 2d59bfb92c8..f739830cfdb 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -299,13 +299,14 @@ static void vicon_keytype_draw_wrapper(
const float yco = y + h / 2 + 0.5f;
GPUVertFormat *format = immVertexFormat();
- const uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- const uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
- uint color_id = GPU_vertformat_attr_add(
+ KeyframeShaderBindings sh_bindings;
+ sh_bindings.pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ sh_bindings.size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+ sh_bindings.color_id = GPU_vertformat_attr_add(
format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- uint outline_color_id = GPU_vertformat_attr_add(
+ sh_bindings.outline_color_id = GPU_vertformat_attr_add(
format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- const uint flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
+ sh_bindings.flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
GPU_program_point_size(true);
immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
@@ -326,11 +327,7 @@ static void vicon_keytype_draw_wrapper(
key_type,
KEYFRAME_SHAPE_BOTH,
alpha,
- pos_id,
- size_id,
- color_id,
- outline_color_id,
- flags_id,
+ &sh_bindings,
handle_type,
KEYFRAME_EXTREME_NONE);
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 6b0b8e8df8f..d61104f094e 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1177,6 +1177,8 @@ uiBut *ui_list_find_mouse_over_ex(const struct ARegion *region,
bool ui_but_contains_password(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
+size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen)
+ ATTR_NONNULL(1, 2);
size_t ui_but_drawstr_len_without_sep_char(const uiBut *but);
size_t ui_but_tip_len_only_first_line(const uiBut *but);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 97d01ac3763..a64797af24f 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -1447,10 +1447,6 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
is_alpha = (region->overlap && (theme_col_back[3] != 255));
- if (fstyle->kerning == 1) {
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
BLF_enable(fontid, BLF_ROTATION);
BLF_rotation(fontid, M_PI_2);
// UI_fontstyle_set(&style->widget);
@@ -1620,10 +1616,6 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
GPU_line_smooth(false);
BLF_disable(fontid, BLF_ROTATION);
-
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
}
#undef TABS_PADDING_BETWEEN_FACTOR
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
index 8534c95b6fd..09429bb6df5 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -23,6 +23,7 @@
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_rect.h"
+#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_screen_types.h"
@@ -553,6 +554,12 @@ size_t ui_but_drawstr_len_without_sep_char(const uiBut *but)
return strlen(but->drawstr);
}
+size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen)
+{
+ size_t str_len_clip = ui_but_drawstr_len_without_sep_char(but);
+ return BLI_strncpy_rlen(str, but->drawstr, min_zz(str_len_clip + 1, str_maxlen));
+}
+
size_t ui_but_tip_len_only_first_line(const uiBut *but)
{
if (but->tip == NULL) {
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 10bc3760b42..a8f289702f8 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -1175,9 +1175,6 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
data->wrap_width = min_ii(UI_TIP_MAXWIDTH * U.pixelsize / aspect, winx - (UI_TIP_PADDING * 2));
font_flag |= BLF_WORD_WRAP;
- if (data->fstyle.kerning == 1) {
- font_flag |= BLF_KERNING_DEFAULT;
- }
BLF_enable(data->fstyle.uifont_id, font_flag);
BLF_enable(blf_mono_font, font_flag);
BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width);
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 88ab6a377d0..804156ba48c 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -83,7 +83,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->paneltitle.uifont_id = uifont_id;
style->paneltitle.points = UI_DEFAULT_TITLE_POINTS;
- style->paneltitle.kerning = 1;
style->paneltitle.shadow = 3;
style->paneltitle.shadx = 0;
style->paneltitle.shady = -1;
@@ -92,7 +91,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->grouplabel.uifont_id = uifont_id;
style->grouplabel.points = UI_DEFAULT_TITLE_POINTS;
- style->grouplabel.kerning = 1;
style->grouplabel.shadow = 3;
style->grouplabel.shadx = 0;
style->grouplabel.shady = -1;
@@ -101,7 +99,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->widgetlabel.uifont_id = uifont_id;
style->widgetlabel.points = UI_DEFAULT_TEXT_POINTS;
- style->widgetlabel.kerning = 1;
style->widgetlabel.shadow = 3;
style->widgetlabel.shadx = 0;
style->widgetlabel.shady = -1;
@@ -110,7 +107,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->widget.uifont_id = uifont_id;
style->widget.points = UI_DEFAULT_TEXT_POINTS;
- style->widget.kerning = 1;
style->widget.shadow = 1;
style->widget.shady = -1;
style->widget.shadowalpha = 0.5f;
@@ -164,9 +160,6 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs,
BLF_shadow(fs->uifont_id, fs->shadow, shadow_color);
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
}
- if (fs->kerning == 1) {
- font_flag |= BLF_KERNING_DEFAULT;
- }
if (fs_params->word_wrap == 1) {
font_flag |= BLF_WORD_WRAP;
}
@@ -278,19 +271,12 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
}
- if (fs->kerning == 1) {
- BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
-
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
BLF_disable(fs->uifont_id, BLF_ROTATION);
BLF_disable(fs->uifont_id, BLF_CLIPPING);
if (fs->shadow) {
BLF_disable(fs->uifont_id, BLF_SHADOW);
}
- if (fs->kerning == 1) {
- BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
}
/**
@@ -302,18 +288,10 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
void UI_fontstyle_draw_simple(
const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
{
- if (fs->kerning == 1) {
- BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
-
UI_fontstyle_set(fs);
BLF_position(fs->uifont_id, x, y, 0.0f);
BLF_color4ubv(fs->uifont_id, col);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
-
- if (fs->kerning == 1) {
- BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
}
/**
@@ -326,10 +304,6 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
const float col_fg[4],
const float col_bg[4])
{
- if (fs->kerning == 1) {
- BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
-
UI_fontstyle_set(fs);
{
@@ -357,10 +331,6 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
BLF_position(fs->uifont_id, x, y, 0.0f);
BLF_color4fv(fs->uifont_id, col_fg);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
-
- if (fs->kerning == 1) {
- BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
}
/* ************** helpers ************************ */
@@ -405,21 +375,8 @@ const uiStyle *UI_style_get_dpi(void)
int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str)
{
- int width;
-
- if (fs->kerning == 1) {
- /* for BLF_width */
- BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
-
UI_fontstyle_set(fs);
- width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
-
- if (fs->kerning == 1) {
- BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
- }
-
- return width;
+ return (int)BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
}
int UI_fontstyle_height_max(const uiFontStyle *fs)
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 766840909cc..0e5a6a79137 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -84,6 +84,8 @@
#include "ED_screen.h"
#include "ED_undo.h"
+#include "RE_engine.h"
+
#include "RNA_access.h"
#include "WM_api.h"
@@ -2621,6 +2623,72 @@ static void constraint_active_func(bContext *UNUSED(C), void *ob_v, void *con_v)
ED_object_constraint_active_set(ob_v, con_v);
}
+static void constraint_ops_extra_draw(bContext *C, uiLayout *layout, void *con_v)
+{
+ PointerRNA op_ptr;
+ uiLayout *row;
+ bConstraint *con = (bConstraint *)con_v;
+
+ PointerRNA ptr;
+ Object *ob = ED_object_active_context(C);
+
+ RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
+ uiLayoutSetContextPointer(layout, "constraint", &ptr);
+ uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
+
+ uiLayoutSetUnitsX(layout, 4.0f);
+
+ /* Apply. */
+ uiItemO(layout,
+ CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"),
+ ICON_CHECKMARK,
+ "CONSTRAINT_OT_apply");
+
+ /* Duplicate. */
+ uiItemO(layout,
+ CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Duplicate"),
+ ICON_DUPLICATE,
+ "CONSTRAINT_OT_copy");
+
+ uiItemO(layout,
+ CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy to Selected"),
+ 0,
+ "CONSTRAINT_OT_copy_to_selected");
+
+ uiItemS(layout);
+
+ /* Move to first. */
+ row = uiLayoutColumn(layout, false);
+ uiItemFullO(row,
+ "CONSTRAINT_OT_move_to_index",
+ IFACE_("Move to First"),
+ ICON_TRIA_UP,
+ NULL,
+ WM_OP_INVOKE_DEFAULT,
+ 0,
+ &op_ptr);
+ RNA_int_set(&op_ptr, "index", 0);
+ if (!con->prev) {
+ uiLayoutSetEnabled(row, false);
+ }
+
+ /* Move to last. */
+ row = uiLayoutColumn(layout, false);
+ uiItemFullO(row,
+ "CONSTRAINT_OT_move_to_index",
+ IFACE_("Move to Last"),
+ ICON_TRIA_DOWN,
+ NULL,
+ WM_OP_INVOKE_DEFAULT,
+ 0,
+ &op_ptr);
+ ListBase *constraint_list = ED_object_constraint_list_from_constraint(ob, con, NULL);
+ RNA_int_set(&op_ptr, "index", BLI_listbase_count(constraint_list) - 1);
+ if (!con->next) {
+ uiLayoutSetEnabled(row, false);
+ }
+}
+
static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *con)
{
bPoseChannel *pchan = BKE_pose_channel_active(ob);
@@ -2652,11 +2720,13 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co
UI_block_emboss_set(block, UI_EMBOSS);
+ uiLayout *row = uiLayoutRow(layout, true);
+
if (proxy_protected == 0) {
- uiItemR(layout, &ptr, "name", 0, "", ICON_NONE);
+ uiItemR(row, &ptr, "name", 0, "", ICON_NONE);
}
else {
- uiItemL(layout, con->name, ICON_NONE);
+ uiItemL(row, con->name, ICON_NONE);
}
/* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
@@ -2697,22 +2767,22 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co
UI_block_emboss_set(block, UI_EMBOSS);
}
else {
- /* enabled */
- UI_block_emboss_set(block, UI_EMBOSS_NONE_OR_STATUS);
- uiItemR(layout, &ptr, "mute", 0, "", 0);
- UI_block_emboss_set(block, UI_EMBOSS);
+ /* Enabled eye icon. */
+ uiItemR(row, &ptr, "enabled", 0, "", ICON_NONE);
- uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
+ /* Extra operators menu. */
+ uiItemMenuF(row, "", ICON_DOWNARROW_HLT, constraint_ops_extra_draw, con);
/* Close 'button' - emboss calls here disable drawing of 'button' behind X */
- UI_block_emboss_set(block, UI_EMBOSS_NONE);
- uiItemO(layout, "", ICON_X, "CONSTRAINT_OT_delete");
- UI_block_emboss_set(block, UI_EMBOSS);
-
- /* Some extra padding at the end, so the 'x' icon isn't too close to drag button. */
- uiItemS(layout);
+ sub = uiLayoutRow(row, false);
+ uiLayoutSetEmboss(sub, UI_EMBOSS_NONE);
+ uiLayoutSetOperatorContext(sub, WM_OP_INVOKE_DEFAULT);
+ uiItemO(sub, "", ICON_X, "CONSTRAINT_OT_delete");
}
+ /* Some extra padding at the end, so the 'x' icon isn't too close to drag button. */
+ uiItemS(layout);
+
/* Set but-locks for protected settings (magic numbers are used here!) */
if (proxy_protected) {
UI_block_lock_set(block, true, TIP_("Cannot edit Proxy-Protected Constraint"));
@@ -6395,6 +6465,41 @@ void uiTemplateCacheFile(uiLayout *layout,
row = uiLayoutRow(layout, false);
uiItemR(row, &fileptr, "is_sequence", 0, NULL, ICON_NONE);
+ /* Only enable render procedural option if the active engine supports it. */
+ const struct RenderEngineType *engine_type = CTX_data_engine_type(C);
+
+ Scene *scene = CTX_data_scene(C);
+ const bool engine_supports_procedural = RE_engine_supports_alembic_procedural(engine_type,
+ scene);
+
+ if (!engine_supports_procedural) {
+ row = uiLayoutRow(layout, false);
+ /* For Cycles, verify that experimental features are enabled. */
+ if (BKE_scene_uses_cycles(scene) && !BKE_scene_uses_cycles_experimental_features(scene)) {
+ uiItemL(row,
+ "The Cycles Alembic Procedural is only available with the experimental feature set",
+ ICON_INFO);
+ }
+ else {
+ uiItemL(row, "The active render engine does not have an Alembic Procedural", ICON_INFO);
+ }
+ }
+
+ row = uiLayoutRow(layout, false);
+ uiLayoutSetActive(row, engine_supports_procedural);
+ uiItemR(row, &fileptr, "use_render_procedural", 0, NULL, ICON_NONE);
+
+ const bool use_render_procedural = RNA_boolean_get(&fileptr, "use_render_procedural");
+ const bool use_prefetch = RNA_boolean_get(&fileptr, "use_prefetch");
+
+ row = uiLayoutRow(layout, false);
+ uiLayoutSetEnabled(row, use_render_procedural);
+ uiItemR(row, &fileptr, "use_prefetch", 0, NULL, ICON_NONE);
+
+ sub = uiLayoutRow(layout, false);
+ uiLayoutSetEnabled(sub, use_prefetch && use_render_procedural);
+ uiItemR(sub, &fileptr, "prefetch_cache_size", 0, NULL, ICON_NONE);
+
row = uiLayoutRowWithHeading(layout, true, IFACE_("Override Frame"));
sub = uiLayoutRow(row, true);
uiLayoutSetPropDecorate(sub, false);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index d3481c449ac..48f638dac33 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1576,11 +1576,6 @@ float UI_text_clip_middle_ex(const uiFontStyle *fstyle,
/* need to set this first */
UI_fontstyle_set(fstyle);
- if (fstyle->kerning == 1) {
- /* for BLF_width */
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
float strwidth = BLF_width(fstyle->uifont_id, str, max_len);
if ((okwidth > 0.0f) && (strwidth > okwidth)) {
@@ -1674,10 +1669,6 @@ float UI_text_clip_middle_ex(const uiFontStyle *fstyle,
strwidth = BLF_width(fstyle->uifont_id, str, max_len);
}
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
BLI_assert(strwidth <= okwidth);
return strwidth;
@@ -1736,11 +1727,6 @@ static void ui_text_clip_cursor(const uiFontStyle *fstyle, uiBut *but, const rct
/* need to set this first */
UI_fontstyle_set(fstyle);
- if (fstyle->kerning == 1) {
- /* for BLF_width */
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
/* define ofs dynamically */
if (but->ofs > but->pos) {
but->ofs = but->pos;
@@ -1785,10 +1771,6 @@ static void ui_text_clip_cursor(const uiFontStyle *fstyle, uiBut *but, const rct
}
}
}
-
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
}
/**
@@ -1806,11 +1788,6 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
/* need to set this first */
UI_fontstyle_set(fstyle);
- if (fstyle->kerning == 1) {
- /* for BLF_width */
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr));
but->ofs = 0;
@@ -1870,10 +1847,6 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
but->strwidth = strwidth;
but->drawstr[drawstr_len] = 0;
}
-
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
}
#ifdef WITH_INPUT_IME
@@ -1985,11 +1958,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
align = UI_STYLE_TEXT_CENTER;
}
- if (fstyle->kerning == 1) {
- /* for BLF_width */
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
/* Special case: when we're entering text for multiple buttons,
* don't draw the text for any of the multi-editing buttons */
if (UNLIKELY(but->flag & UI_BUT_DRAG_MULTI)) {
@@ -2151,10 +2119,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
#endif
}
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
#if 0
ui_rasterpos_safe(x, y, but->aspect);
transopts = ui_translate_buttons();
@@ -2232,10 +2196,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
}
if (ul_index != -1) {
- if (fstyle->kerning == 1) {
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2));
struct UnderlineData ul_data = {
@@ -2256,10 +2216,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
BLF_position(fstyle->uifont_id, pos_x, pos_y, 0.0f);
BLF_color4ubv(fstyle->uifont_id, wcol->text);
BLF_draw(fstyle->uifont_id, "_", 2);
-
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
}
}
}
@@ -5369,11 +5325,6 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
/* need to set this first */
UI_fontstyle_set(fstyle);
- if (fstyle->kerning == 1) {
- /* for BLF_width */
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
if (separator_type == UI_MENU_ITEM_SEPARATOR_SHORTCUT) {
/* Shrink rect to exclude the shortcut string. */
rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_DPI_ICON_SIZE;
@@ -5398,10 +5349,6 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
else {
BLI_assert_msg(0, "Unknwon menu item separator type");
}
-
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
}
}
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index c9bfd883332..e13b69a9763 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -631,7 +631,7 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_NODE_SHADER:
cp = ts->nodeclass_shader;
break;
- case TH_NODE_CONVERTOR:
+ case TH_NODE_CONVERTER:
cp = ts->syntaxv;
break;
case TH_NODE_GROUP:
diff --git a/source/blender/editors/interface/view2d_edge_pan.c b/source/blender/editors/interface/view2d_edge_pan.c
index 1d300c7b275..eaf8ef30311 100644
--- a/source/blender/editors/interface/view2d_edge_pan.c
+++ b/source/blender/editors/interface/view2d_edge_pan.c
@@ -71,7 +71,8 @@ void UI_view2d_edge_pan_init(bContext *C,
float outside_pad,
float speed_ramp,
float max_speed,
- float delay)
+ float delay,
+ float zoom_influence)
{
if (!UI_view2d_edge_pan_poll(C)) {
return;
@@ -89,6 +90,7 @@ void UI_view2d_edge_pan_init(bContext *C,
vpd->speed_ramp = speed_ramp;
vpd->max_speed = max_speed;
vpd->delay = delay;
+ vpd->zoom_influence = zoom_influence;
/* Calculate translation factor, based on size of view. */
const float winx = (float)(BLI_rcti_size_x(&vpd->region->winrct) + 1);
@@ -104,6 +106,7 @@ void UI_view2d_edge_pan_reset(View2DEdgePanData *vpd)
vpd->edge_pan_start_time_x = 0.0;
vpd->edge_pan_start_time_y = 0.0;
vpd->edge_pan_last_time = PIL_check_seconds_timer();
+ vpd->initial_rect = vpd->region->v2d.cur;
}
/**
@@ -168,9 +171,15 @@ static float edge_pan_speed(View2DEdgePanData *vpd,
/* Apply a fade in to the speed based on a start time delay. */
const double start_time = x_dir ? vpd->edge_pan_start_time_x : vpd->edge_pan_start_time_y;
- const float delay_factor = smootherstep(vpd->delay, (float)(current_time - start_time));
+ const float delay_factor = vpd->delay > 0.01f ?
+ smootherstep(vpd->delay, (float)(current_time - start_time)) :
+ 1.0f;
- return distance_factor * delay_factor * vpd->max_speed * U.widget_unit * (float)U.dpi_fac;
+ /* Zoom factor increases speed when zooming in and decreases speed when zooming out. */
+ const float zoomx = (float)(BLI_rcti_size_x(&region->winrct) + 1) / BLI_rctf_size_x(&region->v2d.cur);
+ const float zoom_factor = 1.0f + CLAMPIS(vpd->zoom_influence, 0.0f, 1.0f) * (zoomx - 1.0f);
+
+ return distance_factor * delay_factor * zoom_factor * vpd->max_speed * U.widget_unit * (float)U.dpi_fac;
}
static void edge_pan_apply_delta(bContext *C, View2DEdgePanData *vpd, float dx, float dy)
@@ -264,6 +273,27 @@ void UI_view2d_edge_pan_apply_event(bContext *C, View2DEdgePanData *vpd, const w
UI_view2d_edge_pan_apply(C, vpd, event->x, event->y);
}
+void UI_view2d_edge_pan_cancel(bContext *C, View2DEdgePanData *vpd)
+{
+ View2D *v2d = vpd->v2d;
+ if (!v2d) {
+ return;
+ }
+
+ v2d->cur = vpd->initial_rect;
+
+ /* Inform v2d about changes after this operation. */
+ UI_view2d_curRect_changed(C, v2d);
+
+ /* Don't rebuild full tree in outliner, since we're just changing our view. */
+ ED_region_tag_redraw_no_rebuild(vpd->region);
+
+ /* Request updates to be done. */
+ WM_event_add_mousemove(CTX_wm_window(C));
+
+ UI_view2d_sync(vpd->screen, vpd->area, v2d, V2D_LOCK_COPY);
+}
+
void UI_view2d_edge_pan_operator_properties(wmOperatorType *ot)
{
/* Default values for edge panning operators. */
@@ -272,7 +302,8 @@ void UI_view2d_edge_pan_operator_properties(wmOperatorType *ot)
/*outside_pad*/ 0.0f,
/*speed_ramp*/ 1.0f,
/*max_speed*/ 500.0f,
- /*delay*/ 1.0f);
+ /*delay*/ 1.0f,
+ /*zoom_influence*/ 0.0f);
}
void UI_view2d_edge_pan_operator_properties_ex(struct wmOperatorType *ot,
@@ -280,7 +311,8 @@ void UI_view2d_edge_pan_operator_properties_ex(struct wmOperatorType *ot,
float outside_pad,
float speed_ramp,
float max_speed,
- float delay)
+ float delay,
+ float zoom_influence)
{
RNA_def_float(
ot->srna,
@@ -329,6 +361,15 @@ void UI_view2d_edge_pan_operator_properties_ex(struct wmOperatorType *ot,
"Delay in seconds before maximum speed is reached",
0.0f,
10.0f);
+ RNA_def_float(ot->srna,
+ "zoom_influence",
+ zoom_influence,
+ 0.0f,
+ 1.0f,
+ "Zoom Influence",
+ "Influence of the zoom factor on scroll speed",
+ 0.0f,
+ 1.0f);
}
void UI_view2d_edge_pan_operator_init(bContext *C, View2DEdgePanData *vpd, wmOperator *op)
@@ -339,7 +380,8 @@ void UI_view2d_edge_pan_operator_init(bContext *C, View2DEdgePanData *vpd, wmOpe
RNA_float_get(op->ptr, "outside_padding"),
RNA_float_get(op->ptr, "speed_ramp"),
RNA_float_get(op->ptr, "max_speed"),
- RNA_float_get(op->ptr, "delay"));
+ RNA_float_get(op->ptr, "delay"),
+ RNA_float_get(op->ptr, "zoom_influence"));
}
/** \} */
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index 12890552b1d..bbff37221e8 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -615,6 +615,7 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(col, imfptr, "set_frame_range", 0, NULL, ICON_NONE);
uiItemR(col, imfptr, "is_sequence", 0, NULL, ICON_NONE);
uiItemR(col, imfptr, "validate_meshes", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "always_add_cache_reader", 0, NULL, ICON_NONE);
}
static void wm_alembic_import_draw(bContext *UNUSED(C), wmOperator *op)
@@ -645,6 +646,7 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence");
const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
+ const bool always_add_cache_reader = RNA_boolean_get(op->ptr, "always_add_cache_reader");
const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job");
int offset = 0;
@@ -672,6 +674,7 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
sequence_len,
offset,
validate_meshes,
+ always_add_cache_reader,
as_background_job);
return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
@@ -722,6 +725,13 @@ void WM_OT_alembic_import(wmOperatorType *ot)
"Check imported mesh objects for invalid data (slow)");
RNA_def_boolean(ot->srna,
+ "always_add_cache_reader",
+ false,
+ "Always Add Cache Reader",
+ "Add cache modifiers and constraints to imported objects even if they are not "
+ "animated so that they can be updated when reloading the Alembic archive");
+
+ RNA_def_boolean(ot->srna,
"is_sequence",
false,
"Is Sequence",
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 73f6a3f3238..3e3593d18fd 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -2630,24 +2630,24 @@ static void knife_init_colors(KnifeColors *colors)
}
/* called when modal loop selection gets set up... */
-static void knifetool_init(bContext *C,
+static void knifetool_init(ViewContext *vc,
KnifeTool_OpData *kcd,
const bool only_select,
const bool cut_through,
const bool is_interactive)
{
- Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
+ kcd->vc = *vc;
+
+ Scene *scene = vc->scene;
+ Object *obedit = vc->obedit;
/* assign the drawing handle for drawing preview line... */
kcd->scene = scene;
kcd->ob = obedit;
- kcd->region = CTX_wm_region(C);
+ kcd->region = vc->region;
invert_m4_m4_safe_ortho(kcd->ob_imat, kcd->ob->obmat);
- em_setup_viewcontext(C, &kcd->vc);
-
kcd->em = BKE_editmesh_from_object(kcd->ob);
/* cut all the way through the mesh if use_occlude_geometry button not pushed */
@@ -2694,14 +2694,14 @@ static void knifetool_init(bContext *C,
}
/* called when modal loop selection is done... */
-static void knifetool_exit_ex(bContext *C, KnifeTool_OpData *kcd)
+static void knifetool_exit_ex(KnifeTool_OpData *kcd)
{
if (!kcd) {
return;
}
if (kcd->is_interactive) {
- WM_cursor_modal_restore(CTX_wm_window(C));
+ WM_cursor_modal_restore(kcd->vc.win);
/* deactivate the extra drawing stuff in 3D-View */
ED_region_draw_cb_exit(kcd->region->type, kcd->draw_handle);
@@ -2735,10 +2735,10 @@ static void knifetool_exit_ex(bContext *C, KnifeTool_OpData *kcd)
/* destroy kcd itself */
MEM_freeN(kcd);
}
-static void knifetool_exit(bContext *C, wmOperator *op)
+static void knifetool_exit(wmOperator *op)
{
KnifeTool_OpData *kcd = op->customdata;
- knifetool_exit_ex(C, kcd);
+ knifetool_exit_ex(kcd);
op->customdata = NULL;
}
@@ -2827,10 +2827,10 @@ static void knifetool_finish(wmOperator *op)
/** \name Operator (#MESH_OT_knife_tool)
* \{ */
-static void knifetool_cancel(bContext *C, wmOperator *op)
+static void knifetool_cancel(bContext *UNUSED(C), wmOperator *op)
{
/* this is just a wrapper around exit() */
- knifetool_exit(C, op);
+ knifetool_exit(op);
}
wmKeyMap *knifetool_modal_keymap(wmKeyConfig *keyconf)
@@ -2872,7 +2872,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool do_refresh = false;
if (!obedit || obedit->type != OB_MESH || BKE_editmesh_from_object(obedit) != kcd->em) {
- knifetool_exit(C, op);
+ knifetool_exit(op);
ED_workspace_status_text(C, NULL);
return OPERATOR_FINISHED;
}
@@ -2893,7 +2893,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* finish */
ED_region_tag_redraw(kcd->region);
- knifetool_exit(C, op);
+ knifetool_exit(op);
ED_workspace_status_text(C, NULL);
return OPERATOR_CANCELLED;
@@ -2902,7 +2902,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event)
ED_region_tag_redraw(kcd->region);
knifetool_finish(op);
- knifetool_exit(C, op);
+ knifetool_exit(op);
ED_workspace_status_text(C, NULL);
return OPERATOR_FINISHED;
@@ -3066,8 +3066,11 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
const bool cut_through = !RNA_boolean_get(op->ptr, "use_occlude_geometry");
const bool wait_for_input = RNA_boolean_get(op->ptr, "wait_for_input");
+ ViewContext vc;
KnifeTool_OpData *kcd;
+ em_setup_viewcontext(C, &vc);
+
if (only_select) {
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -3080,7 +3083,7 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* alloc new customdata */
kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
- knifetool_init(C, kcd, only_select, cut_through, true);
+ knifetool_init(&vc, kcd, only_select, cut_through, true);
op->flag |= OP_IS_MODAL_CURSOR_REGION;
@@ -3165,7 +3168,7 @@ static bool edbm_mesh_knife_point_isect(LinkNode *polys, const float cent_ss[2])
/**
* \param use_tag: When set, tag all faces inside the polylines.
*/
-void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_through)
+void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_through)
{
KnifeTool_OpData *kcd;
@@ -3176,7 +3179,7 @@ void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_throug
kcd = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
- knifetool_init(C, kcd, only_select, cut_through, is_interactive);
+ knifetool_init(vc, kcd, only_select, cut_through, is_interactive);
kcd->ignore_edge_snapping = true;
kcd->ignore_vert_snapping = true;
@@ -3313,7 +3316,7 @@ void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_throug
#undef F_ISECT_SET_OUTSIDE
}
- knifetool_exit_ex(C, kcd);
+ knifetool_exit_ex(kcd);
kcd = NULL;
}
}
diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c
index 09b17acf56d..669a09b3fd3 100644
--- a/source/blender/editors/mesh/editmesh_knife_project.c
+++ b/source/blender/editors/mesh/editmesh_knife_project.c
@@ -32,6 +32,8 @@
#include "BKE_curve.h"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_object.h"
@@ -114,7 +116,7 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C,
BKE_nurbList_free(&nurbslist);
if (me_eval_needs_free) {
- BKE_mesh_free((struct Mesh *)me_eval);
+ BKE_id_free(NULL, (ID *)me_eval);
}
}
@@ -124,21 +126,39 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C,
static int knifeproject_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
const bool cut_through = RNA_boolean_get(op->ptr, "cut_through");
LinkNode *polys = NULL;
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
- if (ob != obedit) {
- polys = knifeproject_poly_from_object(C, scene, ob, polys);
+ if (BKE_object_is_in_editmode(ob)) {
+ continue;
}
+ polys = knifeproject_poly_from_object(C, scene, ob, polys);
}
CTX_DATA_END;
- if (polys) {
- EDBM_mesh_knife(C, polys, true, cut_through);
+ if (polys == NULL) {
+ BKE_report(op->reports,
+ RPT_ERROR,
+ "No other selected objects have wire or boundary edges to use for projection");
+ return OPERATOR_CANCELLED;
+ }
+
+ ViewContext vc;
+ em_setup_viewcontext(C, &vc);
+
+ /* TODO: Ideally meshes would occlude each other, currently they don't
+ * since each knife-project runs as a separate operation. */
+ uint objects_len;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
+ vc.view_layer, vc.v3d, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ ED_view3d_viewcontext_init_object(&vc, obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+
+ EDBM_mesh_knife(&vc, polys, true, cut_through);
/* select only tagged faces */
BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false);
@@ -148,16 +168,12 @@ static int knifeproject_exec(bContext *C, wmOperator *op)
BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG);
BM_mesh_select_mode_flush(em->bm);
-
- BLI_linklist_freeN(polys);
-
- return OPERATOR_FINISHED;
}
+ MEM_freeN(objects);
+
+ BLI_linklist_freeN(polys);
- BKE_report(op->reports,
- RPT_ERROR,
- "No other selected objects have wire or boundary edges to use for projection");
- return OPERATOR_CANCELLED;
+ return OPERATOR_FINISHED;
}
void MESH_OT_knife_project(wmOperatorType *ot)
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 1b6643da1aa..956658bd2b7 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -467,40 +467,50 @@ static int edbm_delete_exec(bContext *C, wmOperator *op)
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const int type = RNA_enum_get(op->ptr, "type");
- BM_custom_loop_normals_to_vector_layer(em->bm);
-
switch (type) {
case MESH_DELETE_VERT: /* Erase Vertices */
- if (!(em->bm->totvertsel &&
- EDBM_op_callf(em, op, "delete geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS))) {
+ if (em->bm->totvertsel == 0) {
+ continue;
+ }
+ BM_custom_loop_normals_to_vector_layer(em->bm);
+ if (!EDBM_op_callf(em, op, "delete geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) {
continue;
}
break;
case MESH_DELETE_EDGE: /* Erase Edges */
- if (!(em->bm->totedgesel &&
- EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES))) {
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
+ BM_custom_loop_normals_to_vector_layer(em->bm);
+ if (!EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) {
continue;
}
break;
case MESH_DELETE_FACE: /* Erase Faces */
- if (!(em->bm->totfacesel &&
- EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES))) {
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
+ BM_custom_loop_normals_to_vector_layer(em->bm);
+ if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) {
continue;
}
break;
- case MESH_DELETE_EDGE_FACE:
- /* Edges and Faces */
- if (!((em->bm->totedgesel || em->bm->totfacesel) &&
- EDBM_op_callf(
- em, op, "delete geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES))) {
+ case MESH_DELETE_EDGE_FACE: /* Edges and Faces */
+ if ((em->bm->totedgesel == 0) && (em->bm->totfacesel == 0)) {
+ continue;
+ }
+ BM_custom_loop_normals_to_vector_layer(em->bm);
+ if (!EDBM_op_callf(
+ em, op, "delete geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)) {
continue;
}
break;
- case MESH_DELETE_ONLY_FACE:
- /* Only faces. */
- if (!(em->bm->totfacesel &&
- EDBM_op_callf(
- em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_ONLYFACES))) {
+ case MESH_DELETE_ONLY_FACE: /* Only faces. */
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
+ BM_custom_loop_normals_to_vector_layer(em->bm);
+ if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_ONLYFACES)) {
continue;
}
break;
@@ -2183,6 +2193,61 @@ static bool flip_custom_normals(BMesh *bm, BMLoopNorEditDataArray *lnors_ed_arr)
/* -------------------------------------------------------------------- */
/** \name Flip Normals Operator
* \{ */
+
+static void edbm_flip_normals_custom_loop_normals(Object *obedit, BMEditMesh *em)
+{
+ if (!CustomData_has_layer(&em->bm->ldata, CD_CUSTOMLOOPNORMAL)) {
+ return;
+ }
+
+ /* The mesh has custom normal data, flip them. */
+ BMesh *bm = em->bm;
+
+ BM_lnorspace_update(bm);
+ BMLoopNorEditDataArray *lnors_ed_arr = BM_loop_normal_editdata_array_init(bm, false);
+ BMLoopNorEditData *lnor_ed = lnors_ed_arr->lnor_editdata;
+
+ for (int i = 0; i < lnors_ed_arr->totloop; i++, lnor_ed++) {
+ negate_v3(lnor_ed->nloc);
+
+ BKE_lnor_space_custom_normal_to_data(
+ bm->lnor_spacearr->lspacearr[lnor_ed->loop_index], lnor_ed->nloc, lnor_ed->clnors_data);
+ }
+ BM_loop_normal_editdata_array_free(lnors_ed_arr);
+ EDBM_update(obedit->data,
+ &(const struct EDBMUpdate_Params){
+ .calc_looptri = true,
+ .calc_normals = false,
+ .is_destructive = false,
+ });
+}
+
+static void edbm_flip_normals_face_winding(wmOperator *op, Object *obedit, BMEditMesh *em)
+{
+
+ bool has_flipped_faces = false;
+
+ /* See if we have any custom normals to flip. */
+ BMLoopNorEditDataArray *lnors_ed_arr = flip_custom_normals_init_data(em->bm);
+
+ if (EDBM_op_callf(em, op, "reverse_faces faces=%hf flip_multires=%b", BM_ELEM_SELECT, true)) {
+ has_flipped_faces = true;
+ }
+
+ if (flip_custom_normals(em->bm, lnors_ed_arr) || has_flipped_faces) {
+ EDBM_update(obedit->data,
+ &(const struct EDBMUpdate_Params){
+ .calc_looptri = true,
+ .calc_normals = false,
+ .is_destructive = false,
+ });
+ }
+
+ if (lnors_ed_arr != NULL) {
+ BM_loop_normal_editdata_array_free(lnors_ed_arr);
+ }
+}
+
static int edbm_flip_normals_exec(bContext *C, wmOperator *op)
{
const bool only_clnors = RNA_boolean_get(op->ptr, "only_clnors");
@@ -2197,56 +2262,16 @@ static int edbm_flip_normals_exec(bContext *C, wmOperator *op)
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (only_clnors) {
- if (CustomData_has_layer(&em->bm->ldata, CD_CUSTOMLOOPNORMAL)) {
- /* The mesh has custom normal data, flip them. */
- BMesh *bm = em->bm;
-
- BM_lnorspace_update(bm);
- BMLoopNorEditDataArray *lnors_ed_arr = BM_loop_normal_editdata_array_init(bm, false);
- BMLoopNorEditData *lnor_ed = lnors_ed_arr->lnor_editdata;
-
- for (int i = 0; i < lnors_ed_arr->totloop; i++, lnor_ed++) {
- negate_v3(lnor_ed->nloc);
-
- BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[lnor_ed->loop_index],
- lnor_ed->nloc,
- lnor_ed->clnors_data);
- }
- BM_loop_normal_editdata_array_free(lnors_ed_arr);
- EDBM_update(obedit->data,
- &(const struct EDBMUpdate_Params){
- .calc_looptri = true,
- .calc_normals = false,
- .is_destructive = false,
- });
+ if ((em->bm->totvertsel == 0) && (em->bm->totedgesel == 0) && (em->bm->totfacesel == 0)) {
+ continue;
}
- continue;
- }
-
- if (em->bm->totfacesel == 0) {
- continue;
- }
-
- bool has_flipped_faces = false;
-
- /* See if we have any custom normals to flip. */
- BMLoopNorEditDataArray *lnors_ed_arr = flip_custom_normals_init_data(em->bm);
-
- if (EDBM_op_callf(em, op, "reverse_faces faces=%hf flip_multires=%b", BM_ELEM_SELECT, true)) {
- has_flipped_faces = true;
- }
-
- if (flip_custom_normals(em->bm, lnors_ed_arr) || has_flipped_faces) {
- EDBM_update(obedit->data,
- &(const struct EDBMUpdate_Params){
- .calc_looptri = true,
- .calc_normals = false,
- .is_destructive = false,
- });
+ edbm_flip_normals_custom_loop_normals(obedit, em);
}
-
- if (lnors_ed_arr != NULL) {
- BM_loop_normal_editdata_array_free(lnors_ed_arr);
+ else {
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
+ edbm_flip_normals_face_winding(op, obedit, em);
}
}
@@ -5551,24 +5576,24 @@ static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op)
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
view_layer, CTX_wm_view3d(C), &objects_len);
- bool is_face_pair;
+ const bool do_seam = RNA_boolean_get(op->ptr, "seam");
+ const bool do_sharp = RNA_boolean_get(op->ptr, "sharp");
+ const bool do_uvs = RNA_boolean_get(op->ptr, "uvs");
+ const bool do_vcols = RNA_boolean_get(op->ptr, "vcols");
+ const bool do_materials = RNA_boolean_get(op->ptr, "materials");
+ float angle_face_threshold, angle_shape_threshold;
+ bool is_face_pair;
{
int totelem_sel[3];
EDBM_mesh_stats_multi(objects, objects_len, NULL, totelem_sel);
is_face_pair = (totelem_sel[2] == 2);
}
- for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
- Object *obedit = objects[ob_index];
-
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- bool do_seam, do_sharp, do_uvs, do_vcols, do_materials;
- float angle_face_threshold, angle_shape_threshold;
+ /* When joining exactly 2 faces, no limit.
+ * this is useful for one off joins while editing. */
+ {
PropertyRNA *prop;
-
- /* When joining exactly 2 faces, no limit.
- * this is useful for one off joins while editing. */
prop = RNA_struct_find_property(op->ptr, "face_threshold");
if (is_face_pair && (RNA_property_is_set(op->ptr, prop) == false)) {
angle_face_threshold = DEG2RADF(180.0f);
@@ -5584,12 +5609,15 @@ static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op)
else {
angle_shape_threshold = RNA_property_float_get(op->ptr, prop);
}
+ }
- do_seam = RNA_boolean_get(op->ptr, "seam");
- do_sharp = RNA_boolean_get(op->ptr, "sharp");
- do_uvs = RNA_boolean_get(op->ptr, "uvs");
- do_vcols = RNA_boolean_get(op->ptr, "vcols");
- do_materials = RNA_boolean_get(op->ptr, "materials");
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
BM_custom_loop_normals_to_vector_layer(em->bm);
@@ -6314,7 +6342,7 @@ static int edbm_dissolve_degenerate_exec(bContext *C, wmOperator *op)
BMesh *bm = em->bm;
if (!EDBM_op_callf(em, op, "dissolve_degenerate edges=%he dist=%f", BM_ELEM_SELECT, thresh)) {
- return OPERATOR_CANCELLED;
+ continue;
}
/* tricky to maintain correct selection here, so just flush up from verts */
@@ -8599,7 +8627,7 @@ static int edbm_point_normals_modal(bContext *C, wmOperator *op, const wmEvent *
RNA_enum_set(op->ptr, "mode", mode);
}
- /* Only handle mousemove event in case we are in mouse mode. */
+ /* Only handle mouse-move event in case we are in mouse mode. */
if (event->type == MOUSEMOVE || force_mousemove) {
if (mode == EDBM_CLNOR_POINTTO_MODE_MOUSE) {
ARegion *region = CTX_wm_region(C);
@@ -9506,6 +9534,10 @@ static int edbm_set_normals_from_faces_exec(bContext *C, wmOperator *op)
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
+ if (bm->totfacesel == 0) {
+ continue;
+ }
+
BMFace *f;
BMVert *v;
BMEdge *e;
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index fc9e1aa8b1a..f52cd94b8dc 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -755,11 +755,11 @@ static void undomesh_free_data(UndoMesh *um)
#endif
if (me->key) {
- BKE_key_free(me->key);
+ BKE_key_free_data(me->key);
MEM_freeN(me->key);
}
- BKE_mesh_free(me);
+ BKE_mesh_free_data_for_undo(me);
}
static Object *editmesh_object_from_context(bContext *C)
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index b2379610f65..c075d2550cb 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -1007,15 +1007,8 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator
if (me->flag & ME_AUTOSMOOTH) {
float(*polynors)[3] = MEM_mallocN(sizeof(*polynors) * (size_t)me->totpoly, __func__);
- BKE_mesh_calc_normals_poly(me->mvert,
- NULL,
- me->totvert,
- me->mloop,
- me->mpoly,
- me->totloop,
- me->totpoly,
- polynors,
- true);
+ BKE_mesh_calc_normals_poly(
+ me->mvert, me->totvert, me->mloop, me->totloop, me->mpoly, me->totpoly, polynors);
BKE_edges_sharp_from_angle_set(me->mvert,
me->totvert,
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index f25317e8e85..03c99e40d1e 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -150,7 +150,10 @@ void MESH_OT_face_split_by_edges(struct wmOperatorType *ot);
/* *** editmesh_knife.c *** */
void MESH_OT_knife_tool(struct wmOperatorType *ot);
void MESH_OT_knife_project(struct wmOperatorType *ot);
-void EDBM_mesh_knife(struct bContext *C, struct LinkNode *polys, bool use_tag, bool cut_through);
+void EDBM_mesh_knife(struct ViewContext *vc,
+ struct LinkNode *polys,
+ bool use_tag,
+ bool cut_through);
struct wmKeyMap *knifetool_modal_keymap(struct wmKeyConfig *keyconf);
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index f98f3242163..34400462d38 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -2844,7 +2844,8 @@ static int object_convert_exec(bContext *C, wmOperator *op)
matrix,
0,
use_seams,
- use_faces);
+ use_faces,
+ true);
/* Remove unused materials. */
int actcol = ob_gpencil->actcol;
@@ -3358,8 +3359,13 @@ Base *ED_object_add_duplicate(
Base *basen;
Object *ob;
- basen = object_add_duplicate_internal(
- bmain, scene, view_layer, base->object, dupflag, LIB_ID_DUPLICATE_IS_SUBPROCESS);
+ basen = object_add_duplicate_internal(bmain,
+ scene,
+ view_layer,
+ base->object,
+ dupflag,
+ LIB_ID_DUPLICATE_IS_SUBPROCESS |
+ LIB_ID_DUPLICATE_IS_ROOT_ID);
if (basen == NULL) {
return NULL;
}
@@ -3394,8 +3400,13 @@ static int duplicate_exec(bContext *C, wmOperator *op)
BKE_main_id_newptr_and_tag_clear(bmain);
CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
- Base *basen = object_add_duplicate_internal(
- bmain, scene, view_layer, base->object, dupflag, LIB_ID_DUPLICATE_IS_SUBPROCESS);
+ Base *basen = object_add_duplicate_internal(bmain,
+ scene,
+ view_layer,
+ base->object,
+ dupflag,
+ LIB_ID_DUPLICATE_IS_SUBPROCESS |
+ LIB_ID_DUPLICATE_IS_ROOT_ID);
/* note that this is safe to do with this context iterator,
* the list is made in advance */
@@ -3515,7 +3526,7 @@ static int object_add_named_exec(bContext *C, wmOperator *op)
* the case here. So we have to do the new-ID relinking ourselves
* (#copy_object_set_idnew()).
*/
- LIB_ID_DUPLICATE_IS_SUBPROCESS);
+ LIB_ID_DUPLICATE_IS_SUBPROCESS | LIB_ID_DUPLICATE_IS_ROOT_ID);
}
else {
/* basen is actually not a new base in this case. */
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index 3d0213f1830..e0419e0a4cc 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -1483,13 +1483,11 @@ static int constraint_delete_exec(bContext *C, wmOperator *op)
/* free the constraint */
if (BKE_constraint_remove_ex(lb, ob, con, true)) {
- /* there's no active constraint now, so make sure this is the case */
- BKE_constraints_active_set(&ob->constraints, NULL);
/* needed to set the flags on posebones correctly */
ED_object_constraint_update(bmain, ob);
/* relations */
- DEG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(bmain);
/* notifiers */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
@@ -1507,10 +1505,10 @@ static int constraint_delete_exec(bContext *C, wmOperator *op)
static int constraint_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
- if (edit_constraint_invoke_properties(C, op, event, &retval)) {
- return constraint_delete_exec(C, op);
+ if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
+ return OPERATOR_CANCELLED;
}
- return OPERATOR_CANCELLED;
+ return constraint_delete_exec(C, op);
}
void CONSTRAINT_OT_delete(wmOperatorType *ot)
@@ -1534,6 +1532,320 @@ void CONSTRAINT_OT_delete(wmOperatorType *ot)
/** \} */
/* ------------------------------------------------------------------- */
+/** \name Apply Constraint Operator
+ * \{ */
+
+static int constraint_apply_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ Main *bmain = CTX_data_main(C);
+ Object *ob = ED_object_active_context(C);
+ bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
+ bPoseChannel *pchan;
+ ListBase *constraints = ED_object_constraint_list_from_constraint(ob, con, &pchan);
+
+ /* Store name temporarily for report. */
+ char name[MAX_NAME];
+ strcpy(name, con->name);
+ const bool is_first_constraint = con != constraints->first;
+
+ /* Copy the constraint. */
+ bool success;
+ if (pchan) {
+ success = BKE_constraint_apply_and_remove_for_pose(
+ depsgraph, scene, constraints, ob, con, pchan);
+ }
+ else {
+ success = BKE_constraint_apply_and_remove_for_object(depsgraph, scene, constraints, ob, con);
+ }
+
+ if (!success) {
+ /* Couldn't remove due to some invalid data. */
+ return OPERATOR_CANCELLED;
+ }
+
+ /* Update for any children that may get moved. */
+ DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+
+ /* Needed to set the flags on posebones correctly. */
+ ED_object_constraint_update(bmain, ob);
+
+ DEG_relations_tag_update(bmain);
+ WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
+ if (pchan) {
+ WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ }
+ else {
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
+ }
+
+ if (RNA_boolean_get(op->ptr, "report")) {
+ if (is_first_constraint) {
+ BKE_report(op->reports,
+ RPT_INFO,
+ "Applied constraint was not first, result may not be as expected");
+ }
+ else {
+ /* Only add this report if the operator didn't cause another one. The purpose here is
+ * to alert that something happened, and the previous report will do that anyway. */
+ BKE_reportf(op->reports, RPT_INFO, "Applied constraint: %s", name);
+ }
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static int constraint_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ int retval;
+ if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
+ return OPERATOR_CANCELLED;
+ }
+ return constraint_apply_exec(C, op);
+}
+
+void CONSTRAINT_OT_apply(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Apply Constraint";
+ ot->idname = "CONSTRAINT_OT_apply";
+ ot->description = "Apply constraint and remove from the stack";
+
+ /* callbacks */
+ ot->invoke = constraint_apply_invoke;
+ ot->exec = constraint_apply_exec;
+ ot->poll = edit_constraint_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ edit_constraint_properties(ot);
+ edit_constraint_report_property(ot);
+}
+
+/** \} */
+
+/* ------------------------------------------------------------------- */
+/** \name Copy Constraint Operator
+ * \{ */
+
+static int constraint_copy_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ Object *ob = ED_object_active_context(C);
+ bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
+ bPoseChannel *pchan;
+ ListBase *constraints = ED_object_constraint_list_from_constraint(ob, con, &pchan);
+
+ /* Store name temporarily for report. */
+ char name[MAX_NAME];
+ strcpy(name, con->name);
+
+ /* Copy the constraint. */
+ bConstraint *copy_con;
+ if (pchan) {
+ copy_con = BKE_constraint_copy_for_pose(ob, pchan, con);
+ }
+ else {
+ copy_con = BKE_constraint_copy_for_object(ob, con);
+ }
+
+ if (!copy_con) {
+ /* Couldn't remove due to some invalid data. */
+ return OPERATOR_CANCELLED;
+ }
+ /* Move constraint to correct position. */
+ const int new_index = BLI_findindex(constraints, con) + 1;
+ const int current_index = BLI_findindex(constraints, copy_con);
+ BLI_assert(new_index >= 0);
+ BLI_assert(current_index >= 0);
+ BLI_listbase_link_move(constraints, copy_con, new_index - current_index);
+
+ /* Needed to set the flags on posebones correctly. */
+ ED_object_constraint_update(bmain, ob);
+
+ DEG_relations_tag_update(bmain);
+ WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_ADDED, ob);
+
+ if (RNA_boolean_get(op->ptr, "report")) {
+ BKE_reportf(op->reports, RPT_INFO, "Copied constraint: %s", name);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static int constraint_copy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ int retval;
+ if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
+ return OPERATOR_CANCELLED;
+ }
+ return constraint_copy_exec(C, op);
+}
+
+void CONSTRAINT_OT_copy(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Duplicate Constraint";
+ ot->idname = "CONSTRAINT_OT_copy";
+ ot->description = "Duplicate constraint at the same position in the stack";
+
+ /* callbacks */
+ ot->invoke = constraint_copy_invoke;
+ ot->exec = constraint_copy_exec;
+ ot->poll = edit_constraint_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ edit_constraint_properties(ot);
+ edit_constraint_report_property(ot);
+}
+
+/** \} */
+
+/* ------------------------------------------------------------------- */
+/** \name Copy Constraint To Selected Operator
+ * \{ */
+
+static int constraint_copy_to_selected_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ Object *obact = ED_object_active_context(C);
+ bConstraint *con = edit_constraint_property_get(C, op, obact, 0);
+ bPoseChannel *pchan;
+ ED_object_constraint_list_from_constraint(obact, con, &pchan);
+
+ if (pchan) {
+ /* Don't do anything if bone doesn't exist or doesn't have any constraints. */
+ if (pchan->constraints.first == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No constraints for copying");
+ return OPERATOR_CANCELLED;
+ }
+
+ Object *prev_ob = NULL;
+
+ /* Copy all constraints from active posebone to all selected posebones. */
+ CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
+ /* If we're not handling the object we're copying from, copy all constraints over. */
+ if (pchan == chan) {
+ continue;
+ }
+
+ BKE_constraint_copy_for_pose(ob, chan, con);
+ /* Update flags (need to add here, not just copy). */
+ chan->constflag |= pchan->constflag;
+
+ if (prev_ob == ob) {
+ continue;
+ }
+
+ BKE_pose_tag_recalc(bmain, ob->pose);
+ DEG_id_tag_update((ID *)ob, ID_RECALC_GEOMETRY);
+ prev_ob = ob;
+ }
+ CTX_DATA_END;
+ }
+ else {
+ /* Copy all constraints from active object to all selected objects. */
+ CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
+ /* If we're not handling the object we're copying from, copy all constraints over. */
+ if (obact == ob) {
+ continue;
+ }
+
+ BKE_constraint_copy_for_object(ob, con);
+ DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM);
+ }
+ CTX_DATA_END;
+ }
+
+ /* Force depsgraph to get recalculated since new relationships added. */
+ DEG_relations_tag_update(bmain);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+static int constraint_copy_to_selected_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ int retval;
+ if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
+ return retval;
+ }
+ return constraint_copy_to_selected_exec(C, op);
+}
+
+static bool constraint_copy_to_selected_poll(bContext *C)
+{
+ PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
+ Object *obact = (ptr.owner_id) ? (Object *)ptr.owner_id : ED_object_active_context(C);
+ bConstraint *con = ptr.data;
+ bPoseChannel *pchan;
+ ED_object_constraint_list_from_constraint(obact, con, &pchan);
+
+ if (pchan) {
+ bool found = false;
+ CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, UNUSED(ob)) {
+ if (pchan != chan) {
+ /** NOTE: Can not return here, because CTX_DATA_BEGIN_WITH_ID allocated
+ * a list that needs to be freed by CTX_DATA_END. */
+ found = true;
+ break;
+ }
+ }
+ CTX_DATA_END;
+ if (found) {
+ return true;
+ }
+
+ CTX_wm_operator_poll_msg_set(C, "No other bones are selected");
+ return false;
+ }
+
+ if (!obact) {
+ CTX_wm_operator_poll_msg_set(C, "No selected object to copy from");
+ return false;
+ }
+
+ bool found = false;
+ CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
+ if (ob != obact) {
+ /** NOTE: Can not return here, because CTX_DATA_BEGIN allocated
+ * a list that needs to be freed by CTX_DATA_END. */
+ found = true;
+ break;
+ }
+ }
+ CTX_DATA_END;
+ if (found) {
+ return true;
+ }
+
+ CTX_wm_operator_poll_msg_set(C, "No other objects are selected");
+ return false;
+}
+
+void CONSTRAINT_OT_copy_to_selected(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Copy Constraint To Selected";
+ ot->idname = "CONSTRAINT_OT_copy_to_selected";
+ ot->description = "Copy constraint to other selected objects/bones";
+
+ /* api callbacks */
+ ot->exec = constraint_copy_to_selected_exec;
+ ot->invoke = constraint_copy_to_selected_invoke;
+ ot->poll = constraint_copy_to_selected_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ edit_constraint_properties(ot);
+}
+
+/** \} */
+
+/* ------------------------------------------------------------------- */
/** \name Move Down Constraint Operator
* \{ */
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 6299fdcc7f7..10e016738d0 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -226,6 +226,9 @@ void POSE_OT_ik_add(struct wmOperatorType *ot);
void POSE_OT_ik_clear(struct wmOperatorType *ot);
void CONSTRAINT_OT_delete(struct wmOperatorType *ot);
+void CONSTRAINT_OT_apply(struct wmOperatorType *ot);
+void CONSTRAINT_OT_copy(struct wmOperatorType *ot);
+void CONSTRAINT_OT_copy_to_selected(struct wmOperatorType *ot);
void CONSTRAINT_OT_move_up(struct wmOperatorType *ot);
void CONSTRAINT_OT_move_to_index(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index e9142742d15..e1e0a0600be 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -352,7 +352,7 @@ static bool object_modifier_remove(
/* special cases */
if (md->type == eModifierType_ParticleSystem) {
- object_remove_particle_system(bmain, scene, ob);
+ object_remove_particle_system(bmain, scene, ob, ((ParticleSystemModifierData *)md)->psys);
return true;
}
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index a438c760d3b..c1928cf7f8a 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -183,6 +183,9 @@ void ED_operatortypes_object(void)
WM_operatortype_append(POSE_OT_ik_add);
WM_operatortype_append(POSE_OT_ik_clear);
WM_operatortype_append(CONSTRAINT_OT_delete);
+ WM_operatortype_append(CONSTRAINT_OT_apply);
+ WM_operatortype_append(CONSTRAINT_OT_copy);
+ WM_operatortype_append(CONSTRAINT_OT_copy_to_selected);
WM_operatortype_append(CONSTRAINT_OT_move_up);
WM_operatortype_append(CONSTRAINT_OT_move_down);
WM_operatortype_append(CONSTRAINT_OT_move_to_index);
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index a9a439c5084..ec72ff11683 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -570,6 +570,8 @@ void ED_object_parent_clear(Object *ob, const int type)
/* clear parenting relationship completely */
ob->parent = NULL;
+ ob->partype = PAROBJECT;
+ ob->parsubstr[0] = 0;
break;
}
case CLEAR_PARENT_KEEP_TRANSFORM: {
@@ -2727,16 +2729,14 @@ char *ED_object_ot_drop_named_material_tooltip(bContext *C,
PointerRNA *properties,
const wmEvent *event)
{
- Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
+ Object *ob = ED_view3d_give_object_under_cursor(C, event->mval);
+ if (ob == NULL) {
+ return BLI_strdup("");
+ }
char name[MAX_ID_NAME - 2];
RNA_string_get(properties, "name", name);
- if (base == NULL) {
- return BLI_strdup("");
- }
-
- Object *ob = base->object;
int active_mat_slot = max_ii(ob->actcol, 1);
Material *prev_mat = BKE_object_material_get(ob, active_mat_slot);
@@ -2755,25 +2755,23 @@ char *ED_object_ot_drop_named_material_tooltip(bContext *C,
static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
Main *bmain = CTX_data_main(C);
- Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
+ Object *ob = ED_view3d_give_object_under_cursor(C, event->mval);
Material *ma;
char name[MAX_ID_NAME - 2];
RNA_string_get(op->ptr, "name", name);
ma = (Material *)BKE_libblock_find_name(bmain, ID_MA, name);
- if (base == NULL || ma == NULL) {
+ if (ob == NULL || ma == NULL) {
return OPERATOR_CANCELLED;
}
- Object *ob = base->object;
const short active_mat_slot = ob->actcol;
- BKE_object_material_assign(
- CTX_data_main(C), base->object, ma, active_mat_slot, BKE_MAT_ASSIGN_USERPREF);
+ BKE_object_material_assign(CTX_data_main(C), ob, ma, active_mat_slot, BKE_MAT_ASSIGN_USERPREF);
- DEG_id_tag_update(&base->object->id, ID_RECALC_TRANSFORM);
+ DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
- WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, base->object);
+ WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, ma);
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index f64f95c5322..7a42c9d5d8b 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -1582,7 +1582,7 @@ static void vgroup_fix(
mag = normalize_v3(norm);
if (mag) { /* zeros fix */
d = -dot_v3v3(norm, coord);
- /* dist = (dot_v3v3(norm, m.co) + d); */ /* UNUSED */
+ // dist = (dot_v3v3(norm, m.co) + d); /* UNUSED */
moveCloserToDistanceFromPlane(
depsgraph, scene_eval, object_eval, me, i, norm, coord, d, distToBe, strength, cp);
}
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index 85883a2d29a..8afc5c583e0 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -4667,7 +4667,7 @@ typedef struct BrushEdit {
int lastmouse[2];
float zfac;
- /* optional cached view settings to avoid setting on every mousemove */
+ /** Optional cached view settings to avoid setting on every mouse-move. */
PEData data;
} BrushEdit;
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index 2668846284d..3ac6dca3044 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -124,7 +124,8 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
}
mode_orig = ob->mode;
- object_remove_particle_system(bmain, scene, ob);
+ ParticleSystem *psys = psys_get_current(ob);
+ object_remove_particle_system(bmain, scene, ob, psys);
/* possible this isn't the active object
* object_remove_particle_system() clears the mode on the last psys
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index d3307ebf274..749010a5ba3 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -768,7 +768,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
DRW_opengl_context_enable(); /* Off-screen creation needs to be done in DRW context. */
- ofs = GPU_offscreen_create(sizex, sizey, true, true, err_out);
+ ofs = GPU_offscreen_create(sizex, sizey, true, GPU_RGBA16F, err_out);
DRW_opengl_context_disable();
if (!ofs) {
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index bd4c83c107e..95351de45f0 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -47,6 +47,7 @@
#include "DNA_collection_types.h"
#include "DNA_light_types.h"
#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -265,6 +266,11 @@ static const char *preview_collection_name(const ePreviewType pr_type)
}
}
+static bool render_engine_supports_ray_visibility(const Scene *sce)
+{
+ return !STREQ(sce->r.engine, RE_engine_id_BLENDER_EEVEE);
+}
+
static void switch_preview_collection_visibilty(ViewLayer *view_layer, const ePreviewType pr_type)
{
/* Set appropriate layer as visible. */
@@ -281,29 +287,60 @@ static void switch_preview_collection_visibilty(ViewLayer *view_layer, const ePr
}
}
-static void switch_preview_floor_visibility(ViewLayer *view_layer,
+static const char *preview_floor_material_name(const Scene *scene,
+ const ePreviewRenderMethod pr_method)
+{
+ if (pr_method == PR_ICON_RENDER && render_engine_supports_ray_visibility(scene)) {
+ return "FloorHidden";
+ }
+ return "Floor";
+}
+
+static void switch_preview_floor_material(Main *pr_main,
+ Mesh *me,
+ const Scene *scene,
+ const ePreviewRenderMethod pr_method)
+{
+ if (me->totcol == 0) {
+ return;
+ }
+
+ const char *material_name = preview_floor_material_name(scene, pr_method);
+ Material *mat = BLI_findstring(&pr_main->materials, material_name, offsetof(ID, name) + 2);
+ if (mat) {
+ me->mat[0] = mat;
+ }
+}
+
+static void switch_preview_floor_visibility(Main *pr_main,
+ const Scene *scene,
+ ViewLayer *view_layer,
const ePreviewRenderMethod pr_method)
{
/* Hide floor for icon renders. */
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (STREQ(base->object->id.name + 2, "Floor")) {
+ base->object->visibility_flag &= ~OB_HIDE_RENDER;
if (pr_method == PR_ICON_RENDER) {
- base->object->visibility_flag |= OB_HIDE_RENDER;
+ if (!render_engine_supports_ray_visibility(scene)) {
+ base->object->visibility_flag |= OB_HIDE_RENDER;
+ }
}
- else {
- base->object->visibility_flag &= ~OB_HIDE_RENDER;
+ if (base->object->type == OB_MESH) {
+ switch_preview_floor_material(pr_main, base->object->data, scene, pr_method);
}
}
}
}
-static void set_preview_visibility(Scene *scene,
+static void set_preview_visibility(Main *pr_main,
+ Scene *scene,
ViewLayer *view_layer,
const ePreviewType pr_type,
const ePreviewRenderMethod pr_method)
{
switch_preview_collection_visibilty(view_layer, pr_type);
- switch_preview_floor_visibility(view_layer, pr_method);
+ switch_preview_floor_visibility(pr_main, scene, view_layer, pr_method);
BKE_layer_collection_sync(scene, view_layer);
}
@@ -357,10 +394,31 @@ static ID *duplicate_ids(ID *id, const bool allow_failure)
}
}
-static World *preview_get_world(Main *pr_main)
+static const char *preview_world_name(const Scene *sce,
+ const ID_Type id_type,
+ const ePreviewRenderMethod pr_method)
+{
+ /* When rendering material icons the floor will not be shown in the output. Cycles will use a
+ * material trick to show the floor in the reflections, but hide the floor for camera rays. For
+ * Eevee we use a transparent world that has a projected grid.
+ *
+ * In the future when Eevee supports vulkan raytracing we can re-evaluate and perhaps remove this
+ * approximation.
+ */
+ if (id_type == ID_MA && pr_method == PR_ICON_RENDER &&
+ !render_engine_supports_ray_visibility(sce)) {
+ return "WorldFloor";
+ }
+ return "World";
+}
+
+static World *preview_get_world(Main *pr_main,
+ const Scene *sce,
+ const ID_Type id_type,
+ const ePreviewRenderMethod pr_method)
{
World *result = NULL;
- const char *world_name = "World";
+ const char *world_name = preview_world_name(sce, id_type, pr_method);
result = BLI_findstring(&pr_main->worlds, world_name, offsetof(ID, name) + 2);
/* No world found return first world. */
@@ -380,9 +438,13 @@ static void preview_sync_exposure(World *dst, const World *src)
dst->range = src->range;
}
-static World *preview_prepare_world(Main *pr_main, const World *world)
+static World *preview_prepare_world(Main *pr_main,
+ const Scene *sce,
+ const World *world,
+ const ID_Type id_type,
+ const ePreviewRenderMethod pr_method)
{
- World *result = preview_get_world(pr_main);
+ World *result = preview_get_world(pr_main, sce, id_type, pr_method);
if (world) {
preview_sync_exposure(result, world);
}
@@ -436,7 +498,7 @@ static Scene *preview_prepare_scene(
sce->r.cfra = scene->r.cfra;
/* Setup the world. */
- sce->world = preview_prepare_world(pr_main, scene->world);
+ sce->world = preview_prepare_world(pr_main, sce, scene->world, id_type, sp->pr_method);
if (id_type == ID_TE) {
/* Texture is not actually rendered with engine, just set dummy value. */
@@ -458,7 +520,7 @@ static Scene *preview_prepare_scene(
/* Use current scene world to light sphere. */
sce->world = preview_get_localized_world(sp, scene->world);
}
- else if (sce->world) {
+ else if (sce->world && sp->pr_method != PR_ICON_RENDER) {
/* Use a default world color. Using the current
* scene world can be slow if it has big textures. */
sce->world->use_nodes = false;
@@ -472,7 +534,7 @@ static Scene *preview_prepare_scene(
sp->pr_main == G_pr_main_grease_pencil) ?
MA_SPHERE_A :
mat->pr_type;
- set_preview_visibility(sce, view_layer, preview_type, sp->pr_method);
+ set_preview_visibility(pr_main, sce, view_layer, preview_type, sp->pr_method);
if (sp->pr_method != PR_ICON_RENDER) {
if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) {
@@ -536,7 +598,7 @@ static Scene *preview_prepare_scene(
BLI_addtail(&pr_main->lights, la);
}
- set_preview_visibility(sce, view_layer, MA_LAMP, sp->pr_method);
+ set_preview_visibility(pr_main, sce, view_layer, MA_LAMP, sp->pr_method);
if (sce->world) {
/* Only use lighting from the light. */
@@ -571,7 +633,7 @@ static Scene *preview_prepare_scene(
BLI_addtail(&pr_main->worlds, wrld);
}
- set_preview_visibility(sce, view_layer, MA_SKY, sp->pr_method);
+ set_preview_visibility(pr_main, sce, view_layer, MA_SKY, sp->pr_method);
sce->world = wrld;
if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) {
diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c
index fb9d11feb63..8bc2281db73 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
+#include "DNA_cachefile_types.h"
#include "DNA_light_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
@@ -63,7 +64,9 @@
#include <stdio.h>
-/***************************** Render Engines ********************************/
+/* -------------------------------------------------------------------- */
+/** \name Render Engines
+ * \{ */
/* Update 3D viewport render or draw engine on changes to the scene or view settings. */
void ED_render_view3d_update(Depsgraph *depsgraph,
@@ -204,6 +207,19 @@ void ED_render_engine_changed(Main *bmain, const bool update_scene_data)
ntreeCompositUpdateRLayers(scene->nodetree);
}
}
+
+ /* Update #CacheFiles to ensure that procedurals are properly taken into account. */
+ LISTBASE_FOREACH (CacheFile *, cachefile, &bmain->cachefiles) {
+ /* Only update cache-files which are set to use a render procedural.
+ * We do not use #BKE_cachefile_uses_render_procedural here as we need to update regardless of
+ * the current engine or its settings. */
+ if (cachefile->use_render_procedural) {
+ DEG_id_tag_update(&cachefile->id, ID_RECALC_COPY_ON_WRITE);
+ /* Rebuild relations so that modifiers are reconnected to or disconnected from the
+ * cache-file. */
+ DEG_relations_tag_update(bmain);
+ }
+ }
}
void ED_render_view_layer_changed(Main *bmain, bScreen *screen)
@@ -213,10 +229,16 @@ void ED_render_view_layer_changed(Main *bmain, bScreen *screen)
}
}
-/***************************** Updates ***********************************
- * ED_render_id_flush_update gets called from DEG_id_tag_update, to do *
- * editor level updates when the ID changes. when these ID blocks are in *
- * the dependency graph, we can get rid of the manual dependency checks. */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Updates
+ *
+ * #ED_render_id_flush_update gets called from #DEG_id_tag_update,
+ * to do editor level updates when the ID changes.
+ * When these ID blocks are in the dependency graph,
+ * we can get rid of the manual dependency checks.
+ * \{ */
static void material_changed(Main *UNUSED(bmain), Material *ma)
{
@@ -322,3 +344,5 @@ void ED_render_id_flush_update(const DEGEditorUpdateContext *update_ctx, ID *id)
break;
}
}
+
+/** \} */
diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c
index dca464bbf22..ab50e327de3 100644
--- a/source/blender/editors/screen/screen_draw.c
+++ b/source/blender/editors/screen/screen_draw.c
@@ -451,7 +451,7 @@ static void screen_preview_draw(const bScreen *screen, int size_x, int size_y)
void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, uint *r_rect)
{
char err_out[256] = "unknown";
- GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, true, false, err_out);
+ GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, true, GPU_RGBA8, err_out);
GPU_offscreen_bind(offscreen, true);
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 506b5a9859d..1c068fdd6e4 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -230,7 +230,7 @@ bScreen *screen_add(Main *bmain, const char *name, const rcti *rect)
void screen_data_copy(bScreen *to, bScreen *from)
{
/* free contents of 'to', is from blenkernel screen.c */
- BKE_screen_free(to);
+ BKE_screen_free_data(to);
to->flag = from->flag;
diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c
index d69c7ab8d48..717d87c4972 100644
--- a/source/blender/editors/space_action/action_data.c
+++ b/source/blender/editors/space_action/action_data.c
@@ -599,16 +599,13 @@ void ED_animedit_unlink_action(
id_fake_user_clear(&act->id);
}
- /* If in Tweak Mode, don't unlink. Instead, this
- * becomes a shortcut to exit Tweak Mode instead
- */
+ /* If in Tweak Mode, don't unlink. Instead, this becomes a shortcut to exit Tweak Mode. */
if ((adt) && (adt->flag & ADT_NLA_EDIT_ON)) {
- /* Exit Tweak Mode */
BKE_nla_tweakmode_exit(adt);
- /* Flush this to the Action Editor (if that's where this change was initiated) */
- if (area->spacetype == SPACE_ACTION) {
- actedit_change_action(C, NULL);
+ Scene *scene = CTX_data_scene(C);
+ if (scene != NULL) {
+ scene->flag &= ~SCE_NLA_EDIT_ON;
}
}
else {
@@ -660,6 +657,9 @@ static int action_unlink_exec(bContext *C, wmOperator *op)
ED_animedit_unlink_action(C, NULL, adt, adt->action, op->reports, force_delete);
}
+ /* Unlink is also abused to exit NLA tweak mode. */
+ WM_main_add_notifier(NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c
index ce07b9c5fad..a3bdcd2adf5 100644
--- a/source/blender/editors/space_action/action_draw.c
+++ b/source/blender/editors/space_action/action_draw.c
@@ -144,12 +144,14 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
uchar col1[4], col2[4];
uchar col1a[4], col2a[4];
uchar col1b[4], col2b[4];
+ uchar col_summary[4];
const bool show_group_colors = U.animation_flag & USER_ANIM_SHOW_CHANNEL_GROUP_COLORS;
/* get theme colors */
UI_GetThemeColor4ubv(TH_SHADE2, col2);
UI_GetThemeColor4ubv(TH_HILITE, col1);
+ UI_GetThemeColor4ubv(TH_ANIM_ACTIVE, col_summary);
UI_GetThemeColor4ubv(TH_GROUP, col2a);
UI_GetThemeColor4ubv(TH_GROUP_ACTIVE, col1a);
@@ -244,7 +246,10 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
else if (ac->datatype == ANIMCONT_GPENCIL) {
uchar *color;
uchar gpl_col[4];
- if ((show_group_colors) && (ale->type == ANIMTYPE_GPLAYER)) {
+ if (ale->type == ANIMTYPE_SUMMARY) {
+ color = col_summary;
+ }
+ else if ((show_group_colors) && (ale->type == ANIMTYPE_GPLAYER)) {
bGPDlayer *gpl = (bGPDlayer *)ale->data;
rgb_float_to_uchar(gpl_col, gpl->color);
gpl_col[3] = col1[3];
@@ -265,7 +270,13 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
else if (ac->datatype == ANIMCONT_MASK) {
/* TODO: this is a copy of gpencil. */
/* frames less than one get less saturated background */
- uchar *color = sel ? col1 : col2;
+ uchar *color;
+ if (ale->type == ANIMTYPE_SUMMARY) {
+ color = col_summary;
+ }
+ else {
+ color = sel ? col1 : col2;
+ }
immUniformColor4ubv(color);
immRectf(pos, 0.0f, ymin, v2d->cur.xmin, ymax);
@@ -302,6 +313,8 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
ymax = ACHANNEL_FIRST_TOP(ac);
+ struct AnimKeylistDrawList *draw_list = ED_keylist_draw_list_create();
+
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac)) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
float ycenter = (ymin + ymax) / 2.0f;
@@ -316,34 +329,41 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
/* draw 'keyframes' for each specific datatype */
switch (ale->datatype) {
case ALE_ALL:
- draw_summary_channel(v2d, ale->data, ycenter, ac->yscale_fac, action_flag);
+ draw_summary_channel(draw_list, ale->data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_SCE:
- draw_scene_channel(v2d, ads, ale->key_data, ycenter, ac->yscale_fac, action_flag);
+ draw_scene_channel(
+ draw_list, ads, ale->key_data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_OB:
- draw_object_channel(v2d, ads, ale->key_data, ycenter, ac->yscale_fac, action_flag);
+ draw_object_channel(
+ draw_list, ads, ale->key_data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_ACT:
- draw_action_channel(v2d, adt, ale->key_data, ycenter, ac->yscale_fac, action_flag);
+ draw_action_channel(
+ draw_list, adt, ale->key_data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_GROUP:
- draw_agroup_channel(v2d, adt, ale->data, ycenter, ac->yscale_fac, action_flag);
+ draw_agroup_channel(draw_list, adt, ale->data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_FCURVE:
- draw_fcurve_channel(v2d, adt, ale->key_data, ycenter, ac->yscale_fac, action_flag);
+ draw_fcurve_channel(
+ draw_list, adt, ale->key_data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_GPFRAME:
- draw_gpl_channel(v2d, ads, ale->data, ycenter, ac->yscale_fac, action_flag);
+ draw_gpl_channel(draw_list, ads, ale->data, ycenter, ac->yscale_fac, action_flag);
break;
case ALE_MASKLAY:
- draw_masklay_channel(v2d, ads, ale->data, ycenter, ac->yscale_fac, action_flag);
+ draw_masklay_channel(draw_list, ads, ale->data, ycenter, ac->yscale_fac, action_flag);
break;
}
}
}
}
+ ED_keylist_draw_list_flush(draw_list, v2d);
+ ED_keylist_draw_list_free(draw_list);
+
/* free temporary channels used for drawing */
ANIM_animdata_freelist(&anim_data);
}
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index c141789f171..798f4898aaa 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -198,7 +198,8 @@ static int file_browse_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
FileBrowseOp *fbo = op->customdata;
ID *id;
- char *str, path[FILE_MAX];
+ char *str;
+ int str_len;
const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" :
"filepath";
@@ -206,10 +207,11 @@ static int file_browse_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0);
+ str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0, &str_len);
/* Add slash for directories, important for some properties. */
if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
+ char path[FILE_MAX];
const bool is_relative = RNA_boolean_get(op->ptr, "relative_path");
id = fbo->ptr.owner_id;
@@ -220,13 +222,13 @@ static int file_browse_exec(bContext *C, wmOperator *op)
/* Do this first so '//' isn't converted to '//\' on windows. */
BLI_path_slash_ensure(path);
if (is_relative) {
- BLI_strncpy(path, str, FILE_MAX);
+ const int path_len = BLI_strncpy_rlen(path, str, FILE_MAX);
BLI_path_rel(path, BKE_main_blendfile_path(bmain));
- str = MEM_reallocN(str, strlen(path) + 2);
+ str = MEM_reallocN(str, path_len + 2);
BLI_strncpy(str, path, FILE_MAX);
}
else {
- str = MEM_reallocN(str, strlen(str) + 2);
+ str = MEM_reallocN(str, str_len + 2);
}
}
else {
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index 57a7fe894b0..b04291b7ab4 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -811,6 +811,9 @@ static void buttons_area_listener(const wmSpaceTypeListenerParams *params)
break;
case NC_ANIMATION:
switch (wmn->data) {
+ case ND_NLA_ACTCHANGE:
+ ED_area_tag_redraw(area);
+ break;
case ND_KEYFRAME:
if (ELEM(wmn->action, NA_EDITED, NA_ADDED, NA_REMOVED)) {
ED_area_tag_redraw(area);
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index 67b4fd61d38..834ef847069 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -1037,6 +1037,7 @@ static void prefetch_freejob(void *pjv)
if (clip_local != NULL) {
BKE_libblock_free_datablock(&clip_local->id, 0);
BKE_libblock_free_data(&clip_local->id, false);
+ BLI_assert(!clip_local->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(clip_local);
}
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index bdb7c622cd2..763beb8671b 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -384,7 +384,7 @@ static int console_insert_exec(bContext *C, wmOperator *op)
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
ConsoleLine *ci = console_history_verify(C);
- char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
int len;
if (str[0] == '\t' && str[1] == '\0') {
@@ -860,7 +860,7 @@ static int console_history_append_exec(bContext *C, wmOperator *op)
ScrArea *area = CTX_wm_area(C);
ConsoleLine *ci = console_history_verify(C);
/* own this text in the new line, don't free */
- char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
int cursor = RNA_int_get(op->ptr, "current_character");
const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
int prev_len = ci->len;
@@ -923,7 +923,7 @@ static int console_scrollback_append_exec(bContext *C, wmOperator *op)
ConsoleLine *ci;
/* own this text in the new line, don't free */
- char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
int type = RNA_enum_get(op->ptr, "type");
console_history_verify(C);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 944eb9988fa..2f1acd2ca4d 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -546,6 +546,9 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
const bool fill = RNA_boolean_get(op->ptr, "fill");
const bool do_diropen = RNA_boolean_get(op->ptr, "open");
const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
+ const bool only_activate_if_selected = RNA_boolean_get(op->ptr, "only_activate_if_selected");
+ /* Used so right mouse clicks can do both, activate and spawn the context menu. */
+ const bool pass_through = RNA_boolean_get(op->ptr, "pass_through");
if (region->regiontype != RGN_TYPE_WINDOW) {
return OPERATOR_CANCELLED;
@@ -563,8 +566,13 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int numfiles = filelist_files_ensure(sfile->files);
if ((idx >= 0) && (idx < numfiles)) {
+ const bool is_selected = filelist_entry_select_index_get(sfile->files, idx, CHECK_ALL) &
+ FILE_SEL_SELECTED;
+ if (only_activate_if_selected && is_selected) {
+ /* Don't deselect other items. */
+ }
/* single select, deselect all selected first */
- if (!extend) {
+ else if (!extend) {
file_select_deselect_all(sfile, FILE_SEL_SELECTED);
}
}
@@ -593,7 +601,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
WM_event_add_mousemove(CTX_wm_window(C)); /* for directory changes */
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
- return OPERATOR_FINISHED;
+ return pass_through ? (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH) : OPERATOR_FINISHED;
}
void FILE_OT_select(wmOperatorType *ot)
@@ -628,6 +636,20 @@ void FILE_OT_select(wmOperatorType *ot)
"Deselect On Nothing",
"Deselect all when nothing under the cursor");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna,
+ "only_activate_if_selected",
+ false,
+ "Only Activate if Selected",
+ "Do not change selection if the item under the cursor is already "
+ "selected, only activate it");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna,
+ "pass_through",
+ false,
+ "Pass Through",
+ "Even on successful execution, pass the event on so other operators can "
+ "execute on it as well");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
}
/** \} */
@@ -1366,7 +1388,9 @@ int file_highlight_set(SpaceFile *sfile, ARegion *region, int mx, int my)
FileSelectParams *params;
int numfiles, origfile;
- if (sfile == NULL || sfile->files == NULL) {
+ /* In case blender starts where the mouse is over a File browser,
+ * this operator can be invoked when the `sfile` or `sfile->layout` isn't initialized yet. */
+ if (sfile == NULL || sfile->files == NULL || sfile->layout == NULL) {
return 0;
}
@@ -2516,7 +2540,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN
/* don't do for now because it selects entire text instead of
* placing cursor at the end */
- /* UI_textbutton_activate_but(C, but); */
+ // UI_textbutton_activate_but(C, but);
}
#if defined(WIN32)
else if (!can_create_dir(params->dir)) {
@@ -2750,20 +2774,6 @@ static void file_rename_state_activate(SpaceFile *sfile, int file_idx, bool requ
}
}
-static int file_rename_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
- ScrArea *area = CTX_wm_area(C);
- SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
- FileSelectParams *params = ED_fileselect_get_active_params(sfile);
-
- if (params) {
- file_rename_state_activate(sfile, params->active_file, true);
- ED_area_tag_redraw(area);
- }
-
- return OPERATOR_FINISHED;
-}
-
static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
{
ScrArea *area = CTX_wm_area(C);
@@ -2771,7 +2781,7 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
FileSelectParams *params = ED_fileselect_get_active_params(sfile);
if (params) {
- file_rename_state_activate(sfile, params->highlight_file, false);
+ file_rename_state_activate(sfile, params->active_file, false);
ED_area_tag_redraw(area);
}
@@ -2786,7 +2796,6 @@ void FILE_OT_rename(struct wmOperatorType *ot)
ot->idname = "FILE_OT_rename";
/* api callbacks */
- ot->invoke = file_rename_invoke;
ot->exec = file_rename_exec;
/* File browsing only operator (not asset browsing). */
ot->poll = ED_operator_file_browsing_active;
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 72e7e0716db..4ab7014cf82 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -863,20 +863,8 @@ FileAttributeColumnType file_attribute_column_type_find_isect(const View2D *v2d,
float file_string_width(const char *str)
{
const uiStyle *style = UI_style_get();
- float width;
-
UI_fontstyle_set(&style->widget);
- if (style->widget.kerning == 1) { /* for BLF_width */
- BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
- }
-
- width = BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
-
- if (style->widget.kerning == 1) {
- BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
- }
-
- return width;
+ return BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
}
float file_font_pointsize(void)
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 0b3349f5751..7deaa2fec60 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -1,4 +1,4 @@
-/*
+/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -334,6 +334,12 @@ static void file_refresh(const bContext *C, ScrArea *area)
sfile->files = filelist_new(params->type);
params->highlight_file = -1; /* added this so it opens nicer (ton) */
}
+
+ if (!U.experimental.use_extended_asset_browser && ED_fileselect_is_asset_browser(sfile)) {
+ /* Only poses supported as non-experimental right now. */
+ params->filter_id = FILTER_ID_AC;
+ }
+
filelist_settype(sfile->files, params->type);
filelist_setdir(sfile->files, params->dir);
filelist_setrecursion(sfile->files, params->recursion_level);
@@ -575,6 +581,16 @@ static void file_main_region_message_subscribe(const wmRegionMessageSubscribePar
/* All properties for this space type. */
WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__);
}
+
+ /* Experimental Asset Browser features option. */
+ {
+ PointerRNA ptr;
+ RNA_pointer_create(NULL, &RNA_PreferencesExperimental, &U.experimental, &ptr);
+ PropertyRNA *prop = RNA_struct_find_property(&ptr, "use_extended_asset_browser");
+
+ /* All properties for this space type. */
+ WM_msg_subscribe_rna(mbus, &ptr, prop, &msg_sub_value_area_tag_refresh, __func__);
+ }
}
static bool file_main_region_needs_refresh_before_draw(SpaceFile *sfile)
@@ -852,13 +868,7 @@ static void file_space_subtype_item_extend(bContext *UNUSED(C),
EnumPropertyItem **item,
int *totitem)
{
- if (U.experimental.use_asset_browser) {
- RNA_enum_items_add(item, totitem, rna_enum_space_file_browse_mode_items);
- }
- else {
- RNA_enum_items_add_value(
- item, totitem, rna_enum_space_file_browse_mode_items, FILE_BROWSE_MODE_FILES);
- }
+ RNA_enum_items_add(item, totitem, rna_enum_space_file_browse_mode_items);
}
static const char *file_context_dir[] = {
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index ec5f443e2dc..f4c4b6cafcd 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -364,7 +364,7 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
}
block = uiLayoutGetBlock(layout);
- /* UI_block_func_handle_set(block, do_graph_region_buttons, NULL); */
+ // UI_block_func_handle_set(block, do_graph_region_buttons, NULL);
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c
index 169dafcb8d0..a95189a303f 100644
--- a/source/blender/editors/space_image/image_edit.c
+++ b/source/blender/editors/space_image/image_edit.c
@@ -139,8 +139,10 @@ ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock, int tile)
ImBuf *ibuf;
if (sima && sima->image) {
+ const Image *image = sima->image;
+
#if 0
- if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare()) {
+ if (image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare()) {
return BIF_render_spare_imbuf();
}
else
@@ -152,6 +154,12 @@ ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock, int tile)
}
if (ibuf) {
+ if (image->type == IMA_TYPE_R_RESULT && ibuf->x != 0 && ibuf->y != 0) {
+ /* Render result might be lazily allocated. Return ibuf without buffers to indicate that
+ * there is image buffer but it has no data yet. */
+ return ibuf;
+ }
+
if (ibuf->rect || ibuf->rect_float) {
return ibuf;
}
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 613042a2ab9..4f8feda3911 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1289,8 +1289,10 @@ static Image *image_open_single(Main *bmain,
}
if ((range->length > 1) && (ima->source == IMA_SRC_FILE)) {
- if (range->udim_tiles.first && range->offset == 1001) {
+ if (range->udim_tiles.first) {
ima->source = IMA_SRC_TILED;
+ ImageTile *first_tile = ima->tiles.first;
+ first_tile->tile_number = range->offset;
LISTBASE_FOREACH (LinkData *, node, &range->udim_tiles) {
BKE_image_add_tile(ima, POINTER_AS_INT(node->data), NULL);
}
@@ -1806,10 +1808,13 @@ static int image_save_options_init(Main *bmain,
}
/* append UDIM numbering if not present */
- if (ima->source == IMA_SRC_TILED &&
- (BLI_path_sequence_decode(ima->filepath, NULL, NULL, NULL) != 1001)) {
+ if (ima->source == IMA_SRC_TILED) {
+ char udim[6];
+ ImageTile *tile = ima->tiles.first;
+ BLI_snprintf(udim, sizeof(udim), ".%d", tile->tile_number);
+
int len = strlen(opts->filepath);
- STR_CONCAT(opts->filepath, len, ".1001");
+ STR_CONCAT(opts->filepath, len, udim);
}
}
@@ -3868,9 +3873,9 @@ static void tile_fill_init(PointerRNA *ptr, Image *ima, ImageTile *tile)
/* Acquire ibuf to get the default values.
* If the specified tile has no ibuf, try acquiring the main tile instead
- * (unless the specified tile already was the main tile). */
+ * (unless the specified tile already was the first tile). */
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
- if (ibuf == NULL && (tile != NULL) && (tile->tile_number != 1001)) {
+ if (ibuf == NULL && (tile != NULL) && (tile != ima->tiles.first)) {
ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
}
@@ -3922,7 +3927,7 @@ static int tile_add_exec(bContext *C, wmOperator *op)
Image *ima = CTX_data_edit_image(C);
int start_tile = RNA_int_get(op->ptr, "number");
- int end_tile = start_tile + RNA_int_get(op->ptr, "count");
+ int end_tile = start_tile + RNA_int_get(op->ptr, "count") - 1;
if (start_tile < 1001 || end_tile > IMA_UDIM_MAX) {
BKE_report(op->reports, RPT_ERROR, "Invalid UDIM index range was specified");
@@ -3930,28 +3935,32 @@ static int tile_add_exec(bContext *C, wmOperator *op)
}
bool fill_tile = RNA_boolean_get(op->ptr, "fill");
- char *label = RNA_string_get_alloc(op->ptr, "label", NULL, 0);
+ char *label = RNA_string_get_alloc(op->ptr, "label", NULL, 0, NULL);
+
+ /* BKE_image_add_tile assumes a pre-sorted list of tiles. */
+ BKE_image_sort_tiles(ima);
- bool created_tile = false;
- for (int tile_number = start_tile; tile_number < end_tile; tile_number++) {
+ ImageTile *last_tile_created = NULL;
+ for (int tile_number = start_tile; tile_number <= end_tile; tile_number++) {
ImageTile *tile = BKE_image_add_tile(ima, tile_number, label);
if (tile != NULL) {
- ima->active_tile_index = BLI_findindex(&ima->tiles, tile);
-
if (fill_tile) {
do_fill_tile(op->ptr, ima, tile);
}
- created_tile = true;
+ last_tile_created = tile;
}
}
MEM_freeN(label);
- if (!created_tile) {
+ if (!last_tile_created) {
+ BKE_report(op->reports, RPT_WARNING, "No UDIM tiles were created");
return OPERATOR_CANCELLED;
}
+ ima->active_tile_index = BLI_findindex(&ima->tiles, last_tile_created);
+
WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
return OPERATOR_FINISHED;
}
@@ -4040,7 +4049,7 @@ static bool tile_remove_poll(bContext *C)
{
Image *ima = CTX_data_edit_image(C);
- return (ima != NULL && ima->source == IMA_SRC_TILED && ima->active_tile_index != 0);
+ return (ima != NULL && ima->source == IMA_SRC_TILED && !BLI_listbase_is_single(&ima->tiles));
}
static int tile_remove_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/editors/space_image/image_sequence.c b/source/blender/editors/space_image/image_sequence.c
index 02546e3e3b3..c4f111264a3 100644
--- a/source/blender/editors/space_image/image_sequence.c
+++ b/source/blender/editors/space_image/image_sequence.c
@@ -68,7 +68,7 @@ static void image_sequence_get_frame_ranges(wmOperator *op, ListBase *ranges)
RNA_BEGIN (op->ptr, itemptr, "files") {
char head[FILE_MAX], tail[FILE_MAX];
ushort digits;
- char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
ImageFrame *frame = MEM_callocN(sizeof(ImageFrame), "image_frame");
/* use the first file in the list as base filename */
@@ -124,7 +124,7 @@ static int image_cmp_frame(const void *a, const void *b)
*
* udim_tiles may get filled even if the result ultimately is false!
*/
-static int image_get_udim(char *filepath, ListBase *udim_tiles)
+static bool image_get_udim(char *filepath, ListBase *udim_tiles, int *udim_start, int *udim_range)
{
char filename[FILE_MAX], dirname[FILE_MAXDIR];
BLI_split_dirfile(filepath, dirname, filename, sizeof(dirname), sizeof(filename));
@@ -133,12 +133,12 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles)
char base_head[FILE_MAX], base_tail[FILE_MAX];
int id = BLI_path_sequence_decode(filename, base_head, base_tail, &digits);
- if (id < 1001 || id >= IMA_UDIM_MAX) {
- return 0;
+ if (id < 1001 || id > IMA_UDIM_MAX) {
+ return false;
}
bool is_udim = true;
- bool has_primary = false;
+ int min_udim = IMA_UDIM_MAX + 1;
int max_udim = 0;
struct direntry *dir;
@@ -155,26 +155,27 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles)
continue;
}
- if (id < 1001 || id >= IMA_UDIM_MAX) {
+ if (id < 1001 || id > IMA_UDIM_MAX) {
is_udim = false;
break;
}
- if (id == 1001) {
- has_primary = true;
- }
BLI_addtail(udim_tiles, BLI_genericNodeN(POINTER_FROM_INT(id)));
+ min_udim = min_ii(min_udim, id);
max_udim = max_ii(max_udim, id);
}
BLI_filelist_free(dir, totfile);
- if (is_udim && has_primary) {
+ if (is_udim && min_udim <= IMA_UDIM_MAX) {
char primary_filename[FILE_MAX];
- BLI_path_sequence_encode(primary_filename, base_head, base_tail, digits, 1001);
+ BLI_path_sequence_encode(primary_filename, base_head, base_tail, digits, min_udim);
BLI_join_dirfile(filepath, FILE_MAX, dirname, primary_filename);
- return max_udim - 1000;
+
+ *udim_start = min_udim;
+ *udim_range = max_udim - min_udim + 1;
+ return true;
}
- return 0;
+ return false;
}
/**
@@ -185,11 +186,12 @@ static void image_detect_frame_range(ImageFrameRange *range, const bool detect_u
{
/* UDIM */
if (detect_udim) {
- int len_udim = image_get_udim(range->filepath, &range->udim_tiles);
+ int udim_start, udim_range;
+ bool result = image_get_udim(range->filepath, &range->udim_tiles, &udim_start, &udim_range);
- if (len_udim > 0) {
- range->offset = 1001;
- range->length = len_udim;
+ if (result) {
+ range->offset = udim_start;
+ range->length = udim_range;
return;
}
}
diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c
index 94e53958524..a99396ecdf0 100644
--- a/source/blender/editors/space_info/info_ops.c
+++ b/source/blender/editors/space_info/info_ops.c
@@ -512,7 +512,7 @@ void FILE_OT_report_missing_files(wmOperatorType *ot)
static int find_missing_files_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0);
+ const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
const bool find_all = RNA_boolean_get(op->ptr, "find_all");
BKE_bpath_missing_files_find(bmain, searchpath, op->reports, find_all);
diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c
index 0498964c549..1b87a8c6b9d 100644
--- a/source/blender/editors/space_nla/nla_channels.c
+++ b/source/blender/editors/space_nla/nla_channels.c
@@ -562,7 +562,8 @@ void NLA_OT_action_pushdown(wmOperatorType *ot)
static bool nla_action_unlink_poll(bContext *C)
{
if (ED_operator_nla_active(C)) {
- return nla_panel_context(C, NULL, NULL, NULL);
+ PointerRNA adt_ptr;
+ return (nla_panel_context(C, &adt_ptr, NULL, NULL) && (adt_ptr.data != NULL));
}
/* something failed... */
diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c
index 2bf4c7d4344..c1b308d213f 100644
--- a/source/blender/editors/space_nla/nla_draw.c
+++ b/source/blender/editors/space_nla/nla_draw.c
@@ -140,13 +140,16 @@ static void nla_action_draw_keyframes(
if (key_len > 0) {
format = immVertexFormat();
- pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
- uint color_id = GPU_vertformat_attr_add(
+ KeyframeShaderBindings sh_bindings;
+ sh_bindings.pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ sh_bindings.size_id = GPU_vertformat_attr_add(
+ format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+ sh_bindings.color_id = GPU_vertformat_attr_add(
format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- uint outline_color_id = GPU_vertformat_attr_add(
+ sh_bindings.outline_color_id = GPU_vertformat_attr_add(
format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- uint flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
+ sh_bindings.flags_id = GPU_vertformat_attr_add(
+ format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
GPU_program_point_size(true);
immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
@@ -165,11 +168,7 @@ static void nla_action_draw_keyframes(
ak->key_type,
KEYFRAME_SHAPE_FRAME,
1.0f,
- pos_id,
- size_id,
- color_id,
- outline_color_id,
- flags_id,
+ &sh_bindings,
KEYFRAME_HANDLE_NONE,
KEYFRAME_EXTREME_NONE);
}
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c
index 56efcd8571f..c75b874833a 100644
--- a/source/blender/editors/space_nla/nla_edit.c
+++ b/source/blender/editors/space_nla/nla_edit.c
@@ -241,9 +241,7 @@ bool nlaedit_disable_tweakmode(bAnimContext *ac, bool do_solo)
ANIM_animdata_update(ac, &anim_data);
ANIM_animdata_freelist(&anim_data);
- /* if we managed to enter tweak-mode on at least one AnimData block,
- * set the flag for this in the active scene and send notifiers
- */
+ /* Clear the tweak-mode flag in the active scene and send notifiers. */
if (ac->scene) {
/* clear editing flag */
ac->scene->flag &= ~SCE_NLA_EDIT_ON;
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index 95eb1ccc025..0f7a911e3ce 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -3596,8 +3596,26 @@ static void std_node_socket_draw(
break;
}
case SOCK_TEXTURE: {
- uiTemplateID(
- layout, C, ptr, "default_value", "texture.new", nullptr, nullptr, 0, ICON_NONE, nullptr);
+ if (text[0] == '\0') {
+ uiTemplateID(layout,
+ C,
+ ptr,
+ "default_value",
+ "texture.new",
+ nullptr,
+ nullptr,
+ 0,
+ ICON_NONE,
+ nullptr);
+ }
+ else {
+ /* 0.3 split ratio is inconsistent, but use it here because the "New" button is large. */
+ uiLayout *row = uiLayoutSplit(layout, 0.3f, false);
+ uiItemL(row, text, 0);
+ uiTemplateID(
+ row, C, ptr, "default_value", "texture.new", nullptr, nullptr, 0, ICON_NONE, nullptr);
+ }
+
break;
}
case SOCK_MATERIAL: {
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 6ec6315a238..3b1a55f55ab 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -670,8 +670,8 @@ int node_get_colorid(bNode *node)
return TH_NODE_INPUT;
case NODE_CLASS_OUTPUT:
return (node->flag & NODE_DO_OUTPUT) ? TH_NODE_OUTPUT : TH_NODE;
- case NODE_CLASS_CONVERTOR:
- return TH_NODE_CONVERTOR;
+ case NODE_CLASS_CONVERTER:
+ return TH_NODE_CONVERTER;
case NODE_CLASS_OP_COLOR:
return TH_NODE_COLOR;
case NODE_CLASS_OP_VECTOR:
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index a6901c21862..411719cf6c0 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -17,6 +17,7 @@
#include "BLI_index_range.hh"
#include "BLI_listbase.h"
#include "BLI_map.hh"
+#include "BLI_rect.h"
#include "BLI_set.hh"
#include "BLI_string_ref.hh"
#include "BLI_string_search.h"
diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc
index c6c3ca27d6e..e908a61eed9 100644
--- a/source/blender/editors/space_node/node_relationships.cc
+++ b/source/blender/editors/space_node/node_relationships.cc
@@ -880,6 +880,8 @@ static void node_link_exit(bContext *C, wmOperator *op, bool apply_links)
bNodeTree *ntree = snode->edittree;
bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata;
bool do_tag_update = false;
+ /* View will be reset if no links connect. */
+ bool reset_view = true;
/* avoid updates while applying links */
ntree->is_updating = true;
@@ -917,6 +919,8 @@ static void node_link_exit(bContext *C, wmOperator *op, bool apply_links)
if (link->tonode) {
do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, link->tonode));
}
+
+ reset_view = false;
}
else {
nodeRemLink(ntree, link);
@@ -930,6 +934,10 @@ static void node_link_exit(bContext *C, wmOperator *op, bool apply_links)
snode_dag_update(C, snode);
}
+ if (reset_view) {
+ UI_view2d_edge_pan_cancel(C, &nldrag->pan_data);
+ }
+
BLI_remlink(&snode->runtime->linkdrag, nldrag);
/* links->data pointers are either held by the tree or freed already */
BLI_freelistN(&nldrag->links);
@@ -1207,6 +1215,8 @@ static void node_link_cancel(bContext *C, wmOperator *op)
BLI_remlink(&snode->runtime->linkdrag, nldrag);
+ UI_view2d_edge_pan_cancel(C, &nldrag->pan_data);
+
BLI_freelistN(&nldrag->links);
MEM_freeN(nldrag);
clear_picking_highlight(&snode->edittree->links);
@@ -1258,7 +1268,8 @@ void NODE_OT_link(wmOperatorType *ot)
NODE_EDGE_PAN_OUTSIDE_PAD,
NODE_EDGE_PAN_SPEED_RAMP,
NODE_EDGE_PAN_MAX_SPEED,
- NODE_EDGE_PAN_DELAY);
+ NODE_EDGE_PAN_DELAY,
+ NODE_EDGE_PAN_ZOOM_INFLUENCE);
}
/** \} */
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index 1ec1afe86fc..ff0bd533671 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -625,7 +625,7 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op)
}
const eDupli_ID_Flags dupli_flags = USER_DUP_OBJECT | (linked ? 0 : U.dupflag);
- BKE_collection_duplicate(bmain, parent, collection, dupli_flags, 0);
+ BKE_collection_duplicate(bmain, parent, collection, dupli_flags, LIB_ID_DUPLICATE_IS_ROOT_ID);
DEG_relations_tag_update(bmain);
WM_main_add_notifier(NC_SCENE | ND_LAYER, CTX_data_scene(C));
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 5be6c69363e..738db28a2b6 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -1773,7 +1773,7 @@ static void tree_element_to_path(TreeElement *te,
char buf[128], *name;
temnext = (TreeElement *)(ld->next->data);
- /* tsenext = TREESTORE(temnext); */ /* UNUSED */
+ // tsenext = TREESTORE(temnext); /* UNUSED */
nextptr = &temnext->rnaptr;
name = RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf), NULL);
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index a994368a0ec..d88ae82cc9a 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -92,6 +92,7 @@
#include "RNA_define.h"
#include "RNA_enum_types.h"
+#include "SEQ_relations.h"
#include "SEQ_sequencer.h"
#include "outliner_intern.h"
@@ -1281,18 +1282,31 @@ static void ebone_fn(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem),
}
}
-static void sequence_fn(int event, TreeElement *te, TreeStoreElem *tselem, void *scene_ptr)
+static void sequence_fn(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *scene_ptr)
{
Sequence *seq = (Sequence *)te->directdata;
- if (event == OL_DOP_SELECT) {
- Scene *scene = (Scene *)scene_ptr;
- Editing *ed = SEQ_editing_get(scene, false);
- if (BLI_findindex(ed->seqbasep, seq) != -1) {
+ Scene *scene = (Scene *)scene_ptr;
+ Editing *ed = SEQ_editing_get(scene, false);
+ if (BLI_findindex(ed->seqbasep, seq) != -1) {
+ if (event == OL_DOP_SELECT) {
ED_sequencer_select_sequence_single(scene, seq, true);
}
+ else if (event == OL_DOP_DESELECT) {
+ seq->flag &= ~SELECT;
+ }
+ else if (event == OL_DOP_HIDE) {
+ if (!(seq->flag & SEQ_MUTE)) {
+ seq->flag |= SEQ_MUTE;
+ SEQ_relations_invalidate_dependent(scene, seq);
+ }
+ }
+ else if (event == OL_DOP_UNHIDE) {
+ if (seq->flag & SEQ_MUTE) {
+ seq->flag &= ~SEQ_MUTE;
+ SEQ_relations_invalidate_dependent(scene, seq);
+ }
+ }
}
-
- (void)tselem;
}
static void gpencil_layer_fn(int event,
@@ -2709,16 +2723,6 @@ void OUTLINER_OT_modifier_operation(wmOperatorType *ot)
/** \name Data Menu Operator
* \{ */
-/* XXX: select linked is for RNA structs only. */
-static const EnumPropertyItem prop_data_op_types[] = {
- {OL_DOP_SELECT, "SELECT", 0, "Select", ""},
- {OL_DOP_DESELECT, "DESELECT", 0, "Deselect", ""},
- {OL_DOP_HIDE, "HIDE", 0, "Hide", ""},
- {OL_DOP_UNHIDE, "UNHIDE", 0, "Unhide", ""},
- {OL_DOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
- {0, NULL, 0, NULL, NULL},
-};
-
static int outliner_data_operation_exec(bContext *C, wmOperator *op)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@@ -2762,6 +2766,8 @@ static int outliner_data_operation_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
outliner_do_data_operation(
space_outliner, datalevel, event, &space_outliner->tree, sequence_fn, scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
+ ED_undo_push(C, "Sequencer operation");
break;
}
@@ -2789,6 +2795,42 @@ static int outliner_data_operation_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
+/* Dynamically populate an enum of Keying Sets */
+static const EnumPropertyItem *outliner_data_op_sets_enum_item_fn(bContext *C,
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ bool *UNUSED(r_free))
+{
+ /* Check for invalid states. */
+ if (C == NULL) {
+ return DummyRNA_DEFAULT_items;
+ }
+
+ SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
+ if (space_outliner == NULL) {
+ return DummyRNA_DEFAULT_items;
+ }
+
+ static const EnumPropertyItem optype_sel_and_hide[] = {
+ {OL_DOP_SELECT, "SELECT", 0, "Select", ""},
+ {OL_DOP_DESELECT, "DESELECT", 0, "Deselect", ""},
+ {OL_DOP_HIDE, "HIDE", 0, "Hide", ""},
+ {OL_DOP_UNHIDE, "UNHIDE", 0, "Unhide", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+ static const EnumPropertyItem optype_sel_linked[] = {
+ {OL_DOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""}, {0, NULL, 0, NULL, NULL}};
+
+ TreeElement *te = get_target_element(space_outliner);
+ TreeStoreElem *tselem = TREESTORE(te);
+
+ if (tselem->type == TSE_RNA_STRUCT) {
+ return optype_sel_linked;
+ }
+
+ return optype_sel_and_hide;
+}
+
void OUTLINER_OT_data_operation(wmOperatorType *ot)
{
/* identifiers */
@@ -2802,7 +2844,8 @@ void OUTLINER_OT_data_operation(wmOperatorType *ot)
ot->flag = 0;
- ot->prop = RNA_def_enum(ot->srna, "type", prop_data_op_types, 0, "Data Operation", "");
+ ot->prop = RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Data Operation", "");
+ RNA_def_enum_funcs(ot->prop, outliner_data_op_sets_enum_item_fn);
}
/** \} */
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
index 50cfa2e71c7..13adf6bfc2d 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -47,12 +47,14 @@
static int run_pyfile_exec(bContext *C, wmOperator *op)
{
- char path[512];
+ char path[FILE_MAX];
RNA_string_get(op->ptr, "filepath", path);
#ifdef WITH_PYTHON
if (BPY_run_filepath(C, path, op->reports)) {
ARegion *region = CTX_wm_region(C);
- ED_region_tag_redraw(region);
+ if (region != NULL) {
+ ED_region_tag_redraw(region);
+ }
return OPERATOR_FINISHED;
}
#else
@@ -70,7 +72,6 @@ void SCRIPT_OT_python_file_run(wmOperatorType *ot)
/* api callbacks */
ot->exec = run_pyfile_exec;
- ot->poll = ED_operator_areaactive;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index 265a52ed1a6..16b690dd6e4 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -254,11 +254,11 @@ static void load_data_init_from_operator(SeqLoadData *load_data, bContext *C, wm
BLI_strncpy(load_data->name, BLI_path_basename(load_data->path), sizeof(load_data->name));
}
else if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
- char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0);
+ char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
- char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
BLI_strncpy(load_data->name, filename, sizeof(load_data->name));
BLI_join_dirfile(load_data->path, sizeof(load_data->path), directory, filename);
MEM_freeN(filename);
@@ -643,15 +643,17 @@ static void sequencer_add_movie_multiple_strips(bContext *C,
BLI_strncpy(load_data->name, file_only, sizeof(load_data->name));
Sequence *seq_movie = NULL;
Sequence *seq_sound = NULL;
+ double video_start_offset;
+
load_data->channel++;
- seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data);
+ seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data, &video_start_offset);
load_data->channel--;
if (seq_movie == NULL) {
BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path);
}
else {
if (RNA_boolean_get(op->ptr, "sound")) {
- seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data);
+ seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, video_start_offset);
}
load_data->start_frame += seq_movie->enddisp - seq_movie->startdisp;
seq_load_apply_generic_options(C, op, seq_sound);
@@ -670,8 +672,10 @@ static bool sequencer_add_movie_single_strip(bContext *C, wmOperator *op, SeqLoa
Sequence *seq_movie = NULL;
Sequence *seq_sound = NULL;
+ double video_start_offset;
+
load_data->channel++;
- seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data);
+ seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data, &video_start_offset);
load_data->channel--;
if (seq_movie == NULL) {
@@ -679,7 +683,7 @@ static bool sequencer_add_movie_single_strip(bContext *C, wmOperator *op, SeqLoa
return false;
}
if (RNA_boolean_get(op->ptr, "sound")) {
- seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data);
+ seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, video_start_offset);
}
seq_load_apply_generic_options(C, op, seq_sound);
seq_load_apply_generic_options(C, op, seq_movie);
@@ -707,13 +711,13 @@ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op)
}
else {
if (!sequencer_add_movie_single_strip(C, op, &load_data)) {
+ sequencer_add_cancel(C, op);
return OPERATOR_CANCELLED;
}
}
- if (op->customdata) {
- MEM_freeN(op->customdata);
- }
+ /* Free custom data. */
+ sequencer_add_cancel(C, op);
DEG_relations_tag_update(bmain);
DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
@@ -822,7 +826,7 @@ static void sequencer_add_sound_multiple_strips(bContext *C,
RNA_string_get(&itemptr, "name", file_only);
BLI_join_dirfile(load_data->path, sizeof(load_data->path), dir_only, file_only);
BLI_strncpy(load_data->name, file_only, sizeof(load_data->name));
- Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data);
+ Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, 0.0f);
if (seq == NULL) {
BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path);
}
@@ -840,7 +844,7 @@ static bool sequencer_add_sound_single_strip(bContext *C, wmOperator *op, SeqLoa
Scene *scene = CTX_data_scene(C);
Editing *ed = SEQ_editing_get(scene, true);
- Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data);
+ Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, 0.0f);
if (seq == NULL) {
BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path);
return false;
@@ -940,7 +944,7 @@ int sequencer_image_seq_get_minmax_frame(wmOperator *op,
RNA_BEGIN (op->ptr, itemptr, "files") {
char *filename;
int frame;
- filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
if (filename) {
if (BLI_path_frame_get(filename, &frame, &numdigits)) {
@@ -969,7 +973,7 @@ void sequencer_image_seq_reserve_frames(
{
char *filename = NULL;
RNA_BEGIN (op->ptr, itemptr, "files") {
- filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
break;
}
RNA_END;
@@ -1019,7 +1023,7 @@ static void sequencer_add_image_strip_load_files(
else {
size_t strip_frame = 0;
RNA_BEGIN (op->ptr, itemptr, "files") {
- char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
SEQ_add_image_load_file(seq, strip_frame, filename);
MEM_freeN(filename);
strip_frame++;
@@ -1040,6 +1044,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
load_data.image.len = sequencer_add_image_strip_calculate_length(
op, load_data.start_frame, &minframe, &numdigits);
if (load_data.image.len == 0) {
+ sequencer_add_cancel(C, op);
return OPERATOR_CANCELLED;
}
@@ -1062,9 +1067,8 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
- if (op->customdata) {
- MEM_freeN(op->customdata);
- }
+ /* Free custom data. */
+ sequencer_add_cancel(C, op);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 0472e1264ce..b3c39e2fa6f 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -228,9 +228,93 @@ void color3ubv_from_seq(Scene *curscene, Sequence *seq, uchar col[3])
}
}
+typedef struct WaveVizData {
+ float pos[2];
+ float rms_pos;
+ bool clip;
+ bool end;
+} WaveVizData;
+
+static int get_section_len(WaveVizData *start, WaveVizData *end)
+{
+ int len = 0;
+ while (start != end) {
+ len++;
+ if (start->end) {
+ return len;
+ }
+ start++;
+ }
+ return len;
+}
+
+static void draw_waveform(WaveVizData *iter, WaveVizData *end, GPUPrimType prim_type, bool use_rms)
+{
+ int strip_len = get_section_len(iter, end);
+ if (strip_len > 1) {
+ GPU_blend(GPU_BLEND_ALPHA);
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(prim_type, strip_len);
+
+ while (iter != end) {
+ if (iter->clip) {
+ immAttr4f(col, 1.0f, 0.0f, 0.0f, 0.5f);
+ }
+ else if (use_rms) {
+ immAttr4f(col, 1.0f, 1.0f, 1.0f, 0.8f);
+ }
+ else {
+ immAttr4f(col, 1.0f, 1.0f, 1.0f, 0.5f);
+ }
+
+ if (use_rms) {
+ immVertex2f(pos, iter->pos[0], iter->rms_pos);
+ }
+ else {
+ immVertex2f(pos, iter->pos[0], iter->pos[1]);
+ }
+
+ if (iter->end) {
+ /* End of line. */
+ iter++;
+ strip_len = get_section_len(iter, end);
+ if (strip_len != 0) {
+ immEnd();
+ immUnbindProgram();
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(prim_type, strip_len);
+ }
+ }
+ else {
+ iter++;
+ }
+ }
+ immEnd();
+ immUnbindProgram();
+
+ GPU_blend(GPU_BLEND_NONE);
+ }
+}
+
+static float clamp_frame_coord_to_pixel(float frame_coord,
+ float pixel_frac,
+ float frames_per_pixel)
+{
+ float cur_pixel = (frame_coord / frames_per_pixel);
+ float new_pixel = (int)(frame_coord / frames_per_pixel) + pixel_frac;
+ if (cur_pixel > new_pixel) {
+ new_pixel += 1.0f;
+ }
+ return new_pixel * frames_per_pixel;
+}
+
/**
* \param x1, x2, y1, y2: The starting and end X value to draw the wave, same for y1 and y2.
- * \param stepsize: The width of a pixel.
+ * \param frames_per_pixel: The amount of pixels a whole frame takes up (x-axis direction).
*/
static void draw_seq_waveform_overlay(View2D *v2d,
const bContext *C,
@@ -241,29 +325,34 @@ static void draw_seq_waveform_overlay(View2D *v2d,
float y1,
float x2,
float y2,
- float stepsize)
+ float frames_per_pixel)
{
- /* Offset x1 and x2 values, to match view min/max, if strip is out of bounds. */
- int x1_offset = max_ff(v2d->cur.xmin, x1);
- int x2_offset = min_ff(v2d->cur.xmax + 1.0f, x2);
-
if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
- int length = floor((x2_offset - x1_offset) / stepsize) + 1;
- float ymid = (y1 + y2) / 2.0f;
- float yscale = (y2 - y1) / 2.0f;
- float samplestep;
- float startsample, endsample;
- float volume = seq->volume;
- float value1, value2;
- bSound *sound = seq->sound;
- SoundWaveform *waveform;
-
- if (length < 2) {
+ /* Make sure that the start drawing position is aligned to the pixels on the screen to avoid
+ * flickering when moving around the strip.
+ * To do this we figure out the fractional offset in pixel space by checking where the
+ * window starts.
+ * We then append this pixel offset to our strip start coordinate to ensure we are aligned to
+ * the screen pixel grid. */
+ float pixel_frac = v2d->cur.xmin / frames_per_pixel - floor(v2d->cur.xmin / frames_per_pixel);
+ float x1_adj = clamp_frame_coord_to_pixel(x1, pixel_frac, frames_per_pixel);
+
+ /* Offset x1 and x2 values, to match view min/max, if strip is out of bounds. */
+ float x1_offset = max_ff(v2d->cur.xmin, x1_adj);
+ float x2_offset = min_ff(v2d->cur.xmax, x2);
+
+ /* Calculate how long the strip that is in view is in pixels. */
+ int pix_strip_len = round((x2_offset - x1_offset) / frames_per_pixel);
+
+ if (pix_strip_len < 2) {
return;
}
+ bSound *sound = seq->sound;
+
BLI_spin_lock(sound->spinlock);
if (!sound->waveform) {
+ /* Load the waveform data if it hasn't been loaded and cached already. */
if (!(sound->tags & SOUND_TAGS_WAVEFORM_LOADING)) {
/* Prevent sounds from reloading. */
sound->tags |= SOUND_TAGS_WAVEFORM_LOADING;
@@ -277,87 +366,187 @@ static void draw_seq_waveform_overlay(View2D *v2d,
}
BLI_spin_unlock(sound->spinlock);
- waveform = sound->waveform;
+ SoundWaveform *waveform = sound->waveform;
/* Waveform could not be built. */
if (waveform->length == 0) {
return;
}
- startsample = floor((seq->startofs + seq->anim_startofs) / FPS *
- SOUND_WAVE_SAMPLES_PER_SECOND);
- endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS *
- SOUND_WAVE_SAMPLES_PER_SECOND);
- samplestep = (endsample - startsample) * stepsize / (x2 - x1);
+ /* F-curve lookup is quite expensive, so do this after precondition. */
+ FCurve *fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "volume", 0, NULL);
- length = min_ii(
- floor((waveform->length - startsample) / samplestep - (x1_offset - x1) / stepsize),
- length);
+ WaveVizData *tri_strip_arr = MEM_callocN(sizeof(*tri_strip_arr) * pix_strip_len * 2,
+ "tri_strip");
+ WaveVizData *line_strip_arr = MEM_callocN(sizeof(*line_strip_arr) * pix_strip_len,
+ "line_strip");
- if (length < 2) {
- return;
- }
+ WaveVizData *tri_strip_iter = tri_strip_arr;
+ WaveVizData *line_strip_iter = line_strip_arr;
- /* F-curve lookup is quite expensive, so do this after precondition. */
- FCurve *fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "volume", 0, NULL);
+ /* The y coordinate for the middle of the strip. */
+ float y_mid = (y1 + y2) / 2.0f;
+ /* The length from the middle of the strip to the top/bottom. */
+ float y_scale = (y2 - y1) / 2.0f;
+ float volume = seq->volume;
- GPU_blend(GPU_BLEND_ALPHA);
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
- immBegin(GPU_PRIM_TRI_STRIP, length * 2);
+ /* Value to keep track if the previous item to be drawn was a line strip. */
+ int8_t was_line_strip = -1; /* -1 == no previous value. */
- for (int i = 0; i < length; i++) {
- float sampleoffset = startsample + ((x1_offset - x1) / stepsize + i) * samplestep;
- int p = sampleoffset;
+ float samples_per_frame = SOUND_WAVE_SAMPLES_PER_SECOND / FPS;
- value1 = waveform->data[p * 3];
- value2 = waveform->data[p * 3 + 1];
+ /* How many samples do we have for each pixel? */
+ float samples_per_pix = samples_per_frame * frames_per_pixel;
- if (samplestep > 1.0f) {
- for (int j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) {
- if (value1 > waveform->data[j * 3]) {
- value1 = waveform->data[j * 3];
- }
+ float strip_start_offset = seq->startofs + seq->anim_startofs;
+ float start_sample = 0;
- if (value2 < waveform->data[j * 3 + 1]) {
- value2 = waveform->data[j * 3 + 1];
- }
- }
+ if (strip_start_offset != 0) {
+ /* If start offset is not zero, we need to make sure that we pick the same start sample as if
+ * we simply scrolled the start of the strip off-screen. Otherwise we will get flickering
+ * when changing start offset as the pixel alignment will not be the same for the drawn
+ * samples. */
+ strip_start_offset = clamp_frame_coord_to_pixel(
+ x1 - strip_start_offset, pixel_frac, frames_per_pixel);
+ start_sample = fabsf(strip_start_offset - x1_adj) * samples_per_frame;
+ }
+
+ start_sample += seq->sound->offset_time * SOUND_WAVE_SAMPLES_PER_SECOND;
+ /* If we scrolled the start off-screen, then the start sample should be at the first visible
+ * sample. */
+ start_sample += (x1_offset - x1_adj) * samples_per_frame;
+
+ for (int i = 0; i < pix_strip_len; i++) {
+ float sample_offset = start_sample + i * samples_per_pix;
+ int p = sample_offset;
+
+ if (p >= waveform->length) {
+ break;
}
- else if (p + 1 < waveform->length) {
+
+ float value_min = waveform->data[p * 3];
+ float value_max = waveform->data[p * 3 + 1];
+ float rms = waveform->data[p * 3 + 2];
+
+ if (p + 1 < waveform->length) {
/* Use simple linear interpolation. */
- float f = sampleoffset - p;
- value1 = (1.0f - f) * value1 + f * waveform->data[p * 3 + 3];
- value2 = (1.0f - f) * value2 + f * waveform->data[p * 3 + 4];
+ float f = sample_offset - p;
+ value_min = (1.0f - f) * value_min + f * waveform->data[p * 3 + 3];
+ value_max = (1.0f - f) * value_max + f * waveform->data[p * 3 + 4];
+ rms = (1.0f - f) * rms + f * waveform->data[p * 3 + 5];
+ if (samples_per_pix > 1.0f) {
+ /* We need to sum up the values we skip over until the next step. */
+ float next_pos = sample_offset + samples_per_pix;
+ int end_idx = next_pos;
+
+ for (int j = p + 1; (j < waveform->length) && (j < end_idx); j++) {
+ value_min = min_ff(value_min, waveform->data[j * 3]);
+ value_max = max_ff(value_max, waveform->data[j * 3 + 1]);
+ rms = max_ff(rms, waveform->data[j * 3 + 2]);
+ }
+ }
}
if (fcu && !BKE_fcurve_is_empty(fcu)) {
- float evaltime = x1_offset + (i * stepsize);
+ float evaltime = x1_offset + (i * frames_per_pixel);
volume = evaluate_fcurve(fcu, evaltime);
CLAMP_MIN(volume, 0.0f);
}
- value1 *= volume;
- value2 *= volume;
- if (value2 > 1 || value1 < -1) {
- immAttr4f(col, 1.0f, 0.0f, 0.0f, 0.5f);
+ value_min *= volume;
+ value_max *= volume;
+ rms *= volume;
+
+ bool clipping = false;
- CLAMP_MAX(value2, 1.0f);
- CLAMP_MIN(value1, -1.0f);
+ if (value_max > 1 || value_min < -1) {
+ clipping = true;
+
+ CLAMP_MAX(value_max, 1.0f);
+ CLAMP_MIN(value_min, -1.0f);
}
- else {
- immAttr4f(col, 1.0f, 1.0f, 1.0f, 0.5f);
+
+ bool is_line_strip = (value_max - value_min < 0.05f);
+
+ if (was_line_strip != -1 && is_line_strip != was_line_strip) {
+ /* If the previously added strip type isn't the same as the current one,
+ * add transition areas so they transition smoothly between each other. */
+ if (is_line_strip) {
+ /* This will be a line strip, end the tri strip. */
+ tri_strip_iter->pos[0] = x1_offset + i * frames_per_pixel;
+ tri_strip_iter->pos[1] = y_mid + value_min * y_scale;
+ tri_strip_iter->clip = clipping;
+ tri_strip_iter->rms_pos = tri_strip_iter->pos[1];
+ tri_strip_iter->end = true;
+
+ /* End of section. */
+ tri_strip_iter++;
+
+ /* Check if we are at the end.
+ * If so, skip one point line. */
+ if (i + 1 == pix_strip_len) {
+ continue;
+ }
+ }
+ else {
+ /* This will be a tri strip. */
+ line_strip_iter--;
+ tri_strip_iter->pos[0] = line_strip_iter->pos[0];
+ tri_strip_iter->pos[1] = line_strip_iter->pos[1];
+ tri_strip_iter->clip = line_strip_iter->clip;
+ tri_strip_iter->rms_pos = line_strip_iter->pos[1];
+ tri_strip_iter++;
+
+ /* Check if line had only one point. */
+ line_strip_iter--;
+ if (line_strip_iter < line_strip_arr || line_strip_iter->end) {
+ /* Only one point, skip it. */
+ line_strip_iter++;
+ }
+ else {
+ /* End of section. */
+ line_strip_iter++;
+ line_strip_iter->end = true;
+ line_strip_iter++;
+ }
+ }
}
- immVertex2f(pos, x1_offset + i * stepsize, ymid + value1 * yscale);
- immVertex2f(pos, x1_offset + i * stepsize, ymid + value2 * yscale);
+ was_line_strip = is_line_strip;
+
+ if (is_line_strip) {
+ line_strip_iter->pos[0] = x1_offset + i * frames_per_pixel;
+ line_strip_iter->pos[1] = y_mid + value_min * y_scale;
+ line_strip_iter->clip = clipping;
+ line_strip_iter++;
+ }
+ else {
+ tri_strip_iter->pos[0] = x1_offset + i * frames_per_pixel;
+ tri_strip_iter->pos[1] = y_mid + value_min * y_scale;
+ tri_strip_iter->clip = clipping;
+ tri_strip_iter->rms_pos = y_mid + max_ff(-rms, value_min) * y_scale;
+ tri_strip_iter++;
+
+ tri_strip_iter->pos[0] = x1_offset + i * frames_per_pixel;
+ tri_strip_iter->pos[1] = y_mid + value_max * y_scale;
+ tri_strip_iter->clip = clipping;
+ tri_strip_iter->rms_pos = y_mid + min_ff(rms, value_max) * y_scale;
+ tri_strip_iter++;
+ }
}
- immEnd();
- immUnbindProgram();
- GPU_blend(GPU_BLEND_NONE);
+ WaveVizData *tri_strip_end = tri_strip_iter;
+ WaveVizData *line_strip_end = line_strip_iter;
+
+ tri_strip_iter = tri_strip_arr;
+ line_strip_iter = line_strip_arr;
+
+ draw_waveform(line_strip_iter, line_strip_end, GPU_PRIM_LINE_STRIP, false);
+ draw_waveform(tri_strip_iter, tri_strip_end, GPU_PRIM_TRI_STRIP, false);
+ draw_waveform(tri_strip_iter, tri_strip_end, GPU_PRIM_TRI_STRIP, true);
+
+ MEM_freeN(tri_strip_arr);
+ MEM_freeN(line_strip_arr);
}
}
@@ -1125,7 +1314,7 @@ static void draw_seq_strip(const bContext *C,
}
else {
text_margin_y = y2;
- y_threshold = 1;
+ y_threshold = false;
}
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 4b26469aad3..694e5fbb41d 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -1446,9 +1446,14 @@ static int sequencer_split_exec(bContext *C, wmOperator *op)
}
if (ignore_selection || seq->flag & SELECT) {
- if (SEQ_edit_strip_split(bmain, scene, ed->seqbasep, seq, split_frame, method) != NULL) {
+ const char *error_msg = NULL;
+ if (SEQ_edit_strip_split(bmain, scene, ed->seqbasep, seq, split_frame, method, &error_msg) !=
+ NULL) {
changed = true;
}
+ if (error_msg != NULL) {
+ BKE_report(op->reports, RPT_ERROR, error_msg);
+ }
}
}
@@ -2826,7 +2831,7 @@ static int sequencer_change_path_exec(bContext *C, wmOperator *op)
}
else {
RNA_BEGIN (op->ptr, itemptr, "files") {
- char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
BLI_strncpy(se->name, filename, sizeof(se->name));
MEM_freeN(filename);
se++;
@@ -2943,7 +2948,7 @@ static int seq_cmp_time_startdisp_channel(const void *a, const void *b)
int seq_a_start = SEQ_transform_get_left_handle_frame(seq_a);
int seq_b_start = SEQ_transform_get_left_handle_frame(seq_b);
- /** If strips have the same start frame favor the one with a higher channel. **/
+ /* If strips have the same start frame favor the one with a higher channel. */
if (seq_a_start == seq_b_start) {
return seq_a->machine > seq_b->machine;
}
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 00f3bf6ac72..2a6e49edfb6 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -194,7 +194,7 @@ static void sequencer_free(SpaceLink *sl)
SpaceSeq *sseq = (SpaceSeq *)sl;
SequencerScopes *scopes = &sseq->scopes;
- /* XXX if (sseq->gpd) BKE_gpencil_free(sseq->gpd); */
+ /* XXX if (sseq->gpd) BKE_gpencil_free_data(sseq->gpd); */
if (scopes->zebra_ibuf) {
IMB_freeImBuf(scopes->zebra_ibuf);
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 2b78ecb245d..f480f60a2b9 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -3424,25 +3424,26 @@ static int text_insert_exec(bContext *C, wmOperator *op)
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
char *str;
+ int str_len;
bool done = false;
size_t i = 0;
uint code;
text_drawcache_tag_update(st, 0);
- str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, &str_len);
ED_text_undo_push_init(C);
if (st && st->overwrite) {
while (str[i]) {
- code = BLI_str_utf8_as_unicode_step(str, &i);
+ code = BLI_str_utf8_as_unicode_step(str, str_len, &i);
done |= txt_replace_char(text, code);
}
}
else {
while (str[i]) {
- code = BLI_str_utf8_as_unicode_step(str, &i);
+ code = BLI_str_utf8_as_unicode_step(str, str_len, &i);
done |= txt_add_char(text, code);
}
}
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 3428a738dde..b79303551a1 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -1456,7 +1456,7 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "location", 0, NULL, ICON_NONE);
colsub = uiLayoutColumn(split, true);
- uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE);
+ uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE_OR_STATUS);
uiItemL(colsub, "", ICON_NONE);
uiItemR(colsub,
ptr,
@@ -1472,7 +1472,7 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "rotation_quaternion", 0, IFACE_("Rotation"), ICON_NONE);
colsub = uiLayoutColumn(split, true);
- uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE);
+ uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE_OR_STATUS);
uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, IFACE_("4L"), ICON_NONE);
if (RNA_boolean_get(ptr, "lock_rotations_4d")) {
uiItemR(colsub,
@@ -1496,7 +1496,7 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "rotation_axis_angle", 0, IFACE_("Rotation"), ICON_NONE);
colsub = uiLayoutColumn(split, true);
- uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE);
+ uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE_OR_STATUS);
uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, IFACE_("4L"), ICON_NONE);
if (RNA_boolean_get(ptr, "lock_rotations_4d")) {
uiItemR(colsub,
@@ -1520,7 +1520,7 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "rotation_euler", 0, IFACE_("Rotation"), ICON_NONE);
colsub = uiLayoutColumn(split, true);
- uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE);
+ uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE_OR_STATUS);
uiItemL(colsub, "", ICON_NONE);
uiItemR(colsub,
ptr,
@@ -1536,7 +1536,7 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "scale", 0, NULL, ICON_NONE);
colsub = uiLayoutColumn(split, true);
- uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE);
+ uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE_OR_STATUS);
uiItemL(colsub, "", ICON_NONE);
uiItemR(colsub,
ptr,
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index d87c14b9844..ec99affe43b 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1876,7 +1876,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
if (own_ofs) {
/* bind */
- ofs = GPU_offscreen_create(sizex, sizey, true, false, err_out);
+ ofs = GPU_offscreen_create(sizex, sizey, true, GPU_RGBA8, err_out);
if (ofs == NULL) {
DRW_opengl_context_disable();
return NULL;
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 49299d73337..edc34d0d883 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -299,7 +299,9 @@ static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3], cons
ED_view3d_win_to_3d_int(ruler_info->area->spacedata.first, ruler_info->region, r_co, xy, r_co);
}
-/* use for mousemove events */
+/**
+ * Use for mouse-move events.
+ */
static bool view3d_ruler_item_mousemove(struct Depsgraph *depsgraph,
RulerInfo *ruler_info,
RulerItem *ruler_item,
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index d926ea84e0f..88efc530484 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -843,7 +843,7 @@ bool ED_view3d_unproject_v3(
const int viewport[4] = {0, 0, region->winx, region->winy};
const float region_co[3] = {regionx, regiony, regionz};
- return GPU_matrix_unproject_3fv(region_co, rv3d->viewmat, rv3d->winmat, viewport, world);
+ return GPU_matrix_unproject_3fv(region_co, rv3d->viewinv, rv3d->winmat, viewport, world);
}
/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 2ce5684e874..e3f97dd1c63 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -2521,6 +2521,7 @@ static bool ed_object_select_pick(bContext *C,
}
/* also prevent making it active on mouse selection */
else if (BASE_SELECTABLE(v3d, basact)) {
+ const bool use_activate_selected_base = (oldbasact != basact) && (is_obedit == false);
if (extend) {
ED_object_base_select(basact, BA_SELECT);
}
@@ -2529,7 +2530,8 @@ static bool ed_object_select_pick(bContext *C,
}
else if (toggle) {
if (basact->flag & BASE_SELECTED) {
- if (basact == oldbasact) {
+ /* Keep selected if the base is to be activated. */
+ if (use_activate_selected_base == false) {
ED_object_base_select(basact, BA_DESELECT);
}
}
@@ -2545,7 +2547,7 @@ static bool ed_object_select_pick(bContext *C,
}
}
- if ((oldbasact != basact) && (is_obedit == false)) {
+ if (use_activate_selected_base) {
ED_object_base_activate(C, basact); /* adds notifier */
if ((scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) == 0) {
WM_toolsystem_update_from_context_view3d(C);
diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt
index ad0a330f0f4..e9efed3cd61 100644
--- a/source/blender/editors/transform/CMakeLists.txt
+++ b/source/blender/editors/transform/CMakeLists.txt
@@ -101,6 +101,7 @@ set(SRC
transform_ops.c
transform_orientations.c
transform_snap.c
+ transform_snap_animation.c
transform_snap_object.c
transform_snap_sequencer.c
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 4069a72a8fc..7a83fb71c28 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1671,6 +1671,13 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
+ if ((prop = RNA_struct_find_property(op->ptr, "view2d_edge_pan")) &&
+ RNA_property_is_set(op->ptr, prop)) {
+ if (RNA_property_boolean_get(op->ptr, prop)) {
+ options |= CTX_VIEW2D_EDGE_PAN;
+ }
+ }
+
t->options = options;
t->mode = mode;
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 1fa123e8507..013c5faa54a 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -94,6 +94,8 @@ typedef enum {
CTX_OBMODE_XFORM_OBDATA = (1 << 12),
/** Transform object parents without moving their children. */
CTX_OBMODE_XFORM_SKIP_CHILDREN = (1 << 13),
+ /** Enable edge scrolling in 2D views */
+ CTX_VIEW2D_EDGE_PAN = (1 << 14),
} eTContext;
/** #TransInfo.flag */
@@ -779,7 +781,6 @@ void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis
void applyTransObjects(TransInfo *t);
void restoreTransObjects(TransInfo *t);
-void recalcData(TransInfo *t);
void calculateCenter2D(TransInfo *t);
void calculateCenterLocal(TransInfo *t, const float center_global[3]);
diff --git a/source/blender/editors/transform/transform_convert.c b/source/blender/editors/transform/transform_convert.c
index 3f730956dd0..d756e2c90a6 100644
--- a/source/blender/editors/transform/transform_convert.c
+++ b/source/blender/editors/transform/transform_convert.c
@@ -1662,6 +1662,26 @@ void animrecord_check_state(TransInfo *t, struct Object *ob)
}
}
+void transform_convert_flush_handle2D(TransData *td, TransData2D *td2d, const float y_fac)
+{
+ float delta_x = td->loc[0] - td->iloc[0];
+ float delta_y = (td->loc[1] - td->iloc[1]) * y_fac;
+
+ /* If the handles are to be moved too
+ * (as side-effect of keyframes moving, to keep the general effect)
+ * offset them by the same amount so that the general angles are maintained
+ * (i.e. won't change while handles are free-to-roam and keyframes are snap-locked).
+ */
+ if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) {
+ td2d->h1[0] = td2d->ih1[0] + delta_x;
+ td2d->h1[1] = td2d->ih1[1] + delta_y;
+ }
+ if ((td->flag & TD_MOVEHANDLE2) && td2d->h2) {
+ td2d->h2[0] = td2d->ih2[0] + delta_x;
+ td2d->h2[1] = td2d->ih2[1] + delta_y;
+ }
+}
+
/* called for updating while transform acts, once per redraw */
void recalcData(TransInfo *t)
{
diff --git a/source/blender/editors/transform/transform_convert.h b/source/blender/editors/transform/transform_convert.h
index 971c23b8c69..9cb0400cad9 100644
--- a/source/blender/editors/transform/transform_convert.h
+++ b/source/blender/editors/transform/transform_convert.h
@@ -43,6 +43,8 @@ void sort_trans_data_dist(TransInfo *t);
void createTransData(struct bContext *C, TransInfo *t);
bool clipUVTransform(TransInfo *t, float vec[2], const bool resize);
void clipUVData(TransInfo *t);
+void transform_convert_flush_handle2D(TransData *td, TransData2D *td2d, const float y_fac);
+void recalcData(TransInfo *t);
/* transform_convert_mesh.c */
void transform_convert_mesh_customdatacorrect_init(TransInfo *t);
diff --git a/source/blender/editors/transform/transform_convert_action.c b/source/blender/editors/transform/transform_convert_action.c
index cfa14e21d0d..075db30fa61 100644
--- a/source/blender/editors/transform/transform_convert_action.c
+++ b/source/blender/editors/transform/transform_convert_action.c
@@ -45,6 +45,8 @@
#include "WM_types.h"
#include "transform.h"
+#include "transform_snap.h"
+
#include "transform_convert.h"
/* helper struct for gp-frame transforms */
@@ -140,19 +142,38 @@ static int count_masklayer_frames(MaskLayer *masklay, char side, float cfra, boo
}
/* This function assigns the information to transdata */
-static void TimeToTransData(TransData *td, float *time, AnimData *adt, float ypos)
+static void TimeToTransData(
+ TransData *td, TransData2D *td2d, BezTriple *bezt, AnimData *adt, float ypos)
{
- /* memory is calloc'ed, so that should zero everything nicely for us */
+ float *time = bezt->vec[1];
+
+ /* Setup #TransData2D. */
+ td2d->loc[0] = *time;
+ td2d->loc2d = time;
+ td2d->h1 = bezt->vec[0];
+ td2d->h2 = bezt->vec[2];
+ copy_v2_v2(td2d->ih1, td2d->h1);
+ copy_v2_v2(td2d->ih2, td2d->h2);
+
+ /* Setup #TransData. */
+ td->loc = time; /* Usually #td2d->loc is used here. But this is for when the original location is
+ not float[3]. */
+ copy_v3_v3(td->iloc, td->loc);
td->val = time;
td->ival = *(time);
-
td->center[0] = td->ival;
td->center[1] = ypos;
- /* store the AnimData where this keyframe exists as a keyframe of the
- * active action as td->extra.
- */
+ /* Store the AnimData where this keyframe exists as a keyframe of the
+ * active action as #td->extra. */
td->extra = adt;
+
+ if (bezt->f2 & SELECT) {
+ td->flag |= TD_SELECTED;
+ }
+
+ /* Set flags to move handles as necessary. */
+ td->flag |= TD_MOVEHANDLE1 | TD_MOVEHANDLE2;
}
/* This function advances the address to which td points to, so it must return
@@ -185,19 +206,7 @@ static TransData *ActionFCurveToTransData(TransData *td,
* so can't use BEZT_ISSEL_ANY() macro */
/* only add if on the right 'side' of the current frame */
if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
- TimeToTransData(td, bezt->vec[1], adt, ypos);
-
- if (bezt->f2 & SELECT) {
- td->flag |= TD_SELECTED;
- }
-
- /* Set flags to move handles as necessary. */
- td->flag |= TD_MOVEHANDLE1 | TD_MOVEHANDLE2;
- td2d->h1 = bezt->vec[0];
- td2d->h2 = bezt->vec[2];
-
- copy_v2_v2(td2d->ih1, td2d->h1);
- copy_v2_v2(td2d->ih2, td2d->h2);
+ TimeToTransData(td, td2d, bezt, adt, ypos);
td++;
td2d++;
@@ -233,16 +242,15 @@ static int GPLayerToTransData(TransData *td,
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
if (is_prop_edit || (gpf->flag & GP_FRAME_SELECT)) {
if (FrameOnMouseSide(side, (float)gpf->framenum, cfra)) {
- /* memory is calloc'ed, so that should zero everything nicely for us */
- td->val = &tfd->val;
- td->ival = (float)gpf->framenum;
+ tfd->val = (float)gpf->framenum;
+ tfd->sdata = &gpf->framenum;
+
+ td->val = td->loc = &tfd->val; /* XXX: It's not a 3d array. */
+ td->ival = td->iloc[0] = (float)gpf->framenum;
td->center[0] = td->ival;
td->center[1] = ypos;
- tfd->val = (float)gpf->framenum;
- tfd->sdata = &gpf->framenum;
-
/* Advance `td` now. */
td++;
tfd++;
@@ -598,6 +606,23 @@ void recalcData_actedit(TransInfo *t)
flushTransIntFrameActionData(t);
}
+ /* Flush 2d vector. */
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+ const short autosnap = getAnimEdit_SnapMode(t);
+ TransData *td;
+ TransData2D *td2d;
+ int i = 0;
+ for (td = tc->data, td2d = tc->data_2d; i < tc->data_len; i++, td++, td2d++) {
+ if ((autosnap != SACTSNAP_OFF) && (t->state != TRANS_CANCEL) && !(td->flag & TD_NOTIMESNAP)) {
+ transform_snap_anim_flush_data(t, td, autosnap, td->loc);
+ }
+
+ /* Constrain Y. */
+ td->loc[1] = td->iloc[1];
+
+ transform_convert_flush_handle2D(td, td2d, 0.0f);
+ }
+
if (ac.datatype != ANIMCONT_MASK) {
/* Get animdata blocks visible in editor,
* assuming that these will be the ones where things changed. */
diff --git a/source/blender/editors/transform/transform_convert_armature.c b/source/blender/editors/transform/transform_convert_armature.c
index f56d60b7376..5627a910ab4 100644
--- a/source/blender/editors/transform/transform_convert_armature.c
+++ b/source/blender/editors/transform/transform_convert_armature.c
@@ -131,12 +131,12 @@ static void autokeyframe_pose(
ListBase dsources = {NULL, NULL};
- /* add datasource override for the camera object */
+ /* Add data-source override for the camera object. */
ANIM_relative_keyingset_add_source(&dsources, id, &RNA_PoseBone, pchan);
/* only insert into active keyingset? */
if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
- /* run the active Keying Set on the current datasource */
+ /* Run the active Keying Set on the current data-source. */
ANIM_apply_keyingset(
C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
}
diff --git a/source/blender/editors/transform/transform_convert_graph.c b/source/blender/editors/transform/transform_convert_graph.c
index 111f81ff87b..d22277f9d91 100644
--- a/source/blender/editors/transform/transform_convert_graph.c
+++ b/source/blender/editors/transform/transform_convert_graph.c
@@ -40,7 +40,12 @@
#include "UI_view2d.h"
#include "transform.h"
+#include "transform_snap.h"
+
#include "transform_convert.h"
+#include "transform_snap.h"
+
+#include "transform_mode.h"
typedef struct TransDataGraph {
float unit_scale;
@@ -656,14 +661,12 @@ static bool fcu_test_selected(FCurve *fcu)
*/
static void flushTransGraphData(TransInfo *t)
{
- SpaceGraph *sipo = (SpaceGraph *)t->area->spacedata.first;
TransData *td;
TransData2D *td2d;
TransDataGraph *tdg;
- Scene *scene = t->scene;
- double secf = FPS;
int a;
+ const short autosnap = getAnimEdit_SnapMode(t);
TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
/* flush to 2d vector from internally used 3d vector */
@@ -679,21 +682,8 @@ static void flushTransGraphData(TransInfo *t)
* - Only apply to keyframes (but never to handles).
* - Don't do this when canceling, or else these changes won't go away.
*/
- if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0) {
- switch (sipo->autosnap) {
- case SACTSNAP_FRAME: /* snap to nearest frame */
- td2d->loc[0] = floor((double)td2d->loc[0] + 0.5);
- break;
-
- case SACTSNAP_SECOND: /* snap to nearest second */
- td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
- break;
-
- case SACTSNAP_MARKER: /* snap to nearest marker */
- td2d->loc[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers,
- td2d->loc[0]);
- break;
- }
+ if ((autosnap != SACTSNAP_OFF) && (t->state != TRANS_CANCEL) && !(td->flag & TD_NOTIMESNAP)) {
+ transform_snap_anim_flush_data(t, td, autosnap, td->loc);
}
/* we need to unapply the nla-mapping from the time in some situations */
@@ -704,32 +694,6 @@ static void flushTransGraphData(TransInfo *t)
td2d->loc2d[0] = td2d->loc[0];
}
- /** Time-stepping auto-snapping modes don't get applied for Graph Editor transforms,
- * as these use the generic transform modes which don't account for this sort of thing.
- * These ones aren't affected by NLA mapping, so we do this after the conversion...
- *
- * \note We also have to apply to td->loc,
- * as that's what the handle-adjustment step below looks to,
- * otherwise we get "swimming handles".
- *
- * \note We don't do this when canceling transforms, or else these changes don't go away.
- */
- if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0 &&
- ELEM(sipo->autosnap, SACTSNAP_STEP, SACTSNAP_TSTEP)) {
- switch (sipo->autosnap) {
- case SACTSNAP_STEP: /* frame step */
- td2d->loc2d[0] = floor((double)td2d->loc[0] + 0.5);
- td->loc[0] = floor((double)td->loc[0] + 0.5);
- break;
-
- case SACTSNAP_TSTEP: /* second step */
- /* XXX: the handle behavior in this case is still not quite right... */
- td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
- td->loc[0] = floor(((double)td->loc[0] / secf) + 0.5) * secf;
- break;
- }
- }
-
/* if int-values only, truncate to integers */
if (td->flag & TD_INTVALUES) {
td2d->loc2d[1] = floorf(td2d->loc[1] * inv_unit_scale - tdg->offset + 0.5f);
@@ -738,15 +702,7 @@ static void flushTransGraphData(TransInfo *t)
td2d->loc2d[1] = td2d->loc[1] * inv_unit_scale - tdg->offset;
}
- if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) {
- td2d->h1[0] = td2d->ih1[0] + td->loc[0] - td->iloc[0];
- td2d->h1[1] = td2d->ih1[1] + (td->loc[1] - td->iloc[1]) * inv_unit_scale;
- }
-
- if ((td->flag & TD_MOVEHANDLE2) && td2d->h2) {
- td2d->h2[0] = td2d->ih2[0] + td->loc[0] - td->iloc[0];
- td2d->h2[1] = td2d->ih2[1] + (td->loc[1] - td->iloc[1]) * inv_unit_scale;
- }
+ transform_convert_flush_handle2D(td, td2d, inv_unit_scale);
}
}
diff --git a/source/blender/editors/transform/transform_convert_nla.c b/source/blender/editors/transform/transform_convert_nla.c
index b55005673d9..7e5b80c2453 100644
--- a/source/blender/editors/transform/transform_convert_nla.c
+++ b/source/blender/editors/transform/transform_convert_nla.c
@@ -41,7 +41,12 @@
#include "RNA_access.h"
#include "transform.h"
+#include "transform_snap.h"
+
#include "transform_convert.h"
+#include "transform_snap.h"
+
+#include "transform_mode.h"
/** Used for NLA transform (stored in #TransData.extra pointer). */
typedef struct TransDataNla {
@@ -289,21 +294,30 @@ void createTransNlaData(bContext *C, TransInfo *t)
void recalcData_nla(TransInfo *t)
{
SpaceNla *snla = (SpaceNla *)t->area->spacedata.first;
- Scene *scene = t->scene;
- double secf = FPS;
- int i;
TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
- TransDataNla *tdn = tc->custom.type.data;
+
+ /* handle auto-snapping
+ * NOTE: only do this when transform is still running, or we can't restore
+ */
+ if (t->state != TRANS_CANCEL) {
+ const short autosnap = getAnimEdit_SnapMode(t);
+ if (autosnap != SACTSNAP_OFF) {
+ TransData *td = tc->data;
+ for (int i = 0; i < tc->data_len; i++, td++) {
+ transform_snap_anim_flush_data(t, td, autosnap, td->loc);
+ }
+ }
+ }
/* For each strip we've got, perform some additional validation of the values
* that got set before using RNA to set the value (which does some special
* operations when setting these values to make sure that everything works ok).
*/
- for (i = 0; i < tc->data_len; i++, tdn++) {
+ TransDataNla *tdn = tc->custom.type.data;
+ for (int i = 0; i < tc->data_len; i++, tdn++) {
NlaStrip *strip = tdn->strip;
PointerRNA strip_ptr;
- short iter;
int delta_y1, delta_y2;
/* if this tdn has no handles, that means it is just a dummy that should be skipped */
@@ -367,8 +381,7 @@ void recalcData_nla(TransInfo *t)
next = next->next;
}
- for (iter = 0; iter < 5; iter++) {
-
+ for (short iter = 0; iter < 5; iter++) {
const bool pExceeded = (prev != NULL) && (tdn->h1[0] < prev->end);
const bool nExceeded = (next != NULL) && (tdn->h2[0] > next->start);
@@ -407,50 +420,6 @@ void recalcData_nla(TransInfo *t)
}
}
- /* handle auto-snapping
- * NOTE: only do this when transform is still running, or we can't restore
- */
- if (t->state != TRANS_CANCEL) {
- switch (snla->autosnap) {
- case SACTSNAP_FRAME: /* snap to nearest frame */
- case SACTSNAP_STEP: /* frame step - this is basically the same,
- * since we don't have any remapping going on */
- {
- tdn->h1[0] = floorf(tdn->h1[0] + 0.5f);
- tdn->h2[0] = floorf(tdn->h2[0] + 0.5f);
- break;
- }
-
- case SACTSNAP_SECOND: /* snap to nearest second */
- case SACTSNAP_TSTEP: /* second step - this is basically the same,
- * since we don't have any remapping going on */
- {
- /* This case behaves differently from the rest, since lengths of strips
- * may not be multiples of a second. If we just naively resize adjust
- * the handles, things may not work correctly. Instead, we only snap
- * the first handle, and move the other to fit.
- *
- * FIXME: we do run into problems here when user attempts to negatively
- * scale the strip, as it then just compresses down and refuses
- * to expand out the other end.
- */
- float h1_new = (float)(floor(((double)tdn->h1[0] / secf) + 0.5) * secf);
- float delta = h1_new - tdn->h1[0];
-
- tdn->h1[0] = h1_new;
- tdn->h2[0] += delta;
- break;
- }
-
- case SACTSNAP_MARKER: /* snap to nearest marker */
- {
- tdn->h1[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, tdn->h1[0]);
- tdn->h2[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, tdn->h2[0]);
- break;
- }
- }
- }
-
/* Use RNA to write the values to ensure that constraints on these are obeyed
* (e.g. for transition strips, the values are taken from the neighbors)
*
diff --git a/source/blender/editors/transform/transform_convert_node.c b/source/blender/editors/transform/transform_convert_node.c
index 9d2d3713bf0..ecc7f01be33 100644
--- a/source/blender/editors/transform/transform_convert_node.c
+++ b/source/blender/editors/transform/transform_convert_node.c
@@ -46,12 +46,6 @@
/** \name Node Transform Creation
* \{ */
-typedef struct NodeTransCustomData {
- /* Initial rect of the view2d, used for computing offset during edge panning */
- rctf initial_v2d_cur;
- View2DEdgePanData edge_pan;
-} NodeTransCustomData;
-
/* transcribe given node into TransData2D for Transforming */
static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node, const float dpi_fac)
{
@@ -115,21 +109,16 @@ void createTransNodeData(TransInfo *t)
const float dpi_fac = UI_DPI_FAC;
SpaceNode *snode = t->area->spacedata.first;
- if (t->mode == TFM_TRANSLATION) {
- /* Disable cursor wrapping in the node editor for edge pan */
- t->flag |= T_NO_CURSOR_WRAP;
- }
-
/* Custom data to enable edge panning during the node transform */
- NodeTransCustomData *customdata = MEM_callocN(sizeof(*customdata), __func__);
+ View2DEdgePanData *customdata = MEM_callocN(sizeof(*customdata), __func__);
UI_view2d_edge_pan_init(t->context,
- &customdata->edge_pan,
+ customdata,
NODE_EDGE_PAN_INSIDE_PAD,
NODE_EDGE_PAN_OUTSIDE_PAD,
NODE_EDGE_PAN_SPEED_RAMP,
NODE_EDGE_PAN_MAX_SPEED,
- NODE_EDGE_PAN_DELAY);
- customdata->initial_v2d_cur = t->region->v2d.cur;
+ NODE_EDGE_PAN_DELAY,
+ NODE_EDGE_PAN_ZOOM_INFLUENCE);
t->custom.type.data = customdata;
t->custom.type.use_free = true;
@@ -176,17 +165,22 @@ void flushTransNodes(TransInfo *t)
{
const float dpi_fac = UI_DPI_FAC;
- NodeTransCustomData *customdata = (NodeTransCustomData *)t->custom.type.data;
+ View2DEdgePanData *customdata = (View2DEdgePanData *)t->custom.type.data;
- if (t->mode == TFM_TRANSLATION) {
- /* Edge panning functions expect window coordinates, mval is relative to region */
- const float x = t->region->winrct.xmin + t->mval[0];
- const float y = t->region->winrct.ymin + t->mval[1];
- UI_view2d_edge_pan_apply(t->context, &customdata->edge_pan, x, y);
+ if (t->options & CTX_VIEW2D_EDGE_PAN) {
+ if (t->state == TRANS_CANCEL) {
+ UI_view2d_edge_pan_cancel(t->context, customdata);
+ }
+ else {
+ /* Edge panning functions expect window coordinates, mval is relative to region */
+ const float x = t->region->winrct.xmin + t->mval[0];
+ const float y = t->region->winrct.ymin + t->mval[1];
+ UI_view2d_edge_pan_apply(t->context, customdata, x, y);
+ }
}
/* Initial and current view2D rects for additional transform due to view panning and zooming */
- const rctf *rect_src = &customdata->initial_v2d_cur;
+ const rctf *rect_src = &customdata->initial_rect;
const rctf *rect_dst = &t->region->v2d.cur;
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
diff --git a/source/blender/editors/transform/transform_convert_object.c b/source/blender/editors/transform/transform_convert_object.c
index ee6cb391fdc..bcbac009948 100644
--- a/source/blender/editors/transform/transform_convert_object.c
+++ b/source/blender/editors/transform/transform_convert_object.c
@@ -749,7 +749,7 @@ static void autokeyframe_object(
/* Get flags used for inserting keyframes. */
flag = ANIM_get_keyframing_flags(scene, true);
- /* add datasource override for the object */
+ /* Add data-source override for the object. */
ANIM_relative_keyingset_add_source(&dsources, id, NULL, NULL);
if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
diff --git a/source/blender/editors/transform/transform_convert_sequencer.c b/source/blender/editors/transform/transform_convert_sequencer.c
index 17512c79d03..45ed0f3b664 100644
--- a/source/blender/editors/transform/transform_convert_sequencer.c
+++ b/source/blender/editors/transform/transform_convert_sequencer.c
@@ -400,15 +400,14 @@ static void seq_transform_handle_overlap(TransInfo *t, SeqCollection *transforme
if (seq_transform_check_strip_effects(transformed_strips)) {
/* Update effect strips based on strips just moved in time. */
seq_transform_update_effects(t, transformed_strips);
+ }
- /* If any effects still overlap, we need to move them up. */
- Sequence *seq;
- SEQ_ITERATOR_FOREACH (seq, transformed_strips) {
- if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) {
- if (SEQ_transform_test_overlap(seqbasep, seq)) {
- SEQ_transform_seqbase_shuffle(seqbasep, seq, t->scene);
- }
- }
+ /* If any effects still overlap, we need to move them up.
+ * In some cases other strips can be overlapping still, see T90646. */
+ Sequence *seq;
+ SEQ_ITERATOR_FOREACH (seq, transformed_strips) {
+ if (SEQ_transform_test_overlap(seqbasep, seq)) {
+ SEQ_transform_seqbase_shuffle(seqbasep, seq, t->scene);
}
}
}
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index be8e551a1e8..9f5e74db501 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -60,6 +60,7 @@
#include "UI_view2d.h"
#include "transform.h"
+#include "transform_convert.h"
#include "transform_mode.h"
#include "transform_orientations.h"
#include "transform_snap.h"
@@ -624,6 +625,11 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
#endif
+ /* Disable cursor wrap when edge panning is enabled. */
+ if (t->options & CTX_VIEW2D_EDGE_PAN) {
+ t->flag |= T_NO_CURSOR_WRAP;
+ }
+
setTransformViewAspect(t, t->aspect);
if (op && (prop = RNA_struct_find_property(op->ptr, "center_override")) &&
diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c
index 65a673940f8..8df95222fa1 100644
--- a/source/blender/editors/transform/transform_mode.c
+++ b/source/blender/editors/transform/transform_mode.c
@@ -968,9 +968,9 @@ void ElementResize(const TransInfo *t,
float obsizemat[3][3];
/* Reorient the size mat to fit the oriented object. */
mul_m3_m3m3(obsizemat, tmat, td->axismtx);
- /* print_m3("obsizemat", obsizemat); */
+ // print_m3("obsizemat", obsizemat);
TransMat3ToSize(obsizemat, td->axismtx, fsize);
- /* print_v3("fsize", fsize); */
+ // print_v3("fsize", fsize);
}
else {
mat3_to_size(fsize, tmat);
@@ -1068,102 +1068,6 @@ void ElementResize(const TransInfo *t,
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Transform (Frame Utils)
- * \{ */
-
-/**
- * This function returns the snapping 'mode' for Animation Editors only.
- * We cannot use the standard snapping due to NLA-strip scaling complexities.
- *
- * TODO: these modifier checks should be key-mappable.
- */
-short getAnimEdit_SnapMode(TransInfo *t)
-{
- short autosnap = SACTSNAP_OFF;
-
- if (t->spacetype == SPACE_ACTION) {
- SpaceAction *saction = (SpaceAction *)t->area->spacedata.first;
-
- if (saction) {
- autosnap = saction->autosnap;
- }
- }
- else if (t->spacetype == SPACE_GRAPH) {
- SpaceGraph *sipo = (SpaceGraph *)t->area->spacedata.first;
-
- if (sipo) {
- autosnap = sipo->autosnap;
- }
- }
- else if (t->spacetype == SPACE_NLA) {
- SpaceNla *snla = (SpaceNla *)t->area->spacedata.first;
-
- if (snla) {
- autosnap = snla->autosnap;
- }
- }
- else {
- autosnap = SACTSNAP_OFF;
- }
-
- /* toggle autosnap on/off
- * - when toggling on, prefer nearest frame over 1.0 frame increments
- */
- if (t->modifiers & MOD_SNAP_INVERT) {
- if (autosnap) {
- autosnap = SACTSNAP_OFF;
- }
- else {
- autosnap = SACTSNAP_FRAME;
- }
- }
-
- return autosnap;
-}
-
-/* This function is used by Animation Editor specific transform functions to do
- * the Snap Keyframe to Nearest Frame/Marker
- */
-void doAnimEdit_SnapFrame(
- TransInfo *t, TransData *td, TransData2D *td2d, AnimData *adt, short autosnap)
-{
- if (autosnap != SACTSNAP_OFF) {
- float val;
-
- /* convert frame to nla-action time (if needed) */
- if (adt && (t->spacetype != SPACE_SEQ)) {
- val = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP);
- }
- else {
- val = *(td->val);
- }
-
- snapFrameTransform(t, autosnap, true, val, &val);
-
- /* convert frame out of nla-action time */
- if (adt && (t->spacetype != SPACE_SEQ)) {
- *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
- }
- else {
- *(td->val) = val;
- }
- }
-
- /* If the handles are to be moved too
- * (as side-effect of keyframes moving, to keep the general effect)
- * offset them by the same amount so that the general angles are maintained
- * (i.e. won't change while handles are free-to-roam and keyframes are snap-locked).
- */
- if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) {
- td2d->h1[0] = td2d->ih1[0] + *td->val - td->ival;
- }
- if ((td->flag & TD_MOVEHANDLE2) && td2d->h2) {
- td2d->h2[0] = td2d->ih2[0] + *td->val - td->ival;
- }
-}
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Transform Mode Initialization
* \{ */
diff --git a/source/blender/editors/transform/transform_mode.h b/source/blender/editors/transform/transform_mode.h
index 027fb6b6982..d8601000ddb 100644
--- a/source/blender/editors/transform/transform_mode.h
+++ b/source/blender/editors/transform/transform_mode.h
@@ -63,9 +63,6 @@ void ElementResize(const TransInfo *t,
const TransDataContainer *tc,
TransData *td,
const float mat[3][3]);
-short getAnimEdit_SnapMode(TransInfo *t);
-void doAnimEdit_SnapFrame(
- TransInfo *t, TransData *td, TransData2D *td2d, struct AnimData *adt, short autosnap);
void transform_mode_init(TransInfo *t, struct wmOperator *op, const int mode);
void transform_mode_default_modal_orientation_set(TransInfo *t, int type);
diff --git a/source/blender/editors/transform/transform_mode_align.c b/source/blender/editors/transform/transform_mode_align.c
index 5bc2aa68443..1a1d84699f4 100644
--- a/source/blender/editors/transform/transform_mode_align.c
+++ b/source/blender/editors/transform/transform_mode_align.c
@@ -32,6 +32,8 @@
#include "BLT_translation.h"
#include "transform.h"
+#include "transform_convert.h"
+
#include "transform_mode.h"
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/transform/transform_mode_baketime.c b/source/blender/editors/transform/transform_mode_baketime.c
index 5efed6920dc..653944b56a7 100644
--- a/source/blender/editors/transform/transform_mode_baketime.c
+++ b/source/blender/editors/transform/transform_mode_baketime.c
@@ -36,9 +36,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Bake-Time)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_bbone_resize.c b/source/blender/editors/transform/transform_mode_bbone_resize.c
index e827e604327..95e2d944b9b 100644
--- a/source/blender/editors/transform/transform_mode_bbone_resize.c
+++ b/source/blender/editors/transform/transform_mode_bbone_resize.c
@@ -37,9 +37,11 @@
#include "transform.h"
#include "transform_constraints.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (EditBone B-Bone width scaling)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_bend.c b/source/blender/editors/transform/transform_mode_bend.c
index 850d26571cd..6d84c397fa6 100644
--- a/source/blender/editors/transform/transform_mode_bend.c
+++ b/source/blender/editors/transform/transform_mode_bend.c
@@ -44,9 +44,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Bend) Custom Data
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_boneenvelope.c b/source/blender/editors/transform/transform_mode_boneenvelope.c
index ced159a76c9..da7393ab42e 100644
--- a/source/blender/editors/transform/transform_mode_boneenvelope.c
+++ b/source/blender/editors/transform/transform_mode_boneenvelope.c
@@ -36,9 +36,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Bone Envelope)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_boneroll.c b/source/blender/editors/transform/transform_mode_boneroll.c
index da6c0b44c3a..cd04ca2b844 100644
--- a/source/blender/editors/transform/transform_mode_boneroll.c
+++ b/source/blender/editors/transform/transform_mode_boneroll.c
@@ -36,9 +36,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (EditBone Roll)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_curveshrinkfatten.c b/source/blender/editors/transform/transform_mode_curveshrinkfatten.c
index 68416c780ef..9433502ef55 100644
--- a/source/blender/editors/transform/transform_mode_curveshrinkfatten.c
+++ b/source/blender/editors/transform/transform_mode_curveshrinkfatten.c
@@ -36,9 +36,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Curve Shrink/Fatten)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_edge_bevelweight.c b/source/blender/editors/transform/transform_mode_edge_bevelweight.c
index 425bfec241e..5466ba3e91f 100644
--- a/source/blender/editors/transform/transform_mode_edge_bevelweight.c
+++ b/source/blender/editors/transform/transform_mode_edge_bevelweight.c
@@ -37,9 +37,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Bevel Weight) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_edge_crease.c b/source/blender/editors/transform/transform_mode_edge_crease.c
index 91e2507e544..1d3b4dbb4f0 100644
--- a/source/blender/editors/transform/transform_mode_edge_crease.c
+++ b/source/blender/editors/transform/transform_mode_edge_crease.c
@@ -37,9 +37,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Crease) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_edge_rotate_normal.c b/source/blender/editors/transform/transform_mode_edge_rotate_normal.c
index 6f2bcc148ce..1f57bacf78f 100644
--- a/source/blender/editors/transform/transform_mode_edge_rotate_normal.c
+++ b/source/blender/editors/transform/transform_mode_edge_rotate_normal.c
@@ -35,9 +35,10 @@
#include "UI_interface.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
/* -------------------------------------------------------------------- */
/** \name Transform (Normal Rotation)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_edge_slide.c b/source/blender/editors/transform/transform_mode_edge_slide.c
index 066a2853dc7..cfcb17b8da0 100644
--- a/source/blender/editors/transform/transform_mode_edge_slide.c
+++ b/source/blender/editors/transform/transform_mode_edge_slide.c
@@ -852,7 +852,7 @@ static EdgeSlideData *createEdgeSlideVerts_double_side(TransInfo *t, TransDataCo
#undef EDGESLIDE_VERT_IS_INNER
}
- /* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */
+ // EDBM_flag_disable_all(em, BM_ELEM_SELECT);
BLI_assert(STACK_SIZE(sv_array) == (uint)sv_tot);
@@ -1037,7 +1037,7 @@ static EdgeSlideData *createEdgeSlideVerts_single_side(TransInfo *t, TransDataCo
}
}
- /* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */
+ // EDBM_flag_disable_all(em, BM_ELEM_SELECT);
sld->sv = sv_array;
sld->totsv = sv_tot;
diff --git a/source/blender/editors/transform/transform_mode_gpopacity.c b/source/blender/editors/transform/transform_mode_gpopacity.c
index 7c496d271ef..748769491f1 100644
--- a/source/blender/editors/transform/transform_mode_gpopacity.c
+++ b/source/blender/editors/transform/transform_mode_gpopacity.c
@@ -38,9 +38,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (GPencil Strokes Opacity)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_gpshrinkfatten.c b/source/blender/editors/transform/transform_mode_gpshrinkfatten.c
index 608a49f38b1..bc081edd597 100644
--- a/source/blender/editors/transform/transform_mode_gpshrinkfatten.c
+++ b/source/blender/editors/transform/transform_mode_gpshrinkfatten.c
@@ -38,9 +38,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (GPencil Strokes Shrink/Fatten)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_maskshrinkfatten.c b/source/blender/editors/transform/transform_mode_maskshrinkfatten.c
index cfbd6030788..327a639773c 100644
--- a/source/blender/editors/transform/transform_mode_maskshrinkfatten.c
+++ b/source/blender/editors/transform/transform_mode_maskshrinkfatten.c
@@ -36,9 +36,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Mask Shrink/Fatten)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_mirror.c b/source/blender/editors/transform/transform_mode_mirror.c
index f225f1a7c06..2ae32f3545a 100644
--- a/source/blender/editors/transform/transform_mode_mirror.c
+++ b/source/blender/editors/transform/transform_mode_mirror.c
@@ -37,6 +37,8 @@
#include "BLT_translation.h"
#include "transform.h"
+#include "transform_convert.h"
+
#include "transform_mode.h"
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/transform/transform_mode_push_pull.c b/source/blender/editors/transform/transform_mode_push_pull.c
index 0492ec8df8c..0527d1bc08e 100644
--- a/source/blender/editors/transform/transform_mode_push_pull.c
+++ b/source/blender/editors/transform/transform_mode_push_pull.c
@@ -38,9 +38,11 @@
#include "transform.h"
#include "transform_constraints.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Push/Pull) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_rotate.c b/source/blender/editors/transform/transform_mode_rotate.c
index 44a29cfac45..bfbdaa389f4 100644
--- a/source/blender/editors/transform/transform_mode_rotate.c
+++ b/source/blender/editors/transform/transform_mode_rotate.c
@@ -34,9 +34,11 @@
#include "UI_interface.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Rotation) Matrix Cache
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_shear.c b/source/blender/editors/transform/transform_mode_shear.c
index f5672887905..018725ec6dd 100644
--- a/source/blender/editors/transform/transform_mode_shear.c
+++ b/source/blender/editors/transform/transform_mode_shear.c
@@ -41,9 +41,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Shear) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_shrink_fatten.c b/source/blender/editors/transform/transform_mode_shrink_fatten.c
index 4cdaab599b4..b96b8103392 100644
--- a/source/blender/editors/transform/transform_mode_shrink_fatten.c
+++ b/source/blender/editors/transform/transform_mode_shrink_fatten.c
@@ -40,9 +40,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Shrink-Fatten) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_skin_resize.c b/source/blender/editors/transform/transform_mode_skin_resize.c
index 0a7eea8a989..236c9024201 100644
--- a/source/blender/editors/transform/transform_mode_skin_resize.c
+++ b/source/blender/editors/transform/transform_mode_skin_resize.c
@@ -35,9 +35,11 @@
#include "transform.h"
#include "transform_constraints.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Skin) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_tilt.c b/source/blender/editors/transform/transform_mode_tilt.c
index d3b72fdf503..b48f474e16e 100644
--- a/source/blender/editors/transform/transform_mode_tilt.c
+++ b/source/blender/editors/transform/transform_mode_tilt.c
@@ -36,9 +36,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Tilt)
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_timescale.c b/source/blender/editors/transform/transform_mode_timescale.c
index 7ae97c66660..50fd714727b 100644
--- a/source/blender/editors/transform/transform_mode_timescale.c
+++ b/source/blender/editors/transform/transform_mode_timescale.c
@@ -39,6 +39,9 @@
#include "BLT_translation.h"
#include "transform.h"
+#include "transform_convert.h"
+#include "transform_snap.h"
+
#include "transform_mode.h"
/* -------------------------------------------------------------------- */
@@ -62,7 +65,6 @@ static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR])
static void applyTimeScaleValue(TransInfo *t, float value)
{
Scene *scene = t->scene;
- const short autosnap = getAnimEdit_SnapMode(t);
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data;
@@ -86,9 +88,6 @@ static void applyTimeScaleValue(TransInfo *t, float value)
/* now, calculate the new value */
*(td->val) = ((td->ival - startx) * fac) + startx;
-
- /* apply nearest snapping */
- doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
}
}
}
diff --git a/source/blender/editors/transform/transform_mode_timeslide.c b/source/blender/editors/transform/transform_mode_timeslide.c
index 34d3251f9cf..5cc53eb08ce 100644
--- a/source/blender/editors/transform/transform_mode_timeslide.c
+++ b/source/blender/editors/transform/transform_mode_timeslide.c
@@ -42,6 +42,8 @@
#include "BLT_translation.h"
#include "transform.h"
+#include "transform_convert.h"
+
#include "transform_mode.h"
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/transform/transform_mode_timetranslate.c b/source/blender/editors/transform/transform_mode_timetranslate.c
index 948242e547f..294040946bd 100644
--- a/source/blender/editors/transform/transform_mode_timetranslate.c
+++ b/source/blender/editors/transform/transform_mode_timetranslate.c
@@ -39,9 +39,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Animation Translation)
* \{ */
@@ -57,10 +59,18 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
}
else {
const short autosnap = getAnimEdit_SnapMode(t);
- float val = t->values_final[0];
+ float ival = TRANS_DATA_CONTAINER_FIRST_OK(t)->data->ival;
+ float val = ival + t->values_final[0];
- float snap_val;
- snapFrameTransform(t, autosnap, false, val, &snap_val);
+ float snap_val = val;
+ snapFrameTransform(t, autosnap, ival, val, &snap_val);
+
+ if (ELEM(autosnap, SACTSNAP_SECOND, SACTSNAP_TSTEP)) {
+ /* Convert to seconds. */
+ const Scene *scene = t->scene;
+ const double secf = FPS;
+ snap_val /= secf;
+ }
if (autosnap == SACTSNAP_FRAME) {
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.2f (%.4f)", snap_val, val);
@@ -86,24 +96,11 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
static void applyTimeTranslateValue(TransInfo *t, const float deltax)
{
- const short autosnap = getAnimEdit_SnapMode(t);
-
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ /* It doesn't matter whether we apply to t->data. */
TransData *td = tc->data;
- TransData2D *td2d = tc->data_2d;
- /* It doesn't matter whether we apply to t->data or
- * t->data2d, but t->data2d is more convenient. */
- for (int i = 0; i < tc->data_len; i++, td++, td2d++) {
- /* It is assumed that td->extra is a pointer to the AnimData,
- * whose active action is where this keyframe comes from.
- * (this is only valid when not in NLA)
- * (also: masks and gpencil don't have animadata)
- */
- AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
-
- /* apply nearest snapping */
- *(td->val) = td->ival + deltax * td->factor;
- doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
+ for (int i = 0; i < tc->data_len; i++, td++) {
+ *(td->val) = td->loc[0] = td->ival + deltax * td->factor;
}
}
}
diff --git a/source/blender/editors/transform/transform_mode_tosphere.c b/source/blender/editors/transform/transform_mode_tosphere.c
index 8587d5ae140..bfc85b2fe44 100644
--- a/source/blender/editors/transform/transform_mode_tosphere.c
+++ b/source/blender/editors/transform/transform_mode_tosphere.c
@@ -39,9 +39,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name To Sphere Utilities
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_trackball.c b/source/blender/editors/transform/transform_mode_trackball.c
index 68177c6becf..aa8b0783d0a 100644
--- a/source/blender/editors/transform/transform_mode_trackball.c
+++ b/source/blender/editors/transform/transform_mode_trackball.c
@@ -37,9 +37,11 @@
#include "BLT_translation.h"
#include "transform.h"
-#include "transform_mode.h"
+#include "transform_convert.h"
#include "transform_snap.h"
+#include "transform_mode.h"
+
/* -------------------------------------------------------------------- */
/** \name Transform (Rotation - Trackball) Element
* \{ */
diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c
index 75744f26c15..e44e346d3e4 100644
--- a/source/blender/editors/transform/transform_mode_translate.c
+++ b/source/blender/editors/transform/transform_mode_translate.c
@@ -221,22 +221,30 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
}
else {
float dvec[3];
+ copy_v3_v3(dvec, vec);
+ if (t->spacetype == SPACE_GRAPH) {
+ /* WORKAROUND:
+ * Special case where snapping is done in #recalData.
+ * Update the header based on the first element. */
+ const short autosnap = getAnimEdit_SnapMode(t);
+ float ival = TRANS_DATA_CONTAINER_FIRST_OK(t)->data->ival;
+ float val = ival + dvec[0];
+ snapFrameTransform(t, autosnap, ival, val, &dvec[0]);
+ }
+
if (t->con.mode & CON_APPLY) {
int i = 0;
zero_v3(dvec);
if (t->con.mode & CON_AXIS0) {
- dvec[i++] = vec[0];
+ dvec[i++] = dvec[0];
}
if (t->con.mode & CON_AXIS1) {
- dvec[i++] = vec[1];
+ dvec[i++] = dvec[1];
}
if (t->con.mode & CON_AXIS2) {
- dvec[i++] = vec[2];
+ dvec[i++] = dvec[2];
}
}
- else {
- copy_v3_v3(dvec, vec);
- }
if (t->flag & T_2D_EDIT) {
applyAspectRatio(t, dvec);
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 45c077b8a07..cbc2adf641f 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -709,6 +709,11 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
RNA_def_property_ui_text(prop, "Center Override", "Force using this center value (when set)");
}
+ if (flags & P_VIEW2D_EDGE_PAN) {
+ prop = RNA_def_boolean(ot->srna, "view2d_edge_pan", false, "Edge Pan", "Enable edge panning in 2D view");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+ }
+
if ((flags & P_NO_DEFAULTS) == 0) {
prop = RNA_def_boolean(ot->srna,
"release_confirm",
@@ -754,7 +759,8 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
Transform_Properties(ot,
P_ORIENT_MATRIX | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP |
- P_OPTIONS | P_GPENCIL_EDIT | P_CURSOR_EDIT | P_POST_TRANSFORM);
+ P_OPTIONS | P_GPENCIL_EDIT | P_CURSOR_EDIT | P_VIEW2D_EDGE_PAN |
+ P_POST_TRANSFORM);
}
static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 656a1e5d9c7..05a20a14477 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -594,7 +594,7 @@ static void initSnappingMode(TransInfo *t)
else if (t->spacetype == SPACE_SEQ) {
t->tsnap.mode = SEQ_tool_settings_snap_mode_get(t->scene);
}
- else {
+ else if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE) && !(t->options & CTX_CAMERA)) {
/* force project off when not supported */
if ((ts->snap_mode & SCE_SNAP_MODE_FACE) == 0) {
t->tsnap.project = 0;
@@ -608,6 +608,14 @@ static void initSnappingMode(TransInfo *t)
t->tsnap.mode |= SCE_SNAP_MODE_GRID;
}
}
+ else if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_ACTION, SPACE_NLA)) {
+ /* No incremental snapping. */
+ t->tsnap.mode = 0;
+ }
+ else {
+ /* Fallback. */
+ t->tsnap.mode = SCE_SNAP_MODE_INCREMENT;
+ }
if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE) && !(t->options & CTX_CAMERA)) {
/* Only 3D view or UV. */
@@ -654,10 +662,6 @@ static void initSnappingMode(TransInfo *t)
setSnappingCallback(t);
t->tsnap.modeSelect = SNAP_NOT_SELECTED;
}
- else {
- /* Fallback. */
- t->tsnap.mode = SCE_SNAP_MODE_INCREMENT;
- }
if (t->spacetype == SPACE_VIEW3D) {
if (t->tsnap.object_context == NULL) {
@@ -1461,47 +1465,9 @@ bool snapNodesTransform(
/** \} */
/* -------------------------------------------------------------------- */
-/** \name snap Frames
+/** \name snap Grid
* \{ */
-/* This function is used by Animation Editor specific transform functions to do
- * the Snap Keyframe to Nearest Frame/Marker
- */
-void snapFrameTransform(TransInfo *t,
- const eAnimEdit_AutoSnap autosnap,
- const bool is_frame_value,
- const float delta,
- float *r_val)
-{
- double val = delta;
- switch (autosnap) {
- case SACTSNAP_STEP:
- case SACTSNAP_FRAME:
- val = floor(val + 0.5);
- break;
- case SACTSNAP_MARKER:
- /* snap to nearest marker */
- /* TODO: need some more careful checks for where data comes from. */
- val = ED_markers_find_nearest_marker_time(&t->scene->markers, (float)val);
- break;
- case SACTSNAP_SECOND:
- case SACTSNAP_TSTEP: {
- /* second step */
- const Scene *scene = t->scene;
- const double secf = FPS;
- val = floor((val / secf) + 0.5);
- if (is_frame_value) {
- val *= secf;
- }
- break;
- }
- case SACTSNAP_OFF: {
- break;
- }
- }
- *r_val = (float)val;
-}
-
static void snap_grid_apply(
TransInfo *t, const int max_index, const float grid_dist, const float loc[3], float r_out[3])
{
diff --git a/source/blender/editors/transform/transform_snap.h b/source/blender/editors/transform/transform_snap.h
index 6dfaeab93e6..ed7f93304bc 100644
--- a/source/blender/editors/transform/transform_snap.h
+++ b/source/blender/editors/transform/transform_snap.h
@@ -45,12 +45,6 @@ bool snapNodesTransform(struct TransInfo *t,
float r_loc[2],
float *r_dist_px,
char *r_node_border);
-void snapFrameTransform(struct TransInfo *t,
- const eAnimEdit_AutoSnap autosnap,
- const bool is_frame_value,
- const float delta,
- /* return args */
- float *r_val);
bool transformModeUseSnap(const TransInfo *t);
@@ -86,3 +80,15 @@ struct TransSeqSnapData *transform_snap_sequencer_data_alloc(const TransInfo *t)
void transform_snap_sequencer_data_free(struct TransSeqSnapData *data);
bool transform_snap_sequencer_calc(struct TransInfo *t);
void transform_snap_sequencer_apply_translate(TransInfo *t, float *vec);
+
+/* transform_snap_animation.c */
+short getAnimEdit_SnapMode(TransInfo *t);
+void snapFrameTransform(TransInfo *t,
+ const eAnimEdit_AutoSnap autosnap,
+ const float val_initial,
+ const float val_final,
+ float *r_val_final);
+void transform_snap_anim_flush_data(TransInfo *t,
+ TransData *td,
+ const eAnimEdit_AutoSnap autosnap,
+ float *r_val_final);
diff --git a/source/blender/editors/transform/transform_snap_animation.c b/source/blender/editors/transform/transform_snap_animation.c
new file mode 100644
index 00000000000..08335924ddf
--- /dev/null
+++ b/source/blender/editors/transform/transform_snap_animation.c
@@ -0,0 +1,159 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup edtransform
+ */
+
+#include "DNA_anim_types.h"
+
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+#include "BKE_nla.h"
+
+#include "ED_markers.h"
+#include "ED_screen.h"
+
+#include "transform.h"
+#include "transform_snap.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Snapping in Anim Editors
+ * \{ */
+
+/**
+ * This function returns the snapping 'mode' for Animation Editors only.
+ * We cannot use the standard snapping due to NLA-strip scaling complexities.
+ *
+ * TODO: these modifier checks should be accessible from the key-map.
+ */
+short getAnimEdit_SnapMode(TransInfo *t)
+{
+ short autosnap = SACTSNAP_OFF;
+
+ if (t->spacetype == SPACE_ACTION) {
+ SpaceAction *saction = (SpaceAction *)t->area->spacedata.first;
+
+ if (saction) {
+ autosnap = saction->autosnap;
+ }
+ }
+ else if (t->spacetype == SPACE_GRAPH) {
+ SpaceGraph *sipo = (SpaceGraph *)t->area->spacedata.first;
+
+ if (sipo) {
+ autosnap = sipo->autosnap;
+ }
+ }
+ else if (t->spacetype == SPACE_NLA) {
+ SpaceNla *snla = (SpaceNla *)t->area->spacedata.first;
+
+ if (snla) {
+ autosnap = snla->autosnap;
+ }
+ }
+ else {
+ autosnap = SACTSNAP_OFF;
+ }
+
+ /* toggle autosnap on/off
+ * - when toggling on, prefer nearest frame over 1.0 frame increments
+ */
+ if (t->modifiers & MOD_SNAP_INVERT) {
+ if (autosnap) {
+ autosnap = SACTSNAP_OFF;
+ }
+ else {
+ autosnap = SACTSNAP_FRAME;
+ }
+ }
+
+ return autosnap;
+}
+
+void snapFrameTransform(TransInfo *t,
+ const eAnimEdit_AutoSnap autosnap,
+ const float val_initial,
+ const float val_final,
+ float *r_val_final)
+{
+ float deltax = val_final - val_initial;
+ switch (autosnap) {
+ case SACTSNAP_FRAME:
+ *r_val_final = floorf(val_final + 0.5f);
+ break;
+ case SACTSNAP_MARKER:
+ /* Snap to nearest marker. */
+ /* TODO: need some more careful checks for where data comes from. */
+ *r_val_final = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, val_final);
+ break;
+ case SACTSNAP_SECOND:
+ case SACTSNAP_TSTEP: {
+ const Scene *scene = t->scene;
+ const double secf = FPS;
+ if (autosnap == SACTSNAP_SECOND) {
+ *r_val_final = floorf((val_final / secf) + 0.5) * secf;
+ }
+ else {
+ deltax = (float)(floor((deltax / secf) + 0.5) * secf);
+ *r_val_final = val_initial + deltax;
+ }
+ break;
+ }
+ case SACTSNAP_STEP:
+ deltax = floorf(deltax + 0.5f);
+ *r_val_final = val_initial + deltax;
+ break;
+ case SACTSNAP_OFF:
+ break;
+ }
+}
+
+/* This function is used by Animation Editor specific transform functions to do
+ * the Snap Keyframe to Nearest Frame/Marker
+ */
+void transform_snap_anim_flush_data(TransInfo *t,
+ TransData *td,
+ const eAnimEdit_AutoSnap autosnap,
+ float *r_val_final)
+{
+ BLI_assert(autosnap != SACTSNAP_OFF);
+
+ float val = td->loc[0];
+ float ival = td->iloc[0];
+ AnimData *adt = (!ELEM(t->spacetype, SPACE_NLA, SPACE_SEQ)) ? td->extra : NULL;
+
+ /* Convert frame to nla-action time (if needed) */
+ if (adt) {
+ val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP);
+ ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP);
+ }
+
+ snapFrameTransform(t, autosnap, ival, val, &val);
+
+ /* Convert frame out of nla-action time. */
+ if (adt) {
+ val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
+ }
+
+ *r_val_final = val;
+}
+
+/** \} */
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt
index 54ec6b22e70..b396e348845 100644
--- a/source/blender/editors/util/CMakeLists.txt
+++ b/source/blender/editors/util/CMakeLists.txt
@@ -64,6 +64,7 @@ set(SRC
../include/ED_info.h
../include/ED_keyframes_draw.h
../include/ED_keyframes_edit.h
+ ../include/ED_keyframes_keylist.h
../include/ED_keyframing.h
../include/ED_lattice.h
../include/ED_markers.h
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index 823837e2a42..d0eed6a6eb1 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -178,7 +178,7 @@ void outputNumInput(NumInput *n, char *str, UnitSettings *unit_settings)
}
/* We might have cut some multi-bytes utf8 chars
* (e.g. trailing '°' of degrees values can become only 'A')... */
- BLI_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln]));
+ BLI_str_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln]));
}
}
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 809294ad274..f8d2acc74a8 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -33,9 +33,6 @@ set(SRC
intern/generic_virtual_vector_array.cc
intern/multi_function.cc
intern/multi_function_builder.cc
- intern/multi_function_network.cc
- intern/multi_function_network_evaluation.cc
- intern/multi_function_network_optimization.cc
FN_cpp_type.hh
FN_cpp_type_make.hh
@@ -49,9 +46,6 @@ set(SRC
FN_multi_function_builder.hh
FN_multi_function_context.hh
FN_multi_function_data_type.hh
- FN_multi_function_network.hh
- FN_multi_function_network_evaluation.hh
- FN_multi_function_network_optimization.hh
FN_multi_function_param_type.hh
FN_multi_function_params.hh
FN_multi_function_signature.hh
@@ -68,7 +62,6 @@ if(WITH_GTESTS)
tests/FN_cpp_type_test.cc
tests/FN_generic_span_test.cc
tests/FN_generic_vector_array_test.cc
- tests/FN_multi_function_network_test.cc
tests/FN_multi_function_test.cc
)
set(TEST_LIB
diff --git a/source/blender/functions/FN_generic_vector_array.hh b/source/blender/functions/FN_generic_vector_array.hh
index eeba0c9dba2..179e85671f8 100644
--- a/source/blender/functions/FN_generic_vector_array.hh
+++ b/source/blender/functions/FN_generic_vector_array.hh
@@ -82,6 +82,8 @@ class GVectorArray : NonCopyable, NonMovable {
void extend(IndexMask mask, const GVVectorArray &values);
void extend(IndexMask mask, const GVectorArray &values);
+ void clear(IndexMask mask);
+
GMutableSpan operator[](int64_t index);
GSpan operator[](int64_t index) const;
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index c9398ceb547..f429243e2de 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -129,7 +129,7 @@ class GVArray {
}
/* Same as `get_internal_single`, but `r_value` points to initialized memory. */
- void get_single_to_uninitialized(void *r_value) const
+ void get_internal_single_to_uninitialized(void *r_value) const
{
type_->default_construct(r_value);
this->get_internal_single(r_value);
diff --git a/source/blender/functions/FN_multi_function_network.hh b/source/blender/functions/FN_multi_function_network.hh
deleted file mode 100644
index b303589106a..00000000000
--- a/source/blender/functions/FN_multi_function_network.hh
+++ /dev/null
@@ -1,536 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-/** \file
- * \ingroup fn
- *
- * A multi-function network (`MFNetwork`) allows you to connect multiple multi-functions. The
- * `MFNetworkEvaluator` is a multi-function that wraps an entire network into a new multi-function
- * (which can be used in another network and so on).
- *
- * A MFNetwork is a graph data structure with two kinds of nodes:
- * - MFFunctionNode: Represents a multi-function. Its input and output sockets correspond to
- * parameters of the referenced multi-function.
- * - MFDummyNode: Does not reference a multi-function. Instead it just has sockets that can be
- * used to represent node group inputs and outputs.
- *
- * Links represent data flow. Unlinked input sockets have no value. In order to execute a function
- * node, all its inputs have to be connected to something.
- *
- * Links are only allowed between sockets with the exact same MFDataType. There are no implicit
- * conversions.
- *
- * Every input and output parameter of a multi-function corresponds to exactly one input or output
- * socket respectively. A multiple parameter belongs to exactly one input AND one output socket.
- *
- * There is an .to_dot() method that generates a graph in dot format for debugging purposes.
- */
-
-#include "FN_multi_function.hh"
-
-#include "BLI_vector_set.hh"
-
-namespace blender::fn {
-
-class MFNode;
-class MFFunctionNode;
-class MFDummyNode;
-class MFSocket;
-class MFInputSocket;
-class MFOutputSocket;
-class MFNetwork;
-
-class MFNode : NonCopyable, NonMovable {
- protected:
- MFNetwork *network_;
- Span<MFInputSocket *> inputs_;
- Span<MFOutputSocket *> outputs_;
- bool is_dummy_;
- int id_;
-
- friend MFNetwork;
-
- public:
- StringRefNull name() const;
-
- int id() const;
-
- MFNetwork &network();
- const MFNetwork &network() const;
-
- bool is_dummy() const;
- bool is_function() const;
-
- MFDummyNode &as_dummy();
- const MFDummyNode &as_dummy() const;
-
- MFFunctionNode &as_function();
- const MFFunctionNode &as_function() const;
-
- MFInputSocket &input(int index);
- const MFInputSocket &input(int index) const;
-
- MFOutputSocket &output(int index);
- const MFOutputSocket &output(int index) const;
-
- Span<MFInputSocket *> inputs();
- Span<const MFInputSocket *> inputs() const;
-
- Span<MFOutputSocket *> outputs();
- Span<const MFOutputSocket *> outputs() const;
-
- bool has_unlinked_inputs() const;
-
- private:
- void destruct_sockets();
-};
-
-class MFFunctionNode : public MFNode {
- private:
- const MultiFunction *function_;
- Span<int> input_param_indices_;
- Span<int> output_param_indices_;
-
- friend MFNetwork;
-
- public:
- StringRefNull name() const;
-
- const MultiFunction &function() const;
-
- const MFInputSocket &input_for_param(int param_index) const;
- const MFOutputSocket &output_for_param(int param_index) const;
-};
-
-class MFDummyNode : public MFNode {
- protected:
- StringRefNull name_;
- MutableSpan<StringRefNull> input_names_;
- MutableSpan<StringRefNull> output_names_;
-
- friend MFNetwork;
-
- public:
- StringRefNull name() const;
-
- Span<StringRefNull> input_names() const;
- Span<StringRefNull> output_names() const;
-};
-
-class MFSocket : NonCopyable, NonMovable {
- protected:
- MFNode *node_;
- bool is_output_;
- int index_;
- MFDataType data_type_;
- int id_;
- StringRefNull name_;
-
- friend MFNetwork;
-
- public:
- StringRefNull name() const;
-
- int id() const;
- int index() const;
-
- const MFDataType &data_type() const;
-
- MFNode &node();
- const MFNode &node() const;
-
- bool is_input() const;
- bool is_output() const;
-
- MFInputSocket &as_input();
- const MFInputSocket &as_input() const;
-
- MFOutputSocket &as_output();
- const MFOutputSocket &as_output() const;
-};
-
-class MFInputSocket : public MFSocket {
- private:
- MFOutputSocket *origin_;
-
- friend MFNetwork;
-
- public:
- MFOutputSocket *origin();
- const MFOutputSocket *origin() const;
-};
-
-class MFOutputSocket : public MFSocket {
- private:
- Vector<MFInputSocket *, 1> targets_;
-
- friend MFNetwork;
-
- public:
- Span<MFInputSocket *> targets();
- Span<const MFInputSocket *> targets() const;
-};
-
-class MFNetwork : NonCopyable, NonMovable {
- private:
- LinearAllocator<> allocator_;
-
- VectorSet<MFFunctionNode *> function_nodes_;
- VectorSet<MFDummyNode *> dummy_nodes_;
-
- Vector<MFNode *> node_or_null_by_id_;
- Vector<MFSocket *> socket_or_null_by_id_;
-
- public:
- MFNetwork() = default;
- ~MFNetwork();
-
- MFFunctionNode &add_function(const MultiFunction &function);
- MFDummyNode &add_dummy(StringRef name,
- Span<MFDataType> input_types,
- Span<MFDataType> output_types,
- Span<StringRef> input_names,
- Span<StringRef> output_names);
- void add_link(MFOutputSocket &from, MFInputSocket &to);
-
- MFOutputSocket &add_input(StringRef name, MFDataType data_type);
- MFInputSocket &add_output(StringRef name, MFDataType data_type);
-
- void relink(MFOutputSocket &old_output, MFOutputSocket &new_output);
-
- void remove(MFNode &node);
- void remove(Span<MFNode *> nodes);
-
- int socket_id_amount() const;
- int node_id_amount() const;
-
- Span<MFDummyNode *> dummy_nodes();
- Span<MFFunctionNode *> function_nodes();
-
- MFNode *node_or_null_by_id(int id);
- const MFNode *node_or_null_by_id(int id) const;
-
- MFSocket *socket_or_null_by_id(int id);
- const MFSocket *socket_or_null_by_id(int id) const;
-
- void find_dependencies(Span<const MFInputSocket *> sockets,
- VectorSet<const MFOutputSocket *> &r_dummy_sockets,
- VectorSet<const MFInputSocket *> &r_unlinked_inputs) const;
-
- bool have_dummy_or_unlinked_dependencies(Span<const MFInputSocket *> sockets) const;
-
- std::string to_dot(Span<const MFNode *> marked_nodes = {}) const;
-};
-
-/* --------------------------------------------------------------------
- * MFNode inline methods.
- */
-
-inline StringRefNull MFNode::name() const
-{
- if (is_dummy_) {
- return this->as_dummy().name();
- }
- else {
- return this->as_function().name();
- }
-}
-
-inline int MFNode::id() const
-{
- return id_;
-}
-
-inline MFNetwork &MFNode::network()
-{
- return *network_;
-}
-
-inline const MFNetwork &MFNode::network() const
-{
- return *network_;
-}
-
-inline bool MFNode::is_dummy() const
-{
- return is_dummy_;
-}
-
-inline bool MFNode::is_function() const
-{
- return !is_dummy_;
-}
-
-inline MFDummyNode &MFNode::as_dummy()
-{
- BLI_assert(is_dummy_);
- return static_cast<MFDummyNode &>(*this);
-}
-
-inline const MFDummyNode &MFNode::as_dummy() const
-{
- BLI_assert(is_dummy_);
- return static_cast<const MFDummyNode &>(*this);
-}
-
-inline MFFunctionNode &MFNode::as_function()
-{
- BLI_assert(!is_dummy_);
- return static_cast<MFFunctionNode &>(*this);
-}
-
-inline const MFFunctionNode &MFNode::as_function() const
-{
- BLI_assert(!is_dummy_);
- return static_cast<const MFFunctionNode &>(*this);
-}
-
-inline MFInputSocket &MFNode::input(int index)
-{
- return *inputs_[index];
-}
-
-inline const MFInputSocket &MFNode::input(int index) const
-{
- return *inputs_[index];
-}
-
-inline MFOutputSocket &MFNode::output(int index)
-{
- return *outputs_[index];
-}
-
-inline const MFOutputSocket &MFNode::output(int index) const
-{
- return *outputs_[index];
-}
-
-inline Span<MFInputSocket *> MFNode::inputs()
-{
- return inputs_;
-}
-
-inline Span<const MFInputSocket *> MFNode::inputs() const
-{
- return inputs_;
-}
-
-inline Span<MFOutputSocket *> MFNode::outputs()
-{
- return outputs_;
-}
-
-inline Span<const MFOutputSocket *> MFNode::outputs() const
-{
- return outputs_;
-}
-
-inline bool MFNode::has_unlinked_inputs() const
-{
- for (const MFInputSocket *socket : inputs_) {
- if (socket->origin() == nullptr) {
- return true;
- }
- }
- return false;
-}
-
-/* --------------------------------------------------------------------
- * MFFunctionNode inline methods.
- */
-
-inline StringRefNull MFFunctionNode::name() const
-{
- return function_->name();
-}
-
-inline const MultiFunction &MFFunctionNode::function() const
-{
- return *function_;
-}
-
-inline const MFInputSocket &MFFunctionNode::input_for_param(int param_index) const
-{
- return this->input(input_param_indices_.first_index(param_index));
-}
-
-inline const MFOutputSocket &MFFunctionNode::output_for_param(int param_index) const
-{
- return this->output(output_param_indices_.first_index(param_index));
-}
-
-/* --------------------------------------------------------------------
- * MFDummyNode inline methods.
- */
-
-inline StringRefNull MFDummyNode::name() const
-{
- return name_;
-}
-
-inline Span<StringRefNull> MFDummyNode::input_names() const
-{
- return input_names_;
-}
-
-inline Span<StringRefNull> MFDummyNode::output_names() const
-{
- return output_names_;
-}
-
-/* --------------------------------------------------------------------
- * MFSocket inline methods.
- */
-
-inline StringRefNull MFSocket::name() const
-{
- return name_;
-}
-
-inline int MFSocket::id() const
-{
- return id_;
-}
-
-inline int MFSocket::index() const
-{
- return index_;
-}
-
-inline const MFDataType &MFSocket::data_type() const
-{
- return data_type_;
-}
-
-inline MFNode &MFSocket::node()
-{
- return *node_;
-}
-
-inline const MFNode &MFSocket::node() const
-{
- return *node_;
-}
-
-inline bool MFSocket::is_input() const
-{
- return !is_output_;
-}
-
-inline bool MFSocket::is_output() const
-{
- return is_output_;
-}
-
-inline MFInputSocket &MFSocket::as_input()
-{
- BLI_assert(this->is_input());
- return static_cast<MFInputSocket &>(*this);
-}
-
-inline const MFInputSocket &MFSocket::as_input() const
-{
- BLI_assert(this->is_input());
- return static_cast<const MFInputSocket &>(*this);
-}
-
-inline MFOutputSocket &MFSocket::as_output()
-{
- BLI_assert(this->is_output());
- return static_cast<MFOutputSocket &>(*this);
-}
-
-inline const MFOutputSocket &MFSocket::as_output() const
-{
- BLI_assert(this->is_output());
- return static_cast<const MFOutputSocket &>(*this);
-}
-
-/* --------------------------------------------------------------------
- * MFInputSocket inline methods.
- */
-
-inline MFOutputSocket *MFInputSocket::origin()
-{
- return origin_;
-}
-
-inline const MFOutputSocket *MFInputSocket::origin() const
-{
- return origin_;
-}
-
-/* --------------------------------------------------------------------
- * MFOutputSocket inline methods.
- */
-
-inline Span<MFInputSocket *> MFOutputSocket::targets()
-{
- return targets_;
-}
-
-inline Span<const MFInputSocket *> MFOutputSocket::targets() const
-{
- return targets_;
-}
-
-/* --------------------------------------------------------------------
- * MFNetwork inline methods.
- */
-
-inline Span<MFDummyNode *> MFNetwork::dummy_nodes()
-{
- return dummy_nodes_;
-}
-
-inline Span<MFFunctionNode *> MFNetwork::function_nodes()
-{
- return function_nodes_;
-}
-
-inline MFNode *MFNetwork::node_or_null_by_id(int id)
-{
- return node_or_null_by_id_[id];
-}
-
-inline const MFNode *MFNetwork::node_or_null_by_id(int id) const
-{
- return node_or_null_by_id_[id];
-}
-
-inline MFSocket *MFNetwork::socket_or_null_by_id(int id)
-{
- return socket_or_null_by_id_[id];
-}
-
-inline const MFSocket *MFNetwork::socket_or_null_by_id(int id) const
-{
- return socket_or_null_by_id_[id];
-}
-
-inline int MFNetwork::socket_id_amount() const
-{
- return socket_or_null_by_id_.size();
-}
-
-inline int MFNetwork::node_id_amount() const
-{
- return node_or_null_by_id_.size();
-}
-
-} // namespace blender::fn
diff --git a/source/blender/functions/FN_multi_function_network_evaluation.hh b/source/blender/functions/FN_multi_function_network_evaluation.hh
deleted file mode 100644
index 17cffa406f7..00000000000
--- a/source/blender/functions/FN_multi_function_network_evaluation.hh
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-/** \file
- * \ingroup fn
- */
-
-#include "FN_multi_function_network.hh"
-
-namespace blender::fn {
-
-class MFNetworkEvaluationStorage;
-
-class MFNetworkEvaluator : public MultiFunction {
- private:
- MFSignature signature_;
- Vector<const MFOutputSocket *> inputs_;
- Vector<const MFInputSocket *> outputs_;
-
- public:
- MFNetworkEvaluator(Vector<const MFOutputSocket *> inputs, Vector<const MFInputSocket *> outputs);
-
- void call(IndexMask mask, MFParams params, MFContext context) const override;
-
- private:
- using Storage = MFNetworkEvaluationStorage;
-
- void copy_inputs_to_storage(MFParams params, Storage &storage) const;
- void copy_outputs_to_storage(
- MFParams params,
- Storage &storage,
- Vector<const MFInputSocket *> &outputs_to_initialize_in_the_end) const;
-
- void evaluate_network_to_compute_outputs(MFContext &global_context, Storage &storage) const;
-
- void evaluate_function(MFContext &global_context,
- const MFFunctionNode &function_node,
- Storage &storage) const;
-
- bool can_do_single_value_evaluation(const MFFunctionNode &function_node, Storage &storage) const;
-
- void initialize_remaining_outputs(MFParams params,
- Storage &storage,
- Span<const MFInputSocket *> remaining_outputs) const;
-};
-
-} // namespace blender::fn
diff --git a/source/blender/functions/FN_multi_function_network_optimization.hh b/source/blender/functions/FN_multi_function_network_optimization.hh
deleted file mode 100644
index 96664fa368e..00000000000
--- a/source/blender/functions/FN_multi_function_network_optimization.hh
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-#include "FN_multi_function_network.hh"
-
-#include "BLI_resource_scope.hh"
-
-namespace blender::fn::mf_network_optimization {
-
-void dead_node_removal(MFNetwork &network);
-void constant_folding(MFNetwork &network, ResourceScope &scope);
-void common_subnetwork_elimination(MFNetwork &network);
-
-} // namespace blender::fn::mf_network_optimization
diff --git a/source/blender/functions/FN_multi_function_params.hh b/source/blender/functions/FN_multi_function_params.hh
index e292d11def7..a480287d578 100644
--- a/source/blender/functions/FN_multi_function_params.hh
+++ b/source/blender/functions/FN_multi_function_params.hh
@@ -54,6 +54,11 @@ class MFParamsBuilder {
MFParamsBuilder(const class MultiFunction &fn, int64_t min_array_size);
+ template<typename T> void add_readonly_single_input_value(T value, StringRef expected_name = "")
+ {
+ T *value_ptr = &scope_.add_value<T>(std::move(value), __func__);
+ this->add_readonly_single_input(value_ptr, expected_name);
+ }
template<typename T> void add_readonly_single_input(const T *value, StringRef expected_name = "")
{
this->add_readonly_single_input(scope_.construct<GVArray_For_SingleValueRef>(
@@ -83,6 +88,12 @@ class MFParamsBuilder {
this->add_readonly_vector_input(
scope_.construct<GVVectorArray_For_GVectorArray>(__func__, vector_array), expected_name);
}
+ void add_readonly_vector_input(const GSpan single_vector, StringRef expected_name = "")
+ {
+ this->add_readonly_vector_input(
+ scope_.construct<GVVectorArray_For_SingleGSpan>(__func__, single_vector, min_array_size_),
+ expected_name);
+ }
void add_readonly_vector_input(const GVVectorArray &ref, StringRef expected_name = "")
{
this->assert_current_param_type(MFParamType::ForVectorInput(ref.type()), expected_name);
diff --git a/source/blender/functions/FN_multi_function_signature.hh b/source/blender/functions/FN_multi_function_signature.hh
index 23309c9a5e6..d05948cc645 100644
--- a/source/blender/functions/FN_multi_function_signature.hh
+++ b/source/blender/functions/FN_multi_function_signature.hh
@@ -160,6 +160,21 @@ class MFSignatureBuilder {
}
}
+ void add(StringRef name, const MFParamType &param_type)
+ {
+ switch (param_type.interface_type()) {
+ case MFParamType::Input:
+ this->input(name, param_type.data_type());
+ break;
+ case MFParamType::Mutable:
+ this->mutable_(name, param_type.data_type());
+ break;
+ case MFParamType::Output:
+ this->output(name, param_type.data_type());
+ break;
+ }
+ }
+
/* Context */
/** This indicates that the function accesses the context. This disables optimizations that
diff --git a/source/blender/functions/intern/generic_vector_array.cc b/source/blender/functions/intern/generic_vector_array.cc
index 9556d24218e..ec95a283919 100644
--- a/source/blender/functions/intern/generic_vector_array.cc
+++ b/source/blender/functions/intern/generic_vector_array.cc
@@ -78,6 +78,15 @@ void GVectorArray::extend(IndexMask mask, const GVectorArray &values)
this->extend(mask, virtual_values);
}
+void GVectorArray::clear(IndexMask mask)
+{
+ for (const int64_t i : mask) {
+ Item &item = items_[i];
+ type_.destruct_n(item.start, item.length);
+ item.length = 0;
+ }
+}
+
GMutableSpan GVectorArray::operator[](const int64_t index)
{
Item &item = items_[index];
diff --git a/source/blender/functions/intern/multi_function_network.cc b/source/blender/functions/intern/multi_function_network.cc
deleted file mode 100644
index b5c2c09a35a..00000000000
--- a/source/blender/functions/intern/multi_function_network.cc
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "BLI_dot_export.hh"
-#include "BLI_stack.hh"
-
-#include "FN_multi_function_network.hh"
-
-namespace blender::fn {
-
-MFNetwork::~MFNetwork()
-{
- for (MFFunctionNode *node : function_nodes_) {
- node->destruct_sockets();
- node->~MFFunctionNode();
- }
- for (MFDummyNode *node : dummy_nodes_) {
- node->destruct_sockets();
- node->~MFDummyNode();
- }
-}
-
-void MFNode::destruct_sockets()
-{
- for (MFInputSocket *socket : inputs_) {
- socket->~MFInputSocket();
- }
- for (MFOutputSocket *socket : outputs_) {
- socket->~MFOutputSocket();
- }
-}
-
-/**
- * Add a new function node to the network. The caller keeps the ownership of the function. The
- * function should not be freed before the network. A reference to the new node is returned. The
- * node is owned by the network.
- */
-MFFunctionNode &MFNetwork::add_function(const MultiFunction &function)
-{
- Vector<int, 16> input_param_indices, output_param_indices;
-
- for (int param_index : function.param_indices()) {
- switch (function.param_type(param_index).interface_type()) {
- case MFParamType::Input: {
- input_param_indices.append(param_index);
- break;
- }
- case MFParamType::Output: {
- output_param_indices.append(param_index);
- break;
- }
- case MFParamType::Mutable: {
- input_param_indices.append(param_index);
- output_param_indices.append(param_index);
- break;
- }
- }
- }
-
- MFFunctionNode &node = *allocator_.construct<MFFunctionNode>().release();
- function_nodes_.add_new(&node);
-
- node.network_ = this;
- node.is_dummy_ = false;
- node.id_ = node_or_null_by_id_.append_and_get_index(&node);
- node.function_ = &function;
- node.input_param_indices_ = allocator_.construct_array_copy<int>(input_param_indices);
- node.output_param_indices_ = allocator_.construct_array_copy<int>(output_param_indices);
-
- node.inputs_ = allocator_.construct_elements_and_pointer_array<MFInputSocket>(
- input_param_indices.size());
- node.outputs_ = allocator_.construct_elements_and_pointer_array<MFOutputSocket>(
- output_param_indices.size());
-
- for (int i : input_param_indices.index_range()) {
- int param_index = input_param_indices[i];
- MFParamType param = function.param_type(param_index);
- BLI_assert(param.is_input_or_mutable());
-
- MFInputSocket &socket = *node.inputs_[i];
- socket.data_type_ = param.data_type();
- socket.node_ = &node;
- socket.index_ = i;
- socket.is_output_ = false;
- socket.name_ = function.param_name(param_index);
- socket.origin_ = nullptr;
- socket.id_ = socket_or_null_by_id_.append_and_get_index(&socket);
- }
-
- for (int i : output_param_indices.index_range()) {
- int param_index = output_param_indices[i];
- MFParamType param = function.param_type(param_index);
- BLI_assert(param.is_output_or_mutable());
-
- MFOutputSocket &socket = *node.outputs_[i];
- socket.data_type_ = param.data_type();
- socket.node_ = &node;
- socket.index_ = i;
- socket.is_output_ = true;
- socket.name_ = function.param_name(param_index);
- socket.id_ = socket_or_null_by_id_.append_and_get_index(&socket);
- }
-
- return node;
-}
-
-/**
- * Add a dummy node with the given input and output sockets.
- */
-MFDummyNode &MFNetwork::add_dummy(StringRef name,
- Span<MFDataType> input_types,
- Span<MFDataType> output_types,
- Span<StringRef> input_names,
- Span<StringRef> output_names)
-{
- assert_same_size(input_types, input_names);
- assert_same_size(output_types, output_names);
-
- MFDummyNode &node = *allocator_.construct<MFDummyNode>().release();
- dummy_nodes_.add_new(&node);
-
- node.network_ = this;
- node.is_dummy_ = true;
- node.name_ = allocator_.copy_string(name);
- node.id_ = node_or_null_by_id_.append_and_get_index(&node);
-
- node.inputs_ = allocator_.construct_elements_and_pointer_array<MFInputSocket>(
- input_types.size());
- node.outputs_ = allocator_.construct_elements_and_pointer_array<MFOutputSocket>(
- output_types.size());
-
- node.input_names_ = allocator_.allocate_array<StringRefNull>(input_types.size());
- node.output_names_ = allocator_.allocate_array<StringRefNull>(output_types.size());
-
- for (int i : input_types.index_range()) {
- MFInputSocket &socket = *node.inputs_[i];
- socket.data_type_ = input_types[i];
- socket.node_ = &node;
- socket.index_ = i;
- socket.is_output_ = false;
- socket.name_ = allocator_.copy_string(input_names[i]);
- socket.id_ = socket_or_null_by_id_.append_and_get_index(&socket);
- node.input_names_[i] = socket.name_;
- }
-
- for (int i : output_types.index_range()) {
- MFOutputSocket &socket = *node.outputs_[i];
- socket.data_type_ = output_types[i];
- socket.node_ = &node;
- socket.index_ = i;
- socket.is_output_ = true;
- socket.name_ = allocator_.copy_string(output_names[i]);
- socket.id_ = socket_or_null_by_id_.append_and_get_index(&socket);
- node.output_names_[i] = socket.name_;
- }
-
- return node;
-}
-
-/**
- * Connect two sockets. This invokes undefined behavior if the sockets belong to different
- * networks, the sockets have a different data type, or the `to` socket is connected to something
- * else already.
- */
-void MFNetwork::add_link(MFOutputSocket &from, MFInputSocket &to)
-{
- BLI_assert(to.origin_ == nullptr);
- BLI_assert(from.node_->network_ == to.node_->network_);
- BLI_assert(from.data_type_ == to.data_type_);
- from.targets_.append(&to);
- to.origin_ = &from;
-}
-
-MFOutputSocket &MFNetwork::add_input(StringRef name, MFDataType data_type)
-{
- return this->add_dummy(name, {}, {data_type}, {}, {"Value"}).output(0);
-}
-
-MFInputSocket &MFNetwork::add_output(StringRef name, MFDataType data_type)
-{
- return this->add_dummy(name, {data_type}, {}, {"Value"}, {}).input(0);
-}
-
-void MFNetwork::relink(MFOutputSocket &old_output, MFOutputSocket &new_output)
-{
- BLI_assert(&old_output != &new_output);
- BLI_assert(old_output.data_type_ == new_output.data_type_);
- for (MFInputSocket *input : old_output.targets()) {
- input->origin_ = &new_output;
- }
- new_output.targets_.extend(old_output.targets_);
- old_output.targets_.clear();
-}
-
-void MFNetwork::remove(MFNode &node)
-{
- for (MFInputSocket *socket : node.inputs_) {
- if (socket->origin_ != nullptr) {
- socket->origin_->targets_.remove_first_occurrence_and_reorder(socket);
- }
- socket_or_null_by_id_[socket->id_] = nullptr;
- }
- for (MFOutputSocket *socket : node.outputs_) {
- for (MFInputSocket *other : socket->targets_) {
- other->origin_ = nullptr;
- }
- socket_or_null_by_id_[socket->id_] = nullptr;
- }
- node.destruct_sockets();
- if (node.is_dummy()) {
- MFDummyNode &dummy_node = node.as_dummy();
- dummy_node.~MFDummyNode();
- dummy_nodes_.remove_contained(&dummy_node);
- }
- else {
- MFFunctionNode &function_node = node.as_function();
- function_node.~MFFunctionNode();
- function_nodes_.remove_contained(&function_node);
- }
- node_or_null_by_id_[node.id_] = nullptr;
-}
-
-void MFNetwork::remove(Span<MFNode *> nodes)
-{
- for (MFNode *node : nodes) {
- this->remove(*node);
- }
-}
-
-void MFNetwork::find_dependencies(Span<const MFInputSocket *> sockets,
- VectorSet<const MFOutputSocket *> &r_dummy_sockets,
- VectorSet<const MFInputSocket *> &r_unlinked_inputs) const
-{
- Set<const MFNode *> visited_nodes;
- Stack<const MFInputSocket *> sockets_to_check;
- sockets_to_check.push_multiple(sockets);
-
- while (!sockets_to_check.is_empty()) {
- const MFInputSocket &socket = *sockets_to_check.pop();
- const MFOutputSocket *origin_socket = socket.origin();
- if (origin_socket == nullptr) {
- r_unlinked_inputs.add(&socket);
- continue;
- }
-
- const MFNode &origin_node = origin_socket->node();
-
- if (origin_node.is_dummy()) {
- r_dummy_sockets.add(origin_socket);
- continue;
- }
-
- if (visited_nodes.add(&origin_node)) {
- sockets_to_check.push_multiple(origin_node.inputs());
- }
- }
-}
-
-bool MFNetwork::have_dummy_or_unlinked_dependencies(Span<const MFInputSocket *> sockets) const
-{
- VectorSet<const MFOutputSocket *> dummy_sockets;
- VectorSet<const MFInputSocket *> unlinked_inputs;
- this->find_dependencies(sockets, dummy_sockets, unlinked_inputs);
- return dummy_sockets.size() + unlinked_inputs.size() > 0;
-}
-
-std::string MFNetwork::to_dot(Span<const MFNode *> marked_nodes) const
-{
- dot::DirectedGraph digraph;
- digraph.set_rankdir(dot::Attr_rankdir::LeftToRight);
-
- Map<const MFNode *, dot::NodeWithSocketsRef> dot_nodes;
-
- Vector<const MFNode *> all_nodes;
- all_nodes.extend(function_nodes_.as_span().cast<const MFNode *>());
- all_nodes.extend(dummy_nodes_.as_span().cast<const MFNode *>());
-
- for (const MFNode *node : all_nodes) {
- dot::Node &dot_node = digraph.new_node("");
-
- Vector<std::string> input_names, output_names;
- for (const MFInputSocket *socket : node->inputs_) {
- input_names.append(socket->name() + "(" + socket->data_type().to_string() + ")");
- }
- for (const MFOutputSocket *socket : node->outputs_) {
- output_names.append(socket->name() + " (" + socket->data_type().to_string() + ")");
- }
-
- dot::NodeWithSocketsRef dot_node_ref{dot_node, node->name(), input_names, output_names};
- dot_nodes.add_new(node, dot_node_ref);
- }
-
- for (const MFDummyNode *node : dummy_nodes_) {
- dot_nodes.lookup(node).node().set_background_color("#77EE77");
- }
- for (const MFNode *node : marked_nodes) {
- dot_nodes.lookup(node).node().set_background_color("#7777EE");
- }
-
- for (const MFNode *to_node : all_nodes) {
- dot::NodeWithSocketsRef to_dot_node = dot_nodes.lookup(to_node);
-
- for (const MFInputSocket *to_socket : to_node->inputs_) {
- const MFOutputSocket *from_socket = to_socket->origin_;
- if (from_socket != nullptr) {
- const MFNode *from_node = from_socket->node_;
- dot::NodeWithSocketsRef from_dot_node = dot_nodes.lookup(from_node);
- digraph.new_edge(from_dot_node.output(from_socket->index_),
- to_dot_node.input(to_socket->index_));
- }
- }
- }
-
- return digraph.to_dot_string();
-}
-
-} // namespace blender::fn
diff --git a/source/blender/functions/intern/multi_function_network_evaluation.cc b/source/blender/functions/intern/multi_function_network_evaluation.cc
deleted file mode 100644
index 9a0cb0c35ce..00000000000
--- a/source/blender/functions/intern/multi_function_network_evaluation.cc
+++ /dev/null
@@ -1,1083 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup fn
- *
- * The `MFNetworkEvaluator` class is a multi-function that consists of potentially many smaller
- * multi-functions. When called, it traverses the underlying MFNetwork and executes the required
- * function nodes.
- *
- * There are many possible approaches to evaluate a function network. The approach implemented
- * below has the following features:
- * - It does not use recursion. Those could become problematic with long node chains.
- * - It can handle all existing parameter types (including mutable parameters).
- * - Avoids data copies in many cases.
- * - Every node is executed at most once.
- * - Can compute sub-functions on a single element, when the result is the same for all elements.
- *
- * Possible improvements:
- * - Cache and reuse buffers.
- * - Use "deepest depth first" heuristic to decide which order the inputs of a node should be
- * computed. This reduces the number of required temporary buffers when they are reused.
- */
-
-#include "FN_multi_function_network_evaluation.hh"
-
-#include "BLI_resource_scope.hh"
-#include "BLI_stack.hh"
-
-namespace blender::fn {
-
-struct Value;
-
-/**
- * This keeps track of all the values that flow through the multi-function network. Therefore it
- * maintains a mapping between output sockets and their corresponding values. Every `value`
- * references some memory, that is owned either by the caller or this storage.
- *
- * A value can be owned by different sockets over time to avoid unnecessary copies.
- */
-class MFNetworkEvaluationStorage {
- private:
- LinearAllocator<> allocator_;
- IndexMask mask_;
- Array<Value *> value_per_output_id_;
- int64_t min_array_size_;
-
- public:
- MFNetworkEvaluationStorage(IndexMask mask, int socket_id_amount);
- ~MFNetworkEvaluationStorage();
-
- /* Add the values that have been provided by the caller of the multi-function network. */
- void add_single_input_from_caller(const MFOutputSocket &socket, const GVArray &virtual_array);
- void add_vector_input_from_caller(const MFOutputSocket &socket,
- const GVVectorArray &virtual_vector_array);
- void add_single_output_from_caller(const MFOutputSocket &socket, GMutableSpan span);
- void add_vector_output_from_caller(const MFOutputSocket &socket, GVectorArray &vector_array);
-
- /* Get input buffers for function node evaluations. */
- const GVArray &get_single_input__full(const MFInputSocket &socket, ResourceScope &scope);
- const GVArray &get_single_input__single(const MFInputSocket &socket, ResourceScope &scope);
- const GVVectorArray &get_vector_input__full(const MFInputSocket &socket, ResourceScope &scope);
- const GVVectorArray &get_vector_input__single(const MFInputSocket &socket, ResourceScope &scope);
-
- /* Get output buffers for function node evaluations. */
- GMutableSpan get_single_output__full(const MFOutputSocket &socket);
- GMutableSpan get_single_output__single(const MFOutputSocket &socket);
- GVectorArray &get_vector_output__full(const MFOutputSocket &socket);
- GVectorArray &get_vector_output__single(const MFOutputSocket &socket);
-
- /* Get mutable buffers for function node evaluations. */
- GMutableSpan get_mutable_single__full(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope);
- GMutableSpan get_mutable_single__single(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope);
- GVectorArray &get_mutable_vector__full(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope);
- GVectorArray &get_mutable_vector__single(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope);
-
- /* Mark a node as being done with evaluation. This might free temporary buffers that are no
- * longer needed. */
- void finish_node(const MFFunctionNode &node);
- void finish_output_socket(const MFOutputSocket &socket);
- void finish_input_socket(const MFInputSocket &socket);
-
- IndexMask mask() const;
- bool socket_is_computed(const MFOutputSocket &socket);
- bool is_same_value_for_every_index(const MFOutputSocket &socket);
- bool socket_has_buffer_for_output(const MFOutputSocket &socket);
-};
-
-MFNetworkEvaluator::MFNetworkEvaluator(Vector<const MFOutputSocket *> inputs,
- Vector<const MFInputSocket *> outputs)
- : inputs_(std::move(inputs)), outputs_(std::move(outputs))
-{
- BLI_assert(outputs_.size() > 0);
- MFSignatureBuilder signature{"Function Tree"};
-
- for (const MFOutputSocket *socket : inputs_) {
- BLI_assert(socket->node().is_dummy());
-
- MFDataType type = socket->data_type();
- switch (type.category()) {
- case MFDataType::Single:
- signature.single_input(socket->name(), type.single_type());
- break;
- case MFDataType::Vector:
- signature.vector_input(socket->name(), type.vector_base_type());
- break;
- }
- }
-
- for (const MFInputSocket *socket : outputs_) {
- BLI_assert(socket->node().is_dummy());
-
- MFDataType type = socket->data_type();
- switch (type.category()) {
- case MFDataType::Single:
- signature.single_output(socket->name(), type.single_type());
- break;
- case MFDataType::Vector:
- signature.vector_output(socket->name(), type.vector_base_type());
- break;
- }
- }
-
- signature_ = signature.build();
- this->set_signature(&signature_);
-}
-
-void MFNetworkEvaluator::call(IndexMask mask, MFParams params, MFContext context) const
-{
- if (mask.size() == 0) {
- return;
- }
-
- const MFNetwork &network = outputs_[0]->node().network();
- Storage storage(mask, network.socket_id_amount());
-
- Vector<const MFInputSocket *> outputs_to_initialize_in_the_end;
-
- this->copy_inputs_to_storage(params, storage);
- this->copy_outputs_to_storage(params, storage, outputs_to_initialize_in_the_end);
- this->evaluate_network_to_compute_outputs(context, storage);
- this->initialize_remaining_outputs(params, storage, outputs_to_initialize_in_the_end);
-}
-
-BLI_NOINLINE void MFNetworkEvaluator::copy_inputs_to_storage(MFParams params,
- Storage &storage) const
-{
- for (int input_index : inputs_.index_range()) {
- int param_index = input_index + 0;
- const MFOutputSocket &socket = *inputs_[input_index];
- switch (socket.data_type().category()) {
- case MFDataType::Single: {
- const GVArray &input_list = params.readonly_single_input(param_index);
- storage.add_single_input_from_caller(socket, input_list);
- break;
- }
- case MFDataType::Vector: {
- const GVVectorArray &input_list_list = params.readonly_vector_input(param_index);
- storage.add_vector_input_from_caller(socket, input_list_list);
- break;
- }
- }
- }
-}
-
-BLI_NOINLINE void MFNetworkEvaluator::copy_outputs_to_storage(
- MFParams params,
- Storage &storage,
- Vector<const MFInputSocket *> &outputs_to_initialize_in_the_end) const
-{
- for (int output_index : outputs_.index_range()) {
- int param_index = output_index + inputs_.size();
- const MFInputSocket &socket = *outputs_[output_index];
- const MFOutputSocket &origin = *socket.origin();
-
- if (origin.node().is_dummy()) {
- BLI_assert(inputs_.contains(&origin));
- /* Don't overwrite input buffers. */
- outputs_to_initialize_in_the_end.append(&socket);
- continue;
- }
-
- if (storage.socket_has_buffer_for_output(origin)) {
- /* When two outputs will be initialized to the same values. */
- outputs_to_initialize_in_the_end.append(&socket);
- continue;
- }
-
- switch (socket.data_type().category()) {
- case MFDataType::Single: {
- GMutableSpan span = params.uninitialized_single_output(param_index);
- storage.add_single_output_from_caller(origin, span);
- break;
- }
- case MFDataType::Vector: {
- GVectorArray &vector_array = params.vector_output(param_index);
- storage.add_vector_output_from_caller(origin, vector_array);
- break;
- }
- }
- }
-}
-
-BLI_NOINLINE void MFNetworkEvaluator::evaluate_network_to_compute_outputs(
- MFContext &global_context, Storage &storage) const
-{
- Stack<const MFOutputSocket *, 32> sockets_to_compute;
- for (const MFInputSocket *socket : outputs_) {
- sockets_to_compute.push(socket->origin());
- }
-
- /* This is the main loop that traverses the MFNetwork. */
- while (!sockets_to_compute.is_empty()) {
- const MFOutputSocket &socket = *sockets_to_compute.peek();
- const MFNode &node = socket.node();
-
- if (storage.socket_is_computed(socket)) {
- sockets_to_compute.pop();
- continue;
- }
-
- BLI_assert(node.is_function());
- BLI_assert(!node.has_unlinked_inputs());
- const MFFunctionNode &function_node = node.as_function();
-
- bool all_origins_are_computed = true;
- for (const MFInputSocket *input_socket : function_node.inputs()) {
- const MFOutputSocket *origin = input_socket->origin();
- if (origin != nullptr) {
- if (!storage.socket_is_computed(*origin)) {
- sockets_to_compute.push(origin);
- all_origins_are_computed = false;
- }
- }
- }
-
- if (all_origins_are_computed) {
- this->evaluate_function(global_context, function_node, storage);
- sockets_to_compute.pop();
- }
- }
-}
-
-BLI_NOINLINE void MFNetworkEvaluator::evaluate_function(MFContext &global_context,
- const MFFunctionNode &function_node,
- Storage &storage) const
-{
-
- const MultiFunction &function = function_node.function();
- // std::cout << "Function: " << function.name() << "\n";
-
- if (this->can_do_single_value_evaluation(function_node, storage)) {
- /* The function output would be the same for all elements. Therefore, it is enough to call the
- * function only on a single element. This can avoid many duplicate computations. */
- MFParamsBuilder params{function, 1};
- ResourceScope &scope = params.resource_scope();
-
- for (int param_index : function.param_indices()) {
- MFParamType param_type = function.param_type(param_index);
- switch (param_type.category()) {
- case MFParamType::SingleInput: {
- const MFInputSocket &socket = function_node.input_for_param(param_index);
- const GVArray &values = storage.get_single_input__single(socket, scope);
- params.add_readonly_single_input(values);
- break;
- }
- case MFParamType::VectorInput: {
- const MFInputSocket &socket = function_node.input_for_param(param_index);
- const GVVectorArray &values = storage.get_vector_input__single(socket, scope);
- params.add_readonly_vector_input(values);
- break;
- }
- case MFParamType::SingleOutput: {
- const MFOutputSocket &socket = function_node.output_for_param(param_index);
- GMutableSpan values = storage.get_single_output__single(socket);
- params.add_uninitialized_single_output(values);
- break;
- }
- case MFParamType::VectorOutput: {
- const MFOutputSocket &socket = function_node.output_for_param(param_index);
- GVectorArray &values = storage.get_vector_output__single(socket);
- params.add_vector_output(values);
- break;
- }
- case MFParamType::SingleMutable: {
- const MFInputSocket &input = function_node.input_for_param(param_index);
- const MFOutputSocket &output = function_node.output_for_param(param_index);
- GMutableSpan values = storage.get_mutable_single__single(input, output, scope);
- params.add_single_mutable(values);
- break;
- }
- case MFParamType::VectorMutable: {
- const MFInputSocket &input = function_node.input_for_param(param_index);
- const MFOutputSocket &output = function_node.output_for_param(param_index);
- GVectorArray &values = storage.get_mutable_vector__single(input, output, scope);
- params.add_vector_mutable(values);
- break;
- }
- }
- }
-
- function.call(IndexRange(1), params, global_context);
- }
- else {
- MFParamsBuilder params{function, storage.mask().min_array_size()};
- ResourceScope &scope = params.resource_scope();
-
- for (int param_index : function.param_indices()) {
- MFParamType param_type = function.param_type(param_index);
- switch (param_type.category()) {
- case MFParamType::SingleInput: {
- const MFInputSocket &socket = function_node.input_for_param(param_index);
- const GVArray &values = storage.get_single_input__full(socket, scope);
- params.add_readonly_single_input(values);
- break;
- }
- case MFParamType::VectorInput: {
- const MFInputSocket &socket = function_node.input_for_param(param_index);
- const GVVectorArray &values = storage.get_vector_input__full(socket, scope);
- params.add_readonly_vector_input(values);
- break;
- }
- case MFParamType::SingleOutput: {
- const MFOutputSocket &socket = function_node.output_for_param(param_index);
- GMutableSpan values = storage.get_single_output__full(socket);
- params.add_uninitialized_single_output(values);
- break;
- }
- case MFParamType::VectorOutput: {
- const MFOutputSocket &socket = function_node.output_for_param(param_index);
- GVectorArray &values = storage.get_vector_output__full(socket);
- params.add_vector_output(values);
- break;
- }
- case MFParamType::SingleMutable: {
- const MFInputSocket &input = function_node.input_for_param(param_index);
- const MFOutputSocket &output = function_node.output_for_param(param_index);
- GMutableSpan values = storage.get_mutable_single__full(input, output, scope);
- params.add_single_mutable(values);
- break;
- }
- case MFParamType::VectorMutable: {
- const MFInputSocket &input = function_node.input_for_param(param_index);
- const MFOutputSocket &output = function_node.output_for_param(param_index);
- GVectorArray &values = storage.get_mutable_vector__full(input, output, scope);
- params.add_vector_mutable(values);
- break;
- }
- }
- }
-
- function.call(storage.mask(), params, global_context);
- }
-
- storage.finish_node(function_node);
-}
-
-bool MFNetworkEvaluator::can_do_single_value_evaluation(const MFFunctionNode &function_node,
- Storage &storage) const
-{
- for (const MFInputSocket *socket : function_node.inputs()) {
- if (!storage.is_same_value_for_every_index(*socket->origin())) {
- return false;
- }
- }
- if (storage.mask().min_array_size() >= 1) {
- for (const MFOutputSocket *socket : function_node.outputs()) {
- if (storage.socket_has_buffer_for_output(*socket)) {
- return false;
- }
- }
- }
- return true;
-}
-
-BLI_NOINLINE void MFNetworkEvaluator::initialize_remaining_outputs(
- MFParams params, Storage &storage, Span<const MFInputSocket *> remaining_outputs) const
-{
- ResourceScope scope;
- for (const MFInputSocket *socket : remaining_outputs) {
- int param_index = inputs_.size() + outputs_.first_index_of(socket);
-
- switch (socket->data_type().category()) {
- case MFDataType::Single: {
- const GVArray &values = storage.get_single_input__full(*socket, scope);
- GMutableSpan output_values = params.uninitialized_single_output(param_index);
- values.materialize_to_uninitialized(storage.mask(), output_values.data());
- break;
- }
- case MFDataType::Vector: {
- const GVVectorArray &values = storage.get_vector_input__full(*socket, scope);
- GVectorArray &output_values = params.vector_output(param_index);
- output_values.extend(storage.mask(), values);
- break;
- }
- }
- }
-}
-
-/* -------------------------------------------------------------------- */
-/** \name Value Types
- * \{ */
-
-enum class ValueType {
- InputSingle,
- InputVector,
- OutputSingle,
- OutputVector,
- OwnSingle,
- OwnVector,
-};
-
-struct Value {
- ValueType type;
-
- Value(ValueType type) : type(type)
- {
- }
-};
-
-struct InputSingleValue : public Value {
- /** This virtual array has been provided by the code that called the multi-function network. */
- const GVArray &virtual_array;
-
- InputSingleValue(const GVArray &virtual_array)
- : Value(ValueType::InputSingle), virtual_array(virtual_array)
- {
- }
-};
-
-struct InputVectorValue : public Value {
- /** This virtual vector has been provided by the code that called the multi-function network. */
- const GVVectorArray &virtual_vector_array;
-
- InputVectorValue(const GVVectorArray &virtual_vector_array)
- : Value(ValueType::InputVector), virtual_vector_array(virtual_vector_array)
- {
- }
-};
-
-struct OutputValue : public Value {
- bool is_computed = false;
-
- OutputValue(ValueType type) : Value(type)
- {
- }
-};
-
-struct OutputSingleValue : public OutputValue {
- /** This span has been provided by the code that called the multi-function network. */
- GMutableSpan span;
-
- OutputSingleValue(GMutableSpan span) : OutputValue(ValueType::OutputSingle), span(span)
- {
- }
-};
-
-struct OutputVectorValue : public OutputValue {
- /** This vector array has been provided by the code that called the multi-function network. */
- GVectorArray *vector_array;
-
- OutputVectorValue(GVectorArray &vector_array)
- : OutputValue(ValueType::OutputVector), vector_array(&vector_array)
- {
- }
-};
-
-struct OwnSingleValue : public Value {
- /** This span has been allocated during the evaluation of the multi-function network and contains
- * intermediate data. It has to be freed once the network evaluation is finished. */
- GMutableSpan span;
- int max_remaining_users;
- bool is_single_allocated;
-
- OwnSingleValue(GMutableSpan span, int max_remaining_users, bool is_single_allocated)
- : Value(ValueType::OwnSingle),
- span(span),
- max_remaining_users(max_remaining_users),
- is_single_allocated(is_single_allocated)
- {
- }
-};
-
-struct OwnVectorValue : public Value {
- /** This vector array has been allocated during the evaluation of the multi-function network and
- * contains intermediate data. It has to be freed once the network evaluation is finished. */
- GVectorArray *vector_array;
- int max_remaining_users;
-
- OwnVectorValue(GVectorArray &vector_array, int max_remaining_users)
- : Value(ValueType::OwnVector),
- vector_array(&vector_array),
- max_remaining_users(max_remaining_users)
- {
- }
-};
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Storage methods
- * \{ */
-
-MFNetworkEvaluationStorage::MFNetworkEvaluationStorage(IndexMask mask, int socket_id_amount)
- : mask_(mask),
- value_per_output_id_(socket_id_amount, nullptr),
- min_array_size_(mask.min_array_size())
-{
-}
-
-MFNetworkEvaluationStorage::~MFNetworkEvaluationStorage()
-{
- for (Value *any_value : value_per_output_id_) {
- if (any_value == nullptr) {
- continue;
- }
- if (any_value->type == ValueType::OwnSingle) {
- OwnSingleValue *value = static_cast<OwnSingleValue *>(any_value);
- GMutableSpan span = value->span;
- const CPPType &type = span.type();
- if (value->is_single_allocated) {
- type.destruct(span.data());
- }
- else {
- type.destruct_indices(span.data(), mask_);
- MEM_freeN(span.data());
- }
- }
- else if (any_value->type == ValueType::OwnVector) {
- OwnVectorValue *value = static_cast<OwnVectorValue *>(any_value);
- delete value->vector_array;
- }
- }
-}
-
-IndexMask MFNetworkEvaluationStorage::mask() const
-{
- return mask_;
-}
-
-bool MFNetworkEvaluationStorage::socket_is_computed(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- return false;
- }
- if (ELEM(any_value->type, ValueType::OutputSingle, ValueType::OutputVector)) {
- return static_cast<OutputValue *>(any_value)->is_computed;
- }
- return true;
-}
-
-bool MFNetworkEvaluationStorage::is_same_value_for_every_index(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- switch (any_value->type) {
- case ValueType::OwnSingle:
- return static_cast<OwnSingleValue *>(any_value)->span.size() == 1;
- case ValueType::OwnVector:
- return static_cast<OwnVectorValue *>(any_value)->vector_array->size() == 1;
- case ValueType::InputSingle:
- return static_cast<InputSingleValue *>(any_value)->virtual_array.is_single();
- case ValueType::InputVector:
- return static_cast<InputVectorValue *>(any_value)->virtual_vector_array.is_single_vector();
- case ValueType::OutputSingle:
- return static_cast<OutputSingleValue *>(any_value)->span.size() == 1;
- case ValueType::OutputVector:
- return static_cast<OutputVectorValue *>(any_value)->vector_array->size() == 1;
- }
- BLI_assert(false);
- return false;
-}
-
-bool MFNetworkEvaluationStorage::socket_has_buffer_for_output(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- return false;
- }
-
- BLI_assert(ELEM(any_value->type, ValueType::OutputSingle, ValueType::OutputVector));
- return true;
-}
-
-void MFNetworkEvaluationStorage::finish_node(const MFFunctionNode &node)
-{
- for (const MFInputSocket *socket : node.inputs()) {
- this->finish_input_socket(*socket);
- }
- for (const MFOutputSocket *socket : node.outputs()) {
- this->finish_output_socket(*socket);
- }
-}
-
-void MFNetworkEvaluationStorage::finish_output_socket(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- return;
- }
-
- if (ELEM(any_value->type, ValueType::OutputSingle, ValueType::OutputVector)) {
- static_cast<OutputValue *>(any_value)->is_computed = true;
- }
-}
-
-void MFNetworkEvaluationStorage::finish_input_socket(const MFInputSocket &socket)
-{
- const MFOutputSocket &origin = *socket.origin();
-
- Value *any_value = value_per_output_id_[origin.id()];
- if (any_value == nullptr) {
- /* Can happen when a value has been forward to the next node. */
- return;
- }
-
- switch (any_value->type) {
- case ValueType::InputSingle:
- case ValueType::OutputSingle:
- case ValueType::InputVector:
- case ValueType::OutputVector: {
- break;
- }
- case ValueType::OwnSingle: {
- OwnSingleValue *value = static_cast<OwnSingleValue *>(any_value);
- BLI_assert(value->max_remaining_users >= 1);
- value->max_remaining_users--;
- if (value->max_remaining_users == 0) {
- GMutableSpan span = value->span;
- const CPPType &type = span.type();
- if (value->is_single_allocated) {
- type.destruct(span.data());
- }
- else {
- type.destruct_indices(span.data(), mask_);
- MEM_freeN(span.data());
- }
- value_per_output_id_[origin.id()] = nullptr;
- }
- break;
- }
- case ValueType::OwnVector: {
- OwnVectorValue *value = static_cast<OwnVectorValue *>(any_value);
- BLI_assert(value->max_remaining_users >= 1);
- value->max_remaining_users--;
- if (value->max_remaining_users == 0) {
- delete value->vector_array;
- value_per_output_id_[origin.id()] = nullptr;
- }
- break;
- }
- }
-}
-
-void MFNetworkEvaluationStorage::add_single_input_from_caller(const MFOutputSocket &socket,
- const GVArray &virtual_array)
-{
- BLI_assert(value_per_output_id_[socket.id()] == nullptr);
- BLI_assert(virtual_array.size() >= min_array_size_);
-
- auto *value = allocator_.construct<InputSingleValue>(virtual_array).release();
- value_per_output_id_[socket.id()] = value;
-}
-
-void MFNetworkEvaluationStorage::add_vector_input_from_caller(
- const MFOutputSocket &socket, const GVVectorArray &virtual_vector_array)
-{
- BLI_assert(value_per_output_id_[socket.id()] == nullptr);
- BLI_assert(virtual_vector_array.size() >= min_array_size_);
-
- auto *value = allocator_.construct<InputVectorValue>(virtual_vector_array).release();
- value_per_output_id_[socket.id()] = value;
-}
-
-void MFNetworkEvaluationStorage::add_single_output_from_caller(const MFOutputSocket &socket,
- GMutableSpan span)
-{
- BLI_assert(value_per_output_id_[socket.id()] == nullptr);
- BLI_assert(span.size() >= min_array_size_);
-
- auto *value = allocator_.construct<OutputSingleValue>(span).release();
- value_per_output_id_[socket.id()] = value;
-}
-
-void MFNetworkEvaluationStorage::add_vector_output_from_caller(const MFOutputSocket &socket,
- GVectorArray &vector_array)
-{
- BLI_assert(value_per_output_id_[socket.id()] == nullptr);
- BLI_assert(vector_array.size() >= min_array_size_);
-
- auto *value = allocator_.construct<OutputVectorValue>(vector_array).release();
- value_per_output_id_[socket.id()] = value;
-}
-
-GMutableSpan MFNetworkEvaluationStorage::get_single_output__full(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- const CPPType &type = socket.data_type().single_type();
- void *buffer = MEM_mallocN_aligned(min_array_size_ * type.size(), type.alignment(), AT);
- GMutableSpan span(type, buffer, min_array_size_);
-
- auto *value =
- allocator_.construct<OwnSingleValue>(span, socket.targets().size(), false).release();
- value_per_output_id_[socket.id()] = value;
-
- return span;
- }
-
- BLI_assert(any_value->type == ValueType::OutputSingle);
- return static_cast<OutputSingleValue *>(any_value)->span;
-}
-
-GMutableSpan MFNetworkEvaluationStorage::get_single_output__single(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- const CPPType &type = socket.data_type().single_type();
- void *buffer = allocator_.allocate(type.size(), type.alignment());
- GMutableSpan span(type, buffer, 1);
-
- auto *value =
- allocator_.construct<OwnSingleValue>(span, socket.targets().size(), true).release();
- value_per_output_id_[socket.id()] = value;
-
- return value->span;
- }
-
- BLI_assert(any_value->type == ValueType::OutputSingle);
- GMutableSpan span = static_cast<OutputSingleValue *>(any_value)->span;
- BLI_assert(span.size() == 1);
- return span;
-}
-
-GVectorArray &MFNetworkEvaluationStorage::get_vector_output__full(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- const CPPType &type = socket.data_type().vector_base_type();
- GVectorArray *vector_array = new GVectorArray(type, min_array_size_);
-
- auto *value =
- allocator_.construct<OwnVectorValue>(*vector_array, socket.targets().size()).release();
- value_per_output_id_[socket.id()] = value;
-
- return *value->vector_array;
- }
-
- BLI_assert(any_value->type == ValueType::OutputVector);
- return *static_cast<OutputVectorValue *>(any_value)->vector_array;
-}
-
-GVectorArray &MFNetworkEvaluationStorage::get_vector_output__single(const MFOutputSocket &socket)
-{
- Value *any_value = value_per_output_id_[socket.id()];
- if (any_value == nullptr) {
- const CPPType &type = socket.data_type().vector_base_type();
- GVectorArray *vector_array = new GVectorArray(type, 1);
-
- auto *value =
- allocator_.construct<OwnVectorValue>(*vector_array, socket.targets().size()).release();
- value_per_output_id_[socket.id()] = value;
-
- return *value->vector_array;
- }
-
- BLI_assert(any_value->type == ValueType::OutputVector);
- GVectorArray &vector_array = *static_cast<OutputVectorValue *>(any_value)->vector_array;
- BLI_assert(vector_array.size() == 1);
- return vector_array;
-}
-
-GMutableSpan MFNetworkEvaluationStorage::get_mutable_single__full(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope)
-{
- const MFOutputSocket &from = *input.origin();
- const MFOutputSocket &to = output;
- const CPPType &type = from.data_type().single_type();
-
- Value *from_any_value = value_per_output_id_[from.id()];
- Value *to_any_value = value_per_output_id_[to.id()];
- BLI_assert(from_any_value != nullptr);
- BLI_assert(type == to.data_type().single_type());
-
- if (to_any_value != nullptr) {
- BLI_assert(to_any_value->type == ValueType::OutputSingle);
- GMutableSpan span = static_cast<OutputSingleValue *>(to_any_value)->span;
- const GVArray &virtual_array = this->get_single_input__full(input, scope);
- virtual_array.materialize_to_uninitialized(mask_, span.data());
- return span;
- }
-
- if (from_any_value->type == ValueType::OwnSingle) {
- OwnSingleValue *value = static_cast<OwnSingleValue *>(from_any_value);
- if (value->max_remaining_users == 1 && !value->is_single_allocated) {
- value_per_output_id_[to.id()] = value;
- value_per_output_id_[from.id()] = nullptr;
- value->max_remaining_users = to.targets().size();
- return value->span;
- }
- }
-
- const GVArray &virtual_array = this->get_single_input__full(input, scope);
- void *new_buffer = MEM_mallocN_aligned(min_array_size_ * type.size(), type.alignment(), AT);
- GMutableSpan new_array_ref(type, new_buffer, min_array_size_);
- virtual_array.materialize_to_uninitialized(mask_, new_array_ref.data());
-
- OwnSingleValue *new_value =
- allocator_.construct<OwnSingleValue>(new_array_ref, to.targets().size(), false).release();
- value_per_output_id_[to.id()] = new_value;
- return new_array_ref;
-}
-
-GMutableSpan MFNetworkEvaluationStorage::get_mutable_single__single(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope)
-{
- const MFOutputSocket &from = *input.origin();
- const MFOutputSocket &to = output;
- const CPPType &type = from.data_type().single_type();
-
- Value *from_any_value = value_per_output_id_[from.id()];
- Value *to_any_value = value_per_output_id_[to.id()];
- BLI_assert(from_any_value != nullptr);
- BLI_assert(type == to.data_type().single_type());
-
- if (to_any_value != nullptr) {
- BLI_assert(to_any_value->type == ValueType::OutputSingle);
- GMutableSpan span = static_cast<OutputSingleValue *>(to_any_value)->span;
- BLI_assert(span.size() == 1);
- const GVArray &virtual_array = this->get_single_input__single(input, scope);
- virtual_array.get_single_to_uninitialized(span[0]);
- return span;
- }
-
- if (from_any_value->type == ValueType::OwnSingle) {
- OwnSingleValue *value = static_cast<OwnSingleValue *>(from_any_value);
- if (value->max_remaining_users == 1) {
- value_per_output_id_[to.id()] = value;
- value_per_output_id_[from.id()] = nullptr;
- value->max_remaining_users = to.targets().size();
- BLI_assert(value->span.size() == 1);
- return value->span;
- }
- }
-
- const GVArray &virtual_array = this->get_single_input__single(input, scope);
-
- void *new_buffer = allocator_.allocate(type.size(), type.alignment());
- virtual_array.get_single_to_uninitialized(new_buffer);
- GMutableSpan new_array_ref(type, new_buffer, 1);
-
- OwnSingleValue *new_value =
- allocator_.construct<OwnSingleValue>(new_array_ref, to.targets().size(), true).release();
- value_per_output_id_[to.id()] = new_value;
- return new_array_ref;
-}
-
-GVectorArray &MFNetworkEvaluationStorage::get_mutable_vector__full(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope)
-{
- const MFOutputSocket &from = *input.origin();
- const MFOutputSocket &to = output;
- const CPPType &base_type = from.data_type().vector_base_type();
-
- Value *from_any_value = value_per_output_id_[from.id()];
- Value *to_any_value = value_per_output_id_[to.id()];
- BLI_assert(from_any_value != nullptr);
- BLI_assert(base_type == to.data_type().vector_base_type());
-
- if (to_any_value != nullptr) {
- BLI_assert(to_any_value->type == ValueType::OutputVector);
- GVectorArray &vector_array = *static_cast<OutputVectorValue *>(to_any_value)->vector_array;
- const GVVectorArray &virtual_vector_array = this->get_vector_input__full(input, scope);
- vector_array.extend(mask_, virtual_vector_array);
- return vector_array;
- }
-
- if (from_any_value->type == ValueType::OwnVector) {
- OwnVectorValue *value = static_cast<OwnVectorValue *>(from_any_value);
- if (value->max_remaining_users == 1) {
- value_per_output_id_[to.id()] = value;
- value_per_output_id_[from.id()] = nullptr;
- value->max_remaining_users = to.targets().size();
- return *value->vector_array;
- }
- }
-
- const GVVectorArray &virtual_vector_array = this->get_vector_input__full(input, scope);
-
- GVectorArray *new_vector_array = new GVectorArray(base_type, min_array_size_);
- new_vector_array->extend(mask_, virtual_vector_array);
-
- OwnVectorValue *new_value =
- allocator_.construct<OwnVectorValue>(*new_vector_array, to.targets().size()).release();
- value_per_output_id_[to.id()] = new_value;
-
- return *new_vector_array;
-}
-
-GVectorArray &MFNetworkEvaluationStorage::get_mutable_vector__single(const MFInputSocket &input,
- const MFOutputSocket &output,
- ResourceScope &scope)
-{
- const MFOutputSocket &from = *input.origin();
- const MFOutputSocket &to = output;
- const CPPType &base_type = from.data_type().vector_base_type();
-
- Value *from_any_value = value_per_output_id_[from.id()];
- Value *to_any_value = value_per_output_id_[to.id()];
- BLI_assert(from_any_value != nullptr);
- BLI_assert(base_type == to.data_type().vector_base_type());
-
- if (to_any_value != nullptr) {
- BLI_assert(to_any_value->type == ValueType::OutputVector);
- GVectorArray &vector_array = *static_cast<OutputVectorValue *>(to_any_value)->vector_array;
- BLI_assert(vector_array.size() == 1);
- const GVVectorArray &virtual_vector_array = this->get_vector_input__single(input, scope);
- vector_array.extend({0}, virtual_vector_array);
- return vector_array;
- }
-
- if (from_any_value->type == ValueType::OwnVector) {
- OwnVectorValue *value = static_cast<OwnVectorValue *>(from_any_value);
- if (value->max_remaining_users == 1) {
- value_per_output_id_[to.id()] = value;
- value_per_output_id_[from.id()] = nullptr;
- value->max_remaining_users = to.targets().size();
- return *value->vector_array;
- }
- }
-
- const GVVectorArray &virtual_vector_array = this->get_vector_input__single(input, scope);
-
- GVectorArray *new_vector_array = new GVectorArray(base_type, 1);
- new_vector_array->extend({0}, virtual_vector_array);
-
- OwnVectorValue *new_value =
- allocator_.construct<OwnVectorValue>(*new_vector_array, to.targets().size()).release();
- value_per_output_id_[to.id()] = new_value;
- return *new_vector_array;
-}
-
-const GVArray &MFNetworkEvaluationStorage::get_single_input__full(const MFInputSocket &socket,
- ResourceScope &scope)
-{
- const MFOutputSocket &origin = *socket.origin();
- Value *any_value = value_per_output_id_[origin.id()];
- BLI_assert(any_value != nullptr);
-
- if (any_value->type == ValueType::OwnSingle) {
- OwnSingleValue *value = static_cast<OwnSingleValue *>(any_value);
- if (value->is_single_allocated) {
- return scope.construct<GVArray_For_SingleValueRef>(
- __func__, value->span.type(), min_array_size_, value->span.data());
- }
-
- return scope.construct<GVArray_For_GSpan>(__func__, value->span);
- }
- if (any_value->type == ValueType::InputSingle) {
- InputSingleValue *value = static_cast<InputSingleValue *>(any_value);
- return value->virtual_array;
- }
- if (any_value->type == ValueType::OutputSingle) {
- OutputSingleValue *value = static_cast<OutputSingleValue *>(any_value);
- BLI_assert(value->is_computed);
- return scope.construct<GVArray_For_GSpan>(__func__, value->span);
- }
-
- BLI_assert(false);
- return scope.construct<GVArray_For_Empty>(__func__, CPPType::get<float>());
-}
-
-const GVArray &MFNetworkEvaluationStorage::get_single_input__single(const MFInputSocket &socket,
- ResourceScope &scope)
-{
- const MFOutputSocket &origin = *socket.origin();
- Value *any_value = value_per_output_id_[origin.id()];
- BLI_assert(any_value != nullptr);
-
- if (any_value->type == ValueType::OwnSingle) {
- OwnSingleValue *value = static_cast<OwnSingleValue *>(any_value);
- BLI_assert(value->span.size() == 1);
- return scope.construct<GVArray_For_GSpan>(__func__, value->span);
- }
- if (any_value->type == ValueType::InputSingle) {
- InputSingleValue *value = static_cast<InputSingleValue *>(any_value);
- BLI_assert(value->virtual_array.is_single());
- return value->virtual_array;
- }
- if (any_value->type == ValueType::OutputSingle) {
- OutputSingleValue *value = static_cast<OutputSingleValue *>(any_value);
- BLI_assert(value->is_computed);
- BLI_assert(value->span.size() == 1);
- return scope.construct<GVArray_For_GSpan>(__func__, value->span);
- }
-
- BLI_assert(false);
- return scope.construct<GVArray_For_Empty>(__func__, CPPType::get<float>());
-}
-
-const GVVectorArray &MFNetworkEvaluationStorage::get_vector_input__full(
- const MFInputSocket &socket, ResourceScope &scope)
-{
- const MFOutputSocket &origin = *socket.origin();
- Value *any_value = value_per_output_id_[origin.id()];
- BLI_assert(any_value != nullptr);
-
- if (any_value->type == ValueType::OwnVector) {
- OwnVectorValue *value = static_cast<OwnVectorValue *>(any_value);
- if (value->vector_array->size() == 1) {
- GSpan span = (*value->vector_array)[0];
- return scope.construct<GVVectorArray_For_SingleGSpan>(__func__, span, min_array_size_);
- }
-
- return scope.construct<GVVectorArray_For_GVectorArray>(__func__, *value->vector_array);
- }
- if (any_value->type == ValueType::InputVector) {
- InputVectorValue *value = static_cast<InputVectorValue *>(any_value);
- return value->virtual_vector_array;
- }
- if (any_value->type == ValueType::OutputVector) {
- OutputVectorValue *value = static_cast<OutputVectorValue *>(any_value);
- return scope.construct<GVVectorArray_For_GVectorArray>(__func__, *value->vector_array);
- }
-
- BLI_assert(false);
- return scope.construct<GVVectorArray_For_SingleGSpan>(__func__, GSpan(CPPType::get<float>()), 0);
-}
-
-const GVVectorArray &MFNetworkEvaluationStorage::get_vector_input__single(
- const MFInputSocket &socket, ResourceScope &scope)
-{
- const MFOutputSocket &origin = *socket.origin();
- Value *any_value = value_per_output_id_[origin.id()];
- BLI_assert(any_value != nullptr);
-
- if (any_value->type == ValueType::OwnVector) {
- OwnVectorValue *value = static_cast<OwnVectorValue *>(any_value);
- BLI_assert(value->vector_array->size() == 1);
- return scope.construct<GVVectorArray_For_GVectorArray>(__func__, *value->vector_array);
- }
- if (any_value->type == ValueType::InputVector) {
- InputVectorValue *value = static_cast<InputVectorValue *>(any_value);
- BLI_assert(value->virtual_vector_array.is_single_vector());
- return value->virtual_vector_array;
- }
- if (any_value->type == ValueType::OutputVector) {
- OutputVectorValue *value = static_cast<OutputVectorValue *>(any_value);
- BLI_assert(value->vector_array->size() == 1);
- return scope.construct<GVVectorArray_For_GVectorArray>(__func__, *value->vector_array);
- }
-
- BLI_assert(false);
- return scope.construct<GVVectorArray_For_SingleGSpan>(__func__, GSpan(CPPType::get<float>()), 0);
-}
-
-/** \} */
-
-} // namespace blender::fn
diff --git a/source/blender/functions/intern/multi_function_network_optimization.cc b/source/blender/functions/intern/multi_function_network_optimization.cc
deleted file mode 100644
index 75c3583c5e5..00000000000
--- a/source/blender/functions/intern/multi_function_network_optimization.cc
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup fn
- */
-
-/* Used to check if two multi-functions have the exact same type. */
-#include <typeinfo>
-
-#include "FN_multi_function_builder.hh"
-#include "FN_multi_function_network_evaluation.hh"
-#include "FN_multi_function_network_optimization.hh"
-
-#include "BLI_disjoint_set.hh"
-#include "BLI_ghash.h"
-#include "BLI_map.hh"
-#include "BLI_multi_value_map.hh"
-#include "BLI_rand.h"
-#include "BLI_stack.hh"
-
-namespace blender::fn::mf_network_optimization {
-
-/* -------------------------------------------------------------------- */
-/** \name Utility functions to find nodes in a network.
- * \{ */
-
-static bool set_tag_and_check_if_modified(bool &tag, bool new_value)
-{
- if (tag != new_value) {
- tag = new_value;
- return true;
- }
-
- return false;
-}
-
-static Array<bool> mask_nodes_to_the_left(MFNetwork &network, Span<MFNode *> nodes)
-{
- Array<bool> is_to_the_left(network.node_id_amount(), false);
- Stack<MFNode *> nodes_to_check;
-
- for (MFNode *node : nodes) {
- is_to_the_left[node->id()] = true;
- nodes_to_check.push(node);
- }
-
- while (!nodes_to_check.is_empty()) {
- MFNode &node = *nodes_to_check.pop();
-
- for (MFInputSocket *input_socket : node.inputs()) {
- MFOutputSocket *origin = input_socket->origin();
- if (origin != nullptr) {
- MFNode &origin_node = origin->node();
- if (set_tag_and_check_if_modified(is_to_the_left[origin_node.id()], true)) {
- nodes_to_check.push(&origin_node);
- }
- }
- }
- }
-
- return is_to_the_left;
-}
-
-static Array<bool> mask_nodes_to_the_right(MFNetwork &network, Span<MFNode *> nodes)
-{
- Array<bool> is_to_the_right(network.node_id_amount(), false);
- Stack<MFNode *> nodes_to_check;
-
- for (MFNode *node : nodes) {
- is_to_the_right[node->id()] = true;
- nodes_to_check.push(node);
- }
-
- while (!nodes_to_check.is_empty()) {
- MFNode &node = *nodes_to_check.pop();
-
- for (MFOutputSocket *output_socket : node.outputs()) {
- for (MFInputSocket *target_socket : output_socket->targets()) {
- MFNode &target_node = target_socket->node();
- if (set_tag_and_check_if_modified(is_to_the_right[target_node.id()], true)) {
- nodes_to_check.push(&target_node);
- }
- }
- }
- }
-
- return is_to_the_right;
-}
-
-static Vector<MFNode *> find_nodes_based_on_mask(MFNetwork &network,
- Span<bool> id_mask,
- bool mask_value)
-{
- Vector<MFNode *> nodes;
- for (int id : id_mask.index_range()) {
- if (id_mask[id] == mask_value) {
- MFNode *node = network.node_or_null_by_id(id);
- if (node != nullptr) {
- nodes.append(node);
- }
- }
- }
- return nodes;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Dead Node Removal
- * \{ */
-
-/**
- * Unused nodes are all those nodes that no dummy node depends upon.
- */
-void dead_node_removal(MFNetwork &network)
-{
- Array<bool> node_is_used_mask = mask_nodes_to_the_left(network,
- network.dummy_nodes().cast<MFNode *>());
- Vector<MFNode *> nodes_to_remove = find_nodes_based_on_mask(network, node_is_used_mask, false);
- network.remove(nodes_to_remove);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Constant Folding
- * \{ */
-
-static bool function_node_can_be_constant(MFFunctionNode *node)
-{
- if (node->has_unlinked_inputs()) {
- return false;
- }
- if (node->function().depends_on_context()) {
- return false;
- }
- return true;
-}
-
-static Vector<MFNode *> find_non_constant_nodes(MFNetwork &network)
-{
- Vector<MFNode *> non_constant_nodes;
- non_constant_nodes.extend(network.dummy_nodes().cast<MFNode *>());
-
- for (MFFunctionNode *node : network.function_nodes()) {
- if (!function_node_can_be_constant(node)) {
- non_constant_nodes.append(node);
- }
- }
- return non_constant_nodes;
-}
-
-static bool output_has_non_constant_target_node(MFOutputSocket *output_socket,
- Span<bool> is_not_constant_mask)
-{
- for (MFInputSocket *target_socket : output_socket->targets()) {
- MFNode &target_node = target_socket->node();
- bool target_is_not_constant = is_not_constant_mask[target_node.id()];
- if (target_is_not_constant) {
- return true;
- }
- }
- return false;
-}
-
-static MFInputSocket *try_find_dummy_target_socket(MFOutputSocket *output_socket)
-{
- for (MFInputSocket *target_socket : output_socket->targets()) {
- if (target_socket->node().is_dummy()) {
- return target_socket;
- }
- }
- return nullptr;
-}
-
-static Vector<MFInputSocket *> find_constant_inputs_to_fold(
- MFNetwork &network, Vector<MFDummyNode *> &r_temporary_nodes)
-{
- Vector<MFNode *> non_constant_nodes = find_non_constant_nodes(network);
- Array<bool> is_not_constant_mask = mask_nodes_to_the_right(network, non_constant_nodes);
- Vector<MFNode *> constant_nodes = find_nodes_based_on_mask(network, is_not_constant_mask, false);
-
- Vector<MFInputSocket *> sockets_to_compute;
- for (MFNode *node : constant_nodes) {
- if (node->inputs().size() == 0) {
- continue;
- }
-
- for (MFOutputSocket *output_socket : node->outputs()) {
- MFDataType data_type = output_socket->data_type();
- if (output_has_non_constant_target_node(output_socket, is_not_constant_mask)) {
- MFInputSocket *dummy_target = try_find_dummy_target_socket(output_socket);
- if (dummy_target == nullptr) {
- dummy_target = &network.add_output("Dummy", data_type);
- network.add_link(*output_socket, *dummy_target);
- r_temporary_nodes.append(&dummy_target->node().as_dummy());
- }
-
- sockets_to_compute.append(dummy_target);
- }
- }
- }
- return sockets_to_compute;
-}
-
-static void prepare_params_for_constant_folding(const MultiFunction &network_fn,
- MFParamsBuilder &params,
- ResourceScope &scope)
-{
- for (int param_index : network_fn.param_indices()) {
- MFParamType param_type = network_fn.param_type(param_index);
- MFDataType data_type = param_type.data_type();
-
- switch (data_type.category()) {
- case MFDataType::Single: {
- /* Allocates memory for a single constant folded value. */
- const CPPType &cpp_type = data_type.single_type();
- void *buffer = scope.linear_allocator().allocate(cpp_type.size(), cpp_type.alignment());
- GMutableSpan array{cpp_type, buffer, 1};
- params.add_uninitialized_single_output(array);
- break;
- }
- case MFDataType::Vector: {
- /* Allocates memory for a constant folded vector. */
- const CPPType &cpp_type = data_type.vector_base_type();
- GVectorArray &vector_array = scope.construct<GVectorArray>(AT, cpp_type, 1);
- params.add_vector_output(vector_array);
- break;
- }
- }
- }
-}
-
-static Array<MFOutputSocket *> add_constant_folded_sockets(const MultiFunction &network_fn,
- MFParamsBuilder &params,
- ResourceScope &scope,
- MFNetwork &network)
-{
- Array<MFOutputSocket *> folded_sockets{network_fn.param_indices().size(), nullptr};
-
- for (int param_index : network_fn.param_indices()) {
- MFParamType param_type = network_fn.param_type(param_index);
- MFDataType data_type = param_type.data_type();
-
- const MultiFunction *constant_fn = nullptr;
-
- switch (data_type.category()) {
- case MFDataType::Single: {
- const CPPType &cpp_type = data_type.single_type();
- GMutableSpan array = params.computed_array(param_index);
- void *buffer = array.data();
- scope.add(buffer, array.type().destruct_fn(), AT);
-
- constant_fn = &scope.construct<CustomMF_GenericConstant>(AT, cpp_type, buffer);
- break;
- }
- case MFDataType::Vector: {
- GVectorArray &vector_array = params.computed_vector_array(param_index);
- GSpan array = vector_array[0];
- constant_fn = &scope.construct<CustomMF_GenericConstantArray>(AT, array);
- break;
- }
- }
-
- MFFunctionNode &folded_node = network.add_function(*constant_fn);
- folded_sockets[param_index] = &folded_node.output(0);
- }
- return folded_sockets;
-}
-
-static Array<MFOutputSocket *> compute_constant_sockets_and_add_folded_nodes(
- MFNetwork &network, Span<const MFInputSocket *> sockets_to_compute, ResourceScope &scope)
-{
- MFNetworkEvaluator network_fn{{}, sockets_to_compute};
-
- MFContextBuilder context;
- MFParamsBuilder params{network_fn, 1};
- prepare_params_for_constant_folding(network_fn, params, scope);
- network_fn.call({0}, params, context);
- return add_constant_folded_sockets(network_fn, params, scope, network);
-}
-
-class MyClass {
- MFDummyNode node;
-};
-
-/**
- * Find function nodes that always output the same value and replace those with constant nodes.
- */
-void constant_folding(MFNetwork &network, ResourceScope &scope)
-{
- Vector<MFDummyNode *> temporary_nodes;
- Vector<MFInputSocket *> inputs_to_fold = find_constant_inputs_to_fold(network, temporary_nodes);
- if (inputs_to_fold.size() == 0) {
- return;
- }
-
- Array<MFOutputSocket *> folded_sockets = compute_constant_sockets_and_add_folded_nodes(
- network, inputs_to_fold, scope);
-
- for (int i : inputs_to_fold.index_range()) {
- MFOutputSocket &original_socket = *inputs_to_fold[i]->origin();
- network.relink(original_socket, *folded_sockets[i]);
- }
-
- network.remove(temporary_nodes.as_span().cast<MFNode *>());
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Common Sub-network Elimination
- * \{ */
-
-static uint64_t compute_node_hash(MFFunctionNode &node, RNG *rng, Span<uint64_t> node_hashes)
-{
- if (node.function().depends_on_context()) {
- return BLI_rng_get_uint(rng);
- }
- if (node.has_unlinked_inputs()) {
- return BLI_rng_get_uint(rng);
- }
-
- uint64_t combined_inputs_hash = 394659347u;
- for (MFInputSocket *input_socket : node.inputs()) {
- MFOutputSocket *origin_socket = input_socket->origin();
- uint64_t input_hash = BLI_ghashutil_combine_hash(node_hashes[origin_socket->node().id()],
- origin_socket->index());
- combined_inputs_hash = BLI_ghashutil_combine_hash(combined_inputs_hash, input_hash);
- }
-
- uint64_t function_hash = node.function().hash();
- uint64_t node_hash = BLI_ghashutil_combine_hash(combined_inputs_hash, function_hash);
- return node_hash;
-}
-
-/**
- * Produces a hash for every node. Two nodes with the same hash should have a high probability of
- * outputting the same values.
- */
-static Array<uint64_t> compute_node_hashes(MFNetwork &network)
-{
- RNG *rng = BLI_rng_new(0);
- Array<uint64_t> node_hashes(network.node_id_amount());
- Array<bool> node_is_hashed(network.node_id_amount(), false);
-
- /* No dummy nodes are not assumed to output the same values. */
- for (MFDummyNode *node : network.dummy_nodes()) {
- uint64_t node_hash = BLI_rng_get_uint(rng);
- node_hashes[node->id()] = node_hash;
- node_is_hashed[node->id()] = true;
- }
-
- Stack<MFFunctionNode *> nodes_to_check;
- nodes_to_check.push_multiple(network.function_nodes());
-
- while (!nodes_to_check.is_empty()) {
- MFFunctionNode &node = *nodes_to_check.peek();
- if (node_is_hashed[node.id()]) {
- nodes_to_check.pop();
- continue;
- }
-
- /* Make sure that origin nodes are hashed first. */
- bool all_dependencies_ready = true;
- for (MFInputSocket *input_socket : node.inputs()) {
- MFOutputSocket *origin_socket = input_socket->origin();
- if (origin_socket != nullptr) {
- MFNode &origin_node = origin_socket->node();
- if (!node_is_hashed[origin_node.id()]) {
- all_dependencies_ready = false;
- nodes_to_check.push(&origin_node.as_function());
- }
- }
- }
- if (!all_dependencies_ready) {
- continue;
- }
-
- uint64_t node_hash = compute_node_hash(node, rng, node_hashes);
- node_hashes[node.id()] = node_hash;
- node_is_hashed[node.id()] = true;
- nodes_to_check.pop();
- }
-
- BLI_rng_free(rng);
- return node_hashes;
-}
-
-static MultiValueMap<uint64_t, MFNode *> group_nodes_by_hash(MFNetwork &network,
- Span<uint64_t> node_hashes)
-{
- MultiValueMap<uint64_t, MFNode *> nodes_by_hash;
- for (int id : IndexRange(network.node_id_amount())) {
- MFNode *node = network.node_or_null_by_id(id);
- if (node != nullptr) {
- uint64_t node_hash = node_hashes[id];
- nodes_by_hash.add(node_hash, node);
- }
- }
- return nodes_by_hash;
-}
-
-static bool functions_are_equal(const MultiFunction &a, const MultiFunction &b)
-{
- if (&a == &b) {
- return true;
- }
- if (typeid(a) == typeid(b)) {
- return a.equals(b);
- }
- return false;
-}
-
-static bool nodes_output_same_values(DisjointSet &cache, const MFNode &a, const MFNode &b)
-{
- if (cache.in_same_set(a.id(), b.id())) {
- return true;
- }
-
- if (a.is_dummy() || b.is_dummy()) {
- return false;
- }
- if (!functions_are_equal(a.as_function().function(), b.as_function().function())) {
- return false;
- }
- for (int i : a.inputs().index_range()) {
- const MFOutputSocket *origin_a = a.input(i).origin();
- const MFOutputSocket *origin_b = b.input(i).origin();
- if (origin_a == nullptr || origin_b == nullptr) {
- return false;
- }
- if (!nodes_output_same_values(cache, origin_a->node(), origin_b->node())) {
- return false;
- }
- }
-
- cache.join(a.id(), b.id());
- return true;
-}
-
-static void relink_duplicate_nodes(MFNetwork &network,
- MultiValueMap<uint64_t, MFNode *> &nodes_by_hash)
-{
- DisjointSet same_node_cache{network.node_id_amount()};
-
- for (Span<MFNode *> nodes_with_same_hash : nodes_by_hash.values()) {
- if (nodes_with_same_hash.size() <= 1) {
- continue;
- }
-
- Vector<MFNode *, 16> nodes_to_check = nodes_with_same_hash;
- while (nodes_to_check.size() >= 2) {
- Vector<MFNode *, 16> remaining_nodes;
-
- MFNode &deduplicated_node = *nodes_to_check[0];
- for (MFNode *node : nodes_to_check.as_span().drop_front(1)) {
- /* This is true with fairly high probability, but hash collisions can happen. So we have to
- * check if the node actually output the same values. */
- if (nodes_output_same_values(same_node_cache, deduplicated_node, *node)) {
- for (int i : deduplicated_node.outputs().index_range()) {
- network.relink(node->output(i), deduplicated_node.output(i));
- }
- }
- else {
- remaining_nodes.append(node);
- }
- }
- nodes_to_check = std::move(remaining_nodes);
- }
- }
-}
-
-/**
- * Tries to detect duplicate sub-networks and eliminates them. This can help quite a lot when node
- * groups were used to create the network.
- */
-void common_subnetwork_elimination(MFNetwork &network)
-{
- Array<uint64_t> node_hashes = compute_node_hashes(network);
- MultiValueMap<uint64_t, MFNode *> nodes_by_hash = group_nodes_by_hash(network, node_hashes);
- relink_duplicate_nodes(network, nodes_by_hash);
-}
-
-/** \} */
-
-} // namespace blender::fn::mf_network_optimization
diff --git a/source/blender/functions/tests/FN_multi_function_network_test.cc b/source/blender/functions/tests/FN_multi_function_network_test.cc
deleted file mode 100644
index 7b9738e5ca4..00000000000
--- a/source/blender/functions/tests/FN_multi_function_network_test.cc
+++ /dev/null
@@ -1,280 +0,0 @@
-/* Apache License, Version 2.0 */
-
-#include "testing/testing.h"
-
-#include "FN_multi_function_builder.hh"
-#include "FN_multi_function_network.hh"
-#include "FN_multi_function_network_evaluation.hh"
-
-namespace blender::fn::tests {
-namespace {
-
-TEST(multi_function_network, Test1)
-{
- CustomMF_SI_SO<int, int> add_10_fn("add 10", [](int value) { return value + 10; });
- CustomMF_SI_SI_SO<int, int, int> multiply_fn("multiply", [](int a, int b) { return a * b; });
-
- MFNetwork network;
-
- MFNode &node1 = network.add_function(add_10_fn);
- MFNode &node2 = network.add_function(multiply_fn);
- MFOutputSocket &input_socket = network.add_input("Input", MFDataType::ForSingle<int>());
- MFInputSocket &output_socket = network.add_output("Output", MFDataType::ForSingle<int>());
- network.add_link(node1.output(0), node2.input(0));
- network.add_link(node1.output(0), node2.input(1));
- network.add_link(node2.output(0), output_socket);
- network.add_link(input_socket, node1.input(0));
-
- MFNetworkEvaluator network_fn{{&input_socket}, {&output_socket}};
-
- {
- Array<int> values = {4, 6, 1, 2, 0};
- Array<int> results(values.size(), 0);
-
- MFParamsBuilder params(network_fn, values.size());
- params.add_readonly_single_input(values.as_span());
- params.add_uninitialized_single_output(results.as_mutable_span());
-
- MFContextBuilder context;
-
- network_fn.call({0, 2, 3, 4}, params, context);
-
- EXPECT_EQ(results[0], 14 * 14);
- EXPECT_EQ(results[1], 0);
- EXPECT_EQ(results[2], 11 * 11);
- EXPECT_EQ(results[3], 12 * 12);
- EXPECT_EQ(results[4], 10 * 10);
- }
- {
- int value = 3;
- Array<int> results(5, 0);
-
- MFParamsBuilder params(network_fn, results.size());
- params.add_readonly_single_input(&value);
- params.add_uninitialized_single_output(results.as_mutable_span());
-
- MFContextBuilder context;
-
- network_fn.call({1, 2, 4}, params, context);
-
- EXPECT_EQ(results[0], 0);
- EXPECT_EQ(results[1], 13 * 13);
- EXPECT_EQ(results[2], 13 * 13);
- EXPECT_EQ(results[3], 0);
- EXPECT_EQ(results[4], 13 * 13);
- }
-}
-
-class ConcatVectorsFunction : public MultiFunction {
- public:
- ConcatVectorsFunction()
- {
- static MFSignature signature = create_signature();
- this->set_signature(&signature);
- }
-
- static MFSignature create_signature()
- {
- MFSignatureBuilder signature{"Concat Vectors"};
- signature.vector_mutable<int>("A");
- signature.vector_input<int>("B");
- return signature.build();
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- GVectorArray &a = params.vector_mutable(0);
- const GVVectorArray &b = params.readonly_vector_input(1);
- a.extend(mask, b);
- }
-};
-
-class AppendFunction : public MultiFunction {
- public:
- AppendFunction()
- {
- static MFSignature signature = create_signature();
- this->set_signature(&signature);
- }
-
- static MFSignature create_signature()
- {
- MFSignatureBuilder signature{"Append"};
- signature.vector_mutable<int>("Vector");
- signature.single_input<int>("Value");
- return signature.build();
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- GVectorArray_TypedMutableRef<int> vectors = params.vector_mutable<int>(0);
- const VArray<int> &values = params.readonly_single_input<int>(1);
-
- for (int64_t i : mask) {
- vectors.append(i, values[i]);
- }
- }
-};
-
-class SumVectorFunction : public MultiFunction {
- public:
- SumVectorFunction()
- {
- static MFSignature signature = create_signature();
- this->set_signature(&signature);
- }
-
- static MFSignature create_signature()
- {
- MFSignatureBuilder signature{"Sum Vectors"};
- signature.vector_input<int>("Vector");
- signature.single_output<int>("Sum");
- return signature.build();
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- const VVectorArray<int> &vectors = params.readonly_vector_input<int>(0);
- MutableSpan<int> sums = params.uninitialized_single_output<int>(1);
-
- for (int64_t i : mask) {
- int sum = 0;
- for (int j : IndexRange(vectors.get_vector_size(i))) {
- sum += vectors.get_vector_element(i, j);
- }
- sums[i] = sum;
- }
- }
-};
-
-class CreateRangeFunction : public MultiFunction {
- public:
- CreateRangeFunction()
- {
- static MFSignature signature = create_signature();
- this->set_signature(&signature);
- }
-
- static MFSignature create_signature()
- {
- MFSignatureBuilder signature{"Create Range"};
- signature.single_input<int>("Size");
- signature.vector_output<int>("Range");
- return signature.build();
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- const VArray<int> &sizes = params.readonly_single_input<int>(0, "Size");
- GVectorArray_TypedMutableRef<int> ranges = params.vector_output<int>(1, "Range");
-
- for (int64_t i : mask) {
- int size = sizes[i];
- for (int j : IndexRange(size)) {
- ranges.append(i, j);
- }
- }
- }
-};
-
-TEST(multi_function_network, Test2)
-{
- CustomMF_SI_SO<int, int> add_3_fn("add 3", [](int value) { return value + 3; });
-
- ConcatVectorsFunction concat_vectors_fn;
- AppendFunction append_fn;
- SumVectorFunction sum_fn;
- CreateRangeFunction create_range_fn;
-
- MFNetwork network;
-
- MFOutputSocket &input1 = network.add_input("Input 1", MFDataType::ForVector<int>());
- MFOutputSocket &input2 = network.add_input("Input 2", MFDataType::ForSingle<int>());
- MFInputSocket &output1 = network.add_output("Output 1", MFDataType::ForVector<int>());
- MFInputSocket &output2 = network.add_output("Output 2", MFDataType::ForSingle<int>());
-
- MFNode &node1 = network.add_function(add_3_fn);
- MFNode &node2 = network.add_function(create_range_fn);
- MFNode &node3 = network.add_function(concat_vectors_fn);
- MFNode &node4 = network.add_function(sum_fn);
- MFNode &node5 = network.add_function(append_fn);
- MFNode &node6 = network.add_function(sum_fn);
-
- network.add_link(input2, node1.input(0));
- network.add_link(node1.output(0), node2.input(0));
- network.add_link(node2.output(0), node3.input(1));
- network.add_link(input1, node3.input(0));
- network.add_link(input1, node4.input(0));
- network.add_link(node4.output(0), node5.input(1));
- network.add_link(node3.output(0), node5.input(0));
- network.add_link(node5.output(0), node6.input(0));
- network.add_link(node3.output(0), output1);
- network.add_link(node6.output(0), output2);
-
- // std::cout << network.to_dot() << "\n\n";
-
- MFNetworkEvaluator network_fn{{&input1, &input2}, {&output1, &output2}};
-
- {
- Array<int> input_value_1 = {3, 6};
- int input_value_2 = 4;
-
- GVectorArray output_value_1(CPPType::get<int32_t>(), 5);
- Array<int> output_value_2(5, -1);
-
- MFParamsBuilder params(network_fn, 5);
- GVVectorArray_For_SingleGSpan inputs_1{input_value_1.as_span(), 5};
- params.add_readonly_vector_input(inputs_1);
- params.add_readonly_single_input(&input_value_2);
- params.add_vector_output(output_value_1);
- params.add_uninitialized_single_output(output_value_2.as_mutable_span());
-
- MFContextBuilder context;
-
- network_fn.call({1, 2, 4}, params, context);
-
- EXPECT_EQ(output_value_1[0].size(), 0);
- EXPECT_EQ(output_value_1[1].size(), 9);
- EXPECT_EQ(output_value_1[2].size(), 9);
- EXPECT_EQ(output_value_1[3].size(), 0);
- EXPECT_EQ(output_value_1[4].size(), 9);
-
- EXPECT_EQ(output_value_2[0], -1);
- EXPECT_EQ(output_value_2[1], 39);
- EXPECT_EQ(output_value_2[2], 39);
- EXPECT_EQ(output_value_2[3], -1);
- EXPECT_EQ(output_value_2[4], 39);
- }
- {
- GVectorArray input_value_1(CPPType::get<int32_t>(), 3);
- GVectorArray_TypedMutableRef<int> input_value_1_ref{input_value_1};
- input_value_1_ref.extend(0, {3, 4, 5});
- input_value_1_ref.extend(1, {1, 2});
-
- Array<int> input_value_2 = {4, 2, 3};
-
- GVectorArray output_value_1(CPPType::get<int32_t>(), 3);
- Array<int> output_value_2(3, -1);
-
- MFParamsBuilder params(network_fn, 3);
- params.add_readonly_vector_input(input_value_1);
- params.add_readonly_single_input(input_value_2.as_span());
- params.add_vector_output(output_value_1);
- params.add_uninitialized_single_output(output_value_2.as_mutable_span());
-
- MFContextBuilder context;
-
- network_fn.call({0, 1, 2}, params, context);
-
- EXPECT_EQ(output_value_1[0].size(), 10);
- EXPECT_EQ(output_value_1[1].size(), 7);
- EXPECT_EQ(output_value_1[2].size(), 6);
-
- EXPECT_EQ(output_value_2[0], 45);
- EXPECT_EQ(output_value_2[1], 16);
- EXPECT_EQ(output_value_2[2], 15);
- }
-}
-
-} // namespace
-} // namespace blender::fn::tests
diff --git a/source/blender/functions/tests/FN_multi_function_test.cc b/source/blender/functions/tests/FN_multi_function_test.cc
index 3d73e020eb2..91c72a51dd6 100644
--- a/source/blender/functions/tests/FN_multi_function_test.cc
+++ b/source/blender/functions/tests/FN_multi_function_test.cc
@@ -4,6 +4,7 @@
#include "FN_multi_function.hh"
#include "FN_multi_function_builder.hh"
+#include "FN_multi_function_test_common.hh"
namespace blender::fn::tests {
namespace {
@@ -59,33 +60,6 @@ TEST(multi_function, AddFunction)
EXPECT_EQ(output[2], 36);
}
-class AddPrefixFunction : public MultiFunction {
- public:
- AddPrefixFunction()
- {
- static MFSignature signature = create_signature();
- this->set_signature(&signature);
- }
-
- static MFSignature create_signature()
- {
- MFSignatureBuilder signature{"Add Prefix"};
- signature.single_input<std::string>("Prefix");
- signature.single_mutable<std::string>("Strings");
- return signature.build();
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- const VArray<std::string> &prefixes = params.readonly_single_input<std::string>(0, "Prefix");
- MutableSpan<std::string> strings = params.single_mutable<std::string>(1, "Strings");
-
- for (int64_t i : mask) {
- strings[i] = prefixes[i] + strings[i];
- }
- }
-};
-
TEST(multi_function, AddPrefixFunction)
{
AddPrefixFunction fn;
@@ -113,43 +87,13 @@ TEST(multi_function, AddPrefixFunction)
EXPECT_EQ(strings[3], "ABAnother much longer string to trigger an allocation");
}
-class CreateRangeFunction : public MultiFunction {
- public:
- CreateRangeFunction()
- {
- static MFSignature signature = create_signature();
- this->set_signature(&signature);
- }
-
- static MFSignature create_signature()
- {
- MFSignatureBuilder signature{"Create Range"};
- signature.single_input<uint>("Size");
- signature.vector_output<uint>("Range");
- return signature.build();
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- const VArray<uint> &sizes = params.readonly_single_input<uint>(0, "Size");
- GVectorArray &ranges = params.vector_output(1, "Range");
-
- for (int64_t i : mask) {
- uint size = sizes[i];
- for (uint j : IndexRange(size)) {
- ranges.append(i, &j);
- }
- }
- }
-};
-
TEST(multi_function, CreateRangeFunction)
{
CreateRangeFunction fn;
- GVectorArray ranges(CPPType::get<uint>(), 5);
- GVectorArray_TypedMutableRef<uint> ranges_ref{ranges};
- Array<uint> sizes = {3, 0, 6, 1, 4};
+ GVectorArray ranges(CPPType::get<int>(), 5);
+ GVectorArray_TypedMutableRef<int> ranges_ref{ranges};
+ Array<int> sizes = {3, 0, 6, 1, 4};
MFParamsBuilder params(fn, ranges.size());
params.add_readonly_single_input(sizes.as_span());
@@ -172,34 +116,6 @@ TEST(multi_function, CreateRangeFunction)
EXPECT_EQ(ranges_ref[2][1], 1);
}
-class GenericAppendFunction : public MultiFunction {
- private:
- MFSignature signature_;
-
- public:
- GenericAppendFunction(const CPPType &type)
- {
- MFSignatureBuilder signature{"Append"};
- signature.vector_mutable("Vector", type);
- signature.single_input("Value", type);
- signature_ = signature.build();
- this->set_signature(&signature_);
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- GVectorArray &vectors = params.vector_mutable(0, "Vector");
- const GVArray &values = params.readonly_single_input(1, "Value");
-
- for (int64_t i : mask) {
- BUFFER_FOR_CPP_TYPE_VALUE(values.type(), buffer);
- values.get(i, buffer);
- vectors.append(i, buffer);
- values.type().destruct(buffer);
- }
- }
-};
-
TEST(multi_function, GenericAppendFunction)
{
GenericAppendFunction fn(CPPType::get<int32_t>());
diff --git a/source/blender/functions/tests/FN_multi_function_test_common.hh b/source/blender/functions/tests/FN_multi_function_test_common.hh
new file mode 100644
index 00000000000..51c8fac8a96
--- /dev/null
+++ b/source/blender/functions/tests/FN_multi_function_test_common.hh
@@ -0,0 +1,174 @@
+/* Apache License, Version 2.0 */
+
+#include "FN_multi_function.hh"
+
+namespace blender::fn::tests {
+
+class AddPrefixFunction : public MultiFunction {
+ public:
+ AddPrefixFunction()
+ {
+ static MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static MFSignature create_signature()
+ {
+ MFSignatureBuilder signature{"Add Prefix"};
+ signature.single_input<std::string>("Prefix");
+ signature.single_mutable<std::string>("Strings");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ const VArray<std::string> &prefixes = params.readonly_single_input<std::string>(0, "Prefix");
+ MutableSpan<std::string> strings = params.single_mutable<std::string>(1, "Strings");
+
+ for (int64_t i : mask) {
+ strings[i] = prefixes[i] + strings[i];
+ }
+ }
+};
+
+class CreateRangeFunction : public MultiFunction {
+ public:
+ CreateRangeFunction()
+ {
+ static MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static MFSignature create_signature()
+ {
+ MFSignatureBuilder signature{"Create Range"};
+ signature.single_input<int>("Size");
+ signature.vector_output<int>("Range");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ const VArray<int> &sizes = params.readonly_single_input<int>(0, "Size");
+ GVectorArray &ranges = params.vector_output(1, "Range");
+
+ for (int64_t i : mask) {
+ int size = sizes[i];
+ for (int j : IndexRange(size)) {
+ ranges.append(i, &j);
+ }
+ }
+ }
+};
+
+class GenericAppendFunction : public MultiFunction {
+ private:
+ MFSignature signature_;
+
+ public:
+ GenericAppendFunction(const CPPType &type)
+ {
+ MFSignatureBuilder signature{"Append"};
+ signature.vector_mutable("Vector", type);
+ signature.single_input("Value", type);
+ signature_ = signature.build();
+ this->set_signature(&signature_);
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ GVectorArray &vectors = params.vector_mutable(0, "Vector");
+ const GVArray &values = params.readonly_single_input(1, "Value");
+
+ for (int64_t i : mask) {
+ BUFFER_FOR_CPP_TYPE_VALUE(values.type(), buffer);
+ values.get(i, buffer);
+ vectors.append(i, buffer);
+ values.type().destruct(buffer);
+ }
+ }
+};
+
+class ConcatVectorsFunction : public MultiFunction {
+ public:
+ ConcatVectorsFunction()
+ {
+ static MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static MFSignature create_signature()
+ {
+ MFSignatureBuilder signature{"Concat Vectors"};
+ signature.vector_mutable<int>("A");
+ signature.vector_input<int>("B");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ GVectorArray &a = params.vector_mutable(0);
+ const GVVectorArray &b = params.readonly_vector_input(1);
+ a.extend(mask, b);
+ }
+};
+
+class AppendFunction : public MultiFunction {
+ public:
+ AppendFunction()
+ {
+ static MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static MFSignature create_signature()
+ {
+ MFSignatureBuilder signature{"Append"};
+ signature.vector_mutable<int>("Vector");
+ signature.single_input<int>("Value");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ GVectorArray_TypedMutableRef<int> vectors = params.vector_mutable<int>(0);
+ const VArray<int> &values = params.readonly_single_input<int>(1);
+
+ for (int64_t i : mask) {
+ vectors.append(i, values[i]);
+ }
+ }
+};
+
+class SumVectorFunction : public MultiFunction {
+ public:
+ SumVectorFunction()
+ {
+ static MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static MFSignature create_signature()
+ {
+ MFSignatureBuilder signature{"Sum Vectors"};
+ signature.vector_input<int>("Vector");
+ signature.single_output<int>("Sum");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ const VVectorArray<int> &vectors = params.readonly_vector_input<int>(0);
+ MutableSpan<int> sums = params.uninitialized_single_output<int>(1);
+
+ for (int64_t i : mask) {
+ int sum = 0;
+ for (int j : IndexRange(vectors.get_vector_size(i))) {
+ sum += vectors.get_vector_element(i, j);
+ }
+ sums[i] = sum;
+ }
+ }
+};
+
+} // namespace blender::fn::tests
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 9ac07b9632d..4b71011b99a 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -208,7 +208,7 @@ typedef struct LineartChainRegisterEntry {
enum eLineArtTileRecursiveLimit {
/* If tile gets this small, it's already much smaller than a pixel. No need to continue
* splitting. */
- LRT_TILE_RECURSIVE_PERSPECTIVE = 30,
+ LRT_TILE_RECURSIVE_PERSPECTIVE = 16,
/* This is a tried-and-true safe value for high poly models that also needed ortho rendering. */
LRT_TILE_RECURSIVE_ORTHO = 10,
};
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index f02b73e8430..99e3d59a57f 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -41,6 +41,7 @@
#include "BKE_gpencil.h"
#include "BKE_gpencil_geom.h"
#include "BKE_gpencil_modifier.h"
+#include "BKE_lib_id.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
@@ -1691,8 +1692,7 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu
}
if (obi->free_use_mesh) {
- BKE_mesh_free(obi->original_me);
- MEM_freeN(obi->original_me);
+ BKE_id_free(NULL, &obi->original_me);
}
if (rb->remove_doubles) {
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 6482d9a9d3e..bf0ab3dc533 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -223,7 +223,7 @@ uint GPU_framebuffer_stack_level_get(void);
*/
GPUOffScreen *GPU_offscreen_create(
- int width, int height, bool depth, bool high_bitdepth, char err_out[256]);
+ int width, int height, bool depth, eGPUTextureFormat format, char err_out[256]);
void GPU_offscreen_free(GPUOffScreen *ofs);
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index e073263f352..edf16f04349 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -131,15 +131,11 @@ void GPU_matrix_project_2fv(const float world[3],
float r_win[2]);
bool GPU_matrix_unproject_3fv(const float win[3],
- const float model[4][4],
+ const float model_inverted[4][4],
const float proj[4][4],
const int view[4],
float r_world[3]);
-void GPU_matrix_unproject_3fv_with_precalc(const struct GPUMatrixUnproject_Precalc *unproj_precalc,
- const float win[3],
- float r_world[3]);
-
/* 2D Projection Matrix */
void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top);
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index f980c8fdcd7..9a1885160b6 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -187,25 +187,30 @@ unsigned int GPU_texture_memory_usage_get(void);
* \a mips is the number of mip level to allocate. It must be >= 1.
*/
GPUTexture *GPU_texture_create_1d(
- const char *name, int w, int mips, eGPUTextureFormat format, const float *data);
+ const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data);
GPUTexture *GPU_texture_create_1d_array(
- const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data);
+ const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data);
GPUTexture *GPU_texture_create_2d(
- const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data);
-GPUTexture *GPU_texture_create_2d_array(
- const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data);
+ const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data);
+GPUTexture *GPU_texture_create_2d_array(const char *name,
+ int w,
+ int h,
+ int d,
+ int mip_len,
+ eGPUTextureFormat format,
+ const float *data);
GPUTexture *GPU_texture_create_3d(const char *name,
int w,
int h,
int d,
- int mips,
+ int mip_len,
eGPUTextureFormat texture_format,
eGPUDataFormat data_format,
const void *data);
GPUTexture *GPU_texture_create_cube(
- const char *name, int w, int mips, eGPUTextureFormat format, const float *data);
+ const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data);
GPUTexture *GPU_texture_create_cube_array(
- const char *name, int w, int d, int mips, eGPUTextureFormat format, const float *data);
+ const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data);
/* Special textures. */
GPUTexture *GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert);
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index a6f7d43e563..9099a6e4245 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -591,7 +591,7 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs)
}
GPUOffScreen *GPU_offscreen_create(
- int width, int height, bool depth, bool high_bitdepth, char err_out[256])
+ int width, int height, bool depth, eGPUTextureFormat format, char err_out[256])
{
GPUOffScreen *ofs = (GPUOffScreen *)MEM_callocN(sizeof(GPUOffScreen), __func__);
@@ -600,8 +600,7 @@ GPUOffScreen *GPU_offscreen_create(
height = max_ii(1, height);
width = max_ii(1, width);
- ofs->color = GPU_texture_create_2d(
- "ofs_color", width, height, 1, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, nullptr);
+ ofs->color = GPU_texture_create_2d("ofs_color", width, height, 1, format, nullptr);
if (depth) {
ofs->depth = GPU_texture_create_2d(
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 37089785e0e..56e72fbeca9 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -758,6 +758,7 @@ GPUMaterial *GPU_material_from_nodetree(Scene *scene,
/* Only free after GPU_pass_shader_get where GPUUniformBuf
* read data from the local tree. */
ntreeFreeLocalTree(localtree);
+ BLI_assert(!localtree->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(localtree);
/* note that even if building the shader fails in some way, we still keep
diff --git a/source/blender/gpu/intern/gpu_matrix.cc b/source/blender/gpu/intern/gpu_matrix.cc
index efa04568401..bbcc241f5e3 100644
--- a/source/blender/gpu/intern/gpu_matrix.cc
+++ b/source/blender/gpu/intern/gpu_matrix.cc
@@ -513,93 +513,55 @@ void GPU_matrix_project_2fv(const float world[3],
win[1] = view[1] + (view[3] * (v[1] + 1)) * 0.5f;
}
-/**
- * The same result could be obtained as follows:
- *
- * \code{.c}
- * float projinv[4][4];
- * invert_m4_m4(projinv, projmat);
- * co[0] = 2 * co[0] - 1;
- * co[1] = 2 * co[1] - 1;
- * co[2] = 2 * co[2] - 1;
- * mul_project_m4_v3(projinv, co);
- * \endcode
- *
- * But that solution loses much precision.
- * Therefore, get the same result without inverting the matrix.
- */
-static void gpu_mul_invert_projmat_m4_unmapped_v3_with_precalc(
- const struct GPUMatrixUnproject_Precalc *precalc, float co[3])
-{
- /* 'precalc->dims' is the result of 'projmat_dimensions(proj, ...)'. */
- co[0] = (float)scalenormd(precalc->dims.xmin, precalc->dims.xmax, co[0]);
- co[1] = (float)scalenormd(precalc->dims.ymin, precalc->dims.ymax, co[1]);
-
- if (precalc->is_persp) {
- co[2] = (precalc->dims.zmax * precalc->dims.zmin) /
- (precalc->dims.zmax + co[2] * (precalc->dims.zmin - precalc->dims.zmax));
- co[0] *= co[2] / precalc->dims.zmin;
- co[1] *= co[2] / precalc->dims.zmin;
- }
- else {
- co[2] = (float)scalenormd(precalc->dims.zmin, precalc->dims.zmax, co[2]);
- }
- co[2] *= -1;
-}
-
-bool GPU_matrix_unproject_precalc(struct GPUMatrixUnproject_Precalc *precalc,
- const float model[4][4],
- const float proj[4][4],
- const int view[4])
-{
- precalc->is_persp = proj[3][3] == 0.0f;
- projmat_dimensions_db(proj,
- &precalc->dims.xmin,
- &precalc->dims.xmax,
- &precalc->dims.ymin,
- &precalc->dims.ymax,
- &precalc->dims.zmin,
- &precalc->dims.zmax);
- if (isinf(precalc->dims.zmax)) {
- /* We cannot retrieve the actual value of the clip_end.
- * Use `FLT_MAX` to avoid NAN's. */
- precalc->dims.zmax = FLT_MAX;
- }
- for (int i = 0; i < 4; i++) {
- precalc->view[i] = (float)view[i];
- }
- if (!invert_m4_m4(precalc->model_inverted, model)) {
- unit_m4(precalc->model_inverted);
- return false;
- }
- return true;
-}
-
-void GPU_matrix_unproject_3fv_with_precalc(const struct GPUMatrixUnproject_Precalc *precalc,
- const float win[3],
- float r_world[3])
-{
- float in[3] = {
- (win[0] - precalc->view[0]) / precalc->view[2],
- (win[1] - precalc->view[1]) / precalc->view[3],
- win[2],
- };
- gpu_mul_invert_projmat_m4_unmapped_v3_with_precalc(precalc, in);
- mul_v3_m4v3(r_world, precalc->model_inverted, in);
-}
-
bool GPU_matrix_unproject_3fv(const float win[3],
- const float model[4][4],
+ const float model_inverted[4][4],
const float proj[4][4],
const int view[4],
float r_world[3])
{
- struct GPUMatrixUnproject_Precalc precalc;
- if (!GPU_matrix_unproject_precalc(&precalc, model, proj, view)) {
- zero_v3(r_world);
+ zero_v3(r_world);
+ float in[3] = {
+ 2 * ((win[0] - view[0]) / view[2]) - 1.0f,
+ 2 * ((win[1] - view[1]) / view[3]) - 1.0f,
+ 2 * win[2] - 1.0f,
+ };
+
+ /**
+ * The same result could be obtained as follows:
+ *
+ * \code{.c}
+ * float projinv[4][4];
+ * invert_m4_m4(projinv, projview);
+ * copy_v3_v3(r_world, in);
+ * mul_project_m4_v3(projinv, r_world);
+ * \endcode
+ *
+ * But that solution loses much precision.
+ * Therefore, get the same result without inverting the project view matrix.
+ */
+
+ float out[3];
+ const bool is_persp = proj[3][3] == 0.0f;
+ if (is_persp) {
+ out[2] = proj[3][2] / (proj[2][2] + in[2]);
+ if (isinf(out[2])) {
+ out[2] = FLT_MAX;
+ }
+ out[0] = out[2] * ((proj[2][0] + in[0]) / proj[0][0]);
+ out[1] = out[2] * ((proj[2][1] + in[1]) / proj[1][1]);
+ out[2] *= -1;
+ }
+ else {
+ out[0] = (-proj[3][0] + in[0]) / proj[0][0];
+ out[1] = (-proj[3][1] + in[1]) / proj[1][1];
+ out[2] = (-proj[3][2] + in[2]) / proj[2][2];
+ }
+
+ if (!is_finite_v3(out)) {
return false;
}
- GPU_matrix_unproject_3fv_with_precalc(&precalc, win, r_world);
+
+ mul_v3_m4v3(r_world, model_inverted, out);
return true;
}
diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc
index 6564cbda694..d5d13ea269f 100644
--- a/source/blender/gpu/intern/gpu_texture.cc
+++ b/source/blender/gpu/intern/gpu_texture.cc
@@ -241,55 +241,61 @@ static inline GPUTexture *gpu_texture_create(const char *name,
}
GPUTexture *GPU_texture_create_1d(
- const char *name, int w, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
{
- return gpu_texture_create(name, w, 0, 0, GPU_TEXTURE_1D, mips, format, GPU_DATA_FLOAT, data);
+ return gpu_texture_create(name, w, 0, 0, GPU_TEXTURE_1D, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_1d_array(
- const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
{
return gpu_texture_create(
- name, w, h, 0, GPU_TEXTURE_1D_ARRAY, mips, format, GPU_DATA_FLOAT, data);
+ name, w, h, 0, GPU_TEXTURE_1D_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_2d(
- const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
{
- return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_2D, mips, format, GPU_DATA_FLOAT, data);
+ return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_2D, mip_len, format, GPU_DATA_FLOAT, data);
}
-GPUTexture *GPU_texture_create_2d_array(
- const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data)
+GPUTexture *GPU_texture_create_2d_array(const char *name,
+ int w,
+ int h,
+ int d,
+ int mip_len,
+ eGPUTextureFormat format,
+ const float *data)
{
return gpu_texture_create(
- name, w, h, d, GPU_TEXTURE_2D_ARRAY, mips, format, GPU_DATA_FLOAT, data);
+ name, w, h, d, GPU_TEXTURE_2D_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_3d(const char *name,
int w,
int h,
int d,
- int mips,
+ int mip_len,
eGPUTextureFormat texture_format,
eGPUDataFormat data_format,
const void *data)
{
return gpu_texture_create(
- name, w, h, d, GPU_TEXTURE_3D, mips, texture_format, data_format, data);
+ name, w, h, d, GPU_TEXTURE_3D, mip_len, texture_format, data_format, data);
}
GPUTexture *GPU_texture_create_cube(
- const char *name, int w, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
{
- return gpu_texture_create(name, w, w, 0, GPU_TEXTURE_CUBE, mips, format, GPU_DATA_FLOAT, data);
+ return gpu_texture_create(
+ name, w, w, 0, GPU_TEXTURE_CUBE, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_cube_array(
- const char *name, int w, int d, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
{
return gpu_texture_create(
- name, w, w, d, GPU_TEXTURE_CUBE_ARRAY, mips, format, GPU_DATA_FLOAT, data);
+ name, w, w, d, GPU_TEXTURE_CUBE_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
}
/* DDS texture loading. Return NULL if support is not available. */
diff --git a/source/blender/gpu/tests/gpu_shader_test.cc b/source/blender/gpu/tests/gpu_shader_test.cc
index 43ff86ebbd8..dbe336af097 100644
--- a/source/blender/gpu/tests/gpu_shader_test.cc
+++ b/source/blender/gpu/tests/gpu_shader_test.cc
@@ -108,7 +108,8 @@ void main() {
EXPECT_NE(shader, nullptr);
/* Construct Texture. */
- GPUTexture *texture = GPU_texture_create_1d("gpu_shader_compute_1d", SIZE, 0, GPU_RGBA32F, NULL);
+ GPUTexture *texture = GPU_texture_create_1d(
+ "gpu_shader_compute_1d", SIZE, 0, GPU_RGBA32F, nullptr);
EXPECT_NE(texture, nullptr);
GPU_shader_bind(shader);
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index d527aca184c..4ad7aa98484 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -367,6 +367,11 @@ void IMB_anim_index_rebuild_finish(struct IndexBuildContext *context, short stop
int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc);
/**
+ * Return the encoded start offset (in seconds) of the given \a anim.
+ */
+double IMD_anim_get_offset(struct anim *anim);
+
+/**
* Return the fps contained in movie files (function rval is false,
* and frs_sec and frs_sec_base untouched if none available!)
*/
diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h
index cfeffcca0ea..c4e2ad9da7f 100644
--- a/source/blender/imbuf/intern/IMB_anim.h
+++ b/source/blender/imbuf/intern/IMB_anim.h
@@ -91,6 +91,7 @@ struct anim {
int duration_in_frames;
int frs_sec;
double frs_sec_base;
+ double start_offset;
int x, y;
/* for number */
diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 47514308ae4..dbca16ca82b 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -425,6 +425,7 @@ static int startavi(struct anim *anim)
}
anim->duration_in_frames = anim->avi->header->TotalFrames;
+ anim->start_offset = 0.0f;
anim->params = NULL;
anim->x = anim->avi->header->Width;
@@ -597,6 +598,13 @@ static int startffmpeg(struct anim *anim)
return -1;
}
+ double video_start = 0;
+ double pts_time_base = av_q2d(video_stream->time_base);
+
+ if (video_stream->start_time != AV_NOPTS_VALUE) {
+ video_start = video_stream->start_time * pts_time_base;
+ }
+
frame_rate = av_guess_frame_rate(pFormatCtx, video_stream, NULL);
anim->duration_in_frames = 0;
@@ -616,10 +624,49 @@ static int startffmpeg(struct anim *anim)
}
}
}
- /* Fall back to the container. */
+ /* Fall back to manually estimating the video stream duration.
+ * This is because the video stream duration can be shorter than the pFormatCtx->duration.
+ */
if (anim->duration_in_frames == 0) {
- anim->duration_in_frames = (int)(pFormatCtx->duration * av_q2d(frame_rate) / AV_TIME_BASE +
- 0.5f);
+ double stream_dur;
+
+ if (video_stream->duration != AV_NOPTS_VALUE) {
+ stream_dur = video_stream->duration * pts_time_base;
+ }
+ else {
+ double audio_start = 0;
+
+ /* Find audio stream to guess the duration of the video.
+ * Sometimes the audio AND the video stream have a start offset.
+ * The difference between these is the offset we want to use to
+ * calculate the video duration.
+ */
+ for (i = 0; i < pFormatCtx->nb_streams; i++) {
+ if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ AVStream *audio_stream = pFormatCtx->streams[i];
+ if (audio_stream->start_time != AV_NOPTS_VALUE) {
+ audio_start = audio_stream->start_time * av_q2d(audio_stream->time_base);
+ }
+ break;
+ }
+ }
+
+ if (video_start > audio_start) {
+ stream_dur = (double)pFormatCtx->duration / AV_TIME_BASE - (video_start - audio_start);
+ }
+ else {
+ /* The video stream starts before or at the same time as the audio stream!
+ * We have to assume that the video stream is as long as the full pFormatCtx->duration.
+ */
+ stream_dur = (double)pFormatCtx->duration / AV_TIME_BASE;
+ }
+ }
+ anim->duration_in_frames = (int)(stream_dur * av_q2d(frame_rate) + 0.5f);
+ }
+
+ double ctx_start = 0;
+ if (pFormatCtx->start_time != AV_NOPTS_VALUE) {
+ ctx_start = (double)pFormatCtx->start_time / AV_TIME_BASE;
}
frs_num = frame_rate.num;
@@ -634,6 +681,9 @@ static int startffmpeg(struct anim *anim)
anim->frs_sec = frs_num;
anim->frs_sec_base = frs_den;
+ /* Save the relative start time for the video. IE the start time in relation to where playback
+ * starts. */
+ anim->start_offset = video_start - ctx_start;
anim->params = 0;
@@ -1019,33 +1069,21 @@ static int ffmpeg_seek_by_byte(AVFormatContext *pFormatCtx)
return false;
}
-static int64_t ffmpeg_get_seek_pos(struct anim *anim, int position)
+static int64_t ffmpeg_get_seek_pts(struct anim *anim, int64_t pts_to_search)
{
AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream];
- double frame_rate = av_q2d(av_guess_frame_rate(anim->pFormatCtx, v_st, NULL));
- int64_t st_time = anim->pFormatCtx->start_time;
- int64_t pos = (int64_t)(position)*AV_TIME_BASE;
- /* Step back half a time base position to make sure that we get the requested
- * frame and not the one after it.
+ AVRational frame_rate = v_st->r_frame_rate;
+ AVRational time_base = v_st->time_base;
+ double steps_per_frame = (double)(frame_rate.den * time_base.den) /
+ (double)(frame_rate.num * time_base.num);
+ /* Step back half a frame position to make sure that we get the requested
+ * frame and not the one after it. This is a workaround as ffmpeg will
+ * sometimes not seek to a frame after the requested pts even if
+ * AVSEEK_FLAG_BACKWARD is specified.
*/
- pos -= (AV_TIME_BASE / 2);
- pos /= frame_rate;
-
- av_log(anim->pFormatCtx,
- AV_LOG_DEBUG,
- "NO INDEX seek pos = %" PRId64 ", st_time = %" PRId64 "\n",
- pos,
- (st_time != AV_NOPTS_VALUE) ? st_time : 0);
-
- if (pos < 0) {
- pos = 0;
- }
-
- if (st_time != AV_NOPTS_VALUE) {
- pos += st_time;
- }
+ int64_t pts = pts_to_search - (steps_per_frame / 2);
- return pos;
+ return pts;
}
/* This gives us an estimate of which pts our requested frame will have.
@@ -1062,17 +1100,18 @@ static int64_t ffmpeg_get_pts_to_search(struct anim *anim,
pts_to_search = IMB_indexer_get_pts(tc_index, new_frame_index);
}
else {
- int64_t st_time = anim->pFormatCtx->start_time;
AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream];
- AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, NULL);
+ int64_t start_pts = v_st->start_time;
+ AVRational frame_rate = v_st->r_frame_rate;
AVRational time_base = v_st->time_base;
- int64_t steps_per_frame = (frame_rate.den * time_base.den) / (frame_rate.num * time_base.num);
- pts_to_search = position * steps_per_frame;
+ double steps_per_frame = (double)(frame_rate.den * time_base.den) /
+ (double)(frame_rate.num * time_base.num);
- if (st_time != AV_NOPTS_VALUE && st_time != 0) {
- int64_t start_frame = (double)st_time / AV_TIME_BASE * av_q2d(frame_rate);
- pts_to_search += start_frame * steps_per_frame;
+ pts_to_search = round(position * steps_per_frame);
+
+ if (start_pts != AV_NOPTS_VALUE) {
+ pts_to_search += start_pts;
}
}
return pts_to_search;
@@ -1156,23 +1195,29 @@ static void ffmpeg_decode_video_frame_scan(struct anim *anim, int64_t pts_to_sea
* decoded will be read. See https://trac.ffmpeg.org/ticket/1607 and
* https://developer.blender.org/T86944. */
static int ffmpeg_generic_seek_workaround(struct anim *anim,
- int64_t *requested_pos,
+ int64_t *requested_pts,
int64_t pts_to_search)
{
AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream];
- double frame_rate = av_q2d(av_guess_frame_rate(anim->pFormatCtx, v_st, NULL));
- int64_t current_pos = *requested_pos;
+ AVRational frame_rate = v_st->r_frame_rate;
+ AVRational time_base = v_st->time_base;
+
+ double steps_per_frame = (double)(frame_rate.den * time_base.den) /
+ (double)(frame_rate.num * time_base.num);
+
+ int64_t current_pts = *requested_pts;
int64_t offset = 0;
int64_t cur_pts, prev_pts = -1;
/* Step backward frame by frame until we find the key frame we are looking for. */
- while (current_pos != 0) {
- current_pos = *requested_pos - ((int64_t)(offset)*AV_TIME_BASE / frame_rate);
- current_pos = max_ii(current_pos, 0);
+ while (current_pts != 0) {
+ current_pts = *requested_pts - (int64_t)round(offset * steps_per_frame);
+ current_pts = MAX2(current_pts, 0);
/* Seek to timestamp. */
- if (av_seek_frame(anim->pFormatCtx, -1, current_pos, AVSEEK_FLAG_BACKWARD) < 0) {
+ if (av_seek_frame(anim->pFormatCtx, anim->videoStream, current_pts, AVSEEK_FLAG_BACKWARD) <
+ 0) {
break;
}
@@ -1198,21 +1243,22 @@ static int ffmpeg_generic_seek_workaround(struct anim *anim,
/* We found the I-frame we were looking for! */
break;
}
- if (cur_pts == prev_pts) {
- /* We got the same key frame packet twice.
- * This probably means that we have hit the beginning of the stream. */
- break;
- }
+ }
+
+ if (cur_pts == prev_pts) {
+ /* We got the same key frame packet twice.
+ * This probably means that we have hit the beginning of the stream. */
+ break;
}
prev_pts = cur_pts;
offset++;
}
- *requested_pos = current_pos;
+ *requested_pts = current_pts;
/* Re-seek to timestamp that gave I-frame, so it can be read by decode function. */
- return av_seek_frame(anim->pFormatCtx, -1, current_pos, AVSEEK_FLAG_BACKWARD);
+ return av_seek_frame(anim->pFormatCtx, anim->videoStream, current_pts, AVSEEK_FLAG_BACKWARD);
}
/* Seek to last necessary key frame. */
@@ -1260,13 +1306,13 @@ static int ffmpeg_seek_to_key_frame(struct anim *anim,
else {
/* We have to manually seek with ffmpeg to get to the key frame we want to start decoding from.
*/
- pos = ffmpeg_get_seek_pos(anim, position);
+ pos = ffmpeg_get_seek_pts(anim, pts_to_search);
av_log(anim->pFormatCtx, AV_LOG_DEBUG, "NO INDEX final seek pos = %" PRId64 "\n", pos);
AVFormatContext *format_ctx = anim->pFormatCtx;
if (format_ctx->iformat->read_seek2 || format_ctx->iformat->read_seek) {
- ret = av_seek_frame(anim->pFormatCtx, -1, pos, AVSEEK_FLAG_BACKWARD);
+ ret = av_seek_frame(anim->pFormatCtx, anim->videoStream, pos, AVSEEK_FLAG_BACKWARD);
}
else {
ret = ffmpeg_generic_seek_workaround(anim, &pos, pts_to_search);
@@ -1311,7 +1357,7 @@ static int ffmpeg_seek_to_key_frame(struct anim *anim,
anim->cur_key_frame_pts = gop_pts;
/* Seek back so we are at the correct position after we decoded a frame. */
- av_seek_frame(anim->pFormatCtx, -1, pos, AVSEEK_FLAG_BACKWARD);
+ av_seek_frame(anim->pFormatCtx, anim->videoStream, pos, AVSEEK_FLAG_BACKWARD);
}
}
@@ -1351,18 +1397,18 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
struct anim_index *tc_index = IMB_anim_open_index(anim, tc);
int64_t pts_to_search = ffmpeg_get_pts_to_search(anim, tc_index, position);
AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream];
- double frame_rate = av_q2d(av_guess_frame_rate(anim->pFormatCtx, v_st, NULL));
+ double frame_rate = av_q2d(v_st->r_frame_rate);
double pts_time_base = av_q2d(v_st->time_base);
- int64_t st_time = anim->pFormatCtx->start_time;
+ int64_t start_pts = v_st->start_time;
av_log(anim->pFormatCtx,
AV_LOG_DEBUG,
- "FETCH: looking for PTS=%" PRId64 " (pts_timebase=%g, frame_rate=%g, st_time=%" PRId64
+ "FETCH: looking for PTS=%" PRId64 " (pts_timebase=%g, frame_rate=%g, start_pts=%" PRId64
")\n",
(int64_t)pts_to_search,
pts_time_base,
frame_rate,
- st_time);
+ start_pts);
if (ffmpeg_pts_matches_last_frame(anim, pts_to_search)) {
av_log(anim->pFormatCtx,
@@ -1637,6 +1683,11 @@ int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc)
return IMB_indexer_get_duration(idx);
}
+double IMD_anim_get_offset(struct anim *anim)
+{
+ return anim->start_offset;
+}
+
bool IMB_anim_get_fps(struct anim *anim, short *frs_sec, float *frs_sec_base, bool no_av_base)
{
double frs_sec_base_double;
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index 27195b294d6..bbb0f3b5b22 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -1022,7 +1022,7 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
stream_size = avio_size(context->iFormatCtx->pb);
- context->frame_rate = av_q2d(av_guess_frame_rate(context->iFormatCtx, context->iStream, NULL));
+ context->frame_rate = av_q2d(context->iStream->r_frame_rate);
context->pts_time_base = av_q2d(context->iStream->time_base);
while (av_read_frame(context->iFormatCtx, next_packet) >= 0) {
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index a465c6b92bc..cd323e72003 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -1711,7 +1711,7 @@ static const char *exr_rgba_channelname(MultiPartInputFile &file, const char *ch
const ChannelList &channels = file.header(0).channels();
for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i) {
- /* const Channel &channel = i.channel(); */ /* Not used yet */
+ // const Channel &channel = i.channel(); /* Not used yet. */
const char *str = i.name();
int len = strlen(str);
if (len) {
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index 0dbebb1e4c4..0a3a43bb21f 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -97,6 +97,7 @@ bool ABC_import(struct bContext *C,
int sequence_len,
int offset,
bool validate_meshes,
+ bool always_add_cache_reader,
bool as_background_job);
struct CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
diff --git a/source/blender/io/alembic/intern/abc_reader_curves.cc b/source/blender/io/alembic/intern/abc_reader_curves.cc
index 8d6605d6973..27ee35d1b39 100644
--- a/source/blender/io/alembic/intern/abc_reader_curves.cc
+++ b/source/blender/io/alembic/intern/abc_reader_curves.cc
@@ -112,7 +112,7 @@ void AbcCurveReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSele
read_curve_sample(cu, m_curves_schema, sample_sel);
- if (has_animations(m_curves_schema, m_settings)) {
+ if (m_settings->always_add_cache_reader || has_animations(m_curves_schema, m_settings)) {
addCacheModifier();
}
}
diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc
index c05df7f1ff5..77edd4908bd 100644
--- a/source/blender/io/alembic/intern/abc_reader_mesh.cc
+++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc
@@ -578,7 +578,7 @@ void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
readFaceSetsSample(bmain, mesh, sample_sel);
- if (has_animations(m_schema, m_settings)) {
+ if (m_settings->always_add_cache_reader || has_animations(m_schema, m_settings)) {
addCacheModifier();
}
}
@@ -928,7 +928,7 @@ void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
BKE_mesh_validate(mesh, false, false);
}
- if (has_animations(m_schema, m_settings)) {
+ if (m_settings->always_add_cache_reader || has_animations(m_schema, m_settings)) {
addCacheModifier();
}
}
diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc
index 00b73d29c5c..9a5ffd04bd1 100644
--- a/source/blender/io/alembic/intern/abc_reader_object.cc
+++ b/source/blender/io/alembic/intern/abc_reader_object.cc
@@ -1,4 +1,4 @@
-/*
+/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -197,7 +197,7 @@ void AbcObjectReader::setupObjectTransform(const float time)
BKE_object_apply_mat4(m_object, transform_from_alembic, true, false);
BKE_object_to_mat4(m_object, m_object->obmat);
- if (!is_constant) {
+ if (!is_constant || m_settings->always_add_cache_reader) {
bConstraint *con = BKE_constraint_add_for_object(
m_object, nullptr, CONSTRAINT_TYPE_TRANSFORM_CACHE);
bTransformCacheConstraint *data = static_cast<bTransformCacheConstraint *>(con->data);
diff --git a/source/blender/io/alembic/intern/abc_reader_object.h b/source/blender/io/alembic/intern/abc_reader_object.h
index dacdcf3f722..89590b26b61 100644
--- a/source/blender/io/alembic/intern/abc_reader_object.h
+++ b/source/blender/io/alembic/intern/abc_reader_object.h
@@ -51,6 +51,7 @@ struct ImportSettings {
int read_flag;
bool validate_meshes;
+ bool always_add_cache_reader;
CacheFile *cache_file;
@@ -65,6 +66,7 @@ struct ImportSettings {
sequence_offset(0),
read_flag(0),
validate_meshes(false),
+ always_add_cache_reader(false),
cache_file(NULL)
{
}
diff --git a/source/blender/io/alembic/intern/abc_reader_points.cc b/source/blender/io/alembic/intern/abc_reader_points.cc
index f7dcba7a0de..3aeacbd14fe 100644
--- a/source/blender/io/alembic/intern/abc_reader_points.cc
+++ b/source/blender/io/alembic/intern/abc_reader_points.cc
@@ -95,7 +95,7 @@ void AbcPointsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSel
m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str());
m_object->data = mesh;
- if (has_animations(m_schema, m_settings)) {
+ if (m_settings->always_add_cache_reader || has_animations(m_schema, m_settings)) {
addCacheModifier();
}
}
diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc
index b94b75b2216..deb945b767c 100644
--- a/source/blender/io/alembic/intern/alembic_capi.cc
+++ b/source/blender/io/alembic/intern/alembic_capi.cc
@@ -663,6 +663,7 @@ bool ABC_import(bContext *C,
int sequence_len,
int offset,
bool validate_meshes,
+ bool always_add_cache_reader,
bool as_background_job)
{
/* Using new here since MEM_* functions do not call constructor to properly initialize data. */
@@ -681,6 +682,7 @@ bool ABC_import(bContext *C,
job->settings.sequence_len = sequence_len;
job->settings.sequence_offset = offset;
job->settings.validate_meshes = validate_meshes;
+ job->settings.always_add_cache_reader = always_add_cache_reader;
job->error_code = ABC_NO_ERROR;
job->was_cancelled = false;
job->archive = nullptr;
diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp
index e52bdca0d87..e54192abc54 100644
--- a/source/blender/io/collada/AnimationImporter.cpp
+++ b/source/blender/io/collada/AnimationImporter.cpp
@@ -1363,7 +1363,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob,
calc_joint_parent_mat_rest(par, nullptr, root, node);
mul_m4_m4m4(temp, par, matfra);
- /* evaluate_joint_world_transform_at_frame(temp, NULL, node, fra); */
+ // evaluate_joint_world_transform_at_frame(temp, NULL, node, fra);
/* calc special matrix */
mul_m4_series(mat, irest, temp, irest_dae, rest);
diff --git a/source/blender/io/collada/collada_internal.cpp b/source/blender/io/collada/collada_internal.cpp
index 355aa5c22f0..bd6f496c8ec 100644
--- a/source/blender/io/collada/collada_internal.cpp
+++ b/source/blender/io/collada/collada_internal.cpp
@@ -162,7 +162,7 @@ void UnitConverter::calculate_scale(Scene &sce)
* Translation map.
* Used to translate every COLLADA id to a valid id, no matter what "wrong" letters may be
* included. Look at the IDREF XSD declaration for more.
- * Follows strictly the COLLADA XSD declaration which explicitly allows non-english chars,
+ * Follows strictly the COLLADA XSD declaration which explicitly allows non-English chars,
* like special chars (e.g. micro sign), umlauts and so on.
* The COLLADA spec also allows additional chars for member access ('.'), these
* must obviously be removed too, otherwise they would be heavily misinterpreted.
diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc
index 25f12e683cf..efa31df25c1 100644
--- a/source/blender/io/usd/intern/usd_capi_export.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@ -102,7 +102,7 @@ static void export_startjob(void *customdata,
usd_stage->SetMetadata(pxr::UsdGeomTokens->upAxis, pxr::VtValue(pxr::UsdGeomTokens->z));
usd_stage->SetMetadata(pxr::UsdGeomTokens->metersPerUnit,
- pxr::VtValue(scene->unit.scale_length));
+ static_cast<double>(scene->unit.scale_length));
usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") +
BKE_blender_version_string());
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index beaad31e228..5b7c99f2545 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -605,7 +605,7 @@ enum {
/* tag data-block as having actually increased user-count for the extra virtual user. */
LIB_TAG_EXTRAUSER_SET = 1 << 7,
- /* RESET_AFTER_USE tag newly duplicated/copied IDs.
+ /* RESET_AFTER_USE tag newly duplicated/copied IDs (see #ID_NEW_SET macro above).
* Also used internally in readfile.c to mark data-blocks needing do_versions. */
LIB_TAG_NEW = 1 << 8,
/* RESET_BEFORE_USE free test flag.
@@ -617,13 +617,32 @@ enum {
/**
* The data-block is a copy-on-write/localized version.
*
+ * RESET_NEVER
+ *
* \warning This should not be cleared on existing data.
* If support for this is needed, see T88026 as this flag controls memory ownership
* of physics *shared* pointers.
*/
LIB_TAG_COPIED_ON_WRITE = 1 << 12,
-
+ /**
+ * The data-block is not the original COW ID created by the depsgraph, but has be re-allocated
+ * during the evaluation process of another ID.
+ *
+ * RESET_NEVER
+ *
+ * Typical example is object data, when evaluating the object's modifier stack the final obdata
+ * can be different than the COW initial obdata ID.
+ */
LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT = 1 << 13,
+
+ /**
+ * The data-block is fully outside of any ID management area, and should be considered as a
+ * purely independent data.
+ *
+ * RESET_NEVER
+ *
+ * NOTE: Only used by node-groups currently.
+ */
LIB_TAG_LOCALIZED = 1 << 14,
/* RESET_NEVER tag data-block for freeing etc. behavior
diff --git a/source/blender/makesdna/DNA_cachefile_defaults.h b/source/blender/makesdna/DNA_cachefile_defaults.h
index 521b72567d4..74fbe5012ab 100644
--- a/source/blender/makesdna/DNA_cachefile_defaults.h
+++ b/source/blender/makesdna/DNA_cachefile_defaults.h
@@ -40,6 +40,8 @@
.handle = NULL, \
.handle_filepath[0] = '\0', \
.handle_readers = NULL, \
+ .use_prefetch = 1, \
+ .prefetch_cache_size = 4096, \
}
/** \} */
diff --git a/source/blender/makesdna/DNA_cachefile_types.h b/source/blender/makesdna/DNA_cachefile_types.h
index b38c7827ea5..0f4c53a6e7e 100644
--- a/source/blender/makesdna/DNA_cachefile_types.h
+++ b/source/blender/makesdna/DNA_cachefile_types.h
@@ -87,14 +87,29 @@ typedef struct CacheFile {
/** The frame offset to subtract. */
float frame_offset;
+ char _pad[4];
+
/** Animation flag. */
short flag;
- short draw_flag; /* UNUSED */
/* eCacheFileType enum. */
char type;
- char _pad[2];
+ /** Do not load data from the cache file and display objects in the scene as boxes, Cycles will
+ * load objects directly from the CacheFile. Other render engines which can load Alembic data
+ * directly can take care of rendering it themselves.
+ */
+ char use_render_procedural;
+
+ char _pad1[3];
+
+ /** Enable data prefetching when using the Cycles Procedural. */
+ char use_prefetch;
+
+ /** Size in megabytes for the prefetch cache used by the Cycles Procedural. */
+ int prefetch_cache_size;
+
+ char _pad2[7];
char velocity_unit;
/* Name of the velocity property in the archive. */
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 380d8ad1249..68bd2961f23 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -324,6 +324,7 @@ typedef struct bGPDstroke {
struct bGPDcurve *editcurve;
bGPDstroke_Runtime runtime;
+ void *_pad5;
} bGPDstroke;
/** #bGPDstroke.flag */
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 932f4715298..97f14b2195d 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -231,6 +231,7 @@ typedef struct Mesh {
* default and Face Sets can be used without affecting the color of the mesh. */
int face_sets_color_default;
+ void *_pad2;
Mesh_Runtime runtime;
} Mesh;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index f66de378c35..1bebbc35747 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -136,6 +136,7 @@ typedef struct ModifierData {
/* Runtime field which contains runtime data which is specific to a modifier type. */
void *runtime;
+ void *_pad1;
} ModifierData;
typedef enum {
@@ -215,6 +216,7 @@ typedef struct LatticeModifierData {
float strength;
short flag;
char _pad[2];
+ void *_pad1;
} LatticeModifierData;
/* Lattice modifier flags. */
@@ -232,6 +234,7 @@ typedef struct CurveModifierData {
short defaxis;
short flag;
char _pad[4];
+ void *_pad1;
} CurveModifierData;
/* Curve modifier flags */
@@ -283,6 +286,7 @@ typedef struct MaskModifierData {
/** Flags for various things. */
short flag;
float threshold;
+ void *_pad1;
} MaskModifierData;
/* Mask Modifier -> mode */
@@ -373,6 +377,7 @@ typedef struct MirrorModifierData {
float uv_offset[2];
float uv_offset_copy[2];
struct Object *mirror_ob;
+ void *_pad1;
} MirrorModifierData;
/* MirrorModifierData->flag */
@@ -451,6 +456,7 @@ typedef struct BevelModifierData {
/** Curve info for the custom profile */
struct CurveProfile *custom_profile;
+ void *_pad2;
} BevelModifierData;
/* BevelModifierData->flags and BevelModifierData->lim_flags */
@@ -535,6 +541,7 @@ typedef struct FluidModifierData {
float time;
/** Domain, inflow, outflow, .... */
int type;
+ void *_pad1;
} FluidModifierData;
/* Fluid modifier flags */
@@ -680,6 +687,7 @@ typedef struct CastModifierData {
/** MAX_VGROUP_NAME. */
char defgrp_name[64];
short flag, type;
+ void *_pad1;
} CastModifierData;
/* Cast modifier flags */
@@ -725,6 +733,7 @@ typedef struct WaveModifierData {
float timeoffs, lifetime;
char _pad1[4];
+ void *_pad2;
} WaveModifierData;
/* WaveModifierData.flag */
@@ -797,6 +806,7 @@ typedef struct HookModifierData {
float force;
/** Optional vertexgroup name, MAX_VGROUP_NAME. */
char name[64];
+ void *_pad1;
} HookModifierData;
typedef struct SoftbodyModifierData {
@@ -1001,6 +1011,7 @@ typedef struct ParticleSystemModifierData {
int totdmvert, totdmedge, totdmface;
short flag;
char _pad[2];
+ void *_pad1;
} ParticleSystemModifierData;
typedef enum {
@@ -1037,6 +1048,7 @@ typedef struct ParticleInstanceModifierData {
char index_layer_name[64];
/** MAX_CUSTOMDATA_LAYER_NAME. */
char value_layer_name[64];
+ void *_pad1;
} ParticleInstanceModifierData;
typedef enum {
@@ -1057,6 +1069,7 @@ typedef struct ExplodeModifierData {
float protect;
/** MAX_CUSTOMDATA_LAYER_NAME. */
char uvname[64];
+ void *_pad1;
} ExplodeModifierData;
typedef struct MultiresModifierData {
@@ -1086,6 +1099,7 @@ typedef struct FluidsimModifierData {
/** Definition is in DNA_object_fluidsim_types.h. */
struct FluidsimSettings *fss;
+ void *_pad1;
} FluidsimModifierData;
/* DEPRECATED, only used for versioning. */
@@ -1202,6 +1216,7 @@ typedef struct SimpleDeformModifierData {
char deform_axis;
char flag;
+ void *_pad1;
} SimpleDeformModifierData;
/* SimpleDeform->flag */
@@ -1310,6 +1325,7 @@ typedef struct ScrewModifierData {
short flag;
char axis;
char _pad[5];
+ void *_pad1;
} ScrewModifierData;
enum {
@@ -1434,6 +1450,7 @@ typedef struct WarpModifierData {
char flag;
char falloff_type;
char _pad[6];
+ void *_pad1;
} WarpModifierData;
/* WarpModifierData->flag */
@@ -1497,6 +1514,7 @@ typedef struct WeightVGEditModifierData {
/* Padding... */
char _pad0[4];
+ void *_pad1;
} WeightVGEditModifierData;
/* WeightVGEdit flags. */
@@ -2064,6 +2082,7 @@ typedef struct DataTransferModifierData {
char defgrp_name[64];
int flags;
+ void *_pad2;
} DataTransferModifierData;
/* DataTransferModifierData.flags */
@@ -2094,6 +2113,7 @@ typedef struct NormalEditModifierData {
float mix_limit;
float offset[3];
char _pad0[4];
+ void *_pad1;
} NormalEditModifierData;
/* NormalEditModifierData.mode */
@@ -2154,6 +2174,7 @@ typedef struct MeshSeqCacheModifierData {
float last_lookup_time;
int _pad1;
+ void *_pad2;
} MeshSeqCacheModifierData;
/* MeshSeqCacheModifierData.read_flag */
@@ -2198,6 +2219,7 @@ typedef struct SurfaceDeformModifierData {
float mat[4][4];
float strength;
char defgrp_name[64];
+ void *_pad1;
} SurfaceDeformModifierData;
/* Surface Deform modifier flags */
@@ -2259,6 +2281,7 @@ typedef struct NodesModifierData {
/* Contains logged information from the last evaluation. This can be used to help the user to
* debug a node tree. */
void *runtime_eval_log;
+ void *_pad1;
} NodesModifierData;
typedef struct MeshToVolumeModifierData {
@@ -2286,6 +2309,7 @@ typedef struct MeshToVolumeModifierData {
float density;
char _pad2[4];
+ void *_pad3;
} MeshToVolumeModifierData;
/* MeshToVolumeModifierData->resolution_mode */
@@ -2332,6 +2356,7 @@ typedef struct VolumeToMeshModifierData {
/** MAX_NAME */
char grid_name[64];
+ void *_pad1;
} VolumeToMeshModifierData;
/** VolumeToMeshModifierData->resolution_mode */
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index ad7722d3ed0..fd794ed1b21 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1328,6 +1328,13 @@ typedef struct NodeAttributeConvert {
int8_t domain;
} NodeAttributeConvert;
+typedef struct NodeGeometrySubdivisionSurface {
+ /* eSubsurfUVSmooth. */
+ uint8_t uv_smooth;
+ /* eSubsurfBoundarySmooth. */
+ uint8_t boundary_smooth;
+} NodeGeometrySubdivisionSurface;
+
typedef struct NodeGeometryMeshCircle {
/* GeometryNodeMeshCircleFillType. */
uint8_t fill_type;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index e7091c78f71..0250d853898 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -433,6 +433,7 @@ typedef struct Object {
ObjectLineArt lineart;
/** Runtime evaluation data (keep last). */
+ void *_pad9;
Object_Runtime runtime;
} Object;
@@ -466,8 +467,6 @@ typedef struct ObHook {
/* used many places, should be specialized. */
#define SELECT 1
-#define OBJECT_ACTIVE_MODIFIER_NONE -1
-
/* type */
enum {
OB_EMPTY = 0,
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index af524ff4866..03c38eb71a0 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -296,6 +296,7 @@ typedef struct Editing {
int64_t disk_cache_timestamp;
EditingRuntime runtime;
+ void *_pad1;
} Editing;
/* ************* Effect Variable Structs ********* */
@@ -338,11 +339,8 @@ typedef struct SpeedControlVars {
float *frameMap;
/* DEPRECATED, only used for versioning. */
float globalSpeed;
- /* DEPRECATED, only used for versioning. */
int flags;
- int length;
- int lastValidFrame;
int speed_control_type;
float speed_fader;
diff --git a/source/blender/makesdna/DNA_sound_types.h b/source/blender/makesdna/DNA_sound_types.h
index b2bb50c56a2..e6394f0a56a 100644
--- a/source/blender/makesdna/DNA_sound_types.h
+++ b/source/blender/makesdna/DNA_sound_types.h
@@ -67,6 +67,7 @@ typedef struct bSound {
/** Runtime only, always reset in readfile. */
short tags;
char _pad[4];
+ double offset_time;
/* Unused currently. */
// int type;
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 5f8a8c6230a..27376432092 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -71,14 +71,13 @@ typedef struct uiFontStyle {
short uifont_id;
/** Actual size depends on 'global' dpi. */
short points;
- /** Unfitted or default kerning value. */
- short kerning;
/** Style hint. */
short italic, bold;
/** Value is amount of pixels blur. */
short shadow;
/** Shadow offset in pixels. */
short shadx, shady;
+ char _pad0[2];
/** Total alpha. */
float shadowalpha;
/** 1 value, typically white or black anyway. */
@@ -645,7 +644,7 @@ typedef struct UserDef_Experimental {
char use_full_frame_compositor;
char use_sculpt_vertex_colors;
char use_sculpt_tools_tilt;
- char use_asset_browser;
+ char use_extended_asset_browser;
char use_override_templates;
char _pad[5];
/** `makesdna` does not allow empty structs. */
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index f2a75a60a44..061c3462a69 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -165,6 +165,10 @@ static char **names;
static char **types;
/** At `types_size[a]` is the size of type `a` on this systems bitness (32 or 64). */
static short *types_size_native;
+/** Contains align requirements for a struct on 32 bit systems. */
+static short *types_align_32;
+/** Contains align requirements for a struct on 64 bit systems. */
+static short *types_align_64;
/** Contains sizes as they are calculated on 32 bit systems. */
static short *types_size_32;
/** Contains sizes as they are calculated on 64 bit systems. */
@@ -406,6 +410,8 @@ static int add_type(const char *str, int size)
types_size_native[index] = size;
types_size_32[index] = size;
types_size_64[index] = size;
+ types_align_32[index] = size;
+ types_align_64[index] = size;
}
return index;
}
@@ -419,7 +425,8 @@ static int add_type(const char *str, int size)
types_size_native[types_len] = size;
types_size_32[types_len] = size;
types_size_64[types_len] = size;
-
+ types_align_32[types_len] = size;
+ types_align_64[types_len] = size;
if (types_len >= max_array_len) {
printf("too many types\n");
return types_len - 1;
@@ -966,7 +973,9 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
int size_native = 0;
int size_32 = 0;
int size_64 = 0;
- bool has_pointer = false;
+ /* Sizes of the largest field in a struct. */
+ int max_align_32 = 0;
+ int max_align_64 = 0;
/* check all elements in struct */
for (int b = 0; b < structpoin[1]; b++, sp += 2) {
@@ -995,7 +1004,6 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
/* is it a pointer or function pointer? */
if (cp[0] == '*' || cp[1] == '*') {
- has_pointer = 1;
/* has the name an extra length? (array) */
int mul = 1;
if (cp[namelen - 1] == ']') {
@@ -1042,6 +1050,8 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
size_native += sizeof(void *) * mul;
size_32 += 4 * mul;
size_64 += 8 * mul;
+ max_align_32 = MAX2(max_align_32, 4);
+ max_align_64 = MAX2(max_align_64, 8);
}
else if (cp[0] == '[') {
/* parsing can cause names "var" and "[3]"
@@ -1087,6 +1097,8 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
size_native += mul * types_size_native[type];
size_32 += mul * types_size_32[type];
size_64 += mul * types_size_64[type];
+ max_align_32 = MAX2(max_align_32, types_align_32[type]);
+ max_align_64 = MAX2(max_align_64, types_align_64[type]);
}
else {
size_native = 0;
@@ -1103,16 +1115,42 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
types_size_native[structtype] = size_native;
types_size_32[structtype] = size_32;
types_size_64[structtype] = size_64;
- /* Two ways to detect if a struct contains a pointer:
- * has_pointer is set or size_native doesn't match any of 32/64bit lengths. */
- if (has_pointer || size_64 != size_native || size_32 != size_native) {
- if (size_64 % 8) {
+ types_align_32[structtype] = max_align_32;
+ types_align_64[structtype] = max_align_64;
+
+ /* Sanity check 1: alignment should never be 0. */
+ BLI_assert(max_align_32);
+ BLI_assert(max_align_64);
+
+ /* Sanity check 2: alignment should always be equal or smaller than the maximum
+ * size of a build in type which is 8 bytes (ie int64_t or double). */
+ BLI_assert(max_align_32 <= 8);
+ BLI_assert(max_align_64 <= 8);
+
+ if (size_32 % max_align_32) {
+ /* There is an one odd case where only the 32 bit struct has alignment issues
+ * and the 64 bit does not, that can only be fixed by adding a padding pointer
+ * to the struct to resolve the problem. */
+ if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) {
fprintf(stderr,
- "Sizeerror 8 in struct: %s (add %d bytes)\n",
+ "Sizeerror in 32 bit struct: %s (add paddding pointer)\n",
+ types[structtype]);
+ }
+ else {
+ fprintf(stderr,
+ "Sizeerror in 32 bit struct: %s (add %d bytes)\n",
types[structtype],
- size_64 % 8);
- dna_error = 1;
+ max_align_32 - (size_32 % max_align_32));
}
+ dna_error = 1;
+ }
+
+ if (size_64 % max_align_64) {
+ fprintf(stderr,
+ "Sizeerror in 64 bit struct: %s (add %d bytes)\n",
+ types[structtype],
+ max_align_64 - (size_64 % max_align_64));
+ dna_error = 1;
}
if (size_native % 4 && !ELEM(size_native, 1, 2)) {
@@ -1229,6 +1267,9 @@ static int make_structDNA(const char *base_directory,
types_size_native = MEM_callocN(sizeof(short) * max_array_len, "types_size_native");
types_size_32 = MEM_callocN(sizeof(short) * max_array_len, "types_size_32");
types_size_64 = MEM_callocN(sizeof(short) * max_array_len, "types_size_64");
+ types_align_32 = MEM_callocN(sizeof(short) * max_array_len, "types_size_32");
+ types_align_64 = MEM_callocN(sizeof(short) * max_array_len, "types_size_64");
+
structs = MEM_callocN(sizeof(short *) * max_array_len, "structs");
/* Build versioning data */
@@ -1317,7 +1358,11 @@ static int make_structDNA(const char *base_directory,
sp += 2;
/* ? num_types was elem? */
for (b = 0; b < num_types; b++, sp += 2) {
- printf(" %s %s\n", types[sp[0]], names[sp[1]]);
+ printf(" %s %s allign32:%d, allign64:%d\n",
+ types[sp[0]],
+ names[sp[1]],
+ types_align_32[sp[0]],
+ types_align_64[sp[0]]);
}
}
}
@@ -1439,6 +1484,8 @@ static int make_structDNA(const char *base_directory,
MEM_freeN(types_size_native);
MEM_freeN(types_size_32);
MEM_freeN(types_size_64);
+ MEM_freeN(types_align_32);
+ MEM_freeN(types_align_64);
MEM_freeN(structs);
BLI_memarena_free(mem_arena);
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index a4e56652620..abbe609d0ef 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -499,6 +499,7 @@ extern StructRNA RNA_Pose;
extern StructRNA RNA_PoseBone;
extern StructRNA RNA_Preferences;
extern StructRNA RNA_PreferencesEdit;
+extern StructRNA RNA_PreferencesExperimental;
extern StructRNA RNA_PreferencesFilePaths;
extern StructRNA RNA_PreferencesInput;
extern StructRNA RNA_PreferencesKeymap;
@@ -827,6 +828,7 @@ unsigned int RNA_struct_count_properties(StructRNA *srna);
/* lower level functions for access to type properties */
const struct ListBase *RNA_struct_type_properties(StructRNA *srna);
+PropertyRNA *RNA_struct_type_find_property_no_base(StructRNA *srna, const char *identifier);
PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier);
FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier);
@@ -1027,10 +1029,8 @@ void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *val
void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len);
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop);
void RNA_property_string_get_default(PropertyRNA *prop, char *value, int max_len);
-char *RNA_property_string_get_default_alloc(PointerRNA *ptr,
- PropertyRNA *prop,
- char *fixedbuf,
- int fixedlen);
+char *RNA_property_string_get_default_alloc(
+ PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len);
int RNA_property_string_default_length(PointerRNA *ptr, PropertyRNA *prop);
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop);
@@ -1236,7 +1236,8 @@ bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_ic
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name);
void RNA_string_get(PointerRNA *ptr, const char *name, char *value);
-char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen);
+char *RNA_string_get_alloc(
+ PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len);
int RNA_string_length(PointerRNA *ptr, const char *name);
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value);
diff --git a/source/blender/makesrna/RNA_enum_items.h b/source/blender/makesrna/RNA_enum_items.h
new file mode 100644
index 00000000000..c8f44262020
--- /dev/null
+++ b/source/blender/makesrna/RNA_enum_items.h
@@ -0,0 +1,240 @@
+/*
+ * This program is free software you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup RNA
+ */
+
+/* NOTE: this is included multiple times with different #defines for DEF_ENUM. */
+
+/* use in cases where only dynamic types are used */
+DEF_ENUM(DummyRNA_NULL_items)
+DEF_ENUM(DummyRNA_DEFAULT_items)
+
+/* all others should follow 'rna_enum_*_items' naming */
+DEF_ENUM(rna_enum_id_type_items)
+
+DEF_ENUM(rna_enum_object_mode_items)
+DEF_ENUM(rna_enum_workspace_object_mode_items)
+DEF_ENUM(rna_enum_object_empty_drawtype_items)
+DEF_ENUM(rna_enum_object_gpencil_type_items)
+DEF_ENUM(rna_enum_metaelem_type_items)
+
+DEF_ENUM(rna_enum_proportional_falloff_items)
+DEF_ENUM(rna_enum_proportional_falloff_curve_only_items)
+DEF_ENUM(rna_enum_snap_target_items)
+DEF_ENUM(rna_enum_snap_element_items)
+DEF_ENUM(rna_enum_snap_node_element_items)
+DEF_ENUM(rna_enum_curve_fit_method_items)
+DEF_ENUM(rna_enum_mesh_select_mode_items)
+DEF_ENUM(rna_enum_mesh_select_mode_uv_items)
+DEF_ENUM(rna_enum_mesh_delimit_mode_items)
+DEF_ENUM(rna_enum_space_graph_mode_items)
+DEF_ENUM(rna_enum_space_file_browse_mode_items)
+DEF_ENUM(rna_enum_space_sequencer_view_type_items)
+DEF_ENUM(rna_enum_space_type_items)
+DEF_ENUM(rna_enum_space_image_mode_items)
+DEF_ENUM(rna_enum_space_image_mode_all_items)
+DEF_ENUM(rna_enum_space_action_mode_items)
+DEF_ENUM(rna_enum_fileselect_params_sort_items)
+DEF_ENUM(rna_enum_region_type_items)
+DEF_ENUM(rna_enum_object_modifier_type_items)
+DEF_ENUM(rna_enum_constraint_type_items)
+DEF_ENUM(rna_enum_boidrule_type_items)
+DEF_ENUM(rna_enum_sequence_modifier_type_items)
+DEF_ENUM(rna_enum_object_greasepencil_modifier_type_items)
+DEF_ENUM(rna_enum_object_shaderfx_type_items)
+
+DEF_ENUM(rna_enum_modifier_triangulate_quad_method_items)
+DEF_ENUM(rna_enum_modifier_triangulate_ngon_method_items)
+DEF_ENUM(rna_enum_modifier_shrinkwrap_mode_items)
+
+DEF_ENUM(rna_enum_image_type_items)
+DEF_ENUM(rna_enum_image_color_mode_items)
+DEF_ENUM(rna_enum_image_color_depth_items)
+DEF_ENUM(rna_enum_image_generated_type_items)
+
+DEF_ENUM(rna_enum_normal_space_items)
+DEF_ENUM(rna_enum_normal_swizzle_items)
+DEF_ENUM(rna_enum_bake_save_mode_items)
+DEF_ENUM(rna_enum_bake_target_items)
+
+DEF_ENUM(rna_enum_views_format_items)
+DEF_ENUM(rna_enum_views_format_multilayer_items)
+DEF_ENUM(rna_enum_views_format_multiview_items)
+DEF_ENUM(rna_enum_stereo3d_display_items)
+DEF_ENUM(rna_enum_stereo3d_anaglyph_type_items)
+DEF_ENUM(rna_enum_stereo3d_interlace_type_items)
+
+#ifdef WITH_OPENEXR
+DEF_ENUM(rna_enum_exr_codec_items)
+#endif
+DEF_ENUM(rna_enum_color_sets_items)
+
+DEF_ENUM(rna_enum_beztriple_keyframe_type_items)
+DEF_ENUM(rna_enum_beztriple_interpolation_mode_items)
+DEF_ENUM(rna_enum_beztriple_interpolation_easing_items)
+DEF_ENUM(rna_enum_fcurve_auto_smoothing_items)
+DEF_ENUM(rna_enum_keyframe_handle_type_items)
+DEF_ENUM(rna_enum_driver_target_rotation_mode_items)
+
+DEF_ENUM(rna_enum_keyingset_path_grouping_items)
+DEF_ENUM(rna_enum_keying_flag_items)
+DEF_ENUM(rna_enum_keying_flag_items_api)
+
+DEF_ENUM(rna_enum_fmodifier_type_items)
+
+DEF_ENUM(rna_enum_motionpath_bake_location_items)
+
+DEF_ENUM(rna_enum_event_value_all_items)
+DEF_ENUM(rna_enum_event_value_keymouse_items)
+DEF_ENUM(rna_enum_event_value_tweak_items)
+
+DEF_ENUM(rna_enum_event_type_items)
+DEF_ENUM(rna_enum_event_type_mask_items)
+
+DEF_ENUM(rna_enum_operator_type_flag_items)
+DEF_ENUM(rna_enum_operator_return_items)
+DEF_ENUM(rna_enum_operator_property_tags)
+
+DEF_ENUM(rna_enum_brush_sculpt_tool_items)
+DEF_ENUM(rna_enum_brush_uv_sculpt_tool_items)
+DEF_ENUM(rna_enum_brush_vertex_tool_items)
+DEF_ENUM(rna_enum_brush_weight_tool_items)
+DEF_ENUM(rna_enum_brush_gpencil_types_items)
+DEF_ENUM(rna_enum_brush_gpencil_vertex_types_items)
+DEF_ENUM(rna_enum_brush_gpencil_sculpt_types_items)
+DEF_ENUM(rna_enum_brush_gpencil_weight_types_items)
+DEF_ENUM(rna_enum_brush_image_tool_items)
+
+DEF_ENUM(rna_enum_axis_xy_items)
+DEF_ENUM(rna_enum_axis_xyz_items)
+
+DEF_ENUM(rna_enum_axis_flag_xyz_items)
+
+DEF_ENUM(rna_enum_symmetrize_direction_items)
+
+DEF_ENUM(rna_enum_texture_type_items)
+
+DEF_ENUM(rna_enum_light_type_items)
+
+DEF_ENUM(rna_enum_lightprobes_type_items)
+
+DEF_ENUM(rna_enum_unpack_method_items)
+
+DEF_ENUM(rna_enum_object_type_items)
+DEF_ENUM(rna_enum_object_rotation_mode_items)
+
+DEF_ENUM(rna_enum_object_type_curve_items)
+
+DEF_ENUM(rna_enum_rigidbody_object_type_items)
+DEF_ENUM(rna_enum_rigidbody_object_shape_items)
+DEF_ENUM(rna_enum_rigidbody_constraint_type_items)
+
+DEF_ENUM(rna_enum_object_axis_items)
+
+DEF_ENUM(rna_enum_render_pass_type_items)
+
+DEF_ENUM(rna_enum_bake_pass_type_items)
+DEF_ENUM(rna_enum_bake_pass_filter_type_items)
+
+DEF_ENUM(rna_enum_keymap_propvalue_items)
+
+DEF_ENUM(rna_enum_operator_context_items)
+
+DEF_ENUM(rna_enum_wm_report_items)
+
+DEF_ENUM(rna_enum_property_type_items)
+DEF_ENUM(rna_enum_property_subtype_items)
+DEF_ENUM(rna_enum_property_unit_items)
+
+DEF_ENUM(rna_enum_shading_type_items)
+
+DEF_ENUM(rna_enum_navigation_mode_items)
+
+DEF_ENUM(rna_enum_node_socket_in_out_items)
+
+DEF_ENUM(rna_enum_node_math_items)
+DEF_ENUM(rna_enum_mapping_type_items)
+DEF_ENUM(rna_enum_node_vec_math_items)
+DEF_ENUM(rna_enum_node_boolean_math_items)
+DEF_ENUM(rna_enum_node_float_compare_items)
+DEF_ENUM(rna_enum_node_filter_items)
+DEF_ENUM(rna_enum_node_float_to_int_items)
+DEF_ENUM(rna_enum_node_map_range_items)
+DEF_ENUM(rna_enum_node_clamp_items)
+
+DEF_ENUM(rna_enum_ramp_blend_items)
+
+DEF_ENUM(rna_enum_prop_dynamicpaint_type_items)
+
+DEF_ENUM(rna_enum_clip_editor_mode_items)
+
+DEF_ENUM(rna_enum_icon_items)
+DEF_ENUM(rna_enum_uilist_layout_type_items)
+
+DEF_ENUM(rna_enum_linestyle_color_modifier_type_items)
+DEF_ENUM(rna_enum_linestyle_alpha_modifier_type_items)
+DEF_ENUM(rna_enum_linestyle_thickness_modifier_type_items)
+DEF_ENUM(rna_enum_linestyle_geometry_modifier_type_items)
+
+DEF_ENUM(rna_enum_window_cursor_items)
+
+DEF_ENUM(rna_enum_dt_method_vertex_items)
+DEF_ENUM(rna_enum_dt_method_edge_items)
+DEF_ENUM(rna_enum_dt_method_loop_items)
+DEF_ENUM(rna_enum_dt_method_poly_items)
+DEF_ENUM(rna_enum_dt_mix_mode_items)
+DEF_ENUM(rna_enum_dt_layers_select_src_items)
+DEF_ENUM(rna_enum_dt_layers_select_dst_items)
+
+DEF_ENUM(rna_enum_context_mode_items)
+
+DEF_ENUM(rna_enum_preference_section_items)
+
+DEF_ENUM(rna_enum_attribute_type_items)
+DEF_ENUM(rna_enum_attribute_type_with_auto_items)
+DEF_ENUM(rna_enum_attribute_domain_items)
+DEF_ENUM(rna_enum_attribute_domain_with_auto_items)
+
+DEF_ENUM(rna_enum_collection_color_items)
+
+DEF_ENUM(rna_enum_subdivision_uv_smooth_items)
+DEF_ENUM(rna_enum_subdivision_boundary_smooth_items)
+
+DEF_ENUM(rna_enum_transform_orientation_items)
+
+/* Not available to RNA pre-processing (`makrsrna`).
+ * Defined in editors for example. */
+#ifndef RNA_MAKESRNA
+
+DEF_ENUM(rna_enum_particle_edit_hair_brush_items)
+DEF_ENUM(rna_enum_particle_edit_disconnected_hair_brush_items)
+
+DEF_ENUM(rna_enum_keyframe_paste_offset_items)
+DEF_ENUM(rna_enum_keyframe_paste_merge_items)
+
+DEF_ENUM(rna_enum_transform_pivot_items_full)
+DEF_ENUM(rna_enum_transform_mode_types)
+
+/* In the runtime part of RNA, could be removed from this section. */
+DEF_ENUM(rna_enum_nla_mode_extend_items)
+DEF_ENUM(rna_enum_nla_mode_blend_items)
+DEF_ENUM(rna_enum_keyblock_type_items)
+
+#endif
+
+#undef DEF_ENUM
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index d544083a749..d7520834287 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -32,219 +32,11 @@ struct bNodeTreeType;
struct bNodeType;
/* Types */
+#define DEF_ENUM(id) extern const EnumPropertyItem id[];
+#include "RNA_enum_items.h"
-/* use in cases where only dynamic types are used */
-extern const EnumPropertyItem DummyRNA_NULL_items[];
-extern const EnumPropertyItem DummyRNA_DEFAULT_items[];
-
-/* all others should follow 'rna_enum_*_items' naming */
-extern const EnumPropertyItem rna_enum_id_type_items[];
-
-extern const EnumPropertyItem rna_enum_object_mode_items[];
-extern const EnumPropertyItem rna_enum_workspace_object_mode_items[];
-extern const EnumPropertyItem rna_enum_object_empty_drawtype_items[];
-extern const EnumPropertyItem rna_enum_object_gpencil_type_items[];
-extern const EnumPropertyItem rna_enum_metaelem_type_items[];
-
-extern const EnumPropertyItem rna_enum_proportional_falloff_items[];
-extern const EnumPropertyItem rna_enum_proportional_falloff_curve_only_items[];
-extern const EnumPropertyItem rna_enum_snap_target_items[];
-extern const EnumPropertyItem rna_enum_snap_element_items[];
-extern const EnumPropertyItem rna_enum_snap_node_element_items[];
-extern const EnumPropertyItem rna_enum_curve_fit_method_items[];
-extern const EnumPropertyItem rna_enum_mesh_select_mode_items[];
-extern const EnumPropertyItem rna_enum_mesh_select_mode_uv_items[];
-extern const EnumPropertyItem rna_enum_mesh_delimit_mode_items[];
-extern const EnumPropertyItem rna_enum_space_graph_mode_items[];
-extern const EnumPropertyItem rna_enum_space_file_browse_mode_items[];
-extern const EnumPropertyItem rna_enum_space_sequencer_view_type_items[];
-extern const EnumPropertyItem rna_enum_space_type_items[];
-extern const EnumPropertyItem rna_enum_space_image_mode_items[];
-extern const EnumPropertyItem rna_enum_space_image_mode_all_items[];
-extern const EnumPropertyItem rna_enum_space_action_mode_items[];
-extern const EnumPropertyItem rna_enum_fileselect_params_sort_items[];
-extern const EnumPropertyItem rna_enum_region_type_items[];
-extern const EnumPropertyItem rna_enum_object_modifier_type_items[];
-extern const EnumPropertyItem rna_enum_constraint_type_items[];
-extern const EnumPropertyItem rna_enum_boidrule_type_items[];
-extern const EnumPropertyItem rna_enum_sequence_modifier_type_items[];
-extern const EnumPropertyItem rna_enum_object_greasepencil_modifier_type_items[];
-extern const EnumPropertyItem rna_enum_object_shaderfx_type_items[];
-
-extern const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[];
-extern const EnumPropertyItem rna_enum_modifier_triangulate_ngon_method_items[];
-extern const EnumPropertyItem rna_enum_modifier_shrinkwrap_mode_items[];
-
-extern const EnumPropertyItem rna_enum_image_type_items[];
-extern const EnumPropertyItem rna_enum_image_color_mode_items[];
-extern const EnumPropertyItem rna_enum_image_color_depth_items[];
-extern const EnumPropertyItem rna_enum_image_generated_type_items[];
-
-extern const EnumPropertyItem rna_enum_normal_space_items[];
-extern const EnumPropertyItem rna_enum_normal_swizzle_items[];
-extern const EnumPropertyItem rna_enum_bake_save_mode_items[];
-extern const EnumPropertyItem rna_enum_bake_target_items[];
-
-extern const EnumPropertyItem rna_enum_views_format_items[];
-extern const EnumPropertyItem rna_enum_views_format_multilayer_items[];
-extern const EnumPropertyItem rna_enum_views_format_multiview_items[];
-extern const EnumPropertyItem rna_enum_stereo3d_display_items[];
-extern const EnumPropertyItem rna_enum_stereo3d_anaglyph_type_items[];
-extern const EnumPropertyItem rna_enum_stereo3d_interlace_type_items[];
-
-extern const EnumPropertyItem rna_enum_exr_codec_items[];
-extern const EnumPropertyItem rna_enum_color_sets_items[];
-
-extern const EnumPropertyItem rna_enum_beztriple_keyframe_type_items[];
-extern const EnumPropertyItem rna_enum_beztriple_interpolation_mode_items[];
-extern const EnumPropertyItem rna_enum_beztriple_interpolation_easing_items[];
-extern const EnumPropertyItem rna_enum_fcurve_auto_smoothing_items[];
-extern const EnumPropertyItem rna_enum_keyframe_handle_type_items[];
-extern const EnumPropertyItem rna_enum_driver_target_rotation_mode_items[];
-
-extern const EnumPropertyItem rna_enum_keyblock_type_items[];
-
-extern const EnumPropertyItem rna_enum_keyingset_path_grouping_items[];
-extern const EnumPropertyItem rna_enum_keying_flag_items[];
-extern const EnumPropertyItem rna_enum_keying_flag_items_api[];
-
-extern const EnumPropertyItem rna_enum_keyframe_paste_offset_items[];
-extern const EnumPropertyItem rna_enum_keyframe_paste_merge_items[];
-
-extern const EnumPropertyItem rna_enum_fmodifier_type_items[];
-
-extern const EnumPropertyItem rna_enum_nla_mode_extend_items[];
-extern const EnumPropertyItem rna_enum_nla_mode_blend_items[];
-
-extern const EnumPropertyItem rna_enum_motionpath_bake_location_items[];
-
-extern const EnumPropertyItem rna_enum_event_value_all_items[];
-extern const EnumPropertyItem rna_enum_event_value_keymouse_items[];
-extern const EnumPropertyItem rna_enum_event_value_tweak_items[];
-
-extern const EnumPropertyItem rna_enum_event_type_items[];
-extern const EnumPropertyItem rna_enum_event_type_mask_items[];
-
-extern const EnumPropertyItem rna_enum_operator_type_flag_items[];
-extern const EnumPropertyItem rna_enum_operator_return_items[];
-extern const EnumPropertyItem rna_enum_operator_property_tags[];
-
-extern const EnumPropertyItem rna_enum_brush_sculpt_tool_items[];
-extern const EnumPropertyItem rna_enum_brush_uv_sculpt_tool_items[];
-extern const EnumPropertyItem rna_enum_brush_vertex_tool_items[];
-extern const EnumPropertyItem rna_enum_brush_weight_tool_items[];
-extern const EnumPropertyItem rna_enum_brush_gpencil_types_items[];
-extern const EnumPropertyItem rna_enum_brush_gpencil_vertex_types_items[];
-extern const EnumPropertyItem rna_enum_brush_gpencil_sculpt_types_items[];
-extern const EnumPropertyItem rna_enum_brush_gpencil_weight_types_items[];
-extern const EnumPropertyItem rna_enum_brush_image_tool_items[];
-
-extern const EnumPropertyItem rna_enum_particle_edit_hair_brush_items[];
-extern const EnumPropertyItem rna_enum_particle_edit_disconnected_hair_brush_items[];
-
-extern const EnumPropertyItem rna_enum_uv_sculpt_tool_items[];
-
-extern const EnumPropertyItem rna_enum_axis_xy_items[];
-extern const EnumPropertyItem rna_enum_axis_xyz_items[];
-
-extern const EnumPropertyItem rna_enum_axis_flag_xyz_items[];
-
-extern const EnumPropertyItem rna_enum_symmetrize_direction_items[];
-
-extern const EnumPropertyItem rna_enum_texture_type_items[];
-
-extern const EnumPropertyItem rna_enum_light_type_items[];
-
-extern const EnumPropertyItem rna_enum_lightprobes_type_items[];
-
-extern const EnumPropertyItem rna_enum_unpack_method_items[];
-
-extern const EnumPropertyItem rna_enum_object_type_items[];
-extern const EnumPropertyItem rna_enum_object_rotation_mode_items[];
-
-extern const EnumPropertyItem rna_enum_object_type_curve_items[];
-
-extern const EnumPropertyItem rna_enum_rigidbody_object_type_items[];
-extern const EnumPropertyItem rna_enum_rigidbody_object_shape_items[];
-extern const EnumPropertyItem rna_enum_rigidbody_constraint_type_items[];
-
-extern const EnumPropertyItem rna_enum_object_axis_items[];
-
-extern const EnumPropertyItem rna_enum_controller_type_items[];
-
-extern const EnumPropertyItem rna_enum_render_pass_type_items[];
-extern const EnumPropertyItem rna_enum_render_pass_debug_type_items[];
-
-extern const EnumPropertyItem rna_enum_bake_pass_type_items[];
-extern const EnumPropertyItem rna_enum_bake_pass_filter_type_items[];
-
-extern const EnumPropertyItem rna_enum_keymap_propvalue_items[];
-
-extern const EnumPropertyItem rna_enum_operator_context_items[];
-
-extern const EnumPropertyItem rna_enum_wm_report_items[];
-
-extern const EnumPropertyItem rna_enum_transform_pivot_items_full[];
-extern const EnumPropertyItem rna_enum_transform_orientation_items[];
-extern const EnumPropertyItem rna_enum_transform_mode_types[];
-
-extern const EnumPropertyItem rna_enum_property_type_items[];
-extern const EnumPropertyItem rna_enum_property_subtype_items[];
-extern const EnumPropertyItem rna_enum_property_unit_items[];
-
-extern const EnumPropertyItem rna_enum_shading_type_items[];
-
-extern const EnumPropertyItem rna_enum_navigation_mode_items[];
-
-extern const EnumPropertyItem rna_enum_node_socket_in_out_items[];
-
-extern const EnumPropertyItem rna_enum_node_math_items[];
-extern const EnumPropertyItem rna_enum_mapping_type_items[];
-extern const EnumPropertyItem rna_enum_node_vec_math_items[];
-extern const EnumPropertyItem rna_enum_node_boolean_math_items[];
-extern const EnumPropertyItem rna_enum_node_float_compare_items[];
-extern const EnumPropertyItem rna_enum_node_filter_items[];
-extern const EnumPropertyItem rna_enum_node_float_to_int_items[];
-extern const EnumPropertyItem rna_enum_node_map_range_items[];
-extern const EnumPropertyItem rna_enum_node_clamp_items[];
-
-extern const EnumPropertyItem rna_enum_ramp_blend_items[];
-
-extern const EnumPropertyItem rna_enum_prop_dynamicpaint_type_items[];
-
-extern const EnumPropertyItem rna_enum_clip_editor_mode_items[];
-
-extern const EnumPropertyItem rna_enum_icon_items[];
-extern const EnumPropertyItem rna_enum_uilist_layout_type_items[];
-
-extern const EnumPropertyItem rna_enum_linestyle_color_modifier_type_items[];
-extern const EnumPropertyItem rna_enum_linestyle_alpha_modifier_type_items[];
-extern const EnumPropertyItem rna_enum_linestyle_thickness_modifier_type_items[];
-extern const EnumPropertyItem rna_enum_linestyle_geometry_modifier_type_items[];
-
-extern const EnumPropertyItem rna_enum_window_cursor_items[];
-
-extern const EnumPropertyItem rna_enum_dt_method_vertex_items[];
-extern const EnumPropertyItem rna_enum_dt_method_edge_items[];
-extern const EnumPropertyItem rna_enum_dt_method_loop_items[];
-extern const EnumPropertyItem rna_enum_dt_method_poly_items[];
-extern const EnumPropertyItem rna_enum_dt_mix_mode_items[];
-extern const EnumPropertyItem rna_enum_dt_layers_select_src_items[];
-extern const EnumPropertyItem rna_enum_dt_layers_select_dst_items[];
-
-extern const EnumPropertyItem rna_enum_context_mode_items[];
-
-extern const EnumPropertyItem rna_enum_curveprofile_preset_items[];
-extern const EnumPropertyItem rna_enum_preference_section_items[];
-
-extern const EnumPropertyItem rna_enum_attribute_type_items[];
-extern const EnumPropertyItem rna_enum_attribute_type_with_auto_items[];
-extern const EnumPropertyItem rna_enum_attribute_domain_items[];
-extern const EnumPropertyItem rna_enum_attribute_domain_with_auto_items[];
extern const EnumPropertyItem *rna_enum_attribute_domain_itemf(struct ID *id, bool *r_free);
-extern const EnumPropertyItem rna_enum_collection_color_items[];
-
/**
* For ID filters (#FILTER_ID_AC, #FILTER_ID_AR, ...) an int isn't enough. This version allows 64
* bit integers. So can't use the regular #EnumPropertyItem. Would be nice if RNA supported this
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 95b7b7e5406..7e6d0aea2ee 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -175,6 +175,7 @@ set(SRC_RNA_INC
../RNA_access.h
../RNA_define.h
../RNA_documentation.h
+ ../RNA_enum_items.h
../RNA_enum_types.h
../RNA_types.h
)
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 719b0f73a9d..36f19907080 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -582,6 +582,23 @@ static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
(IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0));
}
+/**
+ * Return the identifier for an enum which is defined in "RNA_enum_items.h".
+ *
+ * Prevents expanding duplicate enums bloating the binary size.
+ */
+static const char *rna_enum_id_from_pointer(const EnumPropertyItem *item)
+{
+#define RNA_MAKESRNA
+#define DEF_ENUM(id) \
+ if (item == id) { \
+ return STRINGIFY(id); \
+ }
+#include "RNA_enum_items.h"
+#undef RNA_MAKESRNA
+ return NULL;
+}
+
static const char *rna_function_string(const void *func)
{
return (func) ? (const char *)func : "NULL";
@@ -3675,37 +3692,55 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
int i, defaultfound = 0, totflag = 0;
if (eprop->item) {
- fprintf(f,
- "static const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t",
- srna->identifier,
- strnest,
- prop->identifier,
- eprop->totitem + 1);
-
- for (i = 0; i < eprop->totitem; i++) {
- fprintf(f, "{%d, ", eprop->item[i].value);
- rna_print_c_string(f, eprop->item[i].identifier);
- fprintf(f, ", ");
- fprintf(f, "%d, ", eprop->item[i].icon);
- rna_print_c_string(f, eprop->item[i].name);
- fprintf(f, ", ");
- rna_print_c_string(f, eprop->item[i].description);
- fprintf(f, "},\n\t");
-
- if (eprop->item[i].identifier[0]) {
- if (prop->flag & PROP_ENUM_FLAG) {
- totflag |= eprop->item[i].value;
+ /* Inline the enum if this is not a defined in "RNA_enum_items.h". */
+ const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
+ if (item_global_id == NULL) {
+ fprintf(f,
+ "static const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t",
+ srna->identifier,
+ strnest,
+ prop->identifier,
+ eprop->totitem + 1);
+
+ for (i = 0; i < eprop->totitem; i++) {
+ fprintf(f, "{%d, ", eprop->item[i].value);
+ rna_print_c_string(f, eprop->item[i].identifier);
+ fprintf(f, ", ");
+ fprintf(f, "%d, ", eprop->item[i].icon);
+ rna_print_c_string(f, eprop->item[i].name);
+ fprintf(f, ", ");
+ rna_print_c_string(f, eprop->item[i].description);
+ fprintf(f, "},\n\t");
+
+ if (eprop->item[i].identifier[0]) {
+ if (prop->flag & PROP_ENUM_FLAG) {
+ totflag |= eprop->item[i].value;
+ }
+ else {
+ if (eprop->defaultvalue == eprop->item[i].value) {
+ defaultfound = 1;
+ }
+ }
}
- else {
- if (eprop->defaultvalue == eprop->item[i].value) {
- defaultfound = 1;
+ }
+
+ fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
+ }
+ else {
+ for (i = 0; i < eprop->totitem; i++) {
+ if (eprop->item[i].identifier[0]) {
+ if (prop->flag & PROP_ENUM_FLAG) {
+ totflag |= eprop->item[i].value;
+ }
+ else {
+ if (eprop->defaultvalue == eprop->item[i].value) {
+ defaultfound = 1;
+ }
}
}
}
}
- fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
-
if (prop->flag & PROP_ENUM_FLAG) {
if (eprop->defaultvalue & ~totflag) {
CLOG_ERROR(&LOG,
@@ -4047,7 +4082,13 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
rna_function_string(eprop->get_ex),
rna_function_string(eprop->set_ex));
if (eprop->item) {
- fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
+ const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
+ if (item_global_id != NULL) {
+ fprintf(f, "%s, ", item_global_id);
+ }
+ else {
+ fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
+ }
}
else {
fprintf(f, "NULL, ");
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index dda1c2ff56a..246446313d4 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -748,8 +748,7 @@ bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
{
- if (identifier[0] == '[' && identifier[1] == '"') { /* " (dummy comment to avoid confusing some
- * function lists in text editors) */
+ if (identifier[0] == '[' && identifier[1] == '"') {
/* id prop lookup, not so common */
PropertyRNA *r_prop = NULL;
PointerRNA r_ptr; /* only support single level props */
@@ -833,19 +832,33 @@ const struct ListBase *RNA_struct_type_properties(StructRNA *srna)
return &srna->cont.properties;
}
-PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
+PropertyRNA *RNA_struct_type_find_property_no_base(StructRNA *srna, const char *identifier)
{
return BLI_findstring_ptr(&srna->cont.properties, identifier, offsetof(PropertyRNA, identifier));
}
+/**
+ * \note #RNA_struct_find_property is a higher level alternative to this function
+ * which takes a #PointerRNA instead of a #StructRNA.
+ */
+PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
+{
+ for (; srna; srna = srna->base) {
+ PropertyRNA *prop = RNA_struct_type_find_property_no_base(srna, identifier);
+ if (prop != NULL) {
+ return prop;
+ }
+ }
+ return NULL;
+}
+
FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier)
{
#if 1
FunctionRNA *func;
- StructRNA *type;
- for (type = srna; type; type = type->base) {
+ for (; srna; srna = srna->base) {
func = (FunctionRNA *)BLI_findstring_ptr(
- &type->functions, identifier, offsetof(FunctionRNA, identifier));
+ &srna->functions, identifier, offsetof(FunctionRNA, identifier));
if (func) {
return func;
}
@@ -2847,7 +2860,7 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
BLI_assert(RNA_property_array_check(prop) == false);
/* useful to check on bad values but set function should clamp */
- /* BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0); */
+ // BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0);
if ((idprop = rna_idproperty_check(&prop, ptr))) {
RNA_property_float_clamp(ptr, prop, &value);
@@ -3241,7 +3254,7 @@ char *RNA_property_string_get_alloc(
buf = fixedbuf;
}
else {
- buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
+ buf = MEM_mallocN(sizeof(char) * (length + 1), __func__);
}
#ifndef NDEBUG
@@ -3376,10 +3389,8 @@ void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int m
strcpy(value, sprop->defaultvalue);
}
-char *RNA_property_string_get_default_alloc(PointerRNA *ptr,
- PropertyRNA *prop,
- char *fixedbuf,
- int fixedlen)
+char *RNA_property_string_get_default_alloc(
+ PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
{
char *buf;
int length;
@@ -3392,11 +3403,15 @@ char *RNA_property_string_get_default_alloc(PointerRNA *ptr,
buf = fixedbuf;
}
else {
- buf = MEM_callocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
+ buf = MEM_callocN(sizeof(char) * (length + 1), __func__);
}
RNA_property_string_get_default(prop, buf, length + 1);
+ if (r_len) {
+ *r_len = length;
+ }
+
return buf;
}
@@ -6423,15 +6438,18 @@ void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
}
}
-char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
+char *RNA_string_get_alloc(
+ PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
{
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
if (prop) {
- /* TODO: pass length. */
- return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL);
+ return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, r_len);
}
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
+ if (r_len != NULL) {
+ *r_len = 0;
+ }
return NULL;
}
@@ -8002,7 +8020,7 @@ bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
}
case PROP_STRING: {
- char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0);
+ char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0, NULL);
RNA_property_string_set(ptr, prop, value);
MEM_freeN(value);
return true;
diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c
index 3912c873fd0..2c552970c82 100644
--- a/source/blender/makesrna/intern/rna_access_compare_override.c
+++ b/source/blender/makesrna/intern/rna_access_compare_override.c
@@ -1096,6 +1096,7 @@ static void rna_property_override_check_resync(Main *bmain,
PointerRNA *ptr_item_dst,
PointerRNA *ptr_item_src)
{
+ ID *id_owner = rna_property_override_property_real_id_owner(bmain, ptr_dst, NULL, NULL);
ID *id_src = rna_property_override_property_real_id_owner(bmain, ptr_item_src, NULL, NULL);
ID *id_dst = rna_property_override_property_real_id_owner(bmain, ptr_item_dst, NULL, NULL);
@@ -1109,9 +1110,18 @@ static void rna_property_override_check_resync(Main *bmain,
* remapped to its new local override. In that case overrides and linked data
* are always properly matching. */
id_src != id_dst &&
- /* If one of the pointers is NULL and not the other, or if linked reference ID
- * of `id_src` is not `id_dst`, we are in a non-matching case. */
- (ELEM(NULL, id_src, id_dst) || id_src->override_library->reference != id_dst)) {
+ /* If one of the pointers is NULL and not the other, we are in a non-matching case. */
+ (ELEM(NULL, id_src, id_dst) ||
+ /* If `id_dst` is not from same lib as id_src, and linked reference ID of `id_src` is not
+ * `id_dst`, we are in a non-matching case. */
+ (id_dst->lib != id_src->lib && id_src->override_library->reference != id_dst) ||
+ /* If `id_dst` is from same lib as id_src, and is not same as `id_owner`, we are in a
+ * non-matching case.
+ *
+ * NOTE: Here we are testing if `id_owner` is referencing itself, in that case the new
+ * override copy generated by `BKE_lib_override_library_update` will already have its
+ * self-references updated to itself, instead of still pointing to its linked source. */
+ (id_dst->lib == id_src->lib && id_dst != id_owner))) {
ptr_dst->owner_id->tag |= LIB_TAG_LIB_OVERRIDE_NEED_RESYNC;
CLOG_INFO(&LOG, 3, "Local override %s detected as needing resync", ptr_dst->owner_id->name);
}
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index 49d02524e43..690506fa517 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -56,7 +56,7 @@ static void rna_Armature_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene),
DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
- /*WM_main_add_notifier(NC_OBJECT|ND_POSE, NULL); */
+ // WM_main_add_notifier(NC_OBJECT|ND_POSE, NULL);
}
static void rna_Armature_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
@@ -994,7 +994,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
}
RNA_def_property_float_sdna(prop, NULL, "rad_head");
/* XXX range is 0 to lim, where lim = 10000.0f * MAX2(1.0, view3d->grid); */
- /*RNA_def_property_range(prop, 0, 1000); */
+ // RNA_def_property_range(prop, 0, 1000);
RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
RNA_def_property_ui_text(
prop, "Envelope Head Radius", "Radius of head of bone (for Envelope deform only)");
@@ -1008,7 +1008,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
}
RNA_def_property_float_sdna(prop, NULL, "rad_tail");
/* XXX range is 0 to lim, where lim = 10000.0f * MAX2(1.0, view3d->grid); */
- /*RNA_def_property_range(prop, 0, 1000); */
+ // RNA_def_property_range(prop, 0, 1000);
RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
RNA_def_property_ui_text(
prop, "Envelope Tail Radius", "Radius of tail of bone (for Envelope deform only)");
@@ -1346,7 +1346,7 @@ static void rna_def_edit_bone(BlenderRNA *brna)
/* calculated and read only, not actual data access */
prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
- /* RNA_def_property_float_sdna(prop, NULL, ""); */ /* Doesn't access any real data. */
+ // RNA_def_property_float_sdna(prop, NULL, ""); /* Doesn't access any real data. */
RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
// RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_THICK_WRAP); /* no reference to original data */
diff --git a/source/blender/makesrna/intern/rna_cachefile.c b/source/blender/makesrna/intern/rna_cachefile.c
index b93f494072c..74d924b8937 100644
--- a/source/blender/makesrna/intern/rna_cachefile.c
+++ b/source/blender/makesrna/intern/rna_cachefile.c
@@ -37,6 +37,7 @@
# include "BKE_cachefile.h"
# include "DEG_depsgraph.h"
+# include "DEG_depsgraph_build.h"
# include "WM_api.h"
# include "WM_types.h"
@@ -53,6 +54,12 @@ static void rna_CacheFile_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
+static void rna_CacheFile_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ rna_CacheFile_update(bmain, scene, ptr);
+ DEG_relations_tag_update(bmain);
+}
+
static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
CacheFile *cache_file = (CacheFile *)ptr->data;
@@ -105,6 +112,16 @@ static void rna_def_cachefile(BlenderRNA *brna)
prop, "Sequence", "Whether the cache is separated in a series of files");
RNA_def_property_update(prop, 0, "rna_CacheFile_update");
+ prop = RNA_def_property(srna, "use_render_procedural", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_ui_text(
+ prop,
+ "Use Render Engine Procedural",
+ "Display boxes in the viewport as placeholders for the objects, Cycles will use a "
+ "procedural to load the objects during viewport rendering in experimental mode, "
+ "other render engines will also receive a placeholder and should take care of loading the "
+ "Alembic data themselves if possible");
+ RNA_def_property_update(prop, 0, "rna_CacheFile_dependency_update");
+
/* ----------------- For Scene time ------------------- */
prop = RNA_def_property(srna, "override_frame", PROP_BOOLEAN, PROP_NONE);
@@ -133,6 +150,23 @@ static void rna_def_cachefile(BlenderRNA *brna)
"determine which file to use in a file sequence");
RNA_def_property_update(prop, 0, "rna_CacheFile_update");
+ /* ----------------- Cache controls ----------------- */
+
+ prop = RNA_def_property(srna, "use_prefetch", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_ui_text(
+ prop,
+ "Use Prefetch",
+ "When enabled, the Cycles Procedural will preload animation data for faster updates");
+ RNA_def_property_update(prop, 0, "rna_CacheFile_update");
+
+ prop = RNA_def_property(srna, "prefetch_cache_size", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_ui_text(
+ prop,
+ "Prefetch Cache Size",
+ "Memory usage limit in megabytes for the Cycles Procedural cache, if the data does not "
+ "fit within the limit, rendering is aborted");
+ RNA_def_property_update(prop, 0, "rna_CacheFile_update");
+
/* ----------------- Axis Conversion ----------------- */
prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c
index 9faf2ae7cb7..5f198a8ed4c 100644
--- a/source/blender/makesrna/intern/rna_color.c
+++ b/source/blender/makesrna/intern/rna_color.c
@@ -701,11 +701,7 @@ static float rna_CurveMapping_evaluateF(struct CurveMapping *cumap,
}
if (!cuma->table) {
- BKE_report(
- reports,
- RPT_ERROR,
- "CurveMap table not initialized, call initialize() on CurveMapping owner of the CurveMap");
- return 0.0f;
+ BKE_curvemapping_init(cumap);
}
return BKE_curvemap_evaluateF(cumap, cuma, value);
}
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c
index e36d052d27c..5968c8bac8f 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -3509,6 +3509,12 @@ void RNA_def_constraint(BlenderRNA *brna)
RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
+ prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CONSTRAINT_OFF);
+ RNA_def_property_ui_text(prop, "Enabled", "Use the results of this constraint");
+ RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
+ RNA_def_property_ui_icon(prop, ICON_HIDE_ON, 1);
+
prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "ui_expand_flag", 0);
diff --git a/source/blender/makesrna/intern/rna_curveprofile.c b/source/blender/makesrna/intern/rna_curveprofile.c
index b3ab8cc15a2..66c0fc72c7a 100644
--- a/source/blender/makesrna/intern/rna_curveprofile.c
+++ b/source/blender/makesrna/intern/rna_curveprofile.c
@@ -23,9 +23,6 @@
#include "DNA_curve_types.h"
#include "DNA_curveprofile_types.h"
-#include "DNA_texture_types.h"
-
-#include "BLI_utildefines.h"
#include "RNA_define.h"
#include "rna_internal.h"
@@ -37,31 +34,7 @@
# include "RNA_access.h"
-# include "DNA_image_types.h"
-# include "DNA_material_types.h"
-# include "DNA_movieclip_types.h"
-# include "DNA_node_types.h"
-# include "DNA_object_types.h"
-# include "DNA_particle_types.h"
-# include "DNA_sequence_types.h"
-
-# include "MEM_guardedalloc.h"
-
-# include "BKE_colorband.h"
# include "BKE_curveprofile.h"
-# include "BKE_image.h"
-# include "BKE_linestyle.h"
-# include "BKE_movieclip.h"
-# include "BKE_node.h"
-
-# include "DEG_depsgraph.h"
-
-# include "ED_node.h"
-
-# include "IMB_colormanagement.h"
-# include "IMB_imbuf.h"
-
-# include "SEQ_sequencer.h"
/**
* Set both handle types for all selected points in the profile-- faster than changing types
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index c058ab6cfcc..e44ddb07d53 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -290,15 +290,10 @@ static void rna_UDIMTile_tile_number_set(PointerRNA *ptr, int value)
ImageTile *tile = (ImageTile *)ptr->data;
Image *image = (Image *)ptr->owner_id;
- /* The index of the first tile can't be changed. */
- if (tile->tile_number == 1001) {
- return;
- }
-
/* Check that no other tile already has that number. */
ImageTile *cur_tile = BKE_image_get_tile(image, value);
- if (cur_tile == NULL || cur_tile == tile) {
- tile->tile_number = value;
+ if (cur_tile == NULL) {
+ BKE_image_reassign_tile(image, tile, value);
}
}
diff --git a/source/blender/makesrna/intern/rna_light.c b/source/blender/makesrna/intern/rna_light.c
index 0593db0dd56..8bec337885e 100644
--- a/source/blender/makesrna/intern/rna_light.c
+++ b/source/blender/makesrna/intern/rna_light.c
@@ -188,6 +188,7 @@ static void rna_def_light(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based lights");
prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c
index ca97f2c9a55..8cd1ac0d963 100644
--- a/source/blender/makesrna/intern/rna_linestyle.c
+++ b/source/blender/makesrna/intern/rna_linestyle.c
@@ -2189,6 +2189,7 @@ static void rna_def_linestyle(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node-based shaders");
prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 8e6ff961721..9a33849b645 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -122,7 +122,7 @@
static void rna_idname_validate(const char *name, char *r_name)
{
BLI_strncpy(r_name, name, MAX_ID_NAME - 2);
- BLI_utf8_invalid_strip(r_name, strlen(r_name));
+ BLI_str_utf8_invalid_strip(r_name, strlen(r_name));
}
static void rna_Main_ID_remove(Main *bmain,
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index d91c0bfaf29..144950235c8 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -849,8 +849,7 @@ void RNA_def_material(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
- /* XXX: remove once overrides in material node trees are supported. */
- RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based materials");
prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 9caff88a3a5..fbc578acb8e 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1687,7 +1687,7 @@ static void rna_def_mvert(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
- /* RNA_def_property_float_sdna(prop, NULL, "no"); */
+ // RNA_def_property_float_sdna(prop, NULL, "no");
RNA_def_property_array(prop, 3);
RNA_def_property_range(prop, -1.0f, 1.0f);
RNA_def_property_float_funcs(
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index b424a575094..486d8d13564 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -595,6 +595,44 @@ const EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
{0, NULL, 0, NULL, NULL},
};
+const EnumPropertyItem rna_enum_subdivision_uv_smooth_items[] = {
+ {SUBSURF_UV_SMOOTH_NONE, "NONE", 0, "None", "UVs are not smoothed, boundaries are kept sharp"},
+ {SUBSURF_UV_SMOOTH_PRESERVE_CORNERS,
+ "PRESERVE_CORNERS",
+ 0,
+ "Keep Corners",
+ "UVs are smoothed, corners on discontinuous boundary are kept sharp"},
+ {SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_AND_JUNCTIONS,
+ "PRESERVE_CORNERS_AND_JUNCTIONS",
+ 0,
+ "Keep Corners, Junctions",
+ "UVs are smoothed, corners on discontinuous boundary and "
+ "junctions of 3 or more regions are kept sharp"},
+ {SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE,
+ "PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE",
+ 0,
+ "Keep Corners, Junctions, Concave",
+ "UVs are smoothed, corners on discontinuous boundary, "
+ "junctions of 3 or more regions and darts and concave corners are kept sharp"},
+ {SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES,
+ "PRESERVE_BOUNDARIES",
+ 0,
+ "Keep Boundaries",
+ "UVs are smoothed, boundaries are kept sharp"},
+ {SUBSURF_UV_SMOOTH_ALL, "SMOOTH_ALL", 0, "All", "UVs and boundaries are smoothed"},
+ {0, NULL, 0, NULL, NULL},
+};
+
+const EnumPropertyItem rna_enum_subdivision_boundary_smooth_items[] = {
+ {SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS,
+ "PRESERVE_CORNERS",
+ 0,
+ "Keep Corners",
+ "Smooth boundaries, but corners are kept sharp"},
+ {SUBSURF_BOUNDARY_SMOOTH_ALL, "ALL", 0, "All", "Smooth boundaries, including corners"},
+ {0, NULL, 0, NULL, NULL},
+};
+
#ifdef RNA_RUNTIME
# include "DNA_curve_types.h"
# include "DNA_fluid_types.h"
@@ -1631,55 +1669,12 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr)
static void rna_def_property_subdivision_common(StructRNA *srna)
{
- static const EnumPropertyItem prop_uv_smooth_items[] = {
- {SUBSURF_UV_SMOOTH_NONE,
- "NONE",
- 0,
- "None",
- "UVs are not smoothed, boundaries are kept sharp"},
- {SUBSURF_UV_SMOOTH_PRESERVE_CORNERS,
- "PRESERVE_CORNERS",
- 0,
- "Keep Corners",
- "UVs are smoothed, corners on discontinuous boundary are kept sharp"},
- {SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_AND_JUNCTIONS,
- "PRESERVE_CORNERS_AND_JUNCTIONS",
- 0,
- "Keep Corners, Junctions",
- "UVs are smoothed, corners on discontinuous boundary and "
- "junctions of 3 or more regions are kept sharp"},
- {SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE,
- "PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE",
- 0,
- "Keep Corners, Junctions, Concave",
- "UVs are smoothed, corners on discontinuous boundary, "
- "junctions of 3 or more regions and darts and concave corners are kept sharp"},
- {SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES,
- "PRESERVE_BOUNDARIES",
- 0,
- "Keep Boundaries",
- "UVs are smoothed, boundaries are kept sharp"},
- {SUBSURF_UV_SMOOTH_ALL, "SMOOTH_ALL", 0, "All", "UVs and boundaries are smoothed"},
- {0, NULL, 0, NULL, NULL},
- };
-
- static const EnumPropertyItem prop_boundary_smooth_items[] = {
- {SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS,
- "PRESERVE_CORNERS",
- 0,
- "Keep Corners",
- "Smooth boundaries, but corners are kept sharp"},
- {SUBSURF_BOUNDARY_SMOOTH_ALL, "ALL", 0, "All", "Smooth boundaries, including corners"},
- {0, NULL, 0, NULL, NULL},
- };
-
PropertyRNA *prop;
-
RNA_define_lib_overridable(true);
prop = RNA_def_property(srna, "uv_smooth", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "uv_smooth");
- RNA_def_property_enum_items(prop, prop_uv_smooth_items);
+ RNA_def_property_enum_items(prop, rna_enum_subdivision_uv_smooth_items);
RNA_def_property_ui_text(prop, "UV Smooth", "Controls how smoothing is applied to UVs");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
@@ -1693,7 +1688,7 @@ static void rna_def_property_subdivision_common(StructRNA *srna)
prop = RNA_def_property(srna, "boundary_smooth", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "boundary_smooth");
- RNA_def_property_enum_items(prop, prop_boundary_smooth_items);
+ RNA_def_property_enum_items(prop, rna_enum_subdivision_boundary_smooth_items);
RNA_def_property_ui_text(prop, "Boundary Smooth", "Controls how open boundaries are smoothed");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 5de7aa9a18b..d8ab7c7a61b 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1036,7 +1036,7 @@ static void rna_NodeTree_get_from_context(
void *ret1, *ret2, *ret3;
RNA_pointer_create(NULL, ntreetype->rna_ext.srna, NULL, &ptr); /* dummy */
- /* RNA_struct_find_function(&ptr, "get_from_context"); */
+ // RNA_struct_find_function(&ptr, "get_from_context");
func = &rna_NodeTree_get_from_context_func;
RNA_parameter_list_create(&list, &ptr, func);
@@ -2987,7 +2987,7 @@ static void rna_NodeSocketInterface_register_properties(bNodeTree *ntree,
}
RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
- /* RNA_struct_find_function(&ptr, "register_properties"); */
+ // RNA_struct_find_function(&ptr, "register_properties");
func = &rna_NodeSocketInterface_register_properties_func;
RNA_parameter_list_create(&list, &ptr, func);
@@ -3013,7 +3013,7 @@ static void rna_NodeSocketInterface_init_socket(
RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sock_ptr);
- /* RNA_struct_find_function(&ptr, "init_socket"); */
+ // RNA_struct_find_function(&ptr, "init_socket");
func = &rna_NodeSocketInterface_init_socket_func;
RNA_parameter_list_create(&list, &ptr, func);
@@ -3043,7 +3043,7 @@ static void rna_NodeSocketInterface_from_socket(bNodeTree *ntree,
RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sock_ptr);
- /* RNA_struct_find_function(&ptr, "from_socket"); */
+ // RNA_struct_find_function(&ptr, "from_socket");
func = &rna_NodeSocketInterface_from_socket_func;
RNA_parameter_list_create(&list, &ptr, func);
@@ -4745,6 +4745,7 @@ static void def_frame(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Text");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Text", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -5752,6 +5753,7 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
NULL,
NULL);
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "resolution", PROP_INT, PROP_NONE);
@@ -6171,6 +6173,7 @@ static void def_sh_tex_ies(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Text");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "IES Text", "Internal IES file");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -6211,6 +6214,7 @@ static void def_sh_script(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Text");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Script", "Internal shader script to define the shader");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_ShaderNodeScript_update");
@@ -7936,6 +7940,7 @@ static void def_cmp_movieclip(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "MovieClip");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Movie Clip", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -7950,6 +7955,7 @@ static void def_cmp_stabilize2d(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "MovieClip");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Movie Clip", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -7980,6 +7986,7 @@ static void def_cmp_moviedistortion(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "MovieClip");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Movie Clip", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8009,6 +8016,7 @@ static void def_cmp_mask(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Mask");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Mask", "");
prop = RNA_def_property(srna, "use_feather", PROP_BOOLEAN, PROP_NONE);
@@ -8501,6 +8509,7 @@ static void def_cmp_keyingscreen(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "MovieClip");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Movie Clip", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8638,6 +8647,7 @@ static void def_cmp_trackpos(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "MovieClip");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Movie Clip", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8702,6 +8712,7 @@ static void def_cmp_planetrackdeform(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "MovieClip");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Movie Clip", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8832,6 +8843,7 @@ static void def_cmp_cryptomatte(StructRNA *srna)
prop, "rna_NodeCryptomatte_scene_get", "rna_NodeCryptomatte_scene_set", NULL, NULL);
RNA_def_property_struct_type(prop, "Scene");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Scene", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8843,6 +8855,7 @@ static void def_cmp_cryptomatte(StructRNA *srna)
"rna_NodeCryptomatte_image_poll");
RNA_def_property_struct_type(prop, "Image");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8942,6 +8955,7 @@ static void def_tex_image(StructRNA *srna)
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Image");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -9095,6 +9109,26 @@ static void def_geo_triangulate(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
+static void def_geo_subdivision_surface(StructRNA *srna)
+{
+ PropertyRNA *prop;
+
+ RNA_def_struct_sdna_from(srna, "NodeGeometrySubdivisionSurface", "storage");
+ prop = RNA_def_property(srna, "uv_smooth", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "uv_smooth");
+ RNA_def_property_enum_items(prop, rna_enum_subdivision_uv_smooth_items);
+ RNA_def_property_enum_default(prop, SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES);
+ RNA_def_property_ui_text(prop, "UV Smooth", "Controls how smoothing is applied to UVs");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "boundary_smooth", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "boundary_smooth");
+ RNA_def_property_enum_items(prop, rna_enum_subdivision_boundary_smooth_items);
+ RNA_def_property_enum_default(prop, SUBSURF_BOUNDARY_SMOOTH_ALL);
+ RNA_def_property_ui_text(prop, "Boundary Smooth", "Controls how open boundaries are smoothed");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
static void def_geo_attribute_randomize(StructRNA *srna)
{
PropertyRNA *prop;
@@ -10909,6 +10943,7 @@ static void rna_def_node_socket_object(BlenderRNA *brna,
RNA_def_property_update(
prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_and_relation_update");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_CONTEXT_UPDATE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
/* socket interface */
srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard");
@@ -10944,6 +10979,7 @@ static void rna_def_node_socket_image(BlenderRNA *brna,
RNA_def_property_update(
prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_and_relation_update");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_CONTEXT_UPDATE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
/* socket interface */
srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard");
@@ -10994,6 +11030,7 @@ static void rna_def_node_socket_collection(BlenderRNA *brna,
RNA_def_property_update(
prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_and_relation_update");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_CONTEXT_UPDATE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
/* socket interface */
srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard");
@@ -11029,6 +11066,7 @@ static void rna_def_node_socket_texture(BlenderRNA *brna,
RNA_def_property_update(
prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_and_relation_update");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_CONTEXT_UPDATE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
/* socket interface */
srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard");
@@ -11066,6 +11104,7 @@ static void rna_def_node_socket_material(BlenderRNA *brna,
RNA_def_property_update(
prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_and_relation_update");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_CONTEXT_UPDATE);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
/* socket interface */
srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard");
@@ -11451,12 +11490,14 @@ static void rna_def_node(BlenderRNA *brna)
prop = RNA_def_property(srna, "inputs", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "inputs", NULL);
RNA_def_property_struct_type(prop, "NodeSocket");
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Inputs", "");
rna_def_node_sockets_api(brna, prop, SOCK_IN);
prop = RNA_def_property(srna, "outputs", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "outputs", NULL);
RNA_def_property_struct_type(prop, "NodeSocket");
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Outputs", "");
rna_def_node_sockets_api(brna, prop, SOCK_OUT);
@@ -11903,6 +11944,7 @@ static void rna_def_nodetree(BlenderRNA *brna)
prop = RNA_def_property(srna, "nodes", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "nodes", NULL);
RNA_def_property_struct_type(prop, "Node");
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Nodes", "");
rna_def_nodetree_nodes_api(brna, prop);
@@ -11920,6 +11962,7 @@ static void rna_def_nodetree(BlenderRNA *brna)
RNA_def_property_pointer_funcs(
prop, NULL, NULL, NULL, "rna_GPencil_datablocks_annotations_poll");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil data-block");
RNA_def_property_update(prop, NC_NODE, NULL);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index bef430b0314..0f6b89722a4 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -218,6 +218,12 @@ static EnumPropertyItem instance_items_pointcloud[] = {
{OB_DUPLIVERTS, "POINTS", 0, "Points", "Instantiate child objects on all points"},
{0, NULL, 0, NULL, NULL},
};
+
+static EnumPropertyItem instance_items_empty[] = {
+ {0, "NONE", 0, "None", ""},
+ INSTANCE_ITEM_COLLECTION,
+ {0, NULL, 0, NULL, NULL},
+};
#endif
#undef INSTANCE_ITEMS_SHARED
#undef INSTANCE_ITEM_COLLECTION
@@ -751,7 +757,7 @@ static const EnumPropertyItem *rna_Object_instance_type_itemf(bContext *UNUSED(C
const EnumPropertyItem *item;
if (ob->type == OB_EMPTY) {
- item = instance_items;
+ item = instance_items_empty;
}
else if (ob->type == OB_POINTCLOUD) {
item = instance_items_pointcloud;
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index de4cfb2b61a..f732e14d905 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -1851,20 +1851,20 @@ static void rna_def_particle(BlenderRNA *brna)
prop = RNA_def_property(srna, "birth_time", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "time");
- /* RNA_def_property_range(prop, lowerLimitf, upperLimitf); */
+ // RNA_def_property_range(prop, lowerLimitf, upperLimitf);
RNA_def_property_ui_text(prop, "Birth Time", "");
prop = RNA_def_property(srna, "lifetime", PROP_FLOAT, PROP_TIME);
- /* RNA_def_property_range(prop, lowerLimitf, upperLimitf); */
+ // RNA_def_property_range(prop, lowerLimitf, upperLimitf);
RNA_def_property_ui_text(prop, "Lifetime", "");
prop = RNA_def_property(srna, "die_time", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "dietime");
- /* RNA_def_property_range(prop, lowerLimitf, upperLimitf); */
+ // RNA_def_property_range(prop, lowerLimitf, upperLimitf);
RNA_def_property_ui_text(prop, "Die Time", "");
prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE);
- /* RNA_def_property_range(prop, lowerLimitf, upperLimitf); */
+ // RNA_def_property_range(prop, lowerLimitf, upperLimitf);
RNA_def_property_ui_text(prop, "Size", "");
/* */
@@ -3658,7 +3658,7 @@ static void rna_def_particle_system(BlenderRNA *brna)
/* access to particle settings is redirected through functions */
/* to allow proper id-buttons functionality */
prop = RNA_def_property(srna, "settings", PROP_POINTER, PROP_NONE);
- /*RNA_def_property_pointer_sdna(prop, NULL, "part"); */
+ // RNA_def_property_pointer_sdna(prop, NULL, "part");
RNA_def_property_struct_type(prop, "ParticleSettings");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
RNA_def_property_pointer_funcs(
diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c
index 73924c45d52..4400d198b4a 100644
--- a/source/blender/makesrna/intern/rna_render.c
+++ b/source/blender/makesrna/intern/rna_render.c
@@ -896,6 +896,12 @@ static void rna_def_render_engine(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
RNA_def_property_ui_text(prop, "Use Stereo Viewport", "Support rendering stereo 3D viewport");
+ prop = RNA_def_property(srna, "bl_use_alembic_procedural", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_ALEMBIC_PROCEDURAL);
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+ RNA_def_property_ui_text(
+ prop, "Use Alembic Procedural", "Support loading Alembic data at render time");
+
RNA_define_verify_sdna(1);
}
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 7d7eec6f256..9d158761a21 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -616,6 +616,7 @@ const EnumPropertyItem rna_enum_transform_orientation_items[] = {
# include "BLI_string_utils.h"
# include "DNA_anim_types.h"
+# include "DNA_cachefile_types.h"
# include "DNA_color_types.h"
# include "DNA_mesh_types.h"
# include "DNA_node_types.h"
@@ -1619,6 +1620,11 @@ static void rna_RenderSettings_engine_update(Main *bmain,
ED_render_engine_changed(bmain, true);
}
+static void rna_Scene_update_render_engine(Main *bmain)
+{
+ ED_render_engine_changed(bmain, true);
+}
+
static bool rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
{
return (BLI_listbase_count(&R_engines) > 1);
@@ -7664,6 +7670,7 @@ void RNA_def_scene(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Compositing node tree");
prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
@@ -7835,6 +7842,10 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SCENE, NULL);
RNA_def_property_update(prop, NC_SCENE, "rna_Scene_volume_update");
+ func = RNA_def_function(srna, "update_render_engine", "rna_Scene_update_render_engine");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_MAIN);
+ RNA_def_function_ui_description(func, "Trigger a render engine update");
+
/* Statistics */
func = RNA_def_function(srna, "statistics", "rna_Scene_statistics_string_get");
RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
@@ -7895,6 +7906,7 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "master_collection");
RNA_def_property_struct_type(prop, "Collection");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop,
"Collection",
"Scene root collection that owns all the objects and other collections "
diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c
index 74fe2a26505..dad77b4aad5 100644
--- a/source/blender/makesrna/intern/rna_sequencer.c
+++ b/source/blender/makesrna/intern/rna_sequencer.c
@@ -148,9 +148,9 @@ static void rna_Sequence_invalidate_preprocessed_update(Main *UNUSED(bmain),
}
}
-static void rna_Sequence_invalidate_composite_update(Main *UNUSED(bmain),
- Scene *UNUSED(scene),
- PointerRNA *ptr)
+static void UNUSED_FUNCTION(rna_Sequence_invalidate_composite_update)(Main *UNUSED(bmain),
+ Scene *UNUSED(scene),
+ PointerRNA *ptr)
{
Scene *scene = (Scene *)ptr->owner_id;
Editing *ed = SEQ_editing_get(scene, false);
@@ -1900,7 +1900,7 @@ static void rna_def_sequence(BlenderRNA *brna)
/* stupid 0-100 -> 0-1 */
RNA_def_property_float_funcs(prop, "rna_Sequence_opacity_get", "rna_Sequence_opacity_set", NULL);
RNA_def_property_update(
- prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_composite_update");
+ prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_preprocessed_update");
prop = RNA_def_property(srna, "effect_fader", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_range(prop, 0.0f, 1.0f);
diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c
index 4895ab11618..7ddbf450e6a 100644
--- a/source/blender/makesrna/intern/rna_sequencer_api.c
+++ b/source/blender/makesrna/intern/rna_sequencer_api.c
@@ -102,13 +102,18 @@ static void rna_Sequences_move_strip_to_meta(
}
static Sequence *rna_Sequence_split(
- ID *id, Sequence *seq, Main *bmain, int frame, int split_method)
+ ID *id, Sequence *seq, Main *bmain, ReportList *reports, int frame, int split_method)
{
Scene *scene = (Scene *)id;
Editing *ed = SEQ_editing_get(scene, false);
ListBase *seqbase = SEQ_get_seqbase_by_seq(&ed->seqbase, seq);
- Sequence *r_seq = SEQ_edit_strip_split(bmain, scene, seqbase, seq, frame, split_method);
+ const char *error_msg = NULL;
+ Sequence *r_seq = SEQ_edit_strip_split(
+ bmain, scene, seqbase, seq, frame, split_method, &error_msg);
+ if (error_msg != NULL) {
+ BKE_report(reports, RPT_ERROR, error_msg);
+ }
/* Update depsgraph. */
DEG_relations_tag_update(bmain);
@@ -119,6 +124,14 @@ static Sequence *rna_Sequence_split(
return r_seq;
}
+static Sequence *rna_Sequence_parent_meta(ID *id, Sequence *seq_self)
+{
+ Scene *scene = (Scene *)id;
+ Editing *ed = SEQ_editing_get(scene, false);
+
+ return SEQ_find_metastrip_by_sequence(&ed->seqbase, NULL, seq_self);
+}
+
static Sequence *rna_Sequences_new_clip(ID *id,
ListBase *seqbase,
Main *bmain,
@@ -310,7 +323,8 @@ static Sequence *rna_Sequences_new_movie(ID *id,
SEQ_add_load_data_init(&load_data, name, file, frame_start, channel);
load_data.fit_method = fit_method;
load_data.allow_invalid_file = true;
- Sequence *seq = SEQ_add_movie_strip(bmain, scene, seqbase, &load_data);
+ double video_start_offset;
+ Sequence *seq = SEQ_add_movie_strip(bmain, scene, seqbase, &load_data, &video_start_offset);
DEG_relations_tag_update(bmain);
DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
@@ -359,7 +373,7 @@ static Sequence *rna_Sequences_new_sound(ID *id,
SeqLoadData load_data;
SEQ_add_load_data_init(&load_data, name, file, frame_start, channel);
load_data.allow_invalid_file = true;
- Sequence *seq = SEQ_add_sound_strip(bmain, scene, seqbase, &load_data);
+ Sequence *seq = SEQ_add_sound_strip(bmain, scene, seqbase, &load_data, 0.0f);
if (seq == NULL) {
BKE_report(reports, RPT_ERROR, "Sequences.new_sound: unable to open sound file");
@@ -696,6 +710,13 @@ void RNA_api_sequence_strip(StructRNA *srna)
"Meta to move the strip into");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ func = RNA_def_function(srna, "parent_meta", "rna_Sequence_parent_meta");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_ui_description(func, "Parent meta");
+ /* return type */
+ parm = RNA_def_pointer(func, "sequence", "Sequence", "", "Parent Meta");
+ RNA_def_function_return(func, parm);
+
func = RNA_def_function(srna, "invalidate_cache", "rna_Sequence_invalidate_cache_rnafunc");
RNA_def_function_flag(func, FUNC_USE_SELF_ID);
RNA_def_function_ui_description(func,
@@ -704,7 +725,7 @@ void RNA_api_sequence_strip(StructRNA *srna)
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
func = RNA_def_function(srna, "split", "rna_Sequence_split");
- RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID | FUNC_USE_MAIN);
RNA_def_function_ui_description(func, "Split Sequence");
parm = RNA_def_int(
func, "frame", 0, INT_MIN, INT_MAX, "", "Frame where to split the strip", INT_MIN, INT_MAX);
diff --git a/source/blender/makesrna/intern/rna_simulation.c b/source/blender/makesrna/intern/rna_simulation.c
index cc9a4bec2e7..6f5041c9ed1 100644
--- a/source/blender/makesrna/intern/rna_simulation.c
+++ b/source/blender/makesrna/intern/rna_simulation.c
@@ -43,6 +43,7 @@ static void rna_def_simulation(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Node tree defining the simulation");
/* common */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index fe43237963d..5ab13e7b44e 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2477,18 +2477,6 @@ static void rna_SpaceClipEditor_mask_set(PointerRNA *ptr,
ED_space_clip_set_mask(NULL, sc, (Mask *)value.data);
}
-static void rna_SpaceClipEditor_cursor_location_get(PointerRNA *ptr, float *values)
-{
- SpaceClip *sc = (SpaceClip *)(ptr->data);
- copy_v2_v2(values, sc->cursor);
-}
-
-static void rna_SpaceClipEditor_cursor_location_set(PointerRNA *ptr, const float *values)
-{
- SpaceClip *sc = (SpaceClip *)(ptr->data);
- copy_v2_v2(sc->cursor, values);
-}
-
static void rna_SpaceClipEditor_clip_mode_update(Main *UNUSED(bmain),
Scene *UNUSED(scene),
PointerRNA *ptr)
@@ -7344,11 +7332,8 @@ static void rna_def_space_clip(BlenderRNA *brna)
/* transform */
prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ);
+ RNA_def_property_float_sdna(prop, NULL, "cursor");
RNA_def_property_array(prop, 2);
- RNA_def_property_float_funcs(prop,
- "rna_SpaceClipEditor_cursor_location_get",
- "rna_SpaceClipEditor_cursor_location_set",
- NULL);
RNA_def_property_ui_text(prop, "2D Cursor Location", "2D cursor location for this view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, NULL);
diff --git a/source/blender/makesrna/intern/rna_speaker.c b/source/blender/makesrna/intern/rna_speaker.c
index 43f0d27f514..2dce9d32006 100644
--- a/source/blender/makesrna/intern/rna_speaker.c
+++ b/source/blender/makesrna/intern/rna_speaker.c
@@ -55,7 +55,9 @@ static void rna_def_speaker(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "Mute", "Mute the speaker");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND);
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "sound", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Sound");
@@ -63,24 +65,30 @@ static void rna_def_speaker(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Sound", "Sound data-block used by this speaker");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_sound_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_sound_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "volume_max", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(
prop, "Maximum Volume", "Maximum volume, no matter how near the object is");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_volume_max_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_volume_max_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "volume_min", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(
prop, "Minimum Volume", "Minimum volume, no matter how far away the object is");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_volume_min_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_volume_min_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "distance_max", PROP_FLOAT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -89,24 +97,30 @@ static void rna_def_speaker(BlenderRNA *brna)
prop,
"Maximum Distance",
"Maximum distance for volume calculation, no matter how far away the object is");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_distance_max_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_distance_max_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "distance_reference", PROP_FLOAT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_text(
prop, "Reference Distance", "Reference distance at which volume is 100%");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_distance_reference_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_distance_reference_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "attenuation", PROP_FLOAT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_text(
prop, "Attenuation", "How strong the distance affects volume, depending on distance model");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_attenuation_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_attenuation_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "cone_angle_outer", PROP_FLOAT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -116,8 +130,10 @@ static void rna_def_speaker(BlenderRNA *brna)
"Outer Cone Angle",
"Angle of the outer cone, in degrees, outside this cone the volume is "
"the outer cone volume, between inner and outer cone the volume is interpolated");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_cone_angle_outer_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_cone_angle_outer_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "cone_angle_inner", PROP_FLOAT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -126,29 +142,37 @@ static void rna_def_speaker(BlenderRNA *brna)
prop,
"Inner Cone Angle",
"Angle of the inner cone, in degrees, inside the cone the volume is 100%");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_cone_angle_inner_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_cone_angle_inner_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "cone_volume_outer", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Outer Cone Volume", "Volume outside the outer cone");
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_cone_volume_outer_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_cone_volume_outer_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "volume", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Volume", "How loud the sound is");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND);
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_volume_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_volume_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
prop = RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.1f, 10.0f);
RNA_def_property_ui_text(prop, "Pitch", "Playback pitch of the sound");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND);
- /* RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_pitch_set", NULL); */
- /* RNA_def_property_update(prop, 0, "rna_Speaker_update"); */
+# if 0
+ RNA_def_property_float_funcs(prop, NULL, "rna_Speaker_pitch_set", NULL);
+ RNA_def_property_update(prop, 0, "rna_Speaker_update");
+# endif
/* common */
rna_def_animdata_common(srna);
diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c
index 1351c027004..52f762e5494 100644
--- a/source/blender/makesrna/intern/rna_text.c
+++ b/source/blender/makesrna/intern/rna_text.c
@@ -240,8 +240,7 @@ static void rna_def_text(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_module", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISSCRIPT);
- RNA_def_property_ui_text(
- prop, "Register", "Run this text as a script on loading, Text name must end with \".py\"");
+ RNA_def_property_ui_text(prop, "Register", "Run this text as a Python script on loading");
prop = RNA_def_property(srna, "indentation", PROP_ENUM, PROP_NONE); /* as an enum */
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flags");
diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c
index 128f1cb1e21..5a74cfa9964 100644
--- a/source/blender/makesrna/intern/rna_texture.c
+++ b/source/blender/makesrna/intern/rna_texture.c
@@ -1642,6 +1642,7 @@ static void rna_def_texture(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node-based textures");
RNA_def_property_update(prop, 0, "rna_Texture_nodes_update");
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index a88b100435a..c506a533032 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -1458,7 +1458,7 @@ static void rna_def_panel(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->description");
RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Panel_bl_description_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
@@ -1820,7 +1820,7 @@ static void rna_def_menu(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->description");
RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Menu_bl_description_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 2d93715a438..73811924c23 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -1118,12 +1118,6 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
- static const EnumPropertyItem font_kerning_style[] = {
- {0, "UNFITTED", 0, "Unfitted", "Use scaled but un-grid-fitted kerning distances"},
- {1, "FITTED", 0, "Fitted", "Use scaled and grid-fitted kerning distances"},
- {0, NULL, 0, NULL, NULL},
- };
-
srna = RNA_def_struct(brna, "ThemeFontStyle", NULL);
RNA_def_struct_sdna(srna, "uiFontStyle");
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
@@ -1134,12 +1128,6 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Points", "Font size in points");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
- prop = RNA_def_property(srna, "font_kerning_style", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "kerning");
- RNA_def_property_enum_items(prop, font_kerning_style);
- RNA_def_property_ui_text(prop, "Kerning Style", "Which style to use for font kerning");
- RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
-
prop = RNA_def_property(srna, "shadow", PROP_INT, PROP_PIXEL);
RNA_def_property_range(prop, 0, 5);
RNA_def_property_ui_text(prop, "Shadow Size", "Shadow size (0, 3 and 5 supported)");
@@ -6297,12 +6285,12 @@ static void rna_def_userdef_experimental(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "Sculpt Mode Tilt Support", "Support for pen tablet tilt events in Sculpt Mode");
- prop = RNA_def_property(srna, "use_asset_browser", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "use_asset_browser", 1);
- RNA_def_property_ui_text(
- prop,
- "Asset Browser",
- "Enable Asset Browser editor and operators to manage data-blocks as asset");
+ prop = RNA_def_property(srna, "use_extended_asset_browser", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_ui_text(prop,
+ "Extended Asset Browser",
+ "Enable Asset Browser editor and operators to manage regular "
+ "data-blocks as assets, not just poses");
+ RNA_def_property_update(prop, 0, "rna_userdef_ui_update");
prop = RNA_def_property(srna, "use_override_templates", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "use_override_templates", 1);
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 667f3822935..b910648495b 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -1915,7 +1915,7 @@ static void rna_def_operator(BlenderRNA *brna)
/* Without setting the length the pointer size would be used. -3 because `.` -> `_OT_`. */
RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME - 3);
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_struct_name_property(srna, prop);
@@ -1923,7 +1923,7 @@ static void rna_def_operator(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->name");
RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_label_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER);
prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
@@ -1943,7 +1943,7 @@ static void rna_def_operator(BlenderRNA *brna)
"rna_Operator_bl_description_get",
"rna_Operator_bl_description_length",
"rna_Operator_bl_description_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
prop = RNA_def_property(srna, "bl_undo_group", PROP_STRING, PROP_NONE);
@@ -1953,7 +1953,7 @@ static void rna_def_operator(BlenderRNA *brna)
"rna_Operator_bl_undo_group_get",
"rna_Operator_bl_undo_group_length",
"rna_Operator_bl_undo_group_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
@@ -2013,7 +2013,7 @@ static void rna_def_macro_operator(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->idname");
RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_struct_name_property(srna, prop);
@@ -2021,7 +2021,7 @@ static void rna_def_macro_operator(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->name");
RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_label_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER);
prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
@@ -2041,7 +2041,7 @@ static void rna_def_macro_operator(BlenderRNA *brna)
"rna_Operator_bl_description_get",
"rna_Operator_bl_description_length",
"rna_Operator_bl_description_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
prop = RNA_def_property(srna, "bl_undo_group", PROP_STRING, PROP_NONE);
@@ -2051,7 +2051,7 @@ static void rna_def_macro_operator(BlenderRNA *brna)
"rna_Operator_bl_undo_group_get",
"rna_Operator_bl_undo_group_length",
"rna_Operator_bl_undo_group_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
@@ -2073,11 +2073,13 @@ static void rna_def_operator_type_macro(BlenderRNA *brna)
srna, "Operator Macro", "Storage of a sub operator in a macro after it has been added");
RNA_def_struct_sdna(srna, "wmOperatorTypeMacro");
- /* prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); */
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
- /* RNA_def_property_string_sdna(prop, NULL, "idname"); */
- /* RNA_def_property_ui_text(prop, "Name", "Name of the sub operator"); */
- /* RNA_def_struct_name_property(srna, prop); */
+# if 0
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_string_sdna(prop, NULL, "idname");
+ RNA_def_property_ui_text(prop, "Name", "Name of the sub operator");
+ RNA_def_struct_name_property(srna, prop);
+# endif
prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index bde15daa682..e123604cbe9 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -230,7 +230,7 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
bool repeat,
bool head)
{
- /* wmWindowManager *wm = CTX_wm_manager(C); */
+ // wmWindowManager *wm = CTX_wm_manager(C);
wmKeyMapItem *kmi = NULL;
char idname_bl[OP_MAX_TYPENAME];
int modifier = 0;
diff --git a/source/blender/makesrna/intern/rna_wm_gizmo.c b/source/blender/makesrna/intern/rna_wm_gizmo.c
index 6a1574f3dbe..febb0e14e07 100644
--- a/source/blender/makesrna/intern/rna_wm_gizmo.c
+++ b/source/blender/makesrna/intern/rna_wm_gizmo.c
@@ -80,7 +80,7 @@ static void rna_gizmo_draw_cb(const struct bContext *C, struct wmGizmo *gz)
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "draw"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "draw")` directly. */
func = &rna_Gizmo_draw_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
RNA_parameter_set_lookup(&list, "context", &C);
@@ -98,7 +98,7 @@ static void rna_gizmo_draw_select_cb(const struct bContext *C, struct wmGizmo *g
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "draw_select"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "draw_select")` directly. */
func = &rna_Gizmo_draw_select_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
RNA_parameter_set_lookup(&list, "context", &C);
@@ -117,7 +117,7 @@ static int rna_gizmo_test_select_cb(struct bContext *C, struct wmGizmo *gz, cons
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "test_select"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "test_select")` directly. */
func = &rna_Gizmo_test_select_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
RNA_parameter_set_lookup(&list, "context", &C);
@@ -144,7 +144,7 @@ static int rna_gizmo_modal_cb(struct bContext *C,
FunctionRNA *func;
const int tweak_flag_int = tweak_flag;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "modal"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "modal")` directly. */
func = &rna_Gizmo_modal_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
RNA_parameter_set_lookup(&list, "context", &C);
@@ -168,7 +168,7 @@ static void rna_gizmo_setup_cb(struct wmGizmo *gz)
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "setup"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "setup")` directly. */
func = &rna_Gizmo_setup_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
gzgroup->type->rna_ext.call((bContext *)NULL, &gz_ptr, func, &list);
@@ -183,7 +183,7 @@ static int rna_gizmo_invoke_cb(struct bContext *C, struct wmGizmo *gz, const str
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "invoke"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "invoke")` directly. */
func = &rna_Gizmo_invoke_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
RNA_parameter_set_lookup(&list, "context", &C);
@@ -206,7 +206,7 @@ static void rna_gizmo_exit_cb(struct bContext *C, struct wmGizmo *gz, bool cance
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "exit"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "exit")` directly. */
func = &rna_Gizmo_exit_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
RNA_parameter_set_lookup(&list, "context", &C);
@@ -226,7 +226,7 @@ static void rna_gizmo_select_refresh_cb(struct wmGizmo *gz)
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, gz->type->rna_ext.srna, gz, &gz_ptr);
- /* RNA_struct_find_function(&gz_ptr, "select_refresh"); */
+ /* Reference `RNA_struct_find_function(&gz_ptr, "select_refresh")` directly. */
func = &rna_Gizmo_select_refresh_func;
RNA_parameter_list_create(&list, &gz_ptr, func);
gzgroup->type->rna_ext.call((bContext *)NULL, &gz_ptr, func, &list);
@@ -785,7 +785,7 @@ static void rna_gizmogroup_invoke_prepare_cb(const bContext *C,
FunctionRNA *func;
RNA_pointer_create(NULL, gzgroup->type->rna_ext.srna, gzgroup, &gzgroup_ptr);
- /* RNA_struct_find_function(&wgroupr, "invoke_prepare"); */
+ /* Reference `RNA_struct_find_function(&wgroupr, "invoke_prepare")` directly. */
func = &rna_GizmoGroup_invoke_prepare_func;
RNA_parameter_list_create(&list, &gzgroup_ptr, func);
@@ -1033,7 +1033,7 @@ static void rna_def_gizmo(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_string_sdna(prop, NULL, "type->idname");
RNA_def_property_string_maxlength(prop, MAX_NAME);
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Gizmo_bl_idname_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_define_verify_sdna(1); /* not in sdna */
@@ -1362,7 +1362,7 @@ static void rna_def_gizmogroup(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->name");
RNA_def_property_string_maxlength(prop, MAX_NAME); /* else it uses the pointer size! */
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GizmoGroup_bl_label_set");
- /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_REGISTER);
prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c
index 1ca0eb74cf5..826e6d21c36 100644
--- a/source/blender/makesrna/intern/rna_world.c
+++ b/source/blender/makesrna/intern/rna_world.c
@@ -216,7 +216,7 @@ void RNA_def_world(BlenderRNA *brna)
RNA_def_property_array(prop, 3);
RNA_def_property_float_array_default(prop, default_world_color);
RNA_def_property_ui_text(prop, "Color", "Color of the background");
- /* RNA_def_property_update(prop, 0, "rna_World_update"); */
+ // RNA_def_property_update(prop, 0, "rna_World_update");
/* render-only uses this */
RNA_def_property_update(prop, 0, "rna_World_draw_update");
@@ -237,6 +237,7 @@ void RNA_def_world(BlenderRNA *brna)
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based worlds");
prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index 52f21e3d3d0..a344a15b0c1 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -61,7 +61,9 @@ static void initData(ModifierData *md)
MEMCPY_STRUCT_AFTER(bmd, DNA_struct_default_get(BuildModifierData), modifier);
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index 4487adcfdda..fa2f70e1a9c 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -220,7 +220,9 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
tclmd->solver_result = NULL;
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index 5dd57469914..e7d5fe056c5 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -95,7 +95,9 @@ static void freeData(ModifierData *md)
}
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index a7ac9f618af..07da18f990d 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -95,7 +95,9 @@ static void requiredDataMask(Object *UNUSED(ob),
}
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c
index 8b1d541d45d..77ae5c4b6f1 100644
--- a/source/blender/modifiers/intern/MOD_dynamicpaint.c
+++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c
@@ -155,7 +155,9 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c
index bf197dca7e5..493b59b3a1a 100644
--- a/source/blender/modifiers/intern/MOD_explode.c
+++ b/source/blender/modifiers/intern/MOD_explode.c
@@ -86,7 +86,9 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
temd->facepa = NULL;
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_fluid.c b/source/blender/modifiers/intern/MOD_fluid.c
index 36d2ab2a11a..a14d582063a 100644
--- a/source/blender/modifiers/intern/MOD_fluid.c
+++ b/source/blender/modifiers/intern/MOD_fluid.c
@@ -132,7 +132,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
#endif /* WITH_FLUID */
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c
index e0507320628..6ef64ad8bc9 100644
--- a/source/blender/modifiers/intern/MOD_meshcache.c
+++ b/source/blender/modifiers/intern/MOD_meshcache.c
@@ -63,7 +63,9 @@ static void initData(ModifierData *md)
MEMCPY_STRUCT_AFTER(mcmd, DNA_struct_default_get(MeshCacheModifierData), modifier);
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
return (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA);
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index 3e6081e0a18..259c1cb2417 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -20,6 +20,7 @@
#include <string.h>
+#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -39,6 +40,8 @@
#include "BKE_cachefile.h"
#include "BKE_context.h"
#include "BKE_lib_query.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
@@ -118,6 +121,44 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
return (mcmd->cache_file == NULL) || (mcmd->object_path[0] == '\0');
}
+static Mesh *generate_bounding_box_mesh(Object *object, Mesh *org_mesh)
+{
+ BoundBox *bb = BKE_object_boundbox_get(object);
+ Mesh *result = BKE_mesh_new_nomain_from_template(org_mesh, 8, 0, 0, 24, 6);
+
+ MVert *mvert = result->mvert;
+ for (int i = 0; i < 8; ++i) {
+ copy_v3_v3(mvert[i].co, bb->vec[i]);
+ }
+
+ /* See DNA_object_types.h for the diagram showing the order of the vertices for a BoundBox. */
+ static unsigned int loops_v[6][4] = {
+ {0, 4, 5, 1},
+ {4, 7, 6, 5},
+ {7, 3, 2, 6},
+ {3, 0, 1, 2},
+ {1, 5, 6, 2},
+ {3, 7, 4, 0},
+ };
+
+ MLoop *mloop = result->mloop;
+ for (int i = 0; i < 6; ++i) {
+ for (int j = 0; j < 4; ++j, ++mloop) {
+ mloop->v = loops_v[i][j];
+ }
+ }
+
+ MPoly *mpoly = result->mpoly;
+ for (int i = 0; i < 6; ++i) {
+ mpoly[i].loopstart = i * 4;
+ mpoly[i].totloop = 4;
+ }
+
+ BKE_mesh_calc_edges(result, false, false);
+
+ return result;
+}
+
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
#if defined(WITH_USD) || defined(WITH_ALEMBIC)
@@ -143,6 +184,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
+ /* Do not process data if using a render procedural, return a box instead for displaying in the
+ * viewport. */
+ if (BKE_cache_file_uses_render_procedural(cache_file, scene, DEG_get_mode(ctx->depsgraph))) {
+ return generate_bounding_box_mesh(ctx->object, org_mesh);
+ }
+
/* If this invocation is for the ORCO mesh, and the mesh hasn't changed topology, we
* must return the mesh as-is instead of deforming it. */
if (ctx->flag & MOD_APPLY_ORCO) {
@@ -223,18 +270,20 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
return result ? result : mesh;
#else
- UNUSED_VARS(ctx, md);
+ UNUSED_VARS(ctx, md, generate_bounding_box_mesh);
return mesh;
#endif
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(Scene *scene, ModifierData *md, const int dag_eval_mode)
{
#if defined(WITH_USD) || defined(WITH_ALEMBIC)
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
- return (mcmd->cache_file != NULL);
+ /* Do not evaluate animations if using the render engine procedural. */
+ return (mcmd->cache_file != NULL) &&
+ !BKE_cache_file_uses_render_procedural(mcmd->cache_file, scene, dag_eval_mode);
#else
- UNUSED_VARS(md);
+ UNUSED_VARS(scene, md, dag_eval_mode);
return false;
#endif
}
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 02a52a39881..9d8630b21e7 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -84,7 +84,8 @@
#include "NOD_derived_node_tree.hh"
#include "NOD_geometry.h"
#include "NOD_geometry_nodes_eval_log.hh"
-#include "NOD_node_tree_multi_function.hh"
+
+#include "FN_multi_function.hh"
using blender::destruct_ptr;
using blender::float3;
@@ -691,7 +692,7 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree,
{
blender::ResourceScope scope;
blender::LinearAllocator<> &allocator = scope.linear_allocator();
- blender::nodes::MultiFunctionByNode mf_by_node = get_multi_function_per_node(tree, scope);
+ blender::nodes::NodeMultiFunctions mf_by_node{tree, scope};
Map<DOutputSocket, GMutablePointer> group_inputs;
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 47dfd9bc8f6..5646e37707c 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -836,7 +836,7 @@ class GeometryNodesEvaluator {
}
/* Use the multi-function implementation if it exists. */
- const MultiFunction *multi_function = params_.mf_by_node->lookup_default(node, nullptr);
+ const MultiFunction *multi_function = params_.mf_by_node->try_get(node);
if (multi_function != nullptr) {
this->execute_multi_function_node(node, *multi_function, node_state);
return;
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.hh b/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
index d8c60d31986..5151be07aa2 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
@@ -20,12 +20,14 @@
#include "NOD_derived_node_tree.hh"
#include "NOD_geometry_nodes_eval_log.hh"
-#include "NOD_node_tree_multi_function.hh"
+#include "NOD_multi_function.hh"
#include "FN_generic_pointer.hh"
#include "DNA_modifier_types.h"
+#include "FN_multi_function.hh"
+
namespace geo_log = blender::nodes::geometry_nodes_eval_log;
namespace blender::modifiers::geometry_nodes {
@@ -45,7 +47,7 @@ struct GeometryNodesEvaluationParams {
* necessary in all cases. Sometimes `log_socket_value_fn` might just want to look at the value
* and then it can be freed. */
Vector<DSocket> force_compute_sockets;
- nodes::MultiFunctionByNode *mf_by_node;
+ nodes::NodeMultiFunctions *mf_by_node;
const NodesModifierData *modifier_;
Depsgraph *depsgraph;
Object *self_object;
diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c
index e7750f0a0d1..1dbdcf87d63 100644
--- a/source/blender/modifiers/intern/MOD_normal_edit.c
+++ b/source/blender/modifiers/intern/MOD_normal_edit.c
@@ -556,15 +556,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
polynors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, num_polys);
CustomData_set_layer_flag(pdata, CD_NORMAL, CD_FLAG_TEMPORARY);
}
- BKE_mesh_calc_normals_poly(mvert,
- NULL,
- num_verts,
- mloop,
- mpoly,
- num_loops,
- num_polys,
- polynors,
- (result->runtime.cd_dirty_vert & CD_MASK_NORMAL) ? false : true);
+ if (result->runtime.cd_dirty_vert & CD_MASK_NORMAL) {
+ BKE_mesh_calc_normals_poly_and_vertex(
+ mvert, num_verts, mloop, num_loops, mpoly, num_polys, polynors, NULL);
+ }
+ else {
+ BKE_mesh_calc_normals_poly(mvert, num_verts, mloop, num_loops, mpoly, num_polys, polynors);
+ }
result->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
diff --git a/source/blender/modifiers/intern/MOD_softbody.c b/source/blender/modifiers/intern/MOD_softbody.c
index d7d2f948955..4187f9087a0 100644
--- a/source/blender/modifiers/intern/MOD_softbody.c
+++ b/source/blender/modifiers/intern/MOD_softbody.c
@@ -62,7 +62,9 @@ static void deformVerts(ModifierData *UNUSED(md),
ctx->depsgraph, scene, ctx->object, DEG_get_ctime(ctx->depsgraph), vertexCos, numVerts);
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c
index e97190b1878..00fa6e24a64 100644
--- a/source/blender/modifiers/intern/MOD_solidify_extrude.c
+++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c
@@ -259,14 +259,12 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
/* calculate only face normals */
poly_nors = MEM_malloc_arrayN(numPolys, sizeof(*poly_nors), __func__);
BKE_mesh_calc_normals_poly(orig_mvert,
- NULL,
(int)numVerts,
orig_mloop,
- orig_mpoly,
(int)numLoops,
+ orig_mpoly,
(int)numPolys,
- poly_nors,
- true);
+ poly_nors);
}
STACK_INIT(new_vert_arr, numVerts * 2);
@@ -507,8 +505,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
/* NOTE: copied vertex layers don't have flipped normals yet. do this after applying offset. */
if ((smd->flag & MOD_SOLIDIFY_EVEN) == 0) {
/* no even thickness, very simple */
- float scalar_short;
- float scalar_short_vgroup;
+ float ofs_new_vgroup;
/* for clamping */
float *vert_lens = NULL;
@@ -597,7 +594,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
uint i_orig, i_end;
bool do_shell_align;
- scalar_short = scalar_short_vgroup = ofs_new / 32767.0f;
+ ofs_new_vgroup = ofs_new;
INIT_VERT_ARRAY_OFFSETS(false);
@@ -606,36 +603,40 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (dvert) {
MDeformVert *dv = &dvert[i];
if (defgrp_invert) {
- scalar_short_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
+ ofs_new_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
}
else {
- scalar_short_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
+ ofs_new_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
}
- scalar_short_vgroup = (offset_fac_vg + (scalar_short_vgroup * offset_fac_vg_inv)) *
- scalar_short;
+ ofs_new_vgroup = (offset_fac_vg + (ofs_new_vgroup * offset_fac_vg_inv)) * ofs_new;
}
if (do_clamp && offset > FLT_EPSILON) {
/* always reset because we may have set before */
if (dvert == NULL) {
- scalar_short_vgroup = scalar_short;
+ ofs_new_vgroup = ofs_new;
}
if (do_angle_clamp) {
float cos_ang = cosf(((2 * M_PI) - vert_angs[i]) * 0.5f);
if (cos_ang > 0) {
float max_off = sqrtf(vert_lens[i]) * 0.5f / cos_ang;
if (max_off < offset * 0.5f) {
- scalar_short_vgroup *= max_off / offset * 2;
+ ofs_new_vgroup *= max_off / offset * 2;
}
}
}
else {
if (vert_lens[i] < offset_sq) {
float scalar = sqrtf(vert_lens[i]) / offset;
- scalar_short_vgroup *= scalar;
+ ofs_new_vgroup *= scalar;
}
}
}
- madd_v3v3short_fl(mv->co, mv->no, scalar_short_vgroup);
+ if (vert_nors) {
+ madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup);
+ }
+ else {
+ madd_v3v3short_fl(mv->co, mv->no, ofs_new_vgroup / 32767.0f);
+ }
}
}
@@ -643,7 +644,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
uint i_orig, i_end;
bool do_shell_align;
- scalar_short = scalar_short_vgroup = ofs_orig / 32767.0f;
+ ofs_new_vgroup = ofs_orig;
/* as above but swapped */
INIT_VERT_ARRAY_OFFSETS(true);
@@ -653,36 +654,40 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (dvert) {
MDeformVert *dv = &dvert[i];
if (defgrp_invert) {
- scalar_short_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
+ ofs_new_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
}
else {
- scalar_short_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
+ ofs_new_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
}
- scalar_short_vgroup = (offset_fac_vg + (scalar_short_vgroup * offset_fac_vg_inv)) *
- scalar_short;
+ ofs_new_vgroup = (offset_fac_vg + (ofs_new_vgroup * offset_fac_vg_inv)) * ofs_orig;
}
if (do_clamp && offset > FLT_EPSILON) {
/* always reset because we may have set before */
if (dvert == NULL) {
- scalar_short_vgroup = scalar_short;
+ ofs_new_vgroup = ofs_orig;
}
if (do_angle_clamp) {
float cos_ang = cosf(vert_angs[i_orig] * 0.5f);
if (cos_ang > 0) {
float max_off = sqrtf(vert_lens[i]) * 0.5f / cos_ang;
if (max_off < offset * 0.5f) {
- scalar_short_vgroup *= max_off / offset * 2;
+ ofs_new_vgroup *= max_off / offset * 2;
}
}
}
else {
if (vert_lens[i] < offset_sq) {
float scalar = sqrtf(vert_lens[i]) / offset;
- scalar_short_vgroup *= scalar;
+ ofs_new_vgroup *= scalar;
}
}
}
- madd_v3v3short_fl(mv->co, mv->no, scalar_short_vgroup);
+ if (vert_nors) {
+ madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup);
+ }
+ else {
+ madd_v3v3short_fl(mv->co, mv->no, ofs_new_vgroup / 32767.0f);
+ }
}
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index 18d308e5f02..5b4716a1a43 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -211,15 +211,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
/* Calculate only face normals. */
poly_nors = MEM_malloc_arrayN(numPolys, sizeof(*poly_nors), __func__);
- BKE_mesh_calc_normals_poly(orig_mvert,
- NULL,
- (int)numVerts,
- orig_mloop,
- orig_mpoly,
- (int)numLoops,
- (int)numPolys,
- poly_nors,
- true);
+ BKE_mesh_calc_normals_poly(
+ orig_mvert, (int)numVerts, orig_mloop, (int)numLoops, orig_mpoly, (int)numPolys, poly_nors);
NewFaceRef *face_sides_arr = MEM_malloc_arrayN(
numPolys * 2, sizeof(*face_sides_arr), "face_sides_arr in solidify");
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index ce427281db3..db0b769684e 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -358,13 +358,8 @@ static bool get_show_adaptive_options(const bContext *C, Panel *panel)
/* Don't show adaptive options if the cycles experimental feature set is disabled. */
Scene *scene = CTX_data_scene(C);
- PointerRNA scene_ptr;
- RNA_id_pointer_create(&scene->id, &scene_ptr);
- if (BKE_scene_uses_cycles(scene)) {
- PointerRNA cycles_ptr = RNA_pointer_get(&scene_ptr, "cycles");
- if (RNA_enum_get(&cycles_ptr, "feature_set") != 1) { /* EXPERIMENTAL */
- return false;
- }
+ if (!BKE_scene_uses_cycles_experimental_features(scene)) {
+ return false;
}
return true;
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index bfd4cd81803..3f2d0a06db8 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -98,7 +98,9 @@ static void freeData(ModifierData *md)
}
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c
index 9f86727ce0a..2c28e9710ef 100644
--- a/source/blender/modifiers/intern/MOD_uvproject.c
+++ b/source/blender/modifiers/intern/MOD_uvproject.c
@@ -72,7 +72,7 @@ static void requiredDataMask(Object *UNUSED(ob),
CustomData_MeshMasks *r_cddata_masks)
{
/* ask for UV coordinates */
- r_cddata_masks->lmask |= CD_MLOOPUV;
+ r_cddata_masks->lmask |= CD_MASK_MLOOPUV;
}
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
diff --git a/source/blender/modifiers/intern/MOD_volume_displace.cc b/source/blender/modifiers/intern/MOD_volume_displace.cc
index af4b31d6bfc..fcf75040a9a 100644
--- a/source/blender/modifiers/intern/MOD_volume_displace.cc
+++ b/source/blender/modifiers/intern/MOD_volume_displace.cc
@@ -95,7 +95,9 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void
walk(userData, ob, md, "texture");
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
VolumeDisplaceModifierData *vdmd = reinterpret_cast<VolumeDisplaceModifierData *>(md);
if (vdmd->texture) {
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index 3bebc52c503..25e33b22bde 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -116,7 +116,9 @@ static void matrix_from_obj_pchan(float mat[4][4],
}
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
WarpModifierData *wmd = (WarpModifierData *)md;
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index cf4c195c66d..03f8e3a1dfb 100644
--- a/source/blender/modifiers/intern/MOD_wave.c
+++ b/source/blender/modifiers/intern/MOD_wave.c
@@ -70,7 +70,9 @@ static void initData(ModifierData *md)
MEMCPY_STRUCT_AFTER(wmd, DNA_struct_default_get(WaveModifierData), modifier);
}
-static bool dependsOnTime(ModifierData *UNUSED(md))
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *UNUSED(md),
+ const int UNUSED(dag_eval_mode))
{
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c
index 3b147c69716..1ee64b935b7 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.c
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.c
@@ -615,8 +615,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
polynors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, numPolys);
CustomData_set_layer_flag(pdata, CD_NORMAL, CD_FLAG_TEMPORARY);
}
- BKE_mesh_calc_normals_poly(
- mvert, NULL, numVerts, mloop, mpoly, numLoops, numPolys, polynors, false);
+ BKE_mesh_calc_normals_poly_and_vertex(
+ mvert, numVerts, mloop, numLoops, mpoly, numPolys, polynors, NULL);
const float split_angle = mesh->smoothresh;
short(*clnors)[2];
diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c
index 093fa118ee0..a9d01c64ff1 100644
--- a/source/blender/modifiers/intern/MOD_weightvgedit.c
+++ b/source/blender/modifiers/intern/MOD_weightvgedit.c
@@ -112,7 +112,9 @@ static void requiredDataMask(Object *UNUSED(ob),
/* No need to ask for CD_PREVIEW_MLOOPCOL... */
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md;
diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c
index 7aae089fa18..b369b82ebb7 100644
--- a/source/blender/modifiers/intern/MOD_weightvgmix.c
+++ b/source/blender/modifiers/intern/MOD_weightvgmix.c
@@ -154,7 +154,9 @@ static void requiredDataMask(Object *UNUSED(ob),
/* No need to ask for CD_PREVIEW_MLOOPCOL... */
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index 6e78774269a..7ee19e1c537 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -362,7 +362,9 @@ static void requiredDataMask(Object *UNUSED(ob),
/* No need to ask for CD_PREVIEW_MLOOPCOL... */
}
-static bool dependsOnTime(ModifierData *md)
+static bool dependsOnTime(struct Scene *UNUSED(scene),
+ ModifierData *md,
+ const int UNUSED(dag_eval_mode))
{
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md;
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 46fb9f54bfe..8680fcee49a 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -345,11 +345,10 @@ set(SRC
intern/node_common.c
intern/node_exec.cc
intern/node_geometry_exec.cc
+ intern/node_multi_function.cc
intern/node_socket.cc
- intern/node_tree_multi_function.cc
intern/node_tree_ref.cc
intern/node_util.c
- intern/type_callbacks.cc
intern/type_conversions.cc
composite/node_composite_util.h
@@ -366,13 +365,12 @@ set(SRC
NOD_geometry_exec.hh
NOD_geometry_nodes_eval_log.hh
NOD_math_functions.hh
- NOD_node_tree_multi_function.hh
+ NOD_multi_function.hh
NOD_node_tree_ref.hh
NOD_shader.h
NOD_socket.h
NOD_static_types.h
NOD_texture.h
- NOD_type_callbacks.hh
NOD_type_conversions.hh
intern/node_common.h
intern/node_exec.h
diff --git a/source/blender/nodes/NOD_multi_function.hh b/source/blender/nodes/NOD_multi_function.hh
new file mode 100644
index 00000000000..2f4b104fb4c
--- /dev/null
+++ b/source/blender/nodes/NOD_multi_function.hh
@@ -0,0 +1,130 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "FN_multi_function.hh"
+
+#include "DNA_node_types.h"
+
+#include "NOD_derived_node_tree.hh"
+
+namespace blender::nodes {
+
+using namespace fn::multi_function_types;
+
+class NodeMultiFunctions;
+
+/**
+ * Utility class to help nodes build a multi-function for themselves.
+ */
+class NodeMultiFunctionBuilder : NonCopyable, NonMovable {
+ private:
+ ResourceScope &resource_scope_;
+ bNode &node_;
+ bNodeTree &tree_;
+ const MultiFunction *built_fn_ = nullptr;
+
+ friend NodeMultiFunctions;
+
+ public:
+ NodeMultiFunctionBuilder(ResourceScope &resource_scope, bNode &node, bNodeTree &tree);
+
+ /**
+ * Assign a multi-function for the current node. The input and output parameters of the function
+ * have to match the available sockets in the node.
+ */
+ void set_matching_fn(const MultiFunction *fn);
+ void set_matching_fn(const MultiFunction &fn);
+
+ /**
+ * Utility method for creating and assigning a multi-function when it can't have a static
+ * lifetime.
+ */
+ template<typename T, typename... Args> void construct_and_set_matching_fn(Args &&...args);
+
+ bNode &node();
+ bNodeTree &tree();
+
+ ResourceScope &resource_scope();
+};
+
+/**
+ * Gives access to multi-functions for all nodes in a node tree that support them.
+ */
+class NodeMultiFunctions {
+ private:
+ Map<const bNode *, const MultiFunction *> map_;
+
+ public:
+ NodeMultiFunctions(const DerivedNodeTree &tree, ResourceScope &resource_scope);
+
+ const MultiFunction *try_get(const DNode &node) const;
+};
+
+/* --------------------------------------------------------------------
+ * NodeMultiFunctionBuilder inline methods.
+ */
+
+inline NodeMultiFunctionBuilder::NodeMultiFunctionBuilder(ResourceScope &resource_scope,
+ bNode &node,
+ bNodeTree &tree)
+ : resource_scope_(resource_scope), node_(node), tree_(tree)
+{
+}
+
+inline bNode &NodeMultiFunctionBuilder::node()
+{
+ return node_;
+}
+
+inline bNodeTree &NodeMultiFunctionBuilder::tree()
+{
+ return tree_;
+}
+
+inline ResourceScope &NodeMultiFunctionBuilder::resource_scope()
+{
+ return resource_scope_;
+}
+
+inline void NodeMultiFunctionBuilder::set_matching_fn(const MultiFunction *fn)
+{
+ built_fn_ = fn;
+}
+
+inline void NodeMultiFunctionBuilder::set_matching_fn(const MultiFunction &fn)
+{
+ this->set_matching_fn(&fn);
+}
+
+template<typename T, typename... Args>
+inline void NodeMultiFunctionBuilder::construct_and_set_matching_fn(Args &&...args)
+{
+ const T &fn = resource_scope_.construct<T>(__func__, std::forward<Args>(args)...);
+ this->set_matching_fn(&fn);
+}
+
+/* --------------------------------------------------------------------
+ * NodeMultiFunctions inline methods.
+ */
+
+inline const MultiFunction *NodeMultiFunctions::try_get(const DNode &node) const
+{
+ return map_.lookup_default(node->bnode(), nullptr);
+}
+
+} // namespace blender::nodes
diff --git a/source/blender/nodes/NOD_node_tree_multi_function.hh b/source/blender/nodes/NOD_node_tree_multi_function.hh
deleted file mode 100644
index 7eeeaef0b98..00000000000
--- a/source/blender/nodes/NOD_node_tree_multi_function.hh
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-/** \file
- * \ingroup nodes
- *
- * This file allows you to generate a multi-function network from a user-generated node tree.
- */
-
-#include "FN_multi_function_builder.hh"
-#include "FN_multi_function_network.hh"
-
-#include "NOD_derived_node_tree.hh"
-#include "NOD_type_callbacks.hh"
-
-#include "BLI_multi_value_map.hh"
-#include "BLI_resource_scope.hh"
-
-namespace blender::nodes {
-
-/**
- * A MFNetworkTreeMap maps various components of a node tree to components of a fn::MFNetwork. This
- * is necessary for further processing of a multi-function network that has been generated from a
- * node tree.
- */
-class MFNetworkTreeMap {
- private:
- /**
- * Store by id instead of using a hash table to avoid unnecessary hash table lookups.
- *
- * Input sockets in a node tree can have multiple corresponding sockets in the generated
- * MFNetwork. This is because nodes are allowed to expand into multiple multi-function nodes.
- */
- const DerivedNodeTree &tree_;
- fn::MFNetwork &network_;
- MultiValueMap<DSocket, fn::MFSocket *> sockets_by_dsocket_;
-
- public:
- MFNetworkTreeMap(const DerivedNodeTree &tree, fn::MFNetwork &network)
- : tree_(tree), network_(network)
- {
- }
-
- const DerivedNodeTree &tree() const
- {
- return tree_;
- }
-
- const fn::MFNetwork &network() const
- {
- return network_;
- }
-
- fn::MFNetwork &network()
- {
- return network_;
- }
-
- void add(const DSocket &dsocket, fn::MFSocket &socket)
- {
- BLI_assert(dsocket->is_input() == socket.is_input());
- BLI_assert(dsocket->is_input() || sockets_by_dsocket_.lookup(dsocket).is_empty());
- sockets_by_dsocket_.add(dsocket, &socket);
- }
-
- void add(const DInputSocket &dsocket, fn::MFInputSocket &socket)
- {
- sockets_by_dsocket_.add(dsocket, &socket);
- }
-
- void add(const DOutputSocket &dsocket, fn::MFOutputSocket &socket)
- {
- /* There can be at most one matching output socket. */
- BLI_assert(sockets_by_dsocket_.lookup(dsocket).is_empty());
- sockets_by_dsocket_.add(dsocket, &socket);
- }
-
- void add(const DTreeContext &context,
- Span<const InputSocketRef *> dsockets,
- Span<fn::MFInputSocket *> sockets)
- {
- assert_same_size(dsockets, sockets);
- for (int i : dsockets.index_range()) {
- this->add(DInputSocket(&context, dsockets[i]), *sockets[i]);
- }
- }
-
- void add(const DTreeContext &context,
- Span<const OutputSocketRef *> dsockets,
- Span<fn::MFOutputSocket *> sockets)
- {
- assert_same_size(dsockets, sockets);
- for (int i : dsockets.index_range()) {
- this->add(DOutputSocket(&context, dsockets[i]), *sockets[i]);
- }
- }
-
- void add_try_match(const DNode &dnode, fn::MFNode &node)
- {
- this->add_try_match(*dnode.context(),
- dnode->inputs().cast<const SocketRef *>(),
- node.inputs().cast<fn::MFSocket *>());
- this->add_try_match(*dnode.context(),
- dnode->outputs().cast<const SocketRef *>(),
- node.outputs().cast<fn::MFSocket *>());
- }
-
- void add_try_match(const DTreeContext &context,
- Span<const InputSocketRef *> dsockets,
- Span<fn::MFInputSocket *> sockets)
- {
- this->add_try_match(
- context, dsockets.cast<const SocketRef *>(), sockets.cast<fn::MFSocket *>());
- }
-
- void add_try_match(const DTreeContext &context,
- Span<const OutputSocketRef *> dsockets,
- Span<fn::MFOutputSocket *> sockets)
- {
- this->add_try_match(
- context, dsockets.cast<const SocketRef *>(), sockets.cast<fn::MFSocket *>());
- }
-
- void add_try_match(const DTreeContext &context,
- Span<const SocketRef *> dsockets,
- Span<fn::MFSocket *> sockets)
- {
- int used_sockets = 0;
- for (const SocketRef *dsocket : dsockets) {
- if (!dsocket->is_available()) {
- continue;
- }
- if (!socket_is_mf_data_socket(*dsocket->typeinfo())) {
- continue;
- }
- fn::MFSocket *socket = sockets[used_sockets];
- this->add(DSocket(&context, dsocket), *socket);
- used_sockets++;
- }
- }
-
- fn::MFOutputSocket &lookup(const DOutputSocket &dsocket)
- {
- return sockets_by_dsocket_.lookup(dsocket)[0]->as_output();
- }
-
- Span<fn::MFInputSocket *> lookup(const DInputSocket &dsocket)
- {
- return sockets_by_dsocket_.lookup(dsocket).cast<fn::MFInputSocket *>();
- }
-
- fn::MFInputSocket &lookup_dummy(const DInputSocket &dsocket)
- {
- Span<fn::MFInputSocket *> sockets = this->lookup(dsocket);
- BLI_assert(sockets.size() == 1);
- fn::MFInputSocket &socket = *sockets[0];
- BLI_assert(socket.node().is_dummy());
- return socket;
- }
-
- fn::MFOutputSocket &lookup_dummy(const DOutputSocket &dsocket)
- {
- fn::MFOutputSocket &socket = this->lookup(dsocket);
- BLI_assert(socket.node().is_dummy());
- return socket;
- }
-
- bool is_mapped(const DSocket &dsocket) const
- {
- return !sockets_by_dsocket_.lookup(dsocket).is_empty();
- }
-};
-
-/**
- * This data is necessary throughout the generation of a MFNetwork from a node tree.
- */
-struct CommonMFNetworkBuilderData {
- ResourceScope &scope;
- fn::MFNetwork &network;
- MFNetworkTreeMap &network_map;
- const DerivedNodeTree &tree;
-};
-
-class MFNetworkBuilderBase {
- protected:
- CommonMFNetworkBuilderData &common_;
-
- public:
- MFNetworkBuilderBase(CommonMFNetworkBuilderData &common) : common_(common)
- {
- }
-
- /**
- * Returns the network that is currently being built.
- */
- fn::MFNetwork &network()
- {
- return common_.network;
- }
-
- /**
- * Returns the map between the node tree and the multi-function network that is being built.
- */
- MFNetworkTreeMap &network_map()
- {
- return common_.network_map;
- }
-
- /**
- * Returns a resource collector that will only be destructed after the multi-function network is
- * destructed.
- */
- ResourceScope &resource_scope()
- {
- return common_.scope;
- }
-
- /**
- * Constructs a new function that will live at least as long as the MFNetwork.
- */
- template<typename T, typename... Args> T &construct_fn(Args &&...args)
- {
- BLI_STATIC_ASSERT((std::is_base_of_v<fn::MultiFunction, T>), "");
- void *buffer = common_.scope.linear_allocator().allocate(sizeof(T), alignof(T));
- T *fn = new (buffer) T(std::forward<Args>(args)...);
- common_.scope.add(destruct_ptr<T>(fn), fn->name().c_str());
- return *fn;
- }
-};
-
-/**
- * This class is used by socket implementations to define how an unlinked input socket is handled
- * in a multi-function network.
- */
-class SocketMFNetworkBuilder : public MFNetworkBuilderBase {
- private:
- bNodeSocket *bsocket_;
- fn::MFOutputSocket *built_socket_ = nullptr;
-
- public:
- SocketMFNetworkBuilder(CommonMFNetworkBuilderData &common, const DSocket &dsocket)
- : MFNetworkBuilderBase(common), bsocket_(dsocket->bsocket())
- {
- }
-
- /**
- * Returns the socket that is currently being built.
- */
- bNodeSocket &bsocket()
- {
- return *bsocket_;
- }
-
- /**
- * Utility method that returns bsocket->default_value for the current socket.
- */
- template<typename T> T *socket_default_value()
- {
- return static_cast<T *>(bsocket_->default_value);
- }
-
- /**
- * Builds a function node for that socket that outputs the given constant value.
- */
- template<typename T> void set_constant_value(T value)
- {
- this->construct_generator_fn<fn::CustomMF_Constant<T>>(std::move(value));
- }
- void set_constant_value(const CPPType &type, const void *value)
- {
- /* The value has live as long as the generated mf network. */
- this->construct_generator_fn<fn::CustomMF_GenericConstant>(type, value);
- }
-
- template<typename T, typename... Args> void construct_generator_fn(Args &&...args)
- {
- const fn::MultiFunction &fn = this->construct_fn<T>(std::forward<Args>(args)...);
- this->set_generator_fn(fn);
- }
-
- /**
- * Uses the first output of the given multi-function as value of the socket.
- */
- void set_generator_fn(const fn::MultiFunction &fn)
- {
- fn::MFFunctionNode &node = common_.network.add_function(fn);
- this->set_socket(node.output(0));
- }
-
- /**
- * Define a multi-function socket that outputs the value of the bsocket.
- */
- void set_socket(fn::MFOutputSocket &socket)
- {
- built_socket_ = &socket;
- }
-
- fn::MFOutputSocket *built_socket()
- {
- return built_socket_;
- }
-};
-
-/**
- * This class is used by node implementations to define how a user-level node expands into
- * multi-function nodes internally.
- */
-class NodeMFNetworkBuilder : public MFNetworkBuilderBase {
- private:
- DNode dnode_;
-
- public:
- NodeMFNetworkBuilder(CommonMFNetworkBuilderData &common, DNode dnode)
- : MFNetworkBuilderBase(common), dnode_(dnode)
- {
- }
-
- /**
- * Tells the builder to build a function that corresponds to the node that is being built. It
- * will try to match up sockets.
- */
- template<typename T, typename... Args> T &construct_and_set_matching_fn(Args &&...args)
- {
- T &function = this->construct_fn<T>(std::forward<Args>(args)...);
- this->set_matching_fn(function);
- return function;
- }
-
- const fn::MultiFunction &get_not_implemented_fn()
- {
- return this->get_default_fn("Not Implemented (" + dnode_->name() + ")");
- }
-
- const fn::MultiFunction &get_default_fn(StringRef name);
-
- const void set_not_implemented()
- {
- this->set_matching_fn(this->get_not_implemented_fn());
- }
-
- /**
- * Tells the builder that the given function corresponds to the node that is being built. It will
- * try to match up sockets. For that it skips unavailable and non-data sockets.
- */
- void set_matching_fn(const fn::MultiFunction &function)
- {
- fn::MFFunctionNode &node = common_.network.add_function(function);
- common_.network_map.add_try_match(dnode_, node);
- }
-
- /**
- * Returns the node that is currently being built.
- */
- bNode &bnode()
- {
- return *dnode_->bnode();
- }
-
- /**
- * Returns the node that is currently being built.
- */
- const DNode &dnode() const
- {
- return dnode_;
- }
-};
-
-MFNetworkTreeMap insert_node_tree_into_mf_network(fn::MFNetwork &network,
- const DerivedNodeTree &tree,
- ResourceScope &scope);
-
-using MultiFunctionByNode = Map<DNode, const fn::MultiFunction *>;
-MultiFunctionByNode get_multi_function_per_node(const DerivedNodeTree &tree, ResourceScope &scope);
-
-} // namespace blender::nodes
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 3852819746e..4da8648173d 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -337,7 +337,7 @@ DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POIN
DefNode(GeometryNode, GEO_NODE_RAYCAST, def_geo_raycast, "RAYCAST", Raycast, "Raycast", "")
DefNode(GeometryNode, GEO_NODE_SELECT_BY_MATERIAL, 0, "SELECT_BY_MATERIAL", SelectByMaterial, "Select by Material", "")
DefNode(GeometryNode, GEO_NODE_SEPARATE_COMPONENTS, 0, "SEPARATE_COMPONENTS", SeparateComponents, "Separate Components", "")
-DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, 0, "SUBDIVISION_SURFACE", SubdivisionSurface, "Subdivision Surface", "")
+DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, def_geo_subdivision_surface, "SUBDIVISION_SURFACE", SubdivisionSurface, "Subdivision Surface", "")
DefNode(GeometryNode, GEO_NODE_SWITCH, def_geo_switch, "SWITCH", Switch, "Switch", "")
DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "")
DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE", Triangulate, "Triangulate", "")
diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c
index d21e0938356..cc657d6f91d 100644
--- a/source/blender/nodes/composite/node_composite_tree.c
+++ b/source/blender/nodes/composite/node_composite_tree.c
@@ -67,7 +67,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
func(calldata, NODE_CLASS_OP_FILTER, N_("Filter"));
- func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor"));
+ func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
func(calldata, NODE_CLASS_MATTE, N_("Matte"));
func(calldata, NODE_CLASS_DISTORT, N_("Distort"));
func(calldata, NODE_CLASS_GROUP, N_("Group"));
diff --git a/source/blender/nodes/composite/nodes/node_composite_idMask.c b/source/blender/nodes/composite/nodes/node_composite_idMask.c
index a81dce10284..84563e7560b 100644
--- a/source/blender/nodes/composite/nodes/node_composite_idMask.c
+++ b/source/blender/nodes/composite/nodes/node_composite_idMask.c
@@ -38,7 +38,7 @@ void register_node_type_cmp_idmask(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_idmask_in, cmp_node_idmask_out);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/composite/nodes/node_composite_math.c b/source/blender/nodes/composite/nodes/node_composite_math.c
index c2982964a9f..2191c6bcdc3 100644
--- a/source/blender/nodes/composite/nodes/node_composite_math.c
+++ b/source/blender/nodes/composite/nodes/node_composite_math.c
@@ -36,7 +36,7 @@ void register_node_type_cmp_math(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_math_in, cmp_node_math_out);
node_type_label(&ntype, node_math_label);
node_type_update(&ntype, node_math_update);
diff --git a/source/blender/nodes/composite/nodes/node_composite_premulkey.c b/source/blender/nodes/composite/nodes/node_composite_premulkey.c
index b5dc15a2789..be76bbf01cf 100644
--- a/source/blender/nodes/composite/nodes/node_composite_premulkey.c
+++ b/source/blender/nodes/composite/nodes/node_composite_premulkey.c
@@ -38,7 +38,7 @@ void register_node_type_cmp_premulkey(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_premulkey_in, cmp_node_premulkey_out);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c
index 03d27caa701..001b197e23a 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c
@@ -40,7 +40,7 @@ void register_node_type_cmp_sephsva(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_sephsva_in, cmp_node_sephsva_out);
nodeRegisterType(&ntype);
@@ -63,7 +63,7 @@ void register_node_type_cmp_combhsva(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_combhsva_in, cmp_node_combhsva_out);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c
index ee8d6b0c186..e08f27db254 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c
@@ -40,7 +40,7 @@ void register_node_type_cmp_seprgba(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_seprgba_in, cmp_node_seprgba_out);
nodeRegisterType(&ntype);
@@ -63,7 +63,7 @@ void register_node_type_cmp_combrgba(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_combrgba_in, cmp_node_combrgba_out);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c
index a4aa6e4bf77..b3884296600 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c
@@ -43,7 +43,7 @@ void register_node_type_cmp_sepycca(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_sepycca_in, cmp_node_sepycca_out);
node_type_init(&ntype, node_composit_init_mode_sepycca);
@@ -72,7 +72,7 @@ void register_node_type_cmp_combycca(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_combycca_in, cmp_node_combycca_out);
node_type_init(&ntype, node_composit_init_mode_combycca);
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c
index 6c416b4f485..4da79ec7981 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c
@@ -38,7 +38,7 @@ void register_node_type_cmp_sepyuva(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_sepyuva_in, cmp_node_sepyuva_out);
nodeRegisterType(&ntype);
@@ -61,7 +61,7 @@ void register_node_type_cmp_combyuva(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_combyuva_in, cmp_node_combyuva_out);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/composite/nodes/node_composite_setalpha.c b/source/blender/nodes/composite/nodes/node_composite_setalpha.c
index 1488ff1a25f..1b44cc011e9 100644
--- a/source/blender/nodes/composite/nodes/node_composite_setalpha.c
+++ b/source/blender/nodes/composite/nodes/node_composite_setalpha.c
@@ -45,7 +45,7 @@ void register_node_type_cmp_setalpha(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SETALPHA, "Set Alpha", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_SETALPHA, "Set Alpha", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_setalpha_in, cmp_node_setalpha_out);
node_type_init(&ntype, node_composit_init_setalpha);
node_type_storage(
diff --git a/source/blender/nodes/composite/nodes/node_composite_switchview.c b/source/blender/nodes/composite/nodes/node_composite_switchview.c
index ec5c79cc087..b09d5119bc4 100644
--- a/source/blender/nodes/composite/nodes/node_composite_switchview.c
+++ b/source/blender/nodes/composite/nodes/node_composite_switchview.c
@@ -146,7 +146,7 @@ void register_node_type_cmp_switch_view(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SWITCH_VIEW, "Switch View", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_SWITCH_VIEW, "Switch View", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, NULL, cmp_node_switch_view_out);
ntype.initfunc_api = init_switch_view;
diff --git a/source/blender/nodes/composite/nodes/node_composite_valToRgb.c b/source/blender/nodes/composite/nodes/node_composite_valToRgb.c
index 0d46341b610..ed6dbfa2bf3 100644
--- a/source/blender/nodes/composite/nodes/node_composite_valToRgb.c
+++ b/source/blender/nodes/composite/nodes/node_composite_valToRgb.c
@@ -43,7 +43,7 @@ void register_node_type_cmp_valtorgb(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_valtorgb_in, cmp_node_valtorgb_out);
node_type_size(&ntype, 240, 200, 320);
node_type_init(&ntype, node_composit_init_valtorgb);
@@ -66,7 +66,7 @@ void register_node_type_cmp_rgbtobw(void)
{
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
+ cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, cmp_node_rgbtobw_in, cmp_node_rgbtobw_out);
node_type_size_preset(&ntype, NODE_SIZE_SMALL);
diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh
index 9fbd6712827..96a8f29c3e9 100644
--- a/source/blender/nodes/function/node_function_util.hh
+++ b/source/blender/nodes/function/node_function_util.hh
@@ -30,7 +30,7 @@
#include "BLT_translation.h"
#include "NOD_function.h"
-#include "NOD_node_tree_multi_function.hh"
+#include "NOD_multi_function.hh"
#include "node_util.h"
diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
index 7a83ff8e016..58e7d82beea 100644
--- a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
+++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
@@ -58,7 +58,7 @@ static void node_boolean_math_label(bNodeTree *UNUSED(ntree), bNode *node, char
BLI_strncpy(label, IFACE_(name), maxlen);
}
-static const blender::fn::MultiFunction &get_multi_function(bNode &bnode)
+static const blender::fn::MultiFunction *get_multi_function(bNode &bnode)
{
static blender::fn::CustomMF_SI_SI_SO<bool, bool, bool> and_fn{
"And", [](bool a, bool b) { return a && b; }};
@@ -68,20 +68,21 @@ static const blender::fn::MultiFunction &get_multi_function(bNode &bnode)
switch (bnode.custom1) {
case NODE_BOOLEAN_MATH_AND:
- return and_fn;
+ return &and_fn;
case NODE_BOOLEAN_MATH_OR:
- return or_fn;
+ return &or_fn;
case NODE_BOOLEAN_MATH_NOT:
- return not_fn;
+ return &not_fn;
}
- BLI_assert(false);
- return blender::fn::dummy_multi_function;
+ BLI_assert_unreachable();
+ return nullptr;
}
-static void node_boolean_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void fn_node_boolean_math_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- const blender::fn::MultiFunction &fn = get_multi_function(builder.bnode());
+ const blender::fn::MultiFunction *fn = get_multi_function(builder.node());
builder.set_matching_fn(fn);
}
@@ -89,11 +90,11 @@ void register_node_type_fn_boolean_math()
{
static bNodeType ntype;
- fn_node_type_base(&ntype, FN_NODE_BOOLEAN_MATH, "Boolean Math", NODE_CLASS_CONVERTOR, 0);
+ fn_node_type_base(&ntype, FN_NODE_BOOLEAN_MATH, "Boolean Math", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, fn_node_boolean_math_in, fn_node_boolean_math_out);
node_type_label(&ntype, node_boolean_math_label);
node_type_update(&ntype, node_boolean_math_update);
- ntype.expand_in_mf_network = node_boolean_expand_in_mf_network;
+ ntype.build_multi_function = fn_node_boolean_math_build_multi_function;
ntype.draw_buttons = fn_node_boolean_math_layout;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/function/nodes/node_fn_float_compare.cc b/source/blender/nodes/function/nodes/node_fn_float_compare.cc
index 6c8df8f2ea0..918dd24e520 100644
--- a/source/blender/nodes/function/nodes/node_fn_float_compare.cc
+++ b/source/blender/nodes/function/nodes/node_fn_float_compare.cc
@@ -64,7 +64,7 @@ static void node_float_compare_label(bNodeTree *UNUSED(ntree),
BLI_strncpy(label, IFACE_(name), maxlen);
}
-static const blender::fn::MultiFunction &get_multi_function(bNode &node)
+static const blender::fn::MultiFunction *get_multi_function(bNode &node)
{
static blender::fn::CustomMF_SI_SI_SO<float, float, bool> less_than_fn{
"Less Than", [](float a, float b) { return a < b; }};
@@ -81,26 +81,27 @@ static const blender::fn::MultiFunction &get_multi_function(bNode &node)
switch (node.custom1) {
case NODE_FLOAT_COMPARE_LESS_THAN:
- return less_than_fn;
+ return &less_than_fn;
case NODE_FLOAT_COMPARE_LESS_EQUAL:
- return less_equal_fn;
+ return &less_equal_fn;
case NODE_FLOAT_COMPARE_GREATER_THAN:
- return greater_than_fn;
+ return &greater_than_fn;
case NODE_FLOAT_COMPARE_GREATER_EQUAL:
- return greater_equal_fn;
+ return &greater_equal_fn;
case NODE_FLOAT_COMPARE_EQUAL:
- return equal_fn;
+ return &equal_fn;
case NODE_FLOAT_COMPARE_NOT_EQUAL:
- return not_equal_fn;
+ return &not_equal_fn;
}
- BLI_assert(false);
- return blender::fn::dummy_multi_function;
+ BLI_assert_unreachable();
+ return nullptr;
}
-static void node_float_compare_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void fn_node_float_compare_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- const blender::fn::MultiFunction &fn = get_multi_function(builder.bnode());
+ const blender::fn::MultiFunction *fn = get_multi_function(builder.node());
builder.set_matching_fn(fn);
}
@@ -108,11 +109,11 @@ void register_node_type_fn_float_compare()
{
static bNodeType ntype;
- fn_node_type_base(&ntype, FN_NODE_FLOAT_COMPARE, "Float Compare", NODE_CLASS_CONVERTOR, 0);
+ fn_node_type_base(&ntype, FN_NODE_FLOAT_COMPARE, "Float Compare", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, fn_node_float_compare_in, fn_node_float_compare_out);
node_type_label(&ntype, node_float_compare_label);
node_type_update(&ntype, node_float_compare_update);
- ntype.expand_in_mf_network = node_float_compare_expand_in_mf_network;
+ ntype.build_multi_function = fn_node_float_compare_build_multi_function;
ntype.draw_buttons = geo_node_float_compare_layout;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/function/nodes/node_fn_float_to_int.cc b/source/blender/nodes/function/nodes/node_fn_float_to_int.cc
index 26cde576400..40b8f27f895 100644
--- a/source/blender/nodes/function/nodes/node_fn_float_to_int.cc
+++ b/source/blender/nodes/function/nodes/node_fn_float_to_int.cc
@@ -50,7 +50,7 @@ static void node_float_to_int_label(bNodeTree *UNUSED(ntree), bNode *node, char
BLI_strncpy(label, IFACE_(name), maxlen);
}
-static const blender::fn::MultiFunction &get_multi_function(bNode &bnode)
+static const blender::fn::MultiFunction *get_multi_function(bNode &bnode)
{
static blender::fn::CustomMF_SI_SO<float, int> round_fn{"Round",
[](float a) { return (int)round(a); }};
@@ -63,22 +63,23 @@ static const blender::fn::MultiFunction &get_multi_function(bNode &bnode)
switch (static_cast<FloatToIntRoundingMode>(bnode.custom1)) {
case FN_NODE_FLOAT_TO_INT_ROUND:
- return round_fn;
+ return &round_fn;
case FN_NODE_FLOAT_TO_INT_FLOOR:
- return floor_fn;
+ return &floor_fn;
case FN_NODE_FLOAT_TO_INT_CEIL:
- return ceil_fn;
+ return &ceil_fn;
case FN_NODE_FLOAT_TO_INT_TRUNCATE:
- return trunc_fn;
+ return &trunc_fn;
}
BLI_assert_unreachable();
- return blender::fn::dummy_multi_function;
+ return nullptr;
}
-static void node_float_to_int_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void fn_node_float_to_int_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- const blender::fn::MultiFunction &fn = get_multi_function(builder.bnode());
+ const blender::fn::MultiFunction *fn = get_multi_function(builder.node());
builder.set_matching_fn(fn);
}
@@ -86,10 +87,10 @@ void register_node_type_fn_float_to_int()
{
static bNodeType ntype;
- fn_node_type_base(&ntype, FN_NODE_FLOAT_TO_INT, "Float to Integer", NODE_CLASS_CONVERTOR, 0);
+ fn_node_type_base(&ntype, FN_NODE_FLOAT_TO_INT, "Float to Integer", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, fn_node_float_to_int_in, fn_node_float_to_int_out);
node_type_label(&ntype, node_float_to_int_label);
- ntype.expand_in_mf_network = node_float_to_int_expand_in_mf_network;
+ ntype.build_multi_function = fn_node_float_to_int_build_multi_function;
ntype.draw_buttons = fn_node_float_to_int_layout;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/function/nodes/node_fn_input_string.cc b/source/blender/nodes/function/nodes/node_fn_input_string.cc
index f16bdef2f38..560ace57aba 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_string.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_string.cc
@@ -29,14 +29,14 @@ static void fn_node_input_string_layout(uiLayout *layout, bContext *UNUSED(C), P
uiItemR(layout, ptr, "string", 0, "", ICON_NONE);
}
-static void fn_node_input_string_expand_in_mf_network(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static void fn_node_input_string_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.bnode();
+ bNode &bnode = builder.node();
NodeInputString *node_storage = static_cast<NodeInputString *>(bnode.storage);
std::string string = std::string((node_storage->string) ? node_storage->string : "");
-
- builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<std::string>>(string);
+ builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<std::string>>(
+ std::move(string));
}
static void fn_node_input_string_init(bNodeTree *UNUSED(ntree), bNode *node)
@@ -78,7 +78,7 @@ void register_node_type_fn_input_string()
node_type_socket_templates(&ntype, nullptr, fn_node_input_string_out);
node_type_init(&ntype, fn_node_input_string_init);
node_type_storage(&ntype, "NodeInputString", fn_node_input_string_free, fn_node_string_copy);
- ntype.expand_in_mf_network = fn_node_input_string_expand_in_mf_network;
+ ntype.build_multi_function = fn_node_input_string_build_multi_function;
ntype.draw_buttons = fn_node_input_string_layout;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/function/nodes/node_fn_input_vector.cc b/source/blender/nodes/function/nodes/node_fn_input_vector.cc
index 2cd4eb1d9df..244c045de9a 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_vector.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_vector.cc
@@ -32,16 +32,14 @@ static void fn_node_input_vector_layout(uiLayout *layout, bContext *UNUSED(C), P
uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE);
}
-static void fn_node_vector_input_expand_in_mf_network(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static void fn_node_vector_input_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.bnode();
+ bNode &bnode = builder.node();
NodeInputVector *node_storage = static_cast<NodeInputVector *>(bnode.storage);
blender::float3 vector(node_storage->vector);
-
builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<blender::float3>>(vector);
}
-
static void fn_node_input_vector_init(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeInputVector *data = (NodeInputVector *)MEM_callocN(sizeof(NodeInputVector),
@@ -58,7 +56,7 @@ void register_node_type_fn_input_vector()
node_type_init(&ntype, fn_node_input_vector_init);
node_type_storage(
&ntype, "NodeInputVector", node_free_standard_storage, node_copy_standard_storage);
- ntype.expand_in_mf_network = fn_node_vector_input_expand_in_mf_network;
+ ntype.build_multi_function = fn_node_vector_input_build_multi_function;
ntype.draw_buttons = fn_node_input_vector_layout;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/function/nodes/node_fn_random_float.cc b/source/blender/nodes/function/nodes/node_fn_random_float.cc
index a3c9f44b6a1..47ec9adf6bd 100644
--- a/source/blender/nodes/function/nodes/node_fn_random_float.cc
+++ b/source/blender/nodes/function/nodes/node_fn_random_float.cc
@@ -67,10 +67,11 @@ class RandomFloatFunction : public blender::fn::MultiFunction {
}
};
-static void fn_node_random_float_expand_in_mf_network(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static void fn_node_random_float_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- builder.construct_and_set_matching_fn<RandomFloatFunction>();
+ static RandomFloatFunction fn;
+ builder.set_matching_fn(fn);
}
void register_node_type_fn_random_float()
@@ -79,6 +80,6 @@ void register_node_type_fn_random_float()
fn_node_type_base(&ntype, FN_NODE_RANDOM_FLOAT, "Random Float", 0, 0);
node_type_socket_templates(&ntype, fn_node_random_float_in, fn_node_random_float_out);
- ntype.expand_in_mf_network = fn_node_random_float_expand_in_mf_network;
+ ntype.build_multi_function = fn_node_random_float_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/geometry/node_geometry_tree.cc b/source/blender/nodes/geometry/node_geometry_tree.cc
index 07a89a1fa8c..d6b23c38ee4 100644
--- a/source/blender/nodes/geometry/node_geometry_tree.cc
+++ b/source/blender/nodes/geometry/node_geometry_tree.cc
@@ -80,7 +80,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_ATTRIBUTE, N_("Attribute"));
func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
- func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor"));
+ func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc
index e0a3f5ad334..5f02061da97 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc
@@ -30,7 +30,7 @@
static bNodeSocketTemplate geo_node_attribute_sample_texture_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
- {SOCK_TEXTURE, N_("Texture")},
+ {SOCK_TEXTURE, N_("Texture"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, PROP_NONE, SOCK_HIDE_LABEL},
{SOCK_STRING, N_("Mapping")},
{SOCK_STRING, N_("Result")},
{-1, ""},
diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
index 0c1d8645411..88e3bf17d43 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
@@ -63,20 +63,20 @@ static void geo_node_raycast_init(bNodeTree *UNUSED(tree), bNode *node)
node->storage = data;
}
+namespace blender::nodes {
+
static void geo_node_raycast_update(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeGeometryRaycast *node_storage = (NodeGeometryRaycast *)node->storage;
- blender::nodes::update_attribute_input_socket_availabilities(
+ update_attribute_input_socket_availabilities(
*node,
"Ray Direction",
(GeometryNodeAttributeInputMode)node_storage->input_type_ray_direction);
- blender::nodes::update_attribute_input_socket_availabilities(
+ update_attribute_input_socket_availabilities(
*node, "Ray Length", (GeometryNodeAttributeInputMode)node_storage->input_type_ray_length);
}
-namespace blender::nodes {
-
-static void raycast_to_mesh(const Mesh *mesh,
+static void raycast_to_mesh(const Mesh &mesh,
const VArray<float3> &ray_origins,
const VArray<float3> &ray_directions,
const VArray<float> &ray_lengths,
@@ -95,62 +95,64 @@ static void raycast_to_mesh(const Mesh *mesh,
BLI_assert(ray_origins.size() == r_hit_distances.size() || r_hit_distances.is_empty());
BVHTreeFromMesh tree_data;
- BKE_bvhtree_from_mesh_get(&tree_data, mesh, BVHTREE_FROM_LOOPTRI, 4);
-
- if (tree_data.tree != nullptr) {
- for (const int i : ray_origins.index_range()) {
- const float ray_length = ray_lengths[i];
- const float3 ray_origin = ray_origins[i];
- const float3 ray_direction = ray_directions[i].normalized();
-
- BVHTreeRayHit hit;
- hit.index = -1;
- hit.dist = ray_length;
- if (BLI_bvhtree_ray_cast(tree_data.tree,
- ray_origin,
- ray_direction,
- 0.0f,
- &hit,
- tree_data.raycast_callback,
- &tree_data) != -1) {
- if (!r_hit.is_empty()) {
- r_hit[i] = hit.index >= 0;
- }
- if (!r_hit_indices.is_empty()) {
- /* Index should always be a valid looptri index, use 0 when hit failed. */
- r_hit_indices[i] = max_ii(hit.index, 0);
- }
- if (!r_hit_positions.is_empty()) {
- r_hit_positions[i] = hit.co;
- }
- if (!r_hit_normals.is_empty()) {
- r_hit_normals[i] = hit.no;
- }
- if (!r_hit_distances.is_empty()) {
- r_hit_distances[i] = hit.dist;
- }
+ BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_LOOPTRI, 4);
+ if (tree_data.tree == nullptr) {
+ free_bvhtree_from_mesh(&tree_data);
+ return;
+ }
+
+ for (const int i : ray_origins.index_range()) {
+ const float ray_length = ray_lengths[i];
+ const float3 ray_origin = ray_origins[i];
+ const float3 ray_direction = ray_directions[i].normalized();
+
+ BVHTreeRayHit hit;
+ hit.index = -1;
+ hit.dist = ray_length;
+ if (BLI_bvhtree_ray_cast(tree_data.tree,
+ ray_origin,
+ ray_direction,
+ 0.0f,
+ &hit,
+ tree_data.raycast_callback,
+ &tree_data) != -1) {
+ if (!r_hit.is_empty()) {
+ r_hit[i] = hit.index >= 0;
+ }
+ if (!r_hit_indices.is_empty()) {
+ /* Index should always be a valid looptri index, use 0 when hit failed. */
+ r_hit_indices[i] = max_ii(hit.index, 0);
+ }
+ if (!r_hit_positions.is_empty()) {
+ r_hit_positions[i] = hit.co;
}
- else {
- if (!r_hit.is_empty()) {
- r_hit[i] = false;
- }
- if (!r_hit_indices.is_empty()) {
- r_hit_indices[i] = 0;
- }
- if (!r_hit_positions.is_empty()) {
- r_hit_positions[i] = float3(0.0f, 0.0f, 0.0f);
- }
- if (!r_hit_normals.is_empty()) {
- r_hit_normals[i] = float3(0.0f, 0.0f, 0.0f);
- }
- if (!r_hit_distances.is_empty()) {
- r_hit_distances[i] = ray_length;
- }
+ if (!r_hit_normals.is_empty()) {
+ r_hit_normals[i] = hit.no;
+ }
+ if (!r_hit_distances.is_empty()) {
+ r_hit_distances[i] = hit.dist;
+ }
+ }
+ else {
+ if (!r_hit.is_empty()) {
+ r_hit[i] = false;
+ }
+ if (!r_hit_indices.is_empty()) {
+ r_hit_indices[i] = 0;
+ }
+ if (!r_hit_positions.is_empty()) {
+ r_hit_positions[i] = float3(0.0f, 0.0f, 0.0f);
+ }
+ if (!r_hit_normals.is_empty()) {
+ r_hit_normals[i] = float3(0.0f, 0.0f, 0.0f);
+ }
+ if (!r_hit_distances.is_empty()) {
+ r_hit_distances[i] = ray_length;
}
}
-
- free_bvhtree_from_mesh(&tree_data);
}
+
+ free_bvhtree_from_mesh(&tree_data);
}
static bke::mesh_surface_sample::eAttributeMapMode get_map_mode(
@@ -166,7 +168,7 @@ static bke::mesh_surface_sample::eAttributeMapMode get_map_mode(
}
static void raycast_from_points(const GeoNodeExecParams &params,
- const GeometrySet &src_geometry,
+ const GeometrySet &target_geometry,
GeometryComponent &dst_component,
const StringRef hit_name,
const StringRef hit_position_name,
@@ -177,7 +179,8 @@ static void raycast_from_points(const GeoNodeExecParams &params,
{
BLI_assert(hit_attribute_names.size() == hit_attribute_output_names.size());
- const MeshComponent *src_mesh_component = src_geometry.get_component_for_read<MeshComponent>();
+ const MeshComponent *src_mesh_component =
+ target_geometry.get_component_for_read<MeshComponent>();
if (src_mesh_component == nullptr) {
return;
}
@@ -211,8 +214,7 @@ static void raycast_from_points(const GeoNodeExecParams &params,
dst_component.attribute_try_get_for_output_only<float>(hit_distance_name, result_domain);
/* Positions and looptri indices are always needed for interpolation,
- * so create temporary arrays if no output attribute is given.
- */
+ * so create temporary arrays if no output attribute is given. */
Array<int> hit_indices;
Array<float3> hit_positions_internal;
if (!hit_attribute_names.is_empty()) {
@@ -232,7 +234,7 @@ static void raycast_from_points(const GeoNodeExecParams &params,
hit_distance_attribute.as_span() :
MutableSpan<float>();
- raycast_to_mesh(src_mesh,
+ raycast_to_mesh(*src_mesh,
ray_origins,
ray_directions,
ray_lengths,
@@ -268,34 +270,32 @@ static void raycast_from_points(const GeoNodeExecParams &params,
static void geo_node_raycast_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
- GeometrySet cast_geometry_set = params.extract_input<GeometrySet>("Target Geometry");
+ GeometrySet target_geometry_set = params.extract_input<GeometrySet>("Target Geometry");
const std::string hit_name = params.extract_input<std::string>("Is Hit");
const std::string hit_position_name = params.extract_input<std::string>("Hit Position");
const std::string hit_normal_name = params.extract_input<std::string>("Hit Normal");
const std::string hit_distance_name = params.extract_input<std::string>("Hit Distance");
- const Array<std::string> hit_attribute_names = {
- params.extract_input<std::string>("Target Attribute")};
- const Array<std::string> hit_attribute_output_names = {
- params.extract_input<std::string>("Hit Attribute")};
+ const Array<std::string> hit_names = {params.extract_input<std::string>("Target Attribute")};
+ const Array<std::string> hit_output_names = {params.extract_input<std::string>("Hit Attribute")};
geometry_set = bke::geometry_set_realize_instances(geometry_set);
- cast_geometry_set = bke::geometry_set_realize_instances(cast_geometry_set);
+ target_geometry_set = bke::geometry_set_realize_instances(target_geometry_set);
- static const Array<GeometryComponentType> SupportedTypes = {
+ static const Array<GeometryComponentType> types = {
GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE};
- for (GeometryComponentType geo_type : SupportedTypes) {
- if (geometry_set.has(geo_type)) {
+ for (const GeometryComponentType type : types) {
+ if (geometry_set.has(type)) {
raycast_from_points(params,
- cast_geometry_set,
- geometry_set.get_component_for_write(geo_type),
+ target_geometry_set,
+ geometry_set.get_component_for_write(type),
hit_name,
hit_position_name,
hit_normal_name,
hit_distance_name,
- hit_attribute_names,
- hit_attribute_output_names);
+ hit_names,
+ hit_output_names);
}
}
@@ -312,7 +312,7 @@ void register_node_type_geo_raycast()
node_type_socket_templates(&ntype, geo_node_raycast_in, geo_node_raycast_out);
node_type_size_preset(&ntype, NODE_SIZE_LARGE);
node_type_init(&ntype, geo_node_raycast_init);
- node_type_update(&ntype, geo_node_raycast_update);
+ node_type_update(&ntype, blender::nodes::geo_node_raycast_update);
node_type_storage(
&ntype, "NodeGeometryRaycast", node_free_standard_storage, node_copy_standard_storage);
ntype.geometry_node_execute = blender::nodes::geo_node_raycast_exec;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
index a2c10af9c4d..4f70252ae75 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
@@ -18,17 +18,15 @@
#include "BKE_subdiv.h"
#include "BKE_subdiv_mesh.h"
+#include "DNA_modifier_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
-
#include "node_geometry_util.hh"
static bNodeSocketTemplate geo_node_subdivision_surface_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_INT, N_("Level"), 1, 0, 0, 0, 0, 6},
{SOCK_BOOLEAN, N_("Use Creases")},
- {SOCK_BOOLEAN, N_("Boundary Smooth"), true},
- {SOCK_BOOLEAN, N_("Smooth UVs")},
{-1, ""},
};
@@ -37,6 +35,30 @@ static bNodeSocketTemplate geo_node_subdivision_surface_out[] = {
{-1, ""},
};
+static void geo_node_subdivision_surface_layout(uiLayout *layout,
+ bContext *UNUSED(C),
+ PointerRNA *ptr)
+{
+#ifndef WITH_OPENSUBDIV
+ UNUSED_VARS(ptr);
+ uiItemL(layout, IFACE_("Disabled, built without OpenSubdiv"), ICON_ERROR);
+#else
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+ uiItemR(layout, ptr, "uv_smooth", 0, nullptr, ICON_NONE);
+ uiItemR(layout, ptr, "boundary_smooth", 0, nullptr, ICON_NONE);
+#endif
+}
+
+static void geo_node_subdivision_surface_init(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ NodeGeometrySubdivisionSurface *data = (NodeGeometrySubdivisionSurface *)MEM_callocN(
+ sizeof(NodeGeometrySubdivisionSurface), __func__);
+ data->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES;
+ data->boundary_smooth = SUBSURF_BOUNDARY_SMOOTH_ALL;
+ node->storage = data;
+}
+
namespace blender::nodes {
static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
{
@@ -53,6 +75,10 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
params.error_message_add(NodeWarningType::Error,
TIP_("Disabled, Blender was compiled without OpenSubdiv"));
#else
+ const NodeGeometrySubdivisionSurface &storage =
+ *(const NodeGeometrySubdivisionSurface *)params.node().storage;
+ const int uv_smooth = storage.uv_smooth;
+ const int boundary_smooth = storage.boundary_smooth;
const int subdiv_level = clamp_i(params.extract_input<int>("Level"), 0, 30);
/* Only process subdivision if level is greater than 0. */
@@ -62,8 +88,6 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
}
const bool use_crease = params.extract_input<bool>("Use Creases");
- const bool boundary_smooth = params.extract_input<bool>("Boundary Smooth");
- const bool smooth_uvs = params.extract_input<bool>("Smooth UVs");
const Mesh *mesh_in = geometry_set.get_mesh_for_read();
/* Initialize mesh settings. */
@@ -79,9 +103,9 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
subdiv_settings.level = subdiv_level;
subdiv_settings.vtx_boundary_interpolation = BKE_subdiv_vtx_boundary_interpolation_from_subsurf(
- !boundary_smooth);
+ boundary_smooth);
subdiv_settings.fvar_linear_interpolation = BKE_subdiv_fvar_interpolation_from_uv_smooth(
- smooth_uvs);
+ uv_smooth);
/* Apply subdivision to mesh. */
Subdiv *subdiv = BKE_subdiv_update_from_mesh(nullptr, &subdiv_settings, mesh_in);
@@ -117,5 +141,12 @@ void register_node_type_geo_subdivision_surface()
node_type_socket_templates(
&ntype, geo_node_subdivision_surface_in, geo_node_subdivision_surface_out);
ntype.geometry_node_execute = blender::nodes::geo_node_subdivision_surface_exec;
+ ntype.draw_buttons = geo_node_subdivision_surface_layout;
+ node_type_init(&ntype, geo_node_subdivision_surface_init);
+ node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
+ node_type_storage(&ntype,
+ "NodeGeometrySubdivisionSurface",
+ node_free_standard_storage,
+ node_copy_standard_storage);
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_switch.cc b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
index 0aa5c68aaf5..c9ce2de1ea1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_switch.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
@@ -179,7 +179,7 @@ void register_node_type_geo_switch()
{
static bNodeType ntype;
- geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_CONVERTOR, 0);
+ geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, geo_node_switch_in, geo_node_switch_out);
node_type_init(&ntype, geo_node_switch_init);
node_type_update(&ntype, blender::nodes::geo_node_switch_update);
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index ffa20579acc..a3bbca90731 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -19,7 +19,6 @@
#include "DEG_depsgraph_query.h"
#include "NOD_geometry_exec.hh"
-#include "NOD_type_callbacks.hh"
#include "NOD_type_conversions.hh"
#include "node_geometry_util.hh"
diff --git a/source/blender/nodes/NOD_type_callbacks.hh b/source/blender/nodes/intern/node_multi_function.cc
index 2be78f929db..c91899ed8c2 100644
--- a/source/blender/nodes/NOD_type_callbacks.hh
+++ b/source/blender/nodes/intern/node_multi_function.cc
@@ -14,21 +14,27 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#pragma once
-
-#include <optional>
-
-#include "BKE_node.h"
-
-#include "FN_multi_function_data_type.hh"
+#include "NOD_multi_function.hh"
namespace blender::nodes {
-using fn::CPPType;
-using fn::MFDataType;
-
-std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype);
-bool socket_is_mf_data_socket(const bNodeSocketType &stype);
-void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder);
+NodeMultiFunctions::NodeMultiFunctions(const DerivedNodeTree &tree, ResourceScope &resource_scope)
+{
+ for (const NodeTreeRef *tree_ref : tree.used_node_tree_refs()) {
+ bNodeTree *btree = tree_ref->btree();
+ for (const NodeRef *node : tree_ref->nodes()) {
+ bNode *bnode = node->bnode();
+ if (bnode->typeinfo->build_multi_function == nullptr) {
+ continue;
+ }
+ NodeMultiFunctionBuilder builder{resource_scope, *bnode, *btree};
+ bnode->typeinfo->build_multi_function(builder);
+ const MultiFunction *fn = builder.built_fn_;
+ if (fn != nullptr) {
+ map_.add_new(bnode, fn);
+ }
+ }
+ }
+}
} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index 4be3fd2468b..528616eb23a 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -44,7 +44,6 @@
#include "MEM_guardedalloc.h"
-#include "NOD_node_tree_multi_function.hh"
#include "NOD_socket.h"
#include "FN_cpp_type_make.hh"
diff --git a/source/blender/nodes/intern/node_tree_multi_function.cc b/source/blender/nodes/intern/node_tree_multi_function.cc
deleted file mode 100644
index 7ab6495f733..00000000000
--- a/source/blender/nodes/intern/node_tree_multi_function.cc
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "NOD_node_tree_multi_function.hh"
-#include "NOD_type_conversions.hh"
-
-#include "FN_multi_function_network_evaluation.hh"
-
-#include "BLI_color.hh"
-#include "BLI_float2.hh"
-#include "BLI_float3.hh"
-
-namespace blender::nodes {
-
-const fn::MultiFunction &NodeMFNetworkBuilder::get_default_fn(StringRef name)
-{
- Vector<fn::MFDataType, 10> input_types;
- Vector<fn::MFDataType, 10> output_types;
-
- for (const InputSocketRef *dsocket : dnode_->inputs()) {
- if (dsocket->is_available()) {
- std::optional<fn::MFDataType> data_type = socket_mf_type_get(*dsocket->typeinfo());
- if (data_type.has_value()) {
- input_types.append(*data_type);
- }
- }
- }
- for (const OutputSocketRef *dsocket : dnode_->outputs()) {
- if (dsocket->is_available()) {
- std::optional<fn::MFDataType> data_type = socket_mf_type_get(*dsocket->typeinfo());
- if (data_type.has_value()) {
- output_types.append(*data_type);
- }
- }
- }
-
- const fn::MultiFunction &fn = this->construct_fn<fn::CustomMF_DefaultOutput>(
- name, input_types, output_types);
- return fn;
-}
-
-static void insert_dummy_node(CommonMFNetworkBuilderData &common, const DNode &dnode)
-{
- constexpr int stack_capacity = 10;
-
- Vector<fn::MFDataType, stack_capacity> input_types;
- Vector<StringRef, stack_capacity> input_names;
- Vector<const InputSocketRef *, stack_capacity> input_dsockets;
-
- for (const InputSocketRef *dsocket : dnode->inputs()) {
- if (dsocket->is_available()) {
- std::optional<fn::MFDataType> data_type = socket_mf_type_get(*dsocket->bsocket()->typeinfo);
- if (data_type.has_value()) {
- input_types.append(*data_type);
- input_names.append(dsocket->name());
- input_dsockets.append(dsocket);
- }
- }
- }
-
- Vector<fn::MFDataType, stack_capacity> output_types;
- Vector<StringRef, stack_capacity> output_names;
- Vector<const OutputSocketRef *, stack_capacity> output_dsockets;
-
- for (const OutputSocketRef *dsocket : dnode->outputs()) {
- if (dsocket->is_available()) {
- std::optional<fn::MFDataType> data_type = socket_mf_type_get(*dsocket->bsocket()->typeinfo);
- if (data_type.has_value()) {
- output_types.append(*data_type);
- output_names.append(dsocket->name());
- output_dsockets.append(dsocket);
- }
- }
- }
-
- fn::MFDummyNode &dummy_node = common.network.add_dummy(
- dnode->name(), input_types, output_types, input_names, output_names);
-
- common.network_map.add(*dnode.context(), input_dsockets, dummy_node.inputs());
- common.network_map.add(*dnode.context(), output_dsockets, dummy_node.outputs());
-}
-
-static bool has_data_sockets(const DNode &dnode)
-{
- for (const InputSocketRef *socket : dnode->inputs()) {
- if (socket_is_mf_data_socket(*socket->bsocket()->typeinfo)) {
- return true;
- }
- }
- for (const OutputSocketRef *socket : dnode->outputs()) {
- if (socket_is_mf_data_socket(*socket->bsocket()->typeinfo)) {
- return true;
- }
- }
- return false;
-}
-
-static void foreach_node_to_insert(CommonMFNetworkBuilderData &common,
- FunctionRef<void(DNode)> callback)
-{
- common.tree.foreach_node([&](const DNode dnode) {
- if (dnode->is_group_node()) {
- return;
- }
- /* Don't insert non-root group input/output nodes, because they will be inlined. */
- if (!dnode.context()->is_root()) {
- if (dnode->is_group_input_node() || dnode->is_group_output_node()) {
- return;
- }
- }
- callback(dnode);
- });
-}
-
-/**
- * Expands all function nodes in the multi-function network. Nodes that don't have an expand
- * function, but do have data sockets, will get corresponding dummy nodes.
- */
-static void insert_nodes(CommonMFNetworkBuilderData &common)
-{
- foreach_node_to_insert(common, [&](const DNode dnode) {
- const bNodeType *node_type = dnode->typeinfo();
- if (node_type->expand_in_mf_network != nullptr) {
- NodeMFNetworkBuilder builder{common, dnode};
- node_type->expand_in_mf_network(builder);
- }
- else if (has_data_sockets(dnode)) {
- insert_dummy_node(common, dnode);
- }
- });
-}
-
-static fn::MFOutputSocket &insert_default_value_for_type(CommonMFNetworkBuilderData &common,
- fn::MFDataType type)
-{
- const fn::MultiFunction *default_fn;
- if (type.is_single()) {
- default_fn = &common.scope.construct<fn::CustomMF_GenericConstant>(
- AT, type.single_type(), type.single_type().default_value());
- }
- else {
- default_fn = &common.scope.construct<fn::CustomMF_GenericConstantArray>(
- AT, fn::GSpan(type.vector_base_type()));
- }
-
- fn::MFNode &node = common.network.add_function(*default_fn);
- return node.output(0);
-}
-
-static fn::MFOutputSocket *insert_unlinked_input(CommonMFNetworkBuilderData &common,
- const DInputSocket &dsocket)
-{
- BLI_assert(socket_is_mf_data_socket(*dsocket->typeinfo()));
-
- SocketMFNetworkBuilder builder{common, dsocket};
- socket_expand_in_mf_network(builder);
-
- fn::MFOutputSocket *built_socket = builder.built_socket();
- BLI_assert(built_socket != nullptr);
- return built_socket;
-}
-
-static void insert_links_and_unlinked_inputs(CommonMFNetworkBuilderData &common)
-{
- foreach_node_to_insert(common, [&](const DNode dnode) {
- for (const InputSocketRef *socket_ref : dnode->inputs()) {
- const DInputSocket to_dsocket{dnode.context(), socket_ref};
- if (!to_dsocket->is_available()) {
- continue;
- }
- if (!socket_is_mf_data_socket(*to_dsocket->typeinfo())) {
- continue;
- }
-
- Span<fn::MFInputSocket *> to_sockets = common.network_map.lookup(to_dsocket);
- BLI_assert(to_sockets.size() >= 1);
- const fn::MFDataType to_type = to_sockets[0]->data_type();
-
- Vector<DSocket> from_dsockets;
- to_dsocket.foreach_origin_socket([&](DSocket socket) { from_dsockets.append(socket); });
- if (from_dsockets.size() > 1) {
- fn::MFOutputSocket &from_socket = insert_default_value_for_type(common, to_type);
- for (fn::MFInputSocket *to_socket : to_sockets) {
- common.network.add_link(from_socket, *to_socket);
- }
- continue;
- }
- if (from_dsockets.is_empty()) {
- /* The socket is not linked. Need to use the value of the socket itself. */
- fn::MFOutputSocket *built_socket = insert_unlinked_input(common, to_dsocket);
- for (fn::MFInputSocket *to_socket : to_sockets) {
- common.network.add_link(*built_socket, *to_socket);
- }
- continue;
- }
- if (from_dsockets[0]->is_input()) {
- DInputSocket from_dsocket{from_dsockets[0]};
- fn::MFOutputSocket *built_socket = insert_unlinked_input(common, from_dsocket);
- for (fn::MFInputSocket *to_socket : to_sockets) {
- common.network.add_link(*built_socket, *to_socket);
- }
- continue;
- }
- DOutputSocket from_dsocket{from_dsockets[0]};
- fn::MFOutputSocket *from_socket = &common.network_map.lookup(from_dsocket);
- const fn::MFDataType from_type = from_socket->data_type();
-
- if (from_type != to_type) {
- const fn::MultiFunction *conversion_fn =
- get_implicit_type_conversions().get_conversion_multi_function(from_type, to_type);
- if (conversion_fn != nullptr) {
- fn::MFNode &node = common.network.add_function(*conversion_fn);
- common.network.add_link(*from_socket, node.input(0));
- from_socket = &node.output(0);
- }
- else {
- from_socket = &insert_default_value_for_type(common, to_type);
- }
- }
-
- for (fn::MFInputSocket *to_socket : to_sockets) {
- common.network.add_link(*from_socket, *to_socket);
- }
- }
- });
-}
-
-/**
- * Expands all function nodes contained in the given node tree within the given multi-function
- * network.
- *
- * Returns a mapping between the original node tree and the generated nodes/sockets for further
- * processing.
- */
-MFNetworkTreeMap insert_node_tree_into_mf_network(fn::MFNetwork &network,
- const DerivedNodeTree &tree,
- ResourceScope &scope)
-{
- MFNetworkTreeMap network_map{tree, network};
-
- CommonMFNetworkBuilderData common{scope, network, network_map, tree};
-
- insert_nodes(common);
- insert_links_and_unlinked_inputs(common);
-
- return network_map;
-}
-
-/**
- * A single node is allowed to expand into multiple nodes before evaluation. Depending on what
- * nodes it expands to, it belongs a different type of the ones below.
- */
-enum class NodeExpandType {
- SingleFunctionNode,
- MultipleFunctionNodes,
- HasDummyNodes,
-};
-
-/**
- * Checks how the given node expanded in the multi-function network. If it is only a single
- * function node, the corresponding function is returned as well.
- */
-static NodeExpandType get_node_expand_type(MFNetworkTreeMap &network_map,
- const DNode &dnode,
- const fn::MultiFunction **r_single_function)
-{
- const fn::MFFunctionNode *single_function_node = nullptr;
- bool has_multiple_nodes = false;
- bool has_dummy_nodes = false;
-
- auto check_mf_node = [&](fn::MFNode &mf_node) {
- if (mf_node.is_function()) {
- if (single_function_node == nullptr) {
- single_function_node = &mf_node.as_function();
- }
- if (&mf_node != single_function_node) {
- has_multiple_nodes = true;
- }
- }
- else {
- BLI_assert(mf_node.is_dummy());
- has_dummy_nodes = true;
- }
- };
-
- for (const InputSocketRef *dsocket : dnode->inputs()) {
- if (dsocket->is_available()) {
- for (fn::MFInputSocket *mf_input :
- network_map.lookup(DInputSocket(dnode.context(), dsocket))) {
- check_mf_node(mf_input->node());
- }
- }
- }
- for (const OutputSocketRef *dsocket : dnode->outputs()) {
- if (dsocket->is_available()) {
- fn::MFOutputSocket &mf_output = network_map.lookup(DOutputSocket(dnode.context(), dsocket));
- check_mf_node(mf_output.node());
- }
- }
-
- if (has_dummy_nodes) {
- return NodeExpandType::HasDummyNodes;
- }
- if (has_multiple_nodes) {
- return NodeExpandType::MultipleFunctionNodes;
- }
- *r_single_function = &single_function_node->function();
- return NodeExpandType::SingleFunctionNode;
-}
-
-static const fn::MultiFunction &create_function_for_node_that_expands_into_multiple(
- const DNode &dnode,
- fn::MFNetwork &network,
- MFNetworkTreeMap &network_map,
- ResourceScope &scope)
-{
- Vector<const fn::MFOutputSocket *> dummy_fn_inputs;
- for (const InputSocketRef *dsocket : dnode->inputs()) {
- if (dsocket->is_available()) {
- MFDataType data_type = *socket_mf_type_get(*dsocket->typeinfo());
- fn::MFOutputSocket &fn_input = network.add_input(data_type.to_string(), data_type);
- for (fn::MFInputSocket *mf_input :
- network_map.lookup(DInputSocket(dnode.context(), dsocket))) {
- network.add_link(fn_input, *mf_input);
- dummy_fn_inputs.append(&fn_input);
- }
- }
- }
- Vector<const fn::MFInputSocket *> dummy_fn_outputs;
- for (const OutputSocketRef *dsocket : dnode->outputs()) {
- if (dsocket->is_available()) {
- fn::MFOutputSocket &mf_output = network_map.lookup(DOutputSocket(dnode.context(), dsocket));
- MFDataType data_type = mf_output.data_type();
- fn::MFInputSocket &fn_output = network.add_output(data_type.to_string(), data_type);
- network.add_link(mf_output, fn_output);
- dummy_fn_outputs.append(&fn_output);
- }
- }
-
- fn::MFNetworkEvaluator &fn_evaluator = scope.construct<fn::MFNetworkEvaluator>(
- __func__, std::move(dummy_fn_inputs), std::move(dummy_fn_outputs));
- return fn_evaluator;
-}
-
-/**
- * Returns a single multi-function for every node that supports it. This makes it easier to reuse
- * the multi-function implementation of nodes in different contexts.
- */
-MultiFunctionByNode get_multi_function_per_node(const DerivedNodeTree &tree, ResourceScope &scope)
-{
- /* Build a network that nodes can insert themselves into. However, the individual nodes are not
- * connected. */
- fn::MFNetwork &network = scope.construct<fn::MFNetwork>(__func__);
- MFNetworkTreeMap network_map{tree, network};
- MultiFunctionByNode functions_by_node;
-
- CommonMFNetworkBuilderData common{scope, network, network_map, tree};
-
- tree.foreach_node([&](DNode dnode) {
- const bNodeType *node_type = dnode->typeinfo();
- if (node_type->expand_in_mf_network == nullptr) {
- /* This node does not have a multi-function implementation. */
- return;
- }
-
- NodeMFNetworkBuilder builder{common, dnode};
- node_type->expand_in_mf_network(builder);
-
- const fn::MultiFunction *single_function = nullptr;
- const NodeExpandType expand_type = get_node_expand_type(network_map, dnode, &single_function);
-
- switch (expand_type) {
- case NodeExpandType::HasDummyNodes: {
- /* Dummy nodes cannot be executed, so skip them. */
- break;
- }
- case NodeExpandType::SingleFunctionNode: {
- /* This is the common case. Most nodes just expand to a single function. */
- functions_by_node.add_new(dnode, single_function);
- break;
- }
- case NodeExpandType::MultipleFunctionNodes: {
- /* If a node expanded into multiple functions, a new function has to be created that
- * combines those. */
- const fn::MultiFunction &fn = create_function_for_node_that_expands_into_multiple(
- dnode, network, network_map, scope);
- functions_by_node.add_new(dnode, &fn);
- break;
- }
- }
- });
-
- return functions_by_node;
-}
-
-} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/type_callbacks.cc b/source/blender/nodes/intern/type_callbacks.cc
deleted file mode 100644
index 881a02c92e9..00000000000
--- a/source/blender/nodes/intern/type_callbacks.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "NOD_node_tree_multi_function.hh"
-#include "NOD_type_callbacks.hh"
-
-namespace blender::nodes {
-
-std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype)
-{
- const CPPType *cpp_type = stype.get_base_cpp_type ? stype.get_base_cpp_type() : nullptr;
- if (cpp_type != nullptr) {
- return MFDataType::ForSingle(*cpp_type);
- }
- return {};
-}
-
-bool socket_is_mf_data_socket(const bNodeSocketType &stype)
-{
- if (!socket_mf_type_get(stype).has_value()) {
- return false;
- }
- if (stype.expand_in_mf_network == nullptr && stype.get_base_cpp_value == nullptr) {
- return false;
- }
- return true;
-}
-
-void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder)
-{
- bNodeSocket &socket = builder.bsocket();
- if (socket.typeinfo->expand_in_mf_network != nullptr) {
- socket.typeinfo->expand_in_mf_network(builder);
- }
- else if (socket.typeinfo->get_base_cpp_value != nullptr) {
- const CPPType &type = *socket.typeinfo->get_base_cpp_type();
- void *buffer = builder.resource_scope().linear_allocator().allocate(type.size(),
- type.alignment());
- socket.typeinfo->get_base_cpp_value(socket, buffer);
- builder.set_constant_value(type, buffer);
- }
- else {
- BLI_assert_unreachable();
- }
-}
-
-} // namespace blender::nodes
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c
index 7367f73d171..c3a675fcd20 100644
--- a/source/blender/nodes/shader/node_shader_tree.c
+++ b/source/blender/nodes/shader/node_shader_tree.c
@@ -130,7 +130,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_TEXTURE, N_("Texture"));
func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
- func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor"));
+ func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
func(calldata, NODE_CLASS_SCRIPT, N_("Script"));
func(calldata, NODE_CLASS_GROUP, N_("Group"));
func(calldata, NODE_CLASS_INTERFACE, N_("Interface"));
@@ -531,6 +531,7 @@ static void ntree_shader_groups_flatten(bNodeTree *localtree)
bNodeTree *ngroup = (bNodeTree *)node->id;
ntreeFreeLocalNode(localtree, node);
ntreeFreeTree(ngroup);
+ BLI_assert(!ngroup->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(ngroup);
}
else {
diff --git a/source/blender/nodes/shader/node_shader_util.h b/source/blender/nodes/shader/node_shader_util.h
index dc44f0fa98f..a75354d3381 100644
--- a/source/blender/nodes/shader/node_shader_util.h
+++ b/source/blender/nodes/shader/node_shader_util.h
@@ -72,7 +72,7 @@
#ifdef __cplusplus
# include "FN_multi_function_builder.hh"
-# include "NOD_node_tree_multi_function.hh"
+# include "NOD_multi_function.hh"
# include "BLI_color.hh"
# include "BLI_float3.hh"
diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.c b/source/blender/nodes/shader/nodes/node_shader_blackbody.c
index c946a76ab51..95c35affc27 100644
--- a/source/blender/nodes/shader/nodes/node_shader_blackbody.c
+++ b/source/blender/nodes/shader/nodes/node_shader_blackbody.c
@@ -52,7 +52,7 @@ void register_node_type_sh_blackbody(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTER, 0);
node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
node_type_socket_templates(&ntype, sh_node_blackbody_in, sh_node_blackbody_out);
node_type_init(&ntype, NULL);
diff --git a/source/blender/nodes/shader/nodes/node_shader_clamp.cc b/source/blender/nodes/shader/nodes/node_shader_clamp.cc
index 4f77421cfe0..b90397e4892 100644
--- a/source/blender/nodes/shader/nodes/node_shader_clamp.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_clamp.cc
@@ -51,7 +51,7 @@ static int gpu_shader_clamp(GPUMaterial *mat,
GPU_stack_link(mat, node, "clamp_range", in, out);
}
-static void sh_node_clamp_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_clamp_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, float> minmax_fn{
"Clamp (Min Max)",
@@ -65,7 +65,7 @@ static void sh_node_clamp_expand_in_mf_network(blender::nodes::NodeMFNetworkBuil
return clamp_f(value, b, a);
}};
- int clamp_type = builder.bnode().custom1;
+ int clamp_type = builder.node().custom1;
if (clamp_type == NODE_CLAMP_MINMAX) {
builder.set_matching_fn(minmax_fn);
}
@@ -78,11 +78,11 @@ void register_node_type_sh_clamp(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_CLAMP, "Clamp", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_CLAMP, "Clamp", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_clamp_in, sh_node_clamp_out);
node_type_init(&ntype, node_shader_init_clamp);
node_type_gpu(&ntype, gpu_shader_clamp);
- ntype.expand_in_mf_network = sh_node_clamp_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_clamp_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.cc b/source/blender/nodes/shader/nodes/node_shader_curves.cc
index f1d5040a292..df075d6e973 100644
--- a/source/blender/nodes/shader/nodes/node_shader_curves.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_curves.cc
@@ -143,9 +143,10 @@ class CurveVecFunction : public blender::fn::MultiFunction {
}
};
-static void sh_node_curve_vec_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_curve_vec_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.bnode();
+ bNode &bnode = builder.node();
CurveMapping *cumap = (CurveMapping *)bnode.storage;
BKE_curvemapping_init(cumap);
builder.construct_and_set_matching_fn<CurveVecFunction>(*cumap);
@@ -162,7 +163,7 @@ void register_node_type_sh_curve_vec(void)
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
node_type_exec(&ntype, node_initexec_curves, nullptr, node_shader_exec_curve_vec);
node_type_gpu(&ntype, gpu_shader_curve_vec);
- ntype.expand_in_mf_network = sh_node_curve_vec_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_curve_vec_build_multi_function;
nodeRegisterType(&ntype);
}
@@ -317,9 +318,10 @@ class CurveRGBFunction : public blender::fn::MultiFunction {
}
};
-static void sh_node_curve_rgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_curve_rgb_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.bnode();
+ bNode &bnode = builder.node();
CurveMapping *cumap = (CurveMapping *)bnode.storage;
BKE_curvemapping_init(cumap);
builder.construct_and_set_matching_fn<CurveRGBFunction>(*cumap);
@@ -336,7 +338,7 @@ void register_node_type_sh_curve_rgb(void)
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
node_type_exec(&ntype, node_initexec_curves, nullptr, node_shader_exec_curve_rgb);
node_type_gpu(&ntype, gpu_shader_curve_rgb);
- ntype.expand_in_mf_network = sh_node_curve_rgb_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_curve_rgb_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc
index ad7abd9d491..f48e824ccb5 100644
--- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc
@@ -261,9 +261,10 @@ class MapRangeSmootherstepFunction : public blender::fn::MultiFunction {
}
};
-static void sh_node_map_range_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_map_range_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.bnode();
+ bNode &bnode = builder.node();
bool clamp = bnode.custom1 != 0;
int interpolation_type = bnode.custom2;
@@ -301,7 +302,6 @@ static void sh_node_map_range_expand_in_mf_network(blender::nodes::NodeMFNetwork
break;
}
default:
- builder.set_not_implemented();
break;
}
}
@@ -310,12 +310,12 @@ void register_node_type_sh_map_range(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_MAP_RANGE, "Map Range", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_MAP_RANGE, "Map Range", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_map_range_in, sh_node_map_range_out);
node_type_init(&ntype, node_shader_init_map_range);
node_type_update(&ntype, node_shader_update_map_range);
node_type_gpu(&ntype, gpu_shader_map_range);
- ntype.expand_in_mf_network = sh_node_map_range_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_map_range_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.cc b/source/blender/nodes/shader/nodes/node_shader_math.cc
index 7a846031456..66c50b6de46 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_math.cc
@@ -69,11 +69,9 @@ static int gpu_shader_math(GPUMaterial *mat,
return 0;
}
-static const blender::fn::MultiFunction &get_base_multi_function(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static const blender::fn::MultiFunction *get_base_multi_function(bNode &node)
{
- const int mode = builder.bnode().custom1;
-
+ const int mode = node.custom1;
const blender::fn::MultiFunction *base_fn = nullptr;
blender::nodes::try_dispatch_float_math_fl_to_fl(
@@ -82,7 +80,7 @@ static const blender::fn::MultiFunction &get_base_multi_function(
base_fn = &fn;
});
if (base_fn != nullptr) {
- return *base_fn;
+ return base_fn;
}
blender::nodes::try_dispatch_float_math_fl_fl_to_fl(
@@ -92,7 +90,7 @@ static const blender::fn::MultiFunction &get_base_multi_function(
base_fn = &fn;
});
if (base_fn != nullptr) {
- return *base_fn;
+ return base_fn;
}
blender::nodes::try_dispatch_float_math_fl_fl_fl_to_fl(
@@ -102,36 +100,51 @@ static const blender::fn::MultiFunction &get_base_multi_function(
base_fn = &fn;
});
if (base_fn != nullptr) {
- return *base_fn;
+ return base_fn;
}
- return builder.get_not_implemented_fn();
+ return nullptr;
}
-static void sh_node_math_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
-{
- const blender::fn::MultiFunction &base_function = get_base_multi_function(builder);
+class ClampWrapperFunction : public blender::fn::MultiFunction {
+ private:
+ const blender::fn::MultiFunction &fn_;
- const blender::nodes::DNode &dnode = builder.dnode();
- blender::fn::MFNetwork &network = builder.network();
- blender::fn::MFFunctionNode &base_node = network.add_function(base_function);
+ public:
+ ClampWrapperFunction(const blender::fn::MultiFunction &fn) : fn_(fn)
+ {
+ this->set_signature(&fn.signature());
+ }
- builder.network_map().add_try_match(*dnode.context(), dnode->inputs(), base_node.inputs());
+ void call(blender::IndexMask mask,
+ blender::fn::MFParams params,
+ blender::fn::MFContext context) const override
+ {
+ fn_.call(mask, params, context);
+
+ /* Assumes the output parameter is the last one. */
+ const int output_param_index = this->param_amount() - 1;
+ /* This has actually been initialized in the call above. */
+ blender::MutableSpan<float> results = params.uninitialized_single_output<float>(
+ output_param_index);
+
+ for (const int i : mask) {
+ float &value = results[i];
+ CLAMP(value, 0.0f, 1.0f);
+ }
+ }
+};
+
+static void sh_node_math_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
+{
+ const blender::fn::MultiFunction *base_function = get_base_multi_function(builder.node());
- const bool clamp_output = builder.bnode().custom2 != 0;
+ const bool clamp_output = builder.node().custom2 != 0;
if (clamp_output) {
- static blender::fn::CustomMF_SI_SO<float, float> clamp_fn{"Clamp", [](float value) {
- CLAMP(value, 0.0f, 1.0f);
- return value;
- }};
- blender::fn::MFFunctionNode &clamp_node = network.add_function(clamp_fn);
- network.add_link(base_node.output(0), clamp_node.input(0));
- builder.network_map().add(blender::nodes::DOutputSocket(dnode.context(), &dnode->output(0)),
- clamp_node.output(0));
+ builder.construct_and_set_matching_fn<ClampWrapperFunction>(*base_function);
}
else {
- builder.network_map().add(blender::nodes::DOutputSocket(dnode.context(), &dnode->output(0)),
- base_node.output(0));
+ builder.set_matching_fn(base_function);
}
}
@@ -139,12 +152,12 @@ void register_node_type_sh_math(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_math_in, sh_node_math_out);
node_type_label(&ntype, node_math_label);
node_type_gpu(&ntype, gpu_shader_math);
node_type_update(&ntype, node_math_update);
- ntype.expand_in_mf_network = sh_node_math_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_math_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc
index 6baaa17f956..ade35a40366 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.cc
@@ -127,15 +127,71 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat,
return 0;
}
+class MixRGBFunction : public blender::fn::MultiFunction {
+ private:
+ bool clamp_;
+ int type_;
+
+ public:
+ MixRGBFunction(bool clamp, int type) : clamp_(clamp), type_(type)
+ {
+ static blender::fn::MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static blender::fn::MFSignature create_signature()
+ {
+ blender::fn::MFSignatureBuilder signature{"MixRGB"};
+ signature.single_input<float>("Fac");
+ signature.single_input<blender::ColorGeometry4f>("Color1");
+ signature.single_input<blender::ColorGeometry4f>("Color2");
+ signature.single_output<blender::ColorGeometry4f>("Color");
+ return signature.build();
+ }
+
+ void call(blender::IndexMask mask,
+ blender::fn::MFParams params,
+ blender::fn::MFContext UNUSED(context)) const override
+ {
+ const blender::VArray<float> &fac = params.readonly_single_input<float>(0, "Fac");
+ const blender::VArray<blender::ColorGeometry4f> &col1 =
+ params.readonly_single_input<blender::ColorGeometry4f>(1, "Color1");
+ const blender::VArray<blender::ColorGeometry4f> &col2 =
+ params.readonly_single_input<blender::ColorGeometry4f>(2, "Color2");
+ blender::MutableSpan<blender::ColorGeometry4f> results =
+ params.uninitialized_single_output<blender::ColorGeometry4f>(3, "Color");
+
+ for (int64_t i : mask) {
+ results[i] = col1[i];
+ ramp_blend(type_, results[i], clamp_f(fac[i], 0.0f, 1.0f), col2[i]);
+ }
+
+ if (clamp_) {
+ for (int64_t i : mask) {
+ clamp_v3(results[i], 0.0f, 1.0f);
+ }
+ }
+ }
+};
+
+static void sh_node_mix_rgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
+{
+ bNode &node = builder.node();
+ bool clamp = node.custom2 & SHD_MIXRGB_CLAMP;
+ int mix_type = node.custom1;
+ builder.construct_and_set_matching_fn<MixRGBFunction>(clamp, mix_type);
+}
+
void register_node_type_sh_mix_rgb(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0);
node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out);
node_type_label(&ntype, node_blend_label);
node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_mix_rgb);
node_type_gpu(&ntype, gpu_shader_mix_rgb);
+ ntype.build_multi_function = sh_node_mix_rgb_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c
index 951755be4f3..dfecb830b35 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c
@@ -61,7 +61,7 @@ void register_node_type_sh_sephsv(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_sephsv_in, sh_node_sephsv_out);
node_type_exec(&ntype, NULL, NULL, node_shader_exec_sephsv);
node_type_gpu(&ntype, gpu_shader_sephsv);
@@ -109,7 +109,7 @@ void register_node_type_sh_combhsv(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_combhsv_in, sh_node_combhsv_out);
node_type_exec(&ntype, NULL, NULL, node_shader_exec_combhsv);
node_type_gpu(&ntype, gpu_shader_combhsv);
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc
index a7239154633..d9cbee33c0f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc
@@ -96,7 +96,7 @@ class SeparateRGBFunction : public blender::fn::MultiFunction {
}
};
-static void sh_node_seprgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_seprgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
static SeparateRGBFunction fn;
builder.set_matching_fn(fn);
@@ -106,11 +106,11 @@ void register_node_type_sh_seprgb(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out);
node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_seprgb);
node_type_gpu(&ntype, gpu_shader_seprgb);
- ntype.expand_in_mf_network = sh_node_seprgb_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_seprgb_build_multi_function;
nodeRegisterType(&ntype);
}
@@ -153,7 +153,7 @@ static int gpu_shader_combrgb(GPUMaterial *mat,
return GPU_stack_link(mat, node, "combine_rgb", in, out);
}
-static void sh_node_combrgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_combrgb_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, blender::ColorGeometry4f> fn{
"Combine RGB",
@@ -165,11 +165,11 @@ void register_node_type_sh_combrgb(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out);
node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_combrgb);
node_type_gpu(&ntype, gpu_shader_combrgb);
- ntype.expand_in_mf_network = sh_node_combrgb_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_combrgb_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc
index efa9581c414..3048ed1e9fc 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc
@@ -81,7 +81,7 @@ class MF_SeparateXYZ : public blender::fn::MultiFunction {
}
};
-static void sh_node_sepxyz_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_sepxyz_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
static MF_SeparateXYZ separate_fn;
builder.set_matching_fn(separate_fn);
@@ -91,10 +91,10 @@ void register_node_type_sh_sepxyz(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out);
node_type_gpu(&ntype, gpu_shader_sepxyz);
- ntype.expand_in_mf_network = sh_node_sepxyz_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_sepxyz_build_multi_function;
nodeRegisterType(&ntype);
}
@@ -120,7 +120,7 @@ static int gpu_shader_combxyz(GPUMaterial *mat,
return GPU_stack_link(mat, node, "combine_xyz", in, out);
}
-static void sh_node_combxyz_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_combxyz_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, blender::float3> fn{
"Combine Vector", [](float x, float y, float z) { return blender::float3(x, y, z); }};
@@ -131,10 +131,10 @@ void register_node_type_sh_combxyz(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out);
node_type_gpu(&ntype, gpu_shader_combxyz);
- ntype.expand_in_mf_network = sh_node_combxyz_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_combxyz_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c
index 4216207d643..25c30aa4081 100644
--- a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c
@@ -50,7 +50,7 @@ void register_node_type_sh_shadertorgb(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_shadertorgb_in, sh_node_shadertorgb_out);
node_type_init(&ntype, NULL);
node_type_storage(&ntype, "", NULL, NULL);
diff --git a/source/blender/nodes/shader/nodes/node_shader_squeeze.c b/source/blender/nodes/shader/nodes/node_shader_squeeze.c
index c7b6af3980a..ca7bdf41df9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_squeeze.c
+++ b/source/blender/nodes/shader/nodes/node_shader_squeeze.c
@@ -61,7 +61,7 @@ void register_node_type_sh_squeeze(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_squeeze_in, sh_node_squeeze_out);
node_type_storage(&ntype, "", NULL, NULL);
node_type_exec(&ntype, NULL, NULL, node_shader_exec_squeeze);
diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc
index 5b2eb300aac..62f6b38c79f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc
@@ -163,9 +163,10 @@ class ColorBandFunction : public blender::fn::MultiFunction {
}
};
-static void sh_node_valtorgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_valtorgb_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.bnode();
+ bNode &bnode = builder.node();
const ColorBand *color_band = (const ColorBand *)bnode.storage;
builder.construct_and_set_matching_fn<ColorBandFunction>(*color_band);
}
@@ -174,14 +175,14 @@ void register_node_type_sh_valtorgb(void)
{
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0);
+ sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_valtorgb_in, sh_node_valtorgb_out);
node_type_init(&ntype, node_shader_init_valtorgb);
node_type_size_preset(&ntype, NODE_SIZE_LARGE);
node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage);
node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_valtorgb);
node_type_gpu(&ntype, gpu_shader_valtorgb);
- ntype.expand_in_mf_network = sh_node_valtorgb_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_valtorgb_build_multi_function;
nodeRegisterType(&ntype);
}
@@ -220,7 +221,7 @@ void register_node_type_sh_rgbtobw(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, sh_node_rgbtobw_in, sh_node_rgbtobw_out);
node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_rgbtobw);
node_type_gpu(&ntype, gpu_shader_rgbtobw);
diff --git a/source/blender/nodes/shader/nodes/node_shader_value.cc b/source/blender/nodes/shader/nodes/node_shader_value.cc
index 495c8d12824..602d5a1cf56 100644
--- a/source/blender/nodes/shader/nodes/node_shader_value.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_value.cc
@@ -39,9 +39,9 @@ static int gpu_shader_value(GPUMaterial *mat,
return GPU_stack_link(mat, node, "set_value", in, out, link);
}
-static void sh_node_value_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_value_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
- const bNodeSocket *bsocket = builder.dnode()->output(0).bsocket();
+ const bNodeSocket *bsocket = (bNodeSocket *)builder.node().outputs.first;
const bNodeSocketValueFloat *value = (const bNodeSocketValueFloat *)bsocket->default_value;
builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<float>>(value->value);
}
@@ -53,7 +53,7 @@ void register_node_type_sh_value(void)
sh_fn_node_type_base(&ntype, SH_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0);
node_type_socket_templates(&ntype, nullptr, sh_node_value_out);
node_type_gpu(&ntype, gpu_shader_value);
- ntype.expand_in_mf_network = sh_node_value_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_value_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc
index 419a11201aa..4424db6aed1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc
@@ -183,12 +183,11 @@ static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node
}
}
-static const blender::fn::MultiFunction &get_multi_function(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static const blender::fn::MultiFunction *get_multi_function(bNode &node)
{
using blender::float3;
- NodeVectorMathOperation operation = NodeVectorMathOperation(builder.bnode().custom1);
+ NodeVectorMathOperation operation = NodeVectorMathOperation(node.custom1);
const blender::fn::MultiFunction *multi_fn = nullptr;
@@ -199,7 +198,7 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
blender::nodes::try_dispatch_float_math_fl3_fl3_fl3_to_fl3(
@@ -209,7 +208,7 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
blender::nodes::try_dispatch_float_math_fl3_fl3_fl_to_fl3(
@@ -219,7 +218,7 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
blender::nodes::try_dispatch_float_math_fl3_fl3_to_fl(
@@ -229,7 +228,7 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
blender::nodes::try_dispatch_float_math_fl3_fl_to_fl3(
@@ -239,7 +238,7 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
blender::nodes::try_dispatch_float_math_fl3_to_fl3(
@@ -248,7 +247,7 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
blender::nodes::try_dispatch_float_math_fl3_to_fl(
@@ -257,15 +256,16 @@ static const blender::fn::MultiFunction &get_multi_function(
multi_fn = &fn;
});
if (multi_fn != nullptr) {
- return *multi_fn;
+ return multi_fn;
}
- return builder.get_not_implemented_fn();
+ return nullptr;
}
-static void sh_node_vector_math_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_vector_math_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- const blender::fn::MultiFunction &fn = get_multi_function(builder);
+ const blender::fn::MultiFunction *fn = get_multi_function(builder.node());
builder.set_matching_fn(fn);
}
@@ -278,7 +278,7 @@ void register_node_type_sh_vect_math(void)
node_type_label(&ntype, node_vector_math_label);
node_type_gpu(&ntype, gpu_shader_vector_math);
node_type_update(&ntype, node_shader_update_vector_math);
- ntype.expand_in_mf_network = sh_node_vector_math_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_vector_math_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
index 3b2c2fa5a03..bc51b7e29ea 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
@@ -100,11 +100,10 @@ static float3 sh_node_vector_rotate_euler(const float3 vector,
return result + center;
}
-static const blender::fn::MultiFunction &get_multi_function(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static const blender::fn::MultiFunction *get_multi_function(bNode &node)
{
- bool invert = builder.bnode().custom2;
- const int mode = builder.bnode().custom1;
+ bool invert = node.custom2;
+ const int mode = node.custom1;
switch (mode) {
case NODE_VECTOR_ROTATE_TYPE_AXIS: {
@@ -113,13 +112,13 @@ static const blender::fn::MultiFunction &get_multi_function(
"Rotate Axis", [](float3 in, float3 center, float3 axis, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
}};
- return fn;
+ return &fn;
}
static blender::fn::CustomMF_SI_SI_SI_SI_SO<float3, float3, float3, float, float3> fn{
"Rotate Axis", [](float3 in, float3 center, float3 axis, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, angle);
}};
- return fn;
+ return &fn;
}
case NODE_VECTOR_ROTATE_TYPE_AXIS_X: {
float3 axis = float3(1.0f, 0.0f, 0.0f);
@@ -128,13 +127,13 @@ static const blender::fn::MultiFunction &get_multi_function(
"Rotate X-Axis", [=](float3 in, float3 center, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
}};
- return fn;
+ return &fn;
}
static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float, float3> fn{
"Rotate X-Axis", [=](float3 in, float3 center, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, angle);
}};
- return fn;
+ return &fn;
}
case NODE_VECTOR_ROTATE_TYPE_AXIS_Y: {
float3 axis = float3(0.0f, 1.0f, 0.0f);
@@ -143,13 +142,13 @@ static const blender::fn::MultiFunction &get_multi_function(
"Rotate Y-Axis", [=](float3 in, float3 center, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
}};
- return fn;
+ return &fn;
}
static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float, float3> fn{
"Rotate Y-Axis", [=](float3 in, float3 center, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, angle);
}};
- return fn;
+ return &fn;
}
case NODE_VECTOR_ROTATE_TYPE_AXIS_Z: {
float3 axis = float3(0.0f, 0.0f, 1.0f);
@@ -158,13 +157,13 @@ static const blender::fn::MultiFunction &get_multi_function(
"Rotate Z-Axis", [=](float3 in, float3 center, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
}};
- return fn;
+ return &fn;
}
static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float, float3> fn{
"Rotate Z-Axis", [=](float3 in, float3 center, float angle) {
return sh_node_vector_rotate_around_axis(in, center, axis, angle);
}};
- return fn;
+ return &fn;
}
case NODE_VECTOR_ROTATE_TYPE_EULER_XYZ: {
if (invert) {
@@ -172,24 +171,24 @@ static const blender::fn::MultiFunction &get_multi_function(
"Rotate Euler", [](float3 in, float3 center, float3 rotation) {
return sh_node_vector_rotate_euler(in, center, rotation, true);
}};
- return fn;
+ return &fn;
}
static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float3, float3> fn{
"Rotate Euler", [](float3 in, float3 center, float3 rotation) {
return sh_node_vector_rotate_euler(in, center, rotation, false);
}};
- return fn;
+ return &fn;
}
default:
BLI_assert_unreachable();
- return builder.get_not_implemented_fn();
+ return nullptr;
}
}
-static void sh_node_vector_rotate_expand_in_mf_network(
- blender::nodes::NodeMFNetworkBuilder &builder)
+static void sh_node_vector_rotate_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
{
- const blender::fn::MultiFunction &fn = get_multi_function(builder);
+ const blender::fn::MultiFunction *fn = get_multi_function(builder.node());
builder.set_matching_fn(fn);
}
@@ -211,7 +210,7 @@ void register_node_type_sh_vector_rotate(void)
node_type_socket_templates(&ntype, sh_node_vector_rotate_in, sh_node_vector_rotate_out);
node_type_gpu(&ntype, gpu_shader_vector_rotate);
node_type_update(&ntype, node_shader_update_vector_rotate);
- ntype.expand_in_mf_network = sh_node_vector_rotate_expand_in_mf_network;
+ ntype.build_multi_function = sh_node_vector_rotate_build_multi_function;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_wavelength.c b/source/blender/nodes/shader/nodes/node_shader_wavelength.c
index 30f69557020..f978537ee85 100644
--- a/source/blender/nodes/shader/nodes/node_shader_wavelength.c
+++ b/source/blender/nodes/shader/nodes/node_shader_wavelength.c
@@ -62,7 +62,7 @@ void register_node_type_sh_wavelength(void)
{
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_WAVELENGTH, "Wavelength", NODE_CLASS_CONVERTOR, 0);
+ sh_node_type_base(&ntype, SH_NODE_WAVELENGTH, "Wavelength", NODE_CLASS_CONVERTER, 0);
node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
node_type_socket_templates(&ntype, sh_node_wavelength_in, sh_node_wavelength_out);
node_type_init(&ntype, NULL);
diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c
index f771b4934b2..7452007639c 100644
--- a/source/blender/nodes/texture/node_texture_tree.c
+++ b/source/blender/nodes/texture/node_texture_tree.c
@@ -101,7 +101,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
func(calldata, NODE_CLASS_PATTERN, N_("Patterns"));
func(calldata, NODE_CLASS_TEXTURE, N_("Textures"));
- func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor"));
+ func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
func(calldata, NODE_CLASS_DISTORT, N_("Distort"));
func(calldata, NODE_CLASS_GROUP, N_("Group"));
func(calldata, NODE_CLASS_INTERFACE, N_("Interface"));
diff --git a/source/blender/nodes/texture/nodes/node_texture_distance.c b/source/blender/nodes/texture/nodes/node_texture_distance.c
index 489318514e5..f7deac9ff4a 100644
--- a/source/blender/nodes/texture/nodes/node_texture_distance.c
+++ b/source/blender/nodes/texture/nodes/node_texture_distance.c
@@ -61,7 +61,7 @@ void register_node_type_tex_distance(void)
{
static bNodeType ntype;
- tex_node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTOR, 0);
+ tex_node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, inputs, outputs);
node_type_storage(&ntype, "", NULL, NULL);
node_type_exec(&ntype, NULL, NULL, exec);
diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c
index 53022c9e120..ab226a4dd38 100644
--- a/source/blender/nodes/texture/nodes/node_texture_math.c
+++ b/source/blender/nodes/texture/nodes/node_texture_math.c
@@ -335,7 +335,7 @@ void register_node_type_tex_math(void)
{
static bNodeType ntype;
- tex_node_type_base(&ntype, TEX_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0);
+ tex_node_type_base(&ntype, TEX_NODE_MATH, "Math", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, inputs, outputs);
node_type_label(&ntype, node_math_label);
node_type_storage(&ntype, "", NULL, NULL);
diff --git a/source/blender/nodes/texture/nodes/node_texture_valToNor.c b/source/blender/nodes/texture/nodes/node_texture_valToNor.c
index 2fb04777848..5ccd44b8bf0 100644
--- a/source/blender/nodes/texture/nodes/node_texture_valToNor.c
+++ b/source/blender/nodes/texture/nodes/node_texture_valToNor.c
@@ -80,7 +80,7 @@ void register_node_type_tex_valtonor(void)
{
static bNodeType ntype;
- tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, 0);
+ tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, inputs, outputs);
node_type_exec(&ntype, NULL, NULL, exec);
diff --git a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c
index 8d365e13fc4..2446ef05e0c 100644
--- a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c
+++ b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c
@@ -63,7 +63,7 @@ void register_node_type_tex_valtorgb(void)
{
static bNodeType ntype;
- tex_node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0);
+ tex_node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, valtorgb_in, valtorgb_out);
node_type_size_preset(&ntype, NODE_SIZE_LARGE);
node_type_init(&ntype, valtorgb_init);
@@ -105,7 +105,7 @@ void register_node_type_tex_rgbtobw(void)
{
static bNodeType ntype;
- tex_node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
+ tex_node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0);
node_type_socket_templates(&ntype, rgbtobw_in, rgbtobw_out);
node_type_exec(&ntype, NULL, NULL, rgbtobw_exec);
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 0ec66e22fa9..9e725730d40 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -493,7 +493,6 @@ PyObject *BPyInit_blf(void)
PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW);
- PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT);
PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP);
PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME);
diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c
index a1fc89e772e..0fef59d6352 100644
--- a/source/blender/python/gpu/gpu_py_buffer.c
+++ b/source/blender/python/gpu/gpu_py_buffer.c
@@ -37,7 +37,7 @@
#include "gpu_py_buffer.h"
-//#define PYGPU_BUFFER_PROTOCOL
+#define PYGPU_BUFFER_PROTOCOL
#define MAX_DIMENSIONS 64
/* -------------------------------------------------------------------- */
@@ -608,7 +608,7 @@ static void pygpu_buffer_strides_calc(const eGPUDataFormat format,
}
/* Here is the buffer interface function */
-static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int flags)
+static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int UNUSED(flags))
{
if (view == NULL) {
PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
@@ -620,7 +620,7 @@ static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int f
view->len = bpygpu_Buffer_size(self);
view->readonly = 0;
view->itemsize = GPU_texture_dataformat_size(self->format);
- view->format = pygpu_buffer_formatstr(self->format);
+ view->format = (char *)pygpu_buffer_formatstr(self->format);
view->ndim = self->shape_len;
view->shape = self->shape;
view->strides = MEM_mallocN(view->ndim * sizeof(*view->strides), "BPyGPUBuffer strides");
diff --git a/source/blender/python/gpu/gpu_py_capabilities.c b/source/blender/python/gpu/gpu_py_capabilities.c
index f3fb93021b2..11e7d48f096 100644
--- a/source/blender/python/gpu/gpu_py_capabilities.c
+++ b/source/blender/python/gpu/gpu_py_capabilities.c
@@ -33,66 +33,166 @@
/** \name Functions
* \{ */
+PyDoc_STRVAR(pygpu_max_texture_size_get_doc,
+ ".. function:: max_texture_size_get()\n"
+ "\n"
+ " Get estimated maximum texture size to be able to handle.\n"
+ "\n"
+ " :return: Texture size.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_texture_size_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_texture_size());
}
+PyDoc_STRVAR(pygpu_max_texture_layers_get_doc,
+ ".. function:: max_texture_layers_get()\n"
+ "\n"
+ " Get maximum number of layers in texture.\n"
+ "\n"
+ " :return: Number of layers.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_texture_layers_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_texture_layers());
}
+PyDoc_STRVAR(pygpu_max_textures_get_doc,
+ ".. function:: max_textures_get()\n"
+ "\n"
+ " Get maximum supported texture image units used for\n"
+ " accessing texture maps from the vertex shader and the\n"
+ " fragment processor.\n"
+ "\n"
+ " :return: Texture image units.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_textures_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_textures());
}
+PyDoc_STRVAR(pygpu_max_textures_vert_get_doc,
+ ".. function:: max_textures_vert_get()\n"
+ "\n"
+ " Get maximum supported texture image units used for\n"
+ " accessing texture maps from the vertex shader.\n"
+ "\n"
+ " :return: Texture image units.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_textures_vert_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_textures_vert());
}
+PyDoc_STRVAR(pygpu_max_textures_geom_get_doc,
+ ".. function:: max_textures_geom_get()\n"
+ "\n"
+ " Get maximum supported texture image units used for\n"
+ " accessing texture maps from the geometry shader.\n"
+ "\n"
+ " :return: Texture image units.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_textures_geom_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_textures_geom());
}
+PyDoc_STRVAR(pygpu_max_textures_frag_get_doc,
+ ".. function:: max_textures_frag_get()\n"
+ "\n"
+ " Get maximum supported texture image units used for\n"
+ " accessing texture maps from the fragment shader.\n"
+ "\n"
+ " :return: Texture image units.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_textures_frag_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_textures_frag());
}
+PyDoc_STRVAR(pygpu_max_uniforms_vert_get_doc,
+ ".. function:: max_uniforms_vert_get()\n"
+ "\n"
+ " Get maximum number of values held in uniform variable\n"
+ " storage for a vertex shader.\n"
+ "\n"
+ " :return: Number of values.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_uniforms_vert_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_uniforms_vert());
}
+PyDoc_STRVAR(pygpu_max_uniforms_frag_get_doc,
+ ".. function:: max_uniforms_frag_get()\n"
+ "\n"
+ " Get maximum number of values held in uniform variable\n"
+ " storage for a fragment shader.\n"
+ "\n"
+ " :return: Number of values.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_uniforms_frag_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_uniforms_frag());
}
+PyDoc_STRVAR(pygpu_max_batch_indices_get_doc,
+ ".. function:: max_batch_indices_get()\n"
+ "\n"
+ " Get maximum number of vertex array indices.\n"
+ "\n"
+ " :return: Number of indices.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_batch_indices_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_batch_indices());
}
+PyDoc_STRVAR(pygpu_max_batch_vertices_get_doc,
+ ".. function:: max_batch_vertices_get()\n"
+ "\n"
+ " Get maximum number of vertex array vertices.\n"
+ "\n"
+ " :return: Number of vertices.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_batch_vertices_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_batch_vertices());
}
+PyDoc_STRVAR(pygpu_max_vertex_attribs_get_doc,
+ ".. function:: max_vertex_attribs_get()\n"
+ "\n"
+ " Get maximum number of vertex attributes accessible to\n"
+ " a vertex shader.\n"
+ "\n"
+ " :return: Number of attributes.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_vertex_attribs_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_vertex_attribs());
}
+PyDoc_STRVAR(pygpu_max_varying_floats_get_doc,
+ ".. function:: max_varying_floats_get()\n"
+ "\n"
+ " Get maximum number of varying variables used by\n"
+ " vertex and fragment shaders.\n"
+ "\n"
+ " :return: Number of variables.\n"
+ " :rtype: int\n");
static PyObject *pygpu_max_varying_floats_get(PyObject *UNUSED(self))
{
return PyLong_FromLong(GPU_max_varying_floats());
}
+PyDoc_STRVAR(pygpu_extensions_get_doc,
+ ".. function:: extensions_get()\n"
+ "\n"
+ " Get supported extensions in the current context.\n"
+ "\n"
+ " :return: Extensions.\n"
+ " :rtype: tuple of string\n");
static PyObject *pygpu_extensions_get(PyObject *UNUSED(self))
{
int extensions_len = GPU_extensions_len();
@@ -112,19 +212,55 @@ static PyObject *pygpu_extensions_get(PyObject *UNUSED(self))
* \{ */
static struct PyMethodDef pygpu_capabilities__tp_methods[] = {
- {"max_texture_size_get", (PyCFunction)pygpu_max_texture_size_get, METH_NOARGS, NULL},
- {"max_texture_layers_get", (PyCFunction)pygpu_max_texture_layers_get, METH_NOARGS, NULL},
- {"max_textures_get", (PyCFunction)pygpu_max_textures_get, METH_NOARGS, NULL},
- {"max_textures_vert_get", (PyCFunction)pygpu_max_textures_vert_get, METH_NOARGS, NULL},
- {"max_textures_geom_get", (PyCFunction)pygpu_max_textures_geom_get, METH_NOARGS, NULL},
- {"max_textures_frag_get", (PyCFunction)pygpu_max_textures_frag_get, METH_NOARGS, NULL},
- {"max_uniforms_vert_get", (PyCFunction)pygpu_max_uniforms_vert_get, METH_NOARGS, NULL},
- {"max_uniforms_frag_get", (PyCFunction)pygpu_max_uniforms_frag_get, METH_NOARGS, NULL},
- {"max_batch_indices_get", (PyCFunction)pygpu_max_batch_indices_get, METH_NOARGS, NULL},
- {"max_batch_vertices_get", (PyCFunction)pygpu_max_batch_vertices_get, METH_NOARGS, NULL},
- {"max_vertex_attribs_get", (PyCFunction)pygpu_max_vertex_attribs_get, METH_NOARGS, NULL},
- {"max_varying_floats_get", (PyCFunction)pygpu_max_varying_floats_get, METH_NOARGS, NULL},
- {"extensions_get", (PyCFunction)pygpu_extensions_get, METH_NOARGS, NULL},
+ {"max_texture_size_get",
+ (PyCFunction)pygpu_max_texture_size_get,
+ METH_NOARGS,
+ pygpu_max_texture_size_get_doc},
+ {"max_texture_layers_get",
+ (PyCFunction)pygpu_max_texture_layers_get,
+ METH_NOARGS,
+ pygpu_max_texture_layers_get_doc},
+ {"max_textures_get",
+ (PyCFunction)pygpu_max_textures_get,
+ METH_NOARGS,
+ pygpu_max_textures_get_doc},
+ {"max_textures_vert_get",
+ (PyCFunction)pygpu_max_textures_vert_get,
+ METH_NOARGS,
+ pygpu_max_textures_vert_get_doc},
+ {"max_textures_geom_get",
+ (PyCFunction)pygpu_max_textures_geom_get,
+ METH_NOARGS,
+ pygpu_max_textures_geom_get_doc},
+ {"max_textures_frag_get",
+ (PyCFunction)pygpu_max_textures_frag_get,
+ METH_NOARGS,
+ pygpu_max_textures_frag_get_doc},
+ {"max_uniforms_vert_get",
+ (PyCFunction)pygpu_max_uniforms_vert_get,
+ METH_NOARGS,
+ pygpu_max_uniforms_vert_get_doc},
+ {"max_uniforms_frag_get",
+ (PyCFunction)pygpu_max_uniforms_frag_get,
+ METH_NOARGS,
+ pygpu_max_uniforms_frag_get_doc},
+ {"max_batch_indices_get",
+ (PyCFunction)pygpu_max_batch_indices_get,
+ METH_NOARGS,
+ pygpu_max_batch_indices_get_doc},
+ {"max_batch_vertices_get",
+ (PyCFunction)pygpu_max_batch_vertices_get,
+ METH_NOARGS,
+ pygpu_max_batch_vertices_get_doc},
+ {"max_vertex_attribs_get",
+ (PyCFunction)pygpu_max_vertex_attribs_get,
+ METH_NOARGS,
+ pygpu_max_vertex_attribs_get_doc},
+ {"max_varying_floats_get",
+ (PyCFunction)pygpu_max_varying_floats_get,
+ METH_NOARGS,
+ pygpu_max_varying_floats_get_doc},
+ {"extensions_get", (PyCFunction)pygpu_extensions_get, METH_NOARGS, pygpu_extensions_get_doc},
{NULL, NULL, 0, NULL},
};
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c
index 32053df5e97..6f23c2213e2 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.c
+++ b/source/blender/python/gpu/gpu_py_offscreen.c
@@ -227,7 +227,7 @@ static PyObject *pygpu_offscreen__tp_new(PyTypeObject *UNUSED(self),
}
if (GPU_context_active_get()) {
- ofs = GPU_offscreen_create(width, height, true, false, err_out);
+ ofs = GPU_offscreen_create(width, height, true, GPU_RGBA8, err_out);
}
else {
STRNCPY(err_out, "No active GPU context found");
diff --git a/source/blender/python/gpu/gpu_py_platform.c b/source/blender/python/gpu/gpu_py_platform.c
index 132052b6f1d..62310a83642 100644
--- a/source/blender/python/gpu/gpu_py_platform.c
+++ b/source/blender/python/gpu/gpu_py_platform.c
@@ -33,16 +33,37 @@
/** \name Functions
* \{ */
+PyDoc_STRVAR(pygpu_platform_vendor_get_doc,
+ ".. function:: vendor_get()\n"
+ "\n"
+ " Get GPU vendor.\n"
+ "\n"
+ " :return: Vendor name.\n"
+ " :rtype: str\n");
static PyObject *pygpu_platform_vendor_get(PyObject *UNUSED(self))
{
return PyUnicode_FromString(GPU_platform_vendor());
}
+PyDoc_STRVAR(pygpu_platform_renderer_get_doc,
+ ".. function:: renderer_get()\n"
+ "\n"
+ " Get GPU to be used for rendering.\n"
+ "\n"
+ " :return: GPU name.\n"
+ " :rtype: str\n");
static PyObject *pygpu_platform_renderer_get(PyObject *UNUSED(self))
{
return PyUnicode_FromString(GPU_platform_renderer());
}
+PyDoc_STRVAR(pygpu_platform_version_get_doc,
+ ".. function:: version_get()\n"
+ "\n"
+ " Get GPU driver version.\n"
+ "\n"
+ " :return: Driver version.\n"
+ " :rtype: str\n");
static PyObject *pygpu_platform_version_get(PyObject *UNUSED(self))
{
return PyUnicode_FromString(GPU_platform_version());
@@ -55,9 +76,18 @@ static PyObject *pygpu_platform_version_get(PyObject *UNUSED(self))
* \{ */
static struct PyMethodDef pygpu_platform__tp_methods[] = {
- {"vendor_get", (PyCFunction)pygpu_platform_vendor_get, METH_NOARGS, NULL},
- {"renderer_get", (PyCFunction)pygpu_platform_renderer_get, METH_NOARGS, NULL},
- {"version_get", (PyCFunction)pygpu_platform_version_get, METH_NOARGS, NULL},
+ {"vendor_get",
+ (PyCFunction)pygpu_platform_vendor_get,
+ METH_NOARGS,
+ pygpu_platform_vendor_get_doc},
+ {"renderer_get",
+ (PyCFunction)pygpu_platform_renderer_get,
+ METH_NOARGS,
+ pygpu_platform_renderer_get_doc},
+ {"version_get",
+ (PyCFunction)pygpu_platform_version_get,
+ METH_NOARGS,
+ pygpu_platform_version_get_doc},
{NULL, NULL, 0, NULL},
};
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c
index b3f1c186716..145586d8ab0 100644
--- a/source/blender/python/gpu/gpu_py_shader.c
+++ b/source/blender/python/gpu/gpu_py_shader.c
@@ -44,14 +44,28 @@
/** \name Enum Conversion.
* \{ */
+#define PYDOC_BUILTIN_SHADER_LIST \
+ " - ``2D_FLAT_COLOR``\n" \
+ " - ``2D_IMAGE``\n" \
+ " - ``2D_SMOOTH_COLOR``\n" \
+ " - ``2D_UNIFORM_COLOR``\n" \
+ " - ``3D_FLAT_COLOR``\n" \
+ " - ``3D_SMOOTH_COLOR``\n" \
+ " - ``3D_UNIFORM_COLOR``\n" \
+ " - ``3D_POLYLINE_FLAT_COLOR``\n" \
+ " - ``3D_POLYLINE_SMOOTH_COLOR``\n" \
+ " - ``3D_POLYLINE_UNIFORM_COLOR``\n"
+
static const struct PyC_StringEnumItems pygpu_shader_builtin_items[] = {
- {GPU_SHADER_2D_UNIFORM_COLOR, "2D_UNIFORM_COLOR"},
{GPU_SHADER_2D_FLAT_COLOR, "2D_FLAT_COLOR"},
- {GPU_SHADER_2D_SMOOTH_COLOR, "2D_SMOOTH_COLOR"},
{GPU_SHADER_2D_IMAGE, "2D_IMAGE"},
- {GPU_SHADER_3D_UNIFORM_COLOR, "3D_UNIFORM_COLOR"},
+ {GPU_SHADER_2D_SMOOTH_COLOR, "2D_SMOOTH_COLOR"},
+ {GPU_SHADER_2D_UNIFORM_COLOR, "2D_UNIFORM_COLOR"},
{GPU_SHADER_3D_FLAT_COLOR, "3D_FLAT_COLOR"},
{GPU_SHADER_3D_SMOOTH_COLOR, "3D_SMOOTH_COLOR"},
+ {GPU_SHADER_3D_UNIFORM_COLOR, "3D_UNIFORM_COLOR"},
+ {GPU_SHADER_3D_POLYLINE_FLAT_COLOR, "3D_POLYLINE_FLAT_COLOR"},
+ {GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, "3D_POLYLINE_SMOOTH_COLOR"},
{GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, "3D_POLYLINE_UNIFORM_COLOR"},
{0, NULL},
};
@@ -197,8 +211,9 @@ static bool pygpu_shader_uniform_vector_impl(PyObject *args,
return false;
}
- if (r_pybuffer->len != (*r_length * *r_count * elem_size)) {
- PyErr_SetString(PyExc_BufferError, "GPUShader.uniform_vector_*: buffer size does not match.");
+ if (r_pybuffer->len < (*r_length * *r_count * elem_size)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "GPUShader.uniform_vector_*: buffer size smaller than required.");
return false;
}
@@ -704,14 +719,8 @@ PyDoc_STRVAR(pygpu_shader_from_builtin_doc,
" For more details, you can check the shader code with the\n"
" :func:`gpu.shader.code_from_builtin` function.\n"
"\n"
- " :param pygpu_shader_name: One of these builtin shader names:\n\n"
- " - ``2D_UNIFORM_COLOR``\n"
- " - ``2D_FLAT_COLOR``\n"
- " - ``2D_SMOOTH_COLOR``\n"
- " - ``2D_IMAGE``\n"
- " - ``3D_UNIFORM_COLOR``\n"
- " - ``3D_FLAT_COLOR``\n"
- " - ``3D_SMOOTH_COLOR``\n"
+ " :param pygpu_shader_name: One of these builtin shader names:\n"
+ "\n" PYDOC_BUILTIN_SHADER_LIST
" :type pygpu_shader_name: str\n"
" :return: Shader object corresponding to the given name.\n"
" :rtype: :class:`bpy.types.GPUShader`\n");
@@ -734,14 +743,8 @@ PyDoc_STRVAR(pygpu_shader_code_from_builtin_doc,
"\n"
" Exposes the internal shader code for query.\n"
"\n"
- " :param pygpu_shader_name: One of these builtin shader names:\n\n"
- " - ``2D_UNIFORM_COLOR``\n"
- " - ``2D_FLAT_COLOR``\n"
- " - ``2D_SMOOTH_COLOR``\n"
- " - ``2D_IMAGE``\n"
- " - ``3D_UNIFORM_COLOR``\n"
- " - ``3D_FLAT_COLOR``\n"
- " - ``3D_SMOOTH_COLOR``\n"
+ " :param pygpu_shader_name: One of these builtin shader names:\n"
+ "\n" PYDOC_BUILTIN_SHADER_LIST
" :type pygpu_shader_name: str\n"
" :return: Vertex, fragment and geometry shader codes.\n"
" :rtype: dict\n");
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index 80ac0dfa443..7646109c1b0 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -419,9 +419,6 @@ void BPy_init_modules(struct bContext *C)
PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod);
Py_DECREF(mod);
- /* run first, initializes rna types */
- BPY_rna_init();
-
/* needs to be first so bpy_types can run */
PyModule_AddObject(mod, "types", BPY_rna_types());
diff --git a/source/blender/python/intern/bpy_app_icons.c b/source/blender/python/intern/bpy_app_icons.c
index 7cca3ae4700..acd809fb8d5 100644
--- a/source/blender/python/intern/bpy_app_icons.c
+++ b/source/blender/python/intern/bpy_app_icons.c
@@ -35,7 +35,7 @@
/* We may want to load direct from file. */
PyDoc_STRVAR(
bpy_app_icons_new_triangles_doc,
- ".. function:: new_triangles(range, coords, colors)"
+ ".. function:: new_triangles(range, coords, colors)\n"
"\n"
" Create a new icon from triangle geometry.\n"
"\n"
@@ -91,7 +91,7 @@ static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *a
}
PyDoc_STRVAR(bpy_app_icons_new_triangles_from_file_doc,
- ".. function:: new_triangles_from_file(filename)"
+ ".. function:: new_triangles_from_file(filename)\n"
"\n"
" Create a new icon from triangle geometry.\n"
"\n"
@@ -122,7 +122,7 @@ static PyObject *bpy_app_icons_new_triangles_from_file(PyObject *UNUSED(self),
}
PyDoc_STRVAR(bpy_app_icons_release_doc,
- ".. function:: release(icon_id)"
+ ".. function:: release(icon_id)\n"
"\n"
" Release the icon.\n");
static PyObject *bpy_app_icons_release(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 35450e3eaad..1a308414bc3 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -502,7 +502,10 @@ void BPY_python_start(bContext *C, int argc, const char **argv)
}
#endif
- /* bpy.* and lets us import it */
+ /* Run first, initializes RNA types. */
+ BPY_rna_init();
+
+ /* Defines `bpy.*` and lets us import it. */
BPy_init_modules(C);
pyrna_alloc_types();
@@ -541,6 +544,8 @@ void BPY_python_end(void)
/* free other python data. */
pyrna_free_types();
+ BPY_rna_exit();
+
/* clear all python data from structs */
bpy_intern_string_exit();
@@ -650,7 +655,7 @@ void BPY_modules_load_user(bContext *C)
bpy_context_set(C, &gilstate);
for (text = bmain->texts.first; text; text = text->id.next) {
- if (text->flags & TXT_ISSCRIPT && BLI_path_extension_check(text->id.name + 2, ".py")) {
+ if (text->flags & TXT_ISSCRIPT) {
if (!(G.f & G_FLAG_SCRIPT_AUTOEXEC)) {
if (!(G.f & G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET)) {
G.f |= G_FLAG_SCRIPT_AUTOEXEC_FAIL;
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 93741d5d9e7..ac1fdeb2bad 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -182,23 +182,13 @@ static PyMethodDef id_free_weakref_cb_def = {
/* Adds a reference to the list, remember to decref. */
static GHash *id_weakref_pool_get(ID *id)
{
- GHash *weakinfo_hash = NULL;
-
- if (id_weakref_pool) {
- weakinfo_hash = BLI_ghash_lookup(id_weakref_pool, (void *)id);
- }
- else {
- /* First time, allocate pool. */
- id_weakref_pool = BLI_ghash_ptr_new("rna_global_pool");
- weakinfo_hash = NULL;
- }
-
+ GHash *weakinfo_hash = BLI_ghash_lookup(id_weakref_pool, (void *)id);
if (weakinfo_hash == NULL) {
- /* We use a ghash as a set, we could use libHX's HXMAP_SINGULAR, but would be an extra dep. */
+ /* This could be a set, values are used to keep a reference back to the ID
+ * (all of them are the same). */
weakinfo_hash = BLI_ghash_ptr_new("rna_id");
BLI_ghash_insert(id_weakref_pool, id, weakinfo_hash);
}
-
return weakinfo_hash;
}
@@ -284,14 +274,6 @@ static void id_release_weakref_list(struct ID *id, GHash *weakinfo_hash)
BLI_ghash_remove(id_weakref_pool, (void *)id, NULL, NULL);
BLI_ghash_free(weakinfo_hash, NULL, NULL);
-
- if (BLI_ghash_len(id_weakref_pool) == 0) {
- BLI_ghash_free(id_weakref_pool, NULL, NULL);
- id_weakref_pool = NULL;
-# ifdef DEBUG_RNA_WEAKREF
- printf("id_release_weakref freeing pool\n");
-# endif
- }
}
static void id_release_weakref(struct ID *id)
@@ -311,7 +293,8 @@ void BPY_id_release(struct ID *id)
#endif
#ifdef USE_PYRNA_INVALIDATE_WEAKREF
- if (id_weakref_pool) {
+ /* Check for NULL since this may run before Python has been started. */
+ if (id_weakref_pool != NULL) {
PyGILState_STATE gilstate = PyGILState_Ensure();
id_release_weakref(id);
@@ -4538,7 +4521,7 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr
if ((ret == NULL) /* || BPy_PropDeferred_CheckTypeExact(ret) */ ) {
StructRNA *srna = srna_from_self(cls, "StructRNA.__getattr__");
if (srna) {
- PropertyRNA *prop = RNA_struct_type_find_property(srna, PyUnicode_AsUTF8(attr));
+ PropertyRNA *prop = RNA_struct_type_find_property_no_base(srna, PyUnicode_AsUTF8(attr));
if (prop) {
PointerRNA tptr;
PyErr_Clear(); /* Clear error from tp_getattro. */
@@ -4560,7 +4543,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb
const char *attr_str = PyUnicode_AsUTF8(attr);
if (srna && !pyrna_write_check() &&
- (is_deferred_prop || RNA_struct_type_find_property(srna, attr_str))) {
+ (is_deferred_prop || RNA_struct_type_find_property_no_base(srna, attr_str))) {
PyErr_Format(PyExc_AttributeError,
"pyrna_struct_meta_idprop_setattro() "
"can't set in readonly state '%.200s.%S'",
@@ -7572,7 +7555,7 @@ static PyObject *pyrna_srna_Subtype(StructRNA *srna)
/* Newclass will now have 2 ref's, ???,
* probably 1 is internal since #Py_DECREF here segfaults. */
- /* PyC_ObSpit("new class ref", newclass); */
+ // PyC_ObSpit("new class ref", newclass);
if (newclass) {
/* srna owns one, and the other is owned by the caller. */
@@ -7826,6 +7809,32 @@ void BPY_rna_init(void)
return;
}
#endif
+
+#ifdef USE_PYRNA_INVALIDATE_WEAKREF
+ BLI_assert(id_weakref_pool == NULL);
+ id_weakref_pool = BLI_ghash_ptr_new("rna_global_pool");
+#endif
+}
+
+void BPY_rna_exit(void)
+{
+#ifdef USE_PYRNA_INVALIDATE_WEAKREF
+ /* This can help track down which kinds of data were not released.
+ * If they were in fact freed by Blender, printing their names
+ * will crash giving a useful error with address sanitizer. The likely cause
+ * for this list not being empty is a missing call to: #BKE_libblock_free_data_py. */
+ const int id_weakref_pool_len = BLI_ghash_len(id_weakref_pool);
+ if (id_weakref_pool_len != 0) {
+ printf("Found %d unreleased ID's\n", id_weakref_pool_len);
+ GHashIterator gh_iter;
+ GHASH_ITER (gh_iter, id_weakref_pool) {
+ ID *id = BLI_ghashIterator_getKey(&gh_iter);
+ printf("ID: %s\n", id->name);
+ }
+ }
+ BLI_ghash_free(id_weakref_pool, NULL, NULL);
+ id_weakref_pool = NULL;
+#endif
}
/* 'bpy.data' from Python. */
@@ -8731,6 +8740,8 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
}
#ifdef USE_PEDANTIC_WRITE
+ /* Handle nested draw calls, see: T89253. */
+ const bool rna_disallow_writes_prev = rna_disallow_writes;
rna_disallow_writes = is_readonly ? true : false;
#endif
/* *** Main Caller *** */
@@ -8740,7 +8751,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
/* *** Done Calling *** */
#ifdef USE_PEDANTIC_WRITE
- rna_disallow_writes = false;
+ rna_disallow_writes = rna_disallow_writes_prev;
#endif
RNA_parameter_list_end(&iter);
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 24dbad53eb3..fd468bed470 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -181,6 +181,7 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix);
StructRNA *pyrna_struct_as_srna(PyObject *self, const bool parent, const char *error_prefix);
void BPY_rna_init(void);
+void BPY_rna_exit(void);
PyObject *BPY_rna_module(void);
void BPY_update_rna_module(void);
// PyObject *BPY_rna_doc(void);
diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c
index abbc332d89d..fcc796d4545 100644
--- a/source/blender/python/intern/bpy_rna_array.c
+++ b/source/blender/python/intern/bpy_rna_array.c
@@ -334,7 +334,7 @@ static int validate_array_length(PyObject *rvalue,
}
if (tot != len) {
- /* BLI_snprintf(error_str, error_str_size, "sequence must have length of %d", len); */
+ // BLI_snprintf(error_str, error_str_size, "sequence must have length of %d", len);
PyErr_Format(PyExc_ValueError,
"%s %.200s.%.200s, sequence must have %d items total, not %d",
error_prefix,
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c
index 3c0ea9a9566..5868c76b28f 100644
--- a/source/blender/python/mathutils/mathutils_geometry.c
+++ b/source/blender/python/mathutils/mathutils_geometry.c
@@ -201,7 +201,7 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
}
if (result == 0) {
- /* Co-linear. */
+ /* Collinear. */
Py_RETURN_NONE;
}
diff --git a/source/blender/render/RE_engine.h b/source/blender/render/RE_engine.h
index 6b2861bbefd..dfc0d5d0e9f 100644
--- a/source/blender/render/RE_engine.h
+++ b/source/blender/render/RE_engine.h
@@ -66,6 +66,7 @@ extern "C" {
#define RE_USE_GPU_CONTEXT 512
#define RE_USE_CUSTOM_FREESTYLE 1024
#define RE_USE_NO_IMAGE_SAVE 2048
+#define RE_USE_ALEMBIC_PROCEDURAL 4096
/* RenderEngine.flag */
#define RE_ENGINE_ANIMATION 1
@@ -235,6 +236,12 @@ void RE_engines_register(RenderEngineType *render_type);
bool RE_engine_is_opengl(RenderEngineType *render_type);
+/**
+ * Return true if the RenderEngineType has native support for direct loading of Alembic data. For
+ * Cycles, this also checks that the experimental feature set is enabled.
+ */
+bool RE_engine_supports_alembic_procedural(const RenderEngineType *render_type, Scene *scene);
+
RenderEngineType *RE_engines_find(const char *idname);
rcti *RE_engine_get_current_tiles(struct Render *re, int *r_total_tiles, bool *r_needs_free);
diff --git a/source/blender/render/RE_pipeline.h b/source/blender/render/RE_pipeline.h
index 4534c86f7f7..cd839385bfb 100644
--- a/source/blender/render/RE_pipeline.h
+++ b/source/blender/render/RE_pipeline.h
@@ -155,6 +155,8 @@ typedef struct RenderResult {
char *error;
struct StampData *stamp_data;
+
+ bool passes_allocated;
} RenderResult;
typedef struct RenderStats {
diff --git a/source/blender/render/intern/engine.c b/source/blender/render/intern/engine.c
index 657cd1f606b..1510587502b 100644
--- a/source/blender/render/intern/engine.c
+++ b/source/blender/render/intern/engine.c
@@ -128,6 +128,19 @@ bool RE_engine_is_opengl(RenderEngineType *render_type)
return (render_type->draw_engine != NULL) && DRW_engine_render_support(render_type->draw_engine);
}
+bool RE_engine_supports_alembic_procedural(const RenderEngineType *render_type, Scene *scene)
+{
+ if ((render_type->flag & RE_USE_ALEMBIC_PROCEDURAL) == 0) {
+ return false;
+ }
+
+ if (BKE_scene_uses_cycles(scene) && !BKE_scene_uses_cycles_experimental_features(scene)) {
+ return false;
+ }
+
+ return true;
+}
+
/* Create, Free */
RenderEngine *RE_engine_create(RenderEngineType *type)
@@ -199,6 +212,8 @@ static RenderResult *render_result_from_bake(RenderEngine *engine, int x, int y,
RenderPass *primitive_pass = render_layer_add_pass(rr, rl, 4, "BakePrimitive", "", "RGBA");
RenderPass *differential_pass = render_layer_add_pass(rr, rl, 4, "BakeDifferential", "", "RGBA");
+ render_result_passes_allocated_ensure(rr);
+
/* Fill render passes from bake pixel array, to be read by the render engine. */
for (int ty = 0; ty < h; ty++) {
size_t offset = ty * w * 4;
@@ -315,6 +330,7 @@ RenderResult *RE_engine_begin_result(
/* can be NULL if we CLAMP the width or height to 0 */
if (result) {
render_result_clone_passes(re, result, viewname);
+ render_result_passes_allocated_ensure(result);
RenderPart *pa;
@@ -387,6 +403,14 @@ void RE_engine_end_result(
return;
}
+ if (!re->result->passes_allocated) {
+ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
+ if (!re->result->passes_allocated) {
+ render_result_passes_allocated_ensure(re->result);
+ }
+ BLI_rw_mutex_unlock(&re->resultmutex);
+ }
+
/* merge. on break, don't merge in result for preview renders, looks nicer */
if (!highlight) {
/* for exr tile render, detect tiles that are done */
diff --git a/source/blender/render/intern/pipeline.c b/source/blender/render/intern/pipeline.c
index 479ad9209f0..9ef52b4bf41 100644
--- a/source/blender/render/intern/pipeline.c
+++ b/source/blender/render/intern/pipeline.c
@@ -354,6 +354,7 @@ RenderResult *RE_AcquireResultWrite(Render *re)
{
if (re) {
BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
+ render_result_passes_allocated_ensure(re->result);
return re->result;
}
diff --git a/source/blender/render/intern/render_result.c b/source/blender/render/intern/render_result.c
index 091f5964291..c29ab342ed7 100644
--- a/source/blender/render/intern/render_result.c
+++ b/source/blender/render/intern/render_result.c
@@ -222,7 +222,6 @@ RenderPass *render_layer_add_pass(RenderResult *rr,
{
const int view_id = BLI_findstringindex(&rr->views, viewname, offsetof(RenderView, name));
RenderPass *rpass = MEM_callocN(sizeof(RenderPass), name);
- size_t rectsize = ((size_t)rr->rectx) * rr->recty * channels;
rpass->channels = channels;
rpass->rectx = rl->rectx;
@@ -249,33 +248,6 @@ RenderPass *render_layer_add_pass(RenderResult *rr,
}
}
- /* Always allocate combined for display, in case of save buffers
- * other passes are not allocated and only saved to the EXR file. */
- if (rl->exrhandle == NULL || STREQ(rpass->name, RE_PASSNAME_COMBINED)) {
- float *rect;
- int x;
-
- rpass->rect = MEM_callocN(sizeof(float) * rectsize, name);
- if (rpass->rect == NULL) {
- MEM_freeN(rpass);
- return NULL;
- }
-
- if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) {
- /* initialize to max speed */
- rect = rpass->rect;
- for (x = rectsize - 1; x >= 0; x--) {
- rect[x] = PASS_VECTOR_MAX;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_Z)) {
- rect = rpass->rect;
- for (x = rectsize - 1; x >= 0; x--) {
- rect[x] = 10e10;
- }
- }
- }
-
BLI_addtail(&rl->passes, rpass);
return rpass;
@@ -316,6 +288,8 @@ RenderResult *render_result_new(
rr->do_exr_tile = true;
}
+ rr->passes_allocated = false;
+
render_result_views_new(rr, &re->r);
/* check renderdata for amount of layers */
@@ -484,6 +458,40 @@ RenderResult *render_result_new(
return rr;
}
+void render_result_passes_allocated_ensure(RenderResult *rr)
+{
+ LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) {
+ LISTBASE_FOREACH (RenderPass *, rp, &rl->passes) {
+ if (rl->exrhandle != NULL && !STREQ(rp->name, RE_PASSNAME_COMBINED)) {
+ continue;
+ }
+
+ if (rp->rect != NULL) {
+ continue;
+ }
+
+ const size_t rectsize = ((size_t)rr->rectx) * rr->recty * rp->channels;
+ rp->rect = MEM_callocN(sizeof(float) * rectsize, rp->name);
+
+ if (STREQ(rp->name, RE_PASSNAME_VECTOR)) {
+ /* initialize to max speed */
+ float *rect = rp->rect;
+ for (int x = rectsize - 1; x >= 0; x--) {
+ rect[x] = PASS_VECTOR_MAX;
+ }
+ }
+ else if (STREQ(rp->name, RE_PASSNAME_Z)) {
+ float *rect = rp->rect;
+ for (int x = rectsize - 1; x >= 0; x--) {
+ rect[x] = 10e10;
+ }
+ }
+ }
+ }
+
+ rr->passes_allocated = true;
+}
+
void render_result_clone_passes(Render *re, RenderResult *rr, const char *viewname)
{
RenderLayer *rl;
@@ -1243,6 +1251,7 @@ void render_result_exr_file_end(Render *re, RenderEngine *engine)
render_result_free_list(&re->fullresult, re->result);
re->result = render_result_new(re, &re->disprect, RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS);
re->result->stamp_data = stamp_data;
+ render_result_passes_allocated_ensure(re->result);
BLI_rw_mutex_unlock(&re->resultmutex);
LISTBASE_FOREACH (RenderLayer *, rl, &re->result->layers) {
diff --git a/source/blender/render/intern/render_result.h b/source/blender/render/intern/render_result.h
index 7732c113700..1fc64a4ea97 100644
--- a/source/blender/render/intern/render_result.h
+++ b/source/blender/render/intern/render_result.h
@@ -55,6 +55,8 @@ struct RenderResult *render_result_new(struct Render *re,
const char *layername,
const char *viewname);
+void render_result_passes_allocated_ensure(struct RenderResult *rr);
+
struct RenderResult *render_result_new_from_exr(
void *exrhandle, const char *colorspace, bool predivide, int rectx, int recty);
diff --git a/source/blender/sequencer/CMakeLists.txt b/source/blender/sequencer/CMakeLists.txt
index e324bc8b407..f060e6ad69b 100644
--- a/source/blender/sequencer/CMakeLists.txt
+++ b/source/blender/sequencer/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC
../render
../windowmanager
../../../intern/atomic
+ ../../../intern/clog
../../../intern/guardedalloc
# dna_type_offsets.h
diff --git a/source/blender/sequencer/SEQ_add.h b/source/blender/sequencer/SEQ_add.h
index 2941eb6f4c0..4025f1a4a04 100644
--- a/source/blender/sequencer/SEQ_add.h
+++ b/source/blender/sequencer/SEQ_add.h
@@ -79,14 +79,16 @@ struct Sequence *SEQ_add_image_strip(struct Main *bmain,
struct Sequence *SEQ_add_sound_strip(struct Main *bmain,
struct Scene *scene,
struct ListBase *seqbase,
- struct SeqLoadData *load_data);
+ struct SeqLoadData *load_data,
+ const double audio_offset);
struct Sequence *SEQ_add_meta_strip(struct Scene *scene,
struct ListBase *seqbase,
struct SeqLoadData *load_data);
struct Sequence *SEQ_add_movie_strip(struct Main *bmain,
struct Scene *scene,
struct ListBase *seqbase,
- struct SeqLoadData *load_data);
+ struct SeqLoadData *load_data,
+ double *r_video_start_offset);
struct Sequence *SEQ_add_scene_strip(struct Scene *scene,
struct ListBase *seqbase,
struct SeqLoadData *load_data);
diff --git a/source/blender/sequencer/SEQ_edit.h b/source/blender/sequencer/SEQ_edit.h
index 6d043dffe72..fbbf4bc53ea 100644
--- a/source/blender/sequencer/SEQ_edit.h
+++ b/source/blender/sequencer/SEQ_edit.h
@@ -53,7 +53,8 @@ struct Sequence *SEQ_edit_strip_split(struct Main *bmain,
struct ListBase *seqbase,
struct Sequence *seq,
const int timeline_frame,
- const eSeqSplitMethod method);
+ const eSeqSplitMethod method,
+ const char **r_error);
bool SEQ_edit_remove_gaps(struct Scene *scene,
struct ListBase *seqbase,
const int initial_frame,
diff --git a/source/blender/sequencer/SEQ_iterator.h b/source/blender/sequencer/SEQ_iterator.h
index cb2091511a9..3ade7309f89 100644
--- a/source/blender/sequencer/SEQ_iterator.h
+++ b/source/blender/sequencer/SEQ_iterator.h
@@ -73,6 +73,7 @@ struct Sequence *SEQ_iterator_yield(SeqIterator *iterator);
SeqCollection *SEQ_collection_create(const char *name);
SeqCollection *SEQ_collection_duplicate(SeqCollection *collection);
uint SEQ_collection_len(const SeqCollection *collection);
+bool SEQ_collection_has_strip(const struct Sequence *seq, const SeqCollection *collection);
bool SEQ_collection_append_strip(struct Sequence *seq, SeqCollection *data);
bool SEQ_collection_remove_strip(struct Sequence *seq, SeqCollection *data);
void SEQ_collection_free(SeqCollection *collection);
diff --git a/source/blender/sequencer/SEQ_relations.h b/source/blender/sequencer/SEQ_relations.h
index 366c1002e22..54e53193b48 100644
--- a/source/blender/sequencer/SEQ_relations.h
+++ b/source/blender/sequencer/SEQ_relations.h
@@ -65,6 +65,9 @@ void SEQ_cache_iterate(
void *userdata,
bool callback_init(void *userdata, size_t item_count),
bool callback_iter(void *userdata, struct Sequence *seq, int timeline_frame, int cache_type));
+struct Sequence *SEQ_find_metastrip_by_sequence(ListBase *seqbase /* = ed->seqbase */,
+ struct Sequence *meta /* = NULL */,
+ struct Sequence *seq);
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c
index 3ca0555d9a5..d4adad9a34d 100644
--- a/source/blender/sequencer/intern/effects.c
+++ b/source/blender/sequencer/intern/effects.c
@@ -61,6 +61,7 @@
#include "SEQ_effects.h"
#include "SEQ_proxy.h"
+#include "SEQ_relations.h"
#include "SEQ_render.h"
#include "SEQ_utils.h"
@@ -3023,7 +3024,7 @@ static ImBuf *do_adjustment_impl(const SeqRenderData *context, Sequence *seq, fl
if (!i) {
Sequence *meta;
- meta = seq_find_metastrip_by_sequence(&ed->seqbase, NULL, seq);
+ meta = SEQ_find_metastrip_by_sequence(&ed->seqbase, NULL, seq);
if (meta) {
i = do_adjustment_impl(context, meta, timeline_frame);
@@ -3069,8 +3070,6 @@ static void init_speed_effect(Sequence *seq)
seq->effectdata = MEM_callocN(sizeof(SpeedControlVars), "speedcontrolvars");
v = (SpeedControlVars *)seq->effectdata;
- v->frameMap = NULL;
- v->length = 0;
v->speed_control_type = SEQ_SPEED_STRETCH;
v->speed_fader = 1.0f;
v->speed_fader_length = 0.0f;
@@ -3080,9 +3079,7 @@ static void init_speed_effect(Sequence *seq)
static void load_speed_effect(Sequence *seq)
{
SpeedControlVars *v = (SpeedControlVars *)seq->effectdata;
-
v->frameMap = NULL;
- v->length = 0;
}
static int num_inputs_speed(void)
@@ -3105,7 +3102,6 @@ static void copy_speed_effect(Sequence *dst, Sequence *src, const int UNUSED(fla
dst->effectdata = MEM_dupallocN(src->effectdata);
v = (SpeedControlVars *)dst->effectdata;
v->frameMap = NULL;
- v->length = 0;
}
static int early_out_speed(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1))
@@ -3127,164 +3123,114 @@ static int seq_effect_speed_get_strip_content_length(const Sequence *seq)
return seq->len;
}
-void seq_effect_speed_rebuild_map(Scene *scene, Sequence *seq, bool force)
+static FCurve *seq_effect_speed_speed_factor_curve_get(Scene *scene, Sequence *seq)
{
- int timeline_frame;
- float fallback_fac = 1.0f;
- SpeedControlVars *v = (SpeedControlVars *)seq->effectdata;
- FCurve *fcu = NULL;
-
- /* if not already done, load / initialize data */
- SEQ_effect_handle_get(seq);
+ return id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL);
+}
- if ((force == false) && (seq->len == v->length) && (v->frameMap != NULL)) {
- return;
- }
+/* Build frame map when speed in mode #SEQ_SPEED_MULTIPLY is animated.
+ * This is, because `target_frame` value is integrated over time. */
+void seq_effect_speed_rebuild_map(Scene *scene, Sequence *seq)
+{
if ((seq->seq1 == NULL) || (seq->len < 1)) {
- /* make coverity happy and check for (CID 598) input strip ... */
- return;
+ return; /* Make coverity happy and check for (CID 598) input strip... */
}
- /* XXX(campbell): new in 2.5x. should we use the animation system this way?
- * The fcurve is needed because many frames need evaluating at once. */
- switch (v->speed_control_type) {
- case SEQ_SPEED_MULTIPLY: {
- fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL);
- break;
- }
- case SEQ_SPEED_FRAME_NUMBER: {
- fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_frame_number", 0, NULL);
- break;
- }
- case SEQ_SPEED_LENGTH: {
- fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_length", 0, NULL);
- break;
- }
+ FCurve *fcu = seq_effect_speed_speed_factor_curve_get(scene, seq);
+ if (fcu == NULL) {
+ return;
}
- if (!v->frameMap || v->length != seq->len) {
- if (v->frameMap) {
- MEM_freeN(v->frameMap);
- }
-
- v->length = seq->len;
- v->frameMap = MEM_callocN(sizeof(float) * v->length, "speedcontrol frameMap");
+ SpeedControlVars *v = (SpeedControlVars *)seq->effectdata;
+ if (v->frameMap) {
+ MEM_freeN(v->frameMap);
}
- fallback_fac = 1.0;
+ const int effect_strip_length = seq->enddisp - seq->startdisp;
+ v->frameMap = MEM_mallocN(sizeof(float) * effect_strip_length, __func__);
+ v->frameMap[0] = 0.0f;
- const int target_strip_length = seq_effect_speed_get_strip_content_length(seq->seq1);
-
- if (v->speed_control_type == SEQ_SPEED_STRETCH) {
- if ((seq->seq1->enddisp != seq->seq1->start) && (target_strip_length != 0)) {
- fallback_fac = (float)target_strip_length / (float)(seq->seq1->enddisp - seq->seq1->start);
- fcu = NULL;
- }
- }
- else {
- /* if there is no fcurve, use value as simple multiplier */
- if (!fcu) {
- switch (v->speed_control_type) {
- case SEQ_SPEED_MULTIPLY: {
- fallback_fac = v->speed_fader;
- break;
- }
- case SEQ_SPEED_FRAME_NUMBER: {
- fallback_fac = v->speed_fader_frame_number;
- break;
- }
- case SEQ_SPEED_LENGTH: {
- fallback_fac = v->speed_fader_length;
- break;
- }
- }
- }
+ float target_frame = 0;
+ for (int frame_index = 1; frame_index < effect_strip_length; frame_index++) {
+ target_frame += evaluate_fcurve(fcu, seq->startdisp + frame_index);
+ v->frameMap[frame_index] = target_frame;
}
+}
- if (ELEM(v->speed_control_type, SEQ_SPEED_MULTIPLY, SEQ_SPEED_STRETCH)) {
- float cursor = 0;
- float facf;
-
- v->frameMap[0] = 0;
- v->lastValidFrame = 0;
-
- for (timeline_frame = 1; timeline_frame < v->length; timeline_frame++) {
- if (fcu) {
- facf = evaluate_fcurve(fcu, seq->startdisp + timeline_frame);
- }
- else {
- facf = fallback_fac;
- }
-
- cursor += facf;
-
- if (cursor >= target_strip_length) {
- v->frameMap[timeline_frame] = target_strip_length - 1;
- }
- else {
- v->frameMap[timeline_frame] = cursor;
- v->lastValidFrame = timeline_frame;
- }
- }
+static void seq_effect_speed_frame_map_ensure(Scene *scene, Sequence *seq)
+{
+ SpeedControlVars *v = (SpeedControlVars *)seq->effectdata;
+ if (v->frameMap != NULL) {
+ return;
}
- else {
- float facf;
- v->lastValidFrame = 0;
- for (timeline_frame = 0; timeline_frame < v->length; timeline_frame++) {
+ seq_effect_speed_rebuild_map(scene, seq);
+}
- if (fcu) {
- facf = evaluate_fcurve(fcu, seq->startdisp + timeline_frame);
- }
- else {
- facf = fallback_fac;
- }
+/* Override timeline_frame when rendering speed effect input. */
+float seq_speed_effect_target_frame_get(Scene *scene,
+ Sequence *seq_speed,
+ float timeline_frame,
+ int input)
+{
+ if (seq_speed->seq1 == NULL) {
+ return 0.0f;
+ }
- if (v->speed_control_type == SEQ_SPEED_LENGTH) {
- facf *= target_strip_length;
- facf /= 100.0f;
- }
+ SEQ_effect_handle_get(seq_speed); /* Ensure, that data are initialized. */
+ int frame_index = seq_give_frame_index(seq_speed, timeline_frame);
+ SpeedControlVars *s = (SpeedControlVars *)seq_speed->effectdata;
+ const Sequence *source = seq_speed->seq1;
- if (facf >= target_strip_length) {
- facf = target_strip_length - 1;
+ float target_frame = 0.0f;
+ switch (s->speed_control_type) {
+ case SEQ_SPEED_STRETCH: {
+ const float target_content_length = seq_effect_speed_get_strip_content_length(source);
+ const float target_strip_length = source->enddisp - source->startdisp;
+ const float ratio = target_content_length / target_strip_length;
+ target_frame = frame_index * ratio;
+ break;
+ }
+ case SEQ_SPEED_MULTIPLY: {
+ FCurve *fcu = seq_effect_speed_speed_factor_curve_get(scene, seq_speed);
+ if (fcu != NULL) {
+ seq_effect_speed_frame_map_ensure(scene, seq_speed);
+ target_frame = s->frameMap[frame_index];
}
else {
- v->lastValidFrame = timeline_frame;
+ target_frame = frame_index * s->speed_fader;
}
- v->frameMap[timeline_frame] = facf;
+ break;
}
+ case SEQ_SPEED_LENGTH:
+ target_frame = seq_effect_speed_get_strip_content_length(source) *
+ (s->speed_fader_length / 100.0f);
+ break;
+ case SEQ_SPEED_FRAME_NUMBER:
+ target_frame = s->speed_fader_frame_number;
+ break;
}
-}
-/* Override timeline_frame when rendering speed effect input. */
-float seq_speed_effect_target_frame_get(const SeqRenderData *context,
- Sequence *seq,
- float timeline_frame,
- int input)
-{
- int frame_index = seq_give_frame_index(seq, timeline_frame);
- SpeedControlVars *s = (SpeedControlVars *)seq->effectdata;
- seq_effect_speed_rebuild_map(context->scene, seq, false);
+ CLAMP(target_frame, 0, seq_effect_speed_get_strip_content_length(source));
+ target_frame += seq_speed->start;
/* No interpolation. */
if ((s->flags & SEQ_SPEED_USE_INTERPOLATION) == 0) {
- return seq->start + s->frameMap[frame_index];
+ return target_frame;
}
- /* We need to provide current and next image for interpolation. */
- if (input == 0) { /* Current frame. */
- return floor(seq->start + s->frameMap[frame_index]);
- }
- /* Next frame. */
- return ceil(seq->start + s->frameMap[frame_index]);
+ /* Interpolation is used, switch between current and next frame based on which input is
+ * requested. */
+ return input == 0 ? target_frame : ceil(target_frame);
}
-static float speed_effect_interpolation_ratio_get(SpeedControlVars *s,
- Sequence *seq,
+static float speed_effect_interpolation_ratio_get(Scene *scene,
+ Sequence *seq_speed,
float timeline_frame)
{
- int frame_index = seq_give_frame_index(seq, timeline_frame);
- return s->frameMap[frame_index] - floor(s->frameMap[frame_index]);
+ const float target_frame = seq_speed_effect_target_frame_get(
+ scene, seq_speed, timeline_frame, 0);
+ return target_frame - floor(target_frame);
}
static ImBuf *do_speed_effect(const SeqRenderData *context,
@@ -3302,7 +3248,7 @@ static ImBuf *do_speed_effect(const SeqRenderData *context,
if (s->flags & SEQ_SPEED_USE_INTERPOLATION) {
out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3);
- facf0 = facf1 = speed_effect_interpolation_ratio_get(s, seq, timeline_frame);
+ facf0 = facf1 = speed_effect_interpolation_ratio_get(context->scene, seq, timeline_frame);
/* Current frame is ibuf1, next frame is ibuf2. */
out = seq_render_effect_execute_threaded(
&cross_effect, context, NULL, timeline_frame, facf0, facf1, ibuf1, ibuf2, ibuf3);
diff --git a/source/blender/sequencer/intern/effects.h b/source/blender/sequencer/intern/effects.h
index 1bce4f324c3..25ba4d8956e 100644
--- a/source/blender/sequencer/intern/effects.h
+++ b/source/blender/sequencer/intern/effects.h
@@ -39,8 +39,8 @@ struct Sequence;
*/
struct SeqEffectHandle seq_effect_get_sequence_blend(struct Sequence *seq);
-void seq_effect_speed_rebuild_map(struct Scene *scene, struct Sequence *seq, bool force);
-float seq_speed_effect_target_frame_get(const struct SeqRenderData *context,
+void seq_effect_speed_rebuild_map(struct Scene *scene, struct Sequence *seq);
+float seq_speed_effect_target_frame_get(struct Scene *scene,
struct Sequence *seq,
float timeline_frame,
int input);
diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index 604c9900355..86bd840ce31 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -102,7 +102,7 @@
/* <cache type>-<resolution X>x<resolution Y>-<rendersize>%(<view_id>)-<frame no>.dcf */
#define DCACHE_FNAME_FORMAT "%d-%dx%d-%d%%(%d)-%d.dcf"
#define DCACHE_IMAGES_PER_FILE 100
-#define DCACHE_CURRENT_VERSION 1
+#define DCACHE_CURRENT_VERSION 2
#define COLORSPACE_NAME_MAX 64 /* XXX: defined in imb intern */
typedef struct DiskCacheHeaderEntry {
@@ -496,24 +496,34 @@ static size_t deflate_imbuf_to_file(ImBuf *ibuf,
int level,
DiskCacheHeaderEntry *header_entry)
{
- if (ibuf->rect) {
- return BLI_gzip_mem_to_file_at_pos(
- ibuf->rect, header_entry->size_raw, file, header_entry->offset, level);
+ void *data = (ibuf->rect != NULL) ? (void *)ibuf->rect : (void *)ibuf->rect_float;
+
+ /* Apply compression if wanted, otherwise just write directly to the file. */
+ if (level > 0) {
+ return BLI_file_zstd_from_mem_at_pos(
+ data, header_entry->size_raw, file, header_entry->offset, level);
}
- return BLI_gzip_mem_to_file_at_pos(
- ibuf->rect_float, header_entry->size_raw, file, header_entry->offset, level);
+ fseek(file, header_entry->offset, SEEK_SET);
+ return fwrite(data, 1, header_entry->size_raw, file);
}
static size_t inflate_file_to_imbuf(ImBuf *ibuf, FILE *file, DiskCacheHeaderEntry *header_entry)
{
- if (ibuf->rect) {
- return BLI_ungzip_file_to_mem_at_pos(
- ibuf->rect, header_entry->size_raw, file, header_entry->offset);
+ void *data = (ibuf->rect != NULL) ? (void *)ibuf->rect : (void *)ibuf->rect_float;
+ char header[4];
+ fseek(file, header_entry->offset, SEEK_SET);
+ if (fread(header, 1, sizeof(header), file) != sizeof(header)) {
+ return 0;
+ }
+
+ /* Check if the data is compressed or raw. */
+ if (BLI_file_magic_is_zstd(header)) {
+ return BLI_file_unzstd_to_mem_at_pos(data, header_entry->size_raw, file, header_entry->offset);
}
- return BLI_ungzip_file_to_mem_at_pos(
- ibuf->rect_float, header_entry->size_raw, file, header_entry->offset);
+ fseek(file, header_entry->offset, SEEK_SET);
+ return fread(data, 1, header_entry->size_raw, file);
}
static bool seq_disk_cache_read_header(FILE *file, DiskCacheHeader *header)
diff --git a/source/blender/sequencer/intern/iterator.c b/source/blender/sequencer/intern/iterator.c
index 09f033e70fb..333a8e46c44 100644
--- a/source/blender/sequencer/intern/iterator.c
+++ b/source/blender/sequencer/intern/iterator.c
@@ -123,6 +123,14 @@ uint SEQ_collection_len(const SeqCollection *collection)
}
/**
+ * Check if seq is in collection.
+ */
+bool SEQ_collection_has_strip(const Sequence *seq, const SeqCollection *collection)
+{
+ return BLI_gset_haskey(collection->set, seq);
+}
+
+/**
* Query strips from seqbase. seq_reference is used by query function as filter condition.
*
* \param seq_reference: reference strip for query function
diff --git a/source/blender/sequencer/intern/prefetch.c b/source/blender/sequencer/intern/prefetch.c
index 15609a76f5c..dd2d828415c 100644
--- a/source/blender/sequencer/intern/prefetch.c
+++ b/source/blender/sequencer/intern/prefetch.c
@@ -53,7 +53,9 @@
#include "DEG_depsgraph_debug.h"
#include "DEG_depsgraph_query.h"
+#include "SEQ_iterator.h"
#include "SEQ_prefetch.h"
+#include "SEQ_relations.h"
#include "SEQ_render.h"
#include "SEQ_sequencer.h"
@@ -359,67 +361,93 @@ void seq_prefetch_free(Scene *scene)
scene->ed->prefetch_job = NULL;
}
-/* Skip frame if we need to render 3D scene strip. Rendering 3D scene requires main lock or setting
- * up render job that doesn't have API to do openGL renders which can be used for sequencer. */
-static bool seq_prefetch_do_skip_frame(PrefetchJob *pfjob, ListBase *seqbase)
+static bool seq_prefetch_seq_has_disk_cache(PrefetchJob *pfjob,
+ Sequence *seq,
+ bool can_have_final_image)
{
- float cfra = seq_prefetch_cfra(pfjob);
- Sequence *seq_arr[MAXSEQ + 1];
- int count = seq_get_shown_sequences(seqbase, cfra, 0, seq_arr);
SeqRenderData *ctx = &pfjob->context_cpy;
- ImBuf *ibuf = NULL;
+ float cfra = seq_prefetch_cfra(pfjob);
- /* Disable prefetching 3D scene strips, but check for disk cache. */
- for (int i = 0; i < count; i++) {
- if (seq_arr[i]->type == SEQ_TYPE_META &&
- seq_prefetch_do_skip_frame(pfjob, &seq_arr[i]->seqbase)) {
- return true;
- }
+ ImBuf *ibuf = seq_cache_get(ctx, seq, cfra, SEQ_CACHE_STORE_PREPROCESSED);
+ if (ibuf != NULL) {
+ IMB_freeImBuf(ibuf);
+ return true;
+ }
- if (seq_arr[i]->type == SEQ_TYPE_SCENE && (seq_arr[i]->flag & SEQ_SCENE_STRIPS) == 0) {
- int cached_types = 0;
+ ibuf = seq_cache_get(ctx, seq, cfra, SEQ_CACHE_STORE_RAW);
+ if (ibuf != NULL) {
+ IMB_freeImBuf(ibuf);
+ return true;
+ }
- ibuf = seq_cache_get(ctx, seq_arr[i], cfra, SEQ_CACHE_STORE_FINAL_OUT);
- if (ibuf != NULL) {
- cached_types |= SEQ_CACHE_STORE_FINAL_OUT;
- IMB_freeImBuf(ibuf);
- ibuf = NULL;
- }
+ if (!can_have_final_image) {
+ return false;
+ }
- ibuf = seq_cache_get(ctx, seq_arr[i], cfra, SEQ_CACHE_STORE_COMPOSITE);
- if (ibuf != NULL) {
- cached_types |= SEQ_CACHE_STORE_COMPOSITE;
- IMB_freeImBuf(ibuf);
- ibuf = NULL;
- }
+ ibuf = seq_cache_get(ctx, seq, cfra, SEQ_CACHE_STORE_FINAL_OUT);
+ if (ibuf != NULL) {
+ IMB_freeImBuf(ibuf);
+ return true;
+ }
- ibuf = seq_cache_get(ctx, seq_arr[i], cfra, SEQ_CACHE_STORE_PREPROCESSED);
- if (ibuf != NULL) {
- cached_types |= SEQ_CACHE_STORE_PREPROCESSED;
- IMB_freeImBuf(ibuf);
- ibuf = NULL;
- }
+ return false;
+}
- ibuf = seq_cache_get(ctx, seq_arr[i], cfra, SEQ_CACHE_STORE_RAW);
- if (ibuf != NULL) {
- cached_types |= SEQ_CACHE_STORE_RAW;
- IMB_freeImBuf(ibuf);
- ibuf = NULL;
- }
+static bool seq_prefetch_scene_strip_is_rendered(PrefetchJob *pfjob,
+ ListBase *seqbase,
+ SeqCollection *scene_strips,
+ bool is_recursive_check)
+{
+ float cfra = seq_prefetch_cfra(pfjob);
+ Sequence *seq_arr[MAXSEQ + 1];
+ int count = seq_get_shown_sequences(seqbase, cfra, 0, seq_arr);
- if ((cached_types & (SEQ_CACHE_STORE_RAW | SEQ_CACHE_STORE_PREPROCESSED)) != 0) {
- continue;
- }
+ /* Iterate over rendered strips. */
+ for (int i = 0; i < count; i++) {
+ Sequence *seq = seq_arr[i];
+ if (seq->type == SEQ_TYPE_META &&
+ seq_prefetch_scene_strip_is_rendered(pfjob, &seq->seqbase, scene_strips, true)) {
+ return true;
+ }
+
+ /* Disable prefetching 3D scene strips, but check for disk cache. */
+ if (seq->type == SEQ_TYPE_SCENE && (seq->flag & SEQ_SCENE_STRIPS) == 0 &&
+ !seq_prefetch_seq_has_disk_cache(pfjob, seq, !is_recursive_check)) {
+ return true;
+ }
- /* It is only safe to use these cache types if strip is last in stack. */
- if (i == count - 1 && (cached_types & SEQ_CACHE_STORE_FINAL_OUT) != 0) {
- continue;
+ /* Check if strip is effect of scene strip or uses it as modifier. This is recursive check. */
+ Sequence *seq_scene;
+ SEQ_ITERATOR_FOREACH (seq_scene, scene_strips) {
+ if (SEQ_relations_render_loop_check(seq, seq_scene)) {
+ return true;
}
+ }
+ }
+ return false;
+}
- return true;
+static SeqCollection *query_scene_strips(ListBase *seqbase)
+{
+ SeqCollection *collection = SEQ_query_all_strips_recursive(seqbase);
+ LISTBASE_FOREACH (Sequence *, seq, seqbase) {
+ if (seq->type != SEQ_TYPE_SCENE || (seq->flag & SEQ_SCENE_STRIPS) != 0) {
+ SEQ_collection_remove_strip(seq, collection);
}
}
+ return collection;
+}
+/* Prefetch must avoid rendering scene strips, because rendering in background locks UI and can
+ * make it unresponsive for long time periods. */
+static bool seq_prefetch_must_skip_frame(PrefetchJob *pfjob, ListBase *seqbase)
+{
+ SeqCollection *scene_strips = query_scene_strips(seqbase);
+ if (seq_prefetch_scene_strip_is_rendered(pfjob, seqbase, scene_strips, false)) {
+ SEQ_collection_free(scene_strips);
+ return true;
+ }
+ SEQ_collection_free(scene_strips);
return false;
}
@@ -464,7 +492,7 @@ static void *seq_prefetch_frames(void *job)
pfjob->scene_eval->ed->prefetch_job = pfjob;
ListBase *seqbase = SEQ_active_seqbase_get(SEQ_editing_get(pfjob->scene, false));
- if (seq_prefetch_do_skip_frame(pfjob, seqbase)) {
+ if (seq_prefetch_must_skip_frame(pfjob, seqbase)) {
pfjob->num_frames_prefetched++;
continue;
}
diff --git a/source/blender/sequencer/intern/render.c b/source/blender/sequencer/intern/render.c
index aba84743621..0c07a25e2e2 100644
--- a/source/blender/sequencer/intern/render.c
+++ b/source/blender/sequencer/intern/render.c
@@ -840,7 +840,7 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context,
for (i = 0; i < 3; i++) {
/* Speed effect requires time remapping of `timeline_frame` for input(s). */
if (input[0] && seq->type == SEQ_TYPE_SPEED) {
- float target_frame = seq_speed_effect_target_frame_get(context, seq, timeline_frame, i);
+ float target_frame = seq_speed_effect_target_frame_get(scene, seq, timeline_frame, i);
ibuf[i] = seq_render_strip(context, state, input[0], target_frame);
}
else { /* Other effects. */
diff --git a/source/blender/sequencer/intern/sound.c b/source/blender/sequencer/intern/sound.c
index 1054dbeeba6..c53aacddcfe 100644
--- a/source/blender/sequencer/intern/sound.c
+++ b/source/blender/sequencer/intern/sound.c
@@ -111,7 +111,12 @@ void SEQ_sound_update_bounds(Scene *scene, Sequence *seq)
/* We have to take into account start frame of the sequence's scene! */
int startofs = seq->startofs + seq->anim_startofs + seq->scene->r.sfra;
- BKE_sound_move_scene_sound(scene, seq->scene_sound, seq->startdisp, seq->enddisp, startofs);
+ BKE_sound_move_scene_sound(scene,
+ seq->scene_sound,
+ seq->startdisp,
+ seq->enddisp,
+ startofs,
+ seq->sound->offset_time);
}
}
else {
diff --git a/source/blender/sequencer/intern/strip_add.c b/source/blender/sequencer/intern/strip_add.c
index dab5593be37..9081c655d2f 100644
--- a/source/blender/sequencer/intern/strip_add.c
+++ b/source/blender/sequencer/intern/strip_add.c
@@ -99,7 +99,7 @@ void SEQ_add_load_data_init(SeqLoadData *load_data,
static void seq_add_generic_update(Scene *scene, ListBase *seqbase, Sequence *seq)
{
- SEQ_sequence_base_unique_name_recursive(scene, seqbase, seq);
+ SEQ_sequence_base_unique_name_recursive(scene, &scene->ed->seqbase, seq);
SEQ_time_update_sequence_bounds(scene, seq);
SEQ_sort(seqbase);
SEQ_relations_invalidate_cache_composite(scene, seq);
@@ -382,9 +382,14 @@ Sequence *SEQ_add_image_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
* \return created strip
*/
-Sequence *SEQ_add_sound_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqLoadData *load_data)
+Sequence *SEQ_add_sound_strip(Main *bmain,
+ Scene *scene,
+ ListBase *seqbase,
+ SeqLoadData *load_data,
+ const double audio_offset)
{
bSound *sound = BKE_sound_new_file(bmain, load_data->path); /* Handles relative paths. */
+ sound->offset_time = audio_offset;
SoundInfo info;
bool sound_loaded = BKE_sound_info_get(bmain, sound, &info);
@@ -398,14 +403,35 @@ Sequence *SEQ_add_sound_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
return NULL;
}
- Sequence *seq = SEQ_sequence_alloc(
- seqbase, load_data->start_frame, load_data->channel, SEQ_TYPE_SOUND_RAM);
+ /* If this sound it part of a video, then the sound might start after the video.
+ * In this case we need to then offset the start frame of the audio so it syncs up
+ * properly with the video.
+ */
+ int start_frame_offset = info.start_offset * FPS;
+ double start_frame_offset_remainer = (info.start_offset * FPS - start_frame_offset) / FPS;
+
+ if (start_frame_offset_remainer > FLT_EPSILON) {
+ /* We can't represent a fraction of a frame, so skip the first frame fraction of sound so we
+ * start on a "whole" frame.
+ */
+ start_frame_offset++;
+ }
+
+ sound->offset_time += start_frame_offset_remainer;
+
+ Sequence *seq = SEQ_sequence_alloc(seqbase,
+ load_data->start_frame + start_frame_offset,
+ load_data->channel,
+ SEQ_TYPE_SOUND_RAM);
seq->sound = sound;
seq->scene_sound = NULL;
- /* We add a very small negative offset here, because
- * ceil(132.0) == 133.0, not nice with videos, see T47135. */
- seq->len = MAX2(1, (int)ceil((double)info.length * FPS - 1e-4));
+ /* We round the frame duration as the audio sample lengths usually does not
+ * line up with the video frames. Therefore we round this number to the
+ * nearest frame as the audio track usually overshoots or undershoots the
+ * end frame of the video by a little bit.
+ * See T47135 for under shoot example. */
+ seq->len = MAX2(1, round((info.length - sound->offset_time) * FPS));
Strip *strip = seq->strip;
/* We only need 1 element to store the filename. */
@@ -436,7 +462,8 @@ Sequence *SEQ_add_sound_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
Sequence *SEQ_add_sound_strip(Main *UNUSED(bmain),
Scene *UNUSED(scene),
ListBase *UNUSED(seqbase),
- SeqLoadData *UNUSED(load_data))
+ SeqLoadData *UNUSED(load_data),
+ const double UNUSED(audio_offset))
{
return NULL;
}
@@ -477,7 +504,11 @@ Sequence *SEQ_add_meta_strip(Scene *scene, ListBase *seqbase, SeqLoadData *load_
* \param load_data: SeqLoadData with information necessary to create strip
* \return created strip
*/
-Sequence *SEQ_add_movie_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqLoadData *load_data)
+Sequence *SEQ_add_movie_strip(Main *bmain,
+ Scene *scene,
+ ListBase *seqbase,
+ SeqLoadData *load_data,
+ double *r_video_start_offset)
{
char path[sizeof(load_data->path)];
BLI_strncpy(path, load_data->path, sizeof(path));
@@ -552,6 +583,7 @@ Sequence *SEQ_add_movie_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
if (anim_arr[0] != NULL) {
seq->len = IMB_anim_get_duration(anim_arr[0], IMB_TC_RECORD_RUN);
+ *r_video_start_offset = IMD_anim_get_offset(anim_arr[0]);
IMB_anim_load_metadata(anim_arr[0]);
diff --git a/source/blender/sequencer/intern/strip_edit.c b/source/blender/sequencer/intern/strip_edit.c
index e92afee08cd..17ff1c90be8 100644
--- a/source/blender/sequencer/intern/strip_edit.c
+++ b/source/blender/sequencer/intern/strip_edit.c
@@ -351,6 +351,11 @@ static void seq_split_set_left_offset(Sequence *seq, int timeline_frame)
SEQ_transform_set_left_handle_frame(seq, timeline_frame);
}
+static bool seq_edit_split_effect_intersect_check(const Sequence *seq, const int timeline_frame)
+{
+ return timeline_frame > seq->startdisp && timeline_frame < seq->enddisp;
+}
+
static void seq_edit_split_handle_strip_offsets(Main *bmain,
Scene *scene,
Sequence *left_seq,
@@ -358,20 +363,82 @@ static void seq_edit_split_handle_strip_offsets(Main *bmain,
const int timeline_frame,
const eSeqSplitMethod method)
{
- switch (method) {
- case SEQ_SPLIT_SOFT:
- seq_split_set_left_offset(right_seq, timeline_frame);
- seq_split_set_right_offset(left_seq, timeline_frame);
- break;
- case SEQ_SPLIT_HARD:
- seq_split_set_right_hold_offset(left_seq, timeline_frame);
- seq_split_set_left_hold_offset(right_seq, timeline_frame);
- SEQ_add_reload_new_file(bmain, scene, left_seq, false);
- SEQ_add_reload_new_file(bmain, scene, right_seq, false);
- break;
- }
- SEQ_time_update_sequence(scene, left_seq);
- SEQ_time_update_sequence(scene, right_seq);
+ if (seq_edit_split_effect_intersect_check(right_seq, timeline_frame)) {
+ switch (method) {
+ case SEQ_SPLIT_SOFT:
+ seq_split_set_left_offset(right_seq, timeline_frame);
+ break;
+ case SEQ_SPLIT_HARD:
+ seq_split_set_left_hold_offset(right_seq, timeline_frame);
+ SEQ_add_reload_new_file(bmain, scene, right_seq, false);
+ break;
+ }
+ SEQ_time_update_sequence(scene, right_seq);
+ }
+
+ if (seq_edit_split_effect_intersect_check(left_seq, timeline_frame)) {
+ switch (method) {
+ case SEQ_SPLIT_SOFT:
+ seq_split_set_right_offset(left_seq, timeline_frame);
+ break;
+ case SEQ_SPLIT_HARD:
+ seq_split_set_right_hold_offset(left_seq, timeline_frame);
+ SEQ_add_reload_new_file(bmain, scene, left_seq, false);
+ break;
+ }
+ SEQ_time_update_sequence(scene, left_seq);
+ }
+}
+
+static bool seq_edit_split_effect_inputs_intersect(const Sequence *seq, const int timeline_frame)
+{
+ bool input_does_intersect = false;
+ if (seq->seq1) {
+ input_does_intersect |= seq_edit_split_effect_intersect_check(seq->seq1, timeline_frame);
+ if ((seq->seq1->type & SEQ_TYPE_EFFECT) != 0) {
+ input_does_intersect |= seq_edit_split_effect_inputs_intersect(seq->seq1, timeline_frame);
+ }
+ }
+ if (seq->seq2) {
+ input_does_intersect |= seq_edit_split_effect_intersect_check(seq->seq2, timeline_frame);
+ if ((seq->seq1->type & SEQ_TYPE_EFFECT) != 0) {
+ input_does_intersect |= seq_edit_split_effect_inputs_intersect(seq->seq2, timeline_frame);
+ }
+ }
+ if (seq->seq3) {
+ input_does_intersect |= seq_edit_split_effect_intersect_check(seq->seq3, timeline_frame);
+ if ((seq->seq1->type & SEQ_TYPE_EFFECT) != 0) {
+ input_does_intersect |= seq_edit_split_effect_inputs_intersect(seq->seq3, timeline_frame);
+ }
+ }
+ return input_does_intersect;
+}
+
+static bool seq_edit_split_operation_permitted_check(SeqCollection *strips,
+ const int timeline_frame,
+ const char **r_error)
+{
+ Sequence *seq;
+ SEQ_ITERATOR_FOREACH (seq, strips) {
+ if ((seq->type & SEQ_TYPE_EFFECT) == 0) {
+ continue;
+ }
+ if (!seq_edit_split_effect_intersect_check(seq, timeline_frame)) {
+ continue;
+ }
+ if (SEQ_effect_get_num_inputs(seq->type) <= 1) {
+ continue;
+ }
+ if (ELEM(seq->type, SEQ_TYPE_CROSS, SEQ_TYPE_GAMCROSS, SEQ_TYPE_WIPE)) {
+ *r_error = "Splitting transition effect is not permitted.";
+ return false;
+ }
+ if (!seq_edit_split_effect_inputs_intersect(seq, timeline_frame)) {
+ *r_error = "Effect inputs don't overlap. Can not split such effect.";
+ return false;
+ }
+ }
+ return true;
}
/**
@@ -390,16 +457,23 @@ Sequence *SEQ_edit_strip_split(Main *bmain,
ListBase *seqbase,
Sequence *seq,
const int timeline_frame,
- const eSeqSplitMethod method)
+ const eSeqSplitMethod method,
+ const char **r_error)
{
- if (timeline_frame <= seq->startdisp || timeline_frame >= seq->enddisp) {
+ if (!seq_edit_split_effect_intersect_check(seq, timeline_frame)) {
return NULL;
}
+ /* Whole strip chain must be duplicated in order to preserve relationships. */
SeqCollection *collection = SEQ_collection_create(__func__);
SEQ_collection_append_strip(seq, collection);
SEQ_collection_expand(seqbase, collection, SEQ_query_strip_effect_chain);
+ if (!seq_edit_split_operation_permitted_check(collection, timeline_frame, r_error)) {
+ SEQ_collection_free(collection);
+ return NULL;
+ }
+
/* Move strips in collection from seqbase to new ListBase. */
ListBase left_strips = {NULL, NULL};
SEQ_ITERATOR_FOREACH (seq, collection) {
@@ -421,7 +495,19 @@ Sequence *SEQ_edit_strip_split(Main *bmain,
Sequence *left_seq = left_strips.first;
Sequence *right_seq = right_strips.first;
Sequence *return_seq = right_strips.first;
+
+ /* Strips can't be tagged while in detached `seqbase`. Collect all strips which needs to be
+ * deleted and delay tagging until they are moved back to `seqbase` in `Editing`. */
+ SeqCollection *strips_to_delete = SEQ_collection_create(__func__);
+
while (left_seq && right_seq) {
+ if (left_seq->startdisp >= timeline_frame) {
+ SEQ_collection_append_strip(left_seq, strips_to_delete);
+ }
+ if (right_seq->enddisp <= timeline_frame) {
+ SEQ_collection_append_strip(right_seq, strips_to_delete);
+ }
+
seq_edit_split_handle_strip_offsets(bmain, scene, left_seq, right_seq, timeline_frame, method);
left_seq = left_seq->next;
right_seq = right_seq->next;
@@ -435,6 +521,12 @@ Sequence *SEQ_edit_strip_split(Main *bmain,
SEQ_ensure_unique_name(seq, scene);
}
+ Sequence *seq_delete;
+ SEQ_ITERATOR_FOREACH (seq_delete, strips_to_delete) {
+ SEQ_edit_flag_for_removal(scene, seqbase, seq_delete);
+ }
+ SEQ_edit_remove_flagged_sequences(scene, seqbase);
+ SEQ_collection_free(strips_to_delete);
return return_seq;
}
@@ -476,6 +568,6 @@ bool SEQ_edit_remove_gaps(Scene *scene,
void SEQ_edit_sequence_name_set(Scene *scene, Sequence *seq, const char *new_name)
{
BLI_strncpy_utf8(seq->name + 2, new_name, MAX_NAME - 2);
- BLI_utf8_invalid_strip(seq->name + 2, strlen(seq->name + 2));
+ BLI_str_utf8_invalid_strip(seq->name + 2, strlen(seq->name + 2));
SEQ_sequence_lookup_tag(scene, SEQ_LOOKUP_TAG_INVALID);
}
diff --git a/source/blender/sequencer/intern/strip_relations.c b/source/blender/sequencer/intern/strip_relations.c
index 7c5a3f031db..ec70a683da5 100644
--- a/source/blender/sequencer/intern/strip_relations.c
+++ b/source/blender/sequencer/intern/strip_relations.c
@@ -118,7 +118,7 @@ static void sequence_invalidate_cache(Scene *scene,
}
if (seq->effectdata && seq->type == SEQ_TYPE_SPEED) {
- seq_effect_speed_rebuild_map(scene, seq, true);
+ seq_effect_speed_rebuild_map(scene, seq);
}
sequence_do_invalidate_dependent(scene, seq, &ed->seqbase);
@@ -268,7 +268,7 @@ void SEQ_relations_free_imbuf(Scene *scene, ListBase *seqbase, bool for_render)
SEQ_relations_sequence_free_anim(seq);
}
if (seq->type == SEQ_TYPE_SPEED) {
- seq_effect_speed_rebuild_map(scene, seq, true);
+ seq_effect_speed_rebuild_map(scene, seq);
}
}
if (seq->type == SEQ_TYPE_META) {
@@ -325,7 +325,7 @@ static bool update_changed_seq_recurs(
SEQ_relations_sequence_free_anim(seq);
}
else if (seq->type == SEQ_TYPE_SPEED) {
- seq_effect_speed_rebuild_map(scene, seq, true);
+ seq_effect_speed_rebuild_map(scene, seq);
}
}
@@ -504,3 +504,23 @@ void SEQ_relations_check_uuids_unique_and_report(const Scene *scene)
BLI_gset_free(used_uuids, NULL);
}
+
+/* Return immediate parent meta of sequence */
+struct Sequence *SEQ_find_metastrip_by_sequence(ListBase *seqbase, Sequence *meta, Sequence *seq)
+{
+ Sequence *iseq;
+
+ for (iseq = seqbase->first; iseq; iseq = iseq->next) {
+ Sequence *rval;
+
+ if (seq == iseq) {
+ return meta;
+ }
+ if (iseq->seqbase.first &&
+ (rval = SEQ_find_metastrip_by_sequence(&iseq->seqbase, iseq, seq))) {
+ return rval;
+ }
+ }
+
+ return NULL;
+} \ No newline at end of file
diff --git a/source/blender/sequencer/intern/strip_time.c b/source/blender/sequencer/intern/strip_time.c
index 68128690773..b73ac631693 100644
--- a/source/blender/sequencer/intern/strip_time.c
+++ b/source/blender/sequencer/intern/strip_time.c
@@ -34,6 +34,7 @@
#include "BKE_scene.h"
#include "BKE_sound.h"
+#include "DNA_sound_types.h"
#include "IMB_imbuf.h"
#include "SEQ_iterator.h"
@@ -134,7 +135,8 @@ static void seq_update_sound_bounds_recursive_impl(Scene *scene,
seq->scene_sound,
seq->start + startofs,
seq->start + seq->len - endofs,
- startofs + seq->anim_startofs);
+ startofs + seq->anim_startofs,
+ seq->sound->offset_time);
}
}
}
diff --git a/source/blender/sequencer/intern/strip_transform.c b/source/blender/sequencer/intern/strip_transform.c
index c9af2fced65..9f69f434ca0 100644
--- a/source/blender/sequencer/intern/strip_transform.c
+++ b/source/blender/sequencer/intern/strip_transform.c
@@ -40,6 +40,10 @@
#include "SEQ_time.h"
#include "SEQ_transform.h"
+#include "CLG_log.h"
+
+static CLG_LogRef LOG = {"seq.strip_transform"};
+
static int seq_tx_get_start(Sequence *seq)
{
return seq->start;
@@ -315,6 +319,12 @@ static int shuffle_seq_time_offset_test(SeqCollection *strips_to_shuffle,
if (!seq_overlap(seq, seq_other)) {
continue;
}
+ if (UNLIKELY(SEQ_collection_has_strip(seq_other, strips_to_shuffle))) {
+ CLOG_WARN(&LOG,
+ "Strip overlaps with itself or another strip, that is to be shuffled."
+ "This should never happen.");
+ continue;
+ }
if (dir == 'L') {
offset = min_ii(offset, seq_other->startdisp - seq->enddisp);
}
diff --git a/source/blender/sequencer/intern/utils.c b/source/blender/sequencer/intern/utils.c
index 98640ea8a5c..f946affe1d8 100644
--- a/source/blender/sequencer/intern/utils.c
+++ b/source/blender/sequencer/intern/utils.c
@@ -431,7 +431,7 @@ const Sequence *SEQ_get_topmost_sequence(const Scene *scene, int frame)
return best_seq;
}
-/* in cases where we done know the sequence's listbase */
+/* in cases where we don't know the sequence's listbase */
ListBase *SEQ_get_seqbase_by_seq(ListBase *seqbase, Sequence *seq)
{
Sequence *iseq;
@@ -449,25 +449,6 @@ ListBase *SEQ_get_seqbase_by_seq(ListBase *seqbase, Sequence *seq)
return NULL;
}
-Sequence *seq_find_metastrip_by_sequence(ListBase *seqbase, Sequence *meta, Sequence *seq)
-{
- Sequence *iseq;
-
- for (iseq = seqbase->first; iseq; iseq = iseq->next) {
- Sequence *rval;
-
- if (seq == iseq) {
- return meta;
- }
- if (iseq->seqbase.first &&
- (rval = seq_find_metastrip_by_sequence(&iseq->seqbase, iseq, seq))) {
- return rval;
- }
- }
-
- return NULL;
-}
-
/**
* Only use as last resort when the StripElem is available but no the Sequence.
* (needed for RNA)
diff --git a/source/blender/sequencer/intern/utils.h b/source/blender/sequencer/intern/utils.h
index 97f33bb3ae0..7aee7d229c9 100644
--- a/source/blender/sequencer/intern/utils.h
+++ b/source/blender/sequencer/intern/utils.h
@@ -31,10 +31,6 @@ struct Scene;
bool sequencer_seq_generates_image(struct Sequence *seq);
void seq_open_anim_file(struct Scene *scene, struct Sequence *seq, bool openfile);
-struct Sequence *seq_find_metastrip_by_sequence(ListBase *seqbase /* = ed->seqbase */,
- struct Sequence *meta /* = NULL */,
- struct Sequence *seq);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index b7fbb9bb82b..4d65726fe2b 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -48,10 +48,6 @@ set(INC
${CMAKE_BINARY_DIR}/source/blender/makesdna/intern
)
-set(INC_SYS
- ${ZLIB_INCLUDE_DIRS}
-)
-
set(SRC
intern/wm.c
intern/wm_cursors.c
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 485d8e5a162..843ceca7700 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -328,11 +328,10 @@ typedef struct wmNotifier {
#define ND_LAYOUTDELETE (2 << 16)
#define ND_ANIMPLAY (4 << 16)
#define ND_GPENCIL (5 << 16)
-#define ND_EDITOR_CHANGED (6 << 16) /* Sent to new editors after switching to them. */
-#define ND_LAYOUTSET (7 << 16)
-#define ND_SKETCH (8 << 16)
-#define ND_WORKSPACE_SET (9 << 16)
-#define ND_WORKSPACE_DELETE (10 << 16)
+#define ND_LAYOUTSET (6 << 16)
+#define ND_SKETCH (7 << 16)
+#define ND_WORKSPACE_SET (8 << 16)
+#define ND_WORKSPACE_DELETE (9 << 16)
/* NC_SCENE Scene */
#define ND_SCENEBROWSE (1 << 16)
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
index 5ec26a7b208..6f6a2402d89 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
@@ -616,11 +616,7 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos,
const int viewport[4] = {0, 0, region->winx, region->winy};
float co_3d_origin[3];
- /* Avoid multiple calculations. */
- struct GPUMatrixUnproject_Precalc unproj_precalc;
- GPU_matrix_unproject_precalc(&unproj_precalc, rv3d->viewmat, rv3d->winmat, viewport);
-
- GPU_matrix_unproject_3fv_with_precalc(&unproj_precalc, co_screen, co_3d_origin);
+ GPU_matrix_unproject_3fv(co_screen, rv3d->viewinv, rv3d->winmat, viewport, co_3d_origin);
uint *buf_iter = buffer;
int hit_found = -1;
@@ -631,7 +627,7 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos,
wmGizmo *gz = visible_gizmos[buf_iter[3] >> 8];
float co_3d[3];
co_screen[2] = int_as_float(buf_iter[1]);
- GPU_matrix_unproject_3fv_with_precalc(&unproj_precalc, co_screen, co_3d);
+ GPU_matrix_unproject_3fv(co_screen, rv3d->viewinv, rv3d->winmat, viewport, co_3d);
float select_bias = gz->select_bias;
if ((gz->flag & WM_GIZMO_DRAW_NO_SCALE) == 0) {
select_bias *= gz->scale_final;
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 9657f8aa03c..e11ef52eb84 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -628,6 +628,7 @@ void wm_close_and_free_all(bContext *C, ListBase *wmlist)
wm_close_and_free(C, wm);
BLI_remlink(wmlist, wm);
BKE_libblock_free_data(&wm->id, true);
+ BKE_libblock_free_data_py(&wm->id);
MEM_freeN(wm);
}
}
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index f01e28f8822..328950cf8f9 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -455,7 +455,7 @@ static void wm_draw_region_buffer_create(ARegion *region, bool stereo, bool use_
* depth or multisample buffers. 3D view creates own buffers with
* the data it needs. */
GPUOffScreen *offscreen = GPU_offscreen_create(
- region->winx, region->winy, false, false, NULL);
+ region->winx, region->winy, false, GPU_RGBA8, NULL);
if (!offscreen) {
WM_report(RPT_ERROR, "Region could not be drawn!");
return;
@@ -691,46 +691,48 @@ static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
/* Then do actual drawing of regions. */
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
- if (region->visible && region->do_draw) {
- CTX_wm_region_set(C, region);
- bool use_viewport = WM_region_use_viewport(area, region);
-
- GPU_debug_group_begin(use_viewport ? "Viewport" : "ARegion");
-
- if (stereo && wm_draw_region_stereo_set(bmain, area, region, STEREO_LEFT_ID)) {
- wm_draw_region_buffer_create(region, true, use_viewport);
-
- for (int view = 0; view < 2; view++) {
- eStereoViews sview;
- if (view == 0) {
- sview = STEREO_LEFT_ID;
- }
- else {
- sview = STEREO_RIGHT_ID;
- wm_draw_region_stereo_set(bmain, area, region, sview);
- }
-
- wm_draw_region_bind(region, view);
- ED_region_do_draw(C, region);
- wm_draw_region_unbind(region);
+ if (!region->visible || !region->do_draw) {
+ continue;
+ }
+
+ CTX_wm_region_set(C, region);
+ bool use_viewport = WM_region_use_viewport(area, region);
+
+ GPU_debug_group_begin(use_viewport ? "Viewport" : "ARegion");
+
+ if (stereo && wm_draw_region_stereo_set(bmain, area, region, STEREO_LEFT_ID)) {
+ wm_draw_region_buffer_create(region, true, use_viewport);
+
+ for (int view = 0; view < 2; view++) {
+ eStereoViews sview;
+ if (view == 0) {
+ sview = STEREO_LEFT_ID;
}
- if (use_viewport) {
- GPUViewport *viewport = region->draw_buffer->viewport;
- GPU_viewport_stereo_composite(viewport, win->stereo3d_format);
+ else {
+ sview = STEREO_RIGHT_ID;
+ wm_draw_region_stereo_set(bmain, area, region, sview);
}
- }
- else {
- wm_draw_region_buffer_create(region, false, use_viewport);
- wm_draw_region_bind(region, 0);
+
+ wm_draw_region_bind(region, view);
ED_region_do_draw(C, region);
wm_draw_region_unbind(region);
}
+ if (use_viewport) {
+ GPUViewport *viewport = region->draw_buffer->viewport;
+ GPU_viewport_stereo_composite(viewport, win->stereo3d_format);
+ }
+ }
+ else {
+ wm_draw_region_buffer_create(region, false, use_viewport);
+ wm_draw_region_bind(region, 0);
+ ED_region_do_draw(C, region);
+ wm_draw_region_unbind(region);
+ }
- GPU_debug_group_end();
+ GPU_debug_group_end();
- region->do_draw = false;
- CTX_wm_region_set(C, NULL);
- }
+ region->do_draw = false;
+ CTX_wm_region_set(C, NULL);
}
CTX_wm_area_set(C, NULL);
@@ -740,29 +742,30 @@ static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
/* Draw menus into their own framebuffer. */
LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) {
- if (region->visible) {
- CTX_wm_menu_set(C, region);
+ if (!region->visible) {
+ continue;
+ }
+ CTX_wm_menu_set(C, region);
- GPU_debug_group_begin("Menu");
+ GPU_debug_group_begin("Menu");
- if (region->type && region->type->layout) {
- /* UI code reads the OpenGL state, but we have to refresh
- * the UI layout beforehand in case the menu size changes. */
- wmViewport(&region->winrct);
- region->type->layout(C, region);
- }
+ if (region->type && region->type->layout) {
+ /* UI code reads the OpenGL state, but we have to refresh
+ * the UI layout beforehand in case the menu size changes. */
+ wmViewport(&region->winrct);
+ region->type->layout(C, region);
+ }
- wm_draw_region_buffer_create(region, false, false);
- wm_draw_region_bind(region, 0);
- GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
- ED_region_do_draw(C, region);
- wm_draw_region_unbind(region);
+ wm_draw_region_buffer_create(region, false, false);
+ wm_draw_region_bind(region, 0);
+ GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
+ ED_region_do_draw(C, region);
+ wm_draw_region_unbind(region);
- GPU_debug_group_end();
+ GPU_debug_group_end();
- region->do_draw = false;
- CTX_wm_menu_set(C, NULL);
- }
+ region->do_draw = false;
+ CTX_wm_menu_set(C, NULL);
}
}
@@ -786,8 +789,12 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
/* Blit non-overlapping area regions. */
ED_screen_areas_iter (win, screen, area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
- if (region->visible && region->overlap == false) {
- /* Blit from offscreen buffer. */
+ if (!region->visible) {
+ continue;
+ }
+
+ if (region->overlap == false) {
+ /* Blit from off-screen buffer. */
wm_draw_region_blit(region, view);
}
}
@@ -796,24 +803,25 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
/* Draw overlays and paint cursors. */
ED_screen_areas_iter (win, screen, area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
- if (region->visible) {
- const bool do_paint_cursor = (wm->paintcursors.first && region == screen->active_region);
- const bool do_draw_overlay = (region->type && region->type->draw_overlay);
- if (!(do_paint_cursor || do_draw_overlay)) {
- continue;
- }
+ if (!region->visible) {
+ continue;
+ }
+ const bool do_paint_cursor = (wm->paintcursors.first && region == screen->active_region);
+ const bool do_draw_overlay = (region->type && region->type->draw_overlay);
+ if (!(do_paint_cursor || do_draw_overlay)) {
+ continue;
+ }
- CTX_wm_area_set(C, area);
- CTX_wm_region_set(C, region);
- if (do_draw_overlay) {
- wm_region_draw_overlay(C, area, region);
- }
- if (do_paint_cursor) {
- wm_paintcursor_draw(C, area, region);
- }
- CTX_wm_region_set(C, NULL);
- CTX_wm_area_set(C, NULL);
+ CTX_wm_area_set(C, area);
+ CTX_wm_region_set(C, region);
+ if (do_draw_overlay) {
+ wm_region_draw_overlay(C, area, region);
+ }
+ if (do_paint_cursor) {
+ wm_paintcursor_draw(C, area, region);
}
+ CTX_wm_region_set(C, NULL);
+ CTX_wm_area_set(C, NULL);
}
}
wmWindowViewport(win);
@@ -821,7 +829,10 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
/* Blend in overlapping area regions */
ED_screen_areas_iter (win, screen, area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
- if (region->visible && region->overlap) {
+ if (!region->visible) {
+ continue;
+ }
+ if (region->overlap) {
wm_draw_region_blend(region, 0, true);
}
}
@@ -834,9 +845,10 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
/* Blend in floating regions (menus). */
LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) {
- if (region->visible) {
- wm_draw_region_blend(region, 0, true);
+ if (!region->visible) {
+ continue;
}
+ wm_draw_region_blend(region, 0, true);
}
/* always draw, not only when screen tagged */
@@ -888,7 +900,7 @@ static void wm_draw_window(bContext *C, wmWindow *win)
* stereo methods, but it's less efficient than drawing directly. */
const int width = WM_window_pixels_x(win);
const int height = WM_window_pixels_y(win);
- GPUOffScreen *offscreen = GPU_offscreen_create(width, height, false, false, NULL);
+ GPUOffScreen *offscreen = GPU_offscreen_create(width, height, false, GPU_RGBA8, NULL);
if (offscreen) {
GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 5cc361fc1bd..b9a3dd0c3fb 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -3471,8 +3471,8 @@ void wm_event_do_handlers(bContext *C)
}
CTX_wm_area_set(C, NULL);
- /* NOTE: do not escape on WM_HANDLER_BREAK,
- * mousemove needs handled for previous area. */
+ /* NOTE: do not escape on #WM_HANDLER_BREAK,
+ * mouse-move needs handled for previous area. */
}
}
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index abf957a6396..f83511e76f0 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -28,11 +28,10 @@
* winsock stuff.
*/
#include <errno.h>
+#include <fcntl.h> /* for open flags (O_BINARY, O_RDONLY). */
#include <stddef.h>
#include <string.h>
-#include "zlib.h" /* wm_read_exotic() */
-
#ifdef WIN32
/* Need to include windows.h so _WIN32_IE is defined. */
# include <windows.h>
@@ -51,6 +50,7 @@
#include "BLI_blenlib.h"
#include "BLI_fileops_types.h"
+#include "BLI_filereader.h"
#include "BLI_linklist.h"
#include "BLI_math.h"
#include "BLI_system.h"
@@ -481,53 +481,64 @@ static void wm_init_userdef(Main *bmain)
/* intended to check for non-blender formats but for now it only reads blends */
static int wm_read_exotic(const char *name)
{
- int len;
- gzFile gzfile;
+ /* make sure we're not trying to read a directory.... */
+
+ int namelen = strlen(name);
+ if (namelen > 0 && ELEM(name[namelen - 1], '/', '\\')) {
+ return BKE_READ_EXOTIC_FAIL_PATH;
+ }
+
+ /* open the file. */
+ const int filedes = BLI_open(name, O_BINARY | O_RDONLY, 0);
+ if (filedes == -1) {
+ return BKE_READ_EXOTIC_FAIL_OPEN;
+ }
+
+ FileReader *rawfile = BLI_filereader_new_file(filedes);
+ if (rawfile == NULL) {
+ return BKE_READ_EXOTIC_FAIL_OPEN;
+ }
+
+ /* read the header (7 bytes are enough to identify all known types). */
char header[7];
- int retval;
+ if (rawfile->read(rawfile, header, sizeof(header)) != sizeof(header)) {
+ rawfile->close(rawfile);
+ return BKE_READ_EXOTIC_FAIL_FORMAT;
+ }
+ rawfile->seek(rawfile, 0, SEEK_SET);
- /* make sure we're not trying to read a directory.... */
+ /* check for uncompressed .blend */
+ if (STREQLEN(header, "BLENDER", 7)) {
+ rawfile->close(rawfile);
+ return BKE_READ_EXOTIC_OK_BLEND;
+ }
- len = strlen(name);
- if (len > 0 && ELEM(name[len - 1], '/', '\\')) {
- retval = BKE_READ_EXOTIC_FAIL_PATH;
+ /* check for compressed .blend */
+ FileReader *compressed_file = NULL;
+ if (BLI_file_magic_is_gzip(header)) {
+ /* In earlier versions of Blender (before 3.0), compressed files used Gzip instead of Zstd.
+ * While these files will no longer be written, there still needs to be reading support. */
+ compressed_file = BLI_filereader_new_gzip(rawfile);
+ }
+ else if (BLI_file_magic_is_zstd(header)) {
+ compressed_file = BLI_filereader_new_zstd(rawfile);
}
- else {
- gzfile = BLI_gzopen(name, "rb");
- if (gzfile == NULL) {
- retval = BKE_READ_EXOTIC_FAIL_OPEN;
- }
- else {
- len = gzread(gzfile, header, sizeof(header));
- gzclose(gzfile);
- if (len == sizeof(header) && STREQLEN(header, "BLENDER", 7)) {
- retval = BKE_READ_EXOTIC_OK_BLEND;
- }
- else {
- /* We may want to support loading other file formats
- * from their header bytes or file extension.
- * This used to be supported in the code below and may be added
- * back at some point. */
-#if 0
- WM_cursor_wait(true);
- if (is_foo_format(name)) {
- read_foo(name);
- retval = BKE_READ_EXOTIC_OK_OTHER;
- }
- else
-#endif
- {
- retval = BKE_READ_EXOTIC_FAIL_FORMAT;
- }
-#if 0
- WM_cursor_wait(false);
-#endif
- }
+ /* If a compression signature matches, try decompressing the start and check if it's a .blend */
+ if (compressed_file != NULL) {
+ size_t len = compressed_file->read(compressed_file, header, sizeof(header));
+ compressed_file->close(compressed_file);
+ if (len == sizeof(header) && STREQLEN(header, "BLENDER", 7)) {
+ return BKE_READ_EXOTIC_OK_BLEND;
}
}
+ else {
+ rawfile->close(rawfile);
+ }
+
+ /* Add check for future file formats here. */
- return retval;
+ return BKE_READ_EXOTIC_FAIL_FORMAT;
}
/** \} */
@@ -596,19 +607,33 @@ static void wm_file_read_pre(bContext *C, bool use_data, bool UNUSED(use_userdef
}
/**
+ * Parameters for #wm_file_read_post, also used for deferred initialization.
+ */
+struct wmFileReadPost_Params {
+ uint use_data : 1;
+ uint use_userdef : 1;
+
+ uint is_startup_file : 1;
+ uint is_factory_startup : 1;
+ uint reset_app_template : 1;
+};
+
+/**
* Logic shared between #WM_file_read & #wm_homefile_read,
* updates to make after reading a file.
*/
-static void wm_file_read_post(bContext *C,
- const bool is_startup_file,
- const bool is_factory_startup,
- const bool use_data,
- const bool use_userdef,
- const bool reset_app_template)
+static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *params)
{
- bool addons_loaded = false;
wmWindowManager *wm = CTX_wm_manager(C);
+ const bool use_data = params->use_data;
+ const bool use_userdef = params->use_userdef;
+ const bool is_startup_file = params->is_startup_file;
+ const bool is_factory_startup = params->is_factory_startup;
+ const bool reset_app_template = params->reset_app_template;
+
+ bool addons_loaded = false;
+
if (use_data) {
if (!G.background) {
/* remove windows which failed to be added via WM_check */
@@ -910,7 +935,14 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
wm_history_file_update();
}
- wm_file_read_post(C, false, false, use_data, use_userdef, false);
+ wm_file_read_post(C,
+ &(const struct wmFileReadPost_Params){
+ .use_data = use_data,
+ .use_userdef = use_userdef,
+ .is_startup_file = false,
+ .is_factory_startup = false,
+ .reset_app_template = false,
+ });
bf_reports.duration.whole = PIL_check_seconds_timer() - bf_reports.duration.whole;
file_read_reports_finalize(&bf_reports);
@@ -993,31 +1025,18 @@ const char *WM_init_state_app_template_get(void)
/**
* Called on startup, (context entirely filled with NULLs)
- * or called for 'New File' both startup.blend and userpref.blend are checked.
- *
- * \param use_factory_settings:
- * Ignore on-disk startup file, use bundled `datatoc_startup_blend` instead.
- * Used for "Restore Factory Settings".
- *
- * \param use_userdef: Load factory settings as well as startup file.
- * Disabled for "File New" we don't want to reload preferences.
- *
- * \param filepath_startup_override:
- * Optional path pointing to an alternative blend file (may be NULL).
+ * or called for 'New File' both `startup.blend` and `userpref.blend` are checked.
*
- * \param app_template_override:
- * Template to use instead of the template defined in user-preferences.
- * When not-null, this is written into the user preferences.
+ * \param r_params_file_read_post: Support postponed initialization,
+ * needed for initial startup when only some sub-systems have been initialized.
+ * When non-null, #wm_file_read_post doesn't run, instead it's arguments are stored
+ * in this return argument.
+ * The caller is responsible for calling #wm_homefile_read_post with this return argument.
*/
-void wm_homefile_read(bContext *C,
- ReportList *reports,
- bool use_factory_settings,
- bool use_empty_data,
- bool use_data,
- bool use_userdef,
- const char *filepath_startup_override,
- const char *app_template_override,
- bool *r_is_factory_startup)
+void wm_homefile_read_ex(bContext *C,
+ const struct wmHomeFileRead_Params *params_homefile,
+ ReportList *reports,
+ struct wmFileReadPost_Params **r_params_file_read_post)
{
#if 0 /* UNUSED, keep as this may be needed later & the comment below isn't self evident. */
/* Context does not always have valid main pointer here. */
@@ -1026,6 +1045,14 @@ void wm_homefile_read(bContext *C,
ListBase wmbase;
bool success = false;
+ /* May be enabled, when the user configuration doesn't exist. */
+ const bool use_data = params_homefile->use_data;
+ const bool use_userdef = params_homefile->use_userdef;
+ bool use_factory_settings = params_homefile->use_factory_settings;
+ const bool use_empty_data = params_homefile->use_empty_data;
+ const char *filepath_startup_override = params_homefile->filepath_startup_override;
+ const char *app_template_override = params_homefile->app_template_override;
+
bool filepath_startup_is_factory = true;
char filepath_startup[FILE_MAX];
char filepath_userdef[FILE_MAX];
@@ -1313,13 +1340,45 @@ void wm_homefile_read(bContext *C,
G.save_over = 0;
}
- wm_file_read_post(C, true, is_factory_startup, use_data, use_userdef, reset_app_template);
+ {
+ const struct wmFileReadPost_Params params_file_read_post = {
+ .use_data = use_data,
+ .use_userdef = use_userdef,
+ .is_startup_file = true,
+ .is_factory_startup = is_factory_startup,
+ .reset_app_template = reset_app_template,
+ };
+ if (r_params_file_read_post == NULL) {
+ wm_file_read_post(C, &params_file_read_post);
+ }
+ else {
+ *r_params_file_read_post = MEM_mallocN(sizeof(struct wmFileReadPost_Params), __func__);
+ **r_params_file_read_post = params_file_read_post;
- if (r_is_factory_startup) {
- *r_is_factory_startup = is_factory_startup;
+ /* Match #wm_file_read_post which leaves the window cleared too. */
+ CTX_wm_window_set(C, NULL);
+ }
}
}
+void wm_homefile_read(bContext *C,
+ const struct wmHomeFileRead_Params *params_homefile,
+ ReportList *reports)
+{
+ wm_homefile_read_ex(C, params_homefile, reports, NULL);
+}
+
+/**
+ * Special case, support deferred execution of #wm_file_read_post,
+ * Needed when loading for the first time to workaround order of initialization bug, see T89046.
+ */
+void wm_homefile_read_post(struct bContext *C,
+ const struct wmFileReadPost_Params *params_file_read_post)
+{
+ wm_file_read_post(C, params_file_read_post);
+ MEM_freeN((void *)params_file_read_post);
+}
+
/* -------------------------------------------------------------------- */
/** \name Blend-File History API
* \{ */
@@ -2087,14 +2146,15 @@ static int wm_userpref_read_exec(bContext *C, wmOperator *op)
UserDef U_backup = U;
wm_homefile_read(C,
- op->reports,
- use_factory_settings,
- false,
- use_data,
- use_userdef,
- NULL,
- WM_init_state_app_template_get(),
- NULL);
+ &(const struct wmHomeFileRead_Params){
+ .use_data = use_data,
+ .use_userdef = use_userdef,
+ .use_factory_settings = use_factory_settings,
+ .use_empty_data = false,
+ .filepath_startup_override = NULL,
+ .app_template_override = WM_init_state_app_template_get(),
+ },
+ op->reports);
wm_userpref_read_exceptions(&U, &U_backup);
SET_FLAG_FROM_TEST(G.f, use_factory_settings, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
@@ -2233,16 +2293,17 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
app_template = WM_init_state_app_template_get();
}
- bool use_data = true;
wm_homefile_read(C,
- op->reports,
- use_factory_settings,
- use_empty_data,
- use_data,
- use_userdef,
- filepath,
- app_template,
- NULL);
+ &(const struct wmHomeFileRead_Params){
+ .use_data = true,
+ .use_userdef = use_userdef,
+ .use_factory_settings = use_factory_settings,
+ .use_empty_data = use_empty_data,
+ .filepath_startup_override = filepath,
+ .app_template_override = app_template,
+ },
+ op->reports);
+
if (use_splash) {
WM_init_splash(C);
}
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index fec5a516688..606c9252ff9 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <string.h>
+#include "CLG_log.h"
+
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
@@ -76,6 +78,8 @@
#include "wm_files.h"
+static CLG_LogRef LOG = {"wm.files_link"};
+
/* -------------------------------------------------------------------- */
/** \name Link/Append Operator
* \{ */
@@ -315,7 +319,7 @@ static bool wm_link_append_item_poll(ReportList *reports,
short idcode;
if (!group || !name) {
- printf("skipping %s\n", path);
+ CLOG_WARN(&LOG, "Skipping %s", path);
return false;
}
@@ -485,11 +489,11 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
}
/* XXX We'd need re-entrant locking on Main for this to work... */
- /* BKE_main_lock(bmain); */
+ // BKE_main_lock(bmain);
wm_link_do(lapp_data, op->reports, bmain, scene, view_layer, CTX_wm_view3d(C));
- /* BKE_main_unlock(bmain); */
+ // BKE_main_unlock(bmain);
/* mark all library linked objects to be updated */
BKE_main_lib_objects_recalc_all(bmain);
@@ -759,12 +763,12 @@ static void lib_relocate_do_remap(Main *bmain,
BLI_assert(new_id);
}
if (new_id) {
-#ifdef PRINT_DEBUG
- printf("before remap of %s, old_id users: %d, new_id users: %d\n",
- old_id->name,
- old_id->us,
- new_id->us);
-#endif
+ CLOG_INFO(&LOG,
+ 4,
+ "Before remap of %s, old_id users: %d, new_id users: %d",
+ old_id->name,
+ old_id->us,
+ new_id->us);
BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags);
if (old_id->flag & LIB_FAKEUSER) {
@@ -772,12 +776,12 @@ static void lib_relocate_do_remap(Main *bmain,
id_fake_user_set(new_id);
}
-#ifdef PRINT_DEBUG
- printf("after remap of %s, old_id users: %d, new_id users: %d\n",
- old_id->name,
- old_id->us,
- new_id->us);
-#endif
+ CLOG_INFO(&LOG,
+ 4,
+ "After remap of %s, old_id users: %d, new_id users: %d",
+ old_id->name,
+ old_id->us,
+ new_id->us);
/* In some cases, new_id might become direct link, remove parent of library in this case. */
if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) {
@@ -831,7 +835,7 @@ static void lib_relocate_do_remap(Main *bmain,
}
}
-static void lib_relocate_do(Main *bmain,
+static void lib_relocate_do(bContext *C,
Library *library,
WMLinkAppendData *lapp_data,
ReportList *reports,
@@ -843,6 +847,10 @@ static void lib_relocate_do(Main *bmain,
LinkNode *itemlink;
int item_idx;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+
/* Remove all IDs to be reloaded from Main. */
lba_idx = set_listbasepointers(bmain, lbarray);
while (lba_idx--) {
@@ -871,9 +879,7 @@ static void lib_relocate_do(Main *bmain,
item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id);
BLI_bitmap_set_all(item->libraries, true, lapp_data->num_libraries);
-#ifdef PRINT_DEBUG
- printf("\tdatablock to seek for: %s\n", id->name);
-#endif
+ CLOG_INFO(&LOG, 4, "Datablock to seek for: %s", id->name);
}
}
}
@@ -990,21 +996,31 @@ static void lib_relocate_do(Main *bmain,
}
}
- /* Update overrides of reloaded linked data-blocks.
- * Note that this will not necessarily fully update the override, it might need to be manually
- * 're-generated' depending on changes in linked data. */
+ /* Update overrides of reloaded linked data-blocks. */
ID *id;
FOREACH_MAIN_ID_BEGIN (bmain, id) {
if (ID_IS_LINKED(id) || !ID_IS_OVERRIDE_LIBRARY_REAL(id) ||
(id->tag & LIB_TAG_PRE_EXISTING) == 0) {
continue;
}
- if (id->override_library->reference->lib == library) {
+ if ((id->override_library->reference->tag & LIB_TAG_PRE_EXISTING) == 0) {
BKE_lib_override_library_update(bmain, id);
}
}
FOREACH_MAIN_ID_END;
+ /* Resync overrides if needed. */
+ if (!USER_EXPERIMENTAL_TEST(&U, no_override_auto_resync)) {
+ BKE_lib_override_library_main_resync(bmain,
+ scene,
+ view_layer,
+ &(struct BlendFileReadReport){
+ .reports = reports,
+ });
+ /* We need to rebuild some of the deleted override rules (for UI feedback purpose). */
+ BKE_lib_override_library_main_operations_create(bmain, true);
+ }
+
BKE_main_collection_sync(bmain);
BKE_main_lib_objects_recalc_all(bmain);
@@ -1039,7 +1055,7 @@ void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
wm_link_append_data_library_add(lapp_data, lib->filepath_abs);
- lib_relocate_do(CTX_data_main(C), lib, lapp_data, reports, true);
+ lib_relocate_do(C, lib, lapp_data, reports, true);
wm_link_append_data_free(lapp_data);
@@ -1103,9 +1119,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
}
if (BLI_path_cmp(lib->filepath_abs, path) == 0) {
-#ifdef PRINT_DEBUG
- printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us);
-#endif
+ CLOG_INFO(&LOG, 4, "We are supposed to reload '%s' lib (%d)", lib->filepath, lib->id.us);
do_reload = true;
@@ -1115,9 +1129,8 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
else {
int totfiles = 0;
-#ifdef PRINT_DEBUG
- printf("We are supposed to relocate '%s' lib to new '%s' one...\n", lib->filepath, libname);
-#endif
+ CLOG_INFO(
+ &LOG, 4, "We are supposed to relocate '%s' lib to new '%s' one", lib->filepath, libname);
/* Check if something is indicated for relocate. */
prop = RNA_struct_find_property(op->ptr, "files");
@@ -1143,17 +1156,13 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
continue;
}
-#ifdef PRINT_DEBUG
- printf("\t candidate new lib to reload datablocks from: %s\n", path);
-#endif
+ CLOG_INFO(&LOG, 4, "\tCandidate new lib to reload datablocks from: %s", path);
wm_link_append_data_library_add(lapp_data, path);
}
RNA_END;
}
else {
-#ifdef PRINT_DEBUG
- printf("\t candidate new lib to reload datablocks from: %s\n", path);
-#endif
+ CLOG_INFO(&LOG, 4, "\tCandidate new lib to reload datablocks from: %s", path);
wm_link_append_data_library_add(lapp_data, path);
}
}
@@ -1162,7 +1171,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
lapp_data->flag |= BLO_LIBLINK_USE_PLACEHOLDERS | BLO_LIBLINK_FORCE_INDIRECT;
}
- lib_relocate_do(bmain, lib, lapp_data, op->reports, do_reload);
+ lib_relocate_do(C, lib, lapp_data, op->reports, do_reload);
wm_link_append_data_free(lapp_data);
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index d7ea47fc625..a8d2e000108 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -222,7 +222,10 @@ static void sound_jack_sync_callback(Main *bmain, int mode, double time)
}
}
-/* only called once, for startup */
+/**
+ * Initialize Blender and load the startup file & preferences
+ * (only called once).
+ */
void WM_init(bContext *C, int argc, const char **argv)
{
@@ -248,24 +251,22 @@ void WM_init(bContext *C, int argc, const char **argv)
ED_undosys_type_init();
- BKE_library_callback_free_notifier_reference_set(
- WM_main_remove_notifier_reference); /* lib_id.c */
- BKE_region_callback_free_gizmomap_set(wm_gizmomap_remove); /* screen.c */
+ BKE_library_callback_free_notifier_reference_set(WM_main_remove_notifier_reference);
+ BKE_region_callback_free_gizmomap_set(wm_gizmomap_remove);
BKE_region_callback_refresh_tag_gizmomap_set(WM_gizmomap_tag_refresh);
- BKE_library_callback_remap_editor_id_reference_set(
- WM_main_remap_editor_id_reference); /* lib_id.c */
- BKE_spacedata_callback_id_remap_set(ED_spacedata_id_remap); /* screen.c */
+ BKE_library_callback_remap_editor_id_reference_set(WM_main_remap_editor_id_reference);
+ BKE_spacedata_callback_id_remap_set(ED_spacedata_id_remap);
DEG_editors_set_update_cb(ED_render_id_flush_update, ED_render_scene_update);
- ED_spacetypes_init(); /* editors/space_api/spacetype.c */
+ ED_spacetypes_init();
ED_node_init_butfuncs();
BLF_init();
BLT_lang_init();
- /* Must call first before doing any '.blend' file reading,
- * since versioning code may create new IDs... See T57066. */
+ /* Must call first before doing any `.blend` file reading,
+ * since versioning code may create new IDs. See T57066. */
BLT_lang_set(NULL);
/* Init icons before reading .blend files for preview icons, which can
@@ -273,37 +274,57 @@ void WM_init(bContext *C, int argc, const char **argv)
* for scripts that do background processing with preview icons. */
BKE_icons_init(BIFICONID_LAST);
- /* reports can't be initialized before the wm,
+ /* Reports can't be initialized before the window-manager,
* but keep before file reading, since that may report errors */
wm_init_reports(C);
WM_msgbus_types_init();
- /* get the default database, plus a wm */
- bool is_factory_startup = true;
- const bool use_data = true;
- const bool use_userdef = true;
-
/* Studio-lights needs to be init before we read the home-file,
* otherwise the versioning cannot find the default studio-light. */
BKE_studiolight_init();
BLI_assert((G.fileflags & G_FILE_NO_UI) == 0);
- wm_homefile_read(C,
- NULL,
- G.factory_startup,
- false,
- use_data,
- use_userdef,
- NULL,
- WM_init_state_app_template_get(),
- &is_factory_startup);
-
- /* Call again to set from userpreferences... */
+ /**
+ * NOTE(@campbellbarton): Startup file and order of initialization.
+ *
+ * Loading #BLENDER_STARTUP_FILE, #BLENDER_USERPREF_FILE, starting Python and other sub-systems,
+ * have inter-dependencies, for example.
+ *
+ * - Some sub-systems depend on the preferences (initializing icons depend on the theme).
+ * - Add-ons depends on the preferences to know what has been enabled.
+ * - Add-ons depends on the window-manger to register their key-maps.
+ * - Evaluating the startup file depends on Python for animation-drivers (see T89046).
+ * - Starting Python depends on the startup file so key-maps can be added in the window-manger.
+ *
+ * Loading preferences early, then application subsystems and finally the startup data would
+ * simplify things if it weren't for key-maps being part of the window-manager
+ * which is blend file data.
+ * Creating a dummy window-manager early, or moving the key-maps into the preferences
+ * would resolve this and may be worth looking into long-term, see: D12184 for details.
+ */
+ struct wmFileReadPost_Params *params_file_read_post = NULL;
+ wm_homefile_read_ex(C,
+ &(const struct wmHomeFileRead_Params){
+ .use_data = true,
+ .use_userdef = true,
+ .use_factory_settings = G.factory_startup,
+ .use_empty_data = false,
+ .filepath_startup_override = NULL,
+ .app_template_override = WM_init_state_app_template_get(),
+ },
+ NULL,
+ &params_file_read_post);
+
+ /* NOTE: leave `G_MAIN->name` set to an empty string since this
+ * matches behavior after loading a new file. */
+ BLI_assert(G_MAIN->name[0] == '\0');
+
+ /* Call again to set from preferences. */
BLT_lang_set(NULL);
- /* For fsMenu. Called here so can include user preference paths if needed. */
+ /* For file-system. Called here so can include user preference paths if needed. */
ED_file_init();
/* That one is generated on demand, we need to be sure it's clear on init. */
@@ -312,12 +333,13 @@ void WM_init(bContext *C, int argc, const char **argv)
if (!G.background) {
#ifdef WITH_INPUT_NDOF
- /* sets 3D mouse deadzone */
+ /* Sets 3D mouse dead-zone. */
WM_ndof_deadzone_set(U.ndof_deadzone);
#endif
WM_init_opengl();
if (!WM_platform_support_perform_checks()) {
+ /* No attempt to avoid memory leaks here. */
exit(-1);
}
@@ -328,20 +350,11 @@ void WM_init(bContext *C, int argc, const char **argv)
ED_spacemacros_init();
- /* NOTE(campbell): there is a bug where python needs initializing before loading the
- * startup.blend because it may contain PyDrivers. It also needs to be after
- * initializing space types and other internal data.
- *
- * However can't redo this at the moment. Solution is to load python
- * before wm_homefile_read() or make py-drivers check if python is running.
- * Will try fix when the crash can be repeated. */
-
#ifdef WITH_PYTHON
BPY_python_start(C, argc, argv);
BPY_python_reset(C);
#else
- (void)argc; /* unused */
- (void)argv; /* unused */
+ UNUSED_VARS(argc, argv);
#endif
if (!G.background) {
@@ -358,14 +371,6 @@ void WM_init(bContext *C, int argc, const char **argv)
wm_history_file_read();
- /* allow a path of "", this is what happens when making a new file */
-#if 0
- if (BKE_main_blendfile_path_from_global()[0] == '\0') {
- BLI_join_dirfile(
- G_MAIN->name, sizeof(G_MAIN->name), BKE_appdir_folder_default(), "untitled.blend");
- }
-#endif
-
BLI_strncpy(G.lib, BKE_main_blendfile_path_from_global(), sizeof(G.lib));
#ifdef WITH_COMPOSITOR
@@ -375,30 +380,7 @@ void WM_init(bContext *C, int argc, const char **argv)
}
#endif
- {
- Main *bmain = CTX_data_main(C);
- /* NOTE: logic here is from wm_file_read_post,
- * call functions that depend on Python being initialized. */
-
- /* normally 'wm_homefile_read' will do this,
- * however python is not initialized when called from this function.
- *
- * unlikely any handlers are set but its possible,
- * note that recovering the last session does its own callbacks. */
- CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first);
-
- BKE_callback_exec_null(bmain, BKE_CB_EVT_VERSION_UPDATE);
- BKE_callback_exec_null(bmain, BKE_CB_EVT_LOAD_POST);
- if (is_factory_startup) {
- BKE_callback_exec_null(bmain, BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST);
- }
-
- wm_file_read_report(C, bmain);
-
- if (!G.background) {
- CTX_wm_window_set(C, NULL);
- }
- }
+ wm_homefile_read_post(C, params_file_read_post);
}
void WM_init_splash(bContext *C)
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 50db8e73844..f1a8f4ffd71 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2497,7 +2497,7 @@ static int radial_control_get_path(PointerRNA *ctx_ptr,
/* get an rna string path from the operator's properties */
char *str;
- if (!(str = RNA_string_get_alloc(op->ptr, name, NULL, 0))) {
+ if (!(str = RNA_string_get_alloc(op->ptr, name, NULL, 0, NULL))) {
return 1;
}
@@ -3178,10 +3178,11 @@ static void redraw_timer_step(bContext *C,
LISTBASE_FOREACH (ScrArea *, area_iter, &screen->areabase) {
CTX_wm_area_set(C, area_iter);
LISTBASE_FOREACH (ARegion *, region_iter, &area_iter->regionbase) {
- if (region_iter->visible) {
- CTX_wm_region_set(C, region_iter);
- wm_draw_region_test(C, area_iter, region_iter);
+ if (!region_iter->visible) {
+ continue;
}
+ CTX_wm_region_set(C, region_iter);
+ wm_draw_region_test(C, area_iter, region_iter);
}
}
diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h
index c7fe07cad7f..2fa5a68829e 100644
--- a/source/blender/windowmanager/wm_files.h
+++ b/source/blender/windowmanager/wm_files.h
@@ -24,6 +24,7 @@
#pragma once
struct Main;
+struct wmFileReadPost_Params;
struct wmGenericCallback;
struct wmOperatorType;
@@ -33,15 +34,45 @@ extern "C" {
/* wm_files.c */
void wm_history_file_read(void);
+
+struct wmHomeFileRead_Params {
+ /** Load data, disable when only loading user preferences. */
+ unsigned int use_data : 1;
+ /** Load factory settings as well as startup file (disabled for "File New"). */
+ unsigned int use_userdef : 1;
+
+ /**
+ * Ignore on-disk startup file, use bundled `datatoc_startup_blend` instead.
+ * Used for "Restore Factory Settings".
+ */
+ unsigned int use_factory_settings : 1;
+ /**
+ * Load the startup file without any data-blocks.
+ * Useful for automated content generation, so the file starts without data.
+ */
+ unsigned int use_empty_data : 1;
+ /**
+ * Optional path pointing to an alternative blend file (may be NULL).
+ */
+ const char *filepath_startup_override;
+ /**
+ * Template to use instead of the template defined in user-preferences.
+ * When not-null, this is written into the user preferences.
+ */
+ const char *app_template_override;
+};
+
+void wm_homefile_read_ex(struct bContext *C,
+ const struct wmHomeFileRead_Params *params_homefile,
+ struct ReportList *reports,
+ struct wmFileReadPost_Params **r_params_file_read_post);
void wm_homefile_read(struct bContext *C,
- struct ReportList *reports,
- bool use_factory_settings,
- bool use_empty_data,
- bool use_data,
- bool use_userdef,
- const char *filepath_startup_override,
- const char *app_template_override,
- bool *r_is_factory_startup);
+ const struct wmHomeFileRead_Params *params_homefile,
+ struct ReportList *reports);
+
+void wm_homefile_read_post(struct bContext *C,
+ const struct wmFileReadPost_Params *params_file_read_post);
+
void wm_file_read_report(bContext *C, struct Main *bmain);
void wm_close_file_dialog(bContext *C, struct wmGenericCallback *post_action);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c
index dd9cac2bb16..ba30b0dd864 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_session.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c
@@ -657,9 +657,6 @@ bool wm_xr_session_surface_offscreen_ensure(wmXrSurfaceData *surface_data,
GPUViewport *viewport = vp->viewport;
const bool size_changed = offscreen && (GPU_offscreen_width(offscreen) != draw_view->width) &&
(GPU_offscreen_height(offscreen) != draw_view->height);
- char err_out[256] = "unknown";
- bool failure = false;
-
if (offscreen) {
BLI_assert(viewport);
@@ -670,8 +667,29 @@ bool wm_xr_session_surface_offscreen_ensure(wmXrSurfaceData *surface_data,
GPU_offscreen_free(offscreen);
}
+ char err_out[256] = "unknown";
+ bool failure = false;
+ eGPUTextureFormat format =
+ GPU_R8; /* Initialize with some unsupported format to check following switch statement. */
+
+ switch (draw_view->swapchain_format) {
+ case GHOST_kXrSwapchainFormatRGBA8:
+ format = GPU_RGBA8;
+ break;
+ case GHOST_kXrSwapchainFormatRGBA16:
+ format = GPU_RGBA16;
+ break;
+ case GHOST_kXrSwapchainFormatRGBA16F:
+ format = GPU_RGBA16F;
+ break;
+ case GHOST_kXrSwapchainFormatRGB10_A2:
+ format = GPU_RGB10_A2;
+ break;
+ }
+ BLI_assert(format != GPU_R8);
+
offscreen = vp->offscreen = GPU_offscreen_create(
- draw_view->width, draw_view->height, true, false, err_out);
+ draw_view->width, draw_view->height, true, format, err_out);
if (offscreen) {
viewport = vp->viewport = GPU_viewport_create();
if (!viewport) {
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index e928be571a2..47fb2642da1 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -345,13 +345,10 @@ elseif(APPLE)
set(TARGETDIR_VER "${PYTHON_LIBPATH}/Resources/${BLENDER_VERSION}")
set(INSTALL_BPY_TO_SITE_PACKAGES ON)
endif()
- # Dylibs folder for bpy.so.
- set(MAC_BLENDER_TARGET_DYLIBS_DIR "${TARGETDIR_VER}/lib")
else()
set(TARGETDIR_VER Blender.app/Contents/Resources/${BLENDER_VERSION})
- # Dylibs folder for Blender executable. @executable_path is an rpath.
- set(MAC_BLENDER_TARGET_DYLIBS_DIR "$<TARGET_FILE_DIR:blender>")
endif()
+ set(MAC_BLENDER_TARGET_DYLIBS_DIR "${TARGETDIR_VER}/lib")
# Skip relinking on cpack / install
set_target_properties(blender PROPERTIES BUILD_WITH_INSTALL_RPATH true)
endif()
diff --git a/source/tools b/source/tools
-Subproject c8579c5cf43229843df505da9644b5b0b720197
+Subproject 5cf2fc3e5dc28025394b57d8743401295528f31
diff --git a/tests/performance/api/environment.py b/tests/performance/api/environment.py
index 70fc15f251c..76c731b6118 100644
--- a/tests/performance/api/environment.py
+++ b/tests/performance/api/environment.py
@@ -47,7 +47,7 @@ class TestEnvironment:
print(f'Init {self.base_dir}')
self.base_dir.mkdir(parents=True, exist_ok=True)
- if len(self.get_configs_names()) == 0:
+ if len(self.get_config_names()) == 0:
config_dir = self.base_dir / 'default'
print(f'Creating default configuration in {config_dir}')
TestConfig.write_default_config(self, config_dir)
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index 0f9665f0a95..79632e49c1f 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -741,10 +741,17 @@ if(WITH_COMPOSITOR)
endif()
set(geo_node_tests
+ attributes
+ curve_primitives
curves
geometry
+ mesh_primitives
mesh
points
+ utilities
+ vector
+ volume
+
)
foreach(geo_node_test ${geo_node_tests})