Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix rendering tiles using nested AtlasTextures #76703

Merged

Conversation

kleonc
Copy link
Member

@kleonc kleonc commented May 3, 2023

In #68960 rendering TileMap tiles was changed from:

tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map, clip_uv);

to:
VisualServerCanvasHelper::tilemap_add_rect(canvas_item, rect, tex->get_rid(), r, modulate, c.transpose, normal_map.is_valid() ? normal_map->get_rid() : RID(), clip_uv);

AtlasTexture's override of the Texture::draw_rect_region was properly handling nested AtlasTextures, but VisualServerCanvasHelper::tilemap_add_rect is not, it uses the passed rects directly within the VisualServer.

This PR adds Texture::get_combined_rect_region virtual method which returns the proper final dst/src rects in case of nested AtlasTextures. Such rects can be passed to VisualServerCanvasHelper::tilemap_add_rect and alike.
I've changed only the TileMap to use this new method, not sure if anything else would need to be changed too (like fonts or anything else changed in #68960? 馃).
Not sure if that's the best solution but it works. 馃檭

Fixes #76686.

Also removed MeshTexture::get_rect_region override as it was doing the same thing as Texture::get_rect_region anyway.

@kleonc kleonc added this to the 3.6 milestone May 3, 2023
@kleonc kleonc requested a review from lawnjelly May 3, 2023 16:20
@kleonc kleonc requested a review from a team as a code owner May 3, 2023 16:20
@kleonc kleonc linked an issue May 3, 2023 that may be closed by this pull request
@kleonc kleonc force-pushed the tilemap-nested-atlas-texture-rendering-fix branch from 3dca77b to 12c923c Compare May 3, 2023 16:29
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Once @lawnjelly takes a look this should be good to merge

@lawnjelly
Copy link
Member

Sorry been away for week, great work on finding this! 馃憤
I'll go through the PR asap.

@lawnjelly
Copy link
Member

Looks like I didn't notice this function was virtual 馃槉 when making the PR and had some different implementations...

The general approach here looks good to me too, replacing the call to draw_rect_region() with some logic in a new function to translate the rects.

I wonder if for the complex texture types LargeTexture, MeshTexture we should just fallback to the old draw_rect_region(). MeshTexture uses a different API call, and LargeTexture probably isn't used enough to worry about accelerating. It would be nice to fix these too, I can do a follow up PR though, as it seems like AtlasTexture is the most pressing. It's a little pity because it makes things less elegant, but is more important it works to start with.

not sure if anything else would need to be changed too (like fonts or anything else changed

From a quick search in the original PR #68960 it seems like only the tilemap is calling draw_rect_region(), the fonts seem to be calling VisualServer directly, so shouldn't be affected unless I'm missing something (I'll look over in more detail this week).

The only thing I wasn't totally sure about was the name of the new function get_combined_rect_region(). I'm not sure it makes sense for e.g. an atlas texture, but I'm struggling to think of a better name. refine_rect_region()? Not sure. 馃

@lawnjelly
Copy link
Member

Am now working on a slightly modified version of this PR (will add coauthor with @kleonc as he found the problem / fix) that should fix all the cases, so maybe we can hold off on merging this until we have the other PR for comparison / discussion.

@akien-mga akien-mga merged commit e250950 into godotengine:3.x May 8, 2023
13 checks passed
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Am now working on a slightly modified version of this PR (will add coauthor with @kleonc as he found the problem / fix) that should fix all the cases, so maybe we can hold off on merging this until we have the other PR for comparison / discussion.

Oops, I hadn't seen this comment and this PR had two approvals so I went ahead and merged it.

#76775 can probably be updated to include a revert of the changes that would not be necessary with that other approach, so it can still be evaluated as a potentially better option to merge later on.

@kleonc kleonc deleted the tilemap-nested-atlas-texture-rendering-fix branch May 8, 2023 13:09
@lawnjelly
Copy link
Member

Oops! 馃槃 Is okay, I'll rebase. This PR does fix the major bug, but we want to catch the other cases as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong atlas coordinates
4 participants