From 978f1ab88a5cd2d30994352b03c79f0b215b71df Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 14 May 2022 13:22:21 -0700 Subject: [PATCH] CTextRenderBuffer Implement image rendering --- Runtime/GuiSys/CGuiTextPane.cpp | 2 +- Runtime/GuiSys/CRasterFont.cpp | 2 +- Runtime/GuiSys/CTextRenderBuffer.cpp | 42 +++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Runtime/GuiSys/CGuiTextPane.cpp b/Runtime/GuiSys/CGuiTextPane.cpp index 1126adb08..39c11ecc4 100644 --- a/Runtime/GuiSys/CGuiTextPane.cpp +++ b/Runtime/GuiSys/CGuiTextPane.cpp @@ -23,7 +23,7 @@ bool testProjectedLine(const zeus::CVector2f& a, const zeus::CVector2f& b, const } } // Anonymous namespace -bool CGuiTextPane::sDrawPaneRects = true; +bool CGuiTextPane::sDrawPaneRects = false; CGuiTextPane::CGuiTextPane(const CGuiWidgetParms& parms, CSimplePool* sp, const zeus::CVector2f& dim, const zeus::CVector3f& vec, CAssetId fontId, const CGuiTextProperties& props, const zeus::CColor& fontCol, const zeus::CColor& outlineCol, s32 extentX, s32 extentY, diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index dddd9b007..6a494e148 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -216,7 +216,7 @@ void CRasterFont::SetupRenderState() { {GX::VA_NULL, GX::NONE} }; - x80_texture->Load(GX::TEXMAP0, EClampMode::Clamp); + //x80_texture->Load(GX::TEXMAP0, EClampMode::Clamp); CGX::SetTevKAlphaSel(GX::TEVSTAGE0, GX::TEV_KASEL_K0_A); CGX::SetTevKColorSel(GX::TEVSTAGE0, GX::TEV_KCSEL_K0); CGX::SetTevColorIn(GX::TEVSTAGE0, GX::CC_ZERO, GX::CC_TEXC, GX::CC_KONST, GX::CC_ZERO); diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 6b5980624..ff4c76f73 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -102,6 +102,11 @@ u32 CTextRenderBuffer::GetCurLen() { } void CTextRenderBuffer::Render(const zeus::CColor& color, float time) { + static const GX::VtxDescList skVtxDesc[3]{ + {GX::VA_POS, GX::DIRECT}, + {GX::VA_TEX0, GX::DIRECT}, + {GX::VA_NULL, GX::NONE}, + }; x4c_activeFont = -1; x4d_activePalette = -1; CMemoryInStream in(x34_bytecode.data(), x44_blobSize); @@ -150,7 +155,42 @@ void CTextRenderBuffer::Render(const zeus::CColor& color, float time) { u16 offY = in.ReadShort(); u8 imageIdx = in.ReadChar(); zeus::CColor imageColor(static_cast(in.ReadLong())); - // TODO: Finish + auto imageDef = x14_images[imageIdx]; + auto tex = imageDef.x4_texs[static_cast(time * imageDef.x0_fps) % imageDef.x4_texs.size()]; + if (tex) { + tex->Load(GX::TEXMAP0, EClampMode::Clamp); + float width = imageDef.x4_texs.front()->GetWidth() * imageDef.x14_cropFactor.x(); + float height = imageDef.x4_texs.front()->GetHeight() * imageDef.x14_cropFactor.y(); + float cropXHalf = imageDef.x14_cropFactor.x() * 0.5f; + float cropYHalf = imageDef.x14_cropFactor.y() * 0.5f; + + CGX::SetTevKAlphaSel(GX::TEVSTAGE0, GX::TEV_KASEL_K0_A); + CGX::SetTevKColorSel(GX::TEVSTAGE0, GX::TEV_KCSEL_K0); + CGX::SetTevColorIn(GX::TEVSTAGE0, GX::CC_ZERO, GX::CC_TEXC, GX::CC_KONST, GX::CC_ZERO); + CGX::SetTevAlphaIn(GX::TEVSTAGE0, GX::CA_ZERO, GX::CA_TEXA, GX::CA_KONST, GX::CA_ZERO); + CGX::SetStandardTevColorAlphaOp(GX::TEVSTAGE0); + CGX::SetVtxDescv(skVtxDesc); + CGX::SetNumChans(0); + CGX::SetNumTexGens(1); + CGX::SetNumTevStages(1); + CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD0, GX::TEXMAP0, GX::COLOR_NULL); + CGX::SetTexCoordGen(GX::TEXCOORD0, GX::TG_MTX2x4, GX::TG_TEX0, GX::IDENTITY, false, GX::PTIDENTITY); + CGX::SetTevKColor(GX::KCOLOR0, imageColor * color); + CGX::Begin(GX::TRIANGLESTRIP, GX::VTXFMT0, 4); + { + GXPosition3f32(offX, 0.f, offY); + GXTexCoord2f32(0.5f - cropXHalf, 0.5f + cropYHalf); + GXPosition3f32(offX + width, 0.f, offY); + GXTexCoord2f32(0.5f + cropXHalf, 0.5f + cropYHalf); + GXPosition3f32(offX, 0.f, offY + height); + GXTexCoord2f32(0.5f - cropXHalf, 0.5f - cropYHalf); + GXPosition3f32(offX + width, 0.f, offY + height); + GXTexCoord2f32(0.5f + cropXHalf, 0.5f - cropYHalf); + } + CGX::End(); + x4e_queuedFont = x4c_activeFont; + x4f_queuedPalette = x4d_activePalette; + } } else if (cmd == Command::PaletteChange) { x4d_activePalette = x4f_queuedPalette = in.ReadChar(); }