Skip to content

Commit 6862675

Browse files
authored
Have getters in GX use const pointers (#118)
* use const for getters in gx.c * fix param declarations, adjust headers and docs * add const to GX_LoadLightObj
1 parent 974af95 commit 6862675

2 files changed

Lines changed: 67 additions & 67 deletions

File tree

gc/ogc/gx.h

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,9 +1229,9 @@ typedef struct _gx_tlutobj {
12291229
*
12301230
* \details This structure contains precompiled register state setting commands and data. The application must use the
12311231
* GX_InitTexCacheRegion() function to initialize or change this object. The proper size of the object is returned by
1232-
*
1232+
*
12331233
* \code sizeof(GXTexRegion) \endcode
1234-
*
1234+
*
12351235
* \details but the internal data representation is not visible to the application.
12361236
*/
12371237
typedef struct _gx_texreg {
@@ -1445,7 +1445,7 @@ void GX_InitFifoLimits(GXFifoObj *fifo,u32 hiwatermark,u32 lowatermark);
14451445
void GX_InitFifoPtrs(GXFifoObj *fifo,void *rd_ptr,void *wt_ptr);
14461446

14471447
/*!
1448-
* \fn void GX_GetFifoPtrs(GXFifoObj *fifo,void **rd_ptr,void **wt_ptr)
1448+
* \fn void GX_GetFifoPtrs(const GXFifoObj *fifo,void **rd_ptr,void **wt_ptr)
14491449
* \brief Returns the current value of the Graphics FIFO read and write pointers.
14501450
*
14511451
* \note See GX_EnableBreakPt() for an example of why you would do this.
@@ -1456,7 +1456,7 @@ void GX_InitFifoPtrs(GXFifoObj *fifo,void *rd_ptr,void *wt_ptr);
14561456
*
14571457
* \return none
14581458
*/
1459-
void GX_GetFifoPtrs(GXFifoObj *fifo,void **rd_ptr,void **wt_ptr);
1459+
void GX_GetFifoPtrs(const GXFifoObj *fifo,void **rd_ptr,void **wt_ptr);
14601460

14611461
/*!
14621462
* \fn void GX_SetCPUFifo(GXFifoObj *fifo)
@@ -1515,17 +1515,17 @@ void GX_GetCPUFifo(GXFifoObj *fifo);
15151515
void GX_GetGPFifo(GXFifoObj *fifo);
15161516

15171517
/*!
1518-
* \fn void* GX_GetFifoBase(GXFifoObj *fifo)
1518+
* \fn void* GX_GetFifoBase(const GXFifoObj *fifo)
15191519
* \brief Get the base address for a given \a fifo.
15201520
*
15211521
* \param[in] fifo the object to get the address from
15221522
*
15231523
* \return pointer to the base address of the FIFO in main memory.
15241524
*/
1525-
void* GX_GetFifoBase(GXFifoObj *fifo);
1525+
void* GX_GetFifoBase(const GXFifoObj *fifo);
15261526

15271527
/*!
1528-
* \fn u32 GX_GetFifoCount(GXFifoObj *fifo)
1528+
* \fn u32 GX_GetFifoCount(const GXFifoObj *fifo)
15291529
* \brief Returns number of cache lines in the FIFO.
15301530
*
15311531
* \note The count is incorrect if an overflow has occurred (i.e. you have written more data than the size of the fifo), as the
@@ -1535,20 +1535,20 @@ void* GX_GetFifoBase(GXFifoObj *fifo);
15351535
*
15361536
* \return number of cache lines in the FIFO
15371537
*/
1538-
u32 GX_GetFifoCount(GXFifoObj *fifo);
1538+
u32 GX_GetFifoCount(const GXFifoObj *fifo);
15391539

15401540
/*!
1541-
* \fn u32 GX_GetFifoSize(GXFifoObj *fifo)
1541+
* \fn u32 GX_GetFifoSize(const GXFifoObj *fifo)
15421542
* \brief Get the size of a given \a fifo.
15431543
*
15441544
* \param[in] fifo the object to get the size from
15451545
*
15461546
* \return size of the FIFO, in bytes
15471547
*/
1548-
u32 GX_GetFifoSize(GXFifoObj *fifo);
1548+
u32 GX_GetFifoSize(const GXFifoObj *fifo);
15491549

15501550
/*!
1551-
* \fn u8 GX_GetFifoWrap(GXFifoObj *fifo)
1551+
* \fn u8 GX_GetFifoWrap(const GXFifoObj *fifo)
15521552
* \brief Returns a non-zero value if the write pointer has passed the TOP of the FIFO.
15531553
*
15541554
* \details Returns true only if the FIFO is attached to the CPU and the FIFO write pointer has passed the top of the FIFO. Use the
@@ -1561,7 +1561,7 @@ u32 GX_GetFifoSize(GXFifoObj *fifo);
15611561
*
15621562
* \return wrap value
15631563
*/
1564-
u8 GX_GetFifoWrap(GXFifoObj *fifo);
1564+
u8 GX_GetFifoWrap(const GXFifoObj *fifo);
15651565

15661566
/*!
15671567
* \fn GXDrawDoneCallback GX_SetDrawDoneCallback(GXDrawDoneCallback cb)
@@ -1747,7 +1747,7 @@ void GX_DrawDone(void);
17471747
* It makes sure that the texture pipeline is finished with that area of the texture memory prior to changing its usage.
17481748
* This function should be called prior to drawing any primitives that uses the texture memory region in its new mode. It is not
17491749
* necessary to call this command when changing texture memory regions from cached to preloaded (or TLUT), since the commands to
1750-
* load the regions with data will cause the necessary synchronization to happen automatically.
1750+
* load the regions with data will cause the necessary synchronization to happen automatically.
17511751
*
17521752
* \return none
17531753
*/
@@ -2775,7 +2775,7 @@ void GX_SetTexCoordGen2(u16 texcoord,u32 tgen_typ,u32 tgen_src,u32 mtxsrc,u32 no
27752775
* to the current 16-bit Z format before comparing with the EFB's Z.
27762776
*
27772777
* \note The Z-texture calculation is done before the fog range calculation.<br><br>
2778-
*
2778+
*
27792779
* \note GX_Init() disables Z texturing.
27802780
*
27812781
* \param[in] op \ref ztexop to perform
@@ -3525,7 +3525,7 @@ void GX_SetDstAlpha(u8 enable,u8 a);
35253525
* \fn void GX_SetFieldMask(u8 even_mask,u8 odd_mask)
35263526
* \brief selectively enables and disables interlacing of the frame buffer image.
35273527
*
3528-
* \details This function is used when rendering fields to an interlaced Embedded Frame Buffer (EFB).
3528+
* \details This function is used when rendering fields to an interlaced Embedded Frame Buffer (EFB).
35293529
*
35303530
* \note When the mask is <tt>GX_FALSE</tt>, that field will not be written to the EFB, but the other field will be computed. In other words, you pay the
35313531
* fill rate price of a frame to produce a field.
@@ -3971,7 +3971,7 @@ void GX_PeekZ(u16 x,u16 y,u32 *z);
39713971
* When \a comp_enable is set to <tt>GX_DISABLE</tt>, poke Z buffering is disabled and the Z buffer is not updated. The \a func parameter determines the
39723972
* comparison that is performed. In the comparison function, the poked Z value is on the left while the Z value from the Z buffer is on the
39733973
* right. If the result of the comparison is false, the poked Z value is discarded. The parameter \a update_enable determines whether or not the
3974-
* Z buffer is updated with the new Z value after a comparison is performed.
3974+
* Z buffer is updated with the new Z value after a comparison is performed.
39753975
*
39763976
* \note The normal rendering Z mode (set by GX_SetZMode()) is not affected by this function.<br><br>
39773977
*
@@ -3986,7 +3986,7 @@ void GX_PeekZ(u16 x,u16 y,u32 *z);
39863986
void GX_PokeZMode(u8 comp_enable,u8 func,u8 update_enable);
39873987

39883988
/*!
3989-
* \fn u32 GX_GetTexObjFmt(GXTexObj *obj)
3989+
* \fn u32 GX_GetTexObjFmt(const GXTexObj *obj)
39903990
* \brief Returns the texture format described by texture object \a obj.
39913991
*
39923992
* \note Use GX_InitTexObj() or GX_InitTexObjCI() to initialize the texture format.
@@ -3995,22 +3995,22 @@ void GX_PokeZMode(u8 comp_enable,u8 func,u8 update_enable);
39953995
*
39963996
* \return texture format of the given texture object
39973997
*/
3998-
u32 GX_GetTexObjFmt(GXTexObj *obj);
3998+
u32 GX_GetTexObjFmt(const GXTexObj *obj);
39993999

40004000
/*!
4001-
* \fn u32 GX_GetTexObjMipMap(GXTexObj *obj)
4001+
* \fn u32 GX_GetTexObjMipMap(const GXTexObj *obj)
40024002
* \brief Returns the texture mipmap enable described by texture object \a obj.
4003-
*
4003+
*
40044004
* \note Use GX_InitTexObj() or GX_InitTexObjCI() to initialize the texture mipmap enable.
40054005
*
40064006
* \param[in] obj ptr to a texture object
40074007
*
40084008
* \return mipmap enable flag
40094009
*/
4010-
u32 GX_GetTexObjMipMap(GXTexObj *obj);
4010+
u32 GX_GetTexObjMipMap(const GXTexObj *obj);
40114011

40124012
/*!
4013-
* \fn void* GX_GetTexObjUserData(GXTexObj *obj)
4013+
* \fn void* GX_GetTexObjUserData(const GXTexObj *obj)
40144014
* \brief Used to get a pointer to user data from the \ref GXTexObj structure.
40154015
*
40164016
* \details You can use this function to retrieve private data structures from the texture object. This pointer is set using GX_InitTexObjUserData().
@@ -4019,10 +4019,10 @@ u32 GX_GetTexObjMipMap(GXTexObj *obj);
40194019
*
40204020
* \return Pointer to user data.
40214021
*/
4022-
void* GX_GetTexObjUserData(GXTexObj *obj);
4022+
void* GX_GetTexObjUserData(const GXTexObj *obj);
40234023

40244024
/*!
4025-
* \fn void* GX_GetTexObjData(GXTexObj *obj)
4025+
* \fn void* GX_GetTexObjData(const GXTexObj *obj)
40264026
* \brief Used to get a pointer to texture data from the \ref GXTexObj structure.
40274027
*
40284028
* \note The returned pointer is a physical address.
@@ -4031,10 +4031,10 @@ void* GX_GetTexObjUserData(GXTexObj *obj);
40314031
*
40324032
* \return Physical pointer to texture data.
40334033
*/
4034-
void* GX_GetTexObjData(GXTexObj *obj);
4034+
void* GX_GetTexObjData(const GXTexObj *obj);
40354035

40364036
/*!
4037-
* \fn u8 GX_GetTexObjWrapS(GXTexObj* obj)
4037+
* \fn u8 GX_GetTexObjWrapS(const GXTexObj* obj)
40384038
* \brief Returns the texture wrap s mode described by texture object \a obj.
40394039
*
40404040
* \note Use GX_InitTexObj() or GX_InitTexObjCI() to initialize the texture wrap s mode.
@@ -4043,10 +4043,10 @@ void* GX_GetTexObjData(GXTexObj *obj);
40434043
*
40444044
* \return wrap s mode
40454045
*/
4046-
u8 GX_GetTexObjWrapS(GXTexObj* obj);
4046+
u8 GX_GetTexObjWrapS(const GXTexObj* obj);
40474047

40484048
/*!
4049-
* \fn u8 GX_GetTexObjWrapT(GXTexObj* obj)
4049+
* \fn u8 GX_GetTexObjWrapT(const GXTexObj* obj)
40504050
* \brief Returns the texture wrap t mode described by texture object \a obj.
40514051
*
40524052
* \note Use GX_InitTexObj() or GX_InitTexObjCI() to initialize the texture wrap t mode.
@@ -4055,10 +4055,10 @@ u8 GX_GetTexObjWrapS(GXTexObj* obj);
40554055
*
40564056
* \return wrap t mode
40574057
*/
4058-
u8 GX_GetTexObjWrapT(GXTexObj* obj);
4058+
u8 GX_GetTexObjWrapT(const GXTexObj* obj);
40594059

40604060
/*!
4061-
* \fn u16 GX_GetTexObjHeight(GXTexObj* obj)
4061+
* \fn u16 GX_GetTexObjHeight(const GXTexObj* obj)
40624062
* \brief Returns the texture height described by texture object \a obj.
40634063
*
40644064
* \note Use GX_InitTexObj() or GX_InitTexObjCI() to initialize the texture height.
@@ -4067,10 +4067,10 @@ u8 GX_GetTexObjWrapT(GXTexObj* obj);
40674067
*
40684068
* \return texture height
40694069
*/
4070-
u16 GX_GetTexObjHeight(GXTexObj* obj);
4070+
u16 GX_GetTexObjHeight(const GXTexObj* obj);
40714071

40724072
/*!
4073-
* \fn u16 GX_GetTexObjWidth(GXTexObj* obj)
4073+
* \fn u16 GX_GetTexObjWidth(const GXTexObj* obj)
40744074
* \brief Returns the texture width described by texture object \a obj.
40754075
*
40764076
* \note Use GX_InitTexObj() or GX_InitTexObjCI() to initialize the texture width.
@@ -4079,10 +4079,10 @@ u16 GX_GetTexObjHeight(GXTexObj* obj);
40794079
*
40804080
* \return texture width
40814081
*/
4082-
u16 GX_GetTexObjWidth(GXTexObj* obj);
4082+
u16 GX_GetTexObjWidth(const GXTexObj* obj);
40834083

40844084
/*!
4085-
* \fn void GX_GetTexObjAll(GXTexObj* obj, void** image_ptr, u16* width, u16* height, u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap);
4085+
* \fn void GX_GetTexObjAll(const GXTexObj* obj, void** image_ptr, u16* width, u16* height, u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap);
40864086
* \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().
40874087
*
40884088
* \param[in] obj ptr to a texture object
@@ -4094,7 +4094,7 @@ u16 GX_GetTexObjWidth(GXTexObj* obj);
40944094
*
40954095
* \return none
40964096
*/
4097-
void GX_GetTexObjAll(GXTexObj* obj, void** image_ptr, u16* width, u16* height, u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap);
4097+
void GX_GetTexObjAll(const GXTexObj* obj, void** image_ptr, u16* width, u16* height, u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap);
40984098

40994099
/*!
41004100
* \fn u32 GX_GetTexBufferSize(u16 wd,u16 ht,u32 fmt,u8 mipmap,u8 maxlod)
@@ -4677,7 +4677,7 @@ void GX_InitLightColor(GXLightObj *lit_obj,GXColor col);
46774677
void GX_InitLightDir(GXLightObj *lit_obj,f32 nx,f32 ny,f32 nz);
46784678

46794679
/*!
4680-
* \fn void GX_LoadLightObj(GXLightObj *lit_obj,u8 lit_id)
4680+
* \fn void GX_LoadLightObj(const GXLightObj *lit_obj,u8 lit_id)
46814681
* \brief Loads a light object into a set of hardware registers associated with a \ref lightid.
46824682
*
46834683
* \details This function copies the light object data into the graphics FIFO through the CPU write-gather buffer mechanism. This guarantees that
@@ -4692,7 +4692,7 @@ void GX_InitLightDir(GXLightObj *lit_obj,f32 nx,f32 ny,f32 nz);
46924692
*
46934693
* \return none
46944694
*/
4695-
void GX_LoadLightObj(GXLightObj *lit_obj,u8 lit_id);
4695+
void GX_LoadLightObj(const GXLightObj *lit_obj,u8 lit_id);
46964696

46974697
/*!
46984698
* \fn void GX_LoadLightObjIdx(u32 litobjidx,u8 litid)

libogc/gx.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,9 @@ void GX_InitFifoPtrs(GXFifoObj *fifo,void *rd_ptr,void *wt_ptr)
12811281
_CPU_ISR_Restore(level);
12821282
}
12831283

1284-
void GX_GetFifoPtrs(GXFifoObj *fifo,void **rd_ptr,void **wt_ptr)
1284+
void GX_GetFifoPtrs(const GXFifoObj *fifo,void **rd_ptr,void **wt_ptr)
12851285
{
1286-
struct __gxfifo *ptr = (struct __gxfifo*)fifo;
1286+
const struct __gxfifo *ptr = (const struct __gxfifo*)fifo;
12871287
*rd_ptr = (void*)ptr->rd_ptr;
12881288
*wt_ptr = (void*)ptr->wt_ptr;
12891289
}
@@ -1472,24 +1472,24 @@ void GX_GetGPFifo(GXFifoObj *fifo)
14721472
ptr->cpufifo_ready = gpfifo->cpufifo_ready;
14731473
}
14741474

1475-
void* GX_GetFifoBase(GXFifoObj *fifo)
1475+
void* GX_GetFifoBase(const GXFifoObj *fifo)
14761476
{
1477-
return (void*)((struct __gxfifo*)fifo)->buf_start;
1477+
return (void*)((const struct __gxfifo*)fifo)->buf_start;
14781478
}
14791479

1480-
u32 GX_GetFifoSize(GXFifoObj *fifo)
1480+
u32 GX_GetFifoSize(const GXFifoObj *fifo)
14811481
{
1482-
return ((struct __gxfifo*)fifo)->size;
1482+
return ((const struct __gxfifo*)fifo)->size;
14831483
}
14841484

1485-
u32 GX_GetFifoCount(GXFifoObj *fifo)
1485+
u32 GX_GetFifoCount(const GXFifoObj *fifo)
14861486
{
1487-
return ((struct __gxfifo*)fifo)->rdwt_dst;
1487+
return ((const struct __gxfifo*)fifo)->rdwt_dst;
14881488
}
14891489

1490-
u8 GX_GetFifoWrap(GXFifoObj *fifo)
1490+
u8 GX_GetFifoWrap(const GXFifoObj *fifo)
14911491
{
1492-
return ((struct __gxfifo*)fifo)->fifo_wrap;
1492+
return ((const struct __gxfifo*)fifo)->fifo_wrap;
14931493
}
14941494

14951495
u32 GX_GetOverflowCount(void)
@@ -2993,45 +2993,45 @@ static void __GetTexTileShift(u32 fmt,u32 *xshift,u32 *yshift)
29932993
}
29942994
#endif
29952995

2996-
u32 GX_GetTexObjFmt(GXTexObj *obj)
2996+
u32 GX_GetTexObjFmt(const GXTexObj *obj)
29972997
{
2998-
return ((struct __gx_texobj*)obj)->tex_fmt;
2998+
return ((const struct __gx_texobj*)obj)->tex_fmt;
29992999
}
30003000

3001-
u32 GX_GetTexObjMipMap(GXTexObj *obj)
3001+
u32 GX_GetTexObjMipMap(const GXTexObj *obj)
30023002
{
3003-
return (((struct __gx_texobj*)obj)->tex_flag&0x01);
3003+
return (((const struct __gx_texobj*)obj)->tex_flag&0x01);
30043004
}
3005-
void* GX_GetTexObjData(GXTexObj *obj)
3005+
void* GX_GetTexObjData(const GXTexObj *obj)
30063006
{
3007-
return (void*)(_SHIFTL(((struct __gx_texobj*)obj)->tex_maddr & 0x00ffffff,5,24));
3007+
return (void*)(_SHIFTL(((const struct __gx_texobj*)obj)->tex_maddr & 0x00ffffff,5,24));
30083008
}
30093009

3010-
u8 GX_GetTexObjWrapS(GXTexObj* obj)
3010+
u8 GX_GetTexObjWrapS(const GXTexObj *obj)
30113011
{
3012-
return ((struct __gx_texobj*)obj)->tex_filt & 0x03;
3012+
return ((const struct __gx_texobj*)obj)->tex_filt & 0x03;
30133013
}
30143014

3015-
u8 GX_GetTexObjWrapT(GXTexObj* obj)
3015+
u8 GX_GetTexObjWrapT(const GXTexObj *obj)
30163016
{
3017-
return _SHIFTR(((struct __gx_texobj*)obj)->tex_filt & 0x0c, 2, 2);
3017+
return _SHIFTR(((const struct __gx_texobj*)obj)->tex_filt & 0x0c, 2, 2);
30183018
}
30193019

3020-
u16 GX_GetTexObjHeight(GXTexObj* obj)
3020+
u16 GX_GetTexObjHeight(const GXTexObj *obj)
30213021
{
3022-
return _SHIFTR(((struct __gx_texobj*)obj)->tex_size & 0xffc00, 10, 10) + 1;
3022+
return _SHIFTR(((const struct __gx_texobj*)obj)->tex_size & 0xffc00, 10, 10) + 1;
30233023
}
30243024

3025-
u16 GX_GetTexObjWidth(GXTexObj* obj)
3025+
u16 GX_GetTexObjWidth(const GXTexObj *obj)
30263026
{
3027-
return (((struct __gx_texobj*)obj)->tex_size & 0x3ff) + 1;
3027+
return (((const struct __gx_texobj*)obj)->tex_size & 0x3ff) + 1;
30283028
}
30293029

30303030

3031-
void GX_GetTexObjAll(GXTexObj* obj, void** image_ptr, u16* width, u16* height,
3031+
void GX_GetTexObjAll(const GXTexObj *obj, void** image_ptr, u16* width, u16* height,
30323032
u8* format, u8* wrap_s, u8* wrap_t, u8* mipmap)
30333033
{
3034-
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
3034+
const struct __gx_texobj *ptr = (const struct __gx_texobj*)obj;
30353035
*image_ptr = (void*)(_SHIFTL(ptr->tex_maddr & 0x00ffffff,5,24));
30363036
*width = (ptr->tex_size & 0x3ff) + 1;
30373037
*height = _SHIFTR(ptr->tex_size & 0xffc00, 10, 10) + 1;
@@ -3389,9 +3389,9 @@ void GX_InitTexObjUserData(GXTexObj *obj,void *userdata)
33893389
ptr->usr_data = (u32)userdata;
33903390
}
33913391

3392-
void* GX_GetTexObjUserData(GXTexObj *obj)
3392+
void* GX_GetTexObjUserData(const GXTexObj *obj)
33933393
{
3394-
struct __gx_texobj *ptr = (struct __gx_texobj*)obj;
3394+
const struct __gx_texobj *ptr = (const struct __gx_texobj*)obj;
33953395
return (void*)ptr->usr_data;
33963396
}
33973397

@@ -4548,11 +4548,11 @@ void GX_InitLightColor(GXLightObj *lit_obj,GXColor col)
45484548
lit->col = ((_SHIFTL(col.r,24,8))|(_SHIFTL(col.g,16,8))|(_SHIFTL(col.b,8,8))|(col.a&0xff));
45494549
}
45504550

4551-
void GX_LoadLightObj(GXLightObj *lit_obj,u8 lit_id)
4551+
void GX_LoadLightObj(const GXLightObj *lit_obj,u8 lit_id)
45524552
{
45534553
u32 id;
45544554
u16 reg;
4555-
struct __gx_litobj *lit = (struct __gx_litobj*)lit_obj;
4555+
const struct __gx_litobj *lit = (const struct __gx_litobj*)lit_obj;
45564556

45574557
switch(lit_id) {
45584558
case GX_LIGHT0:

0 commit comments

Comments
 (0)