4

When I draw any shape (Whether it's textured or not) it will flicker when I go to fullscreen and make the title bar show when I move the mouse to the top. It will turn lighter and then back for like a split second. I don't know if this happens with solid colors, but when I color the vertices and draw a gradient or apply textures, this happens. It's annoying, even though it's subtle. How can I fix it?

How to reproduce: Create a shape in Metal, either color the vertices differently to create a gradient, or apply a texture to it, and make the window fullscreen. Move the cursor to the top of the window. When the title bar shows up, the shape/texture will flash briefly. How can I fix that?

I am using macOS 1.15 Catalina.

This can be demonstrated even with the Xcode's example Metal game. Just go to fullscreen, show the title bar, and it will be unsmooth when you show and unshow the titlebar.

UPDATE: I have realized, that if I put the drawing code in viewDidLoad() instead of draw() this behavior will cease. How do I make it so that it's not buggy without having to only render ONE frame?

ANOTHER UPDATE: It does occur for solid colors.

This is a very difficult question, because I don't know what to try. This bug is also very hard to fix, because it only sometimes happens.

Example of the bug (Video)

Another example of the bug that displays the "white flicker" (Video)

Also this question was only half answered, because it turns out that I managed to fix the problem of the titlebar blocking the framerate, but there is still a problem with the white flash.

  • 2
    You are seeing this behaviour because, the window size change triggers the Metal layer to re-render. This topic is discussed extensively in different places. This link give a solution: https://thume.ca/2019/06/19/glitchless-metal-window-resizing/ – codetiger May 21 '20 at 05:01
  • I wish I knew a easy solution, but the reality is, this seems to be long standing bug in Metal View. There are lot of discussions around the internet and the only solution that seems to work is manually redrawing the scene. I am not sure why you are taking this issue very serious, to me it looks liveable. – codetiger May 22 '20 at 05:01
  • [Related](https://stackoverflow.com/questions/63709936/how-exactly-do-i-render-metal-on-a-background-thread)­ –  Sep 02 '20 at 17:19

2 Answers2

5

After watching your video, I understand what your problem is. In your case UI (Tittle Bar) is blocking the main thread, it's normal behavior because MTKView rendering occurs on the main application threads. You need to create a custom metal view and implement a render loop on a background thread.

Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48
1

Your best bet is to report this as a bug to Apple. I tried to research and there seems to be no results about this bug.

I assume you want a fix, but all I got is a workaround:

It doesn't seem to occur while the drawing code only runs once, in viewDidLoad. Maybe you could keep it there, and manually call the MetalView's draw method 60 times a second. I figured out how to get what I said to work. Leave the drawing code in draw, but make sure to set the preferred framerate to 0. Then manually redraw it 60 times a second. Because the draw method auto redrawing is buggy in this sense.