mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Allow window backends to override window scale dimension units, e.g. for PS2
This commit is contained in:
parent
f5bed6ff69
commit
924a19e078
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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); }
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
}
|
||||
|
@ -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 */
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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); }
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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); }
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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;
|
||||
|
||||
|
75
third_party/gldc/src/aligned_vector.h
vendored
75
third_party/gldc/src/aligned_vector.h
vendored
@ -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;
|
||||
}
|
||||
|
||||
|
37
third_party/gldc/src/flush.c
vendored
37
third_party/gldc/src/flush.c
vendored
@ -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;
|
||||
}
|
||||
|
34
third_party/gldc/src/sh4.c
vendored
34
third_party/gldc/src/sh4.c
vendored
@ -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;
|
||||
|
||||
|
12
third_party/gldc/src/state.c
vendored
12
third_party/gldc/src/state.c
vendored
@ -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;
|
||||
|
4
third_party/gldc/src/types.h
vendored
4
third_party/gldc/src/types.h
vendored
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user