【发布时间】:2016-02-01 23:41:08
【问题描述】:
我有一个 OS X Metal 应用程序,我想以非原生分辨率全屏运行,例如我的原始分辨率是 1920x1080,我想以 1024x768 全屏呈现应用程序。 (除了我无法使用 OpenGL 特定的 NSView 函数之外,我不相信使用 Metal 来绘制东西会影响这个问题。)
我的渲染器使用硬编码大小为 1024x768 的后台缓冲区。
当我使用bounds = 1024x768 创建我的窗口时,我得到了一个全屏窗口,但我的内容是居中绘制的,它不会拉伸以填满整个屏幕。
当我使用bounds = 1920x1080 创建窗口时,我得到一个全屏窗口,但我的内容被绘制在左上角并且缩放不正确(因为两种分辨率之间的比例不匹配)。
使用[NSView - enterFullScreenMode:withOptions:] 产生了相同的结果。设置[NSView autoresizingMask] 也没有改变任何东西。
理想情况下,我希望窗口与屏幕一样大,并让低分辨率后台缓冲区被拉伸以填满整个窗口。我错过了什么可以让我这样做?
相关应用初始化来自我的NSResponder <NSApplicationDelegate>:
// Create the window
self.Window = [NSWindow alloc];
[self.Window initWithContentRect:bounds
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES];
// Create the view
self.View = [NSView alloc];
[self.View initWithFrame:bounds];
[self.View setWantsLayer:YES]; // The generated layer is CAMetalLayer
// Associate the view with the window
[self.Window setContentView:self.View];
// Misc
[self.Window makeKeyAndOrderFront:self.Window];
[self.Window setAcceptsMouseMovedEvents:YES];
[self.Window setHidesOnDeactivate:YES];
// Fullscreen
[self.Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self.Window toggleFullScreen:nil];
[self.Window makeFirstResponder:self.View];
谢谢。
【问题讨论】:
-
支持视图的层被限制为使其框架等于该视图的边界。默认情况下,
CAMetalLayer的drawableSize等于其边界乘以其内容比例。您是否尝试过将图层的drawableSize直接设置为所需的渲染缓冲区大小? -
好的,谢谢!那是缺少的部分。有趣的是,我必须明确调用
setDrawableSize;使用后台缓冲区大小调用setBounds不会改变任何内容。
标签: objective-c macos cocoa metal