diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c2ddf3..d61e992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,13 @@ file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS "src/*.cpp" "src/*.hpp" "src/*.c" "src/*.h" ) -add_library(Gryphn ${SOURCE_FILES}) +if(APPLE) + +file(GLOB_RECURSE METAL_FILES CONFIGURE_DEPENDS + "src/*.m") + +endif() +add_library(Gryphn ${SOURCE_FILES} ${METAL_FILES}) target_include_directories(Gryphn PUBLIC ${CMAKE_SOURCE_DIR}/gryphn/src/) target_include_directories(Gryphn PUBLIC ${CMAKE_SOURCE_DIR}/gryphn/include/) add_compile_definitions(GN_REVEAL_IMPL) @@ -19,6 +25,16 @@ if(APPLE) add_compile_definitions(GN_PLATFORM_MACOS) add_subdirectory(rendering_api/metal/) add_subdirectory(rendering_api/vulkan/) + + target_link_libraries(Gryphn + "-framework IOKit" + "-framework CoreFoundation" + "-framework CoreGraphics" + "-framework AppKit" + "-framework Metal" + "-framework QuartzCore" + "-framework MetalKit" + ) endif() if(UNIX AND NOT APPLE) add_compile_definitions(GN_PLATFORM_LINUX) diff --git a/include/gryphn/gryphn.h b/include/gryphn/gryphn.h index 802a566..110f796 100644 --- a/include/gryphn/gryphn.h +++ b/include/gryphn/gryphn.h @@ -1,6 +1,5 @@ #pragma once #define GRYPHN_INCLUDE -#include #include #include #include diff --git a/include/gryphn/gryphn_platform.h b/include/gryphn/gryphn_platform.h new file mode 100644 index 0000000..924242d --- /dev/null +++ b/include/gryphn/gryphn_platform.h @@ -0,0 +1,2 @@ +#pragma once +#include diff --git a/include/gryphn/utils/gryphn_glfw_util.h b/include/gryphn/utils/gryphn_glfw_util.h index 4370a86..ad8b381 100644 --- a/include/gryphn/utils/gryphn_glfw_util.h +++ b/include/gryphn/utils/gryphn_glfw_util.h @@ -14,10 +14,15 @@ #error "Must define GLFW_EXPOSE_NATIVE_COCOA on macos" #endif -gnReturnCode gnCreateGLFWWindowSurface(struct gnWindowSurface_t* windowSurface, struct gnInstance_t* instance, GLFWwindow* window) { +static gnReturnCode gnCreateGLFWWindowSurface(struct gnWindowSurface_t* windowSurface, struct gnInstance_t* instance, GLFWwindow* window) { + MTKView* view = gnCreateMTKView(glfwGetCocoaWindow(window)); + gnWindowSetMTKView(glfwGetCocoaWindow(window), view); + CAMetalLayer* layer = gnGetCAMetalLayer(glfwGetCocoaWindow(window)); + gnMacOSWindowSurfaceInfo surfaceCreateInfo = { - .window = (NSWindow*)glfwGetCocoaWindow(window) + .layer = layer }; + return gnCreateMacOSWindowSurface(windowSurface, instance, surfaceCreateInfo); } diff --git a/rendering_api/metal/src/bridge/info.txt b/rendering_api/metal/src/bridge/info.txt deleted file mode 100644 index ad78ea6..0000000 --- a/rendering_api/metal/src/bridge/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -(this file is because I have zero god damn clue what is going on) - -UHHHHHHH I FUCKING HATE APPLE WHY DO I HAVE TO WRITE OBJECTIVE C JUST SO THAT I CAN OPEN A WINDOW -AND THAN DRAW SHIT TO IT WHY DONT YOU JUST LET ME DO ALL THIS SHIT IN PLAIN C LIKE ANY OTHER -OPERATING SYSTEM EVEN FUCKING MICROSOFT LETS ME DO THIS SHIT IN C YOU ARE A BITCH APPLE -NO ONE IN THERE LIFE HAS EVER WANTED TO WRITE OBJECTIVE C BECAUSE IT IS THE BIGGEST -PEICE OF SHIT OF ALL TIME BUT THIS IS THE LITTLE OBJECTIVE C THAT I NEEDED TO WRITE TO GET -ALL OF THIS TO WORK. - -(please disregard this file this is just for when I forget how this project works and I want to remember why there is objective-c in here) diff --git a/rendering_api/metal/src/bridge/metal_bridege.m b/rendering_api/metal/src/bridge/metal_bridege.m deleted file mode 100644 index ab074a5..0000000 --- a/rendering_api/metal/src/bridge/metal_bridege.m +++ /dev/null @@ -1,29 +0,0 @@ -#include "metal_bridge.h" -#import -#import -#import -#import - -void mtlObjectCSetContentViewsLayer(void* view, void* layer) { - [CATransaction begin]; - [CATransaction setDisableActions:YES]; - - NSView* contentView = (__bridge NSView*)view; - - CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer; - - [contentView setWantsLayer:YES]; - [contentView setLayer:metalLayer]; - - [CATransaction commit]; -} - -void mtlInitializeMetalLayer(void* layer, gnBool vsync) { - CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer; - metalLayer.maximumDrawableCount = 3; - if (vsync == gnTrue) - metalLayer.displaySyncEnabled = true; - else - metalLayer.displaySyncEnabled = false; - metalLayer.framebufferOnly = true; -} diff --git a/rendering_api/metal/src/bridge/metal_bridge.h b/rendering_api/metal/src/bridge/metal_bridge.h deleted file mode 100644 index cac7022..0000000 --- a/rendering_api/metal/src/bridge/metal_bridge.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include "gryphn/gryphn_utils.h" - -void mtlObjectCSetContentViewsLayer(void* view, void* layer); -void mtlInitializeMetalLayer(void* layer, gnBool vsync); diff --git a/rendering_api/metal/src/core/present/metal_present.m b/rendering_api/metal/src/core/present/metal_present.m index 19e2214..9f90fa1 100644 --- a/rendering_api/metal/src/core/present/metal_present.m +++ b/rendering_api/metal/src/core/present/metal_present.m @@ -15,6 +15,9 @@ gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t info.presentationQueues->info.surface.windowSurface->layer.device = device->outputDevice->device; id drawable = [info.presentationQueues->info.surface.windowSurface->layer nextDrawable]; + if (drawable == nil) { + return GN_FAILED_TO_CREATE_FRAMEBUFFER; + } id commandBuffer = [device->outputDevice->queues[info.queueIndex] commandBuffer]; @@ -42,6 +45,7 @@ gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t [commandBuffer presentDrawable:drawable]; [commandBuffer commit]; + [commandBuffer waitUntilScheduled]; device->outputDevice->executingCommandBuffer = commandBuffer; return GN_SUCCESS; diff --git a/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.m b/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.m index cdf05f5..02ac08f 100644 --- a/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.m +++ b/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.m @@ -46,12 +46,13 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, return GN_SUCCESS; } -void gnPresentationQueueGetImageFn(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex) { +gnReturnCode gnPresentationQueueGetImageFn(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex) { semaphore->semaphore->eventTriggered = gnFalse; *imageIndex = presentationQueue->presentationQueue->currentImage; presentationQueue->presentationQueue->currentImage++; presentationQueue->presentationQueue->currentImage %= presentationQueue->imageCount; semaphore->semaphore->eventTriggered = gnTrue; + return GN_SUCCESS; } void gnDestroyPresentationQueueFn(gnPresentationQueue *presentationQueue) { diff --git a/rendering_api/metal/src/core/surface/metal_surface.h b/rendering_api/metal/src/core/surface/metal_surface.h index 645d892..cfaa274 100644 --- a/rendering_api/metal/src/core/surface/metal_surface.h +++ b/rendering_api/metal/src/core/surface/metal_surface.h @@ -2,7 +2,7 @@ #include "core/window_surface/gryphn_surface.h" #import -typedef struct gnPlatformWindowSurface_t{ +typedef struct gnPlatformWindowSurface_t { CAMetalLayer* layer; } gnPlatformWindowSurface; diff --git a/rendering_api/metal/src/core/surface/metal_surface.m b/rendering_api/metal/src/core/surface/metal_surface.m index a3b2b90..7359230 100644 --- a/rendering_api/metal/src/core/surface/metal_surface.m +++ b/rendering_api/metal/src/core/surface/metal_surface.m @@ -9,20 +9,8 @@ #import gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) { - NSWindow* window = (__bridge NSWindow*)createInfo.window; - NSView* view = [window contentView]; - - CAMetalLayer* layer = [CAMetalLayer layer]; - [layer setContentsScale:[window backingScaleFactor]]; - [layer setFramebufferOnly:YES]; - [layer setPixelFormat:MTLPixelFormatBGRA8Unorm_sRGB]; - [layer setFrame:view.bounds]; - - [view setLayer:layer]; - [view setWantsLayer:YES]; - windowSurface->windowSurface = malloc(sizeof(gnPlatformWindowSurface)); - windowSurface->windowSurface->layer = layer; + windowSurface->windowSurface->layer = createInfo.layer; return GN_SUCCESS; } diff --git a/rendering_api/vulkan/src/present/vulkan_present.c b/rendering_api/vulkan/src/present/vulkan_present.c index 6b6b811..655b23c 100644 --- a/rendering_api/vulkan/src/present/vulkan_present.c +++ b/rendering_api/vulkan/src/present/vulkan_present.c @@ -3,6 +3,8 @@ #include "presentation_queue/vulkan_presentation_queue.h" #include "output_device/vulkan_output_devices.h" +#include "stdio.h" + gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t info) { VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i].semaphore->semaphore; @@ -22,7 +24,8 @@ gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t VkQueue queue; vkGetDeviceQueue(device->outputDevice->device, info.queueIndex, 0, &queue); - vkQueuePresentKHR(queue, &presentInfo); - + VkResult result = vkQueuePresentKHR(queue, &presentInfo); + if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE; + if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; return GN_SUCCESS; } diff --git a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c index 54f4631..0524923 100644 --- a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c +++ b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -110,11 +110,16 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, return GN_SUCCESS; } -void gnPresentationQueueGetImageFn(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex) { - vkAcquireNextImageKHR( +gnReturnCode gnPresentationQueueGetImageFn(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex) { + VkResult result = vkAcquireNextImageKHR( presentationQueue->outputDevice->outputDevice->device, presentationQueue->presentationQueue->swapChain, timeout, semaphore->semaphore->semaphore, VK_NULL_HANDLE, imageIndex); + + if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE; + if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; + + return GN_SUCCESS; } void gnDestroyPresentationQueueFn(gnPresentationQueue* queue) { diff --git a/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.m b/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.m index b75c3bf..fc85764 100644 --- a/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.m +++ b/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.m @@ -12,22 +12,12 @@ #include "vulkan/vulkan_metal.h" gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) { - NSWindow* window = (__bridge NSWindow*)createInfo.window; - NSView* view = [window contentView]; - - CAMetalLayer* layer = [CAMetalLayer layer]; - [layer setContentsScale:[window backingScaleFactor]]; - [layer setFramebufferOnly:YES]; - - [view setLayer:layer]; - [view setWantsLayer:YES]; - windowSurface->windowSurface = malloc(sizeof(gnPlatformWindowSurface)); VkMetalSurfaceCreateInfoEXT surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; surfaceCreateInfo.pNext = NULL; surfaceCreateInfo.flags = 0; - surfaceCreateInfo.pLayer = layer; + surfaceCreateInfo.pLayer = createInfo.layer; VkResult result = vkCreateMetalSurfaceEXT(instance->instance->vk_instance, &surfaceCreateInfo, NULL, &windowSurface->windowSurface->surface); if (result != VK_SUCCESS) diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index e654bd9..95782a8 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -60,7 +60,7 @@ typedef struct gnFunctions_t { #include "core/presentation_queue/gryphn_presentation_queue.h" typedef struct gnDeviceFunctions_t { gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo); - void (*_gnPresentationQueueGetImage)(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex); + gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex); void (*_gnDestroyPresentationQueue)(gnPresentationQueue *presentationQueue); gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo); diff --git a/src/core/presentation_queue/gryphn_presentation_queue.c b/src/core/presentation_queue/gryphn_presentation_queue.c index 77902c0..e219e17 100644 --- a/src/core/presentation_queue/gryphn_presentation_queue.c +++ b/src/core/presentation_queue/gryphn_presentation_queue.c @@ -7,8 +7,8 @@ gnReturnCode gnCreatePresentationQueue(gnPresentationQueue* presentationQueue, s return device->deviceFunctions->_gnCreatePresentationQueue(presentationQueue, device, presentationInfo); } -void gnPresentationQueueGetImage(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex) { - presentationQueue->outputDevice->deviceFunctions->_gnPresentationQueueGetImage(presentationQueue, timeout, semaphore, imageIndex); +gnReturnCode gnPresentationQueueGetImage(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex) { + return presentationQueue->outputDevice->deviceFunctions->_gnPresentationQueueGetImage(presentationQueue, timeout, semaphore, imageIndex); } void gnDestroyPresentationQueue(gnPresentationQueue *presentationQueue) { diff --git a/src/core/presentation_queue/gryphn_presentation_queue.h b/src/core/presentation_queue/gryphn_presentation_queue.h index 10ce0ac..b839bfa 100644 --- a/src/core/presentation_queue/gryphn_presentation_queue.h +++ b/src/core/presentation_queue/gryphn_presentation_queue.h @@ -27,5 +27,5 @@ typedef struct gnPresentationQueue_t { } gnPresentationQueue; gnReturnCode gnCreatePresentationQueue(gnPresentationQueue* presentationQueue, struct gnOutputDevice_t* device, struct gnPresentationQueueInfo_t presentationInfo); -void gnPresentationQueueGetImage(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex); +gnReturnCode gnPresentationQueueGetImage(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex); void gnDestroyPresentationQueue(gnPresentationQueue* presentationQueue); diff --git a/src/core/window_surface/gryphn_surface_create_functions.h b/src/core/window_surface/gryphn_surface_create_functions.h index 64bcddd..5b8542f 100644 --- a/src/core/window_surface/gryphn_surface_create_functions.h +++ b/src/core/window_surface/gryphn_surface_create_functions.h @@ -32,7 +32,7 @@ #ifdef GN_PLATFORM_MACOS typedef struct gnMacOSWindowSurfaceInfo_t { - NSWindow* window; + CAMetalLayer* layer; } gnMacOSWindowSurfaceInfo; gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo); diff --git a/src/platform/platform_macos/gryphn_platform_macos.c b/src/platform/platform_macos/gryphn_platform_macos.c deleted file mode 100644 index 287c109..0000000 --- a/src/platform/platform_macos/gryphn_platform_macos.c +++ /dev/null @@ -1,33 +0,0 @@ -#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" - -gnRenderingAPI renderingAPIs[3] = { - GN_RENDERINGAPI_METAL, - GN_RENDERINGAPI_VULKAN, - GN_RENDERINGAPI_SOFTWARE -}; - -gnRenderingAPI* gnGetSupportedRenderingAPIs(int* count) { - *count = 3; - 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); -} - -#endif diff --git a/src/platform/platform_macos/gryphn_platform_macos.h b/src/platform/platform_macos/gryphn_platform_macos.h index c387b40..d448cb9 100644 --- a/src/platform/platform_macos/gryphn_platform_macos.h +++ b/src/platform/platform_macos/gryphn_platform_macos.h @@ -4,6 +4,19 @@ #ifdef __OBJC__ @class NSWindow; +@class CAMetalLayer; +@class MTKView; #else typedef void NSWindow; +typedef void CAMetalLayer; +typedef void MTKView; #endif + +MTKView* gnCreateMTKView(NSWindow* window); +void gnWindowSetMTKView(NSWindow* window, MTKView* view); +CAMetalLayer* gnGetCAMetalLayer(NSWindow* window); + +// CAMetalLayer* gnCreateMetalLayer(NSWindow* window); +// void gnAttachMetalLayer(NSWindow* window, CAMetalLayer* layer); +// void gnMetalLayerSetBounds(CAMetalLayer* layer, NSWindow* window); +// CAMetalLayer* gnGetMetalLayer(NSWindow* window); diff --git a/src/platform/platform_macos/gryphn_platform_macos.m b/src/platform/platform_macos/gryphn_platform_macos.m new file mode 100644 index 0000000..2e80f61 --- /dev/null +++ b/src/platform/platform_macos/gryphn_platform_macos.m @@ -0,0 +1,91 @@ +#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 "gryphn_platform_macos.h" +#import +#import +#import + +gnRenderingAPI renderingAPIs[3] = { + GN_RENDERINGAPI_METAL, + GN_RENDERINGAPI_VULKAN, + GN_RENDERINGAPI_SOFTWARE +}; + +gnRenderingAPI* gnGetSupportedRenderingAPIs(int* count) { + *count = 3; + 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* gnGetCAMetalLayer(NSWindow* window) { + MTKView* view = window.contentView; + return (CAMetalLayer*)view.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]; + + // if (window.scaleFramebuffer) + // [window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]]; + + [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 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 diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index 2bd846f..a235510 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -33,7 +33,9 @@ typedef enum gnReturnCode_t { GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS, GN_FAILED_TO_CREATE_FENCE, GN_FAILED_TO_CREATE_SEMAPHORE, - GN_FAILED_TO_SUBMIT_COMMAND_BUFFER + GN_FAILED_TO_SUBMIT_COMMAND_BUFFER, + GN_OUT_OF_DATE_PRESENTATION_QUEUE, + GN_SUBOPTIMAL_PRESENTATION_QUEUE } gnReturnCode; typedef gnReturnCode gnErrorCode; @@ -72,5 +74,7 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_FAILED_TO_CREATE_FENCE: return "GN_FAILED_TO_CREATE_FENCE"; case GN_FAILED_TO_CREATE_SEMAPHORE: return "GN_FAILED_TO_CREATE_SEMAPHORE"; case GN_FAILED_TO_SUBMIT_COMMAND_BUFFER: return "GN_FAILED_TO_SUBMIT_COMMAND_BUFFER"; + case GN_OUT_OF_DATE_PRESENTATION_QUEUE: return "GN_OUT_OF_DATE_PRESENTATION_QUEUE"; + case GN_SUBOPTIMAL_PRESENTATION_QUEUE: return "GN_SUBOPTIMAL_PRESENTATION_QUEUE"; } }