port: use proper aspect for 2D elements

this means that now scaling at most 4:3 resolutions will be a bit mangled, since the real base resolution is 320x220
This commit is contained in:
fgsfds committed 2023-12-03 21:10:41 +01:00
1 parent 2c20a0487e
commit f96e7da00f
3 files changed
+10 -6

No files matched your search

+1
View File
@@ -27,6 +27,7 @@ extern struct XYWidthHeight
gfx_current_game_window_viewport; // The area of the window the game is drawn to, (0, 0) is top-left corner
extern uint32_t gfx_msaa_level;
extern struct XYWidthHeight gfx_current_native_viewport; // The internal/native video mode of the game
extern float gfx_current_native_aspect; // The aspect ratio of the above mode
extern bool gfx_framebuffers_enabled;
void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name,
+6 -5
View File
@@ -217,6 +217,7 @@ struct GfxDimensions gfx_current_dimensions;
static struct GfxDimensions gfx_prev_dimensions;
struct XYWidthHeight gfx_current_game_window_viewport;
struct XYWidthHeight gfx_current_native_viewport;
float gfx_current_native_aspect = 4.f / 3.f;
bool gfx_framebuffers_enabled = true;
static bool game_renders_to_framebuffer;
@@ -1652,12 +1653,12 @@ static void gfx_sp_geometry_mode(uint32_t clear, uint32_t set) {
static inline void gfx_update_aspect_mode(void) {
const uint32_t side = rsp.aspect_mode & G_ASPECT_CENTER_EXT;
rsp.aspect_scale = rsp.aspect_mode ? (4.f / 3.f) : gfx_current_window_dimensions.aspect_ratio;
rsp.aspect_scale = rsp.aspect_mode ? gfx_current_native_aspect : gfx_current_window_dimensions.aspect_ratio;
if (side == G_ASPECT_LEFT_EXT) {
rsp.aspect_ofs = 1.f - 3.f * gfx_current_dimensions.aspect_ratio / 4.f;
rsp.aspect_ofs = 1.f - gfx_current_dimensions.aspect_ratio / gfx_current_native_aspect;
} else if (side == G_ASPECT_RIGHT_EXT) {
rsp.aspect_ofs = 3.f * gfx_current_dimensions.aspect_ratio / 4.f - 1.f;
rsp.aspect_ofs = gfx_current_dimensions.aspect_ratio / gfx_current_native_aspect - 1.f;
} else {
rsp.aspect_ofs = 0.f;
}
@@ -1685,8 +1686,8 @@ static void gfx_adjust_viewport_or_scissor(XYWidthHeight* area, bool preserve_as
area->y = SCREEN_HEIGHT - area->y;
area->y *= RATIO_Y;
if (preserve_aspect) {
// preserve 4:3
const float ratio = (4.f / 3.f) / gfx_current_dimensions.aspect_ratio;
// preserve native aspect ratio
const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio;
const float midx = gfx_current_dimensions.width * 0.5f;
area->x = midx + (area->x - midx) * ratio;
area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f;
+3 -1
View File
@@ -39,7 +39,8 @@ s32 videoInit(void)
renderingAPI = &gfx_opengl_api;
gfx_current_native_viewport.width = 320;
gfx_current_native_viewport.height = 240;
gfx_current_native_viewport.height = 220;
gfx_current_native_aspect = 320.f / 220.f;
gfx_framebuffers_enabled = (bool)vidFramebuffers;
gfx_msaa_level = vidMSAA;
@@ -110,6 +111,7 @@ void videoUpdateNativeResolution(s32 w, s32 h)
{
gfx_current_native_viewport.width = w;
gfx_current_native_viewport.height = h;
gfx_current_native_aspect = (float)w / (float)h;
}
s32 videoGetNativeWidth(void)