From 924a19e078b4ea2406eab26f3e50aa2d6fe42856 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 18 Jun 2024 20:40:07 +1000 Subject: [PATCH] Allow window backends to override window scale dimension units, e.g. for PS2 --- src/Gui.c | 7 +-- src/Window.h | 6 +++ src/Window_3DS.c | 11 ++-- src/Window_Android.c | 5 +- src/Window_BeOS.cpp | 6 ++- src/Window_Dreamcast.c | 11 ++-- src/Window_GCWii.c | 11 ++-- src/Window_MacClassic.c | 11 ++-- src/Window_N64.c | 11 ++-- src/Window_NDS.c | 11 ++-- src/Window_PS1.c | 11 ++-- src/Window_PS2.c | 11 ++-- src/Window_PS3.c | 11 ++-- src/Window_PSP.c | 11 ++-- src/Window_PSVita.c | 11 ++-- src/Window_SDL.c | 6 ++- src/Window_SDL3.c | 6 ++- src/Window_Saturn.c | 11 ++-- src/Window_Switch.c | 8 +-- src/Window_Terminal.c | 9 ++-- src/Window_Web.c | 7 ++- src/Window_WiiU.cpp | 11 ++-- src/Window_Win.c | 7 ++- src/Window_X11.c | 6 ++- src/Window_Xbox.c | 11 ++-- src/Window_Xbox360.c | 11 ++-- src/Window_cocoa.m | 6 ++- src/interop_ios.m | 5 +- third_party/gldc/src/aligned_vector.h | 75 ++++++++------------------- third_party/gldc/src/flush.c | 37 +++++-------- third_party/gldc/src/sh4.c | 34 ++++-------- third_party/gldc/src/state.c | 12 ++--- third_party/gldc/src/types.h | 4 +- 33 files changed, 216 insertions(+), 195 deletions(-) diff --git a/src/Gui.c b/src/Gui.c index 670d863eb..b11998037 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -29,8 +29,8 @@ static struct Texture touchBgTex; *----------------------------------------------------------Gui------------------------------------------------------------* *#########################################################################################################################*/ static CC_NOINLINE int GetWindowScale(void) { - float widthScale = Window_Main.Width / 640.0f; - float heightScale = Window_Main.Height / 480.0f; + float widthScale = Window_Main.Width * Window_Main.UIScaleX; + float heightScale = Window_Main.Height * Window_Main.UIScaleY; /* Use larger UI scaling on mobile */ /* TODO move this DPI scaling elsewhere.,. */ @@ -63,7 +63,8 @@ float Gui_GetChatScale(void) { } float Gui_GetCrosshairScale(void) { - return Gui_Scale((Window_Main.Height / 480.0f)) * Gui.RawCrosshairScale; + float heightScale = Window_Main.Height * Window_Main.UIScaleY; + return Gui_Scale(heightScale) * Gui.RawCrosshairScale; } diff --git a/src/Window.h b/src/Window.h index 5c8e0b8fc..b8fa25727 100644 --- a/src/Window.h +++ b/src/Window.h @@ -86,8 +86,14 @@ struct _WindowData { cc_bool Inactive; /* Whether input should be ignored due to soft keyboard being open */ cc_bool SoftKeyboardFocus; + /* Scale factors specifically for some in-game elements (e.g. chat) */ + /* that vary their elements based on the window dimensions */ + float UIScaleX, UIScaleY; }; +#define DEFAULT_UI_SCALE_X (1.0f / 640) +#define DEFAULT_UI_SCALE_Y (1.0f / 480) + /* Data for the game/launcher window */ CC_VAR extern struct _WindowData WindowInfo; /* Named WindowInfo for backwards compatibility */ #define Window_Main WindowInfo diff --git a/src/Window_3DS.c b/src/Window_3DS.c index 48c7296be..96001f9af 100644 --- a/src/Window_3DS.c +++ b/src/Window_3DS.c @@ -41,10 +41,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; - Window_Main.Width = top_width; - Window_Main.Height = top_height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = top_width; + Window_Main.Height = top_height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Input_SetTouchMode(true); diff --git a/src/Window_Android.c b/src/Window_Android.c index 840661e20..cb6e1823d 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -326,7 +326,10 @@ static void RemakeWindowSurface(void) { } static void DoCreateWindow(void) { - Window_Main.Exists = true; + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; + RemakeWindowSurface(); /* always start as fullscreen */ Window_EnterFullscreen(); diff --git a/src/Window_BeOS.cpp b/src/Window_BeOS.cpp index 38ef2d480..d5ea0fe35 100644 --- a/src/Window_BeOS.cpp +++ b/src/Window_BeOS.cpp @@ -349,8 +349,10 @@ static void DoCreateWindow(int width, int height) { BRect frame(x, y, x + width - 1, y + height - 1); win_handle = new CC_BWindow(frame); - Window_Main.Exists = true; - Window_Main.Handle = win_handle; + Window_Main.Exists = true; + Window_Main.Handle = win_handle; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; frame = win_handle->Bounds(); Window_Main.Width = frame.IntegerWidth() + 1; diff --git a/src/Window_Dreamcast.c b/src/Window_Dreamcast.c index 2afb06942..ea49196ad 100644 --- a/src/Window_Dreamcast.c +++ b/src/Window_Dreamcast.c @@ -37,10 +37,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = vid_mode->width; - Window_Main.Height = vid_mode->height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = vid_mode->width; + Window_Main.Height = vid_mode->height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index f03e667d1..c6ce3e658 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -70,10 +70,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = rmode->fbWidth; - Window_Main.Height = rmode->xfbHeight; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = rmode->fbWidth; + Window_Main.Height = rmode->xfbHeight; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_MacClassic.c b/src/Window_MacClassic.c index 2f2057ee2..36ac608f3 100644 --- a/src/Window_MacClassic.c +++ b/src/Window_MacClassic.c @@ -204,10 +204,13 @@ static void DoCreateWindow(int width, int height) { SetPort(win); r = win->portRect; - Window_Main.Width = r.right - r.left; - Window_Main.Height = r.bottom - r.top; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = r.right - r.left; + Window_Main.Height = r.bottom - r.top; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } diff --git a/src/Window_N64.c b/src/Window_N64.c index 2ff2019b4..5d7130996 100644 --- a/src/Window_N64.c +++ b/src/Window_N64.c @@ -28,10 +28,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_NDS.c b/src/Window_NDS.c index 2e6c7fe6b..d3c5167ba 100644 --- a/src/Window_NDS.c +++ b/src/Window_NDS.c @@ -147,10 +147,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Input_SetTouchMode(true); diff --git a/src/Window_PS1.c b/src/Window_PS1.c index e26c63007..f44611b51 100644 --- a/src/Window_PS1.c +++ b/src/Window_PS1.c @@ -36,10 +36,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_PS2.c b/src/Window_PS2.c index 517054cc0..df7edb0f3 100644 --- a/src/Window_PS2.c +++ b/src/Window_PS2.c @@ -44,10 +44,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = 1.0f / Window_Main.Height; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_PS3.c b/src/Window_PS3.c index 46b36ce6d..716c31993 100644 --- a/src/Window_PS3.c +++ b/src/Window_PS3.c @@ -52,10 +52,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = resolution.width; - Window_Main.Height = resolution.height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = resolution.width; + Window_Main.Height = resolution.height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 20; diff --git a/src/Window_PSP.c b/src/Window_PSP.c index bd00374ad..72fe03104 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -35,10 +35,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = SCREEN_WIDTH; - Window_Main.Height = SCREEN_HEIGHT; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = SCREEN_WIDTH; + Window_Main.Height = SCREEN_HEIGHT; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT); diff --git a/src/Window_PSVita.c b/src/Window_PSVita.c index 5840320f9..1f44d98a4 100644 --- a/src/Window_PSVita.c +++ b/src/Window_PSVita.c @@ -42,10 +42,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = DISPLAY_WIDTH; - Window_Main.Height = DISPLAY_HEIGHT; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DISPLAY_WIDTH; + Window_Main.Height = DISPLAY_HEIGHT; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Input_SetTouchMode(true); diff --git a/src/Window_SDL.c b/src/Window_SDL.c index c2c0b759b..c84ddad23 100644 --- a/src/Window_SDL.c +++ b/src/Window_SDL.c @@ -90,8 +90,10 @@ static void DoCreateWindow(int width, int height, int flags) { if (!win_handle) Window_SDLFail("creating window"); RefreshWindowBounds(); - Window_Main.Exists = true; - Window_Main.Handle = win_handle; + Window_Main.Exists = true; + Window_Main.Handle = win_handle; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; ApplyIcon(); /* TODO grab using SDL_SetWindowGrab? seems to be unnecessary on Linux at least */ } diff --git a/src/Window_SDL3.c b/src/Window_SDL3.c index 2bd95c2de..492c689e5 100644 --- a/src/Window_SDL3.c +++ b/src/Window_SDL3.c @@ -73,8 +73,10 @@ static void DoCreateWindow(int width, int height, int flags) { SDL_DestroyProperties(props); RefreshWindowBounds(); - Window_Main.Exists = true; - Window_Main.Handle = win_handle; + Window_Main.Exists = true; + Window_Main.Handle = win_handle; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; ApplyIcon(); /* TODO grab using SDL_SetWindowGrab? seems to be unnecessary on Linux at least */ } diff --git a/src/Window_Saturn.c b/src/Window_Saturn.c index 141ce62da..05aa834ca 100644 --- a/src/Window_Saturn.c +++ b/src/Window_Saturn.c @@ -35,10 +35,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_Switch.c b/src/Window_Switch.c index 485473ec3..b9aea608b 100644 --- a/src/Window_Switch.c +++ b/src/Window_Switch.c @@ -66,9 +66,11 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Focused = true; - Window_Main.Exists = true; - Window_Main.Handle = nwindowGetDefault(); + Window_Main.Focused = true; + Window_Main.Exists = true; + Window_Main.Handle = nwindowGetDefault(); + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Input_SetTouchMode(true); diff --git a/src/Window_Terminal.c b/src/Window_Terminal.c index e643d494f..dac10e44b 100644 --- a/src/Window_Terminal.c +++ b/src/Window_Terminal.c @@ -424,9 +424,12 @@ void Window_Free(void) { } static void DoCreateWindow(int width, int height) { - Window_Main.Exists = true; - Window_Main.Handle = (void*)1; - Window_Main.Focused = true; + Window_Main.Exists = true; + Window_Main.Handle = (void*)1; + Window_Main.Focused = true; + + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } diff --git a/src/Window_Web.c b/src/Window_Web.c index 9001ac4a0..e438b18cc 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -417,8 +417,11 @@ void Window_Free(void) { } extern void interop_InitContainer(void); static void DoCreateWindow(void) { - Window_Main.Exists = true; - Window_Main.Focused = true; + Window_Main.Exists = true; + Window_Main.Focused = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; + HookEvents(); /* Let the webpage decide on initial bounds */ Window_Main.Width = interop_CanvasWidth(); diff --git a/src/Window_WiiU.cpp b/src/Window_WiiU.cpp index 88a30ef62..6fe46945f 100644 --- a/src/Window_WiiU.cpp +++ b/src/Window_WiiU.cpp @@ -89,10 +89,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_Win.c b/src/Window_Win.c index 725a381df..882336379 100644 --- a/src/Window_Win.c +++ b/src/Window_Win.c @@ -394,8 +394,11 @@ static void DoCreateWindow(int width, int height) { win_DC = GetDC(win_handle); if (!win_DC) Logger_Abort2(GetLastError(), "Failed to get device context"); - Window_Main.Exists = true; - Window_Main.Handle = win_handle; + Window_Main.Exists = true; + Window_Main.Handle = win_handle; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; + grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } diff --git a/src/Window_X11.c b/src/Window_X11.c index 8406e2bc4..49d0ff2ab 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -371,8 +371,10 @@ static void DoCreateWindow(int width, int height) { XkbSetDetectableAutoRepeat(win_display, true, &supported); RefreshWindowBounds(width, height); - Window_Main.Exists = true; - Window_Main.Handle = (void*)win_handle; + Window_Main.Exists = true; + Window_Main.Handle = (void*)win_handle; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false); /* So right name appears in e.g. Ubuntu Unity launchbar */ diff --git a/src/Window_Xbox.c b/src/Window_Xbox.c index 18839c873..ed951d72b 100644 --- a/src/Window_Xbox.c +++ b/src/Window_Xbox.c @@ -70,10 +70,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = mode.width; - Window_Main.Height = mode.height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = mode.width; + Window_Main.Height = mode.height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; diff --git a/src/Window_Xbox360.c b/src/Window_Xbox360.c index e6574475c..bf503084c 100644 --- a/src/Window_Xbox360.c +++ b/src/Window_Xbox360.c @@ -33,10 +33,13 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = DisplayInfo.Width; - Window_Main.Height = DisplayInfo.Height; - Window_Main.Focused = true; - Window_Main.Exists = true; + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; diff --git a/src/Window_cocoa.m b/src/Window_cocoa.m index 8ceea0e5b..38d422140 100644 --- a/src/Window_cocoa.m +++ b/src/Window_cocoa.m @@ -378,8 +378,10 @@ static void DoCreateWindow(int width, int height) { AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(HandleQuitMessage), 0, false); - Window_Main.Exists = true; - Window_Main.Handle = winHandle; + Window_Main.Exists = true; + Window_Main.Handle = winHandle; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; // CGAssociateMouseAndMouseCursorPosition implicitly grabs cursor del = [CCWindowDelegate alloc]; diff --git a/src/interop_ios.m b/src/interop_ios.m index 079807898..215ca3600 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -470,7 +470,10 @@ static CGRect DoCreateWindow(void) { win_handle.rootViewController = cc_controller; win_handle.backgroundColor = CalcBackgroundColor(); - Window_Main.Exists = true; + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; + Window_Main.Width = bounds.size.width; Window_Main.Height = bounds.size.height; diff --git a/third_party/gldc/src/aligned_vector.h b/third_party/gldc/src/aligned_vector.h index 7b152dbe0..045ea66a0 100644 --- a/third_party/gldc/src/aligned_vector.h +++ b/third_party/gldc/src/aligned_vector.h @@ -61,12 +61,9 @@ AV_FORCE_INLINE void *AV_MEMCPY4(void *dest, const void *src, size_t len) typedef struct { uint32_t size; uint32_t capacity; -} __attribute__((aligned(32))) AlignedVectorHeader; - -typedef struct { - AlignedVectorHeader hdr; + uint32_t padding[6]; uint8_t* data; -} AlignedVector; +} __attribute__((aligned(32))) AlignedVector; #define ALIGNED_VECTOR_CHUNK_SIZE 256u @@ -76,16 +73,14 @@ typedef struct { AV_FORCE_INLINE void* aligned_vector_at(const AlignedVector* vector, const uint32_t index) { - const AlignedVectorHeader* hdr = &vector->hdr; - assert(index < hdr->size); + assert(index < vector->size); return vector->data + (index * AV_ELEMENT_SIZE); } AV_FORCE_INLINE void* aligned_vector_reserve(AlignedVector* vector, uint32_t element_count) { - AlignedVectorHeader* hdr = &vector->hdr; - uint32_t original_byte_size = (hdr->size * AV_ELEMENT_SIZE); + uint32_t original_byte_size = (vector->size * AV_ELEMENT_SIZE); - if(element_count < hdr->capacity) { + if(element_count < vector->capacity) { return vector->data + original_byte_size; } @@ -101,28 +96,10 @@ AV_FORCE_INLINE void* aligned_vector_reserve(AlignedVector* vector, uint32_t ele AV_MEMCPY4(vector->data, original_data, original_byte_size); free(original_data); - hdr->capacity = element_count; + vector->capacity = element_count; return vector->data + original_byte_size; } -AV_FORCE_INLINE AlignedVectorHeader* aligned_vector_header(const AlignedVector* vector) { - return (AlignedVectorHeader*) &vector->hdr; -} - -AV_FORCE_INLINE uint32_t aligned_vector_size(const AlignedVector* vector) { - const AlignedVectorHeader* hdr = &vector->hdr; - return hdr->size; -} - -AV_FORCE_INLINE uint32_t aligned_vector_capacity(const AlignedVector* vector) { - const AlignedVectorHeader* hdr = &vector->hdr; - return hdr->capacity; -} - -AV_FORCE_INLINE void* aligned_vector_front(const AlignedVector* vector) { - return vector->data; -} - #define av_assert(x) \ do {\ if(!(x)) {\ @@ -135,27 +112,26 @@ AV_FORCE_INLINE void* aligned_vector_front(const AlignedVector* vector) { AV_FORCE_INLINE void* aligned_vector_resize(AlignedVector* vector, const uint32_t element_count) { void* ret = NULL; - AlignedVectorHeader* hdr = &vector->hdr; - uint32_t previous_count = hdr->size; - if(hdr->capacity <= element_count) { + uint32_t previous_count = vector->size; + if(vector->capacity <= element_count) { /* If we didn't have capacity, increase capacity (slow) */ aligned_vector_reserve(vector, element_count); - hdr->size = element_count; + vector->size = element_count; ret = aligned_vector_at(vector, previous_count); - av_assert(hdr->size == element_count); - av_assert(hdr->size <= hdr->capacity); + av_assert(vector->size == element_count); + av_assert(vector->size <= vector->capacity); } else if(previous_count < element_count) { /* So we grew, but had the capacity, just get a pointer to * where we were */ - hdr->size = element_count; - av_assert(hdr->size < hdr->capacity); + vector->size = element_count; + av_assert(vector->size < vector->capacity); ret = aligned_vector_at(vector, previous_count); - } else if(hdr->size != element_count) { - hdr->size = element_count; - av_assert(hdr->size < hdr->capacity); + } else if(vector->size != element_count) { + vector->size = element_count; + av_assert(vector->size < vector->capacity); } return ret; @@ -163,41 +139,36 @@ AV_FORCE_INLINE void* aligned_vector_resize(AlignedVector* vector, const uint32_ AV_FORCE_INLINE void* aligned_vector_push_back(AlignedVector* vector, const void* objs, uint32_t count) { /* Resize enough room */ - AlignedVectorHeader* hdr = &vector->hdr; - assert(count); #ifndef NDEBUG - uint32_t initial_size = hdr->size; + uint32_t initial_size = vector->size; #endif - uint8_t* dest = (uint8_t*) aligned_vector_resize(vector, hdr->size + count); + uint8_t* dest = (uint8_t*) aligned_vector_resize(vector, vector->size + count); assert(dest); /* Copy the objects in */ AV_MEMCPY4(dest, objs, count * AV_ELEMENT_SIZE); - assert(hdr->size == initial_size + count); + assert(vector->size == initial_size + count); return dest; } AV_FORCE_INLINE void* aligned_vector_extend(AlignedVector* vector, const uint32_t additional_count) { - AlignedVectorHeader* hdr = &vector->hdr; - void* ret = aligned_vector_resize(vector, hdr->size + additional_count); + void* ret = aligned_vector_resize(vector, vector->size + additional_count); assert(ret); // Should always return something return ret; } AV_FORCE_INLINE void aligned_vector_clear(AlignedVector* vector){ - AlignedVectorHeader* hdr = &vector->hdr; - hdr->size = 0; + vector->size = 0; } AV_FORCE_INLINE void aligned_vector_init(AlignedVector* vector) { /* Now initialize the header*/ - AlignedVectorHeader* const hdr = &vector->hdr; - hdr->size = 0; - hdr->capacity = 0; + vector->size = 0; + vector->capacity = 0; vector->data = NULL; } diff --git a/third_party/gldc/src/flush.c b/third_party/gldc/src/flush.c index f7328bdbc..47c46b6a0 100644 --- a/third_party/gldc/src/flush.c +++ b/third_party/gldc/src/flush.c @@ -6,18 +6,7 @@ PolyList OP_LIST; PolyList PT_LIST; PolyList TR_LIST; -/** - * FAST_MODE will use invW for all Z coordinates sent to the - * GPU. - * - * This will break orthographic mode so default is FALSE - **/ - -#define FAST_MODE GL_FALSE - void glKosInit() { - TRACE(); - _glInitContext(); _glInitTextures(); @@ -36,31 +25,29 @@ void glKosInit() { void glKosSwapBuffers() { - TRACE(); - + _glApplyScissor(true); + pvr_scene_begin(); - if(aligned_vector_size(&OP_LIST.vector) > 2) { + if(OP_LIST.vector.size > 2) { pvr_list_begin(PVR_LIST_OP_POLY); - SceneListSubmit((Vertex*) aligned_vector_front(&OP_LIST.vector), aligned_vector_size(&OP_LIST.vector)); + SceneListSubmit((Vertex*)OP_LIST.vector.data, OP_LIST.vector.size); pvr_list_finish(); } - if(aligned_vector_size(&PT_LIST.vector) > 2) { + if(PT_LIST.vector.size > 2) { pvr_list_begin(PVR_LIST_PT_POLY); - SceneListSubmit((Vertex*) aligned_vector_front(&PT_LIST.vector), aligned_vector_size(&PT_LIST.vector)); + SceneListSubmit((Vertex*)PT_LIST.vector.data, PT_LIST.vector.size); pvr_list_finish(); } - if(aligned_vector_size(&TR_LIST.vector) > 2) { + if(TR_LIST.vector.size > 2) { pvr_list_begin(PVR_LIST_TR_POLY); - SceneListSubmit((Vertex*) aligned_vector_front(&TR_LIST.vector), aligned_vector_size(&TR_LIST.vector)); + SceneListSubmit((Vertex*)TR_LIST.vector.data, TR_LIST.vector.size); pvr_list_finish(); - } + } pvr_scene_finish(); - aligned_vector_clear(&OP_LIST.vector); - aligned_vector_clear(&PT_LIST.vector); - aligned_vector_clear(&TR_LIST.vector); - - _glApplyScissor(true); + OP_LIST.vector.size = 0; + PT_LIST.vector.size = 0; + TR_LIST.vector.size = 0; } diff --git a/third_party/gldc/src/sh4.c b/third_party/gldc/src/sh4.c index 0dff66f7d..3900be8fe 100644 --- a/third_party/gldc/src/sh4.c +++ b/third_party/gldc/src/sh4.c @@ -14,24 +14,12 @@ GL_FORCE_INLINE float _glFastInvert(float x) { } GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex) { - TRACE(); - const float f = _glFastInvert(vertex->w); /* Convert to NDC and apply viewport */ - vertex->xyz[0] = (vertex->xyz[0] * f * VIEWPORT.hwidth) + VIEWPORT.x_plus_hwidth; - vertex->xyz[1] = (vertex->xyz[1] * f * VIEWPORT.hheight) + VIEWPORT.y_plus_hheight; - - /* Orthographic projections need to use invZ otherwise we lose - the depth information. As w == 1, and clip-space range is -w to +w - we add 1.0 to the Z to bring it into range. We add a little extra to - avoid a divide by zero. - */ - if(vertex->w == 1.0f) { - vertex->xyz[2] = _glFastInvert(1.0001f + vertex->xyz[2]); - } else { - vertex->xyz[2] = f; - } + vertex->x = (vertex->x * f * VIEWPORT.hwidth) + VIEWPORT.x_plus_hwidth; + vertex->y = (vertex->y * f * VIEWPORT.hheight) + VIEWPORT.y_plus_hheight; + vertex->z = f; } @@ -62,17 +50,17 @@ static inline void _glPushHeaderOrVertex(Vertex* v) { } static void _glClipEdge(const Vertex* const v1, const Vertex* const v2, Vertex* vout) { - const float d0 = v1->w + v1->xyz[2]; - const float d1 = v2->w + v2->xyz[2]; - const float t = (fabs(d0) * MATH_fsrra((d1 - d0) * (d1 - d0))) + 0.000001f; + const float d0 = v1->w + v1->z; + const float d1 = v2->w + v2->z; + const float t = (fabsf(d0) * MATH_fsrra((d1 - d0) * (d1 - d0))) + 0.000001f; const float invt = 1.0f - t; - vout->xyz[0] = invt * v1->xyz[0] + t * v2->xyz[0]; - vout->xyz[1] = invt * v1->xyz[1] + t * v2->xyz[1]; - vout->xyz[2] = invt * v1->xyz[2] + t * v2->xyz[2]; + vout->x = invt * v1->x + t * v2->x; + vout->y = invt * v1->y + t * v2->y; + vout->z = invt * v1->z + t * v2->z; - vout->uv[0] = invt * v1->uv[0] + t * v2->uv[0]; - vout->uv[1] = invt * v1->uv[1] + t * v2->uv[1]; + vout->u = invt * v1->u + t * v2->u; + vout->v = invt * v1->v + t * v2->v; vout->w = invt * v1->w + t * v2->w; diff --git a/third_party/gldc/src/state.c b/third_party/gldc/src/state.c index a9b2a72e3..543525940 100644 --- a/third_party/gldc/src/state.c +++ b/third_party/gldc/src/state.c @@ -87,14 +87,10 @@ void glScissor(int x, int y, int width, int height) { */ void _glApplyScissor(int force) { /* Don't do anyting if clipping is disabled */ - if(!SCISSOR_TEST_ENABLED) { - return; - } + if (!SCISSOR_TEST_ENABLED) return; /* Don't apply if we already applied - nothing changed */ - if(scissor_rect.applied && !force) { - return; - } + if (scissor_rect.applied && !force) return; PVRTileClipCommand c; @@ -151,8 +147,8 @@ void apply_poly_header(PolyHeader* dst, PolyList* activePolyList) { int depth_write = DEPTH_MASK_ENABLED ? PVR_DEPTHWRITE_ENABLE : PVR_DEPTHWRITE_DISABLE; int gen_shading = SHADE_MODEL; - int gen_clip_mode = SCISSOR_TEST_ENABLED ? PVR_USERCLIP_INSIDE : PVR_USERCLIP_DISABLE; - int gen_fog_type = FOG_ENABLED ? PVR_FOG_TABLE : PVR_FOG_DISABLE; + int gen_clip_mode = SCISSOR_TEST_ENABLED ? PVR_USERCLIP_INSIDE : PVR_USERCLIP_DISABLE; + int gen_fog_type = FOG_ENABLED ? PVR_FOG_TABLE : PVR_FOG_DISABLE; int gen_alpha = (BLEND_ENABLED || ALPHA_TEST_ENABLED) ? PVR_ALPHA_ENABLE : PVR_ALPHA_DISABLE; int blend_src = PVR_BLEND_SRCALPHA; diff --git a/third_party/gldc/src/types.h b/third_party/gldc/src/types.h index 85df8bad9..429cc6102 100644 --- a/third_party/gldc/src/types.h +++ b/third_party/gldc/src/types.h @@ -5,8 +5,8 @@ typedef struct { /* Same 32 byte layout as pvr_vertex_t */ uint32_t flags; - float xyz[3]; - float uv[2]; + float x, y, z; + float u, v; uint8_t bgra[4]; /* In the pvr_vertex_t structure, this next 4 bytes is oargb