Commit Graph

78 Commits

Author SHA1 Message Date
6145b0ca29 Add Image.load_exr_from_buffer and enable tinyexr by default 2025-11-21 18:58:26 +01:00
e14263f917 Remove empty constructors and destructors from core/ 2025-11-17 20:09:05 +01:00
f64ccadceb Image: Support generating mipmaps for all formats 2025-09-24 18:48:28 +02:00
16b9ee6f50 Image: Implement 16-bit unorm and uint formats 2025-06-28 00:30:52 +02:00
873833b4a7 Remove redundant queue_redraw() & fix typo 2025-05-29 17:22:32 +02:00
2a03b459b9 Overhaul Resource::duplicate()
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.

`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).

The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.

This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
2025-05-26 10:05:25 +02:00
237597b01f BasisU: Use KTX2 format and add import options to configure encoder 2025-05-03 01:45:38 +08:00
5af4bef46f Inline static variables (part 1) 2025-04-29 18:10:44 +02:00
e3063f5675 Merge pull request #104590 from bruvzg/tex_decomp_load
Load decompressable texture format if no supported one is found.
2025-03-28 17:30:28 +01:00
649fa630a7 Image: Remove references to defunct FORMAT_CUSTOM 2025-03-26 21:37:26 +01:00
b384de9013 Load decompressable texture format is no supported one found. 2025-03-25 09:46:19 +02:00
69b281295c Add DDS image load and save functionality
Save and load DDS from Image class.

Co-authored-by: BlueCube3310 <53150244+BlueCube3310@users.noreply.github.com>
2025-03-14 19:31:43 -07:00
324512e11c Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
c7a9d64eaf Add color channel filter to editor texture previews 2025-01-11 23:27:48 +00:00
bf9ef5f8a5 Merge pull request #100564 from YYF233333/iwyu
Remove unused headers in core
2024-12-19 19:59:55 -06:00
be86ce3103 Apply iwyu suggestion in core. 2024-12-19 00:43:47 +08:00
240f510fa7 Core ubsan fixes
This fixes UBSAN errors reported by running our testsuite, importing the
TPS demo, and running the TPS demo. I have tried, wherever possible, to
fix issues related to reported issues but not directly reported by UBSAN
because thse code paths just happened to not have been exercised in
these cases.

These fixes apply only to errors reported, and caused by, core/

The following things have been changed:

* Make sure there are no implicit sign changing casts in core.
* Explicitly type enums that are part of a public API such that users of
  the API cannot pass in wrongly-sized values leading to potential stack
  corruption.
* Ensure that memcpy is never called with invalid or null pointers as
  this is undefined behavior, and when the engine is built with
  optimizations turned on leads to memory corruption and hard to debug
  crashes.
* Replace enum values only used as static values with constexpr static
  const values instead. This has no runtime overhead. This makes it so
  that the size of the enums is explicit.
* Make sure that nan and inf is handled consistently in String.
* Implement a _to_int template to ensure that all of the paths use the
  same algorhithm, and correct the negative integer case.
* Changed the way the json serializer precision work, and added tests to
  verify the new behavior. The behavior doesn't quite match master in
  particulary for negative doubles as the original code tried to cast -inf
  to an int. This then led to negative doubles losing all but one of
  their decimal points when serializing. Behavior in GDScript remains
  unchanged.
2024-12-18 14:31:12 +01:00
335077a03f Image: More cleanup and reduced code duplication. 2024-12-12 11:52:59 +01:00
80a9c0d569 Clean up Image 2024-11-01 21:32:16 +01:00
606eedb0c9 Betsy: Add caching and BC1 compression support 2024-09-11 23:48:29 +02:00
76c8211653 Image: Add a method for detecting signed values 2024-08-27 09:23:17 +02:00
4b8946102b Merge pull request #91535 from BlueCube3310/betsy-bc6h
Add Betsy to speed up BC6 compression
2024-08-21 06:38:03 +02:00
f4037d6f6c Merge pull request #92496 from clayjohn/HDR-2D-sRGB
Ensure MovieWriter output is in gamma space when using HDR 2D
2024-08-19 12:08:40 +02:00
394ea653aa Add Betsy to speed up BC6 compression 2024-08-18 11:14:05 +02:00
0ed45629fd Support 64-bit image sizes for VRAM compression 2024-07-21 21:06:14 +02:00
0445ccf428 Fix Image CowData crash when baking large lightmaps
This switches to 64-bit integers in select locations of the Image
class, so that image resolutions of 16384×16384 (used by
lightmap texture arrays) can be used properly. Values that are larger
should also work.

VRAM compression is also supported, although most VRAM-compressed
formats are limited to individual slices of 16384×16384. WebP
is limited to 16383×16383 due to format limitations.
2024-07-19 16:04:30 +02:00
e651421905 [TextServer, GDExtension] Fix building text servers as GDExtension, expose new/changed low-level methods to GDExtension API. 2024-06-12 19:30:19 +03:00
3b9d074fd7 Ensure MovieWriter output is in gamma space when using HDR 2D 2024-05-28 15:30:13 -07:00
8239aeec8e Image: Add static is_format_compressed function. 2024-02-28 19:42:06 +01:00
eac054f1cc Merge pull request #87971 from bruvzg/font_no_image_dup
[TextServer / Font] Do not duplicate images to prevent unnecessary embedding.
2024-02-15 17:35:36 +01:00
19f1d5afa9 [TextServer / Font] Do not duplicate images to prevent unnecessary embedding. 2024-02-05 10:38:32 +02:00
815038962f Improve error reporting in the asset library and in related types
This also makes errors related to asset image loading
verbose-only, because, frankly, users can't do much about
those errors. Spamming them with error messages
about some assets on the frontend being broken
is pointless.
2024-01-26 20:33:22 +01:00
a120f11c1e Give EXR saving methods a default value of false like the bindings 2024-01-10 15:53:40 -06:00
47d991678d Fix lossless formats in PortableCompressedTexture2D
Update scene/resources/portable_compressed_texture.cpp

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
2024-01-05 00:11:01 +05:00
0045dc204c Revert "Implement loading DDS textures at run-time"
This reverts commit 34ab1c8a36.
2023-08-29 14:25:16 +02:00
a00cf02241 Add support for KTX & KTX2 image format
Add support glTF KHR_texture_basisu extension
2023-08-19 10:27:29 +02:00
34ab1c8a36 Implement loading DDS textures at run-time 2023-07-31 21:31:26 +02:00
26eb3db234 Added Image's load_svg_from_(buffer|string)
No core dependency to the svg module.
2023-06-23 00:43:43 -03:00
28f51ba547 Refactor high quality texture import
* Only two texture import modes for low/high quality now:
  * S3TC/BPTC
  * ETC2/ASTC
* Makes sense given this is the general preferred and most compatible combination in most platforms.
* Removed lossy_quality from VRAM texture compression options. It was unused everywhere.
* Added a new "high_quality" option to texture import. When enabled, it uses BPTC/ASTC (BC7/ASTC4x4) instead of S3TC/ETC2 (DXT1-5/ETC2,ETCA).
* Changed MacOS export settings so required texture formats depend on the architecture selected.

This solves the following problems:

* Makes it simpler to import textures as high quality, without having to worry about the specific format used.
* As the editor can now run on platforms such as web, Mac OS with Apple Silicion and Android, it should no longer be assumed that S3TC/BPTC is available by default for it.
2023-01-30 15:53:23 +01:00
d95794ec8a One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +01:00
f318d60e06 Merge pull request #65376 from reduz/astc-support
Implement basic ASTC support
2022-12-20 12:44:30 +01:00
71d21c7ccb Implement basic ASTC support
Implements basic ASTC support:
* Only 4x4 and 8x8 block sizes.
* Other block sizes are too complex to handle for Godot image compression handling. May be implemented sometime in the future.

The need for ASTC is mostly for the following use cases:
* Implement a high quality compression option for textures on mobile and M1 Apple hardware.
* For this, the 4x4 is sufficient, since it uses the same size as BPTC.

ASTC supports a lot of block sizes, but the benefit of supporting most of them is slim, while the implementation complexity in Godot is very high.
Supporting only 4x4 (and 8x8) solves the real problem, which is lack of a BPTC alternative on hardware where it's missing.

Note: This does not yet support encoding on import, an ASTC encoder will need to be added.
2022-12-20 11:26:30 +01:00
ebec23d8d8 ETCPAK expects BGRA data for ETC 2022-12-02 01:34:05 +11:00
ebf86c96e9 Rename Image's get_rect to get_region
Also renames its parameter to from "rect" to "region".
2022-11-01 23:35:48 +01:00
072f6feaba Make some Image methods static 2022-10-14 14:34:15 +02:00
b7e2d45233 Replace Vector2(i) with Size2(i) for methods returning a size 2022-09-01 20:04:17 +02:00
c8cdc10902 Merge pull request #62861 from samdze/image-size-vector2i
Make Image.get_size() return a Vector2i instead of a Vector2
2022-08-08 12:55:07 +02:00
eea14a0edc Merge pull request #63005 from Chaosus/image_rotate
Implement `rotate_90/rotate_180` functions to `Image`
2022-07-19 15:21:16 +02:00
84431bd782 Use integer types in Image and ImageTexture methods
- Image.blit_rect()
- Image.blit_rect_mask()
- Image.blend_rect()
- Image.blend_rect_mask()
- Image.fill_rect()
- Image.get_used_rect()
- Image.get_rect()
- ImageTexture.set_size_override()
2022-07-18 19:43:32 -05:00
7e66903d56 Implement rotate_90/rotate_180 functions to Image 2022-07-15 11:50:42 +03:00