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

Scoped binds #1633

Closed
nferhat opened this issue Jan 10, 2025 · 4 comments
Closed

Scoped binds #1633

nferhat opened this issue Jan 10, 2025 · 4 comments

Comments

@nferhat
Copy link
Contributor

nferhat commented Jan 10, 2025

I already spoke about this back in the matrix channel but I didn't have the time to actually try to implement this out.

The main idea is to give binds a lifetime, something similar to:

let mut renderer: GlesRenderer = todo!();

let tex1: GlesTexture = todo!();
let _scoped_bind: ScopedBind<'_, GlesRenderer, GlesTexture> = renderer.bind(tex1).unwrap();
{
    // In this scope, framebuffer is bound
    let framebuffer: GlesRenderbuffer = todo!();
    let _other_bind: ScopedBind<'_, GlesRenderer, GlesRenderBuffer> = renderer.bind(framebuffer).unwrap();
    // Now, the bind for framebuffer is dropped, and tex1 is bound again
}

Implementation is open to discussion

This is also needed as part of my rendering tests for blurring, as I need to (on Element::draw) bind a texture, render to it, and then bind back whatever I need to render to on the output surface. While accessing GlesRenderer::target would fix this issue for me, I'd rather implement this better interface too.

@nferhat
Copy link
Contributor Author

nferhat commented Jan 10, 2025

The biggest difficulty is accessing the Renderer and the previous target when dropping a ScopedBind in order to bind it.

@nferhat
Copy link
Contributor Author

nferhat commented Jan 10, 2025

First naive implementation looks kinda bad, not finished enough to get into a PR.

let mut bind = renderer.bind(buffer).map_err(Error::Rendering)?;
let renderer = bind.renderer().unwrap();
let res = self.render_output_internal(renderer, age, elements, clear_color)?;
bind.unbind().map(move |_| res).map_err(Error::Rendering)

Since the Drop trait doesn't have a return type, it has to be a separate function

@Drakulix
Copy link
Member

See #1637

@nferhat
Copy link
Contributor Author

nferhat commented Jan 15, 2025

See #1637

Mhm, seems to do exactly that

Well I guess this solves it, thank you!

@nferhat nferhat closed this as completed Jan 15, 2025
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

2 participants