mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-08 00:02:58 +12:00
More iOS progress
This commit is contained in:
parent
1948bea209
commit
9bc50a4b9c
6 changed files with 67 additions and 26 deletions
|
@ -30,7 +30,6 @@ PICA::ColorFmt ToColorFormat(u32 format) {
|
|||
}
|
||||
|
||||
MTL::Library* loadLibrary(MTL::Device* device, const cmrc::file& shaderSource) {
|
||||
// MTL::CompileOptions* compileOptions = MTL::CompileOptions::alloc()->init();
|
||||
NS::Error* error = nullptr;
|
||||
MTL::Library* library = device->newLibrary(Metal::createDispatchData(shaderSource.begin(), shaderSource.size()), &error);
|
||||
// MTL::Library* library = device->newLibrary(NS::String::string(source.c_str(), NS::ASCIIStringEncoding), compileOptions, &error);
|
||||
|
@ -56,16 +55,38 @@ void RendererMTL::reset() {
|
|||
colorRenderTargetCache.reset();
|
||||
}
|
||||
|
||||
void RendererMTL::display() {
|
||||
#ifdef PANDA3DS_IOS
|
||||
return;
|
||||
#endif
|
||||
void RendererMTL::setMTKDrawable(void* drawable, void* tex) {
|
||||
this->metalDrawable = (CA::MetalDrawable*)drawable;
|
||||
this->drawableTexture = (MTL::Texture*)tex;
|
||||
}
|
||||
|
||||
void RendererMTL::display() {
|
||||
static int frameCount = 0;
|
||||
frameCount++;
|
||||
|
||||
auto manager = MTL::CaptureManager::sharedCaptureManager();
|
||||
auto captureDescriptor = MTL::CaptureDescriptor::alloc()->init();
|
||||
if (frameCount == 200) {
|
||||
captureDescriptor->setCaptureObject(device);
|
||||
manager->startCapture(captureDescriptor, nullptr);
|
||||
}
|
||||
|
||||
#ifdef PANDA3DS_IOS
|
||||
CA::MetalDrawable* drawable = metalDrawable;
|
||||
if (!drawable) {
|
||||
return;
|
||||
}
|
||||
|
||||
MTL::Texture* texture = drawableTexture;
|
||||
#else
|
||||
CA::MetalDrawable* drawable = metalLayer->nextDrawable();
|
||||
if (!drawable) {
|
||||
return;
|
||||
}
|
||||
|
||||
MTL::Texture* texture = drawable->getTexture();
|
||||
#endif
|
||||
|
||||
using namespace PICA::ExternalRegs;
|
||||
|
||||
// Top screen
|
||||
|
@ -91,13 +112,13 @@ void RendererMTL::display() {
|
|||
|
||||
MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init();
|
||||
MTL::RenderPassColorAttachmentDescriptor* colorAttachment = renderPassDescriptor->colorAttachments()->object(0);
|
||||
colorAttachment->setTexture(drawable->texture());
|
||||
colorAttachment->setTexture(texture);
|
||||
colorAttachment->setLoadAction(MTL::LoadActionClear);
|
||||
colorAttachment->setClearColor(MTL::ClearColor{0.0f, 0.0f, 0.0f, 1.0f});
|
||||
colorAttachment->setStoreAction(MTL::StoreActionStore);
|
||||
|
||||
nextRenderPassName = "Display";
|
||||
beginRenderPassIfNeeded(renderPassDescriptor, false, drawable->texture());
|
||||
beginRenderPassIfNeeded(renderPassDescriptor, false, texture);
|
||||
renderCommandEncoder->setRenderPipelineState(displayPipeline);
|
||||
renderCommandEncoder->setFragmentSamplerState(nearestSampler, 0);
|
||||
|
||||
|
@ -124,24 +145,32 @@ void RendererMTL::display() {
|
|||
// Inform the vertex buffer cache that the frame ended
|
||||
vertexBufferCache.endFrame();
|
||||
|
||||
// Release
|
||||
// Release the drawable (not on iOS cause SwiftUI handles it there)
|
||||
#ifndef PANDA3DS_IOS
|
||||
drawable->release();
|
||||
#endif
|
||||
|
||||
if (frameCount == 200) {
|
||||
manager->stopCapture();
|
||||
}
|
||||
captureDescriptor->release();
|
||||
}
|
||||
|
||||
void RendererMTL::initGraphicsContext(SDL_Window* window) {
|
||||
// TODO: what should be the type of the view?
|
||||
|
||||
// On iOS, the SwiftUI side handles MetalLayer & the CommandQueue
|
||||
#ifdef PANDA3DS_IOS
|
||||
// On iOS, the SwiftUI side handles device<->MTKView interaction
|
||||
device = MTL::CreateSystemDefaultDevice();
|
||||
#else
|
||||
// TODO: what should be the type of the view?
|
||||
void* view = SDL_Metal_CreateView(window);
|
||||
metalLayer = (CA::MetalLayer*)SDL_Metal_GetLayer(view);
|
||||
device = MTL::CreateSystemDefaultDevice();
|
||||
metalLayer->setDevice(device);
|
||||
commandQueue = device->newCommandQueue();
|
||||
#endif
|
||||
|
||||
commandQueue = device->newCommandQueue();
|
||||
printf("C++ device pointer: %p\n", device);
|
||||
|
||||
// Textures
|
||||
MTL::TextureDescriptor* textureDescriptor = MTL::TextureDescriptor::alloc()->init();
|
||||
textureDescriptor->setTextureType(MTL::TextureType2D);
|
||||
|
@ -816,7 +845,7 @@ void RendererMTL::beginRenderPassIfNeeded(
|
|||
) {
|
||||
createCommandBufferIfNeeded();
|
||||
|
||||
if (doesClears || !renderCommandEncoder || colorTexture != lastColorTexture ||
|
||||
if (1 ||doesClears || !renderCommandEncoder || colorTexture != lastColorTexture ||
|
||||
(depthTexture != lastDepthTexture && !(lastDepthTexture && !depthTexture))) {
|
||||
endRenderPass();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue