From 7c0c15019cf3895d9643273a18d0aa131f7f57da Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 14 Feb 2023 20:55:47 +0100 Subject: [PATCH] Swap texture window only when the texture changes between faces. Saves a bit on performance, though could be even better if we checked for texture window changes instead of texture ID. --- world.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/world.c b/world.c index e84212a..f64db10 100644 --- a/world.c +++ b/world.c @@ -193,12 +193,6 @@ static void world_drawface_textured(const world_t *world, const ps1bsp_face_t *f } } } - - // Texture window commands needs to be placed *after* the draw commands, because the commands are executed in reverse order - DR_TWIN *twin = (DR_TWIN*)mem_prim(sizeof(DR_TWIN)); - setlen(twin, 1); - twin->code[0] = texture->twin; - addPrim(ot, twin); } static void (*world_drawface)(const world_t*, const ps1bsp_face_t*, u_long *ot) = &world_drawface_fast; @@ -215,6 +209,16 @@ static void world_drawFaces(const world_t *world, const ps1bsp_face_t *firstFace break; world_drawface(world, face, curOT); + + // Texture window commands needs to be placed *after* the draw commands, because the commands are executed in reverse order + if (face->nextFace == NULL || face->textureId != face->nextFace->textureId) + { + const ps1bsp_texture_t *texture = &world->textures[face->textureId]; + DR_TWIN *twin = (DR_TWIN*)mem_prim(sizeof(DR_TWIN)); + setlen(twin, 1); + twin->code[0] = texture->twin; + addPrim(curOT, twin); + } } }