mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-07 07:42:57 +12:00
Better screen layout support
This commit is contained in:
parent
1c0f65c740
commit
cf321b1ed8
17 changed files with 328 additions and 186 deletions
|
@ -89,6 +89,7 @@ class GPU {
|
|||
PICA::Vertex getImmediateModeVertex();
|
||||
|
||||
void getAcceleratedDrawInfo(PICA::DrawAcceleration& accel, bool indexed);
|
||||
|
||||
public:
|
||||
// 256 entries per LUT with each LUT as its own row forming a 2D image 256 * LUT_COUNT
|
||||
// Encoded in PICA native format
|
||||
|
@ -134,6 +135,8 @@ class GPU {
|
|||
|
||||
// Used for setting the size of the window we'll be outputting graphics to
|
||||
void setOutputSize(u32 width, u32 height) { renderer->setOutputSize(width, height); }
|
||||
// Used for notifying the renderer the screen layout has changed
|
||||
void reloadScreenLayout() { renderer->reloadScreenLayout(); }
|
||||
|
||||
// TODO: Emulate the transfer engine & its registers
|
||||
// Then this can be emulated by just writing the appropriate values there
|
||||
|
@ -181,6 +184,7 @@ class GPU {
|
|||
}
|
||||
|
||||
Renderer* getRenderer() { return renderer.get(); }
|
||||
|
||||
private:
|
||||
// GPU external registers
|
||||
// We have them in the end of the struct for cache locality reasons. Tl;dr we want the more commonly used things to be packed in the start
|
||||
|
@ -189,8 +193,8 @@ class GPU {
|
|||
|
||||
ALWAYS_INLINE void setVsOutputMask(u32 val) {
|
||||
val &= 0xffff;
|
||||
|
||||
// Avoid recomputing this if not necessary
|
||||
|
||||
// Avoid recomputing this if not necessary
|
||||
if (oldVsOutputMask != val) [[unlikely]] {
|
||||
oldVsOutputMask = val;
|
||||
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
#pragma once
|
||||
#include <algorithm>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace ScreenLayout {
|
||||
static constexpr u32 TOP_SCREEN_WIDTH = 400;
|
||||
static constexpr u32 BOTTOM_SCREEN_WIDTH = 320;
|
||||
static constexpr u32 TOP_SCREEN_HEIGHT = 240;
|
||||
static constexpr u32 BOTTOM_SCREEN_HEIGHT = 240;
|
||||
|
||||
// The bottom screen is less wide by 80 pixels, so we center it by offsetting it 40 pixels right
|
||||
static constexpr u32 BOTTOM_SCREEN_X_OFFSET = 40;
|
||||
static constexpr u32 CONSOLE_HEIGHT = TOP_SCREEN_HEIGHT + BOTTOM_SCREEN_HEIGHT;
|
||||
|
||||
enum class Layout {
|
||||
Default, // Top screen up, bottom screen down
|
||||
DefaultFlipped, // Top screen down, bottom screen up
|
||||
SideBySide, // Top screen left, bottom screen right,
|
||||
SideBySideFlipped, // Top screen right, bottom screen left,
|
||||
};
|
||||
|
||||
// For properly handling touchscreen, we have to remember what window coordinates our screens map to
|
||||
// We also remember some more information that is useful to our renderers, particularly for the final screen blit.
|
||||
struct WindowCoordinates {
|
||||
u32 topScreenX = 0;
|
||||
u32 topScreenY = 0;
|
||||
u32 topScreenWidth = TOP_SCREEN_WIDTH;
|
||||
u32 topScreenHeight = TOP_SCREEN_HEIGHT;
|
||||
|
||||
u32 bottomScreenX = BOTTOM_SCREEN_X_OFFSET;
|
||||
u32 bottomScreenY = TOP_SCREEN_HEIGHT;
|
||||
u32 bottomScreenWidth = BOTTOM_SCREEN_WIDTH;
|
||||
u32 bottomScreenHeight = BOTTOM_SCREEN_HEIGHT;
|
||||
|
||||
u32 windowWidth = topScreenWidth;
|
||||
u32 windowHeight = topScreenHeight + bottomScreenHeight;
|
||||
|
||||
// Information used when optimizing the final screen blit into a single blit
|
||||
struct {
|
||||
int destX = 0, destY = 0;
|
||||
int destWidth = TOP_SCREEN_WIDTH;
|
||||
int destHeight = CONSOLE_HEIGHT;
|
||||
} singleBlitInfo;
|
||||
};
|
||||
|
||||
// Calculate screen coordinates on the screen for a given layout & a given size for the output window
|
||||
// Used in both the renderers and in the frontends (To eg calculate touch screen boundaries)
|
||||
static void calculateCoordinates(WindowCoordinates& coordinates, u32 outputWindowWidth, u32 outputWindowHeight, Layout layout) {
|
||||
layout = Layout::SideBySideFlipped;
|
||||
const float topScreenPercentage = 0.5f;
|
||||
|
||||
const float destAspect = float(outputWindowWidth) / float(outputWindowHeight);
|
||||
|
||||
if (layout == Layout::Default || layout == Layout::DefaultFlipped) {
|
||||
// Calculate available height for each screen based on split
|
||||
int availableTopHeight = int(outputWindowHeight * topScreenPercentage + 0.5f);
|
||||
int availableBottomHeight = outputWindowHeight - availableTopHeight;
|
||||
|
||||
// Calculate scales for top and bottom screens, and then the actual sizes
|
||||
float scaleTopX = float(outputWindowWidth) / float(TOP_SCREEN_WIDTH);
|
||||
float scaleTopY = float(availableTopHeight) / float(TOP_SCREEN_HEIGHT);
|
||||
float scaleTop = std::min(scaleTopX, scaleTopY);
|
||||
|
||||
float scaleBottomX = float(outputWindowWidth) / float(BOTTOM_SCREEN_WIDTH);
|
||||
float scaleBottomY = float(availableBottomHeight) / float(BOTTOM_SCREEN_HEIGHT);
|
||||
float scaleBottom = std::min(scaleBottomX, scaleBottomY);
|
||||
|
||||
int topScreenWidth = int(TOP_SCREEN_WIDTH * scaleTop + 0.5f);
|
||||
int topScreenHeight = int(TOP_SCREEN_HEIGHT * scaleTop + 0.5f);
|
||||
|
||||
int bottomScreenWidth = int(BOTTOM_SCREEN_WIDTH * scaleBottom + 0.5f);
|
||||
int bottomScreenHeight = int(BOTTOM_SCREEN_HEIGHT * scaleBottom + 0.5f);
|
||||
|
||||
// Center screens horizontally
|
||||
int topScreenX = (outputWindowWidth - topScreenWidth) / 2;
|
||||
int bottomScreenX = (outputWindowWidth - bottomScreenWidth) / 2;
|
||||
|
||||
coordinates.topScreenWidth = topScreenWidth;
|
||||
coordinates.topScreenHeight = topScreenHeight;
|
||||
coordinates.bottomScreenWidth = bottomScreenWidth;
|
||||
coordinates.bottomScreenHeight = bottomScreenHeight;
|
||||
|
||||
coordinates.topScreenX = topScreenX;
|
||||
coordinates.bottomScreenX = bottomScreenX;
|
||||
|
||||
if (layout == Layout::Default) {
|
||||
coordinates.topScreenY = 0;
|
||||
coordinates.bottomScreenY = topScreenHeight;
|
||||
} else {
|
||||
coordinates.bottomScreenY = 0;
|
||||
coordinates.topScreenY = bottomScreenHeight;
|
||||
}
|
||||
|
||||
coordinates.windowWidth = outputWindowWidth;
|
||||
coordinates.windowHeight = outputWindowHeight;
|
||||
|
||||
// Default layout can be rendered using a single blit, flipped layout can't
|
||||
if (layout == Layout::Default) {
|
||||
coordinates.singleBlitInfo.destX = coordinates.topScreenX;
|
||||
coordinates.singleBlitInfo.destY = coordinates.topScreenY;
|
||||
coordinates.singleBlitInfo.destWidth = coordinates.topScreenWidth;
|
||||
coordinates.singleBlitInfo.destHeight = coordinates.topScreenHeight + coordinates.bottomScreenHeight;
|
||||
} else {
|
||||
// Dummy data for the single blit info, as we can't render the screen in 1 blit when the screens are side-by-sid
|
||||
coordinates.singleBlitInfo.destX = 0;
|
||||
coordinates.singleBlitInfo.destY = 0;
|
||||
coordinates.singleBlitInfo.destWidth = 0;
|
||||
coordinates.singleBlitInfo.destHeight = 0;
|
||||
}
|
||||
} else if (layout == Layout::SideBySide || layout == Layout::SideBySideFlipped) {
|
||||
// Calculate available width for each screen based on split
|
||||
int availableTopWidth = int(outputWindowWidth * topScreenPercentage + 0.5f);
|
||||
int availableBottomWidth = outputWindowWidth - availableTopWidth;
|
||||
|
||||
// Calculate scales for top and bottom screens, and then the actual sizes
|
||||
float scaleTop = std::min(float(availableTopWidth) / float(TOP_SCREEN_WIDTH), float(outputWindowHeight) / float(TOP_SCREEN_HEIGHT));
|
||||
float scaleBottom =
|
||||
std::min(float(availableBottomWidth) / float(BOTTOM_SCREEN_WIDTH), float(outputWindowHeight) / float(BOTTOM_SCREEN_HEIGHT));
|
||||
|
||||
int topScreenWidth = int(TOP_SCREEN_WIDTH * scaleTop + 0.5f);
|
||||
int topScreenHeight = int(TOP_SCREEN_HEIGHT * scaleTop + 0.5f);
|
||||
int bottomScreenWidth = int(BOTTOM_SCREEN_WIDTH * scaleBottom + 0.5f);
|
||||
int bottomScreenHeight = int(BOTTOM_SCREEN_HEIGHT * scaleBottom + 0.5f);
|
||||
|
||||
// Vertically center the tallest screen
|
||||
int maxHeight = std::max(topScreenHeight, bottomScreenHeight);
|
||||
int baseY = (outputWindowHeight - maxHeight) / 2;
|
||||
|
||||
int topScreenY = baseY + (maxHeight - topScreenHeight) / 2;
|
||||
int bottomScreenY = baseY + (maxHeight - bottomScreenHeight) / 2;
|
||||
|
||||
if (layout == Layout::SideBySide) {
|
||||
coordinates.topScreenX = (outputWindowWidth - (topScreenWidth + bottomScreenWidth)) / 2;
|
||||
coordinates.bottomScreenX = coordinates.topScreenX + topScreenWidth;
|
||||
} else {
|
||||
coordinates.bottomScreenX = (outputWindowWidth - (topScreenWidth + bottomScreenWidth)) / 2;
|
||||
coordinates.topScreenX = coordinates.bottomScreenX + bottomScreenWidth;
|
||||
}
|
||||
|
||||
coordinates.topScreenY = topScreenY;
|
||||
coordinates.topScreenWidth = topScreenWidth;
|
||||
coordinates.topScreenHeight = topScreenHeight;
|
||||
|
||||
coordinates.bottomScreenY = bottomScreenY;
|
||||
coordinates.bottomScreenWidth = bottomScreenWidth;
|
||||
coordinates.bottomScreenHeight = bottomScreenHeight;
|
||||
|
||||
coordinates.windowWidth = outputWindowWidth;
|
||||
coordinates.windowHeight = outputWindowHeight;
|
||||
|
||||
// Dummy data for the single blit info, as we can't render the screen in 1 blit when the screens are side-by-side
|
||||
coordinates.singleBlitInfo.destX = 0;
|
||||
coordinates.singleBlitInfo.destY = 0;
|
||||
coordinates.singleBlitInfo.destWidth = 0;
|
||||
coordinates.singleBlitInfo.destHeight = 0;
|
||||
} else {
|
||||
Helpers::panic("Unimplemented screen layout");
|
||||
}
|
||||
}
|
||||
} // namespace ScreenLayout
|
|
@ -2,6 +2,7 @@
|
|||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "screen_layout.hpp"
|
||||
#include "audio/dsp_core.hpp"
|
||||
#include "frontend_settings.hpp"
|
||||
#include "renderer.hpp"
|
||||
|
@ -69,6 +70,9 @@ struct EmulatorConfig {
|
|||
bool accelerateShaders = accelerateShadersDefault;
|
||||
bool hashTextures = hashTexturesDefault;
|
||||
|
||||
ScreenLayout::Layout screenLayout = ScreenLayout::Layout::Default;
|
||||
float topScreenSize = 0.5;
|
||||
|
||||
bool accurateShaderMul = false;
|
||||
bool discordRpcEnabled = false;
|
||||
|
||||
|
|
|
@ -115,6 +115,8 @@ class Emulator {
|
|||
|
||||
RomFS::DumpingResult dumpRomFS(const std::filesystem::path& path);
|
||||
void setOutputSize(u32 width, u32 height) { gpu.setOutputSize(width, height); }
|
||||
void reloadScreenLayout() { gpu.reloadScreenLayout(); }
|
||||
|
||||
void deinitGraphicsContext() { gpu.deinitGraphicsContext(); }
|
||||
|
||||
// Reloads some settings that require special handling, such as audio enable
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "PICA/screen_layout.hpp"
|
||||
#include "screen_layout.hpp"
|
||||
#include "gl/context.h"
|
||||
#include "window_info.h"
|
||||
|
||||
|
@ -33,6 +33,11 @@ class ScreenWidget : public QWidget {
|
|||
// Coordinates (x/y/width/height) for the two screens in window space, used for properly handling touchscreen regardless
|
||||
// of layout or resizing
|
||||
ScreenLayout::WindowCoordinates screenCoordinates;
|
||||
// Screen layouts and sizes
|
||||
ScreenLayout::Layout screenLayout = ScreenLayout::Layout::Default;
|
||||
float topScreenSize = 0.5f;
|
||||
|
||||
void reloadScreenLayout(ScreenLayout::Layout newLayout, float newTopScreenSize);
|
||||
|
||||
private:
|
||||
std::unique_ptr<GL::Context> glContext = nullptr;
|
||||
|
@ -44,4 +49,6 @@ class ScreenWidget : public QWidget {
|
|||
int scaledWindowWidth() const;
|
||||
int scaledWindowHeight() const;
|
||||
std::optional<WindowInfo> getWindowInfo();
|
||||
|
||||
void reloadScreenCoordinates();
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <filesystem>
|
||||
|
||||
#include "PICA/screen_layout.hpp"
|
||||
#include "screen_layout.hpp"
|
||||
#include "emulator.hpp"
|
||||
#include "input_mappings.hpp"
|
||||
|
||||
|
|
|
@ -130,4 +130,5 @@ class Renderer {
|
|||
|
||||
void setConfig(EmulatorConfig* config) { emulatorConfig = config; }
|
||||
void setHashTextures(bool setting) { hashTextures = setting; }
|
||||
void reloadScreenLayout() { outputSizeChanged = true; }
|
||||
};
|
||||
|
|
58
include/screen_layout.hpp
Normal file
58
include/screen_layout.hpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace ScreenLayout {
|
||||
static constexpr u32 TOP_SCREEN_WIDTH = 400;
|
||||
static constexpr u32 BOTTOM_SCREEN_WIDTH = 320;
|
||||
static constexpr u32 TOP_SCREEN_HEIGHT = 240;
|
||||
static constexpr u32 BOTTOM_SCREEN_HEIGHT = 240;
|
||||
|
||||
// The bottom screen is less wide by 80 pixels, so we center it by offsetting it 40 pixels right
|
||||
static constexpr u32 BOTTOM_SCREEN_X_OFFSET = 40;
|
||||
static constexpr u32 CONSOLE_HEIGHT = TOP_SCREEN_HEIGHT + BOTTOM_SCREEN_HEIGHT;
|
||||
|
||||
enum class Layout {
|
||||
Default = 0, // Top screen up, bottom screen down
|
||||
DefaultFlipped, // Top screen down, bottom screen up
|
||||
SideBySide, // Top screen left, bottom screen right,
|
||||
SideBySideFlipped, // Top screen right, bottom screen left,
|
||||
};
|
||||
|
||||
// For properly handling touchscreen, we have to remember what window coordinates our screens map to
|
||||
// We also remember some more information that is useful to our renderers, particularly for the final screen blit.
|
||||
struct WindowCoordinates {
|
||||
u32 topScreenX = 0;
|
||||
u32 topScreenY = 0;
|
||||
u32 topScreenWidth = TOP_SCREEN_WIDTH;
|
||||
u32 topScreenHeight = TOP_SCREEN_HEIGHT;
|
||||
|
||||
u32 bottomScreenX = BOTTOM_SCREEN_X_OFFSET;
|
||||
u32 bottomScreenY = TOP_SCREEN_HEIGHT;
|
||||
u32 bottomScreenWidth = BOTTOM_SCREEN_WIDTH;
|
||||
u32 bottomScreenHeight = BOTTOM_SCREEN_HEIGHT;
|
||||
|
||||
u32 windowWidth = topScreenWidth;
|
||||
u32 windowHeight = topScreenHeight + bottomScreenHeight;
|
||||
|
||||
// Information used when optimizing the final screen blit into a single blit
|
||||
struct {
|
||||
// Can we actually render both of the screens in a single blit?
|
||||
bool canDoSingleBlit = false;
|
||||
// Blit information used if we can
|
||||
int destX = 0, destY = 0;
|
||||
int destWidth = TOP_SCREEN_WIDTH;
|
||||
int destHeight = CONSOLE_HEIGHT;
|
||||
} singleBlitInfo;
|
||||
};
|
||||
|
||||
// Calculate screen coordinates on the screen for a given layout & a given size for the output window
|
||||
// Used in both the renderers and in the frontends (To eg calculate touch screen boundaries)
|
||||
void calculateCoordinates(
|
||||
WindowCoordinates& coordinates, u32 outputWindowWidth, u32 outputWindowHeight, float topScreenPercentage, Layout layout
|
||||
);
|
||||
|
||||
Layout layoutFromString(std::string inString);
|
||||
const char* layoutToString(Layout layout);
|
||||
} // namespace ScreenLayout
|
Loading…
Add table
Add a link
Reference in a new issue