From d7e3d6c06470cfc075a738fdf1efd4b869e41ce2 Mon Sep 17 00:00:00 2001 From: briaguya Date: Mon, 23 May 2022 17:03:50 -0400 Subject: [PATCH] use ini window resolution --- libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp | 2 +- libultraship/libultraship/Lib/Fast3D/gfx_glx.cpp | 2 +- libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp | 11 +++++------ libultraship/libultraship/Lib/Fast3D/gfx_pc.h | 5 ++++- libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp | 5 ++++- .../Lib/Fast3D/gfx_window_manager_api.h | 2 +- libultraship/libultraship/Window.cpp | 13 ++++++++----- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp index 49abe0b28bb..2118a1c5be3 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp @@ -264,7 +264,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par return 0; } -void gfx_dxgi_init(const char *game_name, bool start_in_fullscreen) { +void gfx_dxgi_init(const char *game_name, bool start_in_fullscreen, uint32_t width, uint32_t height) { LARGE_INTEGER qpc_init, qpc_freq; QueryPerformanceCounter(&qpc_init); QueryPerformanceFrequency(&qpc_freq); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_glx.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_glx.cpp index d450558b2e6..43dae33ffec 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_glx.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_glx.cpp @@ -298,7 +298,7 @@ static bool gfx_glx_check_extension(const char *extensions, const char *extensio return false; } -static void gfx_glx_init(const char *game_name, bool start_in_fullscreen) { +static void gfx_glx_init(const char *game_name, bool start_in_fullscreen, u_int32_t width, uint32_t height) { // On NVIDIA proprietary driver, make the driver queue up to two frames on glXSwapBuffers, // which means that glXSwapBuffers should be non-blocking, // if we are sure to wait at least one vsync interval between calls. diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index 98bab7f7876..13002993f9f 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -60,8 +60,7 @@ using namespace std; #define SCALE_3_8(VAL_) ((VAL_) * 0x24) #define SCALE_8_3(VAL_) ((VAL_) / 0x24) -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 240 +// SCREEN_WIDTH and SCREEN_HEIGHT are defined in the headerfile #define HALF_SCREEN_WIDTH (SCREEN_WIDTH / 2) #define HALF_SCREEN_HEIGHT (SCREEN_HEIGHT / 2) @@ -2662,15 +2661,15 @@ void gfx_get_dimensions(uint32_t *width, uint32_t *height) { gfx_wapi->get_dimensions(width, height); } -void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, const char *game_name, bool start_in_fullscreen) { +void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, const char *game_name, bool start_in_fullscreen, uint32_t width, uint32_t height) { gfx_wapi = wapi; gfx_rapi = rapi; gfx_wapi->init(game_name, start_in_fullscreen); gfx_rapi->init(); - gfx_rapi->update_framebuffer_parameters(0, SCREEN_WIDTH, SCREEN_HEIGHT, 1, false, true, true, true); + gfx_rapi->update_framebuffer_parameters(0, width, height, 1, false, true, true, true); gfx_current_dimensions.internal_mul = 1; - gfx_current_dimensions.width = SCREEN_WIDTH; - gfx_current_dimensions.height = SCREEN_HEIGHT; + gfx_current_dimensions.width = width; + gfx_current_dimensions.height = height; game_framebuffer = gfx_rapi->create_framebuffer(); game_framebuffer_msaa_resolved = gfx_rapi->create_framebuffer(); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.h b/libultraship/libultraship/Lib/Fast3D/gfx_pc.h index 2ecb68898e9..597b853c48a 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.h +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.h @@ -8,6 +8,9 @@ #include "U64/PR/ultra64/types.h" +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + struct GfxRenderingAPI; struct GfxWindowManagerAPI; @@ -62,7 +65,7 @@ extern uint32_t gfx_msaa_level; } -void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen); +void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen, uint32_t width = SCREEN_WIDTH, uint32_t height = SCREEN_HEIGHT); struct GfxRenderingAPI* gfx_get_current_rendering_api(void); void gfx_start_frame(void); void gfx_run(Gfx* commands, const std::unordered_map& mtx_replacements); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index e80097c814a..5fa61a40661 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -129,7 +129,7 @@ static int frameDivisor = 1; #define FRAME_INTERVAL_US_DENOMINATOR 3 #define FRAME_INTERVAL_US_NUMERATOR (FRAME_INTERVAL_US_NUMERATOR_ * frameDivisor) -static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) { +static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen, uint32_t width, uint32_t height) { SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); @@ -145,6 +145,9 @@ static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) { char title[512]; int len = sprintf(title, "%s (%s)", game_name, GFX_API_NAME); + window_width = width; + window_height = height; + wnd = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h b/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h index 5d7442390da..a2f7cb44041 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h +++ b/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h @@ -5,7 +5,7 @@ #include struct GfxWindowManagerAPI { - void (*init)(const char *game_name, bool start_in_fullscreen); + void (*init)(const char *game_name, bool start_in_fullscreen, uint32_t width, uint32_t height); void (*set_keyboard_callbacks)(bool (*on_key_down)(int scancode), bool (*on_key_up)(int scancode), void (*on_all_keys_up)(void)); void (*set_fullscreen_changed_callback)(void (*on_fullscreen_changed)(bool is_now_fullscreen)); void (*set_fullscreen)(bool enable); diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 5c2cf3caed1..a25cb1f54cc 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -250,15 +250,18 @@ namespace Ship { SetAudioPlayer(); bIsFullscreen = Ship::stob(Conf["WINDOW"]["FULLSCREEN"]); - dwWidth = Ship::stoi(Conf["WINDOW"]["WINDOW WIDTH"], 320); - dwHeight = Ship::stoi(Conf["WINDOW"]["WINDOW HEIGHT"], 240); - dwWidth = Ship::stoi(Conf["WINDOW"]["FULLSCREEN WIDTH"], 1920); - dwHeight = Ship::stoi(Conf["WINDOW"]["FULLSCREEN HEIGHT"], 1080); + if (bIsFullscreen) { + dwWidth = Ship::stoi(Conf["WINDOW"]["FULLSCREEN WIDTH"], 1920); + dwHeight = Ship::stoi(Conf["WINDOW"]["FULLSCREEN HEIGHT"], 1080); + } else { + dwWidth = Ship::stoi(Conf["WINDOW"]["WINDOW WIDTH"], 640); + dwHeight = Ship::stoi(Conf["WINDOW"]["WINDOW HEIGHT"], 480); + } dwMenubar = Ship::stoi(Conf["WINDOW"]["menubar"], 0); const std::string& gfx_backend = Conf["WINDOW"]["GFX BACKEND"]; SetWindowManager(&WmApi, &RenderingApi, gfx_backend); - gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen); + gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen, dwWidth, dwHeight); WmApi->set_fullscreen_changed_callback(Window::OnFullscreenChanged); WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp); }