diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-08-30 16:02:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-30 16:02:12 +0200 |
commit | 348eb4e4c5830628241470d747642c5cf040ab3b (patch) | |
tree | ba2f20939abbdbc773d0b75fcda6164a4f2efd84 /scene/2d/tile_map.cpp | |
parent | a1d7c496b923a247cd9f43552f783592f8f33791 (diff) | |
parent | 3bb5abbc35b6690768f32db7becf874febc25713 (diff) |
Merge pull request #10361 from RandomShaper/tilemap-global-mtl
Let TileMap apply its material
Diffstat (limited to 'scene/2d/tile_map.cpp')
-rw-r--r-- | scene/2d/tile_map.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index d41db1dce5..b1cc8c226a 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -336,6 +336,7 @@ void TileMap::_update_dirty_quadrants() { if (mat.is_valid()) vs->canvas_item_set_material(canvas_item, mat->get_rid()); vs->canvas_item_set_parent(canvas_item, get_canvas_item()); + _update_item_material_state(canvas_item); Transform2D xform; xform.set_origin(q.pos); vs->canvas_item_set_transform(canvas_item, xform); @@ -780,6 +781,35 @@ void TileMap::_clear_quadrants() { } } +void TileMap::set_material(const Ref<Material> &p_material) { + + CanvasItem::set_material(p_material); + _update_all_items_material_state(); +} + +void TileMap::set_use_parent_material(bool p_use_parent_material) { + + CanvasItem::set_use_parent_material(p_use_parent_material); + _update_all_items_material_state(); +} + +void TileMap::_update_all_items_material_state() { + + for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { + + Quadrant &q = E->get(); + for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) { + + _update_item_material_state(E->get()); + } + } +} + +void TileMap::_update_item_material_state(const RID &p_canvas_item) { + + VS::get_singleton()->canvas_item_set_use_parent_material(p_canvas_item, get_use_parent_material() || get_material().is_valid()); +} + void TileMap::clear() { _clear_quadrants(); |