Dreamcast: Minor code tidyup

This commit is contained in:
UnknownShadow200 2024-07-08 18:29:30 +10:00
parent 843173a118
commit 55c4b51a39
4 changed files with 31 additions and 39 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -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) */

View file

@ -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;
}
}