|
| 1 | +#include <nw4r/g3d.h> |
| 2 | + |
| 3 | +#include <libkiwi.h> |
| 4 | + |
| 5 | +namespace nw4r { |
| 6 | +namespace g3d { |
| 7 | + |
| 8 | +/****************************************************************************** |
| 9 | + * |
| 10 | + * ResTev |
| 11 | + * |
| 12 | + ******************************************************************************/ |
| 13 | +void ResTev::GXSetTevColorIn(GXTevStageID stage, GXTevColorArg a, |
| 14 | + GXTevColorArg b, GXTevColorArg c, |
| 15 | + GXTevColorArg d) { |
| 16 | + |
| 17 | + u8* pCmd = ref() |
| 18 | + .dl.dl.var[stage / TEV_STAGES_PER_DL] |
| 19 | + .dl.tevColorCalc[stage % TEV_STAGES_PER_DL]; |
| 20 | + |
| 21 | + // clang-format off |
| 22 | + detail::ResWriteBPCmd(pCmd, |
| 23 | + (d << GX_BP_TEVCOLORCOMBINER_D_SHIFT) | |
| 24 | + (c << GX_BP_TEVCOLORCOMBINER_C_SHIFT) | |
| 25 | + (b << GX_BP_TEVCOLORCOMBINER_B_SHIFT) | |
| 26 | + (a << GX_BP_TEVCOLORCOMBINER_A_SHIFT) | |
| 27 | + ((GX_BP_REG_TEVCOLORCOMBINER0 + stage * 2) |
| 28 | + << GX_BP_OPCODE_SHIFT), |
| 29 | + |
| 30 | + ~(GX_BP_TEVCOLORCOMBINER_DEST_MASK | |
| 31 | + GX_BP_TEVCOLORCOMBINER_SCALE_OR_COMPARE_MODE_MASK | |
| 32 | + GX_BP_TEVCOLORCOMBINER_CLAMP_MASK | |
| 33 | + GX_BP_TEVCOLORCOMBINER_OP_OR_COMPARISON_MASK | |
| 34 | + GX_BP_TEVCOLORCOMBINER_BIAS_MASK)); |
| 35 | + // clang-format on |
| 36 | +} |
| 37 | + |
| 38 | +void ResTev::GXSetTevColorOp(GXTevStageID stage, GXTevOp op, GXTevBias bias, |
| 39 | + GXTevScale scale, GXBool clamp, |
| 40 | + GXTevRegID output) { |
| 41 | + |
| 42 | + u8* pCmd = ref() |
| 43 | + .dl.dl.var[stage / TEV_STAGES_PER_DL] |
| 44 | + .dl.tevColorCalc[stage % TEV_STAGES_PER_DL]; |
| 45 | + |
| 46 | + // Operation |
| 47 | + if (op <= GX_TEV_SUB) { |
| 48 | + // clang-format off |
| 49 | + detail::ResWriteBPCmd(pCmd, |
| 50 | + (bias << GX_BP_TEVCOLORCOMBINER_BIAS_SHIFT) | |
| 51 | + ((op & 1) << GX_BP_TEVCOLORCOMBINER_OP_OR_COMPARISON_SHIFT) | |
| 52 | + (clamp << GX_BP_TEVCOLORCOMBINER_CLAMP_SHIFT) | |
| 53 | + (scale << GX_BP_TEVCOLORCOMBINER_SCALE_OR_COMPARE_MODE_SHIFT) | |
| 54 | + (output << GX_BP_TEVCOLORCOMBINER_DEST_SHIFT) | |
| 55 | + ((GX_BP_REG_TEVCOLORCOMBINER0 + stage * 2) |
| 56 | + << GX_BP_OPCODE_SHIFT), |
| 57 | + |
| 58 | + ~(GX_BP_TEVCOLORCOMBINER_D_MASK | |
| 59 | + GX_BP_TEVCOLORCOMBINER_C_MASK | |
| 60 | + GX_BP_TEVCOLORCOMBINER_B_MASK | |
| 61 | + GX_BP_TEVCOLORCOMBINER_A_MASK)); |
| 62 | + // clang-format on |
| 63 | + } |
| 64 | + // Compare |
| 65 | + else { |
| 66 | + // clang-format off |
| 67 | + detail::ResWriteBPCmd(pCmd, |
| 68 | + ((op & 1) << GX_BP_TEVCOLORCOMBINER_OP_OR_COMPARISON_SHIFT) | |
| 69 | + (GX_MAX_TEVBIAS << GX_BP_TEVCOLORCOMBINER_BIAS_SHIFT) | |
| 70 | + (clamp << GX_BP_TEVCOLORCOMBINER_CLAMP_SHIFT) | |
| 71 | + ((op >> 1 & 3) << GX_BP_TEVCOLORCOMBINER_SCALE_OR_COMPARE_MODE_SHIFT) | |
| 72 | + (output << GX_BP_TEVCOLORCOMBINER_DEST_SHIFT) | |
| 73 | + ((GX_BP_REG_TEVCOLORCOMBINER0 + stage * 2) |
| 74 | + << GX_BP_OPCODE_SHIFT), |
| 75 | + |
| 76 | + // op CONST clamp op output |
| 77 | + |
| 78 | + ~(GX_BP_TEVCOLORCOMBINER_D_MASK | |
| 79 | + GX_BP_TEVCOLORCOMBINER_C_MASK | |
| 80 | + GX_BP_TEVCOLORCOMBINER_B_MASK | |
| 81 | + GX_BP_TEVCOLORCOMBINER_A_MASK)); |
| 82 | + // clang-format on |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +/****************************************************************************** |
| 87 | + * |
| 88 | + * CopiedMatAccess |
| 89 | + * |
| 90 | + ******************************************************************************/ |
| 91 | +ResGenMode ScnMdl::CopiedMatAccess::GetResGenMode(bool markDirty) { |
| 92 | + if (mpScnMdl != NULL && mGenMode.IsValid()) { |
| 93 | + if (markDirty) { |
| 94 | + mpScnMdl->MatBufferDirty(mMatID, ScnMdl::BUFFER_RESGENMODE); |
| 95 | + } |
| 96 | + |
| 97 | + return mGenMode; |
| 98 | + } |
| 99 | + |
| 100 | + return ResGenMode(NULL); |
| 101 | +} |
| 102 | + |
| 103 | +ResMatTevColor ScnMdl::CopiedMatAccess::GetResMatTevColor(bool markDirty) { |
| 104 | + if (mpScnMdl != NULL && mTevColor.IsValid()) { |
| 105 | + if (markDirty) { |
| 106 | + mpScnMdl->MatBufferDirty(mMatID, ScnMdl::BUFFER_RESTEVCOLOR); |
| 107 | + } |
| 108 | + |
| 109 | + return mTevColor; |
| 110 | + } |
| 111 | + |
| 112 | + return ResMatTevColor(NULL); |
| 113 | +} |
| 114 | + |
| 115 | +ResTev ScnMdl::CopiedMatAccess::GetResTev(bool markDirty) { |
| 116 | + if (mpScnMdl != NULL && mTev.IsValid()) { |
| 117 | + if (markDirty) { |
| 118 | + mpScnMdl->MatBufferDirty(mMatID, ScnMdl::BUFFER_RESTEV); |
| 119 | + } |
| 120 | + |
| 121 | + return mTev; |
| 122 | + } |
| 123 | + |
| 124 | + return ResTev(NULL); |
| 125 | +} |
| 126 | + |
| 127 | +} // namespace g3d |
| 128 | +} // namespace nw4r |
0 commit comments