Work on fixing compile for 4.0.

This commit is contained in:
Relintai 2022-02-08 11:53:26 +01:00
parent b78a87d658
commit ae4d222fba
7 changed files with 129 additions and 18 deletions

View File

@ -22,6 +22,8 @@ SOFTWARE.
#include "texture_layer_merger.h" #include "texture_layer_merger.h"
#include "core/version.h"
int TextureLayerMerger::get_width() const { int TextureLayerMerger::get_width() const {
return _width; return _width;
} }
@ -66,7 +68,11 @@ Ref<ImageTexture> TextureLayerMerger::get_result_as_texture() const {
ERR_FAIL_COND_V(!_image.is_valid(), Ref<ImageTexture>()); ERR_FAIL_COND_V(!_image.is_valid(), Ref<ImageTexture>());
Ref<ImageTexture> tex; Ref<ImageTexture> tex;
#if VERSION_MAJOR < 4
tex.instance(); tex.instance();
#else
tex.instantiate();
#endif
tex->create_from_image(_image); tex->create_from_image(_image);
return tex; return tex;
@ -160,7 +166,11 @@ void TextureLayerMerger::set_rect(const int p_index, const Rect2 &p_rect) {
void TextureLayerMerger::remove_texture(const int p_index) { void TextureLayerMerger::remove_texture(const int p_index) {
ERR_FAIL_INDEX(p_index, _entries.size()); ERR_FAIL_INDEX(p_index, _entries.size());
#if VERSION_MAJOR < 4
return _entries.remove(p_index); return _entries.remove(p_index);
#else
return _entries.remove_at(p_index);
#endif
} }
int TextureLayerMerger::get_texture_count() { int TextureLayerMerger::get_texture_count() {
@ -174,8 +184,13 @@ void TextureLayerMerger::clear() {
void TextureLayerMerger::merge() { void TextureLayerMerger::merge() {
ERR_FAIL_COND(_width <= 0 || _height <= 0); ERR_FAIL_COND(_width <= 0 || _height <= 0);
if (!_image.is_valid()) if (!_image.is_valid()) {
#if VERSION_MAJOR < 4
_image.instance(); _image.instance();
#else
_image.instantiate();
#endif
}
PoolVector<uint8_t> data; PoolVector<uint8_t> data;
data.resize(_width * _height * 4); data.resize(_width * _height * 4);
@ -209,7 +224,11 @@ void TextureLayerMerger::merge() {
ERR_CONTINUE(!atlas.is_valid()); ERR_CONTINUE(!atlas.is_valid());
#if VERSION_MAJOR < 4
input_image = atlas->get_data(); input_image = atlas->get_data();
#else
input_image = atlas->get_image();
#endif
Rect2 region = altas_texture->get_region(); Rect2 region = altas_texture->get_region();
@ -225,7 +244,11 @@ void TextureLayerMerger::merge() {
if (rh > atlas_h) if (rh > atlas_h)
rh = atlas_h; rh = atlas_h;
} else { } else {
#if VERSION_MAJOR < 4
input_image = e.texture->get_data(); input_image = e.texture->get_data();
#else
input_image = e.texture->get_image();
#endif
} }
ERR_CONTINUE(!input_image.is_valid()); ERR_CONTINUE(!input_image.is_valid());

View File

@ -26,7 +26,10 @@ SOFTWARE.
#include "core/version.h" #include "core/version.h"
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
#include "core/object/reference.h" #include "core/object/ref_counted.h"
#ifndef Reference
#define Reference RefCounted
#endif
#include "core/templates/vector.h" #include "core/templates/vector.h"
#include "core/io/image.h" #include "core/io/image.h"
#else #else

View File

@ -140,8 +140,13 @@ Ref<AtlasTexture> TextureMerger::add_texture(const Ref<Texture> &texture) {
Ref<AtlasTexture> tex = _packer->add_texture(texture); Ref<AtlasTexture> tex = _packer->add_texture(texture);
if (!contains) { if (!contains) {
if (has_method("_texture_added")) #if VERSION_MAJOR < 4
if (has_method("_texture_added")) {
call("_texture_added", tex); call("_texture_added", tex);
}
#else
GDVIRTUAL_CALL(_texture_added, tex);
#endif
emit_signal("texture_added", tex); emit_signal("texture_added", tex);
@ -169,8 +174,13 @@ Ref<AtlasTexture> TextureMerger::get_texture_index(const int index) {
bool TextureMerger::unref_texture_index(const int index) { bool TextureMerger::unref_texture_index(const int index) {
if (_packer->unref_texture_index(index)) { if (_packer->unref_texture_index(index)) {
if (has_method("_texture_removed")) #if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed"); call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed"); emit_signal("texture_removed");
@ -184,8 +194,13 @@ bool TextureMerger::unref_texture_index(const int index) {
bool TextureMerger::unref_texture(const Ref<Texture> &texture) { bool TextureMerger::unref_texture(const Ref<Texture> &texture) {
if (_packer->unref_texture(texture)) { if (_packer->unref_texture(texture)) {
if (has_method("_texture_removed")) #if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed"); call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed"); emit_signal("texture_removed");
@ -200,8 +215,13 @@ bool TextureMerger::unref_texture(const Ref<Texture> &texture) {
void TextureMerger::remove_texture_index(const int index) { void TextureMerger::remove_texture_index(const int index) {
_packer->remove_texture_index(index); _packer->remove_texture_index(index);
if (has_method("_texture_removed")) #if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed"); call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed"); emit_signal("texture_removed");
@ -211,8 +231,13 @@ void TextureMerger::remove_texture_index(const int index) {
void TextureMerger::remove_texture(const Ref<Texture> &texture) { void TextureMerger::remove_texture(const Ref<Texture> &texture) {
_packer->remove_texture(texture); _packer->remove_texture(texture);
if (has_method("_texture_removed")) #if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed"); call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed"); emit_signal("texture_removed");
@ -237,8 +262,13 @@ int TextureMerger::get_generated_texture_count() {
void TextureMerger::merge() { void TextureMerger::merge() {
_packer->merge(); _packer->merge();
if (has_method("_texture_merged")) #if VERSION_MAJOR < 4
if (has_method("_texture_merged")) {
call("_texture_merged"); call("_texture_merged");
}
#else
GDVIRTUAL_CALL(_texture_merged);
#endif
emit_signal("texture_merged"); emit_signal("texture_merged");
} }
@ -246,7 +276,12 @@ void TextureMerger::merge() {
TextureMerger::TextureMerger() { TextureMerger::TextureMerger() {
_automatic_merge = false; _automatic_merge = false;
#if VERSION_MAJOR < 4
_packer.instance(); _packer.instance();
#else
_packer.instantiate();
#endif
_packer->set_keep_original_atlases(false); _packer->set_keep_original_atlases(false);
} }
@ -278,9 +313,15 @@ void TextureMerger::_bind_methods() {
ADD_SIGNAL(MethodInfo("texture_added", PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "AtlasTexture"))); ADD_SIGNAL(MethodInfo("texture_added", PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "AtlasTexture")));
ADD_SIGNAL(MethodInfo("texture_removed")); ADD_SIGNAL(MethodInfo("texture_removed"));
#if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_texture_merged")); BIND_VMETHOD(MethodInfo("_texture_merged"));
BIND_VMETHOD(MethodInfo("_texture_added", PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "AtlasTexture"))); BIND_VMETHOD(MethodInfo("_texture_added", PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "AtlasTexture")));
BIND_VMETHOD(MethodInfo("_texture_removed")); BIND_VMETHOD(MethodInfo("_texture_removed"));
#else
GDVIRTUAL_BIND(_texture_merged);
GDVIRTUAL_BIND(_texture_added, "texture");
GDVIRTUAL_BIND(_texture_removed);
#endif
ClassDB::bind_method(D_METHOD("get_dirty"), &TextureMerger::get_dirty); ClassDB::bind_method(D_METHOD("get_dirty"), &TextureMerger::get_dirty);
ClassDB::bind_method(D_METHOD("set_dirty", "value"), &TextureMerger::set_dirty); ClassDB::bind_method(D_METHOD("set_dirty", "value"), &TextureMerger::set_dirty);

View File

@ -87,6 +87,12 @@ public:
void merge(); void merge();
#if VERSION_MAJOR >= 4
GDVIRTUAL0(_texture_merged);
GDVIRTUAL1(_texture_added, Ref<AtlasTexture>);
GDVIRTUAL0(_texture_removed);
#endif
TextureMerger(); TextureMerger();
~TextureMerger(); ~TextureMerger();

View File

@ -83,7 +83,11 @@ Ref<AtlasTexture> TexturePacker::add_texture(const Ref<Texture> &texture) {
} }
Ref<AtlasTexture> tex; Ref<AtlasTexture> tex;
#if VERSION_MAJOR < 4
tex.instance(); tex.instance();
#else
tex.instantiate();
#endif
tex->set_atlas(atlas_text->get_atlas()); tex->set_atlas(atlas_text->get_atlas());
tex->set_region(atlas_text->get_region()); tex->set_region(atlas_text->get_region());
@ -120,7 +124,11 @@ Ref<AtlasTexture> TexturePacker::add_texture(const Ref<Texture> &texture) {
} }
Ref<AtlasTexture> tex; Ref<AtlasTexture> tex;
#if VERSION_MAJOR < 4
tex.instance(); tex.instance();
#else
tex.instantiate();
#endif
//Temp setup, so the texture is usable even while the atlases are generating. //Temp setup, so the texture is usable even while the atlases are generating.
tex->set_atlas(texture); tex->set_atlas(texture);
@ -200,7 +208,11 @@ bool TexturePacker::unref_texture_index(const int index) {
int rc = --(r->refcount); int rc = --(r->refcount);
if (rc <= 0) { if (rc <= 0) {
#if VERSION_MAJOR < 4
_rects.remove(index); _rects.remove(index);
#else
_rects.remove_at(index);
#endif
r->original_texture.unref(); r->original_texture.unref();
r->atlas_texture.unref(); r->atlas_texture.unref();
@ -226,11 +238,14 @@ bool TexturePacker::unref_texture(const Ref<Texture> &texture) {
t = r->original_texture; t = r->original_texture;
if (t == texture) { if (t == texture) {
int rc = --(r->refcount); int rc = --(r->refcount);
if (rc <= 0) { if (rc <= 0) {
#if VERSION_MAJOR < 4
_rects.remove(i); _rects.remove(i);
#else
_rects.remove_at(i);
#endif
r->original_texture.unref(); r->original_texture.unref();
r->atlas_texture.unref(); r->atlas_texture.unref();
@ -271,8 +286,11 @@ void TexturePacker::remove_texture(const Ref<Texture> &texture) {
t = r->original_texture; t = r->original_texture;
if (t == texture) { if (t == texture) {
#if VERSION_MAJOR < 4
_rects.remove(i); _rects.remove(i);
#else
_rects.remove_at(i);
#endif
r->original_texture.unref(); r->original_texture.unref();
r->atlas_texture.unref(); r->atlas_texture.unref();
@ -364,7 +382,11 @@ void TexturePacker::merge() {
ERR_CONTINUE(!otext.is_valid()); ERR_CONTINUE(!otext.is_valid());
#if VERSION_MAJOR < 4
Ref<Image> img = otext->get_data(); Ref<Image> img = otext->get_data();
#else
Ref<Image> img = otext->get_image();
#endif
ERR_CONTINUE(!img.is_valid()); ERR_CONTINUE(!img.is_valid());
@ -383,7 +405,6 @@ void TexturePacker::merge() {
int row_width = (r->w - 2 * _margin); int row_width = (r->w - 2 * _margin);
for (int x = 0; x < row_width; ++x) { for (int x = 0; x < row_width; ++x) {
for (int sx = 0; sx < input_format_offset; ++sx) { for (int sx = 0; sx < input_format_offset; ++sx) {
data.set(start_indx + (x * 4) + sx, image_data[orig_img_indx + sx + (x * input_format_offset)]); data.set(start_indx + (x * 4) + sx, image_data[orig_img_indx + sx + (x * input_format_offset)]);
} }
@ -392,11 +413,19 @@ void TexturePacker::merge() {
} }
Ref<Image> image; Ref<Image> image;
#if VERSION_MAJOR < 4
image.instance(); image.instance();
#else
image.instantiate();
#endif
image->create(b.size.w, b.size.h, false, Image::FORMAT_RGBA8, data); image->create(b.size.w, b.size.h, false, Image::FORMAT_RGBA8, data);
Ref<ImageTexture> texture; Ref<ImageTexture> texture;
#if VERSION_MAJOR < 4
texture.instance(); texture.instance();
#else
texture.instantiate();
#endif
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
texture->create_from_image(image, _texture_flags); texture->create_from_image(image, _texture_flags);
@ -452,11 +481,6 @@ int TexturePacker::get_offset_for_format(const Image::Format format) {
case Image::FORMAT_PVRTC2A: case Image::FORMAT_PVRTC2A:
case Image::FORMAT_PVRTC4: case Image::FORMAT_PVRTC4:
case Image::FORMAT_PVRTC4A: case Image::FORMAT_PVRTC4A:
#else
case Image::FORMAT_PVRTC1_2:
case Image::FORMAT_PVRTC1_2A:
case Image::FORMAT_PVRTC1_4:
case Image::FORMAT_PVRTC1_4A:
#endif #endif
case Image::FORMAT_ETC: case Image::FORMAT_ETC:
case Image::FORMAT_ETC2_R11: case Image::FORMAT_ETC2_R11:

View File

@ -22,11 +22,16 @@ SOFTWARE.
#include "editor_plugin_packer_image_resource.h" #include "editor_plugin_packer_image_resource.h"
#include "core/version.h"
void EditorPluginPackerImageResource::_notification(int p_what) { void EditorPluginPackerImageResource::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: case NOTIFICATION_ENTER_TREE:
#if VERSION_MAJOR < 4
_importer.instance(); _importer.instance();
#else
_importer.instantiate();
#endif
add_import_plugin(_importer); add_import_plugin(_importer);
break; break;

View File

@ -74,14 +74,23 @@ Error PackerImageResourceImporter::import(const String &p_source_file, const Str
float scale = p_options["scale"]; float scale = p_options["scale"];
Ref<Image> image; Ref<Image> image;
#if VERSION_MAJOR < 4
image.instance(); image.instance();
#else
image.instantiate();
#endif
Error err = ImageLoader::load_image(p_source_file, image, NULL, hdr_as_srgb, scale); Error err = ImageLoader::load_image(p_source_file, image, NULL, hdr_as_srgb, scale);
if (err != OK) if (err != OK) {
return err; return err;
}
Ref<PackerImageResource> res; Ref<PackerImageResource> res;
#if VERSION_MAJOR < 4
res.instance(); res.instance();
#else
res.instantiate();
#endif
res->set_data(image); res->set_data(image);