SDL/Qt: Better resizing & fullscreen support

This commit is contained in:
wheremyfoodat 2025-06-28 20:35:38 +03:00
parent bfeee04d3e
commit 630952f36b
6 changed files with 85 additions and 7 deletions

View file

@ -582,7 +582,33 @@ void RendererGL::display() {
if constexpr (!Helpers::isHydraCore()) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
screenFramebuffer.bind(OpenGL::ReadFramebuffer);
glBlitFramebuffer(0, 0, 400, 480, 0, 0, outputWindowWidth, outputWindowHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
if (outputSizeChanged) {
outputSizeChanged = false;
const float srcAspect = 400.0f / 480.0f; // 3DS aspect ratio
const float dstAspect = float(outputWindowWidth) / float(outputWindowHeight);
blitInfo.destWidth = outputWindowWidth;
blitInfo.destHeight = outputWindowHeight;
blitInfo.destX = 0;
blitInfo.destY = 0;
if (dstAspect > srcAspect) {
// Window is wider than source
blitInfo.destWidth = int(outputWindowHeight * srcAspect + 0.5f);
blitInfo.destX = (outputWindowWidth - blitInfo.destWidth) / 2;
} else {
// Window is taller than source
blitInfo.destHeight = int(outputWindowWidth / srcAspect + 0.5f);
blitInfo.destY = (outputWindowHeight - blitInfo.destHeight) / 2;
}
}
glBlitFramebuffer(
0, 0, 400, 480, blitInfo.destX, blitInfo.destY, blitInfo.destX + blitInfo.destWidth, blitInfo.destY + blitInfo.destHeight,
GL_COLOR_BUFFER_BIT, GL_LINEAR
);
}
}

View file

@ -103,16 +103,44 @@ void RendererMTL::display() {
renderCommandEncoder->setRenderPipelineState(displayPipeline);
renderCommandEncoder->setFragmentSamplerState(nearestSampler, 0);
if (outputSizeChanged) {
outputSizeChanged = false;
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;
}
// Top screen
if (topScreen) {
renderCommandEncoder->setViewport(MTL::Viewport{0, 0, 400, 240, 0.0f, 1.0f});
renderCommandEncoder->setViewport(
MTL::Viewport{blitInfo.topScreenX, blitInfo.topScreenY + 240 * blitInfo.scale, 400 * blitInfo.scale, 240 * blitInfo.scale, 0.0f, 1.0f}
);
renderCommandEncoder->setFragmentTexture(topScreen->get().texture, 0);
renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangleStrip, NS::UInteger(0), NS::UInteger(4));
}
// Bottom screen
if (bottomScreen) {
renderCommandEncoder->setViewport(MTL::Viewport{40, 240, 320, 240, 0.0f, 1.0f});
renderCommandEncoder->setViewport(
MTL::Viewport{blitInfo.bottomScreenX, blitInfo.bottomScreenY, 320 * blitInfo.scale, 240 * blitInfo.scale, 0.0f, 1.0f}
);
renderCommandEncoder->setFragmentTexture(bottomScreen->get().texture, 0);
renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangleStrip, NS::UInteger(0), NS::UInteger(4));
}

View file

@ -415,9 +415,8 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
case MessageType::SetScreenSize: {
const u32 width = message.screenSize.width;
const u32 height = message.screenSize.height;
emu->setOutputSize(width, height);
screen->resizeSurface(width, height);
emu->setOutputSize(width, height);
break;
}
@ -566,7 +565,10 @@ void MainWindow::handleScreenResize(u32 width, u32 height) {
message.screenSize.width = width;
message.screenSize.height = height;
sendMessage(message);
if (messageQueueMutex.try_lock()) {
messageQueue.push_back(message);
messageQueueMutex.unlock();
}
}
void MainWindow::initControllers() {