Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
imgfx.c File Reference

Go to the source code of this file.

Data Structures

union  ImgFXIntVars
 
union  ImgFXFloatVars
 
struct  ImgFXState
 
struct  ImgFXCacheEntry
 
struct  ImgFXRenderMode
 
struct  ImgFXIntVars.args
 
struct  ImgFXIntVars.anim
 
struct  ImgFXIntVars.wavy
 
struct  ImgFXIntVars.color
 
struct  ImgFXIntVars.hologram
 
struct  ImgFXIntVars.overlay
 
struct  ImgFXFloatVars.anim
 
struct  ImgFXFloatVars.wavy
 
struct  ImgFXFloatVars.overlay
 

Typedefs

typedef ImgFXState ImgFXInstanceList[MAX_IMGFX_INSTANCES]
 

Enumerations

enum  ImgFXAnimFlags { IMGFX_ANIM_FLAG_ABSOLUTE_COORDS = 1 }
 

Functions

void imgfx_cache_instance_data (ImgFXState *state)
 
void imgfx_clear_instance_data (ImgFXState *state)
 
void imgfx_init_instance (ImgFXState *state)
 
void imgfx_make_mesh (ImgFXState *state)
 
void imgfx_appendGfx_mesh (ImgFXState *state, Matrix4f mtx)
 
void imgfx_mesh_make_strip (ImgFXState *state)
 
void imgfx_mesh_make_grid (ImgFXState *state)
 
void imgfx_mesh_anim_update (ImgFXState *state)
 
void imgfx_appendGfx_mesh_basic (ImgFXState *, Matrix4f mtx)
 
void imgfx_appendGfx_mesh_grid (ImgFXState *, Matrix4f mtx)
 
void imgfx_appendGfx_mesh_anim (ImgFXState *, Matrix4f mtx)
 
void imgfx_appendGfx_mesh_strip (ImgFXState *, Matrix4f mtx)
 
void imgfx_wavy_init (ImgFXState *state)
 
void imgfx_mesh_make_wavy (ImgFXState *state)
 
void imgfx_mesh_load_colors (ImgFXState *state)
 
void imgfx_set_vtx_buf_capacity (s16 arg0)
 
void imgfx_init (void)
 
void func_8013A4D0 (void)
 
void imgfx_add_to_cache (void *data, s8 usingContextualHeap)
 
void imgfx_update_cache_impl (void)
 
void imgfx_update_cache (void)
 
s32 imgfx_get_free_instances (s32 count)
 
void imgfx_release_instance (u32 idx)
 
void imgfx_release_instance_chain (u32 idx)
 
s32 imgfx_get_next_instance (s32 idx)
 
ImgFXStateimgfx_get_instance (s32 idx)
 
void imgfx_update (u32 idx, ImgFXType type, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 flags)
 
void imgfx_set_state_flags (s32 idx, u16 flagBits, s32 mode)
 
s32 imgfx_appendGfx_component (s32 idx, ImgFXTexture *ifxImg, u32 flagBits, Matrix4f mtx)
 
ImgFXAnimHeaderimgfx_load_anim (ImgFXState *state)
 

Variables

HeapNode heap_spriteHead
 
BSS ImgFXWorkingTexture ImgFXCurrentTexture
 
BSS VtxImgFXVtxBuffers [2]
 
BSS Vtximgfx_vtxBuf
 
BSS ImgFXInstanceListImgFXInstances
 
BSS ImgFXAnimHeader ImgFXAnimHeaders [MAX_IMGFX_INSTANCES]
 
BSS ImgFXCacheEntry ImgFXDataCache [8]
 
ImgFXWorkingTextureImgFXCurrentTexturePtr = &ImgFXCurrentTexture
 
u16 imgfx_vtxCount = 0
 
Lights2 ImgFXLights = gdSPDefLights2(144, 144, 144, 255, 255, 255, 0, 0, 120, 255, 255, 255, 0, 0, 136)
 
Vp D_8014EE40
 
Vp D_8014EE50
 
u16 ImgFXVtxBufferCapacity = 300
 
Gfx DefaultImgFXSetupGfx []
 
ImgFXRenderMode ImgFXRenderModes []
 
Addr shock_header
 
Addr shiver_header
 
Addr vertical_pipe_curl_header
 
Addr horizontal_pipe_curl_header
 
Addr startle_header
 
Addr flutter_down_header
 
Addr unfurl_header
 
Addr get_in_bed_header
 
Addr spirit_capture_header
 
Addr unused_1_header
 
Addr unused_2_header
 
Addr unused_3_header
 
Addr tutankoopa_gather_header
 
Addr tutankoopa_swirl_2_header
 
Addr tutankoopa_swirl_1_header
 
Addr shuffle_cards_header
 
Addr flip_card_1_header
 
Addr flip_card_2_header
 
Addr flip_card_3_header
 
Addr cymbal_crush_header
 
u8ImgFXAnimOffsets []
 

Data Structure Documentation

◆ ImgFXIntVars

union ImgFXIntVars
Data Fields
s32 raw[2][4]
struct ImgFXIntVars.args args
struct ImgFXIntVars.anim anim
struct ImgFXIntVars.wavy wavy
struct ImgFXIntVars.color color
struct ImgFXIntVars.hologram hologram
struct ImgFXIntVars.overlay overlay

◆ ImgFXFloatVars

union ImgFXFloatVars
Data Fields
f32 raw[2][4]
struct ImgFXFloatVars.anim anim
struct ImgFXFloatVars.wavy wavy
struct ImgFXFloatVars.overlay overlay

◆ ImgFXState

struct ImgFXState
Data Fields
u8 arrayIdx
u8 meshType
u8 renderType
u8 subdivX
u8 subdivY
s8 lastAnimCmd
s8 lastColorCmd
char unk_07[0x1]
u16 firstVtxIdx
u16 lastVtxIdx
u16 unk_0C
s16 unk_0E
s16 nextIdx
s32 flags
char unk_18[0x4]
ImgFXIntVars ints
ImgFXFloatVars floats
Color_RGBA8 * colorBuf
u16 colorBufCount
char unk_62[0x2]
u8 * curAnimOffset
Vtx * vtxBufs[2]
Gfx * gfxBufs[2]
s32 otherModeL

◆ ImgFXCacheEntry

struct ImgFXCacheEntry
Data Fields
s32 * data
u8 staleCooldownTimer
u8 usingContextualHeap
char unk_06[0x2]

◆ ImgFXRenderMode

struct ImgFXRenderMode
Data Fields
s32 mode1
s32 mode2
u8 flags

◆ ImgFXIntVars.args

struct ImgFXIntVars.args
Data Fields
s32 anim[4]
s32 color[4]

◆ ImgFXIntVars.anim

struct ImgFXIntVars.anim
Data Fields
s32 type
s32 interval
s32 step

◆ ImgFXIntVars.wavy

struct ImgFXIntVars.wavy
Data Fields
Vec3i mag

◆ ImgFXIntVars.color

struct ImgFXIntVars.color
Data Fields
char unk_00[0x10]
s32 r
s32 g
s32 b
s32 a

◆ ImgFXIntVars.hologram

struct ImgFXIntVars.hologram
Data Fields
char unk_00[0x10]
s32 mode
s32 noiseAmt
char unk_18[4]
s32 alphaAmt

◆ ImgFXIntVars.overlay

struct ImgFXIntVars.overlay
Data Fields
char unk_00[0x10]
ImgFXOverlayTexture * pattern
s32 alpha

◆ ImgFXFloatVars.anim

struct ImgFXFloatVars.anim
Data Fields
f32 curFrame
f32 curIdx

◆ ImgFXFloatVars.wavy

struct ImgFXFloatVars.wavy
Data Fields
f32 phase1
f32 phase2
f32 phase3

◆ ImgFXFloatVars.overlay

struct ImgFXFloatVars.overlay
Data Fields
char unk_00[0x10]
f32 posX
f32 posY

Typedef Documentation

◆ ImgFXInstanceList

Definition at line 111 of file imgfx.c.

Enumeration Type Documentation

◆ ImgFXAnimFlags

Enumerator
IMGFX_ANIM_FLAG_ABSOLUTE_COORDS 

Definition at line 101 of file imgfx.c.

101 {
102 IMGFX_ANIM_FLAG_ABSOLUTE_COORDS = 1, // image-relative (in percent) when unset
103};
@ IMGFX_ANIM_FLAG_ABSOLUTE_COORDS
Definition imgfx.c:102

Function Documentation

◆ imgfx_cache_instance_data()

void imgfx_cache_instance_data ( ImgFXState * state)

Definition at line 420 of file imgfx.c.

420 {
421 if (state->curAnimOffset != nullptr) {
422 state->curAnimOffset = nullptr;
423 }
424 if (state->vtxBufs[0] != nullptr) {
425 imgfx_add_to_cache(state->vtxBufs[0], true);
426 state->vtxBufs[0] = nullptr;
427 }
428 if (state->vtxBufs[1] != nullptr) {
429 imgfx_add_to_cache(state->vtxBufs[1], true);
430 state->vtxBufs[1] = nullptr;
431 }
432 if (state->gfxBufs[0] != nullptr) {
433 imgfx_add_to_cache(state->gfxBufs[0], true);
434 state->gfxBufs[0] = nullptr;
435 }
436 if (state->gfxBufs[1] != nullptr) {
437 imgfx_add_to_cache(state->gfxBufs[1], true);
438 state->gfxBufs[1] = nullptr;
439 }
440}
Vtx * vtxBufs[2]
Definition imgfx.c:89
void imgfx_add_to_cache(void *data, s8 usingContextualHeap)
Definition imgfx.c:296
Gfx * gfxBufs[2]
Definition imgfx.c:90
u8 * curAnimOffset
Definition imgfx.c:88

Referenced by func_8013A4D0(), imgfx_appendGfx_component(), and imgfx_update().

◆ imgfx_clear_instance_data()

void imgfx_clear_instance_data ( ImgFXState * state)

Definition at line 442 of file imgfx.c.

442 {
443 state->curAnimOffset = nullptr;
444 state->vtxBufs[0] = nullptr;
445 state->vtxBufs[1] = nullptr;
446 state->gfxBufs[0] = nullptr;
447 state->gfxBufs[1] = nullptr;
448 state->colorBuf = nullptr;
449 state->colorBufCount = 0;
450}
u16 colorBufCount
Definition imgfx.c:86
Color_RGBA8 * colorBuf
Definition imgfx.c:85

Referenced by imgfx_init().

◆ imgfx_init_instance()

void imgfx_init_instance ( ImgFXState * state)

Definition at line 452 of file imgfx.c.

452 {
453 s32 i;
454 s32 j;
455
456 state->nextIdx = -1;
457 state->lastAnimCmd = IMGFX_CLEAR;
458 state->lastColorCmd = IMGFX_CLEAR;
459 state->flags = 0;
462 state->firstVtxIdx = 0;
463 state->lastVtxIdx = 0;
464 state->unk_0C = 0;
465 state->unk_0E = 0;
466 state->ints.raw[0][3] = 255;
467 state->ints.raw[1][3] = 255;
468 state->subdivX = 0;
469 state->subdivY = 0;
470 state->firstVtxIdx = 0;
471 state->lastVtxIdx = 0;
472
473 for (i = 0; i < ARRAY_COUNT(state->ints.raw); i++) {
474 for (j = 0; j < ARRAY_COUNT(state->ints.raw[0]); j++) {
475 state->ints.raw[i][j] = 0;
476 }
477 }
478
479 for (i = 0; i < ARRAY_COUNT(state->floats.raw); i++) {
480 for (j = 0; j < ARRAY_COUNT(state->floats.raw[0]); j++) {
481 state->floats.raw[i][j] = 0;
482 }
483 }
484}
BSS s32 PopupMenu_SelectedIndex
@ IMGFX_RENDER_DEFAULT
Definition enums.h:4746
@ IMGFX_CLEAR
Definition enums.h:4702
@ IMGFX_MESH_DEFAULT
Definition enums.h:4770
s8 lastAnimCmd
Definition imgfx.c:73
u16 firstVtxIdx
Definition imgfx.c:76
u16 unk_0C
Definition imgfx.c:78
u8 subdivY
Definition imgfx.c:72
u8 subdivX
Definition imgfx.c:71
s32 flags
Definition imgfx.c:81
u16 lastVtxIdx
Definition imgfx.c:77
s16 unk_0E
Definition imgfx.c:79
s8 lastColorCmd
Definition imgfx.c:74
u8 renderType
Definition imgfx.c:70
ImgFXIntVars ints
Definition imgfx.c:83
u8 meshType
Definition imgfx.c:69
s32 raw[2][4]
Definition imgfx.c:11
ImgFXFloatVars floats
Definition imgfx.c:84
f32 raw[2][4]
Definition imgfx.c:48
s16 nextIdx
Definition imgfx.c:80
#define ARRAY_COUNT(arr)
Definition macros.h:39

Referenced by func_8013A4D0(), imgfx_get_free_instances(), imgfx_init(), and imgfx_update().

◆ imgfx_make_mesh()

void imgfx_make_mesh ( ImgFXState * state)

Definition at line 760 of file imgfx.c.

760 {
761 switch (state->meshType) {
763 if (state->ints.raw[1][2] == 0) {
764 state->subdivX = 1;
765 state->subdivY = 16;
766 } else {
767 state->subdivX = 1;
768 state->subdivY = 1;
769 }
770 // fallthrough
773 break;
776 break;
778 case IMGFX_MESH_STRIP:
780 break;
781 default:
782 return;
783 }
784
785 if (state->lastAnimCmd == IMGFX_SET_WAVY) {
787 }
788
789 switch (state->lastColorCmd) {
793 break;
794 default:
795 break;
796 }
797}
@ IMGFX_COLOR_BUF_SET_MULTIPLY
Definition enums.h:4713
@ IMGFX_SET_WAVY
Definition enums.h:4706
@ IMGFX_COLOR_BUF_SET_MODULATE
Definition enums.h:4714
@ IMGFX_MESH_STRIP
Definition enums.h:4774
@ IMGFX_MESH_GRID_WAVY
Definition enums.h:4771
@ IMGFX_MESH_GRID_UNUSED
Definition enums.h:4773
@ IMGFX_MESH_ANIMATED
Definition enums.h:4772
void imgfx_mesh_make_strip(ImgFXState *state)
Definition imgfx.c:1064
void imgfx_mesh_load_colors(ImgFXState *state)
Definition imgfx.c:1898
void imgfx_mesh_make_grid(ImgFXState *state)
Definition imgfx.c:1146
void imgfx_mesh_make_wavy(ImgFXState *state)
Definition imgfx.c:1819
void imgfx_mesh_anim_update(ImgFXState *state)
Definition imgfx.c:1260

Referenced by imgfx_appendGfx_component().

◆ imgfx_appendGfx_mesh()

void imgfx_appendGfx_mesh ( ImgFXState * state,
Matrix4f mtx )

Definition at line 799 of file imgfx.c.

799 {
800 s16 skipModeChange = false;
801 s32 primAlpha = state->ints.color.a;
802 s32 renderType = state->renderType;
803 s8 angle1;
804 s8 angle2;
806 ImgFXRenderMode* renderMode;
807 s32 mode1;
808 s32 mode2;
809 s32 dirX1;
810 s32 dirZ2;
811
813
814 if (!(state->flags & IMGFX_FLAG_SKIP_GFX_SETUP)) {
816 if (state->flags & IMGFX_FLAG_NO_FILTERING) {
818 }
819 if (state->flags & IMGFX_FLAG_G_CULL_BACK) {
821 }
822 if (state->flags & IMGFX_FLAG_G_CULL_FRONT) {
824 }
825
826 renderMode = &ImgFXRenderModes[state->renderType];
827
828 mode1 = renderMode->mode1;
829 mode2 = renderMode->mode2;
830 if (renderMode->flags & IMGFX_RENDER_NO_OVERRIDE) {
831 skipModeChange = true;
832 }
833
835
836 // some modes dont support alpha < 255 and must be replaced
838 state->ints.color.a = 255;
839 switch (state->renderType) {
842 renderType = IMGFX_RENDER_MULTIPLY_ALPHA;
843 break;
846 renderType = IMGFX_RENDER_MULTIPLY_RGBA;
847 break;
850 break;
851 default:
852 break;
853 }
854 primAlpha = state->ints.color.a * ifxImgAlpha;
855 //TODO figure out bits
856 mode1 = 0x404B40;
857 mode2 = 0x104B40;
858 skipModeChange = true;
859 }
860
861 if ((state->flags & IMGFX_FLAG_400) && !skipModeChange) {
862 mode1 &= ~CVG_DST_FULL;
863 mode2 &= ~CVG_DST_FULL;
864 mode1 |= (ALPHA_CVG_SEL | IM_RD);
865 mode2 |= (ALPHA_CVG_SEL | IM_RD);
866 }
867
868 if (state->flags & IMGFX_FLAG_40) {
870 } else {
872 if (skipModeChange) {
873 mode1 |= Z_CMP;
874 mode2 |= Z_CMP;
875 } else {
876 mode1 |= (Z_CMP | Z_UPD);
877 mode2 |= (Z_CMP | Z_UPD);
878 }
879 }
880 state->otherModeL = mode2;
881 gDPSetRenderMode(gMainGfxPos++, mode1, mode2);
882
883 switch (renderType) {
885 // color: texture * prim
886 // alpha: texture
888 gDPSetPrimColor(gMainGfxPos++, 0, 0, state->ints.color.r, state->ints.color.g,
889 state->ints.color.b, 0);
890 break;
892 // color: texture
893 // alpha: texture * prim
894 if (primAlpha <= 0) {
895 return;
896 }
898 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, primAlpha);
899 break;
901 // color: texture * prim
902 // alpha: texture * prim
903 if (primAlpha <= 0) {
904 return;
905 }
907 gDPSetPrimColor(gMainGfxPos++, 0, 0, state->ints.color.r, state->ints.color.g,
908 state->ints.color.b, primAlpha);
909 break;
911 // color: lerp from prim color to 1 based on texture intensity
912 // alpha: texture
914 gDPSetPrimColor(gMainGfxPos++, 0, 0, state->ints.color.r, state->ints.color.g,
915 state->ints.color.b, 0);
916 break;
918 // color: lerp from prim color to 1 based on texture intensity
919 // alpha: texture * vtx
920 if (primAlpha <= 0) {
921 return;
922 }
924 gDPSetPrimColor(gMainGfxPos++, 0, 0, state->ints.color.r, state->ints.color.g,
925 state->ints.color.b, primAlpha);
926 break;
928 // color: modulate vtx color by texture intensity
929 // alpha: texture
933 break;
935 // color: lerp from vtx color to 1 based on texture intensity
936 // alpha: texture
940 break;
942 // color: texture
943 // alpha: texture * vtx color
947 break;
949 // color: modulate vtx color by texture intensity
950 // alpha: modulate vtx alpha by texture intensity
954 break;
956 // color: lerp from vtx color to 1 based on texture intensity
957 // alpha: vtx color * texture
961 break;
963 if (state->flags & (IMGFX_FLAG_2000 | IMGFX_FLAG_8000)) {
965
968
969 angle1 = cosine(currentCam->curYaw) * 120.0f;
970 angle2 = cosine(currentCam->curYaw + 90.0f) * 120.0f;
971 dirX1 = -angle1;
972 dirZ2 = -angle2;
973 ImgFXLights.l[0].l.dir[0] = dirX1;
974 ImgFXLights.l[1].l.dir[0] = angle1;
975 ImgFXLights.l[0].l.dir[2] = angle2;
976 ImgFXLights.l[1].l.dir[2] = dirZ2;
978 break;
979 }
981 break;
983 if (state->ints.hologram.mode == IMGFX_HOLOGRAM_NOISE) {
984 primAlpha = state->ints.hologram.alphaAmt * ifxImgAlpha;
985 // color: blend texure and noise
986 // alpha: texure * prim
989 state->ints.hologram.noiseAmt,
990 state->ints.hologram.noiseAmt,
991 state->ints.hologram.noiseAmt,
992 primAlpha);
993 } else if (state->ints.hologram.mode == IMGFX_HOLOGRAM_DITHER) {
994 primAlpha = state->ints.hologram.alphaAmt * ifxImgAlpha;
995 // color: texture
996 // alpha: texture * prim
998 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, primAlpha);
1000 } else if (state->ints.hologram.mode == IMGFX_HOLOGRAM_THRESHOLD) {
1001 s32 blendAlpha = state->ints.hologram.alphaAmt + state->ints.hologram.noiseAmt;
1002 if (blendAlpha > 255) {
1003 blendAlpha = 255;
1004 }
1005 primAlpha = state->ints.hologram.alphaAmt * ifxImgAlpha;
1006 // color: texture
1007 // alpha: texture * prim
1011 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, primAlpha);
1013 }
1014 break;
1016 // color: prim
1017 // alpha: texture
1019 gDPSetPrimColor(gMainGfxPos++, 0, 0, state->ints.color.r, state->ints.color.g,
1020 state->ints.color.b, 0);
1021 break;
1025 // color: texture
1026 // alpha: texture
1028 break;
1030 // color: texture
1031 // alpha: texture * prim
1033 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, state->ints.overlay.alpha);
1034 break;
1035 }
1036 }
1037
1038 switch (state->meshType) {
1039 case IMGFX_MESH_DEFAULT:
1040 imgfx_appendGfx_mesh_basic(state, mtx);
1041 break;
1044 imgfx_appendGfx_mesh_grid(state, mtx);
1045 break;
1047 imgfx_appendGfx_mesh_anim(state, mtx);
1048 break;
1049 case IMGFX_MESH_STRIP:
1050 imgfx_appendGfx_mesh_basic(state, mtx);
1052 imgfx_appendGfx_mesh_strip(state, mtx);
1053 break;
1054 }
1055
1057
1058 if (state->renderType == IMGFX_RENDER_HOLOGRAM) {
1061 }
1062}
@ IMGFX_RENDER_MULTIPLY_RGBA
Definition enums.h:4749
@ IMGFX_RENDER_MULTIPLY_SHADE_ALPHA
Definition enums.h:4753
@ IMGFX_RENDER_HOLOGRAM
Definition enums.h:4758
@ IMGFX_RENDER_MULTIPLY_SHADE_RGB
Definition enums.h:4752
@ IMGFX_RENDER_OVERLAY_RGBA
Definition enums.h:4761
@ IMGFX_RENDER_MODULATE_PRIM_RGBA
Definition enums.h:4751
@ IMGFX_RENDER_MULTIPLY_RGB
Definition enums.h:4747
@ IMGFX_RENDER_ANIM
Definition enums.h:4757
@ IMGFX_RENDER_MULTIPLY_SHADE_RGBA
Definition enums.h:4754
@ IMGFX_RENDER_OVERLAY_RGB
Definition enums.h:4760
@ IMGFX_RENDER_MODULATE_PRIM_RGB
Definition enums.h:4750
@ IMGFX_RENDER_MULTIPLY_ALPHA
Definition enums.h:4748
@ IMGFX_RENDER_MODULATE_SHADE_RGB
Definition enums.h:4755
@ IMGFX_RENDER_MODULATE_SHADE_RGBA
Definition enums.h:4756
@ IMGFX_RENDER_COLOR_FILL
Definition enums.h:4759
@ IMGFX_RENDER_UNUSED
Definition enums.h:4762
@ IMGFX_RENDER_NO_OVERRIDE
Definition enums.h:4766
@ IMGFX_HOLOGRAM_DITHER
Definition enums.h:4779
@ IMGFX_HOLOGRAM_NOISE
Definition enums.h:4778
@ IMGFX_HOLOGRAM_THRESHOLD
Definition enums.h:4780
@ IMGFX_FLAG_8000
Definition enums.h:4693
@ IMGFX_FLAG_40
Definition enums.h:4684
@ IMGFX_FLAG_G_CULL_BACK
Definition enums.h:4679
@ IMGFX_FLAG_G_CULL_FRONT
Definition enums.h:4680
@ IMGFX_FLAG_NO_FILTERING
Definition enums.h:4694
@ IMGFX_FLAG_2000
Definition enums.h:4691
@ IMGFX_FLAG_SKIP_GFX_SETUP
Definition enums.h:4682
@ IMGFX_FLAG_400
Definition enums.h:4688
f32 cosine(s16 arg0)
Definition 43F0.c:352
struct ImgFXIntVars::@203 hologram
void imgfx_appendGfx_mesh_strip(ImgFXState *, Matrix4f mtx)
Definition imgfx.c:1776
Lights2 ImgFXLights
Definition imgfx.c:127
ImgFXWorkingTexture * ImgFXCurrentTexturePtr
Definition imgfx.c:123
ImgFXRenderMode ImgFXRenderModes[]
Definition imgfx.c:156
s32 otherModeL
Definition imgfx.c:91
struct ImgFXIntVars::@202 color
struct ImgFXIntVars::@204 overlay
void imgfx_appendGfx_mesh_basic(ImgFXState *, Matrix4f mtx)
Definition imgfx.c:1459
void imgfx_appendGfx_mesh_anim(ImgFXState *, Matrix4f mtx)
Definition imgfx.c:1720
void imgfx_appendGfx_mesh_grid(ImgFXState *, Matrix4f mtx)
Definition imgfx.c:1642
Gfx DefaultImgFXSetupGfx[]
Definition imgfx.c:145
#define PM_CC_5D
Definition macros.h:516
#define PM_CC_5B
Definition macros.h:514
#define PM_CC_5E
Definition macros.h:517
#define PM_CC_IMGFX_COLOR_FILL
Definition macros.h:459
#define PM_CC_5C
Definition macros.h:515
#define PM_CC_12
Definition macros.h:307
#define PM_CC_IMGFX_HOLOGRAM
Definition macros.h:460
#define PM_CC_02
Definition macros.h:288
Camera gCameras[4]
Definition cam_main.c:16
Gfx * gMainGfxPos
Definition cam_main.c:14
s32 gCurrentCameraID
Definition cam_math.c:5

Referenced by imgfx_appendGfx_component().

◆ imgfx_mesh_make_strip()

void imgfx_mesh_make_strip ( ImgFXState * state)

Definition at line 1064 of file imgfx.c.

1064 {
1065 s32 offsetY;
1066 s32 offsetX;
1067 s32 stepY;
1069 s32 leftColor;
1070 s32 temp2;
1071 s32 nextY;
1072
1073 stepY = (128 * 32) / ImgFXCurrentTexturePtr->tex.width;
1076 }
1077
1080 state->firstVtxIdx = imgfx_vtxCount;
1081
1082 // create first pair of vertices to begin the strip
1083 // 'left' side
1084 imgfx_vtxBuf[imgfx_vtxCount].v.ob[0] = offsetX;
1085 imgfx_vtxBuf[imgfx_vtxCount].v.ob[1] = offsetY;
1086 imgfx_vtxBuf[imgfx_vtxCount].v.ob[2] = 0;
1087 imgfx_vtxBuf[imgfx_vtxCount].v.tc[0] = (0 + 256) * 32;
1088 imgfx_vtxBuf[imgfx_vtxCount].v.tc[1] = temp2 = (0 + 256) * 32; // required to match
1089 imgfx_vtxBuf[imgfx_vtxCount].v.cn[0] = 240;
1090 imgfx_vtxBuf[imgfx_vtxCount].v.cn[1] = 240;
1091 imgfx_vtxBuf[imgfx_vtxCount].v.cn[2] = 240;
1092 // 'right' side
1094 imgfx_vtxBuf[imgfx_vtxCount + 1].v.ob[1] = offsetY;
1095 imgfx_vtxBuf[imgfx_vtxCount + 1].v.ob[2] = 0;
1096 imgfx_vtxBuf[imgfx_vtxCount + 1].v.tc[0] = (ImgFXCurrentTexturePtr->tex.width + 256) * 32;
1097 imgfx_vtxBuf[imgfx_vtxCount + 1].v.tc[1] = temp2;
1098 imgfx_vtxBuf[imgfx_vtxCount + 1].v.cn[0] = 120;
1099 imgfx_vtxBuf[imgfx_vtxCount + 1].v.cn[1] = 120;
1100 imgfx_vtxBuf[imgfx_vtxCount + 1].v.cn[2] = 120;
1101
1102 // create remaining pairs of vertices along the strip
1103 nextY = stepY;
1104 while (true) {
1106 leftColor = rightColor + 120;
1107 imgfx_vtxCount += 2;
1108
1109 // 'left' side
1110 imgfx_vtxBuf[imgfx_vtxCount].v.ob[0] = offsetX;
1111 imgfx_vtxBuf[imgfx_vtxCount].v.ob[1] = offsetY - stepY;
1112 imgfx_vtxBuf[imgfx_vtxCount].v.ob[2] = 0;
1113 imgfx_vtxBuf[imgfx_vtxCount].v.tc[0] = (0 + 256) * 32;
1114 imgfx_vtxBuf[imgfx_vtxCount].v.tc[1] = (nextY + 256) * 32;
1118
1119 // 'right' side
1121 imgfx_vtxBuf[imgfx_vtxCount + 1].v.ob[1] = offsetY - stepY;
1122 imgfx_vtxBuf[imgfx_vtxCount + 1].v.ob[2] = 0;
1123 imgfx_vtxBuf[imgfx_vtxCount + 1].v.tc[0] = (ImgFXCurrentTexturePtr->tex.width + 256) * 32;
1124 imgfx_vtxBuf[imgfx_vtxCount + 1].v.tc[1] = (nextY + 256) * 32;
1125 imgfx_vtxBuf[imgfx_vtxCount + 1].v.cn[0] = rightColor;
1126 imgfx_vtxBuf[imgfx_vtxCount + 1].v.cn[1] = rightColor;
1127 imgfx_vtxBuf[imgfx_vtxCount + 1].v.cn[2] = rightColor;
1128
1130 offsetY -= stepY;
1133 }
1134 } else {
1135 imgfx_vtxCount += 2;
1136 break;
1137 }
1138 nextY += stepY;
1139 }
1140
1141 state->lastVtxIdx = imgfx_vtxCount - 1;
1142 state->subdivX = 1;
1143 state->subdivY = ((state->lastVtxIdx - state->firstVtxIdx) - 1) / 2;
1144}
u16 imgfx_vtxCount
Definition imgfx.c:125
BSS Vtx * imgfx_vtxBuf
Definition imgfx.c:117

Referenced by imgfx_make_mesh().

◆ imgfx_mesh_make_grid()

void imgfx_mesh_make_grid ( ImgFXState * state)

Definition at line 1146 of file imgfx.c.

1146 {
1147 f32 divSizeX;
1148 f32 divSizeY;
1149 f32 posX;
1150 f32 posY;
1151 f32 texU;
1152 f32 texV;
1153 Vtx* vtx;
1154 s32 i;
1155
1156 state->firstVtxIdx = imgfx_vtxCount;
1160 texV = 0.0f;
1162
1163 for (i = 0; i <= state->subdivY; i++) {
1164 s32 j;
1165
1166 if (i == state->subdivY) {
1169 }
1170
1172 texU = 0.0f;
1173 for (j = 0; j <= state->subdivX; vtx++, j++) {
1174 if (j == state->subdivX) {
1177 }
1178 vtx->n.ob[0] = posX;
1179 vtx->n.ob[1] = posY;
1180 vtx->n.ob[2] = 0;
1181 vtx->n.tc[0] = ((s32) texU + 256) * 32;
1182 vtx->n.tc[1] = ((s32) texV + 256) * 32;
1184 posX += divSizeX;
1185 texU += divSizeX;
1186 }
1187 posY -= divSizeY;
1188 texV += divSizeY;
1189 }
1190 state->lastVtxIdx = imgfx_vtxCount - 1;
1191}

Referenced by imgfx_make_mesh().

◆ imgfx_mesh_anim_update()

void imgfx_mesh_anim_update ( ImgFXState * state)

Definition at line 1260 of file imgfx.c.

1260 {
1263 s32 curKeyIdx;
1264 ImgFXVtx* curKeyframe = nullptr;
1265 ImgFXVtx* nextKeyframe = nullptr;
1266 s32 keyframeInterval = state->ints.anim.interval;
1267 s32 animStep = state->ints.anim.step;
1268 s32 curSubframe = state->floats.anim.curFrame;
1269 ImgFXAnimHeader* header = imgfx_load_anim(state);
1270 u8* romStart;
1271 f32 lerpAlpha;
1272 s32 i;
1273
1274 if (header == nullptr) {
1275 return;
1276 }
1277
1278 if (state->flags & IMGFX_FLAG_200) {
1279 state->flags &= ~IMGFX_FLAG_200;
1280 if (state->flags & IMGFX_FLAG_REVERSE_ANIM) {
1281 state->floats.anim.curIdx = header->keyframesCount - 1;
1282 }
1283 }
1284 curKeyIdx = state->floats.anim.curIdx;
1286 if (state->flags & IMGFX_FLAG_4000) {
1288 } else {
1289 if (state->flags & IMGFX_FLAG_REVERSE_ANIM) {
1290 nextKeyIdx = curKeyIdx - 1;
1291 if (nextKeyIdx < 0) {
1293 if (state->flags & IMGFX_FLAG_LOOP_ANIM) {
1294 nextKeyIdx = header->keyframesCount - 1;
1295 }
1296 }
1297 } else {
1298 nextKeyIdx = curKeyIdx + 1;
1299 if (nextKeyIdx == header->keyframesCount) {
1301 if (state->flags & IMGFX_FLAG_LOOP_ANIM) {
1302 nextKeyIdx = 0;
1303 }
1304 }
1305 }
1306 }
1307
1308 // find the current + next keyframe vertex data
1309 curKeyframe = heap_malloc(header->vtxCount * sizeof(ImgFXVtx));
1310 romStart = (u8*)((s32)imgfx_data_ROM_START + (s32) header->keyframesOffset + curKeyIdx * header->vtxCount * sizeof(ImgFXVtx));
1311 dma_copy(romStart, romStart + header->vtxCount * sizeof(ImgFXVtx), curKeyframe);
1312 if (keyframeInterval > 1) {
1313 nextKeyframe = heap_malloc(header->vtxCount * sizeof(*nextKeyframe));
1314 romStart = (u8*)((s32)imgfx_data_ROM_START + (s32) header->keyframesOffset + nextKeyIdx * header->vtxCount * sizeof(ImgFXVtx));
1315 dma_copy(romStart, romStart + header->vtxCount * sizeof(ImgFXVtx), nextKeyframe);
1316 }
1317
1319 for (i = 0; i < header->vtxCount; i++) {
1320 if (state->meshType != IMGFX_MESH_ANIMATED) {
1321 return;
1322 }
1323
1324 if (keyframeInterval > 1) {
1325 // get vertex position, interpolated between keyframes
1326 if (header->flags & IMGFX_ANIM_FLAG_ABSOLUTE_COORDS) {
1327 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[0] = (s16)(curKeyframe[i].ob[0] + (nextKeyframe[i].ob[0] - curKeyframe[i].ob[0]) * lerpAlpha);
1328 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[1] = (s16)(curKeyframe[i].ob[1] + (nextKeyframe[i].ob[1] - curKeyframe[i].ob[1]) * lerpAlpha);
1329 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[2] = (s16)(curKeyframe[i].ob[2] + (nextKeyframe[i].ob[2] - curKeyframe[i].ob[2]) * lerpAlpha);
1330 } else {
1331 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[0] = (s16)(curKeyframe[i].ob[0] + (nextKeyframe[i].ob[0] - curKeyframe[i].ob[0]) * lerpAlpha) * 0.01 * ImgFXCurrentTexturePtr->tex.width;
1332 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[1] = (s16)(curKeyframe[i].ob[1] + (nextKeyframe[i].ob[1] - curKeyframe[i].ob[1]) * lerpAlpha) * 0.01 * ImgFXCurrentTexturePtr->tex.height;
1333 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[2] = (s16)(curKeyframe[i].ob[2] + (nextKeyframe[i].ob[2] - curKeyframe[i].ob[2]) * lerpAlpha) * 0.01 * ((ImgFXCurrentTexturePtr->tex.width + ImgFXCurrentTexturePtr->tex.height) / 2);
1334 }
1335 // get vertex color
1336 if (state->flags & (IMGFX_FLAG_2000 | IMGFX_FLAG_8000)) {
1337 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[0] = (s16)(curKeyframe[i].cn[0] + (nextKeyframe[i].cn[0] - curKeyframe[i].cn[0]) * lerpAlpha);
1338 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[1] = (s16)(curKeyframe[i].cn[1] + (nextKeyframe[i].cn[1] - curKeyframe[i].cn[1]) * lerpAlpha);
1339 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[2] = (s16)(curKeyframe[i].cn[2] + (nextKeyframe[i].cn[2] - curKeyframe[i].cn[2]) * lerpAlpha);
1340 } else {
1341 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[0] =
1342 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[1] =
1343 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[2] = 240.0 - (curKeyframe[i].tc[0] + curKeyframe[i].tc[1]) * 1.2;
1344 }
1345 } else {
1346 // get vertex position
1347 if (header->flags & IMGFX_ANIM_FLAG_ABSOLUTE_COORDS) {
1348 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[0] = curKeyframe[i].ob[0];
1349 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[1] = curKeyframe[i].ob[1];
1350 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[2] = curKeyframe[i].ob[2];
1351 } else {
1352 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[0] = curKeyframe[i].ob[0] * 0.01 * ImgFXCurrentTexturePtr->tex.width;
1353 state->vtxBufs[gCurrentDisplayContextIndex][i].v.ob[1] = curKeyframe[i].ob[1] * 0.01 * ImgFXCurrentTexturePtr->tex.height;
1355 }
1356 // get vertex color
1357 if (state->flags & (IMGFX_FLAG_2000 | IMGFX_FLAG_8000)) {
1358 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[0] = curKeyframe[i].cn[0];
1359 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[1] = curKeyframe[i].cn[1];
1360 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[2] = curKeyframe[i].cn[2];
1361 } else {
1362 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[0] =
1363 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[1] =
1364 state->vtxBufs[gCurrentDisplayContextIndex][i].v.cn[2] = 240.0 - (curKeyframe[i].tc[0] + curKeyframe[i].tc[1]) * 1.2;
1365 }
1366 }
1367 // get vertex tex coords
1368 if (header->flags & IMGFX_ANIM_FLAG_ABSOLUTE_COORDS) {
1369 state->vtxBufs[gCurrentDisplayContextIndex][i].v.tc[0] = (curKeyframe[i].tc[0] + 256) * 32;
1370 state->vtxBufs[gCurrentDisplayContextIndex][i].v.tc[1] = (curKeyframe[i].tc[1] + 256) * 32;
1371 } else {
1372 state->vtxBufs[gCurrentDisplayContextIndex][i].v.tc[0] = ((s32)(curKeyframe[i].tc[0] * 0.01 * ImgFXCurrentTexturePtr->tex.width) + 256) * 32;
1373 state->vtxBufs[gCurrentDisplayContextIndex][i].v.tc[1] = ((s32)(curKeyframe[i].tc[1] * 0.01 * ImgFXCurrentTexturePtr->tex.height) + 256) * 32;
1374 }
1375 }
1376
1377 state->firstVtxIdx = 0;
1378 state->lastVtxIdx = header->vtxCount - 1;
1379
1381 if (nextKeyframe != nullptr) {
1383 }
1384
1385 if (animStep == 0 || gGameStatusPtr->frameCounter % animStep != 0) {
1386 return;
1387 }
1388
1389 if (keyframeInterval > 0) {
1390 curSubframe++;
1392 if (state->flags & IMGFX_FLAG_REVERSE_ANIM) {
1393 curKeyIdx--;
1394 if (curKeyIdx < 0) {
1395 if (state->flags & IMGFX_FLAG_LOOP_ANIM) {
1396 curKeyIdx = header->keyframesCount - 1;
1397 } else {
1398 if (state->flags & IMGFX_FLAG_800) {
1399 curKeyIdx = 0;
1400 state->flags |= IMGFX_FLAG_4000;
1401 } else {
1402 state->flags |= IMGFX_FLAG_ANIM_DONE;
1403 }
1404 }
1405 }
1406 } else {
1407 curKeyIdx++;
1408 if (curKeyIdx >= header->keyframesCount) {
1409 if (state->flags & IMGFX_FLAG_LOOP_ANIM) {
1410 curKeyIdx = 0;
1411 } else {
1412 if (state->flags & IMGFX_FLAG_800) {
1413 curKeyIdx--;
1414 state->flags |= IMGFX_FLAG_4000;
1415 } else {
1416 state->flags |= IMGFX_FLAG_ANIM_DONE;
1417 }
1418 }
1419 }
1420 }
1421 curSubframe = 0;
1422 }
1423 } else if (keyframeInterval < 0) {
1424 if (state->flags & IMGFX_FLAG_REVERSE_ANIM) {
1426 if (curKeyIdx < 0) {
1427 if (state->flags & IMGFX_FLAG_LOOP_ANIM) {
1428 curKeyIdx += header->keyframesCount;
1429 } else {
1430 if (state->flags & IMGFX_FLAG_800) {
1431 curKeyIdx = 0;
1432 state->flags |= IMGFX_FLAG_4000;
1433 } else {
1434 state->flags |= IMGFX_FLAG_ANIM_DONE;
1435 }
1436 }
1437 }
1438 } else {
1440 if (curKeyIdx >= header->keyframesCount) {
1441 if (state->flags & IMGFX_FLAG_LOOP_ANIM) {
1442 curKeyIdx %= header->keyframesCount;
1443 } else {
1444 if (state->flags & IMGFX_FLAG_800) {
1445 curKeyIdx = header->keyframesCount - 1;
1446 state->flags |= IMGFX_FLAG_4000;
1447 } else {
1448 state->flags |= IMGFX_FLAG_ANIM_DONE;
1449 }
1450 }
1451 }
1452 }
1453 }
1454
1455 state->floats.anim.curFrame = curSubframe;
1456 state->floats.anim.curIdx = curKeyIdx;
1457}
@ IMGFX_FLAG_ANIM_DONE
Definition enums.h:4690
@ IMGFX_FLAG_LOOP_ANIM
Definition enums.h:4685
@ IMGFX_FLAG_REVERSE_ANIM
Definition enums.h:4686
@ IMGFX_FLAG_200
Definition enums.h:4687
@ IMGFX_FLAG_800
Definition enums.h:4689
@ IMGFX_FLAG_4000
Definition enums.h:4692
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
Definition 43F0.c:442
s32 heap_free(void *ptr)
Definition heap.c:42
void * heap_malloc(s32 size)
Definition heap.c:34
ImgFXAnimHeader * imgfx_load_anim(ImgFXState *state)
Definition imgfx.c:1193
struct ImgFXIntVars::@200 anim
struct ImgFXFloatVars::@205 anim
u16 keyframesCount
Definition imgfx.h:19
ImgFXVtx * keyframesOffset
Definition imgfx.h:15
GameStatus * gGameStatusPtr
Definition main_loop.c:31
s32 gCurrentDisplayContextIndex
Definition main_loop.c:46

Referenced by imgfx_make_mesh().

◆ imgfx_appendGfx_mesh_basic()

void imgfx_appendGfx_mesh_basic ( ImgFXState * state,
Matrix4f mtx )

Definition at line 1459 of file imgfx.c.

1459 {
1460 s32 i;
1461
1462 if (!(state->flags & IMGFX_FLAG_SKIP_TEX_SETUP)) {
1465 }
1466
1467 i = state->firstVtxIdx;
1468
1469 while (true) {
1470 Camera* cam;
1471 s32 uls = (imgfx_vtxBuf[i + 0].v.tc[0] >> 0x5) - 256;
1472 s32 ult = (imgfx_vtxBuf[i + 0].v.tc[1] >> 0x5) - 256;
1473 s32 lrs = (imgfx_vtxBuf[i + 3].v.tc[0] >> 0x5) - 256;
1474 s32 lrt = (imgfx_vtxBuf[i + 3].v.tc[1] >> 0x5) - 256;
1476 s32 alpha;
1477 s32 alpha2;
1478
1479 if (!(state->flags & IMGFX_FLAG_SKIP_TEX_SETUP)) {
1481 && (state->arrayIdx != 0)
1482 && (state->flags & someFlags)
1483 && ( state->renderType == IMGFX_RENDER_DEFAULT
1487 ) {
1491 uls, ult, // top left
1492 lrs - 1, lrt - 1, // bottom right
1493 0, // palette
1494 G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, // clamp wrap mirror
1495 8, 8, // mask
1496 G_TX_NOLOD, G_TX_NOLOD, // shift,
1497 0x100, 0x100); // scroll
1501 gDPSetTileSize(gMainGfxPos++, 2, 0, 0, 252, 0);
1502
1503 alpha = 255;
1504 switch (state->renderType) {
1506 break;
1509 alpha = state->ints.color.a;
1510 break;
1512 alpha = -1;
1513 break;
1514 default:
1515 printf("imgfx: unhandled render type %d for shading palette\n", state->renderType);
1516 break;
1517 }
1518
1520 && ((*ImgFXInstances)[0].arrayIdx != 0)
1521 && (state->flags & someFlags)
1522 ) {
1524
1527 } else {
1528 gSPViewport(gMainGfxPos++, &cam->vpAlt);
1529 }
1530
1532
1533 if (alpha == -1) {
1535 } else {
1536 gDPSetEnvColor(gMainGfxPos++, 0, 0, 0, alpha);
1538 }
1539
1540 gSPVertex(gMainGfxPos++, &imgfx_vtxBuf[i], 4, 0);
1541 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 1, 2, 3, 0);
1543 }
1544 create_shading_palette(mtx, uls, ult, lrs, lrt, alpha, state->otherModeL);
1545 } else {
1549 uls, ult, // top left
1550 lrs - 1, lrt - 1, // bottom right
1551 0, // palette
1552 G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, // clamp wrap mirror
1553 8, 8, // mask
1554 G_TX_NOLOD, G_TX_NOLOD, // shift,
1555 0x100, 0x100); // scroll
1556
1558 && state->arrayIdx != 0
1559 && (state->flags & someFlags)
1560 ) {
1561 alpha2 = 255;
1563
1566 } else {
1567 gSPViewport(gMainGfxPos++, &cam->vpAlt);
1568 }
1569
1570 if (alpha2 == 255) {
1572 } else {
1574 }
1575
1576 switch (state->renderType) {
1578 alpha2 = 255;
1579 break;
1582 alpha2 = state->ints.color.a;
1583 break;
1585 alpha2 = -1;
1586 break;
1587 default:
1588 printf("imgfx: unhandled render type %d for shading palette\n", state->renderType);
1589 break;
1590 }
1591
1592 if (alpha2 == -1) {
1594 } else {
1595 gDPSetEnvColor(gMainGfxPos++, 0, 0, 0, alpha2);
1597 }
1598
1599 gSPVertex(gMainGfxPos++, &imgfx_vtxBuf[i], 4, 0);
1600 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 1, 2, 3, 0);
1602
1603 if (alpha2 == 255) {
1605 } else {
1607 }
1608
1609 gDPSetEnvColor(gMainGfxPos++, 100, 100, 100, 255);
1610 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, alpha2);
1613 }
1614 }
1615 }
1616
1618 && (*ImgFXInstances)[0].arrayIdx != 0
1619 && (state->flags & someFlags)
1620 ) {
1624 D_8014EE50.vp.vtrans[0] = D_8014EE40.vp.vtrans[0] + gGameStatusPtr->altViewportOffset.x;
1625 D_8014EE50.vp.vtrans[1] = D_8014EE40.vp.vtrans[1] + gGameStatusPtr->altViewportOffset.y;
1626 } else {
1627 gSPViewport(gMainGfxPos++, &cam->vp);
1628 }
1629 }
1630
1631 gSPVertex(gMainGfxPos++, &imgfx_vtxBuf[i], 4, 0);
1632 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 1, 2, 3, 0);
1633
1634 if (i + 3 >= state->lastVtxIdx) {
1635 break;
1636 }
1637
1638 i += 2;
1639 }
1640}
Vec2b altViewportOffset
@ SPR_SHADING_FLAG_SET_VIEWPORT
Definition enums.h:4793
@ SPR_SHADING_FLAG_ENABLED
Definition enums.h:4792
@ CONTEXT_PAUSE
Definition enums.h:3564
@ IMGFX_FLAG_SKIP_TEX_SETUP
Definition enums.h:4683
@ IMGFX_FLAG_100000
Definition enums.h:4698
@ IMGFX_FLAG_80000
Definition enums.h:4697
#define gDPScrollMultiTile2_4b(pkt, timg, fmt, width, height, uls, ult, lrs, lrt, pal, cms, cmt, masks, maskt, shifts, shiftt, scrolls, scrollt)
Definition gbi_custom.h:6
#define gDPScrollTextureTile_4b(pkt, timg, fmt, width, height, uls, ult, lrs, lrt, pal, cms, cmt, masks, maskt, shifts, shiftt, scrolls, scrollt)
Definition gbi_custom.h:39
Vp D_8014EE40
Definition imgfx.c:129
BSS ImgFXInstanceList * ImgFXInstances
Definition imgfx.c:118
Vp D_8014EE50
Definition imgfx.c:136
u8 arrayIdx
Definition imgfx.c:68
int printf(const char *restrict fmt,...)
Definition is_debug.c:25
#define PM_CC_0A
Definition macros.h:297
#define PM_CC_59
Definition macros.h:511
#define PM_CC_0C
Definition macros.h:301
#define PM_CC_0B
Definition macros.h:299
#define PM_CC_5A
Definition macros.h:512
#define PM_CC_0D
Definition macros.h:300
void create_shading_palette(Matrix4f mtx, s32 uls, s32 ult, s32 lrs, s32 lrt, s32 alpha, s32)
SpriteShadingProfile * gSpriteShadingProfile
s16 gCurrentCamID
Definition cam_main.c:12

Referenced by imgfx_appendGfx_mesh().

◆ imgfx_appendGfx_mesh_grid()

void imgfx_appendGfx_mesh_grid ( ImgFXState * state,
Matrix4f mtx )

Definition at line 1642 of file imgfx.c.

1642 {
1643 s32 i, j;
1644 s32 firstVtxIdx;
1645
1646 if (!(state->flags & IMGFX_FLAG_SKIP_TEX_SETUP)) {
1649 }
1650
1651 firstVtxIdx = state->firstVtxIdx;
1652 for (i = 0; i < state->subdivY; i++) {
1653 for (j = 0; j < state->subdivX; j++) {
1654 s32 ulIdx = firstVtxIdx + i * (state->subdivX + 1) + j;
1655 s32 urIdx = firstVtxIdx + i * (state->subdivX + 1) + j + 1;
1656 s32 llIdx = firstVtxIdx + (i + 1) * (state->subdivX + 1) + j;
1657 s32 lrIdx = firstVtxIdx + (i + 1) * (state->subdivX + 1) + j + 1;
1658 if (!(state->flags & IMGFX_FLAG_SKIP_TEX_SETUP)) {
1660 && (*ImgFXInstances)[0].arrayIdx != 0
1661 && (state->flags & (IMGFX_FLAG_100000 | IMGFX_FLAG_80000))
1662 && (state->renderType == IMGFX_RENDER_DEFAULT
1665 ) {
1666 s32 alpha = 255;
1670 (imgfx_vtxBuf[ulIdx].v.tc[0] >> 5) - 0x100, (imgfx_vtxBuf[ulIdx].v.tc[1] >> 5) - 0x100, // top left
1671 (imgfx_vtxBuf[lrIdx].v.tc[0] >> 5) - 0x100 - 1, (imgfx_vtxBuf[lrIdx].v.tc[1] >> 5) - 0x100 - 1, // bottom right
1672 0, // palette
1673 G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, // clamp wrap mirror
1674 8, 8, // mask
1675 G_TX_NOLOD, G_TX_NOLOD, // shift,
1676 0x100, 0x100); // scroll
1678 gDPSetTileSize(gMainGfxPos++, 2, 0, 0, 63 << 2, 0);
1679 switch (state->renderType) {
1681 alpha = 255;
1682 break;
1684 alpha = state->ints.color.a;
1685 break;
1687 alpha = -1;
1688 break;
1689 default:
1690 printf("imgfx: unhandled render type %d for shading palette\n", state->renderType);
1691 break;
1692 }
1694 (imgfx_vtxBuf[ulIdx].v.tc[0] >> 5) - 0x100, (imgfx_vtxBuf[ulIdx].v.tc[1] >> 5) - 0x100,
1695 (imgfx_vtxBuf[lrIdx].v.tc[0] >> 5) - 0x100, (imgfx_vtxBuf[lrIdx].v.tc[1] >> 5) - 0x100,
1696 alpha, state->otherModeL);
1697 } else {
1701 (imgfx_vtxBuf[ulIdx].v.tc[0] >> 5) - 0x100, (imgfx_vtxBuf[ulIdx].v.tc[1] >> 5) - 0x100, // top left
1702 (imgfx_vtxBuf[lrIdx].v.tc[0] >> 5) - 0x100 - 1, (imgfx_vtxBuf[lrIdx].v.tc[1] >> 5) - 0x100 - 1, // bottom right
1703 0, // palette
1704 G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, // clamp wrap mirror
1705 8, 8, // mask
1706 G_TX_NOLOD, G_TX_NOLOD, // shift,
1707 0x100, 0x100); // scroll
1708 }
1709 }
1710
1715 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 1, 2, 3, 0);
1716 }
1717 }
1718}

Referenced by imgfx_appendGfx_mesh().

◆ imgfx_appendGfx_mesh_anim()

void imgfx_appendGfx_mesh_anim ( ImgFXState * state,
Matrix4f mtx )

Definition at line 1720 of file imgfx.c.

1720 {
1721 if (state->vtxBufs[gCurrentDisplayContextIndex] == nullptr || state->gfxBufs[gCurrentDisplayContextIndex] == nullptr) {
1722 return;
1723 }
1724
1725 guScale(&gDisplayContext->matrixStack[gMatrixListPos], 0.1f, 0.1f, 0.1f);
1727
1728 if (!(state->flags & IMGFX_FLAG_SKIP_TEX_SETUP)) {
1732 && (state->flags & (IMGFX_FLAG_100000 | IMGFX_FLAG_80000))
1733 && (state->renderType == IMGFX_RENDER_DEFAULT
1736 || state->renderType == IMGFX_RENDER_ANIM)
1737 ) {
1738 s32 alpha = 255;
1743 256, 256);
1744 gDPSetTile(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0x0100, 2, 0,
1746 gDPSetTileSize(gMainGfxPos++, 2, 0, 0, 252, 0);
1747
1748 switch (state->renderType) {
1750 case IMGFX_RENDER_ANIM:
1751 alpha = 255;
1752 break;
1754 alpha = state->ints.color.a;
1755 break;
1757 alpha = -1;
1758 break;
1759 default: // unreachable due to above `if`
1760 printf("imgfx: unhandled render type %d for shading palette\n", state->renderType);
1761 break;
1762 }
1764 } else {
1769 256, 256);
1770 }
1771 }
1774}
Mtx matrixStack[0x200]
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:46
u16 gMatrixListPos
Definition main_loop.c:44
DisplayContext * gDisplayContext
Definition cam_main.c:15

Referenced by imgfx_appendGfx_mesh().

◆ imgfx_appendGfx_mesh_strip()

void imgfx_appendGfx_mesh_strip ( ImgFXState * state,
Matrix4f mtx )

Definition at line 1776 of file imgfx.c.

1776 {
1777 ImgFXOverlayTexture* ufs = state->ints.overlay.pattern;
1778 s32 shifts = integer_log(ufs->width, 2);
1779 s32 shiftt = integer_log(ufs->height, 2);
1780 s32 uls, ult;
1781 s32 lrs, lrt;
1782
1786
1787 if (state->renderType == IMGFX_RENDER_OVERLAY_RGBA) {
1788 s32 alpha = state->ints.overlay.alpha;
1789 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, alpha);
1791 } else {
1793 }
1795 gDPLoadTLUT_pal16(gMainGfxPos++, 0, ufs->palette);
1796 gDPScrollTextureTile_4b(gMainGfxPos++, ufs->raster, G_IM_FMT_CI, ufs->width, ufs->height,
1797 0, 0, ufs->width - 1, ufs->height - 1, 0,
1799 256, 256);
1800
1801 uls = state->floats.overlay.posX;
1802 ult = state->floats.overlay.posY;
1803 lrs = ufs->width * 4 + state->floats.overlay.posX;
1804 lrt = ufs->height * 4 + state->floats.overlay.posY;
1806
1807 state->floats.overlay.posX = (s32)(state->floats.overlay.posX + ufs->offsetX) % (ufs->width * 4);
1808 state->floats.overlay.posY = (s32)(state->floats.overlay.posY + ufs->offsetY) % (ufs->height * 4);
1809 gSPDisplayList(gMainGfxPos++, ufs->displayList);
1811}
s32 integer_log(s32 number, u32 base)
struct ImgFXFloatVars::@207 overlay
#define PM_CC_05
Definition macros.h:292

Referenced by imgfx_appendGfx_mesh().

◆ imgfx_wavy_init()

void imgfx_wavy_init ( ImgFXState * state)

Definition at line 1813 of file imgfx.c.

1813 {
1814 state->floats.wavy.phase1 = 0.0f;
1815 state->floats.wavy.phase2 = 50.0f;
1816 state->floats.wavy.phase3 = 30.0f;
1817}
struct ImgFXFloatVars::@206 wavy

Referenced by imgfx_update().

◆ imgfx_mesh_make_wavy()

void imgfx_mesh_make_wavy ( ImgFXState * state)

Definition at line 1819 of file imgfx.c.

1819 {
1820 Vtx* v1;
1821 Vtx* v2;
1822 Vtx* v3;
1823 f32 vx;
1824 f32 vy;
1825 f32 vz;
1826 f32 angle1;
1827 f32 angle2;
1828 f32 angle3;
1829 f32 phase1;
1830 f32 phase2;
1831 f32 phase3;
1832 s32 angleInc;
1833 s32 amt;
1834 s32 sign;
1835 s32 i;
1836
1837 phase1 = (f32) gGameStatusPtr->frameCounter / 10.3;
1838 while (phase1 > 360.0) {
1839 phase1 -= 360.0;
1840 }
1841
1842 phase2 = (f32) (gGameStatusPtr->frameCounter + 40) / 11.2;
1843 while (phase2 > 360.0) {
1844 phase2 -= 360.0;
1845 }
1846
1847 phase3 = (f32) (gGameStatusPtr->frameCounter + 25) / 10.8;
1848 while (phase3 > 360.0) {
1849 phase3 -= 360.0;
1850 }
1851
1852 state->floats.wavy.phase1 = phase1;
1853 state->floats.wavy.phase2 = phase2;
1854 state->floats.wavy.phase3 = phase3;
1855
1856 if (state->floats.wavy.phase1 >= 360.0) {
1857 state->floats.wavy.phase1-= 360.0;
1858 }
1859
1860 if (state->floats.wavy.phase2 >= 360.0) {
1861 state->floats.wavy.phase2 -= 360.0;
1862 }
1863
1864 if (state->floats.wavy.phase3 >= 360.0) {
1865 state->floats.wavy.phase3 -= 360.0;
1866 }
1867
1868 sign = 0;
1869 angleInc = 0;
1870 amt = (state->lastVtxIdx - state->firstVtxIdx) - state->subdivX;
1871
1872 for (i = 0; i < amt; i++) {
1873 angle1 = state->floats.wavy.phase1 + (angleInc * 45) + (sign * 180);
1874 angle2 = state->floats.wavy.phase2 + (angleInc * 45) + (sign * 180);
1875 angle3 = state->floats.wavy.phase3 + (angleInc * 45) + (sign * 180);
1876
1877 //TODO find better match
1878 v1 = (Vtx*)((state->firstVtxIdx + i) * sizeof(Vtx) + (s32)imgfx_vtxBuf);
1879 vx = v1->v.ob[0];
1880 v1->v.ob[0] = (vx + (sin_deg(angle1) * state->ints.wavy.mag.x));
1881
1882 v2 = (Vtx*)((state->firstVtxIdx + i) * sizeof(Vtx) + (s32)imgfx_vtxBuf);
1883 vy = v2->v.ob[1];
1884 v2->v.ob[1] = (vy + (sin_deg(angle2) * state->ints.wavy.mag.y));
1885
1886 v3 = (Vtx*)((state->firstVtxIdx + i) * sizeof(Vtx) + (s32)imgfx_vtxBuf);
1887 vz = v3->v.ob[2];
1888 v3->v.ob[2] = (vz + (sin_deg(angle3) * state->ints.wavy.mag.z));
1889
1890 angleInc++;
1891 if (i % (state->subdivX + 1) == 0) {
1892 angleInc = 0;
1893 sign = !sign;
1894 }
1895 }
1896}
#define sin_deg
s32 sign(s32 value)
Definition 43F0.c:374
struct ImgFXIntVars::@201 wavy

Referenced by imgfx_make_mesh().

◆ imgfx_mesh_load_colors()

void imgfx_mesh_load_colors ( ImgFXState * state)

Definition at line 1898 of file imgfx.c.

1898 {
1900 s32 vtxCount = state->lastVtxIdx - state->firstVtxIdx;
1901 s32 i;
1902
1903 for (i = 0; i <= vtxCount; i++) {
1904 imgfx_vtxBuf[state->firstVtxIdx + i].v.cn[0] = state->colorBuf[i].r;
1905 imgfx_vtxBuf[state->firstVtxIdx + i].v.cn[1] = state->colorBuf[i].g;
1906 imgfx_vtxBuf[state->firstVtxIdx + i].v.cn[2] = state->colorBuf[i].b;
1907 imgfx_vtxBuf[state->firstVtxIdx + i].v.cn[3] = state->colorBuf[i].a * alpha;
1908 }
1909}

Referenced by imgfx_make_mesh().

◆ imgfx_set_vtx_buf_capacity()

void imgfx_set_vtx_buf_capacity ( s16 arg0)

Definition at line 238 of file imgfx.c.

238 {
240}
u16 ImgFXVtxBufferCapacity
Definition imgfx.c:143

◆ imgfx_init()

void imgfx_init ( void )

Definition at line 242 of file imgfx.c.

242 {
243 s32 i;
244
245 for (i = 0; i < ARRAY_COUNT(ImgFXVtxBuffers); i++) {
247 }
248
250
251 for (i = 0; i < ARRAY_COUNT(*ImgFXInstances); i++) {
254 }
255
256 for (i = 0; i < ARRAY_COUNT(ImgFXDataCache); i++) {
257 ImgFXDataCache[i].data = nullptr;
260 }
261
262 imgfx_vtxCount = 0;
264}
void * _heap_malloc(HeapNode *head, u32 size)
Definition 43F0.c:77
ImgFXState ImgFXInstanceList[MAX_IMGFX_INSTANCES]
Definition imgfx.c:111
void imgfx_clear_instance_data(ImgFXState *state)
Definition imgfx.c:442
BSS Vtx * ImgFXVtxBuffers[2]
Definition imgfx.c:116
u8 usingContextualHeap
Definition imgfx.c:97
s32 * data
Definition imgfx.c:95
HeapNode heap_spriteHead
Definition heaps3.c:4
void imgfx_init_instance(ImgFXState *state)
Definition imgfx.c:452
BSS ImgFXCacheEntry ImgFXDataCache[8]
Definition imgfx.c:120
u8 staleCooldownTimer
Definition imgfx.c:96

Referenced by spr_init_sprites().

◆ func_8013A4D0()

void func_8013A4D0 ( void )

Definition at line 266 of file imgfx.c.

266 {
267 s32 i;
268
270 imgfx_vtxCount = 0;
272
273 (*ImgFXInstances)[0].flags |= IMGFX_FLAG_VALID;
274
275 for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) {
276 if (((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID) && (*ImgFXInstances)[i].lastAnimCmd != IMGFX_SET_ANIM) {
278 }
279 }
280
281 for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) {
282 if (((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID) && (*ImgFXInstances)[i].colorBuf != nullptr) {
283 if ((*ImgFXInstances)[i].lastColorCmd == IMGFX_COLOR_BUF_SET_MULTIPLY) {
284 continue;
285 }
286 if ((*ImgFXInstances)[i].lastColorCmd == IMGFX_COLOR_BUF_SET_MODULATE) {
287 continue;
288 }
289 general_heap_free((*ImgFXInstances)[i].colorBuf);
290 (*ImgFXInstances)[i].colorBuf = nullptr;
291 (*ImgFXInstances)[i].colorBufCount = 0;
292 }
293 }
294}
s8 flags
Definition demo_api.c:15
@ IMGFX_SET_ANIM
Definition enums.h:4707
@ IMGFX_FLAG_VALID
Definition enums.h:4678
s32 general_heap_free(void *data)
Definition heap.c:18
void imgfx_cache_instance_data(ImgFXState *state)
Definition imgfx.c:420

Referenced by spr_update_player_raster_cache().

◆ imgfx_add_to_cache()

void imgfx_add_to_cache ( void * data,
s8 usingContextualHeap )

Definition at line 296 of file imgfx.c.

296 {
297 s32 i;
298
299 for (i = 0; i < ARRAY_COUNT(ImgFXDataCache); i++) {
300 if (ImgFXDataCache[i].data == nullptr) {
301 ImgFXDataCache[i].data = data;
303 ImgFXDataCache[i].usingContextualHeap = usingContextualHeap;
304 return;
305 }
306 }
307}

Referenced by imgfx_cache_instance_data(), and imgfx_load_anim().

◆ imgfx_update_cache_impl()

void imgfx_update_cache_impl ( void )

Definition at line 309 of file imgfx.c.

309 {
310 s32 i;
311
312 for (i = 0; i < ARRAY_COUNT(ImgFXDataCache); i++) {
313 if (ImgFXDataCache[i].data != nullptr) {
315
316 if (ImgFXDataCache[i].staleCooldownTimer == 0) {
317 if (ImgFXDataCache[i].usingContextualHeap) {
318 heap_free(ImgFXDataCache[i].data);
319 ImgFXDataCache[i].data = nullptr;
320 } else {
322 ImgFXDataCache[i].data = nullptr;
323 }
324
327 }
328 }
329 }
330}

Referenced by imgfx_update_cache().

◆ imgfx_update_cache()

void imgfx_update_cache ( void )

Definition at line 332 of file imgfx.c.

332 {
334}
void imgfx_update_cache_impl(void)
Definition imgfx.c:309

Referenced by state_drawUI_world().

◆ imgfx_get_free_instances()

s32 imgfx_get_free_instances ( s32 count)

Definition at line 337 of file imgfx.c.

337 {
340 s32 iPrev;
342 s32 i;
343
344 numAssigned = 0;
345 for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) {
346 if (!((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID)) {
347 numAssigned++;
348 }
349 }
350
351 if (numAssigned < count) {
352 return -1;
353 }
354
355 firstIdx = 0;
356 foundAny = false;
357 numAssigned = 0;
358 iPrev = -1;
359 for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) {
360 if ((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID) {
361 continue;
362 }
363
364 if (!foundAny) {
365 firstIdx = i;
366 foundAny = true;
367 } else {
368 (*ImgFXInstances)[iPrev].nextIdx = i;
369 }
370
371 (*ImgFXInstances)[i].arrayIdx = i;
373 numAssigned++;
374 (*ImgFXInstances)[i].flags |= IMGFX_FLAG_VALID;
375 iPrev = i;
376 if (numAssigned == count) {
377 (*ImgFXInstances)[i].nextIdx = -1;
378 break;
379 }
380 }
381
382 return firstIdx;
383}

Referenced by hud_element_create_transform_A(), spr_load_npc_sprite(), and spr_update_player_sprite().

◆ imgfx_release_instance()

void imgfx_release_instance ( u32 idx)

Definition at line 385 of file imgfx.c.

385 {
386 if (idx < MAX_IMGFX_INSTANCES) {
387 (*ImgFXInstances)[idx].flags = 0;
388 (*ImgFXInstances)[idx].nextIdx = -1;
389 }
390}
#define MAX_IMGFX_INSTANCES
Definition macros.h:97

Referenced by hud_element_free_transform(), imgfx_release_instance_chain(), and spr_free_sprite().

◆ imgfx_release_instance_chain()

void imgfx_release_instance_chain ( u32 idx)

Definition at line 392 of file imgfx.c.

392 {
393 if (idx < MAX_IMGFX_INSTANCES) {
394 s32 next;
395
396 do {
397 next = (*ImgFXInstances)[idx].nextIdx;
399 idx = next;
400 } while (next != -1);
401 }
402}
void imgfx_release_instance(u32 idx)
Definition imgfx.c:385

◆ imgfx_get_next_instance()

s32 imgfx_get_next_instance ( s32 idx)

Definition at line 404 of file imgfx.c.

404 {
406 return -1;
407 }
408
409 if (idx >= MAX_IMGFX_INSTANCES) {
410 return 0xFF;
411 } else {
412 return (*ImgFXInstances)[idx].nextIdx;
413 }
414}

◆ imgfx_get_instance()

ImgFXState * imgfx_get_instance ( s32 idx)

Definition at line 416 of file imgfx.c.

416 {
417 return &(*ImgFXInstances)[idx];
418}

◆ imgfx_update()

void imgfx_update ( u32 idx,
ImgFXType type,
s32 imgfxArg1,
s32 imgfxArg2,
s32 imgfxArg3,
s32 imgfxArg4,
s32 flags )

Definition at line 486 of file imgfx.c.

486 {
487 ImgFXState* state = &(*ImgFXInstances)[idx];
489 u8 r, g, b, a;
490
491 if (!(state->flags & IMGFX_FLAG_VALID) || (idx >= MAX_IMGFX_INSTANCES)) {
492 return;
493 }
494
495 switch (type) {
496 case IMGFX_CLEAR:
497 case IMGFX_RESET:
498 oldFlags = state->flags;
500 imgfx_init_instance(state);
501 state->flags = oldFlags;
502 state->lastAnimCmd = IMGFX_CLEAR;
503 state->lastColorCmd = IMGFX_CLEAR;
506 state->ints.raw[0][0] = -1;
507 state->ints.raw[1][0] = -1;
508
509 state->flags &= IMGFX_FLAG_VALID;
510 if (flags != 0) {
511 state->flags |= flags;
512 } else {
513 state->flags |= 0; // required to match
514 }
515 return;
516 case IMGFX_UNK_1:
517 state->lastAnimCmd = IMGFX_CLEAR;
519 state->ints.raw[0][0] = -1;
520 return;
521 case IMGFX_UNK_2:
522 state->lastColorCmd = IMGFX_CLEAR;
524 state->ints.raw[1][0] = -1;
525 return;
527 if (state->colorBuf != nullptr) {
528 heap_free(state->colorBuf);
529 }
530 state->colorBufCount = imgfxArg1 * 4;
531 state->colorBuf = heap_malloc(state->colorBufCount);
532 return;
533 case IMGFX_OVERLAY:
535 if (type == state->lastColorCmd
536 && imgfxArg1 == (s32) state->ints.overlay.pattern
537 && imgfxArg2 == state->ints.overlay.alpha
538 ) {
539 // no paramaters have changed
540 return;
541 }
542 break;
543 case IMGFX_SET_ANIM:
544 if (state->lastAnimCmd == type
545 && state->ints.anim.type == imgfxArg1
546 && state->ints.anim.interval == imgfxArg2
547 && state->ints.anim.step == imgfxArg3
548 ) {
549 // no paramaters have changed
550 return;
551 }
552 break;
553 default:
554 if (type != IMGFX_HOLOGRAM && state->lastColorCmd == IMGFX_HOLOGRAM) {
556 state->subdivX = 1;
557 state->subdivY = 1;
558 }
559 break;
560 }
561
562 if (type != IMGFX_SET_ANIM && state->lastAnimCmd == IMGFX_SET_ANIM) {
563 state->lastAnimCmd = IMGFX_CLEAR;
564 }
565
566 if (type == IMGFX_SET_WAVY || type == IMGFX_SET_ANIM) {
567 state->lastAnimCmd = type;
568 state->ints.args.anim[0] = imgfxArg1;
569 state->ints.args.anim[1] = imgfxArg2;
570 state->ints.args.anim[2] = imgfxArg3;
571 state->ints.args.anim[3] = imgfxArg4;
572 } else if (type >= IMGFX_SET_COLOR && type <= IMGFX_OVERLAY_XLU) {
573 state->lastColorCmd = type;
574 state->ints.args.color[0] = imgfxArg1;
575 state->ints.args.color[1] = imgfxArg2;
576 state->ints.args.color[2] = imgfxArg3;
577 state->ints.args.color[3] = imgfxArg4;
578 }
579
580 state->flags &= IMGFX_FLAG_VALID;
581 if (flags != 0) {
582 state->flags |= flags;
583 }
585
586 switch (type) {
587 case IMGFX_RESET:
590 break;
591 case IMGFX_SET_WAVY:
592 state->subdivX = 4;
593 state->subdivY = 4;
595 imgfx_wavy_init(state);
596 break;
597 case IMGFX_SET_ANIM:
600 state->floats.anim.curFrame = 0.0f;
601 state->floats.anim.curIdx = 0.0f;
602 state->flags |= IMGFX_FLAG_200;
603 break;
604 case IMGFX_SET_COLOR:
605 case IMGFX_SET_ALPHA:
606 case IMGFX_SET_TINT:
607 if (imgfxArg1 >= 255 && imgfxArg2 >= 255 && imgfxArg3 >= 255 && imgfxArg4 >= 255) {
608 // no color + no transparency
610 } else if (imgfxArg4 >= 255) {
611 // some color + no transparency
613 } else if (imgfxArg1 >= 255 && imgfxArg2 >= 255 && imgfxArg3 >= 255) {
614 // no color + transparency
616 } else {
617 // some color + transparency
619 }
620 break;
623 if (imgfxArg4 == 255.0) {
625 } else {
627 }
628 break;
630 if (imgfxArg1 < state->colorBufCount) {
631 // unpack and store color
632 r = (imgfxArg2 & 0xFF000000) >> 24;
633 g = (imgfxArg2 & 0xFF0000) >> 16;
634 b = (imgfxArg2 & 0xFF00) >> 8;
635 a = (imgfxArg2 & 0xFF);
636 state->colorBuf[imgfxArg1].r = r;
637 state->colorBuf[imgfxArg1].g = g;
638 state->colorBuf[imgfxArg1].b = b;
639 state->colorBuf[imgfxArg1].a = a;
640
642
643 if (a == 255) {
645 } else {
647 }
648 }
649 break;
651 if (imgfxArg1 < state->colorBufCount) {
652 // unpack and store color
653 r = (imgfxArg2 & 0xFF000000) >> 24;
654 g = (imgfxArg2 & 0xFF0000) >> 16;
655 b = (imgfxArg2 & 0xFF00) >> 8;
656 a = (imgfxArg2 & 0xFF);
657 state->colorBuf[imgfxArg1].r = r;
658 state->colorBuf[imgfxArg1].g = g;
659 state->colorBuf[imgfxArg1].b = b;
660 state->colorBuf[imgfxArg1].a = a;
661
663
664 if (a == 255) {
666 } else {
668 }
669 }
670 break;
671 case IMGFX_HOLOGRAM:
673 break;
674 case IMGFX_FILL_COLOR:
676 break;
677 case IMGFX_OVERLAY:
679 state->meshType = IMGFX_MESH_STRIP;
680 if (imgfxArg2 >= 255) {
682 } else {
684 }
685 state->floats.overlay.posX = 0.0f;
686 state->floats.overlay.posY = 0.0f;
687 break;
688 case IMGFX_CLEAR:
689 break;
690 default:
691 break;
692 }
693}
@ IMGFX_SET_ALPHA
Definition enums.h:4709
@ IMGFX_RESET
Definition enums.h:4705
@ IMGFX_HOLOGRAM
Definition enums.h:4715
@ IMGFX_SET_COLOR
Definition enums.h:4708
@ IMGFX_OVERLAY_XLU
Definition enums.h:4718
@ IMGFX_OVERLAY
Definition enums.h:4717
@ IMGFX_ALLOC_COLOR_BUF
Definition enums.h:4719
@ IMGFX_FILL_COLOR
Definition enums.h:4716
@ IMGFX_SET_CREDITS_FADE
Definition enums.h:4712
@ IMGFX_SET_TINT
Definition enums.h:4710
@ IMGFX_SET_WHITE_FADE
Definition enums.h:4711
@ IMGFX_UNK_2
Definition enums.h:4704
@ IMGFX_UNK_1
Definition enums.h:4703
void imgfx_wavy_init(ImgFXState *state)
Definition imgfx.c:1813
struct ImgFXIntVars::@199 args

Referenced by appendGfx_interact_prompt(), appendGfx_ispy_icon(), appendGfx_speech_bubble(), render_complex_hud_element(), set_npc_imgfx_comp(), and set_player_imgfx_comp().

◆ imgfx_set_state_flags()

void imgfx_set_state_flags ( s32 idx,
u16 flagBits,
s32 mode )

Definition at line 695 of file imgfx.c.

695 {
697 if (mode) {
698 (*ImgFXInstances)[idx].flags |= flagBits;
699 } else {
700 (*ImgFXInstances)[idx].flags &= ~flagBits;
701 }
702 }
703}

◆ imgfx_appendGfx_component()

s32 imgfx_appendGfx_component ( s32 idx,
ImgFXTexture * ifxImg,
u32 flagBits,
Matrix4f mtx )

Definition at line 705 of file imgfx.c.

705 {
706 ImgFXState* state = &(*ImgFXInstances)[idx];
707 s32 ret = 0;
708
709 if (ifxImg->alpha == 0) {
710 return 0;
711 }
712
713 state->arrayIdx = idx;
714 state->flags |= flagBits;
724
726 return 0;
727 }
728
729 if (idx >= MAX_IMGFX_INSTANCES || state == nullptr) {
730 return 0;
731 }
732
733 imgfx_make_mesh(state);
734 imgfx_appendGfx_mesh(state, mtx);
735
736 if (state->flags & IMGFX_FLAG_ANIM_DONE) {
737 state->ints.raw[0][0] = -1;
738 state->ints.raw[1][0] = -1;
739 state->lastAnimCmd = IMGFX_CLEAR;
740 state->meshType = 0;
744 ret = 1;
745 } else if (state->flags & IMGFX_FLAG_4000) {
746 ret = 2;
747 } else if (state->flags & IMGFX_FLAG_20000) {
748 state->lastAnimCmd = IMGFX_CLEAR;
749 state->lastColorCmd = IMGFX_CLEAR;
752 state->ints.raw[0][0] = -1;
753 state->ints.raw[1][0] = -1;
754 state->flags &= IMGFX_FLAG_VALID;
755 ret = 1;
756 }
757 return ret;
758}
@ IMGFX_FLAG_20000
Definition enums.h:4695
void imgfx_appendGfx_mesh(ImgFXState *state, Matrix4f mtx)
Definition imgfx.c:799
void imgfx_make_mesh(ImgFXState *state)
Definition imgfx.c:760

Referenced by appendGfx_entity_model(), appendGfx_interact_prompt(), appendGfx_ispy_icon(), appendGfx_pulse_stone_icon(), appendGfx_speech_bubble(), draw_coin_sparkles(), draw_entity_model_E(), gfx_build_knocked_down_player(), render_complex_hud_element(), and spr_appendGfx_component().

◆ imgfx_load_anim()

ImgFXAnimHeader * imgfx_load_anim ( ImgFXState * state)

Definition at line 1193 of file imgfx.c.

1193 {
1194 u8* romStart = (s32) ImgFXAnimOffsets[state->ints.anim.type] + imgfx_data_ROM_START;
1195 ImgFXAnimHeader* anim = &ImgFXAnimHeaders[state->arrayIdx];
1196
1197 if (state->curAnimOffset != romStart) {
1198 u8* romEnd;
1199 s32 i;
1200
1201 state->curAnimOffset = romStart;
1202
1203 dma_copy(state->curAnimOffset, state->curAnimOffset + sizeof(*anim), anim);
1204
1205 if (state->vtxBufs[0] != nullptr) {
1206 imgfx_add_to_cache(state->vtxBufs[0], 1);
1207 state->vtxBufs[0] = nullptr;
1208 }
1209 if (state->vtxBufs[1] != nullptr) {
1210 imgfx_add_to_cache(state->vtxBufs[1], 1);
1211 state->vtxBufs[1] = nullptr;
1212 }
1213 if (state->gfxBufs[0] != nullptr) {
1214 imgfx_add_to_cache(state->gfxBufs[0], 1);
1215 state->gfxBufs[0] = nullptr;
1216 }
1217 if (state->gfxBufs[1] != nullptr) {
1218 // imgfx_add_to_cache(state->gfxBufs[1], 1);
1219 romEnd = (u8*) state->gfxBufs[1]; // required to match
1220 imgfx_add_to_cache(state->gfxBufs[1], 1);
1221 state->gfxBufs[1] = nullptr;
1222 }
1223 state->vtxBufs[0] = heap_malloc(anim->vtxCount * sizeof(Vtx));
1224 state->vtxBufs[1] = heap_malloc(anim->vtxCount * sizeof(Vtx));
1225 state->gfxBufs[0] = heap_malloc(anim->gfxCount * sizeof(Gfx));
1226 state->gfxBufs[1] = heap_malloc(anim->gfxCount * sizeof(Gfx));
1227
1228 romStart = imgfx_data_ROM_START + (s32)anim->gfxOffset;
1229 romEnd = romStart + anim->gfxCount * sizeof(Gfx);
1230 dma_copy(romStart, romEnd, state->gfxBufs[0]);
1231 dma_copy(romStart, romEnd, state->gfxBufs[1]);
1232
1233 // Search through the state's displaylists for vertex commands
1234 // and adjust their addresses to point into the vertex buffers
1235 for (i = 0; i < ARRAY_COUNT(state->gfxBufs); i++) {
1236 Gfx* gfxBuffer = state->gfxBufs[i];
1237 s32 j = 0;
1238 u32 cmd;
1239
1240 // Loop over the displaylist commands until we hit an ENDDL
1241 do {
1242 u32 w0 = gfxBuffer[j++].words.w0;
1243 cmd = w0 >> 0x18;
1244
1245 // If this command is a vertex command, adjust the vertex buffer address
1246 if (cmd == G_VTX) {
1247 // ImgFXVtx structs are 0xC bytes while Vtx are 0x10, so we need a (4/3) scaling factor
1248 // to compute a new, equivalent Vtx[i] address for an existing ImgFXVtx[i] address.
1249 // Unfortunately, using sizeof here does not match.
1250 gfxBuffer[j-1].words.w1 = ((((s32) gfxBuffer[j-1].words.w1 - (s32) anim->keyframesOffset) / 3) * 4) +
1251 (s32) state->vtxBufs[i];
1252 }
1253 } while (cmd != G_ENDDL);
1254 }
1255 }
1256
1257 return anim;
1258}
BSS ImgFXAnimHeader ImgFXAnimHeaders[MAX_IMGFX_INSTANCES]
Definition imgfx.c:119
u8 * ImgFXAnimOffsets[]
Definition imgfx.c:198
Gfx * gfxOffset
Definition imgfx.h:16

Referenced by imgfx_mesh_anim_update().

Variable Documentation

◆ heap_spriteHead

HeapNode heap_spriteHead
extern

Definition at line 4 of file heaps3.c.

Referenced by imgfx_init().

◆ ImgFXCurrentTexture

BSS ImgFXWorkingTexture ImgFXCurrentTexture

Definition at line 115 of file imgfx.c.

◆ ImgFXVtxBuffers

BSS Vtx* ImgFXVtxBuffers[2]

Definition at line 116 of file imgfx.c.

Referenced by func_8013A4D0(), and imgfx_init().

◆ imgfx_vtxBuf

◆ ImgFXInstances

◆ ImgFXAnimHeaders

Definition at line 119 of file imgfx.c.

Referenced by imgfx_load_anim().

◆ ImgFXDataCache

BSS ImgFXCacheEntry ImgFXDataCache[8]

Definition at line 120 of file imgfx.c.

Referenced by imgfx_add_to_cache(), imgfx_init(), and imgfx_update_cache_impl().

◆ ImgFXCurrentTexturePtr

◆ imgfx_vtxCount

u16 imgfx_vtxCount = 0

Definition at line 125 of file imgfx.c.

Referenced by func_8013A4D0(), imgfx_init(), imgfx_mesh_make_grid(), and imgfx_mesh_make_strip().

◆ ImgFXLights

Lights2 ImgFXLights = gdSPDefLights2(144, 144, 144, 255, 255, 255, 0, 0, 120, 255, 255, 255, 0, 0, 136)

Definition at line 127 of file imgfx.c.

Referenced by imgfx_appendGfx_mesh().

◆ D_8014EE40

Vp D_8014EE40
Initial value:
= {
.vp = {
.vscale = { 640, 480, 511, 0 },
.vtrans = { 640, 480, 511, 0 },
}
}

Definition at line 129 of file imgfx.c.

129 {
130 .vp = {
131 .vscale = { 640, 480, 511, 0 },
132 .vtrans = { 640, 480, 511, 0 },
133 }
134};

Referenced by imgfx_appendGfx_mesh_basic().

◆ D_8014EE50

Vp D_8014EE50
Initial value:
= {
.vp = {
.vscale = { 640, 480, 511, 0 },
.vtrans = { 640, 480, 512, 0 },
}
}

Definition at line 136 of file imgfx.c.

136 {
137 .vp = {
138 .vscale = { 640, 480, 511, 0 },
139 .vtrans = { 640, 480, 512, 0 },
140 }
141};

Referenced by imgfx_appendGfx_mesh_basic().

◆ ImgFXVtxBufferCapacity

u16 ImgFXVtxBufferCapacity = 300

Definition at line 143 of file imgfx.c.

Referenced by imgfx_init(), and imgfx_set_vtx_buf_capacity().

◆ DefaultImgFXSetupGfx

◆ ImgFXRenderModes

ImgFXRenderMode ImgFXRenderModes[]
Initial value:
= {
[IMGFX_RENDER_DEFAULT] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_MULTIPLY_RGB] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_MODULATE_PRIM_RGB] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_MULTIPLY_SHADE_RGB] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_MODULATE_SHADE_RGB] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_ANIM] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_HOLOGRAM] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
[IMGFX_RENDER_COLOR_FILL] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_OVERLAY_RGB] { 0x00441208, 0x00111208, 0 },
[IMGFX_RENDER_OVERLAY_RGBA] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
[IMGFX_RENDER_UNUSED] { 0x00441208, 0x00111208, 0 },
}

Definition at line 156 of file imgfx.c.

156 {
157 [IMGFX_RENDER_DEFAULT] { 0x00441208, 0x00111208, 0 },
158 [IMGFX_RENDER_MULTIPLY_RGB] { 0x00441208, 0x00111208, 0 },
159 [IMGFX_RENDER_MULTIPLY_ALPHA] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
160 [IMGFX_RENDER_MULTIPLY_RGBA] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
161 [IMGFX_RENDER_MODULATE_PRIM_RGB] { 0x00441208, 0x00111208, 0 },
162 [IMGFX_RENDER_MODULATE_PRIM_RGBA] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
163 [IMGFX_RENDER_MULTIPLY_SHADE_RGB] { 0x00441208, 0x00111208, 0 },
166 [IMGFX_RENDER_MODULATE_SHADE_RGB] { 0x00441208, 0x00111208, 0 },
168 [IMGFX_RENDER_ANIM] { 0x00441208, 0x00111208, 0 },
169 [IMGFX_RENDER_HOLOGRAM] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
170 [IMGFX_RENDER_COLOR_FILL] { 0x00441208, 0x00111208, 0 },
171 [IMGFX_RENDER_OVERLAY_RGB] { 0x00441208, 0x00111208, 0 },
172 [IMGFX_RENDER_OVERLAY_RGBA] { 0x00404B40, 0x00104B40, IMGFX_RENDER_NO_OVERRIDE },
173 [IMGFX_RENDER_UNUSED] { 0x00441208, 0x00111208, 0 },
174};

Referenced by imgfx_appendGfx_mesh().

◆ shock_header

Addr shock_header
extern

◆ shiver_header

Addr shiver_header
extern

◆ vertical_pipe_curl_header

Addr vertical_pipe_curl_header
extern

◆ horizontal_pipe_curl_header

Addr horizontal_pipe_curl_header
extern

◆ startle_header

Addr startle_header
extern

◆ flutter_down_header

Addr flutter_down_header
extern

◆ unfurl_header

Addr unfurl_header
extern

◆ get_in_bed_header

Addr get_in_bed_header
extern

◆ spirit_capture_header

Addr spirit_capture_header
extern

◆ unused_1_header

Addr unused_1_header
extern

◆ unused_2_header

Addr unused_2_header
extern

◆ unused_3_header

Addr unused_3_header
extern

◆ tutankoopa_gather_header

Addr tutankoopa_gather_header
extern

◆ tutankoopa_swirl_2_header

Addr tutankoopa_swirl_2_header
extern

◆ tutankoopa_swirl_1_header

Addr tutankoopa_swirl_1_header
extern

◆ shuffle_cards_header

Addr shuffle_cards_header
extern

◆ flip_card_1_header

Addr flip_card_1_header
extern

◆ flip_card_2_header

Addr flip_card_2_header
extern

◆ flip_card_3_header

Addr flip_card_3_header
extern

◆ cymbal_crush_header

Addr cymbal_crush_header
extern

◆ ImgFXAnimOffsets

u8* ImgFXAnimOffsets[]
Initial value:
= {
}
@ IMGFX_ANIM_VERTICAL_PIPE_CURL
Definition enums.h:4725
@ IMGFX_ANIM_HORIZONTAL_PIPE_CURL
Definition enums.h:4726
@ IMGFX_ANIM_SHIVER
Definition enums.h:4724
@ IMGFX_ANIM_FLIP_CARD_1
Definition enums.h:4739
@ IMGFX_ANIM_FLUTTER_DOWN
Definition enums.h:4728
@ IMGFX_ANIM_SHUFFLE_CARDS
Definition enums.h:4738
@ IMGFX_ANIM_STARTLE
Definition enums.h:4727
@ IMGFX_ANIM_SPIRIT_CAPTURE
Definition enums.h:4731
@ IMGFX_ANIM_UNUSED_2
Definition enums.h:4733
@ IMGFX_ANIM_FLIP_CARD_2
Definition enums.h:4740
@ IMGFX_ANIM_UNUSED_1
Definition enums.h:4732
@ IMGFX_ANIM_TUTANKOOPA_SWIRL_1
Definition enums.h:4737
@ IMGFX_ANIM_FLIP_CARD_3
Definition enums.h:4741
@ IMGFX_ANIM_TUTANKOOPA_SWIRL_2
Definition enums.h:4736
@ IMGFX_ANIM_UNFURL
Definition enums.h:4729
@ IMGFX_ANIM_CYMBAL_CRUSH
Definition enums.h:4742
@ IMGFX_ANIM_SHOCK
Definition enums.h:4723
@ IMGFX_ANIM_TUTANKOOPA_GATHER
Definition enums.h:4735
@ IMGFX_ANIM_UNUSED_3
Definition enums.h:4734
@ IMGFX_ANIM_GET_IN_BED
Definition enums.h:4730
Addr startle_header
Addr unfurl_header
Addr vertical_pipe_curl_header
Addr shuffle_cards_header
Addr unused_2_header
Addr flip_card_2_header
Addr horizontal_pipe_curl_header
Addr flip_card_1_header
Addr shiver_header
Addr tutankoopa_gather_header
Addr unused_3_header
Addr get_in_bed_header
Addr unused_1_header
Addr flutter_down_header
Addr flip_card_3_header
Addr tutankoopa_swirl_2_header
Addr shock_header
Addr cymbal_crush_header
Addr tutankoopa_swirl_1_header
Addr spirit_capture_header

Definition at line 198 of file imgfx.c.

Referenced by imgfx_load_anim().