فهرست منبع

Ensure ETC2 textures are ALSO compressed to Po2 when have mipmaps. Fixes #26733

Juan Linietsky 6 سال پیش
والد
کامیت
6cb841edcb
4فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 4 0
      core/image.cpp
  2. 1 0
      core/image.h
  3. 5 1
      drivers/gles3/rasterizer_storage_gles3.cpp
  4. 1 1
      editor/import/resource_importer_texture.cpp

+ 4 - 0
core/image.cpp

@@ -735,6 +735,10 @@ static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst,
 	}
 }
 
+bool Image::is_size_po2() const {
+	return uint32_t(width) == next_power_of_2(width) && uint32_t(height) == next_power_of_2(height);
+}
+
 void Image::resize_to_po2(bool p_square) {
 
 	if (!_can_modify(format)) {

+ 1 - 0
core/image.h

@@ -223,6 +223,7 @@ public:
 	void resize(int p_width, int p_height, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
 	void shrink_x2();
 	void expand_x2_hq2x();
+	bool is_size_po2() const;
 	/**
 	 * Crop the image to a specific size, if larger, then the image is filled by black
 	 */

+ 5 - 1
drivers/gles3/rasterizer_storage_gles3.cpp

@@ -752,7 +752,11 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p
 	if (config.keep_original_textures && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
 		texture->images.write[p_layer] = p_image;
 	}
-
+#ifndef GLES_OVER_GL
+	if (p_image->is_compressed() && p_image->has_mipmaps() && !p_image->is_size_po2()) {
+		ERR_PRINTS("Texuture '" + texture->path + "' is compressed, has mipmaps but is not of powerf-of-2 size. This does not work on OpenGL ES 3.0.");
+	}
+#endif
 	Image::Format real_format;
 	Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, real_format, format, internal_format, type, compressed, srgb);
 

+ 1 - 1
editor/import/resource_importer_texture.cpp

@@ -505,7 +505,7 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
 
 		if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) {
 
-			_save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, false);
+			_save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, true);
 			r_platform_variants->push_back("etc2");
 			formats_imported.push_back("etc2");
 		}