diff --git a/rendering_api/metal/CMakeLists.txt b/rendering_api/metal/CMakeLists.txt index a9d42b7..0fc58ff 100644 --- a/rendering_api/metal/CMakeLists.txt +++ b/rendering_api/metal/CMakeLists.txt @@ -24,6 +24,7 @@ target_link_libraries(GryphnMetalImpl spirv-cross-core spirv-cross-msl spirv-cro target_link_libraries(GryphnMetalImpl "-framework IOKit" "-framework CoreFoundation" + "-framework CoreGraphics" "-framework Foundation" "-framework Metal" "-framework QuartzCore" diff --git a/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.h b/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.h new file mode 100644 index 0000000..7eb1d03 --- /dev/null +++ b/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.h @@ -0,0 +1,8 @@ +#pragma once +#import +#include "core/presentation_queue/gryphn_presentation_queue.h" + +typedef struct gnPlatformPresentationQueue_t { + int textureCount; + id* textures; +} gnPlatformPresentationQueue; 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 new file mode 100644 index 0000000..1b3a4ff --- /dev/null +++ b/rendering_api/metal/src/core/presentation_queue/metal_presentation_queue.m @@ -0,0 +1,27 @@ +#include "metal_presentation_queue.h" +#include "core/surface/metal_surface.h" +#include "core/devices/metal_output_devices.h" + +gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo) { + presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t)); + + MTLPixelFormat convertedFormat = mtlGryphnFormatToVulkanFormat(presentationInfo.format.format); + CGColorSpaceRef convertedColorSpace = mtlGryphnColorSpaceToVulkanColorSpace(presentationInfo.format.colorSpace); + + presentationQueue->presentationQueue->textureCount = presentationInfo.ImageCount; + presentationQueue->presentationQueue->textures = malloc(sizeof(id) * presentationInfo.ImageCount); + + MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init]; + textureDescriptor.pixelFormat = convertedFormat; + textureDescriptor.width = presentationInfo.ImageSize.x; + textureDescriptor.height = presentationInfo.ImageSize.y; + textureDescriptor.usage = MTLTextureUsageRenderTarget; + textureDescriptor.textureType = MTLTextureType2D; + + + for (int i = 0; i < presentationInfo.ImageCount; i++) { + presentationQueue->presentationQueue->textures[i] = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor]; + } + + return GN_SUCCESS; +} diff --git a/rendering_api/metal/src/core/surface/metal_surface.m b/rendering_api/metal/src/core/surface/metal_surface.m index fc2af32..c6c7237 100644 --- a/rendering_api/metal/src/core/surface/metal_surface.m +++ b/rendering_api/metal/src/core/surface/metal_surface.m @@ -6,6 +6,7 @@ #import #import #import +#import gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) { NSWindow* window = (__bridge NSWindow*)createInfo.window; @@ -22,6 +23,20 @@ gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurfac return GN_SUCCESS; } +struct gnSurfaceDetails_t gnGetSurfaceDetailsFn( + // struct gnWindowSurface_t* windowSurface, + // struct gnPhysicalDevice_t device, + // uint32_t* formatCount + struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device +) { + struct gnSurfaceDetails_t surfaceDetails; + surfaceDetails.formatCount = 1; + surfaceDetails.formats = (struct gnSurfaceFormat_t[1]){ { GN_FORMAT_BGRA8_SRGB, GN_COLOR_SPACE_SRGB_NONLINEAR } }; + surfaceDetails.minImageCount = 2; + surfaceDetails.maxImageCount = 3; + return surfaceDetails; +} + MTLPixelFormat mtlGryphnFormatToVulkanFormat(gnImageFormat format) { switch (format) { case GN_FORMAT_BGRA8_SRGB: { return MTLPixelFormatBGRA8Unorm_sRGB; }