twn_gl_15_rendering.c: use display lists to cache common series of calls

This commit is contained in:
veclav talica 2024-10-01 14:58:00 +03:00
parent 91ea5356fc
commit aa5ff1edf1

View File

@ -59,18 +59,17 @@ static Pipeline pipeline_last_used = PIPELINE_NO;
void use_space_pipeline(void) {
static GLuint list = 0;
if (!list) {
list = glGenLists(1);
glNewList(list, GL_COMPILE); {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
if (GLAD_GL_ARB_depth_clamp)
glDisable(GL_DEPTH_CLAMP);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(&camera_projection_matrix.row[0].x);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(&camera_look_at_matrix.row[0].x);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
@ -84,6 +83,16 @@ void use_space_pipeline(void) {
/* solid white, no modulation */
glColor4ub(255, 255, 255, 255);
} glEndList();
}
glCallList(list);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(&camera_projection_matrix.row[0].x);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(&camera_look_at_matrix.row[0].x);
pipeline_last_used = PIPELINE_SPACE;
}
@ -95,6 +104,11 @@ void use_2d_pipeline(void) {
glFlush();
}
static GLuint list = 0;
if (!list) {
list = glGenLists(1);
glNewList(list, GL_COMPILE); {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glShadeModel(GL_FLAT);
@ -102,6 +116,15 @@ void use_2d_pipeline(void) {
if (GLAD_GL_ARB_depth_clamp)
glDisable(GL_DEPTH_CLAMP);
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
} glEndList();
}
glCallList(list);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, (double)ctx.base_render_width, (double)ctx.base_render_height, 0, -1, 1);
@ -109,11 +132,6 @@ void use_2d_pipeline(void) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
pipeline_last_used = PIPELINE_2D;
}
@ -183,23 +201,40 @@ void render_circle(const CirclePrimitive *circle) {
void use_texture_mode(TextureMode mode) {
if (mode == TEXTURE_MODE_GHOSTLY) {
GLuint lists = 0;
if (!lists) {
lists = glGenLists(3);
glNewList(lists + 0, GL_COMPILE); {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthFunc(GL_ALWAYS);
glDepthMask(GL_FALSE);
glDisable(GL_ALPHA_TEST);
} else if (mode == TEXTURE_MODE_SEETHROUGH) {
} glEndList();
glNewList(lists + 1, GL_COMPILE); {
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0f);
} else {
} glEndList();
glNewList(lists + 2, GL_COMPILE); {
glDisable(GL_BLEND);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glDisable(GL_ALPHA_TEST);
} glEndList();
}
if (mode == TEXTURE_MODE_GHOSTLY) {
glCallList(lists + 0);
} else if (mode == TEXTURE_MODE_SEETHROUGH) {
glCallList(lists + 1);
} else {
glCallList(lists + 2);
}
}
@ -517,10 +552,6 @@ void finally_render_skybox(char *paths) {
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
/* note: assumes that space pipeline is applied already */
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_TRUE);
if (loading_needed) {
/* load all the sides */
char *expanded = expand_asterisk(paths, "up");
@ -548,8 +579,17 @@ void finally_render_skybox(char *paths) {
SDL_free(expanded);
}
/* TODO: use lists at the very least */
/* TODO: figure out which coordinates to use to not have issues with far z */
/* TODO: recalculate the list if far z requirement changes */
static GLuint list = 0;
if (!list) {
list = glGenLists(1);
glNewList(list, GL_COMPILE); {
/* note: assumes that space pipeline is applied already */
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_TRUE);
glBegin(GL_QUADS); {
/* up */
@ -614,4 +654,9 @@ void finally_render_skybox(char *paths) {
} glEnd();
glDisable(GL_TEXTURE_CUBE_MAP);
} glEndList();
}
glCallList(list);
}