mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-02 13:02:44 +01: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 {
|
struct NullRenderWidget : public RenderWidget {
|
||||||
explicit NullRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {}
|
explicit NullRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {}
|
||||||
};
|
};
|
||||||
|
@ -1056,8 +1064,9 @@ bool GRenderWindow::InitializeVulkan() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GRenderWindow::InitializeMetal() {
|
bool GRenderWindow::InitializeMetal() {
|
||||||
// TODO: initialize Metal
|
auto child = new MetalRenderWidget(this);
|
||||||
child_widget = new NullRenderWidget(this);
|
child_widget = child;
|
||||||
|
child_widget->windowHandle()->create();
|
||||||
main_context = std::make_unique<DummyContext>();
|
main_context = std::make_unique<DummyContext>();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -53,9 +53,6 @@ private:
|
||||||
const CAMetalLayer* layer;
|
const CAMetalLayer* layer;
|
||||||
|
|
||||||
RasterizerMetal rasterizer;
|
RasterizerMetal rasterizer;
|
||||||
|
|
||||||
// HACK
|
|
||||||
MTLTexture_t renderTexture;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Metal
|
} // namespace Metal
|
||||||
|
|
|
@ -13,17 +13,16 @@ RendererMetal::RendererMetal(Core::Frontend::EmuWindow& emu_window,
|
||||||
std::unique_ptr<Core::Frontend::GraphicsContext> context_)
|
std::unique_ptr<Core::Frontend::GraphicsContext> context_)
|
||||||
: RendererBase(emu_window, std::move(context_)), device_memory{device_memory_},
|
: RendererBase(emu_window, std::move(context_)), device_memory{device_memory_},
|
||||||
gpu{gpu_}, device{},
|
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) {
|
rasterizer(gpu_, device, layer) {
|
||||||
// HACK
|
// Give the layer our device
|
||||||
MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm_sRGB
|
layer.device = device.GetDevice();
|
||||||
width:1280
|
|
||||||
height:720
|
|
||||||
mipmapped:NO];
|
|
||||||
renderTexture = [device.GetDevice() newTextureWithDescriptor:textureDescriptor];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RendererMetal::~RendererMetal() = default;
|
RendererMetal::~RendererMetal() {
|
||||||
|
[layer release];
|
||||||
|
}
|
||||||
|
|
||||||
void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
|
void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
|
||||||
if (framebuffers.empty()) {
|
if (framebuffers.empty()) {
|
||||||
|
@ -32,18 +31,19 @@ void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuf
|
||||||
|
|
||||||
// HACK
|
// HACK
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
//id<CAMetalDrawable> drawable = [layer nextDrawable];
|
id<CAMetalDrawable> drawable = [layer nextDrawable];
|
||||||
|
|
||||||
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||||
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(1.0, 0.5, 0.0, 1.0);
|
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(1.0, 0.5, 0.0, 1.0);
|
||||||
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
||||||
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
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<MTLCommandBuffer> commandBuffer = [device.GetCommandQueue() commandBuffer];
|
||||||
id<MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
|
id<MTLRenderCommandEncoder> renderEncoder = [commandBuffer
|
||||||
|
renderCommandEncoderWithDescriptor:renderPassDescriptor];
|
||||||
[renderEncoder endEncoding];
|
[renderEncoder endEncoding];
|
||||||
//[commandBuffer presentDrawable:drawable];
|
[commandBuffer presentDrawable:drawable];
|
||||||
[commandBuffer commit];
|
[commandBuffer commit];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue