Massively optimise GL_POLYGON/GL_TRIANGLE_FAN

This commit is contained in:
Luke Benstead 2019-03-29 11:23:48 +00:00
parent a88a9029f5
commit e876dcb14f
2 changed files with 9 additions and 25 deletions

View File

@ -528,30 +528,18 @@ static void genTriangleStrip(Vertex* output, GLuint count) {
output[count - 1].flags = PVR_CMD_VERTEX_EOL; output[count - 1].flags = PVR_CMD_VERTEX_EOL;
} }
#define MAX_POLYGON_SIZE 32
static void genTriangleFan(Vertex* output, GLuint count) { static void genTriangleFan(Vertex* output, GLuint count) {
assert(count < MAX_POLYGON_SIZE); assert(count <= 255);
static Vertex buffer[MAX_POLYGON_SIZE];
if(count <= 3){ Vertex* dst = output + (((count - 2) * 3) - 1);
output[2].flags = PVR_CMD_VERTEX_EOL; Vertex* src = output + (count - 1);
return;
}
memcpy(buffer, output, sizeof(Vertex) * count); GLubyte i = count - 2;
while(i--) {
// First 3 vertices are in the right place, just end early *dst = *src--;
output[2].flags = PVR_CMD_VERTEX_EOL; (*dst--).flags = PVR_CMD_VERTEX_EOL;
*dst-- = *src;
GLsizei i = 3, target = 3; *dst-- = *output;
Vertex* first = &output[0];
for(; i < count; ++i) {
output[target++] = *first;
output[target++] = buffer[i - 1];
output[target] = buffer[i];
output[target++].flags = PVR_CMD_VERTEX_EOL;
} }
} }

View File

@ -72,8 +72,6 @@ void do_frame() {
int i; int i;
float col; float col;
for(i = 0; i < polycnt; i++) { for(i = 0; i < polycnt; i++) {
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
x = rand() % 640; x = rand() % 640;
@ -91,8 +89,6 @@ void do_frame() {
glEnd(); glEnd();
} }
glKosSwapBuffers(); glKosSwapBuffers();
} }