Commit Graph

842 Commits

Author SHA1 Message Date
Harley Acheson 27c95da888 Refactor: Remove BLF _ex functions using default arguments
Remove all BLF "_ex" versions of functions by using default arguments.
These functions only differ by having an optional argument that can
return extra details about the result of the operation. This PR just
make these part of the main function as optional arguments with default
values - all nullptr.

Pull Request: https://projects.blender.org/blender/blender/pulls/119994
2024-03-28 04:02:13 +01:00
Hans Goudey e1c54d5a24 Fix: Windows build error after recent cleanup commit 2024-03-26 16:20:40 -04:00
Hans Goudey 48e4576162 Cleanup: Remove unnecessary keywords from C++ headers 2024-03-26 15:58:39 -04:00
Hans Goudey 893130e6fe Refactor: Remove unnecessary C wrapper for GPUBatch class
Similar to fe76d8c946

Pull Request: https://projects.blender.org/blender/blender/pulls/119898
2024-03-26 03:06:25 +01:00
Hans Goudey fe76d8c946 Refactor: Remove unnecessary C wrappers for vertex and index buffers
Now that all relevant code is C++, the indirection from the C struct
`GPUVertBuf` to the C++ `blender::gpu::VertBuf` class just adds
complexity and necessitates a wrapper API, making more cleanups like
use of RAII or other C++ types more difficult.

This commit replaces the C wrapper structs with direct use of the
vertex and index buffer base classes. In C++ we can choose which parts
of a class are private, so we don't risk exposing too many
implementation details here.

Pull Request: https://projects.blender.org/blender/blender/pulls/119825
2024-03-24 16:38:30 +01:00
Hans Goudey 8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Aras Pranckevicius a05adbef28 BLF: optimizations and fixes to font shader
Simplifies/optimizes the "font" shader. It runs faster now too, but primarily
this is so that it loads/initializes faster.

* Instead of doing blur via individual bilinear samples (where each sample is 4
  texel fetches), do raw texel fetches of the kernel footprint and compute final
  result by shifting the kernel weights according to bilinear fraction weight.
  For 5x5 blur, this reduces number of texel fetches from 64 down to 36.
* Instead of checking "is the texel inside the glyph box? if so, then fetch it",
  first fetch it, and then set result to zero if it was outside. Simplifies the
  branching code flow in the compiled GPU shader.
* Avoid costly integer modulo/division for "unwrapping" the font texture. The
  texture width is always power of two size, so division/modulo can be replaced
  by masking and a shift. Setup uniforms to contain the needed data.

### Fixes

* The 3x3 blur was not doing a 3x3 blur, due to a copy-pasta typo (one of the
  sample offsets was repeated twice, and thus another sample offset was
  missing).
* Blur towards left/top edges of the glyphs had artifacts, because float->int
  casting in GLSL rounds towards zero, but the code actually wanted to round
  towards floor.

Image of how the blur has changed in the PR.

### First time initialization

* Windows 10, NVIDIA RTX 3080Ti, OpenGL: 274.4ms -> 51.3ms
* macOS, Apple M1 Max, Metal: 456ms -> 289ms (this is including PSO creation
  time).

### Shader performance/complexity

Performance I only measured on macOS (M1 Max), by making a BLF text that is
scaled up to cover most of screen via Python. Using Xcode Metal profiler,
drawing that text with 5x5 shadow blur: 1.5ms -> 0.3ms.

More performance analysis details in PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/119653
2024-03-19 16:29:21 +01:00
Hans Goudey 744f3b2823 Cleanup: Grammar in comments: Fix uses of "own"
"Own" (the adjective) cannot be used on its own. It should be combined
with something like "its own", "our own",  "her own", or "the object's own".
It also isn't used separately to mean something like "separate".

Also, "its own" is correct instead of "it's own" which is a misues of the verb.
2024-03-07 16:23:35 -05:00
Campbell Barton 76867ad4c2 Cleanup: redundant "void" in function declarations for C++ 2024-03-05 11:25:35 +11:00
Harley Acheson b02f0cf206 Refactor: Store BLF Glyphs in blender::Map
Store the GlyphBLFs in a blender::Map rather than our current hash
table, which is an array of 257 ListBases.

Pull Request: https://projects.blender.org/blender/blender/pulls/118528
2024-02-21 18:17:21 +01:00
Harley Acheson af4b09a61c BLF: Utility to Wrap a String into Multiple Lines
Given a string, font id, and width, return a string vector with the string
wrapped to that width.

Pull Request: https://projects.blender.org/blender/blender/pulls/118436
2024-02-21 01:19:04 +01:00
Harley Acheson 4ed6daf490 Refactor: BLF Remove blf_glyph_ensure_ex Using Default Argument
We have both a blf_glyph_ensure and blf_glyph_ensure_ex, with the former
calling the latter with subpixel equal to zero. This PR just combines
the two using a C++ default optional parameter.

Pull Request: https://projects.blender.org/blender/blender/pulls/118470
2024-02-19 21:09:08 +01:00
Harley Acheson 783e565110 Refactor: BLF Remove Size Parameter from blf_glyph_cache_find
The "size" parameter here is unnecessary in that we are passing the
font itself and the function is only ever called (the once) with
font->size. The parameter is also misleading in that you could assume
that the cache is matching only the font size when it actually matches
multiple attributes, including size. Size isn't special here.

Pull Request: https://projects.blender.org/blender/blender/pulls/118469
2024-02-19 20:31:53 +01:00
Hans Goudey fb8f9deaab Cleanup: Store BLF Glyph cache with C++ Vector, use std::mutex
- Store glyph cache entries as unique pointers in a vector
- Use std::mutex instead of `ThreadMutex`

Pull Request: https://projects.blender.org/blender/blender/pulls/118222
2024-02-19 03:34:36 +01:00
Campbell Barton 3f8cd44485 Cleanup: move BLI_strict_flags.h last, not that it should be kept last
Also add a note in the header why it should be kept last.
2024-02-14 13:40:31 +11:00
Hans Goudey 5ba6f6d833 Cleanup: Replace typedef keyword in C++ headers 2024-02-13 15:34:32 -05:00
Hans Goudey 7fa5fc02b7 Cleanup: Move BLF headers to C++ 2024-01-31 14:04:56 -05:00
Brecht Van Lommel e0ff7731e0 Core: make BKE_appdir functions thread safe, using optional<string>
The static variables can cause the wrong path to be used, for example
when asset indexing in a thread affects loading toolbar icons.

Fix #117416: toolbar icon randomly missing

Pull Request: https://projects.blender.org/blender/blender/pulls/117419
2024-01-23 18:38:15 +01:00
Harley Acheson a4a8683788 UI: Increased Overlay Text Contrast
Increased contrast of light text on any background by increasing the
effectiveness of the dark shadow.

Pull Request: https://projects.blender.org/blender/blender/pulls/117351
2024-01-22 21:57:55 +01:00
Hans Goudey 0618de49ad Cleanup: Replace MIN/MAX macros with C++ functions
Use `std::min` and `std::max` instead. Though keep MIN2 and MAX2
just for C code that hasn't been moved to C++ yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/117384
2024-01-22 15:58:18 +01:00
Bastien Montagne d8d44a62f7 Cleanup: Move `BKE_appdir.h` to full Cpp header `BKE_appdir.hh`. 2024-01-21 19:42:13 +01:00
Aras Pranckevicius a705259b4b Cleanup: move imbuf .h files to .hh 2024-01-19 20:29:38 +01:00
Hans Goudey 21407901f8 Cleanup: Various clang tidy changes 2024-01-19 12:08:48 -05:00
Campbell Barton ae29c8d950 Fix font sub-pixel AA impacting character spacing when AA is disabled 2024-01-17 18:36:54 +11:00
Brecht Van Lommel d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Campbell Barton 950334a02c Cleanup: remove duplicate null check in blf_search_by_mem_name 2023-12-17 16:43:18 +11:00
Campbell Barton 4d965615fc Cleanup: various C++ changes (use ELEM & string copy macros) 2023-12-17 16:25:10 +11:00
Campbell Barton 7346727cfc Fix #116215: Sequencer crashes unlinking packed text
[0] caused a regression looking up fonts by filepath.

[0]: d770fd5ac4
2023-12-15 20:13:40 +11:00
Harley Acheson 8c6898c04d Fix #116135: Ensure blf_font_width_to_rstrlen always works
If the string is shorter than the cut-off length, ensure we always
exit cleanly when we iterate to the very start of the string.

Pull Request: https://projects.blender.org/blender/blender/pulls/116208
2023-12-14 23:19:08 +01:00
Campbell Barton ff47eb3e37 Cleanup: minor style tweaks, surround ELEM by parenthesis 2023-12-10 17:12:53 +11:00
Harley Acheson 76bf43f44d Fix #115938: BLF Handle Negative Left-Side Bearings
Our glyph bounds clipping test will fail for the first character of a
string if that character has negative left-side bearing. This is not
usual but can happen in some designs for lowercase "j" to have the tail
hook under the preceding character.

Pull Request: https://projects.blender.org/blender/blender/pulls/115965
2023-12-09 01:52:45 +01:00
Jeroen Bakker 65e58fe574 CMake: Fix Compiling Shader Builder on macOS
Due to changes in the build environment shader_builder wasn't able to
compile on macOs. This patch reverts several recent changes to CMake files.

* dbb2844ed9
* 94817f64b9
* 1b6cd937ff

The idea is that in the near future shader_builder will run on the buildbot as
part of any regular build to ensure that changes to the CMake doesn't break
shader_builder and we only detect it after a few days.

Pull Request: https://projects.blender.org/blender/blender/pulls/115929
2023-12-08 15:47:14 +01:00
Campbell Barton 497600e49e Cleanup: spelling in comments, strings 2023-12-07 12:45:27 +11:00
Brecht Van Lommel e06561a27a Build: replace Blender specific DEBUG by standard NDEBUG
NDEBUG is part of the C standard and disables asserts. Only this will
now be used to decide if asserts are enabled.

DEBUG was a Blender specific define, that has now been removed.

_DEBUG is a Visual Studio define for builds in Debug configuration.
Blender defines this for all platforms. This is still used in a few
places in the draw code, and in external libraries Bullet and Mantaflow.

Pull Request: https://projects.blender.org/blender/blender/pulls/115774
2023-12-06 16:05:14 +01:00
Harley Acheson c8d1bb5902 BLF: Rename Text Shader Depth to Component Len
Rename text shader glyph "depth" to "glyph_comp_len", as requested
by Clément Foucault.

Pull Request: https://projects.blender.org/blender/blender/pulls/115640
2023-12-01 02:07:57 +01:00
Harley Acheson 5d330ddb1f BLF: Support All Render and Bitmap Formats
Add support for all of FreeType's various render formats and output
bitmap formats.

Pull Request: https://projects.blender.org/blender/blender/pulls/115452
2023-11-30 22:17:30 +01:00
Campbell Barton 27c660707d Cleanup: spelling in comments, variables 2023-11-27 09:54:36 +11:00
Ray Molenkamp 1b6cd937ff Cleanup: CMake: Modernize bf_imbuf dependencies
Pretty straightforward

- Remove any bf_imbuf paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115425
2023-11-25 23:37:24 +01:00
Ray Molenkamp ae25298774 Cleanup: CMake: Modernize bf_blenfont dependencies
Pretty straightforward

- Remove any bf_blenfont paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115365
2023-11-24 18:29:09 +01:00
Harley Acheson 604ee2d036 VFont: Use BLF for font & glyph loading
Load VFont curves using BLF API rather than local FreeType calls.

Pull Request: https://projects.blender.org/blender/blender/pulls/110187
2023-11-23 18:12:04 +01:00
Harley Acheson 3f5654b491 Fix #114080: Add Khmer Font
Add Noto Sans Khmer (variable) font, needed for new translation.
2023-11-13 17:38:03 +01:00
Campbell Barton 611930e5a8 Cleanup: use std::min/max instead of MIN2/MAX2 macros 2023-11-07 16:33:19 +11:00
Campbell Barton 79840a9ec6 Cleanup: early returns in BLF, use full scentences 2023-11-07 11:31:01 +11:00
Campbell Barton c8c2343b4b Cleanup: spelling in comments 2023-10-23 10:09:05 +11:00
Harley Acheson b53111e935 BLF: Improved Cached Fallback Font Setup
Changes to FontBLF initialization so that the cached fallback fonts,
which remain faceless until needed, get all required setup.
Otherwise they are not kerned and we also don't get metrics from them.

Pull Request: https://projects.blender.org/blender/blender/pulls/114018
2023-10-22 03:54:57 +02:00
Harley Acheson 0bde01eab5 UI: Configurable UI Font Weight
Allows selecting different font weights in Text Styles

Pull Request: https://projects.blender.org/blender/blender/pulls/112454
2023-10-21 00:28:28 +02:00
Campbell Barton 2e0b844b36 Cleanup: spelling in comments 2023-10-14 13:53:00 +11:00
Harley Acheson 83705a87cb FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
Harley Acheson 2d5c762645 Merge branch 'blender-v4.0-release' 2023-10-13 13:32:28 -07:00
Harley Acheson d625feadd8 Fix #113689: Improved BLF_width_to_strlen Measurement
BLF_width_to_strlen measures text with reduced accuracy with Hinting or
subpixel anti-aliasing enabled. blf_font_width_to_strlen_glyph_process
does not take into account these changes when iterating through glyphs.

Pull Request: https://projects.blender.org/blender/blender/pulls/113698
2023-10-13 22:31:08 +02:00