Initial screen layout implementation

This commit is contained in:
wheremyfoodat
2025-07-04 17:53:36 +03:00
parent d06f600b3a
commit 62748eef47
11 changed files with 335 additions and 126 deletions

View File

@@ -10,6 +10,7 @@
#include "PICA/gpu.hpp"
#include "PICA/pica_hash.hpp"
#include "PICA/screen_layout.hpp"
#include "SDL_metal.h"
using namespace PICA;
@@ -105,26 +106,14 @@ void RendererMTL::display() {
if (outputSizeChanged) {
outputSizeChanged = false;
ScreenLayout::WindowCoordinates windowCoords;
ScreenLayout::calculateCoordinates(windowCoords, outputWindowWidth, outputWindowHeight, ScreenLayout::Layout::Default);
const float srcAspect = 400.0 / 480.0;
const float destAspect = float(outputWindowWidth) / float(outputWindowHeight);
int destX = 0, destY = 0, destWidth = outputWindowWidth, destHeight = outputWindowHeight;
if (destAspect > srcAspect) {
// Window is wider than source
destWidth = int(outputWindowHeight * srcAspect + 0.5f);
destX = (outputWindowWidth - destWidth) / 2;
} else {
// Window is taller than source
destHeight = int(outputWindowWidth / srcAspect + 0.5f);
destY = (outputWindowHeight - destHeight) / 2;
}
blitInfo.scale = float(destWidth) / 400.0f;
blitInfo.topScreenX = float(destX);
blitInfo.topScreenY = float(destY + (destHeight - int(480 * blitInfo.scale)) / 2);
blitInfo.bottomScreenX = float(destX) + 40 * blitInfo.scale;
blitInfo.bottomScreenY = blitInfo.topScreenY + 240 * blitInfo.scale;
blitInfo.scale = windowCoords.scale;
blitInfo.topScreenX = windowCoords.topScreenX;
blitInfo.topScreenY = windowCoords.topScreenY;
blitInfo.bottomScreenX = windowCoords.bottomScreenX;
blitInfo.bottomScreenY = windowCoords.bottomScreenY;
}
// Top screen
@@ -800,7 +789,7 @@ void RendererMTL::updateLightingLUT(MTL::RenderCommandEncoder* encoder) {
void RendererMTL::updateFogLUT(MTL::RenderCommandEncoder* encoder) {
gpu.fogLUTDirty = false;
std::array<float, FOG_LUT_TEXTURE_WIDTH* 2> fogLut = {0.0f};
std::array<float, FOG_LUT_TEXTURE_WIDTH * 2> fogLut = {0.0f};
for (int i = 0; i < fogLut.size(); i += 2) {
const uint32_t value = gpu.fogLUT[i >> 1];
@@ -835,8 +824,11 @@ void RendererMTL::textureCopyImpl(
commandEncoder.setRenderPipelineState(blitPipeline);
// Viewport
renderCommandEncoder->setViewport(MTL::Viewport{
double(destRect.left), double(destRect.bottom), double(destRect.right - destRect.left), double(destRect.top - destRect.bottom), 0.0, 1.0});
renderCommandEncoder->setViewport(
MTL::Viewport{
double(destRect.left), double(destRect.bottom), double(destRect.right - destRect.left), double(destRect.top - destRect.bottom), 0.0, 1.0
}
);
float srcRectNDC[4] = {
srcRect.left / (float)srcFramebuffer.size.u(),