fix: immediately upload sprites when they become visible again#3087
fix: immediately upload sprites when they become visible again#3087contariaa wants to merge 2 commits intoCaffeineMC:devfrom
Conversation
this still has a small delay between the sprite being marked as active again and the sprite being ticked to fix that the SpriteContents.Ticker could be stored in SpriteContents and ensureUpload() called when the sprite is marked as active (after being inactive)
| return; | ||
| } | ||
|
|
||
| Minecraft.getInstance().getTextureManager().getTexture(atlas).bind(); |
There was a problem hiding this comment.
Revisiting this, its probably problematic to change the bound texture here since we can't know at what point in the code a sprite is being marked active and it might mess up render state.
There was a problem hiding this comment.
This issue is not present with just the first commit, but as stated in the initial pr message the behaviour from just the first commit is not 100% correct since it leaves a delay between the texture becoming visible and when its reticked
There was a problem hiding this comment.
is there a safe approach to this? Does anyone know whether this is safe?
|
Do you have a safe and correct approach to this? it seems you expressed some doubt about the method last year. This PR has also accumulated merge conflicts. It should be profiled to see if there's a performance cost to the second change you made (and there were concerns for safety). |
|
I don't know of any way to achieve instant sprite updates safely, the problem is that the hooks for marking a sprite as active may be called at any time before they are rendered, which makes the sprite upload fundamentally unsafe (it has to bind the sprite texture to upload, thus changing render state).
If there is interest I can look into porting the first commit, while it still shows the old frame until the sprite is next ticked, it's still better than having the old frame visible until a new frame is uploaded in my opinion. |
|
Yeah I think the first commit would still be an improvement as you said. Would be interesting see what it looks like in practice with the reproducer shown in the referenced issue. |
When a sprite becomes active again after skipping uploads, it won't immediately update to its correct state, instead it will only do so the next time the frame index changes.
I initially fixed this by just ensuring it will always upload the first tick after becoming active again, however that still leaves the time between being marked as active and being ticked where the texture would be wrong.
The fix for that is to ensure the upload right when the sprite is marked as active, which means we have to look up and bind the atlas texture everytime that happens. I'm unsure about the performance cost of that, if it's a problem I can revert the second commit, the first one alone is still significantly better than the current behaviour.
Closes #2514