Skip to content

Commit

Permalink
Xbox: Be a little more efficient in draw calls
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 11, 2024
1 parent 0bcc2c0 commit 43a49d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/Graphics_Xbox.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/Platform_Xbox.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
}

Expand Down

0 comments on commit 43a49d4

Please sign in to comment.