mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-03 01:19:38 +01:00
Ported: Fix rendering tiles using nested AtlasTextures
- kleonc
12c923cb8b
This commit is contained in:
parent
52ea64d04b
commit
8642a7c722
@ -612,11 +612,15 @@ void TileMap::update_dirty_quadrants() {
|
|||||||
if (r == Rect2()) {
|
if (r == Rect2()) {
|
||||||
tex->draw_rect(canvas_item, rect, false, modulate, c.transpose, normal_map);
|
tex->draw_rect(canvas_item, rect, false, modulate, c.transpose, normal_map);
|
||||||
} else {
|
} else {
|
||||||
if (!multirect_started) {
|
Rect2 dst_rect;
|
||||||
multirect_started = true;
|
Rect2 src_rect;
|
||||||
RenderingServerCanvasHelper::tilemap_begin();
|
if (tex->get_combined_rect_region(rect, r, dst_rect, src_rect)) {
|
||||||
|
if (!multirect_started) {
|
||||||
|
multirect_started = true;
|
||||||
|
RenderingServerCanvasHelper::tilemap_begin();
|
||||||
|
}
|
||||||
|
RenderingServerCanvasHelper::tilemap_add_rect(canvas_item, dst_rect, tex->get_rid(), src_rect, modulate, c.transpose, normal_map.is_valid() ? normal_map->get_rid() : RID(), clip_uv);
|
||||||
}
|
}
|
||||||
RenderingServerCanvasHelper::tilemap_add_rect(canvas_item, rect, tex->get_rid(), r, modulate, c.transpose, normal_map.is_valid() ? normal_map->get_rid() : RID(), clip_uv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<TileSet::ShapeData> shapes = tile_set->tile_get_shapes(c.id);
|
Vector<TileSet::ShapeData> shapes = tile_set->tile_get_shapes(c.id);
|
||||||
|
@ -65,6 +65,10 @@ bool Texture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Texture::get_combined_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_combined_rect, Rect2 &r_combined_src_rect) const {
|
||||||
|
return get_rect_region(p_rect, p_src_rect, r_combined_rect, r_combined_src_rect);
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::_bind_methods() {
|
void Texture::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_width"), &Texture::get_width);
|
ClassDB::bind_method(D_METHOD("get_width"), &Texture::get_width);
|
||||||
ClassDB::bind_method(D_METHOD("get_height"), &Texture::get_height);
|
ClassDB::bind_method(D_METHOD("get_height"), &Texture::get_height);
|
||||||
@ -1028,16 +1032,15 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
|
|||||||
atlas->draw_rect_region(p_canvas_item, dr, rc, p_modulate, p_transpose, p_normal_map);
|
atlas->draw_rect_region(p_canvas_item, dr, rc, p_modulate, p_transpose, p_normal_map);
|
||||||
}
|
}
|
||||||
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const {
|
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const {
|
||||||
//this might not necessarily work well if using a rect, needs to be fixed properly
|
|
||||||
if (!atlas.is_valid()) {
|
if (!atlas.is_valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 dr;
|
Rect2 dst;
|
||||||
Rect2 src_c;
|
Rect2 src;
|
||||||
get_rect_region(p_rect, p_src_rect, dr, src_c);
|
if (get_rect_region(p_rect, p_src_rect, dst, src)) {
|
||||||
|
atlas->draw_rect_region(p_canvas_item, dst, src, p_modulate, p_transpose, p_normal_map);
|
||||||
atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, p_normal_map);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
|
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
|
||||||
@ -1070,6 +1073,18 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AtlasTexture::get_combined_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_combined_rect, Rect2 &r_combined_src_rect) const {
|
||||||
|
if (!atlas.is_valid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Rect2 dst;
|
||||||
|
Rect2 src;
|
||||||
|
if (get_rect_region(p_rect, p_src_rect, dst, src)) {
|
||||||
|
return atlas->get_combined_rect_region(dst, src, r_combined_rect, r_combined_src_rect);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
|
bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
|
||||||
if (!atlas.is_valid()) {
|
if (!atlas.is_valid()) {
|
||||||
return true;
|
return true;
|
||||||
@ -1196,11 +1211,6 @@ void MeshTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const
|
|||||||
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
|
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
|
||||||
RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid);
|
RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid);
|
||||||
}
|
}
|
||||||
bool MeshTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
|
|
||||||
r_rect = p_rect;
|
|
||||||
r_src_rect = p_src_rect;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshTexture::is_pixel_opaque(int p_x, int p_y) const {
|
bool MeshTexture::is_pixel_opaque(int p_x, int p_y) const {
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,10 +32,10 @@
|
|||||||
|
|
||||||
#include "core/io/resource_loader.h"
|
#include "core/io/resource_loader.h"
|
||||||
#include "core/math/rect2.h"
|
#include "core/math/rect2.h"
|
||||||
|
#include "core/object/resource.h"
|
||||||
#include "core/os/mutex.h"
|
#include "core/os/mutex.h"
|
||||||
#include "core/os/rw_lock.h"
|
#include "core/os/rw_lock.h"
|
||||||
#include "core/os/thread_safe.h"
|
#include "core/os/thread_safe.h"
|
||||||
#include "core/object/resource.h"
|
|
||||||
#include "scene/resources/curve.h"
|
#include "scene/resources/curve.h"
|
||||||
#include "scene/resources/gradient.h"
|
#include "scene/resources/gradient.h"
|
||||||
#include "servers/rendering_server.h"
|
#include "servers/rendering_server.h"
|
||||||
@ -75,6 +75,7 @@ public:
|
|||||||
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
||||||
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
||||||
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
||||||
|
virtual bool get_combined_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_combined_rect, Rect2 &r_combined_src_rect) const;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const { return Ref<Image>(); }
|
virtual Ref<Image> get_data() const { return Ref<Image>(); }
|
||||||
|
|
||||||
@ -274,6 +275,7 @@ public:
|
|||||||
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
||||||
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
||||||
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
||||||
|
virtual bool get_combined_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_combined_rect, Rect2 &r_combined_src_rect) const;
|
||||||
|
|
||||||
bool is_pixel_opaque(int p_x, int p_y) const;
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
||||||
|
|
||||||
@ -315,7 +317,6 @@ public:
|
|||||||
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
||||||
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
||||||
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
||||||
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
|
||||||
|
|
||||||
bool is_pixel_opaque(int p_x, int p_y) const;
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user