Skip to content

Commit

Permalink
iOS: Fix multiple issues with PVRTC import, disable ETC1
Browse files Browse the repository at this point in the history
Fixes: godotengine#28683, godotengine#28621, godotengine#28596 and maybe others

For iOS we enable pvrtc feature by default for both GLES2/GLES3
Etc1 for iOS doesn't have any sense, so it disabled.
Fixed checks in export editor.
Fixed pvrtc ability detection in GLES2 driver.
Fixed pvrtc encoding procedure.
  • Loading branch information
DrMoriarty committed Sep 23, 2020
1 parent 26512dd commit f388ea0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5898,7 +5898,7 @@ void RasterizerStorageGLES2::initialize() {
config.float_texture_supported = config.extensions.has("GL_ARB_texture_float") || config.extensions.has("GL_OES_texture_float");
config.s3tc_supported = config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc");
config.etc1_supported = config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture") || config.extensions.has("WEBGL_compressed_texture_etc1");
config.pvrtc_supported = config.extensions.has("IMG_texture_compression_pvrtc") || config.extensions.has("WEBGL_compressed_texture_pvrtc");
config.pvrtc_supported = config.extensions.has("GL_IMG_texture_compression_pvrtc") || config.extensions.has("WEBGL_compressed_texture_pvrtc");
config.support_npot_repeat_mipmap = config.extensions.has("GL_OES_texture_npot");

#ifdef JAVASCRIPT_ENABLED
Expand Down
24 changes: 24 additions & 0 deletions editor/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,30 @@ String EditorExportPlatform::test_etc2() const {
return String();
}

String EditorExportPlatform::test_etc2_or_pvrtc() const {

String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
bool driver_fallback = ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2");
bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2");
bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc");

if (driver == "GLES2" && !pvrtc_supported) {
return TTR("Target platform requires 'PVRTC' texture compression for GLES2. Enable 'Import Pvrtc' in Project Settings.");
} else if (driver == "GLES3") {
String err;
if (!etc2_supported && !pvrtc_supported) {
err += TTR("Target platform requires 'ETC2' or 'PVRTC' texture compression for GLES3. Enable 'Import Etc 2' or 'Import Pvrtc' in Project Settings.");
}
if (driver_fallback && !pvrtc_supported) {
if (err != String())
err += "\n";
err += TTR("Target platform requires 'PVRTC' texture compression for the driver fallback to GLES2.\nEnable 'Import Pvrtc' in Project Settings, or disable 'Driver Fallback Enabled'.");
}
return err;
}
return String();
}

int EditorExport::get_export_preset_count() const {

return export_presets.size();
Expand Down
1 change: 1 addition & 0 deletions editor/editor_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class EditorExportPlatform : public Reference {
virtual Ref<Texture> get_run_icon() const { return get_logo(); }

String test_etc2() const; //generic test for etc2 since most platforms use it
String test_etc2_or_pvrtc() const; // test for etc2 or pvrtc support for iOS
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0;

virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0;
Expand Down
8 changes: 5 additions & 3 deletions modules/pvr/texture_loader_pvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ static void _compress_pvrtc4(Image *p_img) {
int ofs, size, w, h;
img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h);
Javelin::RgbaBitmap bm(w, h);
void *dst = (void *)bm.GetData();
copymem(dst, &r[ofs], size);
Javelin::ColorRgba<unsigned char> *dp = bm.GetData();
for (int j = 0; j < size / 4; j++) {
Javelin::ColorRgba<unsigned char> *dp = bm.GetData();
/* red and Green colors are swapped. */
new (dp) Javelin::ColorRgba<unsigned char>(r[ofs + 4 * j + 2], r[ofs + 4 * j + 1], r[ofs + 4 * j], r[ofs + 4 * j + 3]);
/* red and blue colors are swapped. */
SWAP(dp[j].r, dp[j].b);
}
new_img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h);
Javelin::PvrTcEncoder::EncodeRgba4Bpp(&wr[ofs], bm);
Expand Down
10 changes: 3 additions & 7 deletions platform/iphone/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,9 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {

String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
if (driver == "GLES2") {
r_features->push_back("etc");
} else if (driver == "GLES3") {
r_features->push_back("pvrtc");
if (driver == "GLES3") {
r_features->push_back("etc2");
if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
r_features->push_back("etc");
}
}

Vector<String> architectures = _get_preset_architectures(p_preset);
Expand Down Expand Up @@ -1515,7 +1511,7 @@ bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset
}
}

String etc_error = test_etc2();
String etc_error = test_etc2_or_pvrtc();
if (etc_error != String()) {
valid = false;
err += etc_error;
Expand Down

0 comments on commit f388ea0

Please sign in to comment.