Skip to content

Commit

Permalink
Add GX_GetTexObjLODAll
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Apr 3, 2022
1 parent b4a9312 commit 69c0392
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
41 changes: 41 additions & 0 deletions gc/ogc/gx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4106,6 +4106,18 @@ u8 GX_GetTexObjMipMap(GXTexObj *obj);
*/
void* GX_GetTexObjUserData(GXTexObj *obj);

/*!
* \fn u32 GX_GetTexObjTlut(GXTexObj *obj)
* \brief Returns the TLUT name associated with texture object \a obj.
*
* \note Use GX_InitTexObjCI() to initialize a texture object with the desired TLUT name.
*
* \note Use GX_InitTexObjTlut() to modify the TLUT associated with an existing texture object.
*
* \param[in] obj ptr to a texture object
*
* \return TLUT name associated with this texture object
*/
u32 GX_GetTexObjTlut(GXTexObj *obj);

/*!
Expand All @@ -4117,12 +4129,41 @@ u32 GX_GetTexObjTlut(GXTexObj *obj);
* \param[out] wd Returns the width of the texture or LOD 0 for mipmaps
* \param[out] ht Returns the height of the texture or LOD 0 for mipmaps
* \param[out] fmt Returns the texel format
* \param[out] wrap_s Returns the mode which describes how texture coordinates will be wrapped in the S direction
* \param[out] wrap_t Returns the mode which describes how texture coordinates will be wrapped in the T direction
* \param[out] mipmap Returns the mipmap enable flag.
*
* \return none
*/
void GX_GetTexObjAll(GXTexObj *obj,void **img_ptr,u16 *wd,u16 *ht,u8 *fmt,u8 *wrap_s,u8 *wrap_t,u8 *mipmap);

/*!
* \fn void GX_GetTexObjLODAll(GXTexObj *obj,u8 *minfilt,u8 *magfilt,f32 *minlod,f32 *maxlod,f32 *lodbias,u8 *biasclamp,u8 *edgelod,u8 *maxaniso)
* \brief Returns the LOD-related 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, GXInitTexObjCI(). The LOD-related parameters are set using GX_InitTexObjLOD().
*
* \param[in] obj ptr to a texture object
* \param[out] minfilt Returns the minification filter from the texture object
* \param[out] magfilt Returns the magnification filter
* \param[out] minlod Returns the minimum LOD bound
* \param[out] maxlod Returns the maximum LOD bound
* \param[out] lodbias Returns the LOD bias control
* \param[out] biasclamp Returns the LOD bias clamping parameter
* \param[out] edgelod Returns whether or not edge LOD has been enabled
* \param[out] maxaniso Returns the anisotropic filtering setting
*
* \return none
*/
void GX_GetTexObjLODAll(GXTexObj *obj,u8 *minfilt,u8 *magfilt,f32 *minlod,f32 *maxlod,f32 *lodbias,u8 *biasclamp,u8 *edgelod,u8 *maxaniso);

u8 GX_GetTexObjMinFilt(GXTexObj *obj);
u8 GX_GetTexObjMagFilt(GXTexObj *obj);
f32 GX_GetTexObjMinLOD(GXTexObj *obj);
f32 GX_GetTexObjMaxLOD(GXTexObj *obj);
f32 GX_GetTexObjLODBias(GXTexObj *obj);
u8 GX_GetTexObjBiasClamp(GXTexObj *obj);
u8 GX_GetTexObjEdgeLOD(GXTexObj *obj);
u8 GX_GetTexObjMaxAniso(GXTexObj *obj);

/*!
* \fn u32 GX_GetTexBufferSize(u16 wd,u16 ht,u32 fmt,u8 mipmap,u8 maxlod)
* \brief Returns the amount of memory in bytes needed to store a texture of the given size and \a fmt.
Expand Down
66 changes: 65 additions & 1 deletion libogc/gx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,71 @@ u8 GX_GetTexObjMipMap(GXTexObj *obj)
return ptr->tex_flag&0x01;
}

void GX_GetTexObjLODAll(GXTexObj *obj,u8 *minfilt,u8 *magfilt,f32 *minlod,f32 *maxlod,f32 *lodbias,u8 *biasclamp,u8 *edgelod,u8 *maxaniso)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
static const u8 HW2GXFiltConv[] = {0x00,0x02,0x04,0x00,0x01,0x03,0x05,0x00};

*minfilt = HW2GXFiltConv[_SHIFTR(ptr->tex_filt,5,3)];
*magfilt = _SHIFTR(ptr->tex_filt,4,1);
*minlod = (ptr->tex_lod&0xff)/16.0f;
*maxlod = _SHIFTR(ptr->tex_lod,8,8)/16.0f;
*lodbias = (s8)_SHIFTR(ptr->tex_filt,9,8)/32.0f;
*biasclamp = _SHIFTR(ptr->tex_filt,21,1);
*edgelod = !_SHIFTR(ptr->tex_filt,8,1);
*maxaniso = _SHIFTR(ptr->tex_filt,19,2);
}

u8 GX_GetTexObjMinFilt(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
static const u8 HW2GXFiltConv[] = {0x00,0x02,0x04,0x00,0x01,0x03,0x05,0x00};

return HW2GXFiltConv[_SHIFTR(ptr->tex_filt,5,3)];
}

u8 GX_GetTexObjMagFilt(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return _SHIFTR(ptr->tex_filt,4,1);
}

f32 GX_GetTexObjMinLOD(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return (ptr->tex_lod&0xff)/16.0f;
}

f32 GX_GetTexObjMaxLOD(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return _SHIFTR(ptr->tex_lod,8,8)/16.0f;
}

f32 GX_GetTexObjLODBias(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return (s8)_SHIFTR(ptr->tex_filt,9,8)/32.0f;
}

u8 GX_GetTexObjBiasClamp(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return _SHIFTR(ptr->tex_filt,21,1);
}

u8 GX_GetTexObjEdgeLOD(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return !_SHIFTR(ptr->tex_filt,8,1);
}

u8 GX_GetTexObjMaxAniso(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
return _SHIFTR(ptr->tex_filt,19,2);
}

u32 GX_GetTexObjTlut(GXTexObj *obj)
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
Expand Down Expand Up @@ -3306,7 +3371,6 @@ void GX_InitTexObjLOD(GXTexObj *obj,u8 minfilt,u8 magfilt,f32 minlod,f32 maxlod,
{
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
static const u8 GX2HWFiltConv[] = {0x00,0x04,0x01,0x05,0x02,0x06,0x00,0x00};
//static const u8 HW2GXFiltConv[] = {0x00,0x02,0x04,0x00,0x01,0x03,0x05,0x00};

if(lodbias<-4.0f) lodbias = -4.0f;
else if(lodbias==4.0f) lodbias = 3.99f;
Expand Down

0 comments on commit 69c0392

Please sign in to comment.