Fix build for 4.0.

This commit is contained in:
Relintai 2020-04-09 12:38:21 +02:00
parent b17c174906
commit a1f57d9f86
6 changed files with 84 additions and 3 deletions

View File

@ -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<uint8_t> &data) {

View File

@ -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);

View File

@ -87,7 +87,11 @@ void TextureMerger::set_packer(const Ref<TexturePacker> packer) {
Vector<Variant> TextureMerger::get_textures() {
Vector<Variant> 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;
}

View File

@ -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<Texture> otext = r->original_texture;
@ -397,11 +397,16 @@ void TexturePacker::merge() {
Ref<ImageTexture> 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<AtlasTexture> 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;

View File

@ -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);

View File

@ -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";
}