-
-
Notifications
You must be signed in to change notification settings - Fork 219
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial canvas
implementation
#1438
base: master
Are you sure you want to change the base?
Conversation
It seems like we can't properly handle scaled In this video I'm drawing a tight grid at various scales. The mouse cursor is forcing the redraw of the Video.del.2023-03-21.01-36-00.webmNotice how at 100% scale there are no rendering artifacts, but they appear at any other scale. I think that this can be worked around by the future PR where I'll add drawing a Another solution would be to keep a scaled surface cached somewhere, and use that one instead of the one in the If that doesn't work out, should we add a warning to avoid calling |
Another little edge case: what should we do if the If we decide to draw the "old" version, we could probably solve the "scaled" surface problem at the same time. |
With the latest commit this issue has been solved, and we now draw the surface with the "old" state. |
The latest commit fixes the scaling issue. Now it's time for input validation and cleanup. |
823ce6e
to
589a4a4
Compare
When using `cmd->rensurface = *rs;`, the padding bytes were being copied too. Issue found by valgrind.
This implements a COW cache to make `renderer.draw_canvas` operations result in their "current" state to be drawn on screen, and not their "altered" state.
This avoids artifacts caused by rounding errors in clipping. When we need the scaled version of a canvas, we check if we have already one cached in the current frame cache. If not we check if it was cached in the previous frame, and if so, we copy it to the current frame cache. If the scaled canvas is not found, we create one and push it to the current frame cache. We keep the cache of the previous frame to avoid recreating the same scaled canvas every frame.
I would suggest providing a ready to use |
Do we need that? A future PR will allow loading pixel data without going through Lua strings, but directly from a Btw don't merge this PR yet, as I'm looking into optimizing draw operations by using a pixel format that's more in line with the window pixel format. |
The description mentions that a future PR will allow better re-rendering on only parts of the canvas that changed for stuff like minimap, which means that this "canvas" functionality could be also useful for plugins like https://github.com/ThaCuber/equationgrapher or https://github.com/vincens2005/lite-snake for more performant rendering or at least that is how I interpreted it... Unless this allows the reuse of draw rect and text functions on top of the canvas, performing stuff like the mentioned minimap will require having to constantly deal with pixel data directly, so having a function that does the conversion for you already shouldn't be an optional thing. And as you may already know usually the canvas api provided on various platforms like web browsers, etc... is usually accompanied with various drawing functions for primitive shapes. People may expect more higher level facilities than what is actually provided by this "canvas" functionality which as you are pointing looks more like a generic image loader than what is known as an actual canvas
Maybe the design on the HTML5 canvas API could be used as a foundational idea, I'm not saying to implement all that functionality, but to have a solid idea of what its API should look like for something that is been called a "canvas" on Lite XL core.
Don't worry, I don't believe such important feature as exposed on this PR is mature yet for something that will play an important role on future plugin development. The user facing API needs to be given more thought even if this PR is only going to implement the foundation for it. |
As expressed multiple times on Discord, yes, that's one of the objectives of a future PR.
We will not add support for those.
The API of the basic |
This is just the minimum required to support
canvas
es.A future PR will implement more methods to draw on top of
canvas
es, and other utils.Another future PR will optimize
rencache
to allow re-rendering only the part ofcanvas
es that changed (which will be useful for things likeminimap
).Demo:
Closes #1182.