Create presentation queues on metal
This commit is contained in:
@@ -24,6 +24,7 @@ target_link_libraries(GryphnMetalImpl spirv-cross-core spirv-cross-msl spirv-cro
|
|||||||
target_link_libraries(GryphnMetalImpl
|
target_link_libraries(GryphnMetalImpl
|
||||||
"-framework IOKit"
|
"-framework IOKit"
|
||||||
"-framework CoreFoundation"
|
"-framework CoreFoundation"
|
||||||
|
"-framework CoreGraphics"
|
||||||
"-framework Foundation"
|
"-framework Foundation"
|
||||||
"-framework Metal"
|
"-framework Metal"
|
||||||
"-framework QuartzCore"
|
"-framework QuartzCore"
|
||||||
|
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#import <Metal/Metal.h>
|
||||||
|
#include "core/presentation_queue/gryphn_presentation_queue.h"
|
||||||
|
|
||||||
|
typedef struct gnPlatformPresentationQueue_t {
|
||||||
|
int textureCount;
|
||||||
|
id<MTLTexture>* textures;
|
||||||
|
} gnPlatformPresentationQueue;
|
@@ -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<MTLTexture>) * 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;
|
||||||
|
}
|
@@ -6,6 +6,7 @@
|
|||||||
#import <QuartzCore/CAMetalLayer.h>
|
#import <QuartzCore/CAMetalLayer.h>
|
||||||
#import <QuartzCore/QuartzCore.h>
|
#import <QuartzCore/QuartzCore.h>
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
#import <CoreGraphics/CoreGraphics.h>
|
||||||
|
|
||||||
gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
|
gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
|
||||||
NSWindow* window = (__bridge NSWindow*)createInfo.window;
|
NSWindow* window = (__bridge NSWindow*)createInfo.window;
|
||||||
@@ -22,6 +23,20 @@ gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurfac
|
|||||||
return GN_SUCCESS;
|
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) {
|
MTLPixelFormat mtlGryphnFormatToVulkanFormat(gnImageFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GN_FORMAT_BGRA8_SRGB: { return MTLPixelFormatBGRA8Unorm_sRGB; }
|
case GN_FORMAT_BGRA8_SRGB: { return MTLPixelFormatBGRA8Unorm_sRGB; }
|
||||||
|
Reference in New Issue
Block a user