mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 13:31:37 +00:00
- changed translation management so that the fonts also use translation IDs.
This commit is contained in:
parent
b7970ed763
commit
828cba13a1
17 changed files with 63 additions and 98 deletions
|
@ -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<void(FRemapTable*)> 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];
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -417,7 +417,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
Ranges[CR_UNTRANSLATED] = remap;
|
||||
Translations[CR_UNTRANSLATED] = remap.StoreTranslation(TRANSLATION_Font);
|
||||
forceremap = true;
|
||||
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ void FSpecialFont::LoadTranslations()
|
|||
uint8_t identity[256];
|
||||
TArray<double> Luminosity;
|
||||
int TotalColors;
|
||||
int i, j;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
|
@ -199,22 +199,20 @@ void FSpecialFont::LoadTranslations()
|
|||
static_cast<FFontChar1 *>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<void(FRemapTable*)> post = nullptr);
|
||||
void FixXMoves();
|
||||
|
||||
static int SimpleTranslation (uint32_t *colorsused, uint8_t *translation,
|
||||
|
@ -166,7 +166,7 @@ protected:
|
|||
};
|
||||
TArray<CharData> Chars;
|
||||
int ActiveColors;
|
||||
TArray<FRemapTable> Ranges;
|
||||
TArray<int> Translations;
|
||||
uint8_t PatchRemap[256];
|
||||
|
||||
int Lump;
|
||||
|
|
|
@ -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-- )
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@ enum
|
|||
TRANSLATION_Blood,
|
||||
TRANSLATION_RainPillar,
|
||||
TRANSLATION_Custom,
|
||||
TRANSLATION_Font,
|
||||
|
||||
NUM_TRANSLATION_TABLES
|
||||
};
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)) &&
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<class T>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -284,7 +284,7 @@ struct DrawParms
|
|||
double left;
|
||||
float Alpha;
|
||||
PalEntry fillcolor;
|
||||
FRemapTable *remap;
|
||||
int TranslationId;
|
||||
PalEntry colorOverlay;
|
||||
PalEntry color;
|
||||
INTBOOL alphaChannel;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1047,6 +1047,7 @@ enum ETranslationTable
|
|||
TRANSLATION_Blood,
|
||||
TRANSLATION_RainPillar,
|
||||
TRANSLATION_Custom,
|
||||
TRANSLATION_Font,
|
||||
};
|
||||
|
||||
enum EFindFloorCeiling
|
||||
|
|
Loading…
Reference in a new issue