Add PortableCompressedTexture

* Resource that allows saving textures embedded in scenes or standalone.
* Supports only formats that are portable: Lossy, Lossles or BasisUniversal

This is something I wanted to add for a long time. I made it now because @fire
requires it for importing GLTF2 files with embedded textures, but also this
will allow saving Godot scenes as standalone binary files that will run
in all platforms (because textures will load everywhere).

This is ideal when you want to distribute individual standalone assets online
in games that can be built from Godot scenes.
This commit is contained in:
reduz 2022-03-24 18:18:55 +01:00
parent f6ef63635f
commit 45f74ceb85
9 changed files with 482 additions and 8 deletions

View file

@ -143,12 +143,11 @@ static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::
}
#endif // TOOLS_ENABLED
static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
static Ref<Image> basis_universal_unpacker_ptr(const uint8_t *p_data, int p_size) {
Ref<Image> image;
const uint8_t *r = p_buffer.ptr();
const uint8_t *ptr = r;
int size = p_buffer.size();
const uint8_t *ptr = p_data;
int size = p_size;
basist::transcoder_texture_format format = basist::transcoder_texture_format::cTFTotalTextureFormats;
Image::Format imgfmt = Image::FORMAT_MAX;
@ -259,6 +258,14 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
return image;
}
static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
Ref<Image> image;
const uint8_t *r = p_buffer.ptr();
int size = p_buffer.size();
return basis_universal_unpacker_ptr(r, size);
}
void register_basis_universal_types() {
#ifdef TOOLS_ENABLED
using namespace basisu;
@ -267,6 +274,7 @@ void register_basis_universal_types() {
Image::basis_universal_packer = basis_universal_packer;
#endif
Image::basis_universal_unpacker = basis_universal_unpacker;
Image::basis_universal_unpacker_ptr = basis_universal_unpacker_ptr;
}
void unregister_basis_universal_types() {
@ -274,4 +282,5 @@ void unregister_basis_universal_types() {
Image::basis_universal_packer = nullptr;
#endif
Image::basis_universal_unpacker = nullptr;
Image::basis_universal_unpacker_ptr = nullptr;
}