Commit graph

22 commits

Author SHA1 Message Date
Vladislav Belov
e8a5103f8c
Fixes #8057 by properly initializing atlas texture.
Fixes #8057
Fixes #8184
Fixes #8345
2025-09-17 14:31:16 +02:00
Vladislav Belov
3eca24ed11
Fixes CC for fonts. 2025-09-17 12:32:12 +02:00
Vladislav Belov
e2d9450d0d
Revert "Font: make atlas uploads queue-aware on Vulkan"
This reverts commit 256dff7fd4.
2025-09-17 12:32:08 +02:00
trompetin17
b5e2ca7300
Fix GUI text clipping when scaling interface
When scaling the GUI, GetCapHeight was incorrectly accounting for
m_Scale which caused text to be hidden due to improper clipping
calculations.
This commit corrects the CapHeight calculation by ensuring that the
division by m_Scale is applied, allowing text to be displayed correctly
at all GUI scale levels.
2025-09-13 09:58:09 -05:00
Ralph Sennhauser
ceb491c599
Make cppcheck happy wrt std::span usage
We don't gain anything using a span here, so just don't.

```
source/graphics/Font.cpp:535:35: error: Out of bounds access in 'tempDstRow[3]', if 'tempDstRow' size is 2 and '3' is 3 [containerOutOfBounds]
   const float dstAlpha{tempDstRow[3] / 255.0f};
                                  ^
source/graphics/Font.cpp:543:14: error: Out of bounds access in 'tempDstRow[2]', if 'tempDstRow' size is 2 and '2' is 2 [containerOutOfBounds]
   tempDstRow[2] = static_cast<u8>(std::round(((b * srcAlpha + tempDstRow[2] * dstAlpha * (1.0f - srcAlpha)) / outAlpha)));
             ^
source/graphics/Font.cpp:544:14: error: Out of bounds access in 'tempDstRow[3]', if 'tempDstRow' size is 2 and '3' is 3 [containerOutOfBounds]
   tempDstRow[3] = static_cast<u8>(std::round(outAlpha * 255.0f));
             ^
```

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-24 11:09:57 +02:00
Ralph Sennhauser
77e05ca26d
Convert span with dynamic extent to static extent
In some places we know the size at compile time, so use that knowlage.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-24 11:09:57 +02:00
Ralph Sennhauser
2cedb48de2
Remove custom span and use std::span
With C++20 the custom container PS:span, which was a backport of
std::span is no longer needed.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-24 11:09:57 +02:00
Ralph Sennhauser
8398f1baf4
Fix some includes in source/graphics
Make include-what-you-use happy with some files in source/graphics and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-20 17:28:48 +02:00
Ralph Sennhauser
a2f15bae4e
Fix some includes in source/graphics
Make include-what-you-use happy with some files in source/graphics and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-18 07:30:04 +02:00
trompetin17
256dff7fd4
Font: make atlas uploads queue-aware on Vulkan
Goal
----
Avoid corrupting the dynamic font-atlas on Vulkan by blocking any
re-uploads until the command buffer that created / last updated the
texture has actually been submitted.

What changed
------------
* **Queue-aware textures**
  * Added `queueSubmitAware` flag to `IDevice::CreateTexture*` APIs.
  * `Vulkan::CTexture` now stores two booleans:
      - `m_QueueSubmitAware` – opt-in per texture.
      - `m_PendingQueueSubmit` – set to *true* the moment an upload
        is recorded, cleared once the submit scheduler has flushed.
  * `CRingCommandContext::ScheduleUpload` marks the texture as
    pending (`SetPendingQueueSubmit(true)`).

* **Device-side watcher**
  * `Vulkan::CDevice` keeps a
    `m_TextureUploadWatcherQueue`. Each frame it checks textures that
    were uploaded ≥ `NUMBER_OF_FRAMES_IN_FLIGHT` frames ago and
    clears their pending flag.
  * New helpers
    `ScheduleTextureUploadWatch `,
    `ProcessTextureUploadWatchQueue()`.

* **Font code**
  * Atlas texture is now created with
    `queueSubmitAware = true`.
  * `CFont::UploadTextureAtlasToGPU()` early-outs when
    `IsPendingQueueSubmit()` returns *true*, instead of tracking a
    submit-handle or the manual `m_IsLoadingTextureToGPU` flag
    (removed).

Why this is better
------------------
The logic to wait for a flush is localised inside the rendering
backend, so `CFont` only needs to ask *“is my texture busy?”*.
This removes the fragile submit-handle bookkeeping and works even if
the scheduler issues multiple submits per frame in future.

Result
------
Atlas uploads are deferred until the previous submit completes,
eliminating the intermittent glyph corruption on the Vulkan backend
while leaving GL and the dummy backend unchanged.
2025-07-09 13:09:46 -05:00
Ralph Sennhauser
5e4b49f65f
Fix some includes in source/renderer
Make include-what-you-use happy with some files in source/renderer and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-07 17:45:54 +02:00
trompetin17
dfb4598186
Align font height, capHeight to FreeType metrics
Previously, `height` was derived from a manually chosen glyph (typically
"I", Standard Cap Height) using FontBuilder, and `lineSpacing` was used
inconsistently for layout logic as a height.

Now, with the FreeType-based system:
- `height` uses `face->size->metrics.height`, which includes the
  recommended line height with internal leading/line gap as defined by
  the font designer.
- `lineSpacing` was removed
- `GetCapHeight` uses the standard cap height + ascender to have a
  visual virtual alignment

This change standardizes font metric usage:
- Use `height` for vertical layout and line progression.
- Use `GetCapheight` in layout engines like `CGUIText` or `CGUIString`,

This ensures better alignment across fonts and consistent spacing in
multiline text rendering.

Fixes: #7962
2025-06-11 08:10:18 -05:00
trompetin17
4dc686564e
Fix FreeType font loading from zipped mods
The FreeType font loader was directly passing filesystem-style paths
(e.g., mod.zip/...) to FT_New_Face, which does not support paths inside
ZIP archives. As a result, FreeType failed to open the font, triggering
a crash when the engine attempted to use an invalid face object.

This patch changes the font loading logic to:

Use the VFS to read the .ttf font file into memory (shared_ptr<u8> and
size).

Load the font using FT_New_Memory_Face with the in-memory buffer,
ensuring compatibility with zipped mods.
2025-06-03 11:20:56 -05:00
trompetin17
2781d9a6a3
Add Fallback Font support
In previous fontbuilder.py we have the capacity to specified chain fonts
when a glyph is missed from one font.

This commit enable that behavior.
2025-05-28 01:01:03 -05:00
trompetin17
bdd94bd264
Add font engine aware of Gui.scale
This commit enhances text rendering by leveraging FreeType and a dynamic
font atlas. Previously, GUI scaling relied on bitmap fonts, which led to
blurry and distorted text when scaling up. Now, we scale the font size
directly using FreeType, resulting in much sharper and more readable
text at any GUI scale.

Key improvements:
- Replaced bitmap font scaling with true font size scaling via FreeType.
- Reduced glyph cache dependency on fixed positions, relying on shader
  scaling instead.
- Switched to float-based glyph positioning for more accurate rendering
  and scaling.

These changes ensure clean and consistent text appearance across
different GUI scales.
2025-05-26 13:12:47 -05:00
trompetin17
c8c1522953
Fix memory leak from Font
FreeType’s FT_Glyph_To_Bitmap mutates the FT_Glyph by allocating a new
glyph object and overwriting the input pointer. This creates a risk of
memory leaks if the old glyph isn’t released or if ownership is unclear.

To avoid this, we now store the glyph in a UniqueFTGlyph and explicitly
pass it by reference to FT_Glyph_To_Bitmap. After the mutation,
ownership continues to reside in the smart pointer, and cleanup is
guaranteed even in error branches.

For temporary glyphs (e.g., strokes), we still manually call
FT_Done_Glyph, since they are not managed by UniqueFTGlyph. These
changes ensure all glyph memory is correctly released and reduce the
need for repetitive error-path cleanup code.
2025-05-22 11:35:12 -05:00
trompetin17
734386ce9f
Use freetype for font rendering
Replace premade bitmap fonts with FreeType2 and dynamic texture atlas.

Switched from static, premade bitmap fonts to runtime-generated glyphs using FreeType2.
Glyphs are rendered on demand into a dynamic texture atlas, improving scalability,
font quality, and support for internationalization.

Currently using RGBA format for compatibility across all render
paths while initial support for R8_UNORM is being added.
This prepares for future optimizations in VRAM and performance

Includes groundwork for gamma-corrected blending and future swizzling support.
2025-05-16 14:57:59 -05:00
vladislavbelov
ffc4a56b9f Revert non-ASCII characters from source and configuration files introduced in 157c6af18e.
Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185
This was SVN commit r27965.
2023-12-03 00:30:12 +00:00
bb
157c6af18e Make the space in 0 A.D. non-breaking throughout the codebase.
Avoid cases of filenames
Update years in terms and other legal(ish) documents
Don't update years in license headers, since change is not meaningful

Will add linter rule in seperate commit

Happy recompiling everyone!

Original Patch By: Nescio
Comment By: Gallaecio
Differential Revision: D2620
This was SVN commit r27786.
2023-07-27 20:54:46 +00:00
bb
7c3aed5f36 Set the size of the overlaybox without relying on the arbitrary initSize
Comments By: vladislav
Differential Revision: D4489
This was SVN commit r26523.
2022-03-02 16:27:11 +00:00
Ykkrosh
b6c7c0d799 Optimise glyph lookup in text renderer
std::map lookup was a major cost when rendering large amounts of text.
Replace it with a more efficient 2-level array.

This was SVN commit r14017.
2013-10-18 15:56:12 +00:00
Ykkrosh
5778484a77 Refactor text renderer
Replace unifont with CFont and CFontManager, since the h_mgr interface
was
needlessly inconvenient.

Load the font textures through CTextureManager, to support dynamic
reloading (e.g. when resetting GL state - see #741).

Add CFontMetrics as a convenient wrapper for code that just wants to
measure text.

Fixes #1117.

This was SVN commit r14016.
2013-10-18 15:53:07 +00:00