Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

CompressedTexture: Remove old incomplete texture streaming implementation

BlueCube33105b1b59bc2ac5
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 0be841e9acb..03fff042d21 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -386,7 +386,7 @@ void ResourceImporterTexture::save_to_ctex_format(Ref<FileAccess> f, const Ref<I
}
}
-void ResourceImporterTexture::_save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, const Image::BasisUniversalPackerParams &p_basisu_params, Image::CompressMode p_vram_compression, Image::CompressProfile p_vram_compression_profile, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_roughness, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel, bool p_preserve_alpha_test_coverage, float p_alpha_test_coverage) {
+void ResourceImporterTexture::_save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, const Image::BasisUniversalPackerParams &p_basisu_params, Image::CompressMode p_vram_compression, Image::CompressProfile p_vram_compression_profile, bool p_mipmaps, bool p_detect_3d, bool p_detect_roughness, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel, bool p_preserve_alpha_test_coverage, float p_alpha_test_coverage) {
Ref<FileAccess> f = FileAccess::open(p_to_path, FileAccess::WRITE);
ERR_FAIL_COND(f.is_null());
@@ -404,9 +404,6 @@ void ResourceImporterTexture::_save_ctex(const Ref<Image> &p_image, const String
f->store_32(p_image->get_height());
uint32_t flags = 0;
- if (p_streamable) {
- flags |= CompressedTexture2D::FORMAT_BIT_STREAM;
- }
if (p_mipmaps) {
flags |= CompressedTexture2D::FORMAT_BIT_HAS_MIPMAPS;
}
@@ -790,9 +787,6 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String
}
}
- // Support for texture streaming is not implemented yet.
- const bool stream = false;
-
// SVG-specific options.
float scale = p_options.has("svg/scale") ? float(p_options["svg/scale"]) : 1.0f;
@@ -960,7 +954,7 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String
if (force_uncompressed) {
_save_ctex(image, p_save_path + ".ctex", COMPRESS_VRAM_UNCOMPRESSED, lossy, basisu_params, Image::COMPRESS_S3TC /* This is ignored. */, Image::COMPRESS_PROFILE_AUTOMATIC /* This is ignored. */,
- mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
+ mipmaps, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
} else {
if (can_s3tc_bptc) {
Image::CompressMode image_compress_mode;
@@ -975,7 +969,7 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String
}
_save_ctex(image, p_save_path + "." + image_compress_format + ".ctex", compress_mode, lossy, basisu_params, image_compress_mode, image_compress_profile, mipmaps,
- stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
+ detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
r_platform_variants->push_back(image_compress_format);
}
@@ -991,7 +985,7 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String
image_compress_format = "etc2";
}
- _save_ctex(image, p_save_path + "." + image_compress_format + ".ctex", compress_mode, lossy, basisu_params, image_compress_mode, image_compress_profile, mipmaps, stream, detect_3d,
+ _save_ctex(image, p_save_path + "." + image_compress_format + ".ctex", compress_mode, lossy, basisu_params, image_compress_mode, image_compress_profile, mipmaps, detect_3d,
detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
r_platform_variants->push_back(image_compress_format);
}
@@ -999,12 +993,12 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String
} else {
// Import normally.
_save_ctex(image, p_save_path + ".ctex", compress_mode, lossy, basisu_params, Image::COMPRESS_S3TC /* This is ignored. */, Image::COMPRESS_PROFILE_AUTOMATIC /* This is ignored. */,
- mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
+ mipmaps, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
}
if (editor_image.is_valid()) {
_save_ctex(editor_image, p_save_path + ".editor.ctex", compress_mode, lossy, basisu_params, Image::COMPRESS_S3TC /* This is ignored. */, Image::COMPRESS_PROFILE_AUTOMATIC /* This is ignored. */,
- mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
+ mipmaps, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, mipmap_limit, normal_image, roughness_channel, mipmaps_preserve_alpha_test_coverage, mipmaps_alpha_test_threshold);
// Generate and save editor-specific metadata, which we cannot save to the .import file.
Dictionary editor_meta;
diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h
index 5ccc513f296..8f4f2289ee2 100644
--- a/editor/import/resource_importer_texture.h
+++ b/editor/import/resource_importer_texture.h
@@ -86,7 +86,7 @@ protected:
static ResourceImporterTexture *singleton;
static const char *compression_formats[];
- void _save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, const Image::BasisUniversalPackerParams &p_basisu_params, Image::CompressMode p_vram_compression, Image::CompressProfile p_vram_compression_profile, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel, bool p_preserve_alpha_test_coverage, float p_alpha_test_threshold);
+ void _save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, const Image::BasisUniversalPackerParams &p_basisu_params, Image::CompressMode p_vram_compression, Image::CompressProfile p_vram_compression_profile, bool p_mipmaps, bool p_detect_3d, bool p_detect_srgb, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel, bool p_preserve_alpha_test_coverage, float p_alpha_test_threshold);
void _save_editor_meta(const Dictionary &p_metadata, const String &p_to_path);
Dictionary _load_editor_meta(const String &p_to_path) const;
diff --git a/scene/resources/compressed_texture.cpp b/scene/resources/compressed_texture.cpp
index fa0792edac0..40f673f4edf 100644
--- a/scene/resources/compressed_texture.cpp
+++ b/scene/resources/compressed_texture.cpp
@@ -36,7 +36,7 @@
#include "scene/resources/bit_map.h"
#include "servers/rendering/rendering_server.h"
-Error CompressedTexture2D::_load_data(const String &p_path, int &r_width, int &r_height, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) {
+Error CompressedTexture2D::_load_data(const String &p_path, int &r_width, int &r_height, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit) {
alpha_cache.unref();
ERR_FAIL_COND_V(image.is_null(), ERR_INVALID_PARAMETER);
@@ -57,7 +57,13 @@ Error CompressedTexture2D::_load_data(const String &p_path, int &r_width, int &r
}
r_width = f->get_32();
r_height = f->get_32();
+
+#ifdef TOOLS_ENABLED
+ // df is only used in editor builds at the moment.
uint32_t df = f->get_32(); //data format
+#else
+ f->get_32();
+#endif
//skip reserved
mipmap_limit = int(f->get_32());
@@ -79,11 +85,8 @@ Error CompressedTexture2D::_load_data(const String &p_path, int &r_width, int &r
r_request_normal = false;
#endif
- if (!(df & FORMAT_BIT_STREAM)) {
- p_size_limit = 0;
- }
- image = load_image_from_file(f, p_size_limit);
+ image = load_image_from_file(f);
if (image.is_null() || image->is_empty()) {
return ERR_CANT_OPEN;
@@ -294,7 +297,7 @@ void CompressedTexture2D::reload_from_file() {
load(path);
}
-Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_size_limit) {
+Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f) {
uint32_t data_format = f->get_32();
uint32_t w = f->get_16();
uint32_t h = f->get_16();
@@ -303,10 +306,6 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
if (data_format == DATA_FORMAT_PNG || data_format == DATA_FORMAT_WEBP) {
//look for a PNG or WebP file inside
-
- int sw = w;
- int sh = h;
-
//mipmaps need to be read independently, they will be later combined
Vector<Ref<Image>> mipmap_images;
uint64_t total_size = 0;
@@ -314,14 +313,6 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
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)) {
- //can't load this due to size limit
- sw = MAX(sw >> 1, 1);
- sh = MAX(sh >> 1, 1);
- f->seek(f->get_position() + size);
- continue;
- }
-
Vector<uint8_t> pv;
pv.resize(size);
{
@@ -355,9 +346,6 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
total_size += img->get_data().size();
mipmap_images.push_back(img);
-
- sw = MAX(sw >> 1, 1);
- sh = MAX(sh >> 1, 1);
}
//print_line("mipmap read total: " + itos(mipmap_images.size()));
@@ -393,16 +381,7 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
}
} else if (data_format == DATA_FORMAT_BASIS_UNIVERSAL) {
- int sw = w;
- int sh = h;
uint32_t size = f->get_32();
- if (p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {
- //can't load this due to size limit
- sw = MAX(sw >> 1, 1);
- sh = MAX(sh >> 1, 1);
- f->seek(f->get_position() + size);
- return Ref<Image>();
- }
Vector<uint8_t> pv;
pv.resize(size);
{
@@ -415,35 +394,14 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
ERR_FAIL_COND_V(img.is_null() || img->is_empty(), Ref<Image>());
}
format = img->get_format();
- sw = MAX(sw >> 1, 1);
- sh = MAX(sh >> 1, 1);
return img;
} 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++) {
- int tw, th;
- int ofs = Image::get_image_mipmap_offset_and_dimensions(w, h, format, i, tw, th);
+ int64_t size = Image::get_image_data_size(w, h, format, mipmaps > 0);
+ Vector<uint8_t> data;
+ data.resize(size);
+ f->get_buffer(data.ptrw(), size);
- if (p_size_limit > 0 && i < mipmaps && (p_size_limit > tw || p_size_limit > th)) {
- if (ofs) {
- f->seek(f->get_position() + ofs);
- }
- continue; //oops, size limit enforced, go to next
- }
-
- Vector<uint8_t> data;
- data.resize(size - ofs);
-
- {
- uint8_t *wr = data.ptrw();
- f->get_buffer(wr, data.size());
- }
-
- Ref<Image> image = Image::create_from_data(tw, th, mipmaps - i ? true : false, format, data);
-
- return image;
- }
+ return Image::create_from_data(w, h, mipmaps > 0, format, data);
}
return Ref<Image>();
@@ -504,7 +462,7 @@ Error CompressedTexture3D::_load_data(const String &p_path, Vector<Ref<Image>> &
r_data.clear();
for (int i = 0; i < (r_depth + mipmap_count); i++) {
- Ref<Image> image = CompressedTexture2D::load_image_from_file(f, 0);
+ Ref<Image> image = CompressedTexture2D::load_image_from_file(f);
ERR_FAIL_COND_V(image.is_null() || image->is_empty(), ERR_CANT_OPEN);
if (i == 0) {
r_format = image->get_format();
@@ -627,7 +585,7 @@ Image::Format CompressedTextureLayered::get_format() const {
return format;
}
-Error CompressedTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit) {
+Error CompressedTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit) {
ERR_FAIL_COND_V(images.size() != 0, ERR_INVALID_PARAMETER);
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
@@ -649,21 +607,17 @@ Error CompressedTextureLayered::_load_data(const String &p_path, Vector<Ref<Imag
uint32_t type = f->get_32(); //layer count
ERR_FAIL_COND_V((int)type != layered_type, ERR_INVALID_DATA);
- uint32_t df = f->get_32(); //data format
+ /* uint32_t df = */ f->get_32(); //data format (currently unused)
mipmap_limit = int(f->get_32());
//reserved
f->get_32();
f->get_32();
f->get_32();
- if (!(df & FORMAT_BIT_STREAM)) {
- p_size_limit = 0;
- }
-
images.resize(layer_count);
for (uint32_t i = 0; i < layer_count; i++) {
- Ref<Image> image = CompressedTexture2D::load_image_from_file(f, p_size_limit);
+ Ref<Image> image = CompressedTexture2D::load_image_from_file(f);
ERR_FAIL_COND_V(image.is_null() || image->is_empty(), ERR_CANT_OPEN);
images.write[i] = image;
}
diff --git a/scene/resources/compressed_texture.h b/scene/resources/compressed_texture.h
index d0b79372725..099b09fbb26 100644
--- a/scene/resources/compressed_texture.h
+++ b/scene/resources/compressed_texture.h
@@ -51,7 +51,6 @@ public:
};
enum FormatBits {
- FORMAT_BIT_STREAM = 1 << 22,
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
FORMAT_BIT_DETECT_3D = 1 << 24,
//FORMAT_BIT_DETECT_SRGB = 1 << 25,
@@ -67,7 +66,7 @@ private:
int h = 0;
mutable Ref<BitMap> alpha_cache;
- Error _load_data(const String &p_path, int &r_width, int &r_height, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit = 0);
+ Error _load_data(const String &p_path, int &r_width, int &r_height, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit);
virtual void reload_from_file() override;
static void _requested_3d(void *p_ud);
@@ -78,7 +77,7 @@ protected:
static void _bind_methods();
public:
- static Ref<Image> load_image_from_file(Ref<FileAccess> p_file, int p_size_limit);
+ static Ref<Image> load_image_from_file(Ref<FileAccess> p_file);
typedef void (*TextureFormatRequestCallback)(const Ref<CompressedTexture2D> &);
typedef void (*TextureFormatRoughnessRequestCallback)(const Ref<CompressedTexture2D> &, const String &p_normal_path, RSE::TextureDetectRoughnessChannel p_roughness_channel);
@@ -125,12 +124,11 @@ public:
};
enum FormatBits {
- FORMAT_BIT_STREAM = 1 << 22,
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
};
private:
- Error _load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit = 0);
+ Error _load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit);
String path_to_file;
mutable RID texture;
Image::Format format = Image::FORMAT_L8;
@@ -204,7 +202,6 @@ public:
};
enum FormatBits {
- FORMAT_BIT_STREAM = 1 << 22,
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
};