From 43a49d48ccecf316fbf608240a45fe73d29dc270 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 10 May 2024 22:54:36 +1000 Subject: [PATCH] Xbox: Be a little more efficient in draw calls --- src/Graphics_Xbox.c | 19 +++++++++++++++---- src/Platform_Xbox.c | 10 ++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index 6b360e577..04d784f5e 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -476,6 +476,18 @@ void Gfx_SetFog(cc_bool enabled) { } void Gfx_SetFogCol(PackedCol color) { + int R = PackedCol_R(color); + int G = PackedCol_G(color); + int B = PackedCol_B(color); + int A = PackedCol_A(color); + + uint32_t* p = pb_begin(); + p = pb_push1(p, NV097_SET_FOG_COLOR, + MASK(NV097_SET_FOG_COLOR_RED, R) | + MASK(NV097_SET_FOG_COLOR_GREEN, G) | + MASK(NV097_SET_FOG_COLOR_BLUE, B) | + MASK(NV097_SET_FOG_COLOR_ALPHA, A)); + pb_end(p); } void Gfx_SetFogDensity(float value) { @@ -655,16 +667,16 @@ static void DrawArrays(int mode, int start, int count) { uint32_t *p = pb_begin(); p = pb_push1(p, NV097_SET_BEGIN_END, mode); - // NV097_DRAW_ARRAYS_COUNT is an 8 bit mask, so must be < 256 + // NV097_DRAW_ARRAYS_COUNT is an 8 bit mask, so must be <= 256 while (count > 0) { - int batch_count = min(count, 64); // TODO increase? + int batch_count = min(count, 256); p = pb_push1(p, 0x40000000 | NV097_DRAW_ARRAYS, MASK(NV097_DRAW_ARRAYS_COUNT, (batch_count-1)) | MASK(NV097_DRAW_ARRAYS_START_INDEX, start)); - start += batch_count; + start += batch_count; count -= batch_count; } @@ -676,7 +688,6 @@ void Gfx_DrawVb_Lines(int verticesCount) { DrawArrays(NV097_SET_BEGIN_END_OP_LINES, 0, verticesCount); } -#define MAX_BATCH 120 static void DrawIndexedVertices(int verticesCount, int startVertex) { // TODO switch to indexed rendering DrawArrays(NV097_SET_BEGIN_END_OP_QUADS, startVertex, verticesCount); diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index cea3e781e..5c3bbf3f1 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -111,7 +111,7 @@ cc_result Directory_Create(const cc_string* path) { } int File_Exists(const cc_string* path) { - if (!hdd_mounted) return ERR_NOT_SUPPORTED; + if (!hdd_mounted) return 0; char str[NATIVE_STR_LEN]; DWORD attribs; @@ -203,7 +203,8 @@ cc_result File_Write(cc_file file, const void* data, cc_uint32 count, cc_uint32* } cc_result File_Close(cc_file file) { - return CloseHandle(file) ? 0 : GetLastError(); + NTSTATUS status = NtClose(file); + return NT_SUCCESS(status) ? 0 : status; } cc_result File_Seek(cc_file file, int offset, int seekType) { @@ -243,8 +244,9 @@ void Thread_Run(void** handle, Thread_StartFunc func, int stackSize, const char* } void Thread_Detach(void* handle) { - if (!CloseHandle((HANDLE)handle)) { - Logger_Abort2(GetLastError(), "Freeing thread handle"); + NTSTATUS status = NtClose((HANDLE)handle); + if (!NT_SUCCESS(status)) { + Logger_Abort2(status, "Freeing thread handle"); } }