Panda3DS/src/core/renderer_mtl/renderer_mtl.cpp
2024-07-02 09:11:09 +02:00

75 lines
2.5 KiB
C++

#include "renderer_mtl/renderer_mtl.hpp"
#include <cmrc/cmrc.hpp>
#include "SDL_metal.h"
CMRC_DECLARE(RendererMTL);
RendererMTL::RendererMTL(GPU& gpu, const std::array<u32, regNum>& internalRegs, const std::array<u32, extRegNum>& externalRegs)
: Renderer(gpu, internalRegs, externalRegs) {}
RendererMTL::~RendererMTL() {}
void RendererMTL::reset() {
// TODO: implement
}
void RendererMTL::display() {
CA::MetalDrawable* drawable = metalLayer->nextDrawable();
MTL::CommandBuffer* commandBuffer = commandQueue->commandBuffer();
MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init();
MTL::RenderPassColorAttachmentDescriptor* colorAttachment = renderPassDescriptor->colorAttachments()->object(0);
colorAttachment->setTexture(drawable->texture());
colorAttachment->setLoadAction(MTL::LoadActionClear);
colorAttachment->setClearColor(MTL::ClearColor{1.0f, 0.0f, 0.0f, 1.0f});
colorAttachment->setStoreAction(MTL::StoreActionStore);
MTL::RenderCommandEncoder* renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
renderCommandEncoder->endEncoding();
commandBuffer->presentDrawable(drawable);
commandBuffer->commit();
}
void RendererMTL::initGraphicsContext(SDL_Window* window) {
// 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();
// HACK
MTL::TextureDescriptor* descriptor = MTL::TextureDescriptor::texture2DDescriptor(MTL::PixelFormatRGBA8Unorm, 400, 240, false);
topScreenTexture = device->newTexture(descriptor);
// Pipelines
auto mtlResources = cmrc::RendererMTL::get_filesystem();
auto shaderSource = mtlResources.open("metal_shaders.metal");
}
void RendererMTL::clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control) {
// TODO: implement
}
void RendererMTL::displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags) {
// TODO: implement
}
void RendererMTL::textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 inputSize, u32 outputSize, u32 flags) {
// TODO: implement
}
void RendererMTL::drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices) {
// TODO: implement
}
void RendererMTL::screenshot(const std::string& name) {
// TODO: implement
}
void RendererMTL::deinitGraphicsContext() {
// TODO: implement
}