mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 06:01:14 +00:00
Add static methods for creating Image and ImageTexture
This commit is contained in:
parent
ca18a02e00
commit
d2900429e8
42 changed files with 117 additions and 243 deletions
|
|
@ -2284,6 +2284,21 @@ Error Image::load(const String &p_path) {
|
||||||
return ImageLoader::load_image(p_path, this);
|
return ImageLoader::load_image(p_path, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<Image> Image::load_from_file(const String &p_path) {
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
if (p_path.begins_with("res://") && ResourceLoader::exists(p_path)) {
|
||||||
|
WARN_PRINT("Loaded resource as image file, this will not work on export: '" + p_path + "'. Instead, import the image file as an Image resource and load it normally as a resource.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Ref<Image> image;
|
||||||
|
image.instantiate();
|
||||||
|
Error err = ImageLoader::load_image(p_path, image);
|
||||||
|
if (err != OK) {
|
||||||
|
ERR_FAIL_V_MSG(Ref<Image>(), vformat("Failed to load image. Error %d", err));
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
Error Image::save_png(const String &p_path) const {
|
Error Image::save_png(const String &p_path) const {
|
||||||
if (save_png_func == nullptr) {
|
if (save_png_func == nullptr) {
|
||||||
return ERR_UNAVAILABLE;
|
return ERR_UNAVAILABLE;
|
||||||
|
|
@ -3183,6 +3198,7 @@ void Image::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("is_empty"), &Image::is_empty);
|
ClassDB::bind_method(D_METHOD("is_empty"), &Image::is_empty);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("load", "path"), &Image::load);
|
ClassDB::bind_method(D_METHOD("load", "path"), &Image::load);
|
||||||
|
ClassDB::bind_static_method("Image", D_METHOD("load_from_file", "path"), &Image::load_from_file);
|
||||||
ClassDB::bind_method(D_METHOD("save_png", "path"), &Image::save_png);
|
ClassDB::bind_method(D_METHOD("save_png", "path"), &Image::save_png);
|
||||||
ClassDB::bind_method(D_METHOD("save_png_to_buffer"), &Image::save_png_to_buffer);
|
ClassDB::bind_method(D_METHOD("save_png_to_buffer"), &Image::save_png_to_buffer);
|
||||||
ClassDB::bind_method(D_METHOD("save_jpg", "path", "quality"), &Image::save_jpg, DEFVAL(0.75));
|
ClassDB::bind_method(D_METHOD("save_jpg", "path", "quality"), &Image::save_jpg, DEFVAL(0.75));
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,7 @@ public:
|
||||||
Vector<uint8_t> get_data() const;
|
Vector<uint8_t> get_data() const;
|
||||||
|
|
||||||
Error load(const String &p_path);
|
Error load(const String &p_path);
|
||||||
|
static Ref<Image> load_from_file(const String &p_path);
|
||||||
Error save_png(const String &p_path) const;
|
Error save_png(const String &p_path) const;
|
||||||
Error save_jpg(const String &p_path, float p_quality = 0.75) const;
|
Error save_jpg(const String &p_path, float p_quality = 0.75) const;
|
||||||
Vector<uint8_t> save_png_to_buffer() const;
|
Vector<uint8_t> save_png_to_buffer() const;
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,7 @@
|
||||||
if error != OK:
|
if error != OK:
|
||||||
push_error("Couldn't load the image.")
|
push_error("Couldn't load the image.")
|
||||||
|
|
||||||
var texture = ImageTexture.new()
|
var texture = ImageTexture.create_from_image(image)
|
||||||
texture.create_from_image(image)
|
|
||||||
|
|
||||||
# Display the image in a TextureRect node.
|
# Display the image in a TextureRect node.
|
||||||
var texture_rect = TextureRect.new()
|
var texture_rect = TextureRect.new()
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,13 @@
|
||||||
[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.
|
[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.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="load_from_file" qualifiers="static">
|
||||||
|
<return type="Image" />
|
||||||
|
<argument index="0" name="path" type="String" />
|
||||||
|
<description>
|
||||||
|
Creates a new [Image] and loads data from the specified file.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="load_jpg_from_buffer">
|
<method name="load_jpg_from_buffer">
|
||||||
<return type="int" enum="Error" />
|
<return type="int" enum="Error" />
|
||||||
<argument index="0" name="buffer" type="PackedByteArray" />
|
<argument index="0" name="buffer" type="PackedByteArray" />
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,8 @@
|
||||||
<description>
|
<description>
|
||||||
A [Texture2D] based on an [Image]. For an image to be displayed, an [ImageTexture] has to be created from it using the [method create_from_image] method:
|
A [Texture2D] based on an [Image]. For an image to be displayed, an [ImageTexture] has to be created from it using the [method create_from_image] method:
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var texture = ImageTexture.new()
|
var image = Image.load_from_file("res://icon.png")
|
||||||
var image = Image.new()
|
var texture = ImageTexture.create_from_image(image)
|
||||||
image.load("res://icon.png")
|
|
||||||
texture.create_from_image(image)
|
|
||||||
$Sprite2D.texture = texture
|
$Sprite2D.texture = texture
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
This way, textures can be created at run-time by loading images both from within the editor and externally.
|
This way, textures can be created at run-time by loading images both from within the editor and externally.
|
||||||
|
|
@ -31,11 +29,11 @@
|
||||||
<link title="Importing images">$DOCS_URL/tutorials/assets_pipeline/importing_images.html</link>
|
<link title="Importing images">$DOCS_URL/tutorials/assets_pipeline/importing_images.html</link>
|
||||||
</tutorials>
|
</tutorials>
|
||||||
<methods>
|
<methods>
|
||||||
<method name="create_from_image">
|
<method name="create_from_image" qualifiers="static">
|
||||||
<return type="void" />
|
<return type="ImageTexture" />
|
||||||
<argument index="0" name="image" type="Image" />
|
<argument index="0" name="image" type="Image" />
|
||||||
<description>
|
<description>
|
||||||
Initializes the texture by allocating and setting the data from an [Image].
|
Creates a new [ImageTexture] and initializes it by allocating and setting the data from an [Image].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_format" qualifiers="const">
|
<method name="get_format" qualifiers="const">
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ void EditorProfiler::_update_plot() {
|
||||||
if (graph_texture.is_null()) {
|
if (graph_texture.is_null()) {
|
||||||
graph_texture.instantiate();
|
graph_texture.instantiate();
|
||||||
}
|
}
|
||||||
graph_texture->create_from_image(img);
|
graph_texture->set_image(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
graph_texture->update(img);
|
graph_texture->update(img);
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ void EditorVisualProfiler::_update_plot() {
|
||||||
if (graph_texture.is_null()) {
|
if (graph_texture.is_null()) {
|
||||||
graph_texture.instantiate();
|
graph_texture.instantiate();
|
||||||
}
|
}
|
||||||
graph_texture->create_from_image(img);
|
graph_texture->set_image(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
graph_texture->update(img);
|
graph_texture->update(img);
|
||||||
|
|
|
||||||
|
|
@ -4046,10 +4046,8 @@ Ref<ImageTexture> EditorNode::_load_custom_class_icon(const String &p_path) cons
|
||||||
Ref<Image> img = memnew(Image);
|
Ref<Image> img = memnew(Image);
|
||||||
Error err = ImageLoader::load_image(p_path, img);
|
Error err = ImageLoader::load_image(p_path, img);
|
||||||
if (err == OK) {
|
if (err == OK) {
|
||||||
Ref<ImageTexture> icon = memnew(ImageTexture);
|
|
||||||
img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS);
|
img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS);
|
||||||
icon->create_from_image(img);
|
return ImageTexture::create_from_image(img);
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -5404,9 +5402,7 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
|
||||||
Ref<Image> img = texture->get_image();
|
Ref<Image> img = texture->get_image();
|
||||||
img = img->duplicate();
|
img = img->duplicate();
|
||||||
img->resize(48, 48); // meh
|
img->resize(48, 48); // meh
|
||||||
Ref<ImageTexture> resized_pic = Ref<ImageTexture>(memnew(ImageTexture));
|
preview = ImageTexture::create_from_image(img);
|
||||||
resized_pic->create_from_image(img);
|
|
||||||
preview = resized_pic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drag_preview->set_texture(preview);
|
drag_preview->set_texture(preview);
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,7 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh
|
||||||
Main::iteration();
|
Main::iteration();
|
||||||
Ref<Image> img = RS::get_singleton()->texture_2d_get(viewport_texture);
|
Ref<Image> img = RS::get_singleton()->texture_2d_get(viewport_texture);
|
||||||
ERR_CONTINUE(!img.is_valid() || img->is_empty());
|
ERR_CONTINUE(!img.is_valid() || img->is_empty());
|
||||||
Ref<ImageTexture> it(memnew(ImageTexture));
|
Ref<ImageTexture> it = ImageTexture::create_from_image(img);
|
||||||
it->create_from_image(img);
|
|
||||||
|
|
||||||
RS::get_singleton()->free(inst);
|
RS::get_singleton()->free(inst);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -678,7 +678,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
|
||||||
if (!texture.is_valid()) {
|
if (!texture.is_valid()) {
|
||||||
texture.instantiate();
|
texture.instantiate();
|
||||||
}
|
}
|
||||||
texture->create_from_image(dropped_resource);
|
texture->set_image(dropped_resource);
|
||||||
dropped_resource = texture;
|
dropped_resource = texture;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<
|
||||||
small_image = small_image->duplicate();
|
small_image = small_image->duplicate();
|
||||||
small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC);
|
small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC);
|
||||||
r_small_texture.instantiate();
|
r_small_texture.instantiate();
|
||||||
r_small_texture->create_from_image(small_image);
|
r_small_texture->set_image(small_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -300,14 +300,14 @@ void EditorResourcePreview::_iterate() {
|
||||||
cache_valid = false;
|
cache_valid = false;
|
||||||
} else {
|
} else {
|
||||||
texture.instantiate();
|
texture.instantiate();
|
||||||
texture->create_from_image(img);
|
texture->set_image(img);
|
||||||
|
|
||||||
if (has_small_texture) {
|
if (has_small_texture) {
|
||||||
if (small_img->load(cache_base + "_small.png") != OK) {
|
if (small_img->load(cache_base + "_small.png") != OK) {
|
||||||
cache_valid = false;
|
cache_valid = false;
|
||||||
} else {
|
} else {
|
||||||
small_texture.instantiate();
|
small_texture.instantiate();
|
||||||
small_texture->create_from_image(small_img);
|
small_texture->set_image(small_img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,7 @@ void EditorRunNative::_notification(int p_what) {
|
||||||
im->clear_mipmaps();
|
im->clear_mipmaps();
|
||||||
if (!im->is_empty()) {
|
if (!im->is_empty()) {
|
||||||
im->resize(16 * EDSCALE, 16 * EDSCALE);
|
im->resize(16 * EDSCALE, 16 * EDSCALE);
|
||||||
Ref<ImageTexture> small_icon;
|
Ref<ImageTexture> small_icon = ImageTexture::create_from_image(im);
|
||||||
small_icon.instantiate();
|
|
||||||
small_icon->create_from_image(im);
|
|
||||||
MenuButton *mb = memnew(MenuButton);
|
MenuButton *mb = memnew(MenuButton);
|
||||||
mb->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::run_native), varray(i));
|
mb->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::run_native), varray(i));
|
||||||
mb->connect("pressed", callable_mp(this, &EditorRunNative::run_native), varray(-1, i));
|
mb->connect("pressed", callable_mp(this, &EditorRunNative::run_native), varray(-1, i));
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,6 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false,
|
||||||
return p_texture;
|
return p_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
|
||||||
Ref<Image> img = p_texture->get_image();
|
Ref<Image> img = p_texture->get_image();
|
||||||
ERR_FAIL_NULL_V(img, Ref<Texture2D>());
|
ERR_FAIL_NULL_V(img, Ref<Texture2D>());
|
||||||
img = img->duplicate();
|
img = img->duplicate();
|
||||||
|
|
@ -109,14 +108,12 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false,
|
||||||
img->flip_x();
|
img->flip_x();
|
||||||
}
|
}
|
||||||
|
|
||||||
texture->create_from_image(img);
|
return ImageTexture::create_from_image(img);
|
||||||
return texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MODULE_SVG_ENABLED
|
#ifdef MODULE_SVG_ENABLED
|
||||||
// See also `generate_icon()` in `scene/resources/default_theme.cpp`.
|
// See also `generate_icon()` in `scene/resources/default_theme.cpp`.
|
||||||
static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, float p_saturation = 1.0, Dictionary p_convert_colors = Dictionary()) {
|
static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, float p_saturation = 1.0, Dictionary p_convert_colors = Dictionary()) {
|
||||||
Ref<ImageTexture> icon = memnew(ImageTexture);
|
|
||||||
Ref<Image> img = memnew(Image);
|
Ref<Image> img = memnew(Image);
|
||||||
|
|
||||||
// Upsample icon generation only if the editor scale isn't an integer multiplier.
|
// Upsample icon generation only if the editor scale isn't an integer multiplier.
|
||||||
|
|
@ -129,9 +126,9 @@ static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color,
|
||||||
if (p_saturation != 1.0) {
|
if (p_saturation != 1.0) {
|
||||||
img->adjust_bcs(1.0, 1.0, p_saturation);
|
img->adjust_bcs(1.0, 1.0, p_saturation);
|
||||||
}
|
}
|
||||||
icon->create_from_image(img); // in this case filter really helps
|
|
||||||
|
|
||||||
return icon;
|
// In this case filter really helps.
|
||||||
|
return ImageTexture::create_from_image(img);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,13 +88,7 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St
|
||||||
//use an xpm because it's size independent, the editor images are vector and size dependent
|
//use an xpm because it's size independent, the editor images are vector and size dependent
|
||||||
//it's a simple hack
|
//it's a simple hack
|
||||||
Ref<Image> broken = memnew(Image((const char **)atlas_import_failed_xpm));
|
Ref<Image> broken = memnew(Image((const char **)atlas_import_failed_xpm));
|
||||||
Ref<ImageTexture> broken_texture;
|
ResourceSaver::save(p_save_path + ".tex", ImageTexture::create_from_image(broken));
|
||||||
broken_texture.instantiate();
|
|
||||||
broken_texture->create_from_image(broken);
|
|
||||||
|
|
||||||
String target_file = p_save_path + ".tex";
|
|
||||||
|
|
||||||
ResourceSaver::save(target_file, broken_texture);
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
@ -308,9 +302,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
|
||||||
Ref<Texture2D> cache;
|
Ref<Texture2D> cache;
|
||||||
cache = ResourceCache::get_ref(p_group_file);
|
cache = ResourceCache::get_ref(p_group_file);
|
||||||
if (!cache.is_valid()) {
|
if (!cache.is_valid()) {
|
||||||
Ref<ImageTexture> res_cache;
|
Ref<ImageTexture> res_cache = ImageTexture::create_from_image(new_atlas);
|
||||||
res_cache.instantiate();
|
|
||||||
res_cache->create_from_image(new_atlas);
|
|
||||||
res_cache->set_path(p_group_file);
|
res_cache->set_path(p_group_file);
|
||||||
cache = res_cache;
|
cache = res_cache;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
|
||||||
autoplay_reset_img->blit_rect(autoplay_img, Rect2(Point2(), icon_size), Point2());
|
autoplay_reset_img->blit_rect(autoplay_img, Rect2(Point2(), icon_size), Point2());
|
||||||
autoplay_reset_img->blit_rect(reset_img, Rect2(Point2(), icon_size), Point2(icon_size.x, 0));
|
autoplay_reset_img->blit_rect(reset_img, Rect2(Point2(), icon_size), Point2(icon_size.x, 0));
|
||||||
autoplay_reset_icon.instantiate();
|
autoplay_reset_icon.instantiate();
|
||||||
autoplay_reset_icon->create_from_image(autoplay_reset_img);
|
autoplay_reset_icon->set_image(autoplay_reset_img);
|
||||||
}
|
}
|
||||||
stop->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
|
stop->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,14 +165,9 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const
|
||||||
|
|
||||||
// Overlay and thumbnail need the same format for `blend_rect` to work.
|
// Overlay and thumbnail need the same format for `blend_rect` to work.
|
||||||
thumbnail->convert(Image::FORMAT_RGBA8);
|
thumbnail->convert(Image::FORMAT_RGBA8);
|
||||||
|
|
||||||
thumbnail->blend_rect(overlay, overlay->get_used_rect(), overlay_pos);
|
thumbnail->blend_rect(overlay, overlay->get_used_rect(), overlay_pos);
|
||||||
|
preview_images[i].button->set_icon(ImageTexture::create_from_image(thumbnail));
|
||||||
|
|
||||||
Ref<ImageTexture> tex;
|
|
||||||
tex.instantiate();
|
|
||||||
tex->create_from_image(thumbnail);
|
|
||||||
|
|
||||||
preview_images[i].button->set_icon(tex);
|
|
||||||
// Make it clearer that clicking it will open an external link
|
// Make it clearer that clicking it will open an external link
|
||||||
preview_images[i].button->set_default_cursor_shape(Control::CURSOR_POINTING_HAND);
|
preview_images[i].button->set_default_cursor_shape(Control::CURSOR_POINTING_HAND);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -790,9 +785,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PackedB
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ImageTexture> tex;
|
Ref<ImageTexture> tex = ImageTexture::create_from_image(image);
|
||||||
tex.instantiate();
|
|
||||||
tex->create_from_image(image);
|
|
||||||
|
|
||||||
obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex);
|
obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex);
|
||||||
image_set = true;
|
image_set = true;
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,7 @@
|
||||||
#include "editor/editor_scale.h"
|
#include "editor/editor_scale.h"
|
||||||
|
|
||||||
void BitMapEditor::setup(const Ref<BitMap> &p_bitmap) {
|
void BitMapEditor::setup(const Ref<BitMap> &p_bitmap) {
|
||||||
Ref<ImageTexture> texture;
|
texture_rect->set_texture(ImageTexture::create_from_image(p_bitmap->convert_to_image()));
|
||||||
texture.instantiate();
|
|
||||||
texture->create_from_image(p_bitmap->convert_to_image());
|
|
||||||
texture_rect->set_texture(texture);
|
|
||||||
|
|
||||||
size_label->set_text(vformat(String::utf8("%s×%s"), p_bitmap->get_size().width, p_bitmap->get_size().height));
|
size_label->set_text(vformat(String::utf8("%s×%s"), p_bitmap->get_size().width, p_bitmap->get_size().height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -841,9 +841,5 @@ Ref<Texture2D> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, cons
|
||||||
|
|
||||||
prev_y = y;
|
prev_y = y;
|
||||||
}
|
}
|
||||||
|
return ImageTexture::create_from_image(img_ref);
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
|
||||||
|
|
||||||
ptex->create_from_image(img_ref);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,13 +127,9 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from,
|
||||||
}
|
}
|
||||||
Vector2i new_size_i(MAX(1, (int)new_size.x), MAX(1, (int)new_size.y));
|
Vector2i new_size_i(MAX(1, (int)new_size.x), MAX(1, (int)new_size.y));
|
||||||
img->resize(new_size_i.x, new_size_i.y, Image::INTERPOLATE_CUBIC);
|
img->resize(new_size_i.x, new_size_i.y, Image::INTERPOLATE_CUBIC);
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
|
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
return ImageTexture::create_from_image(img);
|
||||||
|
|
||||||
ptex->create_from_image(img);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() {
|
EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() {
|
||||||
|
|
@ -171,14 +167,9 @@ Ref<Texture2D> EditorImagePreviewPlugin::generate(const Ref<Resource> &p_from, c
|
||||||
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
||||||
}
|
}
|
||||||
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
|
|
||||||
Ref<ImageTexture> ptex;
|
return ImageTexture::create_from_image(img);
|
||||||
ptex.instantiate();
|
|
||||||
|
|
||||||
ptex->create_from_image(img);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorImagePreviewPlugin::EditorImagePreviewPlugin() {
|
EditorImagePreviewPlugin::EditorImagePreviewPlugin() {
|
||||||
|
|
@ -239,13 +230,9 @@ Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const Ref<Resource> &p_from,
|
||||||
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
||||||
}
|
}
|
||||||
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
|
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
return ImageTexture::create_from_image(img);
|
||||||
|
|
||||||
ptex->create_from_image(img);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorBitmapPreviewPlugin::generate_small_preview_automatically() const {
|
bool EditorBitmapPreviewPlugin::generate_small_preview_automatically() const {
|
||||||
|
|
@ -282,11 +269,8 @@ Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String &
|
||||||
img.instantiate();
|
img.instantiate();
|
||||||
Error err = img->load(path);
|
Error err = img->load(path);
|
||||||
if (err == OK) {
|
if (err == OK) {
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
ptex->create_from_image(img);
|
return ImageTexture::create_from_image(img);
|
||||||
return ptex;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Ref<Texture2D>();
|
return Ref<Texture2D>();
|
||||||
|
|
@ -336,9 +320,7 @@ Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const Ref<Resource> &p_from
|
||||||
int thumbnail_size = MAX(p_size.x, p_size.y);
|
int thumbnail_size = MAX(p_size.x, p_size.y);
|
||||||
img->resize(thumbnail_size, thumbnail_size, Image::INTERPOLATE_CUBIC);
|
img->resize(thumbnail_size, thumbnail_size, Image::INTERPOLATE_CUBIC);
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
return ImageTexture::create_from_image(img);
|
||||||
ptex->create_from_image(img);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ref<Texture2D>();
|
return Ref<Texture2D>();
|
||||||
|
|
@ -591,13 +573,8 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const Ref<Resource> &p_from,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
|
return ImageTexture::create_from_image(img);
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
|
||||||
|
|
||||||
ptex->create_from_image(img);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() {
|
EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() {
|
||||||
|
|
@ -676,12 +653,10 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const Ref<Resource> &p_f
|
||||||
|
|
||||||
//post_process_preview(img);
|
//post_process_preview(img);
|
||||||
|
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
|
||||||
Ref<Image> image;
|
Ref<Image> image;
|
||||||
image.instantiate();
|
image.instantiate();
|
||||||
image->create(w, h, false, Image::FORMAT_RGB8, img);
|
image->create(w, h, false, Image::FORMAT_RGB8, img);
|
||||||
ptex->create_from_image(image);
|
return ImageTexture::create_from_image(image);
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorAudioStreamPreviewPlugin::EditorAudioStreamPreviewPlugin() {
|
EditorAudioStreamPreviewPlugin::EditorAudioStreamPreviewPlugin() {
|
||||||
|
|
@ -746,12 +721,9 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const Ref<Resource> &p_from, co
|
||||||
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
||||||
}
|
}
|
||||||
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
|
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
return ImageTexture::create_from_image(img);
|
||||||
ptex->create_from_image(img);
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() {
|
EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() {
|
||||||
|
|
@ -859,13 +831,9 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path,
|
||||||
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
|
||||||
}
|
}
|
||||||
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
|
||||||
|
|
||||||
post_process_preview(img);
|
post_process_preview(img);
|
||||||
|
|
||||||
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
|
return ImageTexture::create_from_image(img);
|
||||||
ptex->create_from_image(img);
|
|
||||||
|
|
||||||
return ptex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Texture2D> EditorFontPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const {
|
Ref<Texture2D> EditorFontPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const {
|
||||||
|
|
@ -915,11 +883,7 @@ Ref<Texture2D> EditorGradientPreviewPlugin::generate(const Ref<Resource> &p_from
|
||||||
ptex.instantiate();
|
ptex.instantiate();
|
||||||
ptex->set_width(p_size.width * GRADIENT_PREVIEW_TEXTURE_SCALE_FACTOR * EDSCALE);
|
ptex->set_width(p_size.width * GRADIENT_PREVIEW_TEXTURE_SCALE_FACTOR * EDSCALE);
|
||||||
ptex->set_gradient(gradient);
|
ptex->set_gradient(gradient);
|
||||||
|
return ImageTexture::create_from_image(ptex->get_image());
|
||||||
Ref<ImageTexture> itex;
|
|
||||||
itex.instantiate();
|
|
||||||
itex->create_from_image(ptex->get_image());
|
|
||||||
return itex;
|
|
||||||
}
|
}
|
||||||
return Ref<Texture2D>();
|
return Ref<Texture2D>();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -299,12 +299,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
|
||||||
|
|
||||||
img.instantiate();
|
img.instantiate();
|
||||||
img->create(w, h, false, Image::FORMAT_RGF, texdata);
|
img->create(w, h, false, Image::FORMAT_RGF, texdata);
|
||||||
|
pm->set_emission_point_texture(ImageTexture::create_from_image(img));
|
||||||
Ref<ImageTexture> imgt;
|
|
||||||
imgt.instantiate();
|
|
||||||
imgt->create_from_image(img);
|
|
||||||
|
|
||||||
pm->set_emission_point_texture(imgt);
|
|
||||||
pm->set_emission_point_count(vpc);
|
pm->set_emission_point_count(vpc);
|
||||||
|
|
||||||
if (capture_colors) {
|
if (capture_colors) {
|
||||||
|
|
@ -320,10 +315,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
|
||||||
|
|
||||||
img.instantiate();
|
img.instantiate();
|
||||||
img->create(w, h, false, Image::FORMAT_RGBA8, colordata);
|
img->create(w, h, false, Image::FORMAT_RGBA8, colordata);
|
||||||
|
pm->set_emission_color_texture(ImageTexture::create_from_image(img));
|
||||||
imgt.instantiate();
|
|
||||||
imgt->create_from_image(img);
|
|
||||||
pm->set_emission_color_texture(imgt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_normals.size()) {
|
if (valid_normals.size()) {
|
||||||
|
|
@ -343,10 +335,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
|
||||||
|
|
||||||
img.instantiate();
|
img.instantiate();
|
||||||
img->create(w, h, false, Image::FORMAT_RGF, normdata);
|
img->create(w, h, false, Image::FORMAT_RGF, normdata);
|
||||||
|
pm->set_emission_normal_texture(ImageTexture::create_from_image(img));
|
||||||
imgt.instantiate();
|
|
||||||
imgt->create_from_image(img);
|
|
||||||
pm->set_emission_normal_texture(imgt);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pm->set_emission_shape(ParticlesMaterial::EMISSION_SHAPE_POINTS);
|
pm->set_emission_shape(ParticlesMaterial::EMISSION_SHAPE_POINTS);
|
||||||
|
|
|
||||||
|
|
@ -363,10 +363,7 @@ void GPUParticles3DEditor::_generate_emission_points() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> image = memnew(Image(w, h, false, Image::FORMAT_RGBF, point_img));
|
Ref<Image> image = memnew(Image(w, h, false, Image::FORMAT_RGBF, point_img));
|
||||||
|
Ref<ImageTexture> tex = ImageTexture::create_from_image(image);
|
||||||
Ref<ImageTexture> tex;
|
|
||||||
tex.instantiate();
|
|
||||||
tex->create_from_image(image);
|
|
||||||
|
|
||||||
Ref<ParticlesMaterial> material = node->get_process_material();
|
Ref<ParticlesMaterial> material = node->get_process_material();
|
||||||
ERR_FAIL_COND(material.is_null());
|
ERR_FAIL_COND(material.is_null());
|
||||||
|
|
@ -392,12 +389,7 @@ void GPUParticles3DEditor::_generate_emission_points() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> image2 = memnew(Image(w, h, false, Image::FORMAT_RGBF, point_img2));
|
Ref<Image> image2 = memnew(Image(w, h, false, Image::FORMAT_RGBF, point_img2));
|
||||||
|
material->set_emission_normal_texture(ImageTexture::create_from_image(image2));
|
||||||
Ref<ImageTexture> tex2;
|
|
||||||
tex2.instantiate();
|
|
||||||
tex2->create_from_image(image2);
|
|
||||||
|
|
||||||
material->set_emission_normal_texture(tex2);
|
|
||||||
} else {
|
} else {
|
||||||
material->set_emission_shape(ParticlesMaterial::EMISSION_SHAPE_POINTS);
|
material->set_emission_shape(ParticlesMaterial::EMISSION_SHAPE_POINTS);
|
||||||
material->set_emission_point_count(point_count);
|
material->set_emission_point_count(point_count);
|
||||||
|
|
|
||||||
|
|
@ -116,12 +116,8 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ImageTexture> output_image_texture;
|
|
||||||
output_image_texture.instantiate();
|
|
||||||
output_image_texture->create_from_image(output_image);
|
|
||||||
|
|
||||||
merged->set_name(p_atlas_sources[0]->get_name());
|
merged->set_name(p_atlas_sources[0]->get_name());
|
||||||
merged->set_texture(output_image_texture);
|
merged->set_texture(ImageTexture::create_from_image(output_image));
|
||||||
merged->set_texture_region_size(new_texture_region_size);
|
merged->set_texture_region_size(new_texture_region_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,12 +121,9 @@ void TilesEditorPlugin::_thread() {
|
||||||
pattern_preview_done.wait();
|
pattern_preview_done.wait();
|
||||||
|
|
||||||
Ref<Image> image = viewport->get_texture()->get_image();
|
Ref<Image> image = viewport->get_texture()->get_image();
|
||||||
Ref<ImageTexture> image_texture;
|
|
||||||
image_texture.instantiate();
|
|
||||||
image_texture->create_from_image(image);
|
|
||||||
|
|
||||||
// Find the index for the given pattern. TODO: optimize.
|
// Find the index for the given pattern. TODO: optimize.
|
||||||
Variant args[] = { item.pattern, image_texture };
|
Variant args[] = { item.pattern, ImageTexture::create_from_image(image) };
|
||||||
const Variant *args_ptr[] = { &args[0], &args[1] };
|
const Variant *args_ptr[] = { &args[0], &args[1] };
|
||||||
Variant r;
|
Variant r;
|
||||||
Callable::CallError error;
|
Callable::CallError error;
|
||||||
|
|
|
||||||
|
|
@ -1167,9 +1167,7 @@ void ProjectList::load_project_icon(int p_index) {
|
||||||
Error err = img->load(item.icon.replace_first("res://", item.path + "/"));
|
Error err = img->load(item.icon.replace_first("res://", item.path + "/"));
|
||||||
if (err == OK) {
|
if (err == OK) {
|
||||||
img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS);
|
img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS);
|
||||||
Ref<ImageTexture> it = memnew(ImageTexture);
|
icon = ImageTexture::create_from_image(img);
|
||||||
it->create_from_image(img);
|
|
||||||
icon = it;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (icon.is_null()) {
|
if (icon.is_null()) {
|
||||||
|
|
|
||||||
|
|
@ -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<Image> img = memnew(Image(width, height, mipmaps - 1, info.format, src_data));
|
||||||
|
Ref<ImageTexture> texture = ImageTexture::create_from_image(img);
|
||||||
Ref<ImageTexture> texture = memnew(ImageTexture);
|
|
||||||
texture->create_from_image(img);
|
|
||||||
|
|
||||||
if (r_error) {
|
if (r_error) {
|
||||||
*r_error = OK;
|
*r_error = OK;
|
||||||
|
|
|
||||||
|
|
@ -3202,12 +3202,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat
|
||||||
state->images.push_back(Ref<Texture2D>());
|
state->images.push_back(Ref<Texture2D>());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
state->images.push_back(ImageTexture::create_from_image(img));
|
||||||
Ref<ImageTexture> t;
|
|
||||||
t.instantiate();
|
|
||||||
t->create_from_image(img);
|
|
||||||
|
|
||||||
state->images.push_back(t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_verbose("glTF: Total images: " + itos(state->images.size()));
|
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_image->generate_mipmaps();
|
||||||
orm_texture->create_from_image(orm_image);
|
orm_texture->set_image(orm_image);
|
||||||
GLTFTextureIndex orm_texture_index = -1;
|
GLTFTextureIndex orm_texture_index = -1;
|
||||||
if (has_ao || has_roughness || has_metalness) {
|
if (has_ao || has_roughness || has_metalness) {
|
||||||
orm_texture->set_name(material->get_name() + "_orm");
|
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);
|
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();
|
rm_img->generate_mipmaps();
|
||||||
r_spec_gloss->diffuse_img->generate_mipmaps();
|
r_spec_gloss->diffuse_img->generate_mipmaps();
|
||||||
Ref<ImageTexture> diffuse_image_texture;
|
p_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, ImageTexture::create_from_image(r_spec_gloss->diffuse_img));
|
||||||
diffuse_image_texture.instantiate();
|
Ref<ImageTexture> rm_image_texture = ImageTexture::create_from_image(rm_img);
|
||||||
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);
|
|
||||||
if (has_roughness) {
|
if (has_roughness) {
|
||||||
p_material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, rm_image_texture);
|
p_material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, rm_image_texture);
|
||||||
p_material->set_roughness_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_GREEN);
|
p_material->set_roughness_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_GREEN);
|
||||||
|
|
|
||||||
|
|
@ -2381,9 +2381,7 @@ void TextServerAdvanced::font_set_texture_image(const RID &p_font_rid, const Vec
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
tex.texture = Ref<ImageTexture>();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture.instantiate();
|
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
tex.dirty = false;
|
tex.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2688,8 +2686,7 @@ RID TextServerAdvanced::font_get_glyph_texture_rid(const RID &p_font_rid, const
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
tex.texture->update(img);
|
||||||
}
|
}
|
||||||
|
|
@ -2728,8 +2725,7 @@ Size2 TextServerAdvanced::font_get_glyph_texture_size(const RID &p_font_rid, con
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
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();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
tex.texture->update(img);
|
||||||
}
|
}
|
||||||
|
|
@ -3139,8 +3134,7 @@ void TextServerAdvanced::font_draw_glyph_outline(const RID &p_font_rid, const RI
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
tex.texture->update(img);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1493,9 +1493,7 @@ void TextServerFallback::font_set_texture_image(const RID &p_font_rid, const Vec
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
tex.texture = Ref<ImageTexture>();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture.instantiate();
|
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
tex.dirty = false;
|
tex.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1786,8 +1784,7 @@ RID TextServerFallback::font_get_glyph_texture_rid(const RID &p_font_rid, const
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
tex.texture->update(img);
|
||||||
}
|
}
|
||||||
|
|
@ -1826,8 +1823,7 @@ Size2 TextServerFallback::font_get_glyph_texture_size(const RID &p_font_rid, con
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
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();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
tex.texture->update(img);
|
||||||
}
|
}
|
||||||
|
|
@ -2219,8 +2214,7 @@ void TextServerFallback::font_draw_glyph_outline(const RID &p_font_rid, const RI
|
||||||
img->generate_mipmaps();
|
img->generate_mipmaps();
|
||||||
}
|
}
|
||||||
if (tex.texture.is_null()) {
|
if (tex.texture.is_null()) {
|
||||||
tex.texture.instantiate();
|
tex.texture = ImageTexture::create_from_image(img);
|
||||||
tex.texture->create_from_image(img);
|
|
||||||
} else {
|
} else {
|
||||||
tex.texture->update(img);
|
tex.texture->update(img);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
|
||||||
Ref<Image> img;
|
Ref<Image> img;
|
||||||
img.instantiate();
|
img.instantiate();
|
||||||
img->create(w, h, false, Image::FORMAT_RGBA8);
|
img->create(w, h, false, Image::FORMAT_RGBA8);
|
||||||
texture->create_from_image(img);
|
texture->set_image(img);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* tear down the partial theora setup */
|
/* tear down the partial theora setup */
|
||||||
|
|
|
||||||
|
|
@ -3118,13 +3118,8 @@ void EditorExportPlatformAndroid::resolve_platform_feature_priorities(const Ref<
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
|
EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
|
||||||
Ref<Image> img = memnew(Image(_android_logo));
|
logo = ImageTexture::create_from_image(memnew(Image(_android_logo)));
|
||||||
logo.instantiate();
|
run_icon = ImageTexture::create_from_image(memnew(Image(_android_run_icon)));
|
||||||
logo->create_from_image(img);
|
|
||||||
|
|
||||||
img = Ref<Image>(memnew(Image(_android_run_icon)));
|
|
||||||
run_icon.instantiate();
|
|
||||||
run_icon->create_from_image(img);
|
|
||||||
|
|
||||||
devices_changed.set();
|
devices_changed.set();
|
||||||
plugins_changed.set();
|
plugins_changed.set();
|
||||||
|
|
|
||||||
|
|
@ -1838,12 +1838,8 @@ bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorExportPlatformIOS::EditorExportPlatformIOS() {
|
EditorExportPlatformIOS::EditorExportPlatformIOS() {
|
||||||
Ref<Image> img = memnew(Image(_iphone_logo));
|
logo = ImageTexture::create_from_image(memnew(Image(_iphone_logo)));
|
||||||
logo.instantiate();
|
|
||||||
logo->create_from_image(img);
|
|
||||||
|
|
||||||
plugins_changed.set();
|
plugins_changed.set();
|
||||||
|
|
||||||
check_for_changes_thread.start(_check_for_changes_poll_thread, this);
|
check_for_changes_thread.start(_check_for_changes_poll_thread, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -661,13 +661,8 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
|
||||||
server.instantiate();
|
server.instantiate();
|
||||||
server_thread.start(_server_thread_poll, this);
|
server_thread.start(_server_thread_poll, this);
|
||||||
|
|
||||||
Ref<Image> img = memnew(Image(_javascript_logo));
|
logo = ImageTexture::create_from_image(memnew(Image(_javascript_logo)));
|
||||||
logo.instantiate();
|
run_icon = ImageTexture::create_from_image(memnew(Image(_javascript_run_icon)));
|
||||||
logo->create_from_image(img);
|
|
||||||
|
|
||||||
img = Ref<Image>(memnew(Image(_javascript_run_icon)));
|
|
||||||
run_icon.instantiate();
|
|
||||||
run_icon->create_from_image(img);
|
|
||||||
|
|
||||||
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
|
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
|
||||||
if (theme.is_valid()) {
|
if (theme.is_valid()) {
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,7 @@
|
||||||
void register_linuxbsd_exporter() {
|
void register_linuxbsd_exporter() {
|
||||||
Ref<EditorExportPlatformLinuxBSD> platform;
|
Ref<EditorExportPlatformLinuxBSD> platform;
|
||||||
platform.instantiate();
|
platform.instantiate();
|
||||||
|
platform->set_logo(ImageTexture::create_from_image(memnew(Image(_linuxbsd_logo))));
|
||||||
Ref<Image> img = memnew(Image(_linuxbsd_logo));
|
|
||||||
Ref<ImageTexture> logo;
|
|
||||||
logo.instantiate();
|
|
||||||
logo->create_from_image(img);
|
|
||||||
platform->set_logo(logo);
|
|
||||||
platform->set_name("Linux/X11");
|
platform->set_name("Linux/X11");
|
||||||
platform->set_extension("x86_32");
|
platform->set_extension("x86_32");
|
||||||
platform->set_extension("x86_64", "binary_format/64_bits");
|
platform->set_extension("x86_64", "binary_format/64_bits");
|
||||||
|
|
|
||||||
|
|
@ -1178,10 +1178,7 @@ Ref<Texture2D> DisplayServerOSX::global_menu_get_item_icon(const String &p_menu_
|
||||||
GodotMenuItem *obj = [menu_item representedObject];
|
GodotMenuItem *obj = [menu_item representedObject];
|
||||||
if (obj) {
|
if (obj) {
|
||||||
if (obj->img.is_valid()) {
|
if (obj->img.is_valid()) {
|
||||||
Ref<ImageTexture> txt;
|
return ImageTexture::create_from_image(obj->img);
|
||||||
txt.instantiate();
|
|
||||||
txt->create_from_image(obj->img);
|
|
||||||
return txt;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
|
||||||
|
|
||||||
if (icon_infos[i].is_png) {
|
if (icon_infos[i].is_png) {
|
||||||
// Encode PNG icon.
|
// Encode PNG icon.
|
||||||
it->create_from_image(copy);
|
it->set_image(copy);
|
||||||
String path = EditorPaths::get_singleton()->get_cache_dir().plus_file("icon.png");
|
String path = EditorPaths::get_singleton()->get_cache_dir().plus_file("icon.png");
|
||||||
ResourceSaver::save(path, it);
|
ResourceSaver::save(path, it);
|
||||||
|
|
||||||
|
|
@ -1666,9 +1666,7 @@ bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorExportPlatformOSX::EditorExportPlatformOSX() {
|
EditorExportPlatformOSX::EditorExportPlatformOSX() {
|
||||||
Ref<Image> img = memnew(Image(_osx_logo));
|
logo = ImageTexture::create_from_image(memnew(Image(_osx_logo)));
|
||||||
logo.instantiate();
|
|
||||||
logo->create_from_image(img);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorExportPlatformOSX::~EditorExportPlatformOSX() {
|
EditorExportPlatformOSX::~EditorExportPlatformOSX() {
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,5 @@ void EditorExportPlatformUWP::resolve_platform_feature_priorities(const Ref<Edit
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorExportPlatformUWP::EditorExportPlatformUWP() {
|
EditorExportPlatformUWP::EditorExportPlatformUWP() {
|
||||||
Ref<Image> img = memnew(Image(_uwp_logo));
|
logo = ImageTexture::create_from_image(memnew(Image(_uwp_logo)));
|
||||||
logo.instantiate();
|
|
||||||
logo->create_from_image(img);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,7 @@ void register_windows_exporter() {
|
||||||
|
|
||||||
Ref<EditorExportPlatformWindows> platform;
|
Ref<EditorExportPlatformWindows> platform;
|
||||||
platform.instantiate();
|
platform.instantiate();
|
||||||
|
platform->set_logo(ImageTexture::create_from_image(memnew(Image(_windows_logo))));
|
||||||
Ref<Image> img = memnew(Image(_windows_logo));
|
|
||||||
Ref<ImageTexture> logo;
|
|
||||||
logo.instantiate();
|
|
||||||
logo->create_from_image(img);
|
|
||||||
platform->set_logo(logo);
|
|
||||||
platform->set_name("Windows Desktop");
|
platform->set_name("Windows Desktop");
|
||||||
platform->set_os_name("Windows");
|
platform->set_os_name("Windows");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ static Ref<StyleBoxFlat> sb_expand(Ref<StyleBoxFlat> p_sbox, float p_left, float
|
||||||
|
|
||||||
// See also `editor_generate_icon()` in `editor/editor_themes.cpp`.
|
// See also `editor_generate_icon()` in `editor/editor_themes.cpp`.
|
||||||
static Ref<ImageTexture> generate_icon(int p_index) {
|
static Ref<ImageTexture> generate_icon(int p_index) {
|
||||||
Ref<ImageTexture> icon = memnew(ImageTexture);
|
|
||||||
Ref<Image> img = memnew(Image);
|
Ref<Image> img = memnew(Image);
|
||||||
|
|
||||||
#ifdef MODULE_SVG_ENABLED
|
#ifdef MODULE_SVG_ENABLED
|
||||||
|
|
@ -87,9 +86,8 @@ static Ref<ImageTexture> generate_icon(int p_index) {
|
||||||
ImageLoaderSVG img_loader;
|
ImageLoaderSVG img_loader;
|
||||||
img_loader.create_image_from_string(img, default_theme_icons_sources[p_index], scale, upsample, false);
|
img_loader.create_image_from_string(img, default_theme_icons_sources[p_index], scale, upsample, false);
|
||||||
#endif
|
#endif
|
||||||
icon->create_from_image(img);
|
|
||||||
|
|
||||||
return icon;
|
return ImageTexture::create_from_image(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
|
static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ void ImageTexture::reload_from_file() {
|
||||||
img.instantiate();
|
img.instantiate();
|
||||||
|
|
||||||
if (ImageLoader::load_image(path, img) == OK) {
|
if (ImageLoader::load_image(path, img) == OK) {
|
||||||
create_from_image(img);
|
set_image(img);
|
||||||
} else {
|
} else {
|
||||||
Resource::reload_from_file();
|
Resource::reload_from_file();
|
||||||
notify_property_list_changed();
|
notify_property_list_changed();
|
||||||
|
|
@ -149,7 +149,7 @@ void ImageTexture::reload_from_file() {
|
||||||
|
|
||||||
bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
|
bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
if (p_name == "image") {
|
if (p_name == "image") {
|
||||||
create_from_image(p_value);
|
set_image(p_value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -167,7 +167,16 @@ void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||||
p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("image"), PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT));
|
p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("image"), PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageTexture::create_from_image(const Ref<Image> &p_image) {
|
Ref<ImageTexture> ImageTexture::create_from_image(const Ref<Image> &p_image) {
|
||||||
|
ERR_FAIL_COND_V_MSG(p_image.is_null() || p_image->is_empty(), Ref<ImageTexture>(), "Invalid image");
|
||||||
|
|
||||||
|
Ref<ImageTexture> image_texture;
|
||||||
|
image_texture.instantiate();
|
||||||
|
image_texture->set_image(p_image);
|
||||||
|
return image_texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageTexture::set_image(const Ref<Image> &p_image) {
|
||||||
ERR_FAIL_COND_MSG(p_image.is_null() || p_image->is_empty(), "Invalid image");
|
ERR_FAIL_COND_MSG(p_image.is_null() || p_image->is_empty(), "Invalid image");
|
||||||
w = p_image->get_width();
|
w = p_image->get_width();
|
||||||
h = p_image->get_height();
|
h = p_image->get_height();
|
||||||
|
|
@ -311,7 +320,7 @@ void ImageTexture::set_path(const String &p_path, bool p_take_over) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageTexture::_bind_methods() {
|
void ImageTexture::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image);
|
ClassDB::bind_static_method("ImageTexture", D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image);
|
||||||
ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format);
|
ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("update", "image"), &ImageTexture::update);
|
ClassDB::bind_method(D_METHOD("update", "image"), &ImageTexture::update);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,8 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void create_from_image(const Ref<Image> &p_image);
|
void set_image(const Ref<Image> &p_image);
|
||||||
|
static Ref<ImageTexture> create_from_image(const Ref<Image> &p_image);
|
||||||
|
|
||||||
Image::Format get_format() const;
|
Image::Format get_format() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1809,11 +1809,8 @@ Vector<Vector<Ref<Texture2D>>> TileSet::generate_terrains_icons(Size2i p_size) {
|
||||||
image->create(1, 1, false, Image::FORMAT_RGBA8);
|
image->create(1, 1, false, Image::FORMAT_RGBA8);
|
||||||
image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain));
|
image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain));
|
||||||
}
|
}
|
||||||
Ref<ImageTexture> icon;
|
Ref<ImageTexture> icon = ImageTexture::create_from_image(image);
|
||||||
icon.instantiate();
|
|
||||||
icon->create_from_image(image);
|
|
||||||
icon->set_size_override(p_size);
|
icon->set_size_override(p_size);
|
||||||
|
|
||||||
output.write[terrain_set].write[terrain] = icon;
|
output.write[terrain_set].write[terrain] = icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4594,7 +4591,7 @@ void TileSetAtlasSource::_update_padded_texture() {
|
||||||
if (!padded_texture.is_valid()) {
|
if (!padded_texture.is_valid()) {
|
||||||
padded_texture.instantiate();
|
padded_texture.instantiate();
|
||||||
}
|
}
|
||||||
padded_texture->create_from_image(image);
|
padded_texture->set_image(image);
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -470,7 +470,7 @@ void VisualShaderNodeParticleMeshEmitter::_update_texture(const Vector<Vector2>
|
||||||
image->set_pixel(i, 0, Color(v.x, v.y, 0));
|
image->set_pixel(i, 0, Color(v.x, v.y, 0));
|
||||||
}
|
}
|
||||||
if (r_texture->get_width() != p_array.size() || p_array.size() == 0) {
|
if (r_texture->get_width() != p_array.size() || p_array.size() == 0) {
|
||||||
r_texture->create_from_image(image);
|
r_texture->set_image(image);
|
||||||
} else {
|
} else {
|
||||||
r_texture->update(image);
|
r_texture->update(image);
|
||||||
}
|
}
|
||||||
|
|
@ -491,7 +491,7 @@ void VisualShaderNodeParticleMeshEmitter::_update_texture(const Vector<Vector3>
|
||||||
image->set_pixel(i, 0, Color(v.x, v.y, v.z));
|
image->set_pixel(i, 0, Color(v.x, v.y, v.z));
|
||||||
}
|
}
|
||||||
if (r_texture->get_width() != p_array.size() || p_array.size() == 0) {
|
if (r_texture->get_width() != p_array.size() || p_array.size() == 0) {
|
||||||
r_texture->create_from_image(image);
|
r_texture->set_image(image);
|
||||||
} else {
|
} else {
|
||||||
r_texture->update(image);
|
r_texture->update(image);
|
||||||
}
|
}
|
||||||
|
|
@ -511,7 +511,7 @@ void VisualShaderNodeParticleMeshEmitter::_update_texture(const Vector<Color> &p
|
||||||
image->set_pixel(i, 0, p_array[i]);
|
image->set_pixel(i, 0, p_array[i]);
|
||||||
}
|
}
|
||||||
if (r_texture->get_width() != p_array.size() || p_array.size() == 0) {
|
if (r_texture->get_width() != p_array.size() || p_array.size() == 0) {
|
||||||
r_texture->create_from_image(image);
|
r_texture->set_image(image);
|
||||||
} else {
|
} else {
|
||||||
r_texture->update(image);
|
r_texture->update(image);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue