diff --git a/port/fast3d/gfx_api.h b/port/fast3d/gfx_api.h index 17a1a1310..1f53f0ed4 100644 --- a/port/fast3d/gfx_api.h +++ b/port/fast3d/gfx_api.h @@ -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, diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index 5b2dcc0e3..a5c997a31 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -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; diff --git a/port/src/video.c b/port/src/video.c index afe485f5b..075546218 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -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)