Skip to content

Commit d74580f

Browse files
committed
Implement loading DDS textures at run-time
1 parent 4e4c199 commit d74580f

9 files changed

Lines changed: 507 additions & 357 deletions

File tree

core/io/image.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,7 @@ ImageMemLoadFunc Image::_webp_mem_loader_func = nullptr;
30173017
ImageMemLoadFunc Image::_tga_mem_loader_func = nullptr;
30183018
ImageMemLoadFunc Image::_bmp_mem_loader_func = nullptr;
30193019
ScalableImageMemLoadFunc Image::_svg_scalable_mem_loader_func = nullptr;
3020+
ImageMemLoadFunc Image::_dds_mem_loader_func = nullptr;
30203021

30213022
void (*Image::_image_compress_bc_func)(Image *, Image::UsedChannels) = nullptr;
30223023
void (*Image::_image_compress_bptc_func)(Image *, Image::UsedChannels) = nullptr;
@@ -3488,6 +3489,7 @@ void Image::_bind_methods() {
34883489
ClassDB::bind_method(D_METHOD("load_webp_from_buffer", "buffer"), &Image::load_webp_from_buffer);
34893490
ClassDB::bind_method(D_METHOD("load_tga_from_buffer", "buffer"), &Image::load_tga_from_buffer);
34903491
ClassDB::bind_method(D_METHOD("load_bmp_from_buffer", "buffer"), &Image::load_bmp_from_buffer);
3492+
ClassDB::bind_method(D_METHOD("load_dds_from_buffer", "buffer"), &Image::load_dds_from_buffer);
34913493

34923494
ClassDB::bind_method(D_METHOD("load_svg_from_buffer", "buffer", "scale"), &Image::load_svg_from_buffer, DEFVAL(1.0));
34933495
ClassDB::bind_method(D_METHOD("load_svg_from_string", "svg_str", "scale"), &Image::load_svg_from_string, DEFVAL(1.0));
@@ -3863,6 +3865,14 @@ Error Image::load_svg_from_string(const String &p_svg_str, float scale) {
38633865
return load_svg_from_buffer(p_svg_str.to_utf8_buffer(), scale);
38643866
}
38653867

3868+
Error Image::load_dds_from_buffer(const Vector<uint8_t> &p_array) {
3869+
ERR_FAIL_NULL_V_MSG(
3870+
_dds_mem_loader_func,
3871+
ERR_UNAVAILABLE,
3872+
"The DDS module isn't enabled. Recompile the Godot editor or export template binary with the `module_dds_enabled=yes` SCons option.");
3873+
return _load_from_buffer(p_array, _dds_mem_loader_func);
3874+
}
3875+
38663876
void Image::convert_rg_to_ra_rgba8() {
38673877
ERR_FAIL_COND(format != FORMAT_RGBA8);
38683878
ERR_FAIL_COND(!data.size());

core/io/image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class Image : public Resource {
150150
static ImageMemLoadFunc _tga_mem_loader_func;
151151
static ImageMemLoadFunc _bmp_mem_loader_func;
152152
static ScalableImageMemLoadFunc _svg_scalable_mem_loader_func;
153+
static ImageMemLoadFunc _dds_mem_loader_func;
153154

154155
static void (*_image_compress_bc_func)(Image *, UsedChannels p_channels);
155156
static void (*_image_compress_bptc_func)(Image *, UsedChannels p_channels);
@@ -402,6 +403,7 @@ class Image : public Resource {
402403
Error load_webp_from_buffer(const Vector<uint8_t> &p_array);
403404
Error load_tga_from_buffer(const Vector<uint8_t> &p_array);
404405
Error load_bmp_from_buffer(const Vector<uint8_t> &p_array);
406+
Error load_dds_from_buffer(const Vector<uint8_t> &p_array);
405407

406408
Error load_svg_from_buffer(const Vector<uint8_t> &p_array, float scale = 1.0);
407409
Error load_svg_from_string(const String &p_svg_str, float scale = 1.0);

doc/classes/Image.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@
312312
[b]Note:[/b] Godot's BMP module doesn't support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
313313
</description>
314314
</method>
315+
<method name="load_dds_from_buffer">
316+
<return type="int" enum="Error" />
317+
<param index="0" name="buffer" type="PackedByteArray" />
318+
<description>
319+
Loads an image from the binary contents of a DDS file.
320+
</description>
321+
</method>
315322
<method name="load_from_file" qualifiers="static">
316323
<return type="Image" />
317324
<param index="0" name="path" type="String" />

0 commit comments

Comments
 (0)