Skip to content

Fix macOS window embedding#1688

Merged
robertosfield merged 1 commit intovsg-dev:masterfrom
nolankramer:master
Apr 6, 2026
Merged

Fix macOS window embedding#1688
robertosfield merged 1 commit intovsg-dev:masterfrom
nolankramer:master

Conversation

@nolankramer
Copy link
Copy Markdown
Contributor

Pull Request Template

Description

MacOS_Window ignores WindowTraits::nativeWindow and always creates a standalone NSWindow, making it impossible to embed a VSG Vulkan surface into an existing view hierarchy (e.g. a Qt QWindow via QWidget::createWindowContainer).

This change adds an embedded window path to MacOS_Window that mirrors what Win32_Window already does on Windows: when traits->nativeWindow contains a valid handle, the provided NSView is used directly instead of creating a new NSWindow/NSView. A CAMetalLayer is attached to the external view if one doesn't already exist, and the Vulkan surface is created from it.

Additionally, pollEvents() skips NSApp event draining in the embedded case (the host framework owns the event loop), and resize() falls back to [_view window] for backingScaleFactor when no standalone _window exists.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Embedded VSG Vulkan rendering inside a Qt 6.9 QWidget::createWindowContainer on macOS — surface creation, swapchain, rendering, and resize all function correctly
  • Verified standalone (non-embedded) window path is unchanged

Test Configuration:

  • Hardware: Apple M1 (arm64)
  • Toolchain: AppleClang 17.0.0 (Xcode)
  • SDK: macOS 15 (Sequoia), MoltenVK 1.4.0, Vulkan 1.4.323
  • Qt: 6.9.3

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@robertosfield robertosfield merged commit 9736f9f into vsg-dev:master Apr 6, 2026
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants