From 0b6108a35d28ff1f4bf8c240f19ed3196d4728be Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Mon, 13 May 2024 22:29:34 +0300 Subject: [PATCH] gx: add GX_GetTexObjLOD() 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 56c6c8157..40cc465ae 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 86c79ce25..be075a8af 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)