Skip to content

Commit

Permalink
gx: add GX_GetTexObjLOD() (#173)
Browse files Browse the repository at this point in the history
These values are written into the texture object by GX_InitTexObjLOD(),
GX_InitTexObjMinLOD() and GX_InitTexObjMaxLOD() but there was no getter
for them.
  • Loading branch information
mardy authored May 13, 2024
1 parent 0ea7278 commit 2cb532d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gc/ogc/gx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
6 changes: 6 additions & 0 deletions libogc/gx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2cb532d

Please sign in to comment.