diff options
author | Pablo Andres Fuente <pfuente@heroku.com> | 2024-10-01 23:41:13 -0300 |
---|---|---|
committer | Pablo Andres Fuente <pablo.andres.fuente@gmail.com> | 2024-11-12 08:46:52 -0300 |
commit | eb86670f94ef505e9b4adc37bc0948a3a5588ed8 (patch) | |
tree | 5daa03dd78b80c77820e7e9ae203f909d02e9dab /core/io/file_access.cpp | |
parent | ec6a1c0e792ac8be44990749800a4654a293b9ee (diff) | |
download | redot-engine-eb86670f94ef505e9b4adc37bc0948a3a5588ed8.tar.gz |
Add half precision floating point support to `StreamPeer`
Closes godotengine/godot-proposals#5983
Adds put/get methods to `StreamPeer` that handles half precision
floating point values.
Adds endode/decode half precision floating point to `marshalls`.
Adds `get_half` and `store_half` to `FileAccess`
Co-Authored-By: "Alfonso J. Ramos" <theraot@gmail.com>
Diffstat (limited to 'core/io/file_access.cpp')
-rw-r--r-- | core/io/file_access.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp index d8bf645a7d..01b189f5f2 100644 --- a/core/io/file_access.cpp +++ b/core/io/file_access.cpp @@ -263,6 +263,10 @@ uint64_t FileAccess::get_64() const { return data; } +float FileAccess::get_half() const { + return Math::half_to_float(get_16()); +} + float FileAccess::get_float() const { MarshallFloat m; m.i = get_32(); @@ -522,6 +526,10 @@ void FileAccess::store_real(real_t p_real) { } } +void FileAccess::store_half(float p_dest) { + store_16(Math::make_half_float(p_dest)); +} + void FileAccess::store_float(float p_dest) { MarshallFloat m; m.f = p_dest; @@ -828,6 +836,7 @@ void FileAccess::_bind_methods() { ClassDB::bind_method(D_METHOD("get_16"), &FileAccess::get_16); ClassDB::bind_method(D_METHOD("get_32"), &FileAccess::get_32); ClassDB::bind_method(D_METHOD("get_64"), &FileAccess::get_64); + ClassDB::bind_method(D_METHOD("get_half"), &FileAccess::get_half); ClassDB::bind_method(D_METHOD("get_float"), &FileAccess::get_float); ClassDB::bind_method(D_METHOD("get_double"), &FileAccess::get_double); ClassDB::bind_method(D_METHOD("get_real"), &FileAccess::get_real); @@ -846,6 +855,7 @@ void FileAccess::_bind_methods() { ClassDB::bind_method(D_METHOD("store_16", "value"), &FileAccess::store_16); ClassDB::bind_method(D_METHOD("store_32", "value"), &FileAccess::store_32); ClassDB::bind_method(D_METHOD("store_64", "value"), &FileAccess::store_64); + ClassDB::bind_method(D_METHOD("store_half", "value"), &FileAccess::store_half); ClassDB::bind_method(D_METHOD("store_float", "value"), &FileAccess::store_float); ClassDB::bind_method(D_METHOD("store_double", "value"), &FileAccess::store_double); ClassDB::bind_method(D_METHOD("store_real", "value"), &FileAccess::store_real); |