Skip to content

Winit redraws, request vs set_poll. #421

@marknefedov

Description

@marknefedov

Hello, I'm a complete newbie in this question.
In a lot of tutorials and example codes, I see that render is being performed in Event::RedrawRequested event, but according to Winit documentation continuously drawn apps, such as games should use control_flow.set_poll() and render inside Event::MainEventsCleared. Can anybody provide any information on this matter?

Reference from the docs.

    // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
    // dispatched any events. This is ideal for games and similar applications.
    control_flow.set_poll();

    // ControlFlow::Wait pauses the event loop if no events are available to process.
    // This is ideal for non-game applications that only update in response to user
    // input, and uses significantly less power/CPU time than ControlFlow::Poll.
    control_flow.set_wait();

    match event {
        Event::WindowEvent {
            event: WindowEvent::CloseRequested,
            ..
        } => {
            println!("The close button was pressed; stopping");
            control_flow.set_exit();
        },
        Event::MainEventsCleared => {
            // Application update code.

            // Queue a RedrawRequested event.
            //
            // You only need to call this if you've determined that you need to redraw, in
            // applications which do not always need to. Applications that redraw continuously
            // can just render here instead.
            window.request_redraw();
        },
        Event::RedrawRequested(_) => {
            // Redraw the application.
            //
            // It's preferable for applications that do not render continuously to render in
            // this event rather than in MainEventsCleared, since rendering in here allows
            // the program to gracefully handle redraws requested by the OS.
        },
        _ => ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions