Skip to content

Commit

Permalink
gx: add GX_GetTexObjFilterMode()
Browse files Browse the repository at this point in the history
Without this function there is no way to retrieve the texture
minification and magnification filters.
  • Loading branch information
mardy committed Jun 15, 2024
1 parent 30d9592 commit dc18844
Show file tree
Hide file tree
Showing 2 changed files with 31 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 @@ -4110,6 +4110,21 @@ u16 GX_GetTexObjWidth(const GXTexObj* obj);
*/
void GX_GetTexObjLOD(const GXTexObj* obj, f32 *minlod, f32 *maxlod);

/*!
* \fn void GX_GetTexObjFilterMode(const GXTexObj* obj, u8 *minfilt, u8 *magfilt)
* \brief Returns the filter mode for the texture object \a obj.
*
* \note Use GX_InitTexObjLOD() or GX_InitTexObjFilterMode() to initialize the
* texture filter mode.
*
* \param[in] obj ptr to a texture object
* \param[out] minfilt minification filter mode; will be one of \ref texfilter
* \param[out] maxfilt magnification filter mode; will be \a GX_NEAR or \a GX_LINEAR
*
* \return none
*/
void GX_GetTexObjFilterMode(const GXTexObj *obj, u8 *minfilt, u8 *magfilt);

/*!
* \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
16 changes: 16 additions & 0 deletions libogc/gx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,22 @@ void GX_GetTexObjLOD(const GXTexObj *obj, f32 *minlod, f32 *maxlod)
*maxlod = _SHIFTR(ptr->tex_lod, 8, 8) / 16.0f;
}

void GX_GetTexObjFilterMode(const GXTexObj *obj, u8 *minfilt, u8 *magfilt)
{
const struct __gx_texobj *ptr = (const struct __gx_texobj*)obj;
u8 hw_filt, i;

*magfilt = ptr->tex_filt & 0x10 ? GX_LINEAR : GX_NEAR;
hw_filt = _SHIFTR(ptr->tex_filt, 5, 3);
for (i = 0; i < sizeof(_gx2HWFiltConv); i++)
if (_gx2HWFiltConv[i] == hw_filt) {
*minfilt = i;
break;
}
if (i == sizeof(_gx2HWFiltConv)) /* we didn't find it */
*minfilt = GX_NEAR;
}

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 dc18844

Please sign in to comment.