summaryrefslogtreecommitdiff
path: root/modules/basis_universal
diff options
context:
space:
mode:
Diffstat (limited to 'modules/basis_universal')
-rw-r--r--modules/basis_universal/SCsub6
-rw-r--r--modules/basis_universal/register_types.cpp58
-rw-r--r--modules/basis_universal/register_types.h10
-rw-r--r--modules/basis_universal/texture_basisu.cpp218
-rw-r--r--modules/basis_universal/texture_basisu.h80
5 files changed, 42 insertions, 330 deletions
diff --git a/modules/basis_universal/SCsub b/modules/basis_universal/SCsub
index 1f9fde966d..a44a7f0db3 100644
--- a/modules/basis_universal/SCsub
+++ b/modules/basis_universal/SCsub
@@ -13,16 +13,14 @@ thirdparty_obj = []
thirdparty_dir = "#thirdparty/basis_universal/"
# Sync list with upstream CMakeLists.txt
encoder_sources = [
- "apg_bmp.c",
- "basisu_astc_decomp.cpp",
"basisu_backend.cpp",
"basisu_basis_file.cpp",
"basisu_bc7enc.cpp",
+ "basisu_opencl.cpp",
"basisu_comp.cpp",
"basisu_enc.cpp",
"basisu_etc.cpp",
"basisu_frontend.cpp",
- "basisu_global_selector_palette_helpers.cpp",
"basisu_gpu_texture.cpp",
"basisu_kernels_sse.cpp",
"basisu_pvrtc1_4.cpp",
@@ -31,7 +29,7 @@ encoder_sources = [
"basisu_ssim.cpp",
"basisu_uastc_enc.cpp",
"jpgd.cpp",
- "lodepng.cpp",
+ "pvpngreader.cpp",
]
encoder_sources = [thirdparty_dir + "encoder/" + file for file in encoder_sources]
transcoder_sources = [thirdparty_dir + "transcoder/basisu_transcoder.cpp"]
diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp
index 772ac87dbf..e80d453df7 100644
--- a/modules/basis_universal/register_types.cpp
+++ b/modules/basis_universal/register_types.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,7 +32,6 @@
#include "core/os/os.h"
#include "servers/rendering_server.h"
-#include "texture_basisu.h"
#ifdef TOOLS_ENABLED
#include <encoder/basisu_comp.h>
@@ -50,8 +49,6 @@ enum BasisDecompressFormat {
//workaround for lack of ETC2 RG
#define USE_RG_AS_RGBA
-basist::etc1_global_selector_codebook *sel_codebook = nullptr;
-
#ifdef TOOLS_ENABLED
static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::UsedChannels p_channels) {
Vector<uint8_t> budata;
@@ -78,18 +75,14 @@ static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::
memcpy(buimg.get_ptr(), r, vec.size());
}
- //image->save_png("pepeche.png");
-
basisu::basis_compressor_params params;
+ params.m_uastc = true;
params.m_max_endpoint_clusters = 512;
params.m_max_selector_clusters = 512;
params.m_multithreading = true;
- //params.m_no_hybrid_sel_cb = true; //fixme, default on this causes crashes //seems fixed?
- params.m_pSel_codebook = sel_codebook;
//params.m_quality_level = 0;
//params.m_disable_hierarchical_endpoint_codebooks = true;
//params.m_no_selector_rdo = true;
- params.m_auto_global_sel_pal = false;
basisu::job_pool jpool(OS::get_singleton()->get_processor_count());
params.m_pJob_pool = &jpool;
@@ -150,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;
@@ -203,7 +195,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
format = basist::transcoder_texture_format::cTFETC2; // get this from renderer
imgfmt = Image::FORMAT_ETC2_RGBA8;
} else {
- //gles2 most likely
+ //opengl most likely
format = basist::transcoder_texture_format::cTFRGBA4444; // get this from renderer
imgfmt = Image::FORMAT_RGBA4444;
}
@@ -216,7 +208,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
format = basist::transcoder_texture_format::cTFETC2; // get this from renderer
imgfmt = Image::FORMAT_ETC2_RGBA8;
} else {
- //gles2 most likely, bad for normal maps, nothing to do about this.
+ //opengl most likely, bad for normal maps, nothing to do about this.
format = basist::transcoder_texture_format::cTFRGBA32;
imgfmt = Image::FORMAT_RGBA8;
}
@@ -226,7 +218,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
ptr += 4;
size -= 4;
- basist::basisu_transcoder tr(nullptr);
+ basist::basisu_transcoder tr;
ERR_FAIL_COND_V(!tr.validate_header(ptr, size), image);
@@ -252,7 +244,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
bool ret = tr.transcode_image_level(ptr, size, 0, i, dst + ofs, level.m_total_blocks - i, format);
if (!ret) {
- printf("failed! on level %i\n", i);
+ printf("failed! on level %u\n", i);
break;
};
@@ -260,25 +252,43 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
};
};
- image.instance();
+ image.instantiate();
image->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata);
return image;
}
-void register_basis_universal_types() {
+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 initialize_basis_universal_module(ModuleInitializationLevel p_level) {
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
+
#ifdef TOOLS_ENABLED
- sel_codebook = new basist::etc1_global_selector_codebook(basist::g_global_selector_cb_size, basist::g_global_selector_cb);
+ using namespace basisu;
+ using namespace basist;
+ basisu_encoder_init();
Image::basis_universal_packer = basis_universal_packer;
#endif
Image::basis_universal_unpacker = basis_universal_unpacker;
- //ClassDB::register_class<TextureBasisU>();
+ Image::basis_universal_unpacker_ptr = basis_universal_unpacker_ptr;
}
-void unregister_basis_universal_types() {
+void uninitialize_basis_universal_module(ModuleInitializationLevel p_level) {
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
+
#ifdef TOOLS_ENABLED
- delete sel_codebook;
Image::basis_universal_packer = nullptr;
#endif
Image::basis_universal_unpacker = nullptr;
+ Image::basis_universal_unpacker_ptr = nullptr;
}
diff --git a/modules/basis_universal/register_types.h b/modules/basis_universal/register_types.h
index 30b465e344..68d5dd64f3 100644
--- a/modules/basis_universal/register_types.h
+++ b/modules/basis_universal/register_types.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,7 +31,9 @@
#ifndef BASIS_UNIVERSAL_REGISTER_TYPES_H
#define BASIS_UNIVERSAL_REGISTER_TYPES_H
-void register_basis_universal_types();
-void unregister_basis_universal_types();
+#include "modules/register_module_types.h"
+
+void initialize_basis_universal_module(ModuleInitializationLevel p_level);
+void uninitialize_basis_universal_module(ModuleInitializationLevel p_level);
#endif // BASIS_UNIVERSAL_REGISTER_TYPES_H
diff --git a/modules/basis_universal/texture_basisu.cpp b/modules/basis_universal/texture_basisu.cpp
deleted file mode 100644
index 6a5f6313c4..0000000000
--- a/modules/basis_universal/texture_basisu.cpp
+++ /dev/null
@@ -1,218 +0,0 @@
-/*************************************************************************/
-/* texture_basisu.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "texture_basisu.h"
-#if 0
-#include "core/os/os.h"
-
-#ifdef TOOLS_ENABLED
-#include <encoder/basisu_comp.h>
-#endif
-
-#include <transcoder/basisu_transcoder.h>
-
-void TextureBasisU::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_basisu_data", "data"), &TextureBasisU::set_basisu_data);
- ClassDB::bind_method(D_METHOD("get_basisu_data"), &TextureBasisU::get_data);
- ClassDB::bind_method(D_METHOD("import"), &TextureBasisU::import);
-
- ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "basisu_data"), "set_basisu_data", "get_basisu_data");
-};
-
-int TextureBasisU::get_width() const {
- return tex_size.x;
-};
-
-int TextureBasisU::get_height() const {
- return tex_size.y;
-};
-
-RID TextureBasisU::get_rid() const {
- return texture;
-};
-
-
-bool TextureBasisU::has_alpha() const {
- return false;
-};
-
-void TextureBasisU::set_flags(uint32_t p_flags) {
- flags = p_flags;
- RenderingServer::get_singleton()->texture_set_flags(texture, p_flags);
-};
-
-uint32_t TextureBasisU::get_flags() const {
- return flags;
-};
-
-
-void TextureBasisU::set_basisu_data(const Vector<uint8_t>& p_data) {
-
-#ifdef TOOLS_ENABLED
- data = p_data;
-#endif
-
- const uint8_t* r = p_data.ptr();
- const void* ptr = r.ptr();
- int size = p_data.size();
-
- basist::transcoder_texture_format format;
- Image::Format imgfmt;
-
- if (OS::get_singleton()->has_feature("s3tc")) {
- format = basist::cTFBC3; // get this from renderer
- imgfmt = Image::FORMAT_DXT5;
-
- } else if (OS::get_singleton()->has_feature("etc2")) {
- format = basist::cTFETC2;
- imgfmt = Image::FORMAT_ETC2_RGBA8;
- };
-
- basist::basisu_transcoder tr(nullptr);
-
- ERR_FAIL_COND(!tr.validate_header(ptr, size));
-
- basist::basisu_image_info info;
- tr.get_image_info(ptr, size, info, 0);
- tex_size = Size2(info.m_width, info.m_height);
-
- int block_size = basist::basis_get_bytes_per_block(format);
- Vector<uint8_t> gpudata;
- gpudata.resize(info.m_total_blocks * block_size);
-
- {
- uint8_t* w = gpudata.ptrw();
- uint8_t* dst = w.ptr();
- for (int i=0; i<gpudata.size(); i++)
- dst[i] = 0x00;
-
- int ofs = 0;
- tr.start_transcoding(ptr, size);
- for (int i=0; i<info.m_total_levels; i++) {
- basist::basisu_image_level_info level;
- tr.get_image_level_info(ptr, size, level, 0, i);
-
- bool ret = tr.transcode_image_level(ptr, size, 0, i, dst + ofs, level.m_total_blocks - i, format);
- if (!ret) {
- printf("failed! on level %i\n", i);
- break;
- };
-
- ofs += level.m_total_blocks * block_size;
- };
- };
-
- Ref<Image> img;
- img.instance();
- img->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata);
-
- RenderingServer::get_singleton()->texture_allocate(texture, tex_size.x, tex_size.y, 0, img->get_format(), RS::TEXTURE_TYPE_2D, flags);
- RenderingServer::get_singleton()->texture_set_data(texture, img);
-};
-
-Error TextureBasisU::import(const Ref<Image>& p_img) {
-
-#ifdef TOOLS_ENABLED
-
- Vector<uint8_t> budata;
-
- {
- Image::Format format = p_img->get_format();
- if (format != Image::FORMAT_RGB8 && format != Image::FORMAT_RGBA8) {
- ERR_FAIL_V(ERR_INVALID_PARAMETER);
- return ERR_INVALID_PARAMETER;
- };
-
- Ref<Image> copy = p_img->duplicate();
- if (format == Image::FORMAT_RGB8)
- copy->convert(Image::FORMAT_RGBA8);
-
- basisu::image buimg(p_img->get_width(), p_img->get_height());
- int size = p_img->get_width() * p_img->get_height() * 4;
-
- Vector<uint8_t> vec = copy->get_data();
- {
- const uint8_t* r = vec.ptr();
- memcpy(buimg.get_ptr(), r.ptr(), size);
- };
-
- basisu::basis_compressor_params params;
- params.m_max_endpoint_clusters = 512;
- params.m_max_selector_clusters = 512;
- params.m_multithreading = true;
-
- basisu::job_pool jpool(1);
- params.m_pJob_pool = &jpool;
-
- params.m_mip_gen = p_img->get_mipmap_count() > 0;
- params.m_source_images.push_back(buimg);
-
- basisu::basis_compressor c;
- c.init(params);
-
- int buerr = c.process();
- if (buerr != basisu::basis_compressor::cECSuccess) {
- ERR_FAIL_V(ERR_INVALID_PARAMETER);
- return ERR_INVALID_PARAMETER;
- };
-
- const basisu::uint8_vec& buvec = c.get_output_basis_file();
- budata.resize(buvec.size());
-
- {
- uint8_t* w = budata.ptrw();
- memcpy(w.ptr(), &buvec[0], budata.size());
- };
- };
-
- set_basisu_data(budata);
-
- return OK;
-#else
-
- return ERR_UNAVAILABLE;
-#endif
-};
-
-
-Vector<uint8_t> TextureBasisU::get_basisu_data() const {
- return data;
-};
-
-TextureBasisU::TextureBasisU() {
- texture = RenderingServer::get_singleton()->texture_create();
-};
-
-
-TextureBasisU::~TextureBasisU() {
- RenderingServer::get_singleton()->free(texture);
-};
-
-#endif
diff --git a/modules/basis_universal/texture_basisu.h b/modules/basis_universal/texture_basisu.h
deleted file mode 100644
index 3316035404..0000000000
--- a/modules/basis_universal/texture_basisu.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*************************************************************************/
-/* texture_basisu.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef BASIS_UNIVERSAL_TEXTURE_BASISU_H
-#define BASIS_UNIVERSAL_TEXTURE_BASISU_H
-
-#include "scene/resources/texture.h"
-
-#ifdef TOOLS_ENABLED
-#include <encoder/basisu_comp.h>
-#endif
-
-#include <transcoder/basisu_transcoder.h>
-
-#if 0
-class TextureBasisU : public Texture {
- GDCLASS(TextureBasisU, Texture);
- RES_BASE_EXTENSION("butex");
-
- RID texture;
- Size2 tex_size;
-
- uint32_t flags = FLAGS_DEFAULT;
-
- Vector<uint8_t> data;
-
- static void _bind_methods();
-
-public:
-
- virtual int get_width() const;
- virtual int get_height() const;
- virtual RID get_rid() const;
- virtual bool has_alpha() const;
-
- virtual void set_flags(uint32_t p_flags);
- virtual uint32_t get_flags() const;
-
-
- Error import(const Ref<Image> &p_img);
-
- void set_basisu_data(const Vector<uint8_t>& p_data);
-
- Vector<uint8_t> get_basisu_data() const;
- String get_img_path() const;
-
- TextureBasisU();
- ~TextureBasisU();
-};
-
-#endif
-
-#endif // BASIS_UNIVERSAL_TEXTURE_BASISU_H