From 2cb532db27fa2a866371037081b82d2745835fdc Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Mon, 13 May 2024 23:04:55 +0300 Subject: [PATCH] gx: add GX_GetTexObjLOD() (#173) These values are written into the texture object by GX_InitTexObjLOD(), GX_InitTexObjMinLOD() and GX_InitTexObjMaxLOD() but there was no getter for them. --- gc/ogc/gx.h | 15 +++++++++++++++ libogc/gx.c | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/gc/ogc/gx.h b/gc/ogc/gx.h index 56c6c815..40cc465a 100644 --- a/gc/ogc/gx.h +++ b/gc/ogc/gx.h @@ -4095,6 +4095,21 @@ u16 GX_GetTexObjHeight(const GXTexObj* obj); */ u16 GX_GetTexObjWidth(const GXTexObj* obj); +/*! + * \fn void GX_GetTexObjLOD(const GXTexObj* obj, f32 *minlod, f32 *maxlod) + * \brief Returns the min and max LOD values for the texture object \a obj. + * + * \note Use GX_InitTexObjLOD(), GX_InitTexObjMinLOD() or GX_InitTexObjMaxLOD() + * to initialize the texture minimum and maximum LOD. + * + * \param[in] obj ptr to a texture object + * \param[out] minlod minimum LOD value from 0.0 - 10.0 inclusive + * \param[out] maxlod maximum LOD value from 0.0 - 10.0 inclusive + * + * \return none + */ +void GX_GetTexObjLOD(const GXTexObj* obj, f32 *minlod, f32 *maxlod); + /*! * \fn void GX_GetTexObjAll(const GXTexObj* obj, void** image_ptr, u16* width, u16* height, u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap); * \brief Returns the parameters described by a texture object. Texture objects are used to describe all the parameters associated with a texture, including size, format, wrap modes, filter modes, etc. Texture objects are initialized using either GX_InitTexObj() or, for color index format textures, GX_InitTexObjCI(). diff --git a/libogc/gx.c b/libogc/gx.c index 86c79ce2..be075a8a 100644 --- a/libogc/gx.c +++ b/libogc/gx.c @@ -3027,6 +3027,12 @@ u16 GX_GetTexObjWidth(const GXTexObj *obj) return (((const struct __gx_texobj*)obj)->tex_size & 0x3ff) + 1; } +void GX_GetTexObjLOD(const GXTexObj *obj, f32 *minlod, f32 *maxlod) +{ + const struct __gx_texobj *ptr = (const struct __gx_texobj*)obj; + *minlod = (ptr->tex_lod & 0xff) / 16.0f; + *maxlod = _SHIFTR(ptr->tex_lod, 8, 8) / 16.0f; +} void GX_GetTexObjAll(const GXTexObj *obj, void** image_ptr, u16* width, u16* height, u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap)