diff options
author | clayjohn <claynjohn@gmail.com> | 2022-10-12 12:45:47 -0700 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2022-10-14 08:02:28 -0700 |
commit | b6f44859d7ab5b128d71ce0d64b46b171b9357aa (patch) | |
tree | c472b1e1f9e20dc541fc55aaca5b9bc66ec77072 /servers | |
parent | 09b1a6f85f3f1ae1c7771d215770d9667747f198 (diff) |
Implement multiple clip_children modes for CanvasItems
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/renderer_rd/effects/copy_effects.cpp | 4 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp | 16 | ||||
-rw-r--r-- | servers/rendering_server.cpp | 3 | ||||
-rw-r--r-- | servers/rendering_server.h | 3 |
4 files changed, 18 insertions, 8 deletions
diff --git a/servers/rendering/renderer_rd/effects/copy_effects.cpp b/servers/rendering/renderer_rd/effects/copy_effects.cpp index 53237c1dfb..a14228eb3d 100644 --- a/servers/rendering/renderer_rd/effects/copy_effects.cpp +++ b/servers/rendering/renderer_rd/effects/copy_effects.cpp @@ -357,8 +357,8 @@ void CopyEffects::copy_to_rect(RID p_source_rd_texture, RID p_dest_texture, cons copy.push_constant.flags |= COPY_FLAG_ALPHA_TO_ONE; } - copy.push_constant.section[0] = 0; - copy.push_constant.section[1] = 0; + copy.push_constant.section[0] = p_rect.position.x; + copy.push_constant.section[1] = p_rect.position.y; copy.push_constant.section[2] = p_rect.size.width; copy.push_constant.section[3] = p_rect.size.height; copy.push_constant.target[0] = p_rect.position.x; diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index 7c4d5238a0..7d524f949f 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -1112,13 +1112,17 @@ void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_co RID material = ci->material_owner == nullptr ? ci->material : ci->material_owner->material; if (ci->canvas_group != nullptr) { - if (ci->canvas_group->mode == RS::CANVAS_GROUP_MODE_OPAQUE) { + if (ci->canvas_group->mode == RS::CANVAS_GROUP_MODE_CLIP_AND_DRAW) { if (!p_to_backbuffer) { material = default_clip_children_material; } } else { if (material.is_null()) { - material = default_canvas_group_material; + if (ci->canvas_group->mode == RS::CANVAS_GROUP_MODE_CLIP_ONLY) { + material = default_clip_children_material; + } else { + material = default_canvas_group_material; + } } } } @@ -1445,10 +1449,12 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list); item_count = 0; - if (ci->canvas_group_owner->canvas_group->mode == RS::CANVAS_GROUP_MODE_OPAQUE) { + if (ci->canvas_group_owner->canvas_group->mode != RS::CANVAS_GROUP_MODE_TRANSPARENT) { Rect2i group_rect = ci->canvas_group_owner->global_rect_cache; texture_storage->render_target_copy_to_back_buffer(p_to_render_target, group_rect, false); - items[item_count++] = ci->canvas_group_owner; + if (ci->canvas_group_owner->canvas_group->mode == RS::CANVAS_GROUP_MODE_CLIP_AND_DRAW) { + items[item_count++] = ci->canvas_group_owner; + } } else if (!backbuffer_cleared) { texture_storage->render_target_clear_back_buffer(p_to_render_target, Rect2i(), Color(0, 0, 0, 0)); backbuffer_cleared = true; @@ -2752,7 +2758,9 @@ void fragment() { material_storage->shader_set_code(default_clip_children_shader, R"( // Default clip children shader. + shader_type canvas_item; + void fragment() { vec4 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0); COLOR.rgb = c.rgb; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index cf13118451..e1a3fe46be 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2636,7 +2636,8 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_MAX); BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_DISABLED); - BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_OPAQUE); + BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_CLIP_ONLY); + BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_CLIP_AND_DRAW); BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_TRANSPARENT); /* CANVAS LIGHT */ diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 6885d80301..3c6f46a985 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -1367,7 +1367,8 @@ public: enum CanvasGroupMode { CANVAS_GROUP_MODE_DISABLED, - CANVAS_GROUP_MODE_OPAQUE, + CANVAS_GROUP_MODE_CLIP_ONLY, + CANVAS_GROUP_MODE_CLIP_AND_DRAW, CANVAS_GROUP_MODE_TRANSPARENT, }; |