From d9539da841faa1ecb8e394910cef1c5f5c69044f Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Wed, 13 Mar 2019 15:35:42 +0000 Subject: [PATCH] Optimisations --- GL/draw.c | 25 +++++++++++++------------ GL/immediate.c | 1 + GL/profiler.c | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/GL/draw.c b/GL/draw.c index 844149b..7045557 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -501,13 +501,12 @@ static inline void transformNormalToEyeSpace(GLfloat* normal) { mat_trans_normal3(normal[0], normal[1], normal[2]); } -static inline void swapVertex(ClipVertex* v1, ClipVertex* v2) { - static ClipVertex tmp; - - tmp = *v1; - *v1 = *v2; - *v2 = tmp; -} +#define swapVertex(a, b) \ +do { \ + ClipVertex temp = *a; \ + *a = *b; \ + *b = temp; \ +} while(0) static inline FloatParseFunc _calcVertexParseFunc() { switch(VERTEX_POINTER.type) { @@ -850,15 +849,17 @@ static inline void genArraysTriangles(ClipVertex* output, GLuint count) { } } -static void genArraysQuads(ClipVertex* output, GLuint count) { - GLsizei i = 3; +static inline void genArraysQuads(ClipVertex* output, GLuint count) { + ClipVertex* previous; + ClipVertex* this = output + 3; - for(; i < count; i += 4) { - ClipVertex* this = output + i; - ClipVertex* previous = output + (i - 1); + const ClipVertex* end = output + count; + while(this < end) { + previous = this - 1; swapVertex(previous, this); this->flags = PVR_CMD_VERTEX_EOL; + this += 4; } } diff --git a/GL/immediate.c b/GL/immediate.c index 0c7e46c..b45e79f 100644 --- a/GL/immediate.c +++ b/GL/immediate.c @@ -92,6 +92,7 @@ void APIENTRY glColor3fv(const GLfloat* v) { } void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) { + aligned_vector_reserve(&VERTICES, VERTICES.size + 3); aligned_vector_push_back(&VERTICES, &x, 1); aligned_vector_push_back(&VERTICES, &y, 1); aligned_vector_push_back(&VERTICES, &z, 1); diff --git a/GL/profiler.c b/GL/profiler.c index bc51cf0..968bc9f 100644 --- a/GL/profiler.c +++ b/GL/profiler.c @@ -138,6 +138,6 @@ void profiler_print_stats() { float ms = ((float) result->total_time_us) / 1000.0f; float avg = ms / (float) result->total_calls; - fprintf(stderr, "%-60s%-20f%-20f%u\n", result->name, avg, ms, result->total_calls); + fprintf(stderr, "%-60s%-20f%-20f%" PRIu64 "\n", result->name, (double)avg, (double)ms, result->total_calls); } }