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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get window from render context #583

Open
saverioscagnoli opened this issue Jan 8, 2025 · 0 comments
Open

Get window from render context #583

saverioscagnoli opened this issue Jan 8, 2025 · 0 comments

Comments

@saverioscagnoli
Copy link

saverioscagnoli commented Jan 8, 2025

Hello! I was wondering if it was possible to get the window handle from the render context on another thread.

Let's say i wanted to create another thread with the render context:

       let thread = std::thread::spawn(move || {
            render_context.make_current();
            gl::load_with(|symbol| render_context.get_proc_address(symbol) as *const _);

            while !render_context.should_close() {
                window.set_title("new title");

                for (_, event) in glfw::flush_messages(&events) {
                    match event {
                        WindowEvent::Close => {
                            render_context.set_should_close(true);
                            render_context.post_empty_event();
                        }
                        _ => {}
                    }
                }

                render_context.swap_buffers();
            }
        });

and I wanted to set the title from this secondary thread.
The problem is that i need the window for the main window.should_close() loop under this thread code:

       while !window.should_close() {
            glfw.wait_events_unbuffered(|window_id, event| {
                if let (_, WindowEvent::Close) = event {
                    window.set_should_close(false);
                };

                Some(event)
            });
        }

i see that PRenderContext has the window_ptr() function, so techincally i can do this on the second thread:

unsafe {
    glfwSetWindowTitle(window_ptr, ...)
}

is this bad? If not, is there a way to retrieve the window from the render context? do I need to use Arc<Mutex>?

Thank you!

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

No branches or pull requests

1 participant