diff options
author | kobewi <kobewi4e@gmail.com> | 2022-05-04 01:49:20 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-07-08 13:40:47 +0200 |
commit | d2900429e81175a9f48240b180f1d8e3ab52865c (patch) | |
tree | 9a22ed1cd2ecea275dac8e9420d7a1d56c661382 /modules | |
parent | ca18a02e00f7009d084c55b7e9de17df634f3d47 (diff) |
Add static methods for creating Image and ImageTexture
Diffstat (limited to 'modules')
-rw-r--r-- | modules/dds/texture_loader_dds.cpp | 4 | ||||
-rw-r--r-- | modules/gltf/gltf_document.cpp | 20 | ||||
-rw-r--r-- | modules/text_server_adv/text_server_adv.cpp | 16 | ||||
-rw-r--r-- | modules/text_server_fb/text_server_fb.cpp | 16 | ||||
-rw-r--r-- | modules/theora/video_stream_theora.cpp | 2 |
5 files changed, 17 insertions, 41 deletions
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 2c0e604e66..eb5614338b 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -409,9 +409,7 @@ Ref<Resource> ResourceFormatDDS::load(const String &p_path, const String &p_orig } Ref<Image> img = memnew(Image(width, height, mipmaps - 1, info.format, src_data)); - - Ref<ImageTexture> texture = memnew(ImageTexture); - texture->create_from_image(img); + Ref<ImageTexture> texture = ImageTexture::create_from_image(img); if (r_error) { *r_error = OK; diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index e8036098cb..babdc9f33b 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3202,12 +3202,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat state->images.push_back(Ref<Texture2D>()); continue; } - - Ref<ImageTexture> t; - t.instantiate(); - t->create_from_image(img); - - state->images.push_back(t); + state->images.push_back(ImageTexture::create_from_image(img)); } print_verbose("glTF: Total images: " + itos(state->images.size())); @@ -3428,7 +3423,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { } } orm_image->generate_mipmaps(); - orm_texture->create_from_image(orm_image); + orm_texture->set_image(orm_image); GLTFTextureIndex orm_texture_index = -1; if (has_ao || has_roughness || has_metalness) { orm_texture->set_name(material->get_name() + "_orm"); @@ -3476,7 +3471,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { img->set_pixel(x, y, c); } } - tex->create_from_image(img); + tex->set_image(img); } } } @@ -3784,13 +3779,8 @@ void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Re } rm_img->generate_mipmaps(); r_spec_gloss->diffuse_img->generate_mipmaps(); - Ref<ImageTexture> diffuse_image_texture; - diffuse_image_texture.instantiate(); - diffuse_image_texture->create_from_image(r_spec_gloss->diffuse_img); - p_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, diffuse_image_texture); - Ref<ImageTexture> rm_image_texture; - rm_image_texture.instantiate(); - rm_image_texture->create_from_image(rm_img); + p_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, ImageTexture::create_from_image(r_spec_gloss->diffuse_img)); + Ref<ImageTexture> rm_image_texture = ImageTexture::create_from_image(rm_img); if (has_roughness) { p_material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, rm_image_texture); p_material->set_roughness_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_GREEN); diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index fd7636566a..6076b87203 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -2381,9 +2381,7 @@ void TextServerAdvanced::font_set_texture_image(const RID &p_font_rid, const Vec img->generate_mipmaps(); } - tex.texture = Ref<ImageTexture>(); - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); tex.dirty = false; } @@ -2688,8 +2686,7 @@ RID TextServerAdvanced::font_get_glyph_texture_rid(const RID &p_font_rid, const img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } @@ -2728,8 +2725,7 @@ Size2 TextServerAdvanced::font_get_glyph_texture_size(const RID &p_font_rid, con img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } @@ -3060,8 +3056,7 @@ void TextServerAdvanced::font_draw_glyph(const RID &p_font_rid, const RID &p_can img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } @@ -3139,8 +3134,7 @@ void TextServerAdvanced::font_draw_glyph_outline(const RID &p_font_rid, const RI img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 8f57aa339c..7ccc9e3533 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -1493,9 +1493,7 @@ void TextServerFallback::font_set_texture_image(const RID &p_font_rid, const Vec img->generate_mipmaps(); } - tex.texture = Ref<ImageTexture>(); - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); tex.dirty = false; } @@ -1786,8 +1784,7 @@ RID TextServerFallback::font_get_glyph_texture_rid(const RID &p_font_rid, const img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } @@ -1826,8 +1823,7 @@ Size2 TextServerFallback::font_get_glyph_texture_size(const RID &p_font_rid, con img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } @@ -2140,8 +2136,7 @@ void TextServerFallback::font_draw_glyph(const RID &p_font_rid, const RID &p_can img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } @@ -2219,8 +2214,7 @@ void TextServerFallback::font_draw_glyph_outline(const RID &p_font_rid, const RI img->generate_mipmaps(); } if (tex.texture.is_null()) { - tex.texture.instantiate(); - tex.texture->create_from_image(img); + tex.texture = ImageTexture::create_from_image(img); } else { tex.texture->update(img); } diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 77e370849f..c4462ba687 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -331,7 +331,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { Ref<Image> img; img.instantiate(); img->create(w, h, false, Image::FORMAT_RGBA8); - texture->create_from_image(img); + texture->set_image(img); } else { /* tear down the partial theora setup */ |