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

View File

@ -26,7 +26,10 @@ SOFTWARE.
#include "core/version.h"
#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/io/image.h"
#else

View File

@ -140,8 +140,13 @@ Ref<AtlasTexture> TextureMerger::add_texture(const Ref<Texture> &texture) {
Ref<AtlasTexture> tex = _packer->add_texture(texture);
if (!contains) {
if (has_method("_texture_added"))
#if VERSION_MAJOR < 4
if (has_method("_texture_added")) {
call("_texture_added", tex);
}
#else
GDVIRTUAL_CALL(_texture_added, tex);
#endif
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) {
if (_packer->unref_texture_index(index)) {
if (has_method("_texture_removed"))
#if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed");
@ -184,8 +194,13 @@ bool TextureMerger::unref_texture_index(const int index) {
bool TextureMerger::unref_texture(const Ref<Texture> &texture) {
if (_packer->unref_texture(texture)) {
if (has_method("_texture_removed"))
#if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed");
@ -200,8 +215,13 @@ bool TextureMerger::unref_texture(const Ref<Texture> &texture) {
void TextureMerger::remove_texture_index(const int index) {
_packer->remove_texture_index(index);
if (has_method("_texture_removed"))
#if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed");
@ -211,8 +231,13 @@ void TextureMerger::remove_texture_index(const int index) {
void TextureMerger::remove_texture(const Ref<Texture> &texture) {
_packer->remove_texture(texture);
if (has_method("_texture_removed"))
#if VERSION_MAJOR < 4
if (has_method("_texture_removed")) {
call("_texture_removed");
}
#else
GDVIRTUAL_CALL(_texture_removed);
#endif
emit_signal("texture_removed");
@ -237,8 +262,13 @@ int TextureMerger::get_generated_texture_count() {
void TextureMerger::merge() {
_packer->merge();
if (has_method("_texture_merged"))
#if VERSION_MAJOR < 4
if (has_method("_texture_merged")) {
call("_texture_merged");
}
#else
GDVIRTUAL_CALL(_texture_merged);
#endif
emit_signal("texture_merged");
}
@ -246,7 +276,12 @@ void TextureMerger::merge() {
TextureMerger::TextureMerger() {
_automatic_merge = false;
#if VERSION_MAJOR < 4
_packer.instance();
#else
_packer.instantiate();
#endif
_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_removed"));
#if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_texture_merged"));
BIND_VMETHOD(MethodInfo("_texture_added", PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "AtlasTexture")));
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("set_dirty", "value"), &TextureMerger::set_dirty);

View File

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

View File

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

View File

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

View File

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