diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index 87815ab9ff..85053ad322 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -666,7 +666,7 @@ void FFont::SetDefaultTranslation(uint32_t *othercolors) } } } - Ranges[CR_UNTRANSLATED] = remap; + Translations[CR_UNTRANSLATED] = remap.StoreTranslation(TRANSLATION_Font); forceremap = true; } @@ -769,7 +769,7 @@ int FFont::SimpleTranslation (uint32_t *colorsused, uint8_t *translation, uint8_ //========================================================================== void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity, - const void *ranges, int total_colors, const PalEntry *palette) + const void *ranges, int total_colors, const PalEntry *palette, std::function post) { int i, j; const TranslationParm *parmstart = (const TranslationParm *)ranges; @@ -777,32 +777,32 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity FRemapTable remap(total_colors); // Create different translations for different color ranges - Ranges.Clear(); + Translations.Clear(); for (i = 0; i < NumTextColors; i++) { if (i == CR_UNTRANSLATED) { if (identity != nullptr) { - memcpy (remap.Remap, identity, ActiveColors); + memcpy(remap.Remap, identity, ActiveColors); if (palette != nullptr) { - memcpy (remap.Palette, palette, ActiveColors*sizeof(PalEntry)); + memcpy(remap.Palette, palette, ActiveColors * sizeof(PalEntry)); } else { - remap.Palette[0] = GPalette.BaseColors[identity[0]] & MAKEARGB(0,255,255,255); + remap.Palette[0] = GPalette.BaseColors[identity[0]] & MAKEARGB(0, 255, 255, 255); for (j = 1; j < ActiveColors; ++j) { - remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255,0,0,0); + remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255, 0, 0, 0); } } + Translations.Push(remap.StoreTranslation(TRANSLATION_Font)); } else { - remap = Ranges[0]; + Translations.Push(Translations[0]); } - Ranges.Push(remap); continue; } @@ -836,7 +836,8 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity remap.Remap[j] = ColorMatcher.Pick(r, g, b); remap.Palette[j] = PalEntry(255,r,g,b); } - Ranges.Push(remap); + if (post) post(&remap); + Translations.Push(remap.StoreTranslation(TRANSLATION_Font)); // Advance to the next color range. while (parmstart[1].RangeStart > parmstart[0].RangeEnd) @@ -853,7 +854,7 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity // //========================================================================== -FRemapTable *FFont::GetColorTranslation (EColorRange range, PalEntry *color) const +int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const { if (noTranslate) { @@ -866,11 +867,11 @@ FRemapTable *FFont::GetColorTranslation (EColorRange range, PalEntry *color) con if (color != nullptr) *color = retcolor; } if (ActiveColors == 0) - return nullptr; + return -1; else if (range >= NumTextColors) range = CR_UNTRANSLATED; //if (range == CR_UNTRANSLATED && !translateUntranslated) return nullptr; - return &Ranges[range]; + return Translations[range]; } //========================================================================== diff --git a/src/gamedata/fonts/hexfont.cpp b/src/gamedata/fonts/hexfont.cpp index e579829282..fde86bc3d9 100644 --- a/src/gamedata/fonts/hexfont.cpp +++ b/src/gamedata/fonts/hexfont.cpp @@ -417,7 +417,7 @@ public: } } } - Ranges[CR_UNTRANSLATED] = remap; + Translations[CR_UNTRANSLATED] = remap.StoreTranslation(TRANSLATION_Font); forceremap = true; } diff --git a/src/gamedata/fonts/specialfont.cpp b/src/gamedata/fonts/specialfont.cpp index 8bac60fe2d..6231db07e4 100644 --- a/src/gamedata/fonts/specialfont.cpp +++ b/src/gamedata/fonts/specialfont.cpp @@ -160,7 +160,7 @@ void FSpecialFont::LoadTranslations() uint8_t identity[256]; TArray Luminosity; int TotalColors; - int i, j; + int i; for (i = 0; i < count; i++) { @@ -199,22 +199,20 @@ void FSpecialFont::LoadTranslations() static_cast(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap); } - BuildTranslations (Luminosity.Data(), identity, &TranslationParms[0][0], TotalColors, nullptr); - - // add the untranslated colors to the Ranges tables - if (ActiveColors < TotalColors) - { - for (i = 0; i < NumTextColors; i++) + BuildTranslations(Luminosity.Data(), identity, &TranslationParms[0][0], TotalColors, nullptr, [=](FRemapTable* remap) { - FRemapTable *remap = &Ranges[i]; - for (j = ActiveColors; j < TotalColors; ++j) + // add the untranslated colors to the Ranges tables + if (ActiveColors < TotalColors) { - remap->Remap[j] = identity[j]; - remap->Palette[j] = GPalette.BaseColors[identity[j]]; - remap->Palette[j].a = 0xff; + for (int j = ActiveColors; j < TotalColors; ++j) + { + remap->Remap[j] = identity[j]; + remap->Palette[j] = GPalette.BaseColors[identity[j]]; + remap->Palette[j].a = 0xff; + } } - } - } + }); + ActiveColors = TotalColors; } diff --git a/src/gamedata/fonts/v_font.h b/src/gamedata/fonts/v_font.h index 67c7318d4e..e97a5ebc49 100644 --- a/src/gamedata/fonts/v_font.h +++ b/src/gamedata/fonts/v_font.h @@ -39,8 +39,8 @@ #include "vectors.h" class DCanvas; -struct FRemapTable; class FTexture; +struct FRemapTable; enum EColorRange : int { @@ -98,7 +98,7 @@ public: virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; virtual int GetCharWidth (int code) const; - FRemapTable *GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const; + int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const; int GetLump() const { return Lump; } int GetSpaceWidth () const { return SpaceWidth; } int GetHeight () const { return FontHeight; } @@ -137,7 +137,7 @@ protected: FFont (int lump); void BuildTranslations (const double *luminosity, const uint8_t *identity, - const void *ranges, int total_colors, const PalEntry *palette); + const void *ranges, int total_colors, const PalEntry *palette, std::function post = nullptr); void FixXMoves(); static int SimpleTranslation (uint32_t *colorsused, uint8_t *translation, @@ -166,7 +166,7 @@ protected: }; TArray Chars; int ActiveColors; - TArray Ranges; + TArray Translations; uint8_t PatchRemap[256]; int Lump; diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index e536e38826..2db8457489 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -370,7 +370,6 @@ void DIntermissionScreenText::Drawer () int w; size_t count; int c; - const FRemapTable *range; const uint8_t *ch = (const uint8_t*)mText.GetChars(); // Count number of rows in this text. Since it does not word-wrap, we just count @@ -424,7 +423,6 @@ void DIntermissionScreenText::Drawer () // draw some of the text onto the screen count = (mTicker - mTextDelay) / mTextSpeed; - range = font->GetColorTranslation (mTextColor); for ( ; count > 0 ; count-- ) { diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index bf0d386464..7f57e680d1 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -19,6 +19,7 @@ enum TRANSLATION_Blood, TRANSLATION_RainPillar, TRANSLATION_Custom, + TRANSLATION_Font, NUM_TRANSLATION_TABLES }; diff --git a/src/rendering/2d/v_2ddrawer.cpp b/src/rendering/2d/v_2ddrawer.cpp index f36ee05c41..beec887459 100644 --- a/src/rendering/2d/v_2ddrawer.cpp +++ b/src/rendering/2d/v_2ddrawer.cpp @@ -393,12 +393,12 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) dg.mTexture = img; if (img->isWarped()) dg.mFlags |= DTF_Wrap; - dg.mTranslation = 0; + dg.mTranslationId = 0; SetStyle(img, parms, vertexcolor, dg); - if (!img->isHardwareCanvas() && parms.remap != nullptr && !parms.remap->Inactive) + if (!img->isHardwareCanvas() && parms.TranslationId != -1) { - dg.mTranslation = parms.remap; + dg.mTranslationId = parms.TranslationId; } u1 = parms.srcx; v1 = parms.srcy; @@ -472,11 +472,11 @@ void F2DDrawer::AddShape( FTexture *img, DShape2D *shape, DrawParms &parms ) dg.mFlags |= DTF_Wrap; dg.mTexture = img; - dg.mTranslation = 0; + dg.mTranslationId = 0; SetStyle(img, parms, vertexcolor, dg); - if (!img->isHardwareCanvas() && parms.remap != nullptr && !parms.remap->Inactive) - dg.mTranslation = parms.remap; + if (!img->isHardwareCanvas() && parms.TranslationId != -1) + dg.mTranslationId = parms.TranslationId; if (shape->dirty) { if (shape->mVertices.Size() != shape->mTransformedVertices.Size()) diff --git a/src/rendering/2d/v_2ddrawer.h b/src/rendering/2d/v_2ddrawer.h index 23aae88d7c..53ea596c95 100644 --- a/src/rendering/2d/v_2ddrawer.h +++ b/src/rendering/2d/v_2ddrawer.h @@ -109,7 +109,7 @@ public: int mIndexCount; FTexture *mTexture; - FRemapTable *mTranslation; + int mTranslationId; PalEntry mSpecialColormap[2]; int mScissor[4]; int mDesaturate; @@ -128,7 +128,7 @@ public: { return mTexture == other.mTexture && mType == other.mType && - mTranslation == other.mTranslation && + mTranslationId == other.mTranslationId && mSpecialColormap[0].d == other.mSpecialColormap[0].d && mSpecialColormap[1].d == other.mSpecialColormap[1].d && !memcmp(mScissor, other.mScissor, sizeof(mScissor)) && diff --git a/src/rendering/2d/v_draw.cpp b/src/rendering/2d/v_draw.cpp index 095cf780e8..473db44a81 100644 --- a/src/rendering/2d/v_draw.cpp +++ b/src/rendering/2d/v_draw.cpp @@ -558,7 +558,7 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3 parms->destheight = INT_MAX; parms->Alpha = 1.f; parms->fillcolor = -1; - parms->remap = NULL; + parms->TranslationId = -1; parms->colorOverlay = 0; parms->alphaChannel = false; parms->flipX = false; @@ -756,7 +756,7 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3 break; case DTA_TranslationIndex: - parms->remap = TranslationToTable(ListGetInt(tags)); + parms->TranslationId = ListGetInt(tags); break; case DTA_ColorOverlay: @@ -971,11 +971,6 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3 } ListEnd(tags); - if (parms->remap != nullptr && parms->remap->Inactive) - { // If it's inactive, pretend we were passed NULL instead. - parms->remap = nullptr; - } - // intersect with the canvas's clipping rectangle. if (clipwidth >= 0 && clipheight >= 0) { diff --git a/src/rendering/2d/v_drawtext.cpp b/src/rendering/2d/v_drawtext.cpp index 46dea65616..4dff23df3b 100644 --- a/src/rendering/2d/v_drawtext.cpp +++ b/src/rendering/2d/v_drawtext.cpp @@ -59,14 +59,14 @@ int ListGetInt(VMVa_List &tags); // Create a texture from a text in a given font. // //========================================================================== - +#if 0 FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor) { int w; const uint8_t *ch; int cx; int cy; - FRemapTable *range; + int trans = -1; int kerning; FTexture *pic; @@ -122,7 +122,7 @@ FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor) EColorRange newcolor = V_ParseFontColor(ch, textcolor, textcolor); if (newcolor != CR_UNDEFINED) { - range = font->GetColorTranslation(newcolor); + trans = font->GetColorTranslation(newcolor); textcolor = newcolor; } continue; @@ -158,7 +158,7 @@ FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor) TexMan.AddTexture(tex); return tex; } - +#endif //========================================================================== @@ -193,7 +193,7 @@ void DFrameBuffer::DrawChar (FFont *font, int normalcolor, double x, double y, i return; } PalEntry color = 0xffffffff; - parms.remap = redirected? nullptr : font->GetColorTranslation((EColorRange)normalcolor, &color); + parms.TranslationId = redirected? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255); DrawTextureParms(pic, parms); } @@ -218,7 +218,7 @@ void DFrameBuffer::DrawChar(FFont *font, int normalcolor, double x, double y, in bool res = ParseDrawTextureTags(pic, x, y, tag, args, &parms, false); if (!res) return; PalEntry color = 0xffffffff; - parms.remap = redirected ? nullptr : font->GetColorTranslation((EColorRange)normalcolor, &color); + parms.TranslationId = redirected ? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255); DrawTextureParms(pic, parms); } @@ -261,7 +261,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double double cx; double cy; int boldcolor; - FRemapTable *range; + int trans = -1; int kerning; FTexture *pic; @@ -274,7 +274,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double PalEntry colorparm = parms.color; PalEntry color = 0xffffffff; - range = font->GetColorTranslation((EColorRange)normalcolor, &color); + trans = font->GetColorTranslation((EColorRange)normalcolor, &color); parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255); kerning = font->GetDefaultKerning(); @@ -301,7 +301,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double EColorRange newcolor = V_ParseFontColor(ch, normalcolor, boldcolor); if (newcolor != CR_UNDEFINED) { - range = font->GetColorTranslation(newcolor, &color); + trans = font->GetColorTranslation(newcolor, &color); parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255); currentcolor = newcolor; } @@ -318,7 +318,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double bool redirected = false; if (NULL != (pic = font->GetChar(c, currentcolor, &w, &redirected))) { - parms.remap = redirected? nullptr : range; + parms.TranslationId = redirected? -1 : trans; SetTextureParms(&parms, pic, cx, cy); if (parms.cellx) { diff --git a/src/rendering/gl/textures/gl_hwtexture.cpp b/src/rendering/gl/textures/gl_hwtexture.cpp index 74799fc889..c864eedd2a 100644 --- a/src/rendering/gl/textures/gl_hwtexture.cpp +++ b/src/rendering/gl/textures/gl_hwtexture.cpp @@ -317,15 +317,8 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i { int usebright = false; - if (translation <= 0) - { - translation = -translation; - } - else - { - auto remap = TranslationToTable(translation); - translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); - } + auto remap = TranslationToTable(translation); + translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); bool needmipmap = (clampmode <= CLAMP_XY); diff --git a/src/rendering/hwrenderer/textures/hw_texcontainer.h b/src/rendering/hwrenderer/textures/hw_texcontainer.h index 755fecb6ba..87abb95ae4 100644 --- a/src/rendering/hwrenderer/textures/hw_texcontainer.h +++ b/src/rendering/hwrenderer/textures/hw_texcontainer.h @@ -124,15 +124,8 @@ public: static int TranslationToIndex(int translation) { - if (translation <= 0) - { - return -translation; - } - else - { - auto remap = TranslationToTable(translation); - return remap == nullptr ? 0 : remap->GetUniqueIndex(); - } + auto remap = TranslationToTable(translation); + return remap == nullptr ? 0 : remap->GetUniqueIndex(); } template diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 18955c2cd8..d34742c031 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -167,8 +167,7 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) auto mat = FMaterial::ValidateTexture(cmd.mTexture, false); if (mat == nullptr) continue; - if (gltrans == -1 && cmd.mTranslation != nullptr) gltrans = cmd.mTranslation->GetUniqueIndex(); - state.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, -gltrans, -1); + state.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); state.EnableTexture(true); // Canvas textures are stored upside down diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index a9d03e904f..f7b1bc6fdf 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -167,15 +167,8 @@ void PolyHardwareTexture::CreateImage(FTexture *tex, int translation, int flags) if (!tex->isHardwareCanvas()) { - if (translation <= 0) - { - translation = -translation; - } - else - { - auto remap = TranslationToTable(translation); - translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); - } + auto remap = TranslationToTable(translation); + translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); FTextureBuffer texbuffer = tex->CreateTexBuffer(translation, flags | CTF_ProcessData); mCanvas->Resize(texbuffer.mWidth, texbuffer.mHeight, false); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 479b5d145a..285d8d4c6a 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -284,7 +284,7 @@ struct DrawParms double left; float Alpha; PalEntry fillcolor; - FRemapTable *remap; + int TranslationId; PalEntry colorOverlay; PalEntry color; INTBOOL alphaChannel; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index 27882402e3..125cc441d4 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -207,15 +207,8 @@ void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags) { if (!tex->isHardwareCanvas()) { - if (translation <= 0) - { - translation = -translation; - } - else - { - auto remap = TranslationToTable(translation); - translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); - } + auto remap = TranslationToTable(translation); + translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); FTextureBuffer texbuffer = tex->CreateTexBuffer(translation, flags | CTF_ProcessData); CreateTexture(texbuffer.mWidth, texbuffer.mHeight, 4, VK_FORMAT_B8G8R8A8_UNORM, texbuffer.mBuffer); diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index 02e6d4fced..64884c0189 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -1047,6 +1047,7 @@ enum ETranslationTable TRANSLATION_Blood, TRANSLATION_RainPillar, TRANSLATION_Custom, + TRANSLATION_Font, }; enum EFindFloorCeiling