From a1f57d9f86c13c2eec0f465be485526012b24685 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 9 Apr 2020 12:38:21 +0200 Subject: [PATCH] Fix build for 4.0. --- layers/texture_layer_merger.cpp | 4 ++ layers/texture_layer_merger.h | 7 +++ texture_merger.cpp | 4 ++ texture_packer.cpp | 56 ++++++++++++++++++- texture_packer.h | 10 ++++ .../packer_image_resource_importer.cpp | 6 ++ 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/layers/texture_layer_merger.cpp b/layers/texture_layer_merger.cpp index cbbefe0..9bfd0e1 100644 --- a/layers/texture_layer_merger.cpp +++ b/layers/texture_layer_merger.cpp @@ -311,7 +311,11 @@ void TextureLayerMerger::merge() { } } + #if VERSION_MAJOR < 4 _image->create(_width, _height, (_texture_flags & Texture::FLAG_MIPMAPS) != 0, Image::FORMAT_RGBA8, data); + #else + _image->create(_width, _height, true, Image::FORMAT_RGBA8, data); + #endif } void TextureLayerMerger::write_base_color_to_array(PoolVector &data) { diff --git a/layers/texture_layer_merger.h b/layers/texture_layer_merger.h index 9556e8d..8b17901 100644 --- a/layers/texture_layer_merger.h +++ b/layers/texture_layer_merger.h @@ -30,6 +30,13 @@ SOFTWARE. #include "core/vector.h" #include "scene/resources/texture.h" +#include "core/version.h" + +#if VERSION_MAJOR >= 4 +#define PoolVector Vector +#define Texture Texture2D +#endif + class TextureLayerMerger : public Reference { GDCLASS(TextureLayerMerger, Reference); diff --git a/texture_merger.cpp b/texture_merger.cpp index bb6be8d..c87ffc7 100644 --- a/texture_merger.cpp +++ b/texture_merger.cpp @@ -87,7 +87,11 @@ void TextureMerger::set_packer(const Ref packer) { Vector TextureMerger::get_textures() { Vector r; for (int i = 0; i < _textures.size(); i++) { + #if VERSION_MAJOR < 4 r.push_back(_textures[i].get_ref_ptr()); + #else + r.push_back(_textures[i]); + #endif } return r; } diff --git a/texture_packer.cpp b/texture_packer.cpp index 2fe2894..46e693f 100644 --- a/texture_packer.cpp +++ b/texture_packer.cpp @@ -324,7 +324,7 @@ void TexturePacker::merge() { _generated_textures.resize(bins.size()); - for (int i = 0; i < bins.size(); ++i) { + for (uint32_t i = 0; i < bins.size(); ++i) { bin b = bins[i]; PoolByteArray data; @@ -344,7 +344,7 @@ void TexturePacker::merge() { } //Process rects - for (int j = 0; j < b.rects.size(); ++j) { + for (uint32_t j = 0; j < b.rects.size(); ++j) { rect_xywhf *r = b.rects[j]; Ref otext = r->original_texture; @@ -397,11 +397,16 @@ void TexturePacker::merge() { Ref texture; texture.instance(); + + #if VERSION_MAJOR < 4 texture->create_from_image(image, _texture_flags); + #else + texture->create_from_image(image); + #endif _generated_textures.set(i, texture); - for (int j = 0; j < b.rects.size(); ++j) { + for (uint32_t j = 0; j < b.rects.size(); ++j) { rect_xywhf *r = b.rects[j]; Ref at = r->atlas_texture; @@ -419,13 +424,58 @@ int TexturePacker::get_offset_for_format(Image::Format format) { return 3; case Image::FORMAT_RGBA8: return 4; + + case Image::FORMAT_L8: + case Image::FORMAT_LA8: + case Image::FORMAT_R8: + case Image::FORMAT_RG8: + case Image::FORMAT_RGBA4444: + case Image::FORMAT_RGB565: + case Image::FORMAT_RF: + case Image::FORMAT_RGF: + case Image::FORMAT_RGBF: + case Image::FORMAT_RGBAF: + case Image::FORMAT_RH: + case Image::FORMAT_RGH: + case Image::FORMAT_RGBH: + case Image::FORMAT_RGBAH: + case Image::FORMAT_RGBE9995: + case Image::FORMAT_DXT1: + case Image::FORMAT_DXT3: + case Image::FORMAT_DXT5: + case Image::FORMAT_RGTC_R: + case Image::FORMAT_RGTC_RG: + case Image::FORMAT_BPTC_RGBA: + case Image::FORMAT_BPTC_RGBF: + case Image::FORMAT_BPTC_RGBFU: + case Image::FORMAT_PVRTC2: + case Image::FORMAT_PVRTC2A: + case Image::FORMAT_PVRTC4: + case Image::FORMAT_PVRTC4A: + case Image::FORMAT_ETC: + case Image::FORMAT_ETC2_R11: + case Image::FORMAT_ETC2_R11S: + case Image::FORMAT_ETC2_RG11: + case Image::FORMAT_ETC2_RG11S: + case Image::FORMAT_ETC2_RGB8: + case Image::FORMAT_ETC2_RGBA8: + case Image::FORMAT_ETC2_RGB8A1: + case Image::FORMAT_ETC2_RA_AS_RG: + case Image::FORMAT_DXT5_RA_AS_RG: + case Image::FORMAT_MAX: + return 0; } return 0; } TexturePacker::TexturePacker() { + #if VERSION_MAJOR < 4 _texture_flags = Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER; + #else + _texture_flags = 0; + #endif + _max_atlas_size = 1024; _keep_original_atlases = false; _margin = 0; diff --git a/texture_packer.h b/texture_packer.h index e4b4edf..284440e 100644 --- a/texture_packer.h +++ b/texture_packer.h @@ -33,6 +33,16 @@ SOFTWARE. #include "rectpack2D/pack.h" +#include "core/version.h" + +#if VERSION_MAJOR >= 4 +#define PoolVector Vector +#define Texture Texture2D +#define PoolByteArray PackedByteArray + +#define REAL FLOAT +#endif + class TexturePacker : public Reference { GDCLASS(TexturePacker, Reference); diff --git a/texture_resource/packer_image_resource_importer.cpp b/texture_resource/packer_image_resource_importer.cpp index 51fa7e0..a9498c4 100644 --- a/texture_resource/packer_image_resource_importer.cpp +++ b/texture_resource/packer_image_resource_importer.cpp @@ -22,6 +22,12 @@ SOFTWARE. #include "packer_image_resource_importer.h" +#include "core/version.h" + +#if VERSION_MAJOR >= 4 +#define REAL FLOAT +#endif + String PackerImageResourceImporter::get_importer_name() const { return "packer_image_resource"; }