Initialize submission target on boot to save runtime cost

This commit is contained in:
Luke Benstead 2022-11-04 19:23:50 +00:00
parent 4d8c507706
commit 8ca70a2920
3 changed files with 29 additions and 21 deletions

View File

@ -1049,7 +1049,28 @@ GL_FORCE_INLINE void push(PolyHeader* header, GLboolean multiTextureHeader, Poly
#define DEBUG_CLIPPING 0
static AlignedVector VERTEX_EXTRAS;
static SubmissionTarget SUBMISSION_TARGET;
void _glInitSubmissionTarget() {
SubmissionTarget* target = &SUBMISSION_TARGET;
target->extras = NULL;
target->count = 0;
target->output = NULL;
target->header_offset = target->start_offset = 0;
aligned_vector_init(&VERTEX_EXTRAS, sizeof(VertexExtra));
target->extras = &VERTEX_EXTRAS;
}
GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type, const GLvoid* indices) {
SubmissionTarget* const target = &SUBMISSION_TARGET;
AlignedVector* const extras = target->extras;
TRACE();
/* Do nothing if vertices aren't enabled */
@ -1062,26 +1083,6 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
return;
}
if(mode == GL_LINE_STRIP || mode == GL_LINES) {
fprintf(stderr, "Line drawing is currently unsupported\n");
return;
}
static SubmissionTarget* target = NULL;
static AlignedVector extras;
/* Initialization of the target and extras */
if(!target) {
target = (SubmissionTarget*) malloc(sizeof(SubmissionTarget));
target->extras = NULL;
target->count = 0;
target->output = NULL;
target->header_offset = target->start_offset = 0;
aligned_vector_init(&extras, sizeof(VertexExtra));
target->extras = &extras;
}
/* Polygons are treated as triangle fans, the only time this would be a
* problem is if we supported glPolygonMode(..., GL_LINE) but we don't.
* We optimise the triangle and quad cases.
@ -1096,6 +1097,11 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
}
}
if(mode == GL_LINE_STRIP || mode == GL_LINES) {
fprintf(stderr, "Line drawing is currently unsupported\n");
return;
}
// We don't handle this any further, so just make sure we never pass it down */
gl_assert(mode != GL_POLYGON);
@ -1107,7 +1113,7 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
gl_assert(target->count);
/* Make sure we have enough room for all the "extra" data */
aligned_vector_resize(&extras, target->count);
aligned_vector_resize(extras, target->count);
/* Make room for the vertices and header */
aligned_vector_extend(&target->output->vector, target->count + 1);

View File

@ -58,6 +58,7 @@ void APIENTRY glKosInitEx(GLdcConfig* config) {
AUTOSORT_ENABLED = config->autosort_enabled;
_glInitSubmissionTarget();
_glInitMatrices();
_glInitAttributePointers();
_glInitContext();

View File

@ -290,6 +290,7 @@ void _glInitLights();
void _glInitImmediateMode(GLuint initial_size);
void _glInitMatrices();
void _glInitFramebuffers();
void _glInitSubmissionTarget();
void _glMatrixLoadNormal();
void _glMatrixLoadModelView();