fix CAMetalLayers
This commit is contained in:
@@ -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)
|
@@ -1,29 +0,0 @@
|
||||
#include "metal_bridge.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
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;
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
#include "gryphn/gryphn_utils.h"
|
||||
|
||||
void mtlObjectCSetContentViewsLayer(void* view, void* layer);
|
||||
void mtlInitializeMetalLayer(void* layer, gnBool vsync);
|
@@ -15,6 +15,9 @@ gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t
|
||||
|
||||
info.presentationQueues->info.surface.windowSurface->layer.device = device->outputDevice->device;
|
||||
id<CAMetalDrawable> drawable = [info.presentationQueues->info.surface.windowSurface->layer nextDrawable];
|
||||
if (drawable == nil) {
|
||||
return GN_FAILED_TO_CREATE_FRAMEBUFFER;
|
||||
}
|
||||
|
||||
id<MTLCommandBuffer> 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;
|
||||
|
@@ -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) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include "core/window_surface/gryphn_surface.h"
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
typedef struct gnPlatformWindowSurface_t{
|
||||
typedef struct gnPlatformWindowSurface_t {
|
||||
CAMetalLayer* layer;
|
||||
} gnPlatformWindowSurface;
|
||||
|
||||
|
@@ -9,20 +9,8 @@
|
||||
#import <CoreGraphics/CoreGraphics.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];
|
||||
[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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user