Add Metal support to Qt frontend and clean up renderer creation code (#795)

* Qt: Initial support for Metal renderer

* Clean up graphics context code

* Nits

* More nits

* Qt: Move screen-related stuff to own folder

* Qt: Make screen widget polymorphic

* Qt: Re-add Metal

* Add factory for screen widget

* Qt: Support compilation without Metal

* Qt: Fix build without Metal

* Oops

* oops
This commit is contained in:
wheremyfoodat
2025-07-26 23:13:08 +03:00
committed by GitHub
parent 8b0b1939cf
commit 0446bcdaa1
23 changed files with 331 additions and 146 deletions

View File

@@ -10,8 +10,8 @@
#include "PICA/gpu.hpp"
#include "PICA/pica_hash.hpp"
#include "screen_layout.hpp"
#include "SDL_metal.h"
#include "screen_layout.hpp"
using namespace PICA;
@@ -57,9 +57,7 @@ void RendererMTL::reset() {
colorRenderTargetCache.reset();
}
void RendererMTL::setMTKLayer(void* layer) {
metalLayer = (CA::MetalLayer*)layer;
}
void RendererMTL::setMTKLayer(void* layer) { metalLayer = (CA::MetalLayer*)layer; }
void RendererMTL::display() {
CA::MetalDrawable* drawable = metalLayer->nextDrawable();
@@ -151,13 +149,13 @@ void RendererMTL::display() {
drawable->release();
}
void RendererMTL::initGraphicsContext(SDL_Window* window) {
// On iOS, the SwiftUI side handles the MetalLayer
#ifdef PANDA3DS_IOS
void RendererMTL::initGraphicsContext(void* window) {
// On Qt and IOS, the frontend handles the MetalLayer
#if defined(PANDA3DS_FRONTEND_QT) || defined(PANDA3DS_IOS)
device = MTL::CreateSystemDefaultDevice();
#else
// TODO: what should be the type of the view?
void* view = SDL_Metal_CreateView(window);
void* view = SDL_Metal_CreateView((SDL_Window*)window);
metalLayer = (CA::MetalLayer*)SDL_Metal_GetLayer(view);
device = MTL::CreateSystemDefaultDevice();
metalLayer->setDevice(device);