diff options
Diffstat (limited to 'scene/resources/texture.cpp')
-rw-r--r-- | scene/resources/texture.cpp | 839 |
1 files changed, 450 insertions, 389 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 749dff24f2..331cffed5d 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -39,7 +39,6 @@ #include "servers/camera/camera_feed.h" Size2 Texture2D::get_size() const { - return Size2(get_width(), get_height()); } @@ -48,28 +47,24 @@ bool Texture2D::is_pixel_opaque(int p_x, int p_y) const { } void Texture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, get_size()), get_rid(), false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void Texture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_rid(), p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void Texture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { - RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, get_rid(), p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { - r_rect = p_rect; r_src_rect = p_src_rect; @@ -77,7 +72,6 @@ bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Re } void Texture2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_width"), &Texture2D::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height); ClassDB::bind_method(D_METHOD("get_size"), &Texture2D::get_size); @@ -96,10 +90,10 @@ Texture2D::Texture2D() { ///////////////////// void ImageTexture::reload_from_file() { - String path = ResourceLoader::path_remap(get_path()); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } Ref<Image> img; img.instance(); @@ -114,43 +108,42 @@ void ImageTexture::reload_from_file() { } bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) { - - if (p_name == "image") + if (p_name == "image") { create_from_image(p_value); - else if (p_name == "size") { + } else if (p_name == "size") { Size2 s = p_value; w = s.width; h = s.height; RenderingServer::get_singleton()->texture_set_size_override(texture, w, h); - } else + } else { return false; + } return true; } bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const { - - if (p_name == "image") + if (p_name == "image") { r_ret = get_data(); - else if (p_name == "size") + } else if (p_name == "size") { r_ret = Size2(w, h); - else + } else { return false; + } return true; } void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "")); } void ImageTexture::_reload_hook(const RID &p_hook) { - String path = get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } Ref<Image> img; img.instance(); @@ -166,7 +159,6 @@ void ImageTexture::_reload_hook(const RID &p_hook) { } void ImageTexture::create_from_image(const Ref<Image> &p_image) { - ERR_FAIL_COND(p_image.is_null()); w = p_image->get_width(); h = p_image->get_height(); @@ -186,12 +178,10 @@ void ImageTexture::create_from_image(const Ref<Image> &p_image) { } Image::Format ImageTexture::get_format() const { - return format; } void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { - ERR_FAIL_COND(p_image.is_null()); ERR_FAIL_COND(texture.is_null()); ERR_FAIL_COND(p_image->get_width() != w || p_image->get_height() != h); @@ -212,12 +202,10 @@ void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { } void ImageTexture::_resource_path_changed() { - String path = get_path(); } Ref<Image> ImageTexture::get_data() const { - if (image_stored) { return RenderingServer::get_singleton()->texture_2d_get(texture); } else { @@ -226,17 +214,14 @@ Ref<Image> ImageTexture::get_data() const { } int ImageTexture::get_width() const { - return w; } int ImageTexture::get_height() const { - return h; } RID ImageTexture::get_rid() const { - if (texture.is_null()) { //we are in trouble, create something temporary texture = RenderingServer::get_singleton()->texture_2d_placeholder_create(); @@ -245,37 +230,37 @@ RID ImageTexture::get_rid() const { } bool ImageTexture::has_alpha() const { - return (format == Image::FORMAT_LA8 || format == Image::FORMAT_RGBA8); } void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if ((w | h) == 0) +void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { - if ((w | h) == 0) +void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { - if (!alpha_cache.is_valid()) { Ref<Image> img = get_data(); if (img.is_valid()) { @@ -290,7 +275,6 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { } if (alpha_cache.is_valid()) { - int aw = int(alpha_cache->get_size().width); int ah = int(alpha_cache->get_size().height); if (aw == 0 || ah == 0) { @@ -310,17 +294,17 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { } void ImageTexture::set_size_override(const Size2 &p_size) { - Size2 s = p_size; - if (s.x != 0) + if (s.x != 0) { w = s.x; - if (s.y != 0) + } + if (s.y != 0) { h = s.y; + } RenderingServer::get_singleton()->texture_set_size_override(texture, w, h); } void ImageTexture::set_path(const String &p_path, bool p_take_over) { - if (texture.is_valid()) { RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -329,7 +313,6 @@ void ImageTexture::set_path(const String &p_path, bool p_take_over) { } void ImageTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image); ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format); @@ -339,7 +322,6 @@ void ImageTexture::_bind_methods() { } ImageTexture::ImageTexture() { - w = h = 0; image_stored = false; mipmaps = false; @@ -347,7 +329,6 @@ ImageTexture::ImageTexture() { } ImageTexture::~ImageTexture() { - if (texture.is_valid()) { RenderingServer::get_singleton()->free(texture); } @@ -355,8 +336,7 @@ ImageTexture::~ImageTexture() { ////////////////////////////////////////// -Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) { - +Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit) { uint32_t data_format = f->get_32(); uint32_t w = f->get_16(); uint32_t h = f->get_16(); @@ -376,7 +356,6 @@ Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) bool first = true; for (uint32_t i = 0; i < mipmaps + 1; i++) { - uint32_t size = f->get_32(); if (p_size_limit > 0 && i < (mipmaps - 1) && (sw > p_size_limit || sh > p_size_limit)) { @@ -444,7 +423,6 @@ Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) int ofs = 0; for (int i = 0; i < mipmap_images.size(); i++) { - Vector<uint8_t> id = mipmap_images[i]->get_data(); int len = id.size(); const uint8_t *r = id.ptr(); @@ -458,7 +436,6 @@ Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) } } else if (data_format == DATA_FORMAT_IMAGE) { - int size = Image::get_image_data_size(w, h, format, mipmaps ? true : false); for (uint32_t i = 0; i < mipmaps + 1; i++) { @@ -492,8 +469,7 @@ Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) return Ref<Image>(); } -void StreamTexture::set_path(const String &p_path, bool p_take_over) { - +void StreamTexture2D::set_path(const String &p_path, bool p_take_over) { if (texture.is_valid()) { RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -501,41 +477,36 @@ void StreamTexture::set_path(const String &p_path, bool p_take_over) { Resource::set_path(p_path, p_take_over); } -void StreamTexture::_requested_3d(void *p_ud) { - - StreamTexture *st = (StreamTexture *)p_ud; - Ref<StreamTexture> stex(st); +void StreamTexture2D::_requested_3d(void *p_ud) { + StreamTexture2D *st = (StreamTexture2D *)p_ud; + Ref<StreamTexture2D> stex(st); ERR_FAIL_COND(!request_3d_callback); request_3d_callback(stex); } -void StreamTexture::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) { - - StreamTexture *st = (StreamTexture *)p_ud; - Ref<StreamTexture> stex(st); +void StreamTexture2D::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) { + StreamTexture2D *st = (StreamTexture2D *)p_ud; + Ref<StreamTexture2D> stex(st); ERR_FAIL_COND(!request_roughness_callback); request_roughness_callback(stex, p_normal_path, p_roughness_channel); } -void StreamTexture::_requested_normal(void *p_ud) { - - StreamTexture *st = (StreamTexture *)p_ud; - Ref<StreamTexture> stex(st); +void StreamTexture2D::_requested_normal(void *p_ud) { + StreamTexture2D *st = (StreamTexture2D *)p_ud; + Ref<StreamTexture2D> stex(st); ERR_FAIL_COND(!request_normal_callback); request_normal_callback(stex); } -StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback = nullptr; -StreamTexture::TextureFormatRoughnessRequestCallback StreamTexture::request_roughness_callback = nullptr; -StreamTexture::TextureFormatRequestCallback StreamTexture::request_normal_callback = nullptr; - -Image::Format StreamTexture::get_format() const { +StreamTexture2D::TextureFormatRequestCallback StreamTexture2D::request_3d_callback = nullptr; +StreamTexture2D::TextureFormatRoughnessRequestCallback StreamTexture2D::request_roughness_callback = nullptr; +StreamTexture2D::TextureFormatRequestCallback StreamTexture2D::request_normal_callback = nullptr; +Image::Format StreamTexture2D::get_format() const { return format; } -Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) { - +Error StreamTexture2D::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) { alpha_cache.unref(); ERR_FAIL_COND_V(image.is_null(), ERR_INVALID_PARAMETER); @@ -595,8 +566,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_ return OK; } -Error StreamTexture::load(const String &p_path) { - +Error StreamTexture2D::load(const String &p_path) { int lw, lh, lwc, lhc; Ref<Image> image; image.instance(); @@ -607,8 +577,9 @@ Error StreamTexture::load(const String &p_path) { int mipmap_limit; Error err = _load_data(p_path, lw, lh, lwc, lhc, image, request_3d, request_normal, request_roughness, mipmap_limit); - if (err) + if (err) { return err; + } if (texture.is_valid()) { RID new_texture = RS::get_singleton()->texture_2d_create(image); @@ -661,59 +632,58 @@ Error StreamTexture::load(const String &p_path) { emit_changed(); return OK; } -String StreamTexture::get_load_path() const { +String StreamTexture2D::get_load_path() const { return path_to_file; } -int StreamTexture::get_width() const { - +int StreamTexture2D::get_width() const { return w; } -int StreamTexture::get_height() const { +int StreamTexture2D::get_height() const { return h; } -RID StreamTexture::get_rid() const { +RID StreamTexture2D::get_rid() const { if (!texture.is_valid()) { texture = RS::get_singleton()->texture_2d_placeholder_create(); } return texture; } -void StreamTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - - if ((w | h) == 0) +void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void StreamTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if ((w | h) == 0) +void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void StreamTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { - if ((w | h) == 0) +void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } -bool StreamTexture::has_alpha() const { - +bool StreamTexture2D::has_alpha() const { return false; } -Ref<Image> StreamTexture::get_data() const { - +Ref<Image> StreamTexture2D::get_data() const { if (texture.is_valid()) { return RS::get_singleton()->texture_2d_get(texture); } else { @@ -721,8 +691,7 @@ Ref<Image> StreamTexture::get_data() const { } } -bool StreamTexture::is_pixel_opaque(int p_x, int p_y) const { - +bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const { if (!alpha_cache.is_valid()) { Ref<Image> img = get_data(); if (img.is_valid()) { @@ -738,7 +707,6 @@ bool StreamTexture::is_pixel_opaque(int p_x, int p_y) const { } if (alpha_cache.is_valid()) { - int aw = int(alpha_cache->get_size().width); int ah = int(alpha_cache->get_size().height); if (aw == 0 || ah == 0) { @@ -757,166 +725,163 @@ bool StreamTexture::is_pixel_opaque(int p_x, int p_y) const { return true; } -void StreamTexture::reload_from_file() { - +void StreamTexture2D::reload_from_file() { String path = get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } path = ResourceLoader::path_remap(path); //remap for translation path = ResourceLoader::import_remap(path); //remap for import - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } load(path); } -void StreamTexture::_validate_property(PropertyInfo &property) const { +void StreamTexture2D::_validate_property(PropertyInfo &property) const { } -void StreamTexture::_bind_methods() { - - ClassDB::bind_method(D_METHOD("load", "path"), &StreamTexture::load); - ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTexture::get_load_path); +void StreamTexture2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("load", "path"), &StreamTexture2D::load); + ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTexture2D::get_load_path); ADD_PROPERTY(PropertyInfo(Variant::STRING, "load_path", PROPERTY_HINT_FILE, "*.stex"), "load", "get_load_path"); } -StreamTexture::StreamTexture() { - +StreamTexture2D::StreamTexture2D() { format = Image::FORMAT_MAX; w = 0; h = 0; } -StreamTexture::~StreamTexture() { - +StreamTexture2D::~StreamTexture2D() { if (texture.is_valid()) { RS::get_singleton()->free(texture); } } -RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { - - Ref<StreamTexture> st; +RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { + Ref<StreamTexture2D> st; st.instance(); Error err = st->load(p_path); - if (r_error) + if (r_error) { *r_error = err; - if (err != OK) + } + if (err != OK) { return RES(); + } return st; } -void ResourceFormatLoaderStreamTexture::get_recognized_extensions(List<String> *p_extensions) const { - +void ResourceFormatLoaderStreamTexture2D::get_recognized_extensions(List<String> *p_extensions) const { p_extensions->push_back("stex"); } -bool ResourceFormatLoaderStreamTexture::handles_type(const String &p_type) const { - return p_type == "StreamTexture"; + +bool ResourceFormatLoaderStreamTexture2D::handles_type(const String &p_type) const { + return p_type == "StreamTexture2D"; } -String ResourceFormatLoaderStreamTexture::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "stex") - return "StreamTexture"; +String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_path) const { + if (p_path.get_extension().to_lower() == "stex") { + return "StreamTexture2D"; + } return ""; } ////////////////////////////////////////// int AtlasTexture::get_width() const { - if (region.size.width == 0) { - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->get_width(); + } return 1; } else { return region.size.width + margin.size.width; } } -int AtlasTexture::get_height() const { +int AtlasTexture::get_height() const { if (region.size.height == 0) { - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->get_height(); + } return 1; } else { return region.size.height + margin.size.height; } } -RID AtlasTexture::get_rid() const { - if (atlas.is_valid()) +RID AtlasTexture::get_rid() const { + if (atlas.is_valid()) { return atlas->get_rid(); + } return RID(); } bool AtlasTexture::has_alpha() const { - - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->has_alpha(); + } return false; } void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) { - ERR_FAIL_COND(p_atlas == this); - if (atlas == p_atlas) + if (atlas == p_atlas) { return; + } atlas = p_atlas; emit_changed(); _change_notify("atlas"); } -Ref<Texture2D> AtlasTexture::get_atlas() const { +Ref<Texture2D> AtlasTexture::get_atlas() const { return atlas; } void AtlasTexture::set_region(const Rect2 &p_region) { - - if (region == p_region) + if (region == p_region) { return; + } region = p_region; emit_changed(); _change_notify("region"); } Rect2 AtlasTexture::get_region() const { - return region; } void AtlasTexture::set_margin(const Rect2 &p_margin) { - - if (margin == p_margin) + if (margin == p_margin) { return; + } margin = p_margin; emit_changed(); _change_notify("margin"); } Rect2 AtlasTexture::get_margin() const { - return margin; } void AtlasTexture::set_filter_clip(const bool p_enable) { - filter_clip = p_enable; emit_changed(); _change_notify("filter_clip"); } bool AtlasTexture::has_filter_clip() const { - return filter_clip; } void AtlasTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_atlas", "atlas"), &AtlasTexture::set_atlas); ClassDB::bind_method(D_METHOD("get_atlas"), &AtlasTexture::get_atlas); @@ -936,9 +901,9 @@ void AtlasTexture::_bind_methods() { } void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return; + } Rect2 rc = region; @@ -956,9 +921,9 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m } void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return; + } Rect2 rc = region; @@ -977,11 +942,12 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); } -void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { //this might not necessarily work well if using a rect, needs to be fixed properly - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return; + } Rect2 dr; Rect2 src_c; @@ -993,9 +959,9 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons } bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { - - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return false; + } Rect2 rc = region; @@ -1007,8 +973,9 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, src.position += (rc.position - margin.position); Rect2 src_c = rc.clip(src); - if (src_c.size == Size2()) + if (src_c.size == Size2()) { return false; + } Vector2 ofs = (src_c.position - src.position); if (scale.x < 0) { @@ -1029,16 +996,20 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, } bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const { - - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return true; + } int x = p_x + region.position.x - margin.position.x; int y = p_y + region.position.y - margin.position.y; // margin edge may outside of atlas - if (x < 0 || x >= atlas->get_width()) return false; - if (y < 0 || y >= atlas->get_height()) return false; + if (x < 0 || x >= atlas->get_width()) { + return false; + } + if (y < 0 || y >= atlas->get_height()) { + return false; + } return atlas->is_pixel_opaque(x, y); } @@ -1052,9 +1023,11 @@ AtlasTexture::AtlasTexture() { int MeshTexture::get_width() const { return size.width; } + int MeshTexture::get_height() const { return size.height; } + RID MeshTexture::get_rid() const { return RID(); } @@ -1066,6 +1039,7 @@ bool MeshTexture::has_alpha() const { void MeshTexture::set_mesh(const Ref<Mesh> &p_mesh) { mesh = p_mesh; } + Ref<Mesh> MeshTexture::get_mesh() const { return mesh; } @@ -1075,7 +1049,6 @@ void MeshTexture::set_image_size(const Size2 &p_size) { } Size2 MeshTexture::get_image_size() const { - return size; } @@ -1088,7 +1061,6 @@ Ref<Texture2D> MeshTexture::get_base_texture() const { } void MeshTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if (mesh.is_null() || base_texture.is_null()) { return; } @@ -1102,6 +1074,7 @@ void MeshTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_mo RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } + void MeshTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if (mesh.is_null() || base_texture.is_null()) { return; @@ -1125,8 +1098,8 @@ void MeshTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void MeshTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void MeshTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { if (mesh.is_null() || base_texture.is_null()) { return; } @@ -1149,6 +1122,7 @@ void MeshTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } + bool MeshTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { r_rect = p_rect; r_src_rect = p_src_rect; @@ -1178,30 +1152,28 @@ MeshTexture::MeshTexture() { ////////////////////////////////////////// int LargeTexture::get_width() const { - return size.width; } -int LargeTexture::get_height() const { +int LargeTexture::get_height() const { return size.height; } -RID LargeTexture::get_rid() const { +RID LargeTexture::get_rid() const { return RID(); } bool LargeTexture::has_alpha() const { - for (int i = 0; i < pieces.size(); i++) { - if (pieces[i].texture->has_alpha()) + if (pieces[i].texture->has_alpha()) { return true; + } } return false; } int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND_V(p_texture.is_null(), -1); Piece p; p.offset = p_offset; @@ -1212,13 +1184,11 @@ int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture2D> &p_text } void LargeTexture::set_piece_offset(int p_idx, const Point2 &p_offset) { - ERR_FAIL_INDEX(p_idx, pieces.size()); pieces.write[p_idx].offset = p_offset; }; void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND(p_texture == this); ERR_FAIL_COND(p_texture.is_null()); ERR_FAIL_INDEX(p_idx, pieces.size()); @@ -1226,17 +1196,15 @@ void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture2D> &p_texture) }; void LargeTexture::set_size(const Size2 &p_size) { - size = p_size; } -void LargeTexture::clear() { +void LargeTexture::clear() { pieces.clear(); size = Size2i(); } Array LargeTexture::_get_data() const { - Array arr; for (int i = 0; i < pieces.size(); i++) { arr.push_back(pieces[i].offset); @@ -1245,8 +1213,8 @@ Array LargeTexture::_get_data() const { arr.push_back(Size2(size)); return arr; } -void LargeTexture::_set_data(const Array &p_array) { +void LargeTexture::_set_data(const Array &p_array) { ERR_FAIL_COND(p_array.size() < 1); ERR_FAIL_COND(!(p_array.size() & 1)); clear(); @@ -1257,24 +1225,22 @@ void LargeTexture::_set_data(const Array &p_array) { } int LargeTexture::get_piece_count() const { - return pieces.size(); } -Vector2 LargeTexture::get_piece_offset(int p_idx) const { +Vector2 LargeTexture::get_piece_offset(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, pieces.size(), Vector2()); return pieces[p_idx].offset; } -Ref<Texture2D> LargeTexture::get_piece_texture(int p_idx) const { +Ref<Texture2D> LargeTexture::get_piece_texture(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, pieces.size(), Ref<Texture2D>()); return pieces[p_idx].texture; } -Ref<Image> LargeTexture::to_image() const { +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); } @@ -1283,7 +1249,6 @@ Ref<Image> LargeTexture::to_image() const { } void LargeTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_piece", "ofs", "texture"), &LargeTexture::add_piece); ClassDB::bind_method(D_METHOD("set_piece_offset", "idx", "ofs"), &LargeTexture::set_piece_offset); ClassDB::bind_method(D_METHOD("set_piece_texture", "idx", "texture"), &LargeTexture::set_piece_texture); @@ -1301,42 +1266,40 @@ void LargeTexture::_bind_methods() { } void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - for (int i = 0; i < pieces.size(); i++) { - // TODO pieces[i].texture->draw(p_canvas_item, pieces[i].offset + p_pos, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } } void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - //tiling not supported for this - if (size.x == 0 || size.y == 0) + if (size.x == 0 || size.y == 0) { return; + } Size2 scale = p_rect.size / size; for (int i = 0; i < pieces.size(); i++) { - // TODO pieces[i].texture->draw_rect(p_canvas_item, Rect2(pieces[i].offset * scale + p_rect.position, pieces[i].texture->get_size() * scale), false, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } } -void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { //tiling not supported for this - if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0) + if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0) { return; + } Size2 scale = p_rect.size / p_src_rect.size; for (int i = 0; i < pieces.size(); i++) { - // TODO Rect2 rect(pieces[i].offset, pieces[i].texture->get_size()); - if (!p_src_rect.intersects(rect)) + if (!p_src_rect.intersects(rect)) { continue; + } Rect2 local = p_src_rect.clip(rect); Rect2 target = local; target.size *= scale; @@ -1347,12 +1310,11 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons } bool LargeTexture::is_pixel_opaque(int p_x, int p_y) const { - for (int i = 0; i < pieces.size(); i++) { - // TODO - if (!pieces[i].texture.is_valid()) + if (!pieces[i].texture.is_valid()) { continue; + } Rect2 rect(pieces[i].offset, pieces[i].texture->get_size()); if (rect.has_point(Point2(p_x, p_y))) { @@ -1369,7 +1331,6 @@ LargeTexture::LargeTexture() { /////////////////// void CurveTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_width", "width"), &CurveTexture::set_width); ClassDB::bind_method(D_METHOD("set_curve", "curve"), &CurveTexture::set_curve); @@ -1382,14 +1343,12 @@ void CurveTexture::_bind_methods() { } void CurveTexture::set_width(int p_width) { - ERR_FAIL_COND(p_width < 32 || p_width > 4096); _width = p_width; _update(); } int CurveTexture::get_width() const { - return _width; } @@ -1419,7 +1378,6 @@ void CurveTexture::set_curve(Ref<Curve> p_curve) { } void CurveTexture::_update() { - Vector<uint8_t> data; data.resize(_width * sizeof(float)); @@ -1455,12 +1413,10 @@ void CurveTexture::_update() { } Ref<Curve> CurveTexture::get_curve() const { - return _curve; } RID CurveTexture::get_rid() const { - if (!_texture.is_valid()) { _texture = RS::get_singleton()->texture_2d_placeholder_create(); } @@ -1470,11 +1426,13 @@ RID CurveTexture::get_rid() const { CurveTexture::CurveTexture() { _width = 2048; } + CurveTexture::~CurveTexture() { if (_texture.is_valid()) { RS::get_singleton()->free(_texture); } } + ////////////////// //setter and getter names for property serialization @@ -1497,7 +1455,6 @@ GradientTexture::~GradientTexture() { } void GradientTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_gradient", "gradient"), &GradientTexture::set_gradient); ClassDB::bind_method(D_METHOD("get_gradient"), &GradientTexture::get_gradient); @@ -1510,8 +1467,9 @@ void GradientTexture::_bind_methods() { } void GradientTexture::set_gradient(Ref<Gradient> p_gradient) { - if (p_gradient == gradient) + if (p_gradient == gradient) { return; + } if (gradient.is_valid()) { gradient->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &GradientTexture::_update)); } @@ -1528,20 +1486,20 @@ Ref<Gradient> GradientTexture::get_gradient() const { } void GradientTexture::_queue_update() { - - if (update_pending) + if (update_pending) { return; + } update_pending = true; call_deferred("_update"); } void GradientTexture::_update() { - update_pending = false; - if (gradient.is_null()) + if (gradient.is_null()) { return; + } Vector<uint8_t> data; data.resize(width * 4); @@ -1550,7 +1508,6 @@ void GradientTexture::_update() { Gradient &g = **gradient; for (int i = 0; i < width; i++) { - float ofs = float(i) / (width - 1); Color color = g.get_color_at_offset(ofs); @@ -1574,12 +1531,11 @@ void GradientTexture::_update() { } void GradientTexture::set_width(int p_width) { - width = p_width; _queue_update(); } -int GradientTexture::get_width() const { +int GradientTexture::get_width() const { return width; } @@ -1593,7 +1549,6 @@ Ref<Image> GradientTexture::get_data() const { ////////////////////////////////////// void ProxyTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base", "base"), &ProxyTexture::set_base); ClassDB::bind_method(D_METHOD("get_base"), &ProxyTexture::get_base); @@ -1601,7 +1556,6 @@ void ProxyTexture::_bind_methods() { } void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND(p_texture == this); base = p_texture; @@ -1619,24 +1573,24 @@ void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) { } Ref<Texture2D> ProxyTexture::get_base() const { - return base; } int ProxyTexture::get_width() const { - - if (base.is_valid()) + if (base.is_valid()) { return base->get_width(); + } return 1; } -int ProxyTexture::get_height() const { - if (base.is_valid()) +int ProxyTexture::get_height() const { + if (base.is_valid()) { return base->get_height(); + } return 1; } -RID ProxyTexture::get_rid() const { +RID ProxyTexture::get_rid() const { if (proxy.is_null()) { proxy_ph = RS::get_singleton()->texture_2d_placeholder_create(); proxy = RS::get_singleton()->texture_proxy_create(proxy_ph); @@ -1645,19 +1599,17 @@ RID ProxyTexture::get_rid() const { } bool ProxyTexture::has_alpha() const { - - if (base.is_valid()) + if (base.is_valid()) { return base->has_alpha(); + } return false; } ProxyTexture::ProxyTexture() { - //proxy = RS::get_singleton()->texture_create(); } ProxyTexture::~ProxyTexture() { - if (proxy_ph.is_valid()) { RS::get_singleton()->free(proxy_ph); } @@ -1665,10 +1617,10 @@ ProxyTexture::~ProxyTexture() { RS::get_singleton()->free(proxy); } } + ////////////////////////////////////////////// void AnimatedTexture::_update_proxy() { - RWLockRead r(rw_lock); float delta; @@ -1692,15 +1644,20 @@ void AnimatedTexture::_update_proxy() { } int iter_max = frame_count; - while (iter_max) { + while (iter_max && !pause) { float frame_limit = limit + frames[current_frame].delay_sec; if (time > frame_limit) { current_frame++; if (current_frame >= frame_count) { - current_frame = 0; + if (oneshot) { + current_frame = frame_count - 1; + } else { + current_frame = 0; + } } time -= frame_limit; + _change_notify("current_frame"); } else { break; } @@ -1719,12 +1676,42 @@ void AnimatedTexture::set_frames(int p_frames) { frame_count = p_frames; } + int AnimatedTexture::get_frames() const { return frame_count; } -void AnimatedTexture::set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture) { +void AnimatedTexture::set_current_frame(int p_frame) { + ERR_FAIL_COND(p_frame < 0 || p_frame >= frame_count); + + RWLockWrite r(rw_lock); + + current_frame = p_frame; +} + +int AnimatedTexture::get_current_frame() const { + return current_frame; +} +void AnimatedTexture::set_pause(bool p_pause) { + RWLockWrite r(rw_lock); + pause = p_pause; +} + +bool AnimatedTexture::get_pause() const { + return pause; +} + +void AnimatedTexture::set_oneshot(bool p_oneshot) { + RWLockWrite r(rw_lock); + oneshot = p_oneshot; +} + +bool AnimatedTexture::get_oneshot() const { + return oneshot; +} + +void AnimatedTexture::set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture) { ERR_FAIL_COND(p_texture == this); ERR_FAIL_INDEX(p_frame, MAX_FRAMES); @@ -1732,6 +1719,7 @@ void AnimatedTexture::set_frame_texture(int p_frame, const Ref<Texture2D> &p_tex frames[p_frame].texture = p_texture; } + Ref<Texture2D> AnimatedTexture::get_frame_texture(int p_frame) const { ERR_FAIL_INDEX_V(p_frame, MAX_FRAMES, Ref<Texture2D>()); @@ -1747,6 +1735,7 @@ void AnimatedTexture::set_frame_delay(int p_frame, float p_delay_sec) { frames[p_frame].delay_sec = p_delay_sec; } + float AnimatedTexture::get_frame_delay(int p_frame) const { ERR_FAIL_INDEX_V(p_frame, MAX_FRAMES, 0); @@ -1760,6 +1749,7 @@ void AnimatedTexture::set_fps(float p_fps) { fps = p_fps; } + float AnimatedTexture::get_fps() const { return fps; } @@ -1773,6 +1763,7 @@ int AnimatedTexture::get_width() const { return frames[current_frame].texture->get_width(); } + int AnimatedTexture::get_height() const { RWLockRead r(rw_lock); @@ -1782,12 +1773,12 @@ int AnimatedTexture::get_height() const { return frames[current_frame].texture->get_height(); } + RID AnimatedTexture::get_rid() const { return proxy; } bool AnimatedTexture::has_alpha() const { - RWLockRead r(rw_lock); if (!frames[current_frame].texture.is_valid()) { @@ -1798,7 +1789,6 @@ bool AnimatedTexture::has_alpha() const { } Ref<Image> AnimatedTexture::get_data() const { - RWLockRead r(rw_lock); if (!frames[current_frame].texture.is_valid()) { @@ -1809,7 +1799,6 @@ Ref<Image> AnimatedTexture::get_data() const { } bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const { - RWLockRead r(rw_lock); if (frames[current_frame].texture.is_valid()) { @@ -1819,7 +1808,6 @@ bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const { } void AnimatedTexture::_validate_property(PropertyInfo &property) const { - String prop = property.name; if (prop.begins_with("frame_")) { int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); @@ -1833,6 +1821,15 @@ void AnimatedTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_frames", "frames"), &AnimatedTexture::set_frames); ClassDB::bind_method(D_METHOD("get_frames"), &AnimatedTexture::get_frames); + ClassDB::bind_method(D_METHOD("set_current_frame", "frame"), &AnimatedTexture::set_current_frame); + ClassDB::bind_method(D_METHOD("get_current_frame"), &AnimatedTexture::get_current_frame); + + ClassDB::bind_method(D_METHOD("set_pause", "pause"), &AnimatedTexture::set_pause); + ClassDB::bind_method(D_METHOD("get_pause"), &AnimatedTexture::get_pause); + + ClassDB::bind_method(D_METHOD("set_oneshot", "oneshot"), &AnimatedTexture::set_oneshot); + ClassDB::bind_method(D_METHOD("get_oneshot"), &AnimatedTexture::get_oneshot); + ClassDB::bind_method(D_METHOD("set_fps", "fps"), &AnimatedTexture::set_fps); ClassDB::bind_method(D_METHOD("get_fps"), &AnimatedTexture::get_fps); @@ -1843,6 +1840,9 @@ void AnimatedTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("get_frame_delay", "frame"), &AnimatedTexture::get_frame_delay); ADD_PROPERTY(PropertyInfo(Variant::INT, "frames", PROPERTY_HINT_RANGE, "1," + itos(MAX_FRAMES), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_frames", "get_frames"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "current_frame", PROPERTY_HINT_NONE, "", 0), "set_current_frame", "get_current_frame"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pause"), "set_pause", "get_pause"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "oneshot"), "set_oneshot", "get_oneshot"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fps", PROPERTY_HINT_RANGE, "0,1024,0.1"), "set_fps", "get_fps"); for (int i = 0; i < MAX_FRAMES; i++) { @@ -1864,6 +1864,8 @@ AnimatedTexture::AnimatedTexture() { fps = 4; prev_ticks = 0; current_frame = 0; + pause = false; + oneshot = false; RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy)); #ifndef NO_THREADS @@ -1880,25 +1882,49 @@ AnimatedTexture::~AnimatedTexture() { memdelete(rw_lock); } } + /////////////////////////////// -Image::Format TextureLayered::get_format() const { +void TextureLayered::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_format"), &TextureLayered::get_format); + ClassDB::bind_method(D_METHOD("get_layered_type"), &TextureLayered::get_layered_type); + ClassDB::bind_method(D_METHOD("get_width"), &TextureLayered::get_width); + ClassDB::bind_method(D_METHOD("get_height"), &TextureLayered::get_height); + ClassDB::bind_method(D_METHOD("get_layers"), &TextureLayered::get_layers); + ClassDB::bind_method(D_METHOD("has_mipmaps"), &TextureLayered::has_mipmaps); + ClassDB::bind_method(D_METHOD("get_layer_data", "layer"), &TextureLayered::get_layer_data); + + BIND_ENUM_CONSTANT(LAYERED_TYPE_2D_ARRAY); + BIND_ENUM_CONSTANT(LAYERED_TYPE_CUBEMAP); + BIND_ENUM_CONSTANT(LAYERED_TYPE_CUBEMAP_ARRAY); +} + +/////////////////////////////// +Image::Format ImageTextureLayered::get_format() const { return format; } -uint32_t TextureLayered::get_width() const { +int ImageTextureLayered::get_width() const { return width; } -uint32_t TextureLayered::get_height() const { +int ImageTextureLayered::get_height() const { return height; } -uint32_t TextureLayered::get_layers() const { +int ImageTextureLayered::get_layers() const { return layers; } -Error TextureLayered::_create_from_images(const Array &p_images) { +bool ImageTextureLayered::has_mipmaps() const { + return mipmaps; +} + +ImageTextureLayered::LayeredType ImageTextureLayered::get_layered_type() const { + return layered_type; +} + +Error ImageTextureLayered::_create_from_images(const Array &p_images) { Vector<Ref<Image>> images; for (int i = 0; i < p_images.size(); i++) { Ref<Image> img = p_images[i]; @@ -1909,7 +1935,7 @@ Error TextureLayered::_create_from_images(const Array &p_images) { return create_from_images(images); } -Array TextureLayered::_get_images() const { +Array ImageTextureLayered::_get_images() const { Array images; for (int i = 0; i < layers; i++) { images.push_back(get_layer_data(i)); @@ -1917,14 +1943,13 @@ Array TextureLayered::_get_images() const { return images; } -Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) { - +Error ImageTextureLayered::create_from_images(Vector<Ref<Image>> p_images) { int new_layers = p_images.size(); ERR_FAIL_COND_V(new_layers == 0, ERR_INVALID_PARAMETER); - if (layered_type == RS::TEXTURE_LAYERED_CUBEMAP) { + if (layered_type == LAYERED_TYPE_CUBEMAP) { ERR_FAIL_COND_V_MSG(new_layers != 6, ERR_INVALID_PARAMETER, "Cubemaps require exactly 6 layers"); - } else if (layered_type == RS::TEXTURE_LAYERED_CUBEMAP_ARRAY) { + } else if (layered_type == LAYERED_TYPE_CUBEMAP_ARRAY) { ERR_FAIL_COND_V_MSG((new_layers % 6) != 0, ERR_INVALID_PARAMETER, "Cubemap array layers must be a multiple of 6"); } @@ -1946,11 +1971,11 @@ Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) { } if (texture.is_valid()) { - RID new_texture = RS::get_singleton()->texture_2d_layered_create(p_images, layered_type); + RID new_texture = RS::get_singleton()->texture_2d_layered_create(p_images, RS::TextureLayeredType(layered_type)); ERR_FAIL_COND_V(!new_texture.is_valid(), ERR_CANT_CREATE); RS::get_singleton()->texture_replace(texture, new_texture); } else { - texture = RS::get_singleton()->texture_2d_layered_create(p_images, layered_type); + texture = RS::get_singleton()->texture_2d_layered_create(p_images, RS::TextureLayeredType(layered_type)); ERR_FAIL_COND_V(!texture.is_valid(), ERR_CANT_CREATE); } @@ -1962,7 +1987,7 @@ Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) { return OK; } -void TextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) { +void ImageTextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) { ERR_FAIL_COND(texture.is_valid()); ERR_FAIL_COND(p_image.is_null()); ERR_FAIL_COND(p_image->get_format() != format); @@ -1972,19 +1997,19 @@ void TextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) { RS::get_singleton()->texture_2d_update(texture, p_image, p_layer); } -Ref<Image> TextureLayered::get_layer_data(int p_layer) const { +Ref<Image> ImageTextureLayered::get_layer_data(int p_layer) const { ERR_FAIL_INDEX_V(p_layer, layers, Ref<Image>()); return RS::get_singleton()->texture_2d_layer_get(texture, p_layer); } -RID TextureLayered::get_rid() const { +RID ImageTextureLayered::get_rid() const { if (texture.is_null()) { - texture = RS::get_singleton()->texture_2d_layered_placeholder_create(); + texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type)); } return texture; } -void TextureLayered::set_path(const String &p_path, bool p_take_over) { +void ImageTextureLayered::set_path(const String &p_path, bool p_take_over) { if (texture.is_valid()) { RS::get_singleton()->texture_set_path(texture, p_path); } @@ -1992,24 +2017,16 @@ void TextureLayered::set_path(const String &p_path, bool p_take_over) { Resource::set_path(p_path, p_take_over); } -void TextureLayered::_bind_methods() { +void ImageTextureLayered::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_from_images", "images"), &ImageTextureLayered::_create_from_images); + ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &ImageTextureLayered::update_layer); - ClassDB::bind_method(D_METHOD("get_format"), &TextureLayered::get_format); - - ClassDB::bind_method(D_METHOD("get_width"), &TextureLayered::get_width); - ClassDB::bind_method(D_METHOD("get_height"), &TextureLayered::get_height); - ClassDB::bind_method(D_METHOD("get_layers"), &TextureLayered::get_layers); - - ClassDB::bind_method(D_METHOD("create_from_images", "images"), &TextureLayered::_create_from_images); - ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &TextureLayered::update_layer); - ClassDB::bind_method(D_METHOD("get_layer_data", "layer"), &TextureLayered::get_layer_data); - - ClassDB::bind_method(D_METHOD("_get_images"), &TextureLayered::_get_images); + ClassDB::bind_method(D_METHOD("_get_images"), &ImageTextureLayered::_get_images); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_INTERNAL), "create_from_images", "_get_images"); } -TextureLayered::TextureLayered(RenderingServer::TextureLayeredType p_layered_type) { +ImageTextureLayered::ImageTextureLayered(LayeredType p_layered_type) { layered_type = p_layered_type; format = Image::FORMAT_MAX; @@ -2018,193 +2035,237 @@ TextureLayered::TextureLayered(RenderingServer::TextureLayeredType p_layered_typ layers = 0; } -TextureLayered::~TextureLayered() { +ImageTextureLayered::~ImageTextureLayered() { if (texture.is_valid()) { RS::get_singleton()->free(texture); } } -RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +/////////////////////////////////////////// - if (r_error) { - *r_error = ERR_CANT_OPEN; - } - - Ref<TextureLayered> lt; - - if (p_path.ends_with("cube")) { - Ref<Cubemap> cube; - cube.instance(); - lt = cube; - } else if (p_path.ends_with("cubearr")) { - Ref<CubemapArray> cubearr; - cubearr.instance(); - lt = cubearr; - } else if (p_path.ends_with("tex2darr")) { - Ref<Texture2DArray> t2darr; - t2darr.instance(); - lt = t2darr; - } else { - ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture extension."); +void StreamTextureLayered::set_path(const String &p_path, bool p_take_over) { + if (texture.is_valid()) { + RenderingServer::get_singleton()->texture_set_path(texture, p_path); } - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'."); + Resource::set_path(p_path, p_take_over); +} - char header[5] = { 0, 0, 0, 0, 0 }; - f->get_buffer((uint8_t *)header, 4); +Image::Format StreamTextureLayered::get_format() const { + return format; +} - if (String(header) != "GDLT") { - f->close(); - memdelete(f); - if (r_error) { - *r_error = ERR_FILE_CORRUPT; - } - // FIXME: It's bogus that we fail in both branches. Seen while rebasing - // vulkan branch on master branch. - ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture."); - } else { +Error StreamTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit) { + ERR_FAIL_COND_V(images.size() != 0, ERR_INVALID_PARAMETER); - f->close(); - memdelete(f); - ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format '" + String((const char *)header) + "'."); + FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); + ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + + uint8_t header[4]; + f->get_buffer(header, 4); + if (header[0] != 'G' || header[1] != 'S' || header[2] != 'T' || header[3] != 'L') { + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Stream texture layered file is corrupt (Bad header)."); } - int tw = f->get_32(); - int th = f->get_32(); - int td = f->get_32(); - bool use_mipmaps = f->get_32() != 0; //texture flags (deprecated) - Image::Format format = Image::Format(f->get_32()); - uint32_t compression = f->get_32(); // 0 - lossless (PNG), 1 - vram, 2 - uncompressed + uint32_t version = f->get_32(); - Vector<Ref<Image>> images; - for (int layer = 0; layer < td; layer++) { + if (version > FORMAT_VERSION) { + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Stream texture file is too new."); + } - Ref<Image> image; - image.instance(); + uint32_t layer_count = f->get_32(); //layer count + uint32_t type = f->get_32(); //layer count + ERR_FAIL_COND_V(type != layered_type, ERR_INVALID_DATA); - if (compression == COMPRESSION_LOSSLESS) { - //look for a PNG file inside + uint32_t df = f->get_32(); //data format + mipmap_limit = int(f->get_32()); + //reserverd + f->get_32(); + f->get_32(); + f->get_32(); - int mipmaps = f->get_32(); - Vector<Ref<Image>> mipmap_images; + if (!(df & FORMAT_BIT_STREAM)) { + p_size_limit = 0; + } - for (int i = 0; i < mipmaps; i++) { - uint32_t size = f->get_32(); + images.resize(layer_count); - Vector<uint8_t> pv; - pv.resize(size); - { - uint8_t *w = pv.ptrw(); - f->get_buffer(w, size); - } + for (uint32_t i = 0; i < layer_count; i++) { + Ref<Image> image = StreamTexture2D::load_image_from_file(f, p_size_limit); + ERR_FAIL_COND_V(image.is_null() || image->empty(), ERR_CANT_OPEN); + images.write[i] = image; + } - Ref<Image> img = Image::lossless_unpacker(pv); + return OK; +} - if (img.is_null() || img->empty() || format != img->get_format()) { - if (r_error) { - *r_error = ERR_FILE_CORRUPT; - } - f->close(); - memdelete(f); - ERR_FAIL_V(RES()); - } +Error StreamTextureLayered::load(const String &p_path) { + Vector<Ref<Image>> images; - mipmap_images.push_back(img); - } + int mipmap_limit; - if (mipmap_images.size() == 1) { + Error err = _load_data(p_path, images, mipmap_limit); + if (err) { + return err; + } - image = mipmap_images[0]; + if (texture.is_valid()) { + RID new_texture = RS::get_singleton()->texture_2d_layered_create(images, RS::TextureLayeredType(layered_type)); + RS::get_singleton()->texture_replace(texture, new_texture); + } else { + texture = RS::get_singleton()->texture_2d_layered_create(images, RS::TextureLayeredType(layered_type)); + } - } else { - int total_size = Image::get_image_data_size(tw, th, format, true); - Vector<uint8_t> img_data; - img_data.resize(total_size); - - { - uint8_t *w = img_data.ptrw(); - - int ofs = 0; - for (int i = 0; i < mipmap_images.size(); i++) { - - Vector<uint8_t> id = mipmap_images[i]->get_data(); - int len = id.size(); - const uint8_t *r = id.ptr(); - copymem(&w[ofs], r, len); - ofs += len; - } - } + w = images[0]->get_width(); + h = images[0]->get_height(); + mipmaps = images[0]->has_mipmaps(); + format = images[0]->get_format(); + layers = images.size(); - image->create(tw, th, true, format, img_data); - if (image->empty()) { - if (r_error) { - *r_error = ERR_FILE_CORRUPT; - } - f->close(); - memdelete(f); - ERR_FAIL_V(RES()); - } - } + path_to_file = p_path; - } else { + if (get_path() == String()) { + //temporarily set path if no path set for resource, helps find errors + RenderingServer::get_singleton()->texture_set_path(texture, p_path); + } - //look for regular format + _change_notify(); + emit_changed(); + return OK; +} - int total_size = Image::get_image_data_size(tw, th, format, use_mipmaps); +String StreamTextureLayered::get_load_path() const { + return path_to_file; +} - Vector<uint8_t> img_data; - img_data.resize(total_size); +int StreamTextureLayered::get_width() const { + return w; +} - { - uint8_t *w = img_data.ptrw(); - int bytes = f->get_buffer(w, total_size); - if (bytes != total_size) { - if (r_error) { - *r_error = ERR_FILE_CORRUPT; - } - f->close(); - memdelete(f); - ERR_FAIL_V(RES()); - } - } +int StreamTextureLayered::get_height() const { + return h; +} - image->create(tw, th, use_mipmaps, format, img_data); - } +int StreamTextureLayered::get_layers() const { + return layers; +} + +bool StreamTextureLayered::has_mipmaps() const { + return mipmaps; +} - images.push_back(image); +TextureLayered::LayeredType StreamTextureLayered::get_layered_type() const { + return layered_type; +} + +RID StreamTextureLayered::get_rid() const { + if (!texture.is_valid()) { + texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type)); } + return texture; +} - Error err = lt->create_from_images(images); - if (err != OK) { - *r_error = err; - return RES(); +Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const { + if (texture.is_valid()) { + return RS::get_singleton()->texture_2d_layer_get(texture, p_layer); } else { + return Ref<Image>(); + } +} - if (r_error) - *r_error = OK; +void StreamTextureLayered::reload_from_file() { + String path = get_path(); + if (!path.is_resource_file()) { + return; } - return lt; + path = ResourceLoader::path_remap(path); //remap for translation + path = ResourceLoader::import_remap(path); //remap for import + if (!path.is_resource_file()) { + return; + } + + load(path); +} + +void StreamTextureLayered::_validate_property(PropertyInfo &property) const { } -void ResourceFormatLoaderTextureLayered::get_recognized_extensions(List<String> *p_extensions) const { +void StreamTextureLayered::_bind_methods() { + ClassDB::bind_method(D_METHOD("load", "path"), &StreamTextureLayered::load); + ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTextureLayered::get_load_path); - p_extensions->push_back("cube"); - p_extensions->push_back("cubearr"); - p_extensions->push_back("tex2darr"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "load_path", PROPERTY_HINT_FILE, "*.stex"), "load", "get_load_path"); +} + +StreamTextureLayered::StreamTextureLayered(LayeredType p_type) { + layered_type = p_type; + format = Image::FORMAT_MAX; + w = 0; + h = 0; + layers = 0; + mipmaps = false; } -bool ResourceFormatLoaderTextureLayered::handles_type(const String &p_type) const { - return p_type == "Texture2DArray" || p_type == "Cubemap" || p_type == "CubemapArray"; + +StreamTextureLayered::~StreamTextureLayered() { + if (texture.is_valid()) { + RS::get_singleton()->free(texture); + } } -String ResourceFormatLoaderTextureLayered::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "cube") - return "Cubemap"; - if (p_path.get_extension().to_lower() == "cubearr") - return "CubemapArray"; - if (p_path.get_extension().to_lower() == "tex2darr") - return "Texture2DArray"; +///////////////////////////////////////////////// + +RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { + Ref<StreamTextureLayered> st; + if (p_path.get_extension().to_lower() == "stexarray") { + Ref<StreamTexture2DArray> s; + s.instance(); + st = s; + } else if (p_path.get_extension().to_lower() == "scube") { + Ref<StreamCubemap> s; + s.instance(); + st = s; + } else if (p_path.get_extension().to_lower() == "scubearray") { + Ref<StreamCubemapArray> s; + s.instance(); + st = s; + } else { + if (r_error) { + *r_error = ERR_FILE_UNRECOGNIZED; + } + return RES(); + } + Error err = st->load(p_path); + if (r_error) { + *r_error = err; + } + if (err != OK) { + return RES(); + } + + return st; +} + +void ResourceFormatLoaderStreamTextureLayered::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("stexarray"); + p_extensions->push_back("scube"); + p_extensions->push_back("scubearray"); +} + +bool ResourceFormatLoaderStreamTextureLayered::handles_type(const String &p_type) const { + return p_type == "StreamTexture2DArray" || p_type == "StreamCubemap" || p_type == "StreamCubemapArray"; +} + +String ResourceFormatLoaderStreamTextureLayered::get_resource_type(const String &p_path) const { + if (p_path.get_extension().to_lower() == "stexarray") { + return "StreamTexture2DArray"; + } + if (p_path.get_extension().to_lower() == "scube") { + return "StreamCubemap"; + } + if (p_path.get_extension().to_lower() == "scubearray") { + return "StreamCubemapArray"; + } return ""; } |