mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 10:51:50 -05:00
metal: draw to on-screen qwidget
This commit is contained in:
parent
7ea460a800
commit
380af618d3
3 changed files with 23 additions and 17 deletions
|
@ -277,6 +277,14 @@ struct VulkanRenderWidget : public RenderWidget {
|
|||
}
|
||||
};
|
||||
|
||||
struct MetalRenderWidget : public RenderWidget {
|
||||
explicit MetalRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
|
||||
// HACK: manually resize the renderable area
|
||||
resize(600, 400);
|
||||
windowHandle()->setSurfaceType(QWindow::MetalSurface);
|
||||
}
|
||||
};
|
||||
|
||||
struct NullRenderWidget : public RenderWidget {
|
||||
explicit NullRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {}
|
||||
};
|
||||
|
@ -1056,8 +1064,9 @@ bool GRenderWindow::InitializeVulkan() {
|
|||
}
|
||||
|
||||
bool GRenderWindow::InitializeMetal() {
|
||||
// TODO: initialize Metal
|
||||
child_widget = new NullRenderWidget(this);
|
||||
auto child = new MetalRenderWidget(this);
|
||||
child_widget = child;
|
||||
child_widget->windowHandle()->create();
|
||||
main_context = std::make_unique<DummyContext>();
|
||||
|
||||
return true;
|
||||
|
|
|
@ -53,9 +53,6 @@ private:
|
|||
const CAMetalLayer* layer;
|
||||
|
||||
RasterizerMetal rasterizer;
|
||||
|
||||
// HACK
|
||||
MTLTexture_t renderTexture;
|
||||
};
|
||||
|
||||
} // namespace Metal
|
||||
|
|
|
@ -13,17 +13,16 @@ RendererMetal::RendererMetal(Core::Frontend::EmuWindow& emu_window,
|
|||
std::unique_ptr<Core::Frontend::GraphicsContext> context_)
|
||||
: RendererBase(emu_window, std::move(context_)), device_memory{device_memory_},
|
||||
gpu{gpu_}, device{},
|
||||
layer(static_cast<const CAMetalLayer*>(render_window.GetWindowInfo().render_surface)),
|
||||
layer([static_cast<const CAMetalLayer*>(render_window.GetWindowInfo().render_surface)
|
||||
retain]),
|
||||
rasterizer(gpu_, device, layer) {
|
||||
// HACK
|
||||
MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm_sRGB
|
||||
width:1280
|
||||
height:720
|
||||
mipmapped:NO];
|
||||
renderTexture = [device.GetDevice() newTextureWithDescriptor:textureDescriptor];
|
||||
// Give the layer our device
|
||||
layer.device = device.GetDevice();
|
||||
}
|
||||
|
||||
RendererMetal::~RendererMetal() = default;
|
||||
RendererMetal::~RendererMetal() {
|
||||
[layer release];
|
||||
}
|
||||
|
||||
void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
|
||||
if (framebuffers.empty()) {
|
||||
|
@ -32,18 +31,19 @@ void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuf
|
|||
|
||||
// HACK
|
||||
@autoreleasepool {
|
||||
//id<CAMetalDrawable> drawable = [layer nextDrawable];
|
||||
id<CAMetalDrawable> drawable = [layer nextDrawable];
|
||||
|
||||
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(1.0, 0.5, 0.0, 1.0);
|
||||
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
||||
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||
renderPassDescriptor.colorAttachments[0].texture = renderTexture;//drawable.texture;
|
||||
renderPassDescriptor.colorAttachments[0].texture = drawable.texture;
|
||||
|
||||
id<MTLCommandBuffer> commandBuffer = [device.GetCommandQueue() commandBuffer];
|
||||
id<MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
|
||||
id<MTLRenderCommandEncoder> renderEncoder = [commandBuffer
|
||||
renderCommandEncoderWithDescriptor:renderPassDescriptor];
|
||||
[renderEncoder endEncoding];
|
||||
//[commandBuffer presentDrawable:drawable];
|
||||
[commandBuffer presentDrawable:drawable];
|
||||
[commandBuffer commit];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue