From 90279e6f9ef82e4cb7d14a307978393d4b2cf253 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:11:56 +0200 Subject: [PATCH] ios: Pass CAMetalLayer instead of void* to Obj-C++ bridging header --- CMakeLists.txt | 2 +- include/ios_driver.h | 4 +++- src/core/renderer_mtl/renderer_mtl.cpp | 4 ++-- src/ios_driver.mm | 10 ++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6d8fb4c..2362ffb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -673,7 +673,7 @@ if(ENABLE_METAL AND APPLE) target_compile_definitions(AlberCore PUBLIC "PANDA3DS_ENABLE_METAL=1") target_include_directories(AlberCore PRIVATE third_party/metal-cpp) # TODO: check if all of them are needed - target_link_libraries(AlberCore PRIVATE "-framework Metal" "-framework Foundation" "-framework QuartzCore" resources_renderer_mtl) + target_link_libraries(AlberCore PUBLIC "-framework Metal" "-framework Foundation" "-framework QuartzCore" resources_renderer_mtl) endif() source_group("Header Files\\Core" FILES ${HEADER_FILES}) diff --git a/include/ios_driver.h b/include/ios_driver.h index 5158fead..5be62943 100644 --- a/include/ios_driver.h +++ b/include/ios_driver.h @@ -1,4 +1,6 @@ #pragma once +#include +#include void iosCreateEmulator(); -void iosRunFrame(void* drawable); \ No newline at end of file +void iosRunFrame(CAMetalLayer* layer); \ No newline at end of file diff --git a/src/core/renderer_mtl/renderer_mtl.cpp b/src/core/renderer_mtl/renderer_mtl.cpp index 211fa265..2e6b0d1f 100644 --- a/src/core/renderer_mtl/renderer_mtl.cpp +++ b/src/core/renderer_mtl/renderer_mtl.cpp @@ -57,7 +57,6 @@ void RendererMTL::reset() { void RendererMTL::setMTKLayer(void* layer) { metalLayer = (CA::MetalLayer*)layer; - // metalLayer->retain(); } void RendererMTL::display() { @@ -127,8 +126,9 @@ void RendererMTL::display() { // Inform the vertex buffer cache that the frame ended vertexBufferCache.endFrame(); drawable->release(); + #ifdef PANDA3DS_IOS - // metalLayer->release(); + // metalLayer->autorelease(); #endif } diff --git a/src/ios_driver.mm b/src/ios_driver.mm index 8e965d41..050b222b 100644 --- a/src/ios_driver.mm +++ b/src/ios_driver.mm @@ -30,9 +30,15 @@ IOS_EXPORT void iosCreateEmulator() { printf("Created emulator\n"); } -IOS_EXPORT void iosRunFrame(void* layer) { +IOS_EXPORT void iosRunFrame(CAMetalLayer* layer) { printf("Running a frame\n"); - emulator->getRenderer()->setMTKLayer(layer); + // void* layerBridged = (void*)CFBridgingRetain(layer); + void* layerBridged = (__bridge void*)layer; + + emulator->getRenderer()->setMTKLayer(layerBridged); emulator->runFrame(); + CFRelease(layerBridged); + + // CFBridgingAutorelease(layerBridged); printf("Ran a frame\n"); } \ No newline at end of file