Enable some draw call merging in text rendering

Don't set state between characters if possible.

Next step is page merging so it can do full lines of text at once.
This commit is contained in:
PJB3005
2026-04-13 13:27:21 +02:00
parent b5b0913739
commit 0a95a9e538
5 changed files with 89 additions and 25 deletions
+47 -19
View File
@@ -231,14 +231,14 @@ void JUTResFont::setGX(JUtility::TColor col1, JUtility::TColor col2) {
}
f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, int str_int,
bool flag) {
bool flag FONT_DRAW_CTX) {
f32 x1;
f32 x2;
f32 y1;
JUT_ASSERT(378, mValid);
JUTFont::TWidth width;
loadFont(str_int, GX_TEXMAP0, &width);
loadFont(str_int, GX_TEXMAP0, &width FONT_DRAW_CTX_ARG);
if ((mFixed) || (!flag)) {
x1 = pos_x;
@@ -266,7 +266,13 @@ f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, i
s32 u2 = ((mWidth + cellW) * 0x8000) / texW;
s32 v2 = ((mHeight + cellH) * 0x8000) / texH;
#if TARGET_PC
if (!context) {
pushDrawState();
}
#else
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
#endif
GXBegin(GX_QUADS, GX_VTXFMT0, 4);
// Bottom Left
@@ -290,18 +296,33 @@ f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, i
GXTexCoord2u16(u1, v2);
GXEnd();
#if TARGET_PC
if (!context) {
popDrawState();
}
#else
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
#endif
return retval;
}
void JUTResFont::loadFont(int code, GXTexMapID texMapID, JUTFont::TWidth* pDstWidth) {
#if TARGET_PC
void JUTResFont::pushDrawState() {
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
}
void JUTResFont::popDrawState() {
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
}
#endif
void JUTResFont::loadFont(int code, GXTexMapID texMapID, JUTFont::TWidth* pDstWidth FONT_DRAW_CTX) {
if (pDstWidth != 0) {
getWidthEntry(code, pDstWidth);
}
int fontCode = getFontCode(code);
loadImage(fontCode, texMapID);
loadImage(fontCode, texMapID FONT_DRAW_CTX_ARG);
}
void JUTResFont::getWidthEntry(int code, JUTFont::TWidth* i_width) const {
@@ -403,7 +424,7 @@ int JUTResFont::getFontCode(int chr) const {
return ret;
}
void JUTResFont::loadImage(int code, GXTexMapID id){
void JUTResFont::loadImage(int code, GXTexMapID id FONT_DRAW_CTX){
int i = 0;
for (; i < mGly1BlockNum; i++)
{
@@ -435,22 +456,29 @@ void JUTResFont::loadImage(int code, GXTexMapID id){
mHeight = cellRow * cellH;
#if TARGET_PC
const auto found = mGlyphTextures->textures.find(pageIdx);
GXTexObj* texObj;
if (found == mGlyphTextures->textures.end()) {
texObj = &mGlyphTextures->textures[pageIdx];
void* pImg = &mpGlyphBlocks[i]->data[pageIdx * mpGlyphBlocks[i]->textureSize];
GXInitTexObj(texObj, pImg, mpGlyphBlocks[i]->textureWidth,
mpGlyphBlocks[i]->textureHeight, (GXTexFmt)(u16)mpGlyphBlocks[i]->textureFormat,
GX_CLAMP, GX_CLAMP, 0);
if (!context || context->loadedPage != pageIdx || context->loadedBlock != i) {
const auto found = mGlyphTextures->textures.find(pageIdx);
GXTexObj* texObj;
if (found == mGlyphTextures->textures.end()) {
texObj = &mGlyphTextures->textures[pageIdx];
void* pImg = &mpGlyphBlocks[i]->data[pageIdx * mpGlyphBlocks[i]->textureSize];
GXInitTexObj(texObj, pImg, mpGlyphBlocks[i]->textureWidth,
mpGlyphBlocks[i]->textureHeight, (GXTexFmt)(u16)mpGlyphBlocks[i]->textureFormat,
GX_CLAMP, GX_CLAMP, 0);
GXInitTexObjLOD(texObj, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, 0U, 0U, GX_ANISO_1);
} else {
texObj = &found->second;
GXInitTexObjLOD(texObj, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, 0U, 0U, GX_ANISO_1);
} else {
texObj = &found->second;
}
GXLoadTexObj(texObj, id);
if (context) {
context->loadedBlock = i;
context->loadedPage = pageIdx;
}
}
GXLoadTexObj(texObj, id);
// Gets used by some other code.
mTexPageIdx = pageIdx;
field_0x66 = i;