macos helpers

This commit is contained in:
Greg Wells
2025-06-03 13:04:50 -04:00
parent 5b9f0d8ebe
commit 3a32b996e1
2 changed files with 28 additions and 5 deletions

View File

@@ -12,9 +12,11 @@ typedef void CAMetalLayer;
typedef void MTKView; typedef void MTKView;
#endif #endif
MTKView* gnCreateMTKView(NSWindow* window); // MTKView* gnCreateMTKView(NSWindow* window);
void gnWindowSetMTKView(NSWindow* window, MTKView* view); // void gnWindowSetMTKView(NSWindow* window, MTKView* view);
CAMetalLayer* gnCreateCAMetalLayer(NSWindow* window);
CAMetalLayer* gnGetCAMetalLayer(NSWindow* window); CAMetalLayer* gnGetCAMetalLayer(NSWindow* window);
void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer);
// CAMetalLayer* gnCreateMetalLayer(NSWindow* window); // CAMetalLayer* gnCreateMetalLayer(NSWindow* window);
// void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer); // void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer);

View File

@@ -48,11 +48,32 @@ void gnWindowSetMTKView(NSWindow* window, MTKView* view) {
[window setContentView:view]; [window setContentView:view];
} }
CAMetalLayer* gnGetCAMetalLayer(NSWindow* window) { CAMetalLayer* gnCreateCAMetalLayer(NSWindow* window) {
MTKView* view = window.contentView; CAMetalLayer* layer = [CAMetalLayer layer];
return (CAMetalLayer*)view.layer; layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
layer.frame = window.contentView.layer.bounds;
window.contentView.wantsLayer = YES;
window.contentView.layer = layer;
return layer;
} }
CAMetalLayer* gnGetCAMetalLayer(NSWindow* window) {
return (CAMetalLayer*)window.contentView.layer;
}
void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer) {
// CGSize newSize = window.contentView.bounds.size;
// CGFloat scale = window.contentView.window.backingScaleFactor;
// layer.drawableSize = CGSizeMake(newSize.width * scale, newSize.height * scale);
// CAMetalLayer* layer = [CAMetalLayer layer];
// layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
// layer.frame = window.contentView.layer.bounds;
// window.contentView.wantsLayer = YES;
// window.contentView.layer = layer;
layer.drawableSize = CGSizeMake(window.frame.size.width, window.frame.size.height);
}
/* /*
CAMetalLayer* gnCreateMetalLayer(NSWindow* window) { CAMetalLayer* gnCreateMetalLayer(NSWindow* window) {
// CAMetalLayer* layer = [CAMetalLayer layer]; // CAMetalLayer* layer = [CAMetalLayer layer];