-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: offscreen rendering #957
Conversation
Is this relevant to your commit? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to expose this in a somewhat isolated or decoupled way.
Specifically, I'm not convinced using a feature flag to switch between normal and offscreen rendering is the best API to satisfy the most common use case of this feature: taking a screenshot of (part of) the application.
I think maybe we could expose this as some kind of method in the new Window
argument that will be provided to the update
method in Application
once #930 is merged soon!
The API could look like this:
impl Application for Example {
// ...
fn update(&mut self, message: Message, _clipboard: &mut Clipboard, window: &mut Window<Message>) -> Command<Message> {
match message {
Message::TakeScreenshot => {
window.take_screenshot(window::Region::All, Message::ScreenshotTaken);
}
Message::ScreenshotTaken(pixels) => {
// Do stuff with the pixels!
}
}
Command::none()
}
// ...
}
After every call to Application::update
, the runtime would check the Window
argument and call special methods on the Compositor
to take the screenshot. There is no need for the window and offscreen drawing logics to share the same code path.
What do you think?
@13r0ck
I agree, the feature flag was just a simple way to get started.
I like the idea, but the problem here would be that rendering itself has nothing to do with the windowing, the "presentation" is what couples them. For example, in The problem becomes apparent if you were to create something like a headless mode (which I'm currently working on), there we don't have a Still, even though we are not exactly using a proper |
I like this idea a lot.
having with #930 closed via #1019, I was thinking that an api for taking screenshots could be brought up in I think adding a method to |
e6ab610
to
8b0f2e6
Compare
Superseded by #1783. |
Allows the application to render in an offscreen buffer instead of the onscreen framebuffer. This would allow the application to render and save the screen content into a file.
I'm not sure how to expose this feature to the application (expose the
&[u8]
to theApplication
trait), so I'm opening a draft PT to get some ideas.Currently, this is gated under the
offscreen
feature flag, which renders the first frame of the application to aframebuffer.png
file.Some ideas
New method
Create a new method on the
Application
trait, something likeframe(&mut self, buffer: &[u8])
and call it on the event loop (application.frame(&pixels)
). The problem would be gating this through the feature, since we needoffscreen
rendering enabled on the backend to be able to read the content of the buffer.New trait
Almost the same as the new method idea, just instead we add it to a new
OffscreenProgram
trait, or later on for example, aHeadlessApplication
(I'm working on enabling Iced to run headless, and this could be used in conjunction to enable server side rendering).Subscription
Not sure if this is feasible, but we could allow the user to use a
frames
subscription.Note: While rendering to an offscreen buffer you won't see anything on the window.
Also: Technically, on OpenGL you can read the framebuffer directly, by using
glReadPixels
, but onwgpu
the same isn't guaranteed, you'd have to request an extension for that.