ios: Pass CAMetalLayer instead of void* to Obj-C++ bridging header

This commit is contained in:
wheremyfoodat 2025-03-08 22:11:56 +02:00
parent e378a52b5a
commit 90279e6f9e
4 changed files with 14 additions and 6 deletions

View file

@ -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})

View file

@ -1,4 +1,6 @@
#pragma once
#include <Foundation/Foundation.h>
#include <QuartzCore/QuartzCore.h>
void iosCreateEmulator();
void iosRunFrame(void* drawable);
void iosRunFrame(CAMetalLayer* layer);

View file

@ -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
}

View file

@ -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");
}