如何防止标题栏在Metal中引起渲染问题? [英] How do I keep the title bar from causing rendering issues in Metal?

查看:101
本文介绍了如何防止标题栏在Metal中引起渲染问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我绘制任何形状(无论是否带有纹理)时,当我进入全屏模式时,它都会闪烁,并在将鼠标移至顶部时显示标题栏.它将变轻,然后像瞬间一样返回.我不知道单色是否会发生这种情况,但是当我为顶点着色并绘制渐变或应用纹理时,就会发生这种情况.即使很微妙,也很烦人.我该如何解决?

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?

我正在使用macOS 1.15 Catalina.

I am using macOS 1.15 Catalina.

即使使用Xcode的示例Metal游戏也可以证明这一点.只需进入全屏模式,显示标题栏,当您显示和取消显示标题栏时,它将变得不流畅.

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.

更新:我已经意识到,如果我将绘图代码放在viewDidLoad()而不是draw()中,此行为将停止.我如何做到这一点,而不必只渲染一帧就不会出错?

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.

错误示例(视频)

显示白色闪烁"(视频)的错误的另一个示例

这个问题只得到了一半的回答,因为事实证明我设法解决了标题栏阻止帧速率的问题,但是白色闪光灯仍然存在问题.

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.

推荐答案

观看视频后,我了解您的问题所在.在您的情况下,UI(标题栏)阻止了主线程,这是正常行为,因为 MTKView 渲染发生在主应用程序线程上.您需要创建一个自定义金属视图并实现渲染循环在后台线程上.

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.

这篇关于如何防止标题栏在Metal中引起渲染问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆