diff --git a/include/renderer.hpp b/include/renderer.hpp index ef1d27d4..d32077f6 100644 --- a/include/renderer.hpp +++ b/include/renderer.hpp @@ -87,8 +87,8 @@ class Renderer { virtual void setupGLES() {} // Only relevant for Metal renderer on iOS - // Passes a SwiftUI MTKView Drawable to the renderer - virtual void setMTKDrawable(void* drawable) {}; + // Passes a SwiftUI MTKView's layer (CAMetalLayer) to the renderer + virtual void setMTKLayer(void* layer) {}; // This function is called on every draw call before parsing vertex data. // It is responsible for things like looking up which vertex/fragment shaders to use, recompiling them if they don't exist, choosing between diff --git a/include/renderer_mtl/renderer_mtl.hpp b/include/renderer_mtl/renderer_mtl.hpp index e11485bd..10fac7cd 100644 --- a/include/renderer_mtl/renderer_mtl.hpp +++ b/include/renderer_mtl/renderer_mtl.hpp @@ -42,11 +42,10 @@ class RendererMTL final : public Renderer { virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override {} #endif - virtual void setMTKDrawable(void* drawable) override; + virtual void setMTKLayer(void* layer) override; private: CA::MetalLayer* metalLayer = nullptr; - CA::MetalDrawable* metalDrawable = nullptr; MTL::Device* device = nullptr; MTL::CommandQueue* commandQueue = nullptr; diff --git a/src/core/renderer_mtl/renderer_mtl.cpp b/src/core/renderer_mtl/renderer_mtl.cpp index 4c40f064..211fa265 100644 --- a/src/core/renderer_mtl/renderer_mtl.cpp +++ b/src/core/renderer_mtl/renderer_mtl.cpp @@ -55,29 +55,21 @@ void RendererMTL::reset() { colorRenderTargetCache.reset(); } -void RendererMTL::setMTKDrawable(void* drawable) { - metalDrawable = (CA::MetalDrawable*)drawable; +void RendererMTL::setMTKLayer(void* layer) { + metalLayer = (CA::MetalLayer*)layer; + // metalLayer->retain(); } void RendererMTL::display() { -#ifdef PANDA3DS_IOS - CA::MetalDrawable* drawable = metalDrawable; - if (!drawable) { - return; - } - - MTL::Texture* texture = drawable->texture(); -#else CA::MetalDrawable* drawable = metalLayer->nextDrawable(); if (!drawable) { return; } MTL::Texture* texture = drawable->texture(); -#endif using namespace PICA::ExternalRegs; - printf("Device pointer: %p\nDrawable pointer: %p\nTexture pointer: %p\n", device, drawable, texture); + printf("Layer pointer: %p\nDevice pointer: %p\nDrawable pointer: %p\nTexture pointer: %p\n", metalLayer, device, drawable, texture); // Top screen const u32 topActiveFb = externalRegs[Framebuffer0Select] & 1; @@ -134,10 +126,9 @@ void RendererMTL::display() { // Inform the vertex buffer cache that the frame ended vertexBufferCache.endFrame(); - - // Release the drawable (not on iOS cause SwiftUI handles it there) -#ifndef PANDA3DS_IOS drawable->release(); +#ifdef PANDA3DS_IOS + // metalLayer->release(); #endif } diff --git a/src/ios_driver.mm b/src/ios_driver.mm index c09768c7..8e965d41 100644 --- a/src/ios_driver.mm +++ b/src/ios_driver.mm @@ -30,9 +30,9 @@ IOS_EXPORT void iosCreateEmulator() { printf("Created emulator\n"); } -IOS_EXPORT void iosRunFrame(void* drawable) { +IOS_EXPORT void iosRunFrame(void* layer) { printf("Running a frame\n"); - emulator->getRenderer()->setMTKDrawable(drawable); + emulator->getRenderer()->setMTKLayer(layer); emulator->runFrame(); printf("Ran a frame\n"); } \ No newline at end of file