summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/texture.cpp11
-rw-r--r--scene/resources/texture.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index ad962a3551..2e0f04ffcb 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1205,6 +1205,17 @@ Ref<Texture> LargeTexture::get_piece_texture(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, pieces.size(), Ref<Texture>());
return pieces[p_idx].texture;
}
+Ref<Image> LargeTexture::to_image() const {
+
+ Ref<Image> img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8));
+ for (int i = 0; i < pieces.size(); i++) {
+
+ Ref<Image> src_img = pieces[i].texture->get_data();
+ img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset);
+ }
+
+ return img;
+}
void LargeTexture::_bind_methods() {
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index cf23aad239..2b67ebec62 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -330,6 +330,7 @@ public:
int get_piece_count() const;
Vector2 get_piece_offset(int p_idx) const;
Ref<Texture> get_piece_texture(int p_idx) const;
+ Ref<Image> to_image() const;
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;