From 3695c087829843b108bf55296d7dca39a08f135b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 27 Sep 2019 14:43:04 +0200 Subject: basis_universal: Use proper basisu_transcoder.h header, fixes Clang build Also renames bu to basisu to be more explicit and match upstream name. --- modules/basis_universal/SCsub | 10 +- modules/basis_universal/register_types.cpp | 11 +- modules/basis_universal/texture_basisu.cpp | 203 +++++++++++++++++++++++++++++ modules/basis_universal/texture_basisu.h | 47 +++++++ modules/basis_universal/texture_bu.cpp | 203 ----------------------------- modules/basis_universal/texture_bu.h | 47 ------- 6 files changed, 260 insertions(+), 261 deletions(-) create mode 100644 modules/basis_universal/texture_basisu.cpp create mode 100644 modules/basis_universal/texture_basisu.h delete mode 100644 modules/basis_universal/texture_bu.cpp delete mode 100644 modules/basis_universal/texture_bu.h (limited to 'modules/basis_universal') diff --git a/modules/basis_universal/SCsub b/modules/basis_universal/SCsub index b933e78de8..3e179762a5 100644 --- a/modules/basis_universal/SCsub +++ b/modules/basis_universal/SCsub @@ -3,7 +3,7 @@ Import('env') Import('env_modules') -env_bu = env_modules.Clone() +env_basisu = env_modules.Clone() # Thirdparty source files # Not unbundled so far since not widespread as shared library @@ -28,16 +28,16 @@ tool_sources = [ tool_sources = [thirdparty_dir + file for file in tool_sources] transcoder_sources = [thirdparty_dir + "transcoder/basisu_transcoder.cpp"] -env_bu.Append(CPPPATH=[thirdparty_dir, thirdparty_dir + "transcoder"]) +env_basisu.Append(CPPPATH=[thirdparty_dir, thirdparty_dir + "transcoder"]) if env['target'] == "debug": - env_bu.Append(CPPFLAGS=["-DBASISU_DEVEL_MESSAGES=1", "-DBASISD_ENABLE_DEBUG_FLAGS=1"]) + env_basisu.Append(CPPFLAGS=["-DBASISU_DEVEL_MESSAGES=1", "-DBASISD_ENABLE_DEBUG_FLAGS=1"]) -env_thirdparty = env_bu.Clone() +env_thirdparty = env_basisu.Clone() env_thirdparty.disable_warnings() if env['tools']: env_thirdparty.add_source_files(env.modules_sources, tool_sources) env_thirdparty.add_source_files(env.modules_sources, transcoder_sources) # Godot source files -env_bu.add_source_files(env.modules_sources, "*.cpp") +env_basisu.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index 780630c857..04f488de96 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -1,15 +1,14 @@ #include "register_types.h" #include "core/os/os.h" -#include "texture_bu.h" +#include "servers/visual_server.h" +#include "texture_basisu.h" #ifdef TOOLS_ENABLED -#include "thirdparty/basis_universal/basisu_comp.h" +#include #endif -#include "thirdparty/basis_universal/transcoder/basisu.h" - -#include "servers/visual_server.h" +#include enum BasisDecompressFormat { BASIS_DECOMPRESS_RG, @@ -250,7 +249,7 @@ void register_basis_universal_types() { Image::basis_universal_packer = basis_universal_packer; #endif Image::basis_universal_unpacker = basis_universal_unpacker; - // ClassDB::register_class(); + //ClassDB::register_class(); } void unregister_basis_universal_types() { diff --git a/modules/basis_universal/texture_basisu.cpp b/modules/basis_universal/texture_basisu.cpp new file mode 100644 index 0000000000..20c4974da5 --- /dev/null +++ b/modules/basis_universal/texture_basisu.cpp @@ -0,0 +1,203 @@ +#include "texture_basisu.h" +#if 0 +#include "core/os/os.h" + +#ifdef TOOLS_ENABLED +#include +#endif + +#include + +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::POOL_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; + VisualServer::get_singleton()->texture_set_flags(texture, p_flags); +}; + +uint32_t TextureBasisU::get_flags() const { + + return flags; +}; + + +void TextureBasisU::set_basisu_data(const PoolVector& p_data) { + +#ifdef TOOLS_ENABLED + data = p_data; +#endif + + PoolVector::Read r = p_data.read(); + 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(NULL); + + 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); + PoolVector gpudata; + gpudata.resize(info.m_total_blocks * block_size); + + { + PoolVector::Write w = gpudata.write(); + uint8_t* dst = w.ptr(); + for (int i=0; i img; + img.instance(); + img->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata); + + VisualServer::get_singleton()->texture_allocate(texture, tex_size.x, tex_size.y, 0, img->get_format(), VS::TEXTURE_TYPE_2D, flags); + VisualServer::get_singleton()->texture_set_data(texture, img); +}; + +Error TextureBasisU::import(const Ref& p_img) { + +#ifdef TOOLS_ENABLED + + PoolVector 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 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; + + PoolVector vec = copy->get_data(); + { + PoolVector::Read r = vec.read(); + 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()); + + { + PoolVector::Write w = budata.write(); + memcpy(w.ptr(), &buvec[0], budata.size()); + }; + }; + + set_basisu_data(budata); + + return OK; +#else + + return ERR_UNAVAILABLE; +#endif +}; + + +PoolVector TextureBasisU::get_basisu_data() const { + + return data; +}; + +TextureBasisU::TextureBasisU() { + + flags = FLAGS_DEFAULT; + texture = VisualServer::get_singleton()->texture_create(); +}; + + +TextureBasisU::~TextureBasisU() { + + VisualServer::get_singleton()->free(texture); +}; + +#endif diff --git a/modules/basis_universal/texture_basisu.h b/modules/basis_universal/texture_basisu.h new file mode 100644 index 0000000000..20cfd65e3a --- /dev/null +++ b/modules/basis_universal/texture_basisu.h @@ -0,0 +1,47 @@ +#include "scene/resources/texture.h" + +#ifdef TOOLS_ENABLED +#include +#endif + +#include + +#if 0 +class TextureBasisU : public Texture { + + GDCLASS(TextureBasisU, Texture); + RES_BASE_EXTENSION("butex"); + + RID texture; + Size2 tex_size; + + uint32_t flags; + + PoolVector 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 &p_img); + + void set_basisu_data(const PoolVector& p_data); + + PoolVector get_basisu_data() const; + String get_img_path() const; + + TextureBasisU(); + ~TextureBasisU(); + +}; + +#endif diff --git a/modules/basis_universal/texture_bu.cpp b/modules/basis_universal/texture_bu.cpp deleted file mode 100644 index 73a945b33d..0000000000 --- a/modules/basis_universal/texture_bu.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#include "texture_bu.h" -#if 0 -#include "core/os/os.h" - -#ifdef TOOLS_ENABLED -#include "basisu_comp.h" -#endif - -#include "transcoder/basisu.h" - -void TextureBU::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_bu_data", "data"), &TextureBU::set_bu_data); - ClassDB::bind_method(D_METHOD("get_bu_data"), &TextureBU::get_data); - ClassDB::bind_method(D_METHOD("import"), &TextureBU::import); - - ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "bu_data"), "set_bu_data", "get_bu_data"); - -}; - -int TextureBU::get_width() const { - - return tex_size.x; -}; - -int TextureBU::get_height() const { - - return tex_size.y; -}; - -RID TextureBU::get_rid() const { - - return texture; -}; - - -bool TextureBU::has_alpha() const { - - return false; -}; - -void TextureBU::set_flags(uint32_t p_flags) { - - flags = p_flags; - VisualServer::get_singleton()->texture_set_flags(texture, p_flags); -}; - -uint32_t TextureBU::get_flags() const { - - return flags; -}; - - -void TextureBU::set_bu_data(const PoolVector& p_data) { - -#ifdef TOOLS_ENABLED - data = p_data; -#endif - - PoolVector::Read r = p_data.read(); - 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(NULL); - - 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); - PoolVector gpudata; - gpudata.resize(info.m_total_blocks * block_size); - - { - PoolVector::Write w = gpudata.write(); - uint8_t* dst = w.ptr(); - for (int i=0; i img; - img.instance(); - img->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata); - - VisualServer::get_singleton()->texture_allocate(texture, tex_size.x, tex_size.y, 0, img->get_format(), VS::TEXTURE_TYPE_2D, flags); - VisualServer::get_singleton()->texture_set_data(texture, img); -}; - -Error TextureBU::import(const Ref& p_img) { - -#ifdef TOOLS_ENABLED - - PoolVector 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 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; - - PoolVector vec = copy->get_data(); - { - PoolVector::Read r = vec.read(); - 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()); - - { - PoolVector::Write w = budata.write(); - memcpy(w.ptr(), &buvec[0], budata.size()); - }; - }; - - set_bu_data(budata); - - return OK; -#else - - return ERR_UNAVAILABLE; -#endif -}; - - -PoolVector TextureBU::get_bu_data() const { - - return data; -}; - -TextureBU::TextureBU() { - - flags = FLAGS_DEFAULT; - texture = VisualServer::get_singleton()->texture_create(); -}; - - -TextureBU::~TextureBU() { - - VisualServer::get_singleton()->free(texture); -}; - -#endif diff --git a/modules/basis_universal/texture_bu.h b/modules/basis_universal/texture_bu.h deleted file mode 100644 index 9ec9194a96..0000000000 --- a/modules/basis_universal/texture_bu.h +++ /dev/null @@ -1,47 +0,0 @@ -#include "scene/resources/texture.h" - -#ifdef TOOLS_ENABLED -#include "thirdparty/basis_universal/basisu_comp.h" -#endif - -#include "thirdparty/basis_universal/transcoder/basisu.h" - -#if 0 -class TextureBU : public Texture { - - GDCLASS(TextureBU, Texture); - RES_BASE_EXTENSION("butex"); - - RID texture; - Size2 tex_size; - - uint32_t flags; - - PoolVector 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 &p_img); - - void set_bu_data(const PoolVector& p_data); - - PoolVector get_bu_data() const; - String get_img_path() const; - - TextureBU(); - ~TextureBU(); - -}; - -#endif -- cgit v1.2.3