glutin icon indicating copy to clipboard operation
glutin copied to clipboard

Screenbuffer does not resize on Mac

Open kanjiwar opened this issue 4 years ago • 13 comments

I want to toggle the aspect ratio between 16:9 and 9:16 at runtime. Everything works fine on app start, but there is something wrong with the Mac implementation of set_inner_size(). My framebuffers resize properly but the window's screenbuffer does not change size.

@Osspial recommended calling Glutin's resize() function but this produced a black screen.

kanjiwar avatar Oct 13 '19 17:10 kanjiwar

Can you post the code that's calling resize? It should work.

Osspial avatar Oct 13 '19 18:10 Osspial

pub fn resize(&mut self, width: usize, height: usize) {
        let logical_size = LogicalSize {
            width: width as f64,
            height: height as f64
        };

        self.windowed_context.window().set_inner_size(logical_size);

        {   // hack to fix resize on mac
            let physical_size = logical_size.to_physical(self.dpi as f64);

            self.windowed_context.resize(physical_size);
        }
}

kanjiwar avatar Oct 13 '19 18:10 kanjiwar

Maybe it would work if it were called in the WindowEvent::Resized handler?

Osspial avatar Oct 13 '19 18:10 Osspial

Same behavior - black screen.

                        Resized(logical_size) => {
                            let physical_size = logical_size.to_physical(window.dpi as f64);

                            window.windowed_context.resize(physical_size);
                        }

kanjiwar avatar Oct 13 '19 18:10 kanjiwar

Hmm. Not entirely sure what to do, then.

cc @vbogaevsky would you be able to look into this? Also, I'm going to move this issue over to Glutin, since it seems more likely to be a bug there.

Osspial avatar Oct 13 '19 18:10 Osspial

Should probably call glViewport to update the viewport.

goddessfreya avatar Feb 01 '20 10:02 goddessfreya

Should probably call glViewport to update the viewport.

It's not a viewport issue.

kanjiwar avatar Feb 05 '20 10:02 kanjiwar

Do you have an example I can test?

goddessfreya avatar Feb 06 '20 03:02 goddessfreya

bug.zip

@goddessfreya here you go. This actually demonstrates a more general form of the bug. Simply resize the window with your mouse on mac. The red unit rectangle fills the screen on startup but the background is visible after window resize. It resembles a viewport issue, but I am setting the viewport properly

kanjiwar avatar Jun 22 '20 08:06 kanjiwar

I have a similar issue. When I resize the window, the screen buffer is not changing. So the rendered image is getting distorted.

AcrylicShrimp avatar Jun 02 '22 08:06 AcrylicShrimp

I have a similar issue. When I resize the window, the screen buffer is not changing. So the rendered image is getting distorted.

Oh, hold on, I fixed my problem. My case was that I forgot to call ContextWrapper::resize on resizing event handlers. It works well after calling this function correctly.

AcrylicShrimp avatar Jun 02 '22 10:06 AcrylicShrimp

@AcrylicShrimp Would this also be resolved if glutin had a helper function to handle winit events? After all, glutin heavily builds on top of winit.

I'm (slowly) working on this for Android lifecycle support.

MarijnS95 avatar Jun 05 '22 14:06 MarijnS95

@MarijnS95 If you mean helper functions to handle window events in the glutin, yes, it would maybe. But I'm not sure it's a good way to go. The main problem was that it's hard to know how to resize correctly. And I didn't even know existence of the resize function on the ContextWrapper. Adding a section on the docs for resizing with detailed description would be better.

AcrylicShrimp avatar Jun 05 '22 18:06 AcrylicShrimp

No winit in glutin anymore.

kchibisov avatar Sep 03 '22 06:09 kchibisov