get stuff working on macos

This commit is contained in:
Greg Wells
2025-06-24 22:32:55 -04:00
parent cc31fd7d5c
commit f791b01705
12 changed files with 84 additions and 138 deletions

View File

@@ -15,8 +15,8 @@ typedef void MTKView;
// MTKView* gnCreateMTKView(NSWindow* window);
// void gnWindowSetMTKView(NSWindow* window, MTKView* view);
CAMetalLayer* gnCreateCAMetalLayer(NSWindow* window);
CAMetalLayer* gnGetCAMetalLayer(NSWindow* window);
void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer);
// CAMetalLayer* gnGetCAMetalLayer(NSWindow* window);
// void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer);
// CAMetalLayer* gnCreateMetalLayer(NSWindow* window);
// void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer);

View File

@@ -1,8 +1,4 @@
#ifdef GN_PLATFORM_MACOS
#undef GN_UTILS_CPP
#include "core/gryphn_rendering_api.h"
#include "core/instance/init/gryphn_dynamic_library.h"
#include "dlfcn.h"
#include "src/gryphn_rendering_api.h"
#include "gryphn_platform_macos.h"
#import <QuartzCore/QuartzCore.h>
#import <Cocoa/Cocoa.h>
@@ -19,34 +15,6 @@ gnRenderingAPI* gnGetSupportedRenderingAPIs(int* count) {
return renderingAPIs;
}
struct gnDynamicLibrary_t* gnLoadDynamicLibrary(const gnString path) {
struct gnDynamicLibrary_t* dll = malloc(sizeof(struct gnDynamicLibrary_t));
dll->dllPtr = dlopen(gnToCString(gnCombineStrings(path, ".dylib")), RTLD_LAZY),
dll->isValid = true;
if (dll->dllPtr == NULL) dll->isValid = false;
return dll;
}
void* gnLoadFunctionPtr(struct gnDynamicLibrary_t* dll, const char* name) {
if (dll->isValid == false) return NULL;
return dlsym(dll->dllPtr, name);
}
void gnUnloadDynamicLibrary(struct gnDynamicLibrary_t* dll) {
if (dll->isValid) dlclose(dll->dllPtr);
}
MTKView* gnCreateMTKView(NSWindow* window) {
MTKView* view = [[MTKView alloc] initWithFrame:window.frame];
[view setColorPixelFormat:MTLPixelFormatBGRA8Unorm_sRGB];
[view setPreferredFramesPerSecond:120];
CGSize rect = { window.frame.size.width * window.backingScaleFactor, window.frame.size.height * window.backingScaleFactor };
[view setClearColor:MTLClearColorMake(1.0f, 0.0f, 0.0f, 1.0f)];
[view setDrawableSize:rect];
return view;
}
void gnWindowSetMTKView(NSWindow* window, MTKView* view) {
[window setContentView:view];
}
CAMetalLayer* gnCreateCAMetalLayer(NSWindow* window) {
NSView* view = window.contentView;
@@ -58,56 +26,55 @@ CAMetalLayer* gnCreateCAMetalLayer(NSWindow* window) {
return layer;
}
CAMetalLayer* gnGetCAMetalLayer(NSWindow* window) {
return (CAMetalLayer*)window.contentView.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);
}
// 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* layer = [CAMetalLayer layer];
// [window.contentView setWantsLayer:YES];
// [layer setContentsScale:[window backingScaleFactor]];
// [layer setFrame:window.contentView.bounds];
// [window.contentView setLayer:layer];
// return layer;
// /*
// CAMetalLayer* gnCreateMetalLayer(NSWindow* window) {
// // CAMetalLayer* layer = [CAMetalLayer layer];
// // [window.contentView setWantsLayer:YES];
// // [layer setContentsScale:[window backingScaleFactor]];
// // [layer setFrame:window.contentView.bounds];
// // [window.contentView setLayer:layer];
// // return layer;
CAMetalLayer* layer = [CAMetalLayer layer];
// CAMetalLayer* layer = [CAMetalLayer layer];
// if (window.scaleFramebuffer)
// [window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
// // if (window.scaleFramebuffer)
// // [window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
[window.contentView layer];
[window.contentView setWantsLayer:YES];
return layer;
}
// [window.contentView layer];
// [window.contentView setWantsLayer:YES];
// return layer;
// }
void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer) {
// [window.contentView setWantsLayer:YES];
// // [window.contentView setLayer:layer];
// [layer setFrame:window.contentView.bounds];
// [layer setContentsScale:[window backingScaleFactor]];
}
// void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer) {
// // [window.contentView setWantsLayer:YES];
// // // [window.contentView setLayer:layer];
// // [layer setFrame:window.contentView.bounds];
// // [layer setContentsScale:[window backingScaleFactor]];
// }
void gnMetalLayerSetBounds(CAMetalLayer* layer, NSWindow* window) {
// CGSize size = window.contentView.bounds.size;
// CGFloat scale = window.backingScaleFactor;
// void gnMetalLayerSetBounds(CAMetalLayer* layer, NSWindow* window) {
// // CGSize size = window.contentView.bounds.size;
// // CGFloat scale = window.backingScaleFactor;
// [layer setFrame:window.contentView.bounds];
// [layer setDrawableSize:CGSizeMake(size.width * scale, size.height * scale)];
// [layer setContentsScale:[window backingScaleFactor]];
}
*/
#endif
// // [layer setFrame:window.contentView.bounds];
// // [layer setDrawableSize:CGSizeMake(size.width * scale, size.height * scale)];
// // [layer setContentsScale:[window backingScaleFactor]];
// }
// */