rework the present system

This commit is contained in:
Samuliak 2024-08-23 10:52:20 +02:00
parent 6bb191212b
commit d4a1074425
5 changed files with 120 additions and 47 deletions

View file

@ -0,0 +1,45 @@
#include "Cafe/HW/Latte/Renderer/Metal/MetalLayerHandle.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalLayer.h"
#include "gui/guiWrapper.h"
MetalLayerHandle::MetalLayerHandle(MTL::Device* device, const Vector2i& size)
{
const auto& windowInfo = gui_getWindowInfo().window_main;
m_layer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.handle, m_layerScaleX, m_layerScaleY);
m_layer->setDevice(device);
m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
}
MetalLayerHandle::~MetalLayerHandle()
{
if (m_layer)
m_layer->release();
}
void MetalLayerHandle::Resize(const Vector2i& size)
{
m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
}
bool MetalLayerHandle::AcquireDrawable()
{
if (m_drawable)
return true;
m_drawable = m_layer->nextDrawable();
if (!m_drawable)
{
debug_printf("failed to acquire next drawable\n");
return false;
}
return true;
}
void MetalLayerHandle::PresentDrawable(MTL::CommandBuffer* commandBuffer)
{
commandBuffer->presentDrawable(m_drawable);
m_drawable = nullptr;
}