fix: present

This commit is contained in:
Samuliak 2024-08-16 15:33:49 +02:00
parent d79d7fea63
commit 0d0152d6e0
6 changed files with 30 additions and 5 deletions

View File

@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.21.1)
# TODO: remove this
set(CMAKE_CXX_FLAGS_DEBUG "-g")
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF)
set(EXPERIMENTAL_VERSION "" CACHE STRING "") # used by CI script to set experimental version
@ -23,7 +26,7 @@ if (ENABLE_VCPKG)
OUTPUT_VARIABLE is_vcpkg_shallow
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(is_vcpkg_shallow STREQUAL "true")
message(STATUS "vcpkg is shallow. Unshallowing it now...")
execute_process(

View File

@ -1,3 +1,3 @@
#pragma once
void* CreateMetalLayer(void* handle);
void* CreateMetalLayer(void* handle, float& scaleX, float& scaleY);

View File

@ -2,7 +2,7 @@
#include "Cafe/HW/Latte/Renderer/MetalView.h"
void* CreateMetalLayer(void* handle)
void* CreateMetalLayer(void* handle, float& scaleX, float& scaleY)
{
NSView* view = (NSView*)handle;
@ -12,5 +12,11 @@ void* CreateMetalLayer(void* handle)
[view addSubview:childView];
const NSRect points = [childView frame];
const NSRect pixels = [childView convertRectToBacking:points];
scaleX = (float)(pixels.size.width / points.size.width);
scaleY = (float)(pixels.size.height / points.size.height);
return childView.layer;
}

View File

@ -138,13 +138,20 @@ MetalRenderer::~MetalRenderer()
m_device->release();
}
// TODO: don't ignore "mainWindow" argument and respect size
// TODO: don't ignore "mainWindow" argument
void MetalRenderer::InitializeLayer(const Vector2i& size, bool mainWindow)
{
const auto& windowInfo = gui_getWindowInfo().window_main;
m_metalLayer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.handle);
m_metalLayer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.handle, m_layerScaleX, m_layerScaleY);
m_metalLayer->setDevice(m_device);
m_metalLayer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
}
// TODO: don't ignore "mainWindow" argument
void MetalRenderer::ResizeLayer(const Vector2i& size, bool mainWindow)
{
m_metalLayer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
}
void MetalRenderer::Initialize()
@ -215,6 +222,7 @@ void MetalRenderer::SwapBuffers(bool swapTV, bool swapDRC)
m_memoryManager->ResetTemporaryBuffers();
}
// TODO: use `shader` for drawing
void MetalRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutputShader* shader, bool useLinearTexFilter,
sint32 imageX, sint32 imageY, sint32 imageWidth, sint32 imageHeight,
bool padView, bool clearBackground)
@ -240,6 +248,9 @@ void MetalRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutput
renderCommandEncoder->setFragmentTexture(presentTexture, 0);
renderCommandEncoder->setFragmentSamplerState((useLinearTexFilter ? m_linearSampler : m_nearestSampler), 0);
renderCommandEncoder->setViewport(MTL::Viewport{(double)imageX, (double)imageY, (double)imageWidth, (double)imageHeight, 0.0, 1.0});
renderCommandEncoder->setScissorRect(MTL::ScissorRect{(uint32)imageX, (uint32)imageY, (uint32)imageWidth, (uint32)imageHeight});
renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(3));
EndEncoding();

View File

@ -141,6 +141,7 @@ public:
}
void InitializeLayer(const Vector2i& size, bool mainWindow);
void ResizeLayer(const Vector2i& size, bool mainWindow);
void Initialize() override;
void Shutdown() override;
@ -330,6 +331,7 @@ public:
private:
CA::MetalLayer* m_metalLayer;
float m_layerScaleX, m_layerScaleY;
class MetalMemoryManager* m_memoryManager;
class MetalPipelineCache* m_pipelineCache;

View File

@ -60,4 +60,7 @@ void MetalCanvas::OnResize(wxSizeEvent& event)
const wxRect refreshRect(size);
RefreshRect(refreshRect, false);
auto metal_renderer = MetalRenderer::GetInstance();
metal_renderer->InitializeLayer({size.x, size.y}, m_is_main_window);
}