mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-08 20:09:36 +01:00
Ported: Multirect - Fix refining regions for all derived Textures
Fixes allowing all derived texture types to modify region prior to rendering.
- lawnjelly
43b6205887
This commit is contained in:
parent
8642a7c722
commit
37273d29c9
@ -609,17 +609,30 @@ void TileMap::update_dirty_quadrants() {
|
|||||||
|
|
||||||
modulate = Color(modulate.r * self_modulate.r - col, modulate.g * self_modulate.g - col,
|
modulate = Color(modulate.r * self_modulate.r - col, modulate.g * self_modulate.g - col,
|
||||||
modulate.b * self_modulate.b - col, modulate.a * self_modulate.a);
|
modulate.b * self_modulate.b - col, modulate.a * self_modulate.a);
|
||||||
|
|
||||||
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 {
|
||||||
Rect2 dst_rect;
|
Texture::RefineRectResult res = tex->refine_rect_region(rect, r);
|
||||||
Rect2 src_rect;
|
switch (res) {
|
||||||
if (tex->get_combined_rect_region(rect, r, dst_rect, src_rect)) {
|
case Texture::REFINE_RECT_RESULT_DRAW: {
|
||||||
if (!multirect_started) {
|
if (!multirect_started) {
|
||||||
multirect_started = true;
|
multirect_started = true;
|
||||||
RenderingServerCanvasHelper::tilemap_begin();
|
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);
|
||||||
|
} break;
|
||||||
|
case Texture::REFINE_RECT_RESULT_FALLBACK: {
|
||||||
|
if (multirect_started) {
|
||||||
|
// If we are currently writing a multirect, we must flush
|
||||||
|
// to ensure there are no issues due to overlap.
|
||||||
|
RenderingServerCanvasHelper::tilemap_end();
|
||||||
|
multirect_started = false;
|
||||||
|
}
|
||||||
|
tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map, clip_uv);
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +65,6 @@ 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);
|
||||||
@ -1031,6 +1027,19 @@ 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);
|
||||||
}
|
}
|
||||||
|
Texture::RefineRectResult AtlasTexture::refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const {
|
||||||
|
if (!atlas.is_valid()) {
|
||||||
|
return REFINE_RECT_RESULT_NO_DRAW;
|
||||||
|
}
|
||||||
|
Rect2 temp_rect = r_dst_rect;
|
||||||
|
Rect2 temp_src_rect = r_src_rect;
|
||||||
|
|
||||||
|
if (get_rect_region(temp_rect, temp_src_rect, r_dst_rect, r_src_rect)) {
|
||||||
|
return atlas->refine_rect_region(r_dst_rect, r_src_rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
return REFINE_RECT_RESULT_NO_DRAW;
|
||||||
|
}
|
||||||
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 {
|
||||||
if (!atlas.is_valid()) {
|
if (!atlas.is_valid()) {
|
||||||
return;
|
return;
|
||||||
@ -1073,18 +1082,6 @@ 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;
|
||||||
|
@ -59,6 +59,12 @@ public:
|
|||||||
FLAG_MIRRORED_REPEAT = RenderingServer::TEXTURE_FLAG_MIRRORED_REPEAT
|
FLAG_MIRRORED_REPEAT = RenderingServer::TEXTURE_FLAG_MIRRORED_REPEAT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum RefineRectResult {
|
||||||
|
REFINE_RECT_RESULT_DRAW,
|
||||||
|
REFINE_RECT_RESULT_FALLBACK,
|
||||||
|
REFINE_RECT_RESULT_NO_DRAW,
|
||||||
|
};
|
||||||
|
|
||||||
virtual int get_width() const = 0;
|
virtual int get_width() const = 0;
|
||||||
virtual int get_height() const = 0;
|
virtual int get_height() const = 0;
|
||||||
virtual Size2 get_size() const;
|
virtual Size2 get_size() const;
|
||||||
@ -75,7 +81,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 RefineRectResult refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const { return REFINE_RECT_RESULT_DRAW; }
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const { return Ref<Image>(); }
|
virtual Ref<Image> get_data() const { return Ref<Image>(); }
|
||||||
|
|
||||||
@ -143,6 +149,7 @@ 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 RefineRectResult refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const { return ((w | h) == 0) ? REFINE_RECT_RESULT_NO_DRAW : REFINE_RECT_RESULT_DRAW; }
|
||||||
void set_storage(Storage p_storage);
|
void set_storage(Storage p_storage);
|
||||||
Storage get_storage() const;
|
Storage get_storage() const;
|
||||||
|
|
||||||
@ -214,6 +221,7 @@ 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 RefineRectResult refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const { return ((w | h) == 0) ? REFINE_RECT_RESULT_NO_DRAW : REFINE_RECT_RESULT_DRAW; }
|
||||||
|
|
||||||
virtual bool has_alpha() const;
|
virtual bool has_alpha() const;
|
||||||
virtual void set_flags(uint32_t p_flags);
|
virtual void set_flags(uint32_t p_flags);
|
||||||
@ -275,7 +283,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 RefineRectResult refine_rect_region(Rect2 &r_dst_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;
|
||||||
|
|
||||||
@ -317,6 +325,7 @@ 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 RefineRectResult refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const { return REFINE_RECT_RESULT_FALLBACK; }
|
||||||
|
|
||||||
bool is_pixel_opaque(int p_x, int p_y) const;
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
||||||
|
|
||||||
@ -365,6 +374,7 @@ 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 RefineRectResult refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const { return REFINE_RECT_RESULT_FALLBACK; }
|
||||||
|
|
||||||
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