From 55c4b51a396f648c217cd837f393707aa6ac8e9e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 8 Jul 2024 18:29:30 +1000 Subject: [PATCH] Dreamcast: Minor code tidyup --- src/Graphics_Dreamcast.c | 13 ++++++------ third_party/gldc/src/aligned_vector.h | 3 ++- third_party/gldc/src/gldc.h | 24 +++++++-------------- third_party/gldc/src/state.c | 30 +++++++++++++-------------- 4 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index 217bd1399..23e8cd133 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -530,16 +530,15 @@ static Vertex* ReserveOutput(AlignedVector* vec, uint32_t elems) { void DrawQuads(int count, void* src) { if (!count) return; - PolyList* output = _glActivePolyList(); - AlignedVector* vec = &output->vector; + AlignedVector* vec = _glActivePolyList(); uint32_t header_required = (vec->size == 0) || STATE_DIRTY; // Reserve room for the vertices and header - Vertex* beg = ReserveOutput(&output->vector, vec->size + (header_required) + count); + Vertex* beg = ReserveOutput(vec, vec->size + (header_required) + count); if (!beg) return; if (header_required) { - apply_poly_header((pvr_poly_hdr_t*)beg, output->list_type); + apply_poly_header((pvr_poly_hdr_t*)beg, vec->list_type); STATE_DIRTY = false; beg++; vec->size += 1; @@ -638,9 +637,9 @@ void Gfx_OnWindowResize(void) { } static void PushCommand(void* cmd) { - aligned_vector_push_back(&OP_LIST.vector, cmd, 1); - aligned_vector_push_back(&PT_LIST.vector, cmd, 1); - aligned_vector_push_back(&TR_LIST.vector, cmd, 1); + aligned_vector_push_back(&OP_LIST, cmd, 1); + aligned_vector_push_back(&PT_LIST, cmd, 1); + aligned_vector_push_back(&TR_LIST, cmd, 1); } void Gfx_SetViewport(int x, int y, int w, int h) { diff --git a/third_party/gldc/src/aligned_vector.h b/third_party/gldc/src/aligned_vector.h index b95209638..3a3710a88 100644 --- a/third_party/gldc/src/aligned_vector.h +++ b/third_party/gldc/src/aligned_vector.h @@ -13,7 +13,8 @@ typedef struct { uint32_t size; uint32_t capacity; - uint32_t padding[6]; + uint32_t list_type; + uint32_t padding[5]; uint8_t* data; } __attribute__((aligned(32))) AlignedVector; diff --git a/third_party/gldc/src/gldc.h b/third_party/gldc/src/gldc.h index 35c69e071..6d462c18e 100644 --- a/third_party/gldc/src/gldc.h +++ b/third_party/gldc/src/gldc.h @@ -44,11 +44,6 @@ typedef struct { #define GL_FORCE_INLINE static __attribute__((always_inline)) inline -typedef struct { - unsigned int list_type; - AlignedVector vector; -} PolyList; - typedef struct { float hwidth; /* width * 0.5f */ float hheight; /* height * 0.5f */ @@ -102,18 +97,15 @@ extern GLenum SHADE_MODEL; extern GLboolean AUTOSORT_ENABLED; -extern PolyList OP_LIST; -extern PolyList PT_LIST; -extern PolyList TR_LIST; +extern AlignedVector OP_LIST; +extern AlignedVector PT_LIST; +extern AlignedVector TR_LIST; -GL_FORCE_INLINE PolyList* _glActivePolyList() { - if(BLEND_ENABLED) { - return &TR_LIST; - } else if(ALPHA_TEST_ENABLED) { - return &PT_LIST; - } else { - return &OP_LIST; - } +GL_FORCE_INLINE AlignedVector* _glActivePolyList() { + if (BLEND_ENABLED) return &TR_LIST; + if (ALPHA_TEST_ENABLED) return &PT_LIST; + + return &OP_LIST; } /* Memory allocation extension (GL_KOS_texture_memory_management) */ diff --git a/third_party/gldc/src/state.c b/third_party/gldc/src/state.c index 05f3674d9..c9068a63f 100644 --- a/third_party/gldc/src/state.c +++ b/third_party/gldc/src/state.c @@ -23,9 +23,9 @@ GLboolean BLEND_ENABLED; GLboolean TEXTURES_ENABLED; GLboolean AUTOSORT_ENABLED; -PolyList OP_LIST; -PolyList PT_LIST; -PolyList TR_LIST; +AlignedVector OP_LIST; +AlignedVector PT_LIST; +AlignedVector TR_LIST; Viewport VIEWPORTS[3]; void glKosInit() { @@ -35,31 +35,31 @@ void glKosInit() { PT_LIST.list_type = PVR_LIST_PT_POLY; TR_LIST.list_type = PVR_LIST_TR_POLY; - aligned_vector_reserve(&OP_LIST.vector, 1024 * 3); - aligned_vector_reserve(&PT_LIST.vector, 512 * 3); - aligned_vector_reserve(&TR_LIST.vector, 1024 * 3); + aligned_vector_reserve(&OP_LIST, 1024 * 3); + aligned_vector_reserve(&PT_LIST, 512 * 3); + aligned_vector_reserve(&TR_LIST, 1024 * 3); } void glKosSwapBuffers() { - if (OP_LIST.vector.size > 2) { + if (OP_LIST.size > 2) { pvr_list_begin(PVR_LIST_OP_POLY); - SceneListSubmit((Vertex*)OP_LIST.vector.data, OP_LIST.vector.size, 0); + SceneListSubmit((Vertex*)OP_LIST.data, OP_LIST.size, 0); pvr_list_finish(); - OP_LIST.vector.size = 0; + OP_LIST.size = 0; } - if (PT_LIST.vector.size > 2) { + if (PT_LIST.size > 2) { pvr_list_begin(PVR_LIST_PT_POLY); - SceneListSubmit((Vertex*)PT_LIST.vector.data, PT_LIST.vector.size, 1); + SceneListSubmit((Vertex*)PT_LIST.data, PT_LIST.size, 1); pvr_list_finish(); - PT_LIST.vector.size = 0; + PT_LIST.size = 0; } - if (TR_LIST.vector.size > 2) { + if (TR_LIST.size > 2) { pvr_list_begin(PVR_LIST_TR_POLY); - SceneListSubmit((Vertex*)TR_LIST.vector.data, TR_LIST.vector.size, 2); + SceneListSubmit((Vertex*)TR_LIST.data, TR_LIST.size, 2); pvr_list_finish(); - TR_LIST.vector.size = 0; + TR_LIST.size = 0; } }