Commit Graph

5369 Commits

Author SHA1 Message Date
Sergey Sharybin
0b369f0ff1 Fix compilation error on macOS after recent cleanup
Fixes the following error:
  error: must use 'struct' tag to refer to type 'timezone' in this scope
2025-02-13 10:28:39 +01:00
Campbell Barton
640e70b6e8 Cleanup: various non-functional changes for C++ 2025-02-13 13:33:09 +11:00
Brecht Van Lommel
e2e1984e60 Refactor: Convert remainder of blenlib to C++
A few headers like BLI_math_constants.h and BLI_utildefines.h keep working
for C code, for remaining makesdna and userdef defaults code in C.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Brecht Van Lommel
7b3fa03e56 Math: Work around Windows math::is_negative build failures
Don't template size for matrix is_negative. These are causing random
build failures on the Windows buildbot.

Note that these already have the assumption of 3D coordinates baked
in. For 2D or 4D coordinates the implementation would have to be
different. So templating these for arbitrary dimensions does not
make much sense.

Pull Request: https://projects.blender.org/blender/blender/pulls/134137
2025-02-06 14:29:09 +01:00
Campbell Barton
95393726b0 Cleanup: quiet check_spelling_* warnings 2025-02-04 14:43:20 +11:00
Campbell Barton
ded798ba28 Fix #133921: Borderless windows on Wayland when run from VSCode
Workaround a problem where Electron overrides XDG_CURRENT_DESKTOP
by checking if an "ORIGINAL_" prefixed version of the variable.
2025-02-03 19:35:11 +11:00
Brecht Van Lommel
6b6cd3307b Cleanup: Various clang-tidy warnings in blenlib
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Jacques Lucke
e1753900b7 BLI: improve UTF-8 safety when copying StringRef to char buffers
Previously, there was a `StringRef.copy` method which would copy the string into
the given buffer. However, it was not defined for the case when the buffer was
too small. It moved the responsibility of making sure the buffer is large enough
to the caller.

Unfortunately, in practice that easily hides bugs in builds without asserts
which don't come up in testing much. Now, the method is replaced with
`StringRef.copy_utf8_truncated` which has much more well defined semantics and
also makes sure that the string remains valid utf-8.

This also renames `unsafe_copy` to `copy_unsafe` to make the naming more similar
to `copy_utf8_truncated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133677
2025-01-29 12:12:27 +01:00
Jacques Lucke
48187684a3 BLI: assert valid utf8 in string search
This has been discussed in the context of #129209.
2025-01-27 16:38:06 +01:00
Jacques Lucke
fb7eef9271 BLI: add IndexMask::from_ranges constructor function
This can be useful when going from a selection of curves to the corresponding
selection of points.

The simple implementation given here should work quite well in the majority of
cases. There is still optimization potential for some cases involving masks with
many gaps. The implementation is also single threaded for now. Using
multi-threading is possible, but should ideally be done in some way to still
lets us exploit the fact that the index ranges are already in sorted order.

Pull Request: https://projects.blender.org/blender/blender/pulls/133323
2025-01-21 18:18:12 +01:00
Brecht Van Lommel
890455affe Refactor: Rename function to clarify it's for sRGB only
Pull Request: https://projects.blender.org/blender/blender/pulls/133368
2025-01-21 18:05:56 +01:00
Campbell Barton
723cd87d49 Cleanup: quiet compiler warning 2025-01-20 17:10:21 +11:00
Ray Molenkamp
f6f1d610d8 Fix: Failing geo node tests on MSVC 2022
The MSVC 2022 optimizer generates bad code for perlin_fractal_distorted
when perlin_fbm gets inlined leading to incorrect results and failing
tests that rely on perlin noise. For now just disable inlining for this
function for msvc2022 until we can get the compiler fixed.

This fixes the following failing tests on MSVC 2022:

- geo_node_curves_deform_curves_on_surface
- geo_node_geometry_delete_geometry_propogate_corner_attribute
- geo_node_utilities_field_on_domain_demo

Pull Request: https://projects.blender.org/blender/blender/pulls/133130
2025-01-17 01:00:40 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Jacques Lucke
41b2611a8d BLI: add remove_if function for global memory cache
Before, it was only possible to clear the entire cache at once or to rely on
automatic clearing when it gets full. This patch adds the ability to remove
cached data based on a predicate function.

This is useful for #124369 for partially invalidating the cache for some files.

Pull Request: https://projects.blender.org/blender/blender/pulls/132605
2025-01-06 18:07:03 +01:00
YimingWu
18b690dee6 Fix #132325: Decimate fails to convert small faces to quads
Decimate used `is_quad_convex_v3` to check if faces should be converted
to quads, adjust the epsilon since small faces were being skipped.

Ref: !132342
2025-01-06 13:46:41 +11:00
Brecht Van Lommel
841ae6e8ab Fix part of #131933: Crash with playback of deforming subdivision surface
The `ForeachContext` in `deform_coarse_vertices` does not use TLS but still has
a `func_free` callback set. Change the task API to allow this.

Pull Request: https://projects.blender.org/blender/blender/pulls/132498
2025-01-02 12:21:56 +01:00
Campbell Barton
dca0996777 Cleanup: various non-functional changes for C++ 2025-01-02 15:11:20 +11:00
Campbell Barton
dfef060ea4 Cleanup: spelling in comments (make check_spelling_*)
Also use doxy-code blocks for inlined TEX to avoid
them being interpreted as English.
2025-01-02 15:11:17 +11:00
Campbell Barton
1b0cef86fa Fix UNIX crash on startup when HOME isn't set
Regression in [0] which re-introduced #2931.

Accessing environment variables must always null check the result.

Resolve by checking the result as well as replacing $HOME
access with a function that falls back to `passwd::pw_dir`.

Also add code-comments to to clarify the current behavior.

[0]: b308b360eb
2025-01-02 14:46:55 +11:00
Hans Goudey
2f0d1a52f9 Cleanup: Formatting 2024-12-30 11:37:25 -05:00
Hans Goudey
dacc9455ba Cleanup: Remove unused color math functions
Unused for at least 14 years.
2024-12-30 11:13:47 -05:00
Hans Goudey
cc2e0808eb Cleanup: Remove unused math C-API functions
Pull Request: https://projects.blender.org/blender/blender/pulls/132183
2024-12-20 21:47:00 +01:00
Hans Goudey
853443a390 Cleanup: Formatting 2024-12-20 15:27:03 -05:00
Hans Goudey
90cfc4d89f Cleanup: Remove unused color conversion function
Unused for 14 years.
2024-12-20 15:05:56 -05:00
Hans Goudey
ab53a84299 Cleanup: Remove unused qsort utility functions 2024-12-20 15:05:56 -05:00
Hans Goudey
0e15649bf8 Cleanup: Remove unused dynlib files
This has been unused since the game engine was removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/132186
2024-12-20 20:38:40 +01:00
Hans Goudey
31964ef5ca Cleanup: Move BLI_kdopbvh to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/132031
2024-12-17 21:04:55 +01:00
Jacques Lucke
52989a1b9a BLI: simplify creating the union of multiple index masks
This adds a new function to combine multiple index masks into one.

Pull Request: https://projects.blender.org/blender/blender/pulls/131898
2024-12-14 16:56:16 +01:00
Campbell Barton
21ecc1a804 Cleanup: use function style casts 2024-12-09 09:14:46 +11:00
Campbell Barton
083b690fb5 Cleanup: spelling in comments 2024-12-09 09:14:44 +11:00
Hans Goudey
77af97d5b9 Cleanup: Move some blenlib files to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/131319
2024-12-05 14:36:01 +01:00
Christoph Lendenfeld
2536ddac0d Fix #123875: FCurve noise modifier producing values out of range
This patch adds an option to use the new perlin noise as a noise function for the FCurve modifier.
That fixes the issue of the old noise function which could produce values outside the -0.5/0.5 range (For a strength of 1).

The old way is still preserved and will be automatically used for old files.
Because of the different noise function, I've added two more parameters to the noise modifier.
The default values for those parameters are chosen to be as close to the original noise modifier as possible.
However the match is not 1:1

## Depth
With the new noise, the parameters for "Lacunarity" and "Roughness" are available to the user.
By default they are set in such a way that changing the "Depth" results in a similar noise pattern.

## Offset and Scale
The offset and scale parameters now behave differently. Before they would also shift the phase in some way, now all they do is shift or scale the noise.

## Amplitude

The biggest difference is in the amplitude of the noise.

Overall the amplitude is a lot smaller in general than with the legacy noise, but it does fix the issue of the amplitude reaching outside the -0.5/0.5 range.
By shifting the phase I was able to find points where the amplitude reaches 0.5 but never above that.

Pull Request: https://projects.blender.org/blender/blender/pulls/129535
2024-12-05 10:48:27 +01:00
Hans Goudey
6836dca44d Cleanup: Remove unused parts of BLI_rand.h C-API 2024-12-04 11:29:28 -05:00
Hans Goudey
a31b6c1863 BLI: Inline math vector "is finite" checks
These functions showed up in a profile of a geometry nodes setup
using BVH sampling. They are so simple that function call overhead
is likely to be significant, and giving the compiler a view of what they
do is also likely to be helpful.
2024-12-04 09:04:43 -05:00
Hans Goudey
0299ea5463 Cleanup: Remove unused functions from BLI math C-API 2024-12-04 08:48:38 -05:00
Omar Emara
462b81efca Fix: Border bicubic interpolation is wrong around edges
The BLI bicubic interpolation function with border boundary is wrong
around edges. It returns zero, where interpolated values should exist.
This is due to a wrong early exit condition, where only a 2x2 window is
assumed instead of the 4x4 window considered by bicubic interpolation.
To fix this, assume a 2 pixel region in the early exit condition for
both directions.

Pull Request: https://projects.blender.org/blender/blender/pulls/131320
2024-12-04 08:39:58 +01:00
Hans Goudey
0675353625 Cleanup: Remove unused functions from BLI math C-API
Pull Request: https://projects.blender.org/blender/blender/pulls/131313
2024-12-03 15:44:36 +01:00
Omar Emara
be22fcf425 Fix: Wrong border nearest interpolation around negative edges
The BLI wrapmode variant of nearest interpolation for border boundary is
wrong for coordinates between [-1, 0]. That's because the negative
comparison in wrap_coord is done on the integer rounded coordinates,
which will be zero in this case, so the condition will not fail. To fix
this, do the comparison on the original coordinates instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/131306
2024-12-03 15:04:50 +01:00
Aras Pranckevicius
377e998e39 BLI: Add pixel sampling functions with arbitrary UV wrapping modes
Implements #130836:

interpolate_*_wrapmode_fl take InterpWrapMode wrap_u and wrap_v arguments.
U and V coordinate axes can have different wrap modes: clamp/extend,
border/zero, wrap/repeat.

Note that this removes inconsistency where cubic interpolation was
returning zero for samples completely outside the image, but all other
functions were not, and the behavior was not matching the function
documentation either.

Use the new functions in the new compositor CPU backend.

Possible performance impact for other places (e.g. VSE): measured on
4K resolution, transformed (scaled and rotated) 4K EXR image:
- Nearest filter: no change,
- Bilinear filter: no change,
- Cubic BSpline filter: slight performance decrease, IMB_transform
  19.5 -> 20.7 ms (Ryzen 5950X, VS2022). Feels acceptable.

Pull Request: https://projects.blender.org/blender/blender/pulls/130893
2024-11-25 16:03:33 +01:00
Campbell Barton
0de8ae8046 Cleanup: spelling in comments 2024-11-25 13:24:46 +11:00
Hans Goudey
a4c9b691a0 Attributes: Add 2D 16 bit integer type
Add a `short2` attribute type, intended to store the existing
`CD_CUSTOMLOOPNORMAL` custom data type in order to move the custom
normal storage to generic attributes. This type probably won't get much
use besides that, but generally we don't have reasons not to add these
generic types, besides binary size. In the future we should consolidate
usage of `convert_to_static_type` to avoid large binary size increases
(about 700KB here) for this sort of addition.

This is the first step of #130484.

Pull Request: https://projects.blender.org/blender/blender/pulls/130530
2024-11-21 17:02:05 +01:00
Hans Goudey
c497d5c3fa Refactor: Move quad triangulation function to blenlib
Make this available for a Mesh-based triangulation implementation
implemented elsewhere. Part of #112264.
2024-11-21 08:30:28 -05:00
Iliya Katueshenock
ae0ab14716 Cleanup: BLI: Binary search first_if and last_if utils
Cleanup to simplify code by using common terms like _first_ and _last_ in context
of predicate applying in a range just like we do for spans and range containers.

Pull Request: https://projects.blender.org/blender/blender/pulls/130380
2024-11-19 11:05:57 +01:00
Jacques Lucke
64a9260921 Core: remove WITH_CXX_GUARDEDALLOC option
This implements the proposal from #124512. For that it contains the following
changes:
* Remove the global override of `new`/`delete` when `WITH_CXX_GUARDEDALLOC` was
  enabled.
* Always use `MEM_CXX_CLASS_ALLOC_FUNCS` where it is currently used. This used
  to be guarded by `WITH_CXX_GUARDEDALLOC` in some but not all cases. This means
  that a few classes which didn't use our guarded allocator by default before,
  are now using it.

Pull Request: https://projects.blender.org/blender/blender/pulls/130181
2024-11-13 13:39:49 +01:00
Sergey Sharybin
e5775c3924 Cleanup: Use C marker for unused arguments
Fixes the following warning:
system.c:63:74: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions]
2024-11-11 11:36:28 +01:00
Germano Cavalcante
7ce080cf72 Refactor: prevent storing dangling pointers
The `_EXCEPTION_POINTERS` structure is valid only within the context of
the `UnhandledExceptionFilter` function.

After the function exits, the memory referenced by the pointer might no
longer be valid or the exception information.

The solution for this was to create `BLI_system_backtrace_with_os_info`
and passing a system-specific data as the second argument.
`BLI_system_backtrace` calls `BLI_system_backtrace_with_os_info` with a
null second argument internally.

Pull Request: https://projects.blender.org/blender/blender/pulls/129999
2024-11-08 23:17:36 +01:00
Germano Cavalcante
1633766c2e Refactor: move blenlib system_win32 to C++ 2024-11-07 17:33:27 -03:00
Julian Eisel
a482ffdf56 Merge branch 'blender-v4.3-release' 2024-11-07 15:50:10 +01:00
Julian Eisel
3a7b6c4f79 Fix #129622: Crash loading asset library with malformed asset index JSON
Catch any exception from the JSON parser and handle it by returning a
null value from the deserialization function. Let the asset indexer
regenerate the index file to handle the error.

At least for the asset index case we don't care about the exact parsing
error, so this simple error handling strategy is fine. Should more
precise error reporting be necessary for other use-cases this can be
added still, but I think these errors are usually a bit too low level to
expose to users.

Pull Request: https://projects.blender.org/blender/blender/pulls/129879
2024-11-07 15:39:58 +01:00