Skip to content

Commit

Permalink
Add ETC1/ETC2 compression support though etc2comp.
Browse files Browse the repository at this point in the history
Remove rg-etc1 code. Also updated travis to use ubuntu 14.04.

Fixes godotengine#8457.
  • Loading branch information
tagcup committed May 31, 2017
1 parent bd26fa7 commit 6a9c990
Show file tree
Hide file tree
Showing 61 changed files with 12,981 additions and 2,765 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: cpp

dist: trusty

sudo: false

compiler:
Expand Down Expand Up @@ -73,7 +75,6 @@ addons:
# For style checks.
- clang-format-3.9


before_script:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; brew install scons; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$GODOT_TARGET" = "android" ]; then
Expand All @@ -86,5 +87,9 @@ script:
- if [ "$STATIC_CHECKS" = "yes" ]; then
sh ./misc/travis/clang-format.sh;
else
scons platform=$GODOT_TARGET CXX=$CXX openssl=builtin;
if [ "$TRAVIS_OS_NAME" = "windows" ]; then
scons platform=$GODOT_TARGET CXX=$CXX openssl=builtin;
else
scons platform=$GODOT_TARGET bits=64 CXX=$CXX openssl=builtin;
fi
fi
22 changes: 11 additions & 11 deletions core/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,16 +1483,16 @@ Error Image::decompress() {
_image_decompress_bc(this);
else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc)
_image_decompress_pvrtc(this);
else if (format == FORMAT_ETC && _image_decompress_etc)
_image_decompress_etc(this);
else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RGB8A1 && _image_decompress_etc)
else if (format == FORMAT_ETC && _image_decompress_etc1)
_image_decompress_etc1(this);
else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RGB8A1 && _image_decompress_etc1)
_image_decompress_etc2(this);
else
return ERR_UNAVAILABLE;
return OK;
}

Error Image::compress(CompressMode p_mode, bool p_for_srgb) {
Error Image::compress(CompressMode p_mode, bool p_for_srgb, float p_lossy_quality) {

switch (p_mode) {

Expand All @@ -1513,13 +1513,13 @@ Error Image::compress(CompressMode p_mode, bool p_for_srgb) {
} break;
case COMPRESS_ETC: {

ERR_FAIL_COND_V(!_image_compress_etc_func, ERR_UNAVAILABLE);
_image_compress_etc_func(this);
ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE);
_image_compress_etc1_func(this, p_lossy_quality);
} break;
case COMPRESS_ETC2: {

ERR_FAIL_COND_V(!_image_compress_etc_func, ERR_UNAVAILABLE);
_image_compress_etc_func(this);
ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE);
_image_compress_etc2_func(this, p_lossy_quality);
} break;
}

Expand Down Expand Up @@ -1652,11 +1652,11 @@ Ref<Image> (*Image::_jpg_mem_loader_func)(const uint8_t *, int) = NULL;
void (*Image::_image_compress_bc_func)(Image *, bool) = NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL;
void (*Image::_image_compress_etc_func)(Image *) = NULL;
void (*Image::_image_compress_etc2_func)(Image *) = NULL;
void (*Image::_image_compress_etc1_func)(Image *, float) = NULL;
void (*Image::_image_compress_etc2_func)(Image *, float) = NULL;
void (*Image::_image_decompress_pvrtc)(Image *) = NULL;
void (*Image::_image_decompress_bc)(Image *) = NULL;
void (*Image::_image_decompress_etc)(Image *) = NULL;
void (*Image::_image_decompress_etc1)(Image *) = NULL;
void (*Image::_image_decompress_etc2)(Image *) = NULL;

PoolVector<uint8_t> (*Image::lossy_packer)(const Ref<Image> &, float) = NULL;
Expand Down
8 changes: 4 additions & 4 deletions core/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ class Image : public Resource {
static void (*_image_compress_bc_func)(Image *, bool p_srgb);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc_func)(Image *);
static void (*_image_compress_etc2_func)(Image *);
static void (*_image_compress_etc1_func)(Image *, float);
static void (*_image_compress_etc2_func)(Image *, float);

static void (*_image_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
static void (*_image_decompress_etc)(Image *);
static void (*_image_decompress_etc1)(Image *);
static void (*_image_decompress_etc2)(Image *);

static PoolVector<uint8_t> (*lossy_packer)(const Ref<Image> &p_image, float p_quality);
Expand Down Expand Up @@ -267,7 +267,7 @@ class Image : public Resource {
COMPRESS_ETC2,
};

Error compress(CompressMode p_mode = COMPRESS_S3TC, bool p_for_srgb = false);
Error compress(CompressMode p_mode = COMPRESS_S3TC, bool p_for_srgb = false, float p_lossy_quality = 0.7);
Error decompress();
bool is_compressed() const;

Expand Down
17 changes: 17 additions & 0 deletions core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ class Math {
static _ALWAYS_INLINE_ bool is_inf(double p_val) {
#ifdef _MSC_VER
return !_finite(p_val);
// workaround for mingw builds on travis
#elif defined(__MINGW32__) || defined(__MINGW64__)
union {
uint64_t u;
double f;
} ieee754;
ieee754.f = p_val;
return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
((unsigned)ieee754.u == 0);
#else
return isinf(p_val);
#endif
Expand All @@ -120,6 +129,14 @@ class Math {
static _ALWAYS_INLINE_ bool is_inf(float p_val) {
#ifdef _MSC_VER
return !_finite(p_val);
// workaround for mingw builds on travis
#elif defined(__MINGW32__) || defined(__MINGW64__)
union {
uint32_t u;
float f;
} ieee754;
ieee754.f = p_val;
return (ieee754.u & 0x7fffffff) == 0x7f800000;
#else
return isinf(p_val);
#endif
Expand Down
4 changes: 3 additions & 1 deletion doc/base/classes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18490,8 +18490,10 @@
</return>
<argument index="0" name="format" type="int" default="0">
</argument>
<argument index="0" name="quality" type="float" default="0">
</argument>
<description>
Return a new compressed [Image] from this [Image] using one of [Image].COMPRESS_*.
Return a new compressed [Image] from this [Image] using one of [Image].COMPRESS_*. Quality only affects ETC1 and ETC2 encoding.
</description>
</method>
<method name="converted">
Expand Down
14 changes: 9 additions & 5 deletions editor/import/resource_importer_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ String ResourceImporterTexture::get_resource_type() const {

bool ResourceImporterTexture::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {

if (p_option == "compress/lossy_quality" && int(p_options["compress/mode"]) != COMPRESS_LOSSY)
return false;
if (p_option == "compress/lossy_quality") {
int compress_mode = int(p_options["compress/mode"]);
if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VIDEO_RAM) {
return false;
}
}

return true;
}
Expand Down Expand Up @@ -277,7 +281,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
if (p_force_rgbe && image->get_format() >= Image::FORMAT_R8 && image->get_format() <= Image::FORMAT_RGBE9995) {
image->convert(Image::FORMAT_RGBE9995);
} else {
image->compress(p_vram_compression, p_texture_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR);
image->compress(p_vram_compression, p_texture_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR, p_lossy_quality);
}

format |= image->get_format();
Expand Down Expand Up @@ -382,8 +386,8 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
//Android, GLES 2.x
_save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe);
r_platform_variants->push_back("etc");
//_save_stex(image,p_save_path+".etc2.stex",compress_mode,lossy,Image::COMPRESS_ETC2,mipmaps,tex_flags,stream);
//r_platform_variants->push_back("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);
r_platform_variants->push_back("etc2");
_save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe);
r_platform_variants->push_back("s3tc");

Expand Down
37 changes: 37 additions & 0 deletions modules/etc/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

Import('env')
Import('env_modules')

env_etc = env_modules.Clone()

# Thirdparty source files
# Not unbundled so far since not widespread as shared library
thirdparty_dir = "#thirdparty/etc2comp/"
thirdparty_sources = [
"EtcBlock4x4.cpp",
"EtcBlock4x4Encoding.cpp",
"EtcBlock4x4Encoding_ETC1.cpp",
"EtcBlock4x4Encoding_R11.cpp",
"EtcBlock4x4Encoding_RG11.cpp",
"EtcBlock4x4Encoding_RGB8A1.cpp",
"EtcBlock4x4Encoding_RGB8.cpp",
"EtcBlock4x4Encoding_RGBA8.cpp",
"Etc.cpp",
"EtcDifferentialTrys.cpp",
"EtcFilter.cpp",
"EtcImage.cpp",
"EtcIndividualTrys.cpp",
"EtcMath.cpp",
"EtcSortedBlockList.cpp",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

env_etc.add_source_files(env.modules_sources, thirdparty_sources)
env_etc.Append(CPPPATH=[thirdparty_dir])

# Godot source files
env_etc.add_source_files(env.modules_sources, "*.cpp")

# upstream uses c++11
env_etc.Append(CXXFLAGS="-std=gnu++11")
File renamed without changes.
Loading

0 comments on commit 6a9c990

Please sign in to comment.