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;
}
#define MAX_POLYGON_SIZE 32
static void genTriangleFan(Vertex* output, GLuint count) {
assert(count < MAX_POLYGON_SIZE);
static Vertex buffer[MAX_POLYGON_SIZE];
assert(count <= 255);
if(count <= 3){
output[2].flags = PVR_CMD_VERTEX_EOL;
return;
}
Vertex* dst = output + (((count - 2) * 3) - 1);
Vertex* src = output + (count - 1);
memcpy(buffer, output, sizeof(Vertex) * count);
// First 3 vertices are in the right place, just end early
output[2].flags = PVR_CMD_VERTEX_EOL;
GLsizei i = 3, target = 3;
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;
GLubyte i = count - 2;
while(i--) {
*dst = *src--;
(*dst--).flags = PVR_CMD_VERTEX_EOL;
*dst-- = *src;
*dst-- = *output;
}
}

View File

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