diff --git a/n64e1m1.ps1bsp b/n64e1m1.ps1bsp index 46578cc..74aba34 100755 Binary files a/n64e1m1.ps1bsp and b/n64e1m1.ps1bsp differ diff --git a/n64e2m2.ps1bsp b/n64e2m2.ps1bsp index 82e6a56..bb0f8e6 100755 Binary files a/n64e2m2.ps1bsp and b/n64e2m2.ps1bsp differ diff --git a/n64start.ps1bsp b/n64start.ps1bsp index cfebcfb..54e7bfc 100755 Binary files a/n64start.ps1bsp and b/n64start.ps1bsp differ diff --git a/ps1bsp.h b/ps1bsp.h index 0889884..653f3be 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -58,6 +58,7 @@ typedef struct { unsigned short tpage; // Texture page in PS1 VRAM (precalculated when generating the texture atlas) unsigned short nextframe; // If non-zero, the texture is animated and this points to the next texture in the sequence + unsigned int twin; // Texture window for repeating textures } ps1bsp_texture_t; // This matches the SVECTOR data type; we can use the extra padding to store some more data. diff --git a/world.c b/world.c index b08e12d..e84212a 100644 --- a/world.c +++ b/world.c @@ -193,6 +193,12 @@ 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; @@ -205,7 +211,7 @@ static void world_drawFaces(const world_t *world, const ps1bsp_face_t *firstFace for (const ps1bsp_face_t *face = firstFace; face != NULL; face = face->nextFace) { // Early primitive buffer check - if (!mem_checkprim(sizeof(POLY_GT4), face->totalPrimitives)) + if (!mem_checkprim(sizeof(POLY_GT4) + sizeof(DR_TWIN), face->totalPrimitives)) break; world_drawface(world, face, curOT); @@ -482,5 +488,11 @@ void world_draw(const world_t *world) else world_drawface = &world_drawface_lit; + // Make sure we set the texture window back to default after drawing the world + DR_TWIN *twin = (DR_TWIN*)mem_prim(sizeof(DR_TWIN)); + setlen(twin, 1); + twin->code[0] = 0xe2000000; + addPrim(curOT, twin); + world_drawFaces(world, firstFace); }