From 0cd447dbcf2b35fcbb2c0ae490ffbfea400f3334 Mon Sep 17 00:00:00 2001 From: jnmartin84 Date: Sun, 13 Jul 2025 00:16:43 -0400 Subject: [PATCH] don't waste a full byte on mirror/flip setting moved MIRROR bits into bits 2 and 3 of what used to be `uv_clamp` member of TextureObject renamed `uv_clamp` member to `uv_wrap` updated and commented code accessing `uv_wrap` for both clamp and mirror settings --- GL/private.h | 6 ++---- GL/state.c | 6 ++++-- GL/texture.c | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/GL/private.h b/GL/private.h index 5ba1834..bdf9cb7 100644 --- a/GL/private.h +++ b/GL/private.h @@ -138,7 +138,7 @@ typedef struct { GLubyte mipmap_bias; GLubyte env; GLubyte mipmapCount; /* The number of mipmap levels */ - GLubyte uv_clamp; + GLubyte uv_wrap; /* clamp and flip settings for u and v */ //40 /* Mipmap textures have a different * offset for the base level when supplying the data, this @@ -153,9 +153,7 @@ typedef struct { //50 GLenum internalFormat; //54 - GLubyte uv_flip; - // 55 - GLubyte padding[9]; // Pad to 64-bytes + GLubyte padding[10]; // Pad to 64-bytes } __attribute__((aligned(32))) TextureObject; typedef struct { diff --git a/GL/state.c b/GL/state.c index 4d70b38..e667cdc 100644 --- a/GL/state.c +++ b/GL/state.c @@ -390,8 +390,10 @@ void _glUpdatePVRTextureContext(PolyContext *context, GLshort textureUnit) { } context->txr.env = tx1->env; - context->txr.uv_flip = tx1->uv_flip; - context->txr.uv_clamp = tx1->uv_clamp; + // extract mirror setting from bits 2 and 3 of uv_wrap by shifting out the clamp bits and masking + context->txr.uv_flip = (tx1->uv_wrap >> 2) & 3; + // extract clamp setting from bits 0 and 1 of uv_wrap by masking + context->txr.uv_clamp = tx1->uv_wrap & 3; } } diff --git a/GL/texture.c b/GL/texture.c index f6cbc35..fdf1c6e 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -14,12 +14,13 @@ * issues with the allocator */ #define PVR_MEM_BUFFER_SIZE (64 * 1024) +/* Clamp settings go in lower bits of uv_wrap + * Mirror settings go in upper bits */ +#define MIRROR_U (1<<3) +#define MIRROR_V (1<<2) #define CLAMP_U (1<<1) #define CLAMP_V (1<<0) -#define MIRROR_U (1<<1) -#define MIRROR_V (1<<0) - static TextureObject* TEXTURE_UNITS[MAX_GLDC_TEXTURE_UNITS] = {NULL, NULL}; static NamedArray TEXTURE_OBJECTS; GLubyte ACTIVE_TEXTURE = 0; @@ -507,8 +508,7 @@ static void _glInitializeTextureObject(TextureObject* txr, unsigned int id) { txr->index = id; txr->width = txr->height = 0; txr->mipmap = 0; - txr->uv_clamp = 0; - txr->uv_flip = 0; + txr->uv_wrap = 0; txr->env = GPU_TXRENV_MODULATEALPHA; txr->data = NULL; txr->mipmapCount = 0; @@ -1897,15 +1897,15 @@ void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param) { switch(param) { case GL_CLAMP_TO_EDGE: case GL_CLAMP: - active->uv_clamp |= CLAMP_U; + active->uv_wrap |= CLAMP_U; break; case GL_REPEAT: - active->uv_clamp &= ~CLAMP_U; + active->uv_wrap &= ~CLAMP_U; break; case GL_MIRRORED_REPEAT: - active->uv_flip |= MIRROR_U; + active->uv_wrap |= MIRROR_U; break; } @@ -1915,15 +1915,15 @@ void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param) { switch(param) { case GL_CLAMP_TO_EDGE: case GL_CLAMP: - active->uv_clamp |= CLAMP_V; + active->uv_wrap |= CLAMP_V; break; case GL_REPEAT: - active->uv_clamp &= ~CLAMP_V; + active->uv_wrap &= ~CLAMP_V; break; case GL_MIRRORED_REPEAT: - active->uv_flip |= MIRROR_V; + active->uv_wrap |= MIRROR_V; break; }