mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-29 07:21:54 +00:00
use FTranslationID in the 2D drawer.
This commit is contained in:
parent
752b67c5a7
commit
7a5d89c851
15 changed files with 58 additions and 43 deletions
|
@ -443,7 +443,7 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
|
|||
if (img->isWarped()) dg.mFlags |= DTF_Wrap;
|
||||
if (parms.indexed) dg.mFlags |= DTF_Indexed;
|
||||
|
||||
dg.mTranslationId = 0;
|
||||
dg.mTranslationId = NO_TRANSLATION;
|
||||
SetStyle(img, parms, vertexcolor, dg);
|
||||
if (parms.indexed)
|
||||
{
|
||||
|
@ -451,7 +451,7 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
|
|||
vertexcolor = 0xffffffff;
|
||||
}
|
||||
|
||||
if (!img->isHardwareCanvas() && parms.TranslationId != -1)
|
||||
if (!img->isHardwareCanvas() && parms.TranslationId != INVALID_TRANSLATION)
|
||||
{
|
||||
dg.mTranslationId = parms.TranslationId;
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
|
|||
dg.mFlags |= DTF_Wrap;
|
||||
dg.mTexture = img;
|
||||
|
||||
dg.mTranslationId = 0;
|
||||
dg.mTranslationId = NO_TRANSLATION;
|
||||
SetStyle(img, parms, vertexcolor, dg);
|
||||
|
||||
if (shape->lastParms == nullptr) {
|
||||
|
@ -624,7 +624,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
|
|||
shape->lastParms = new DrawParms(parms);
|
||||
}
|
||||
|
||||
if (!(img != nullptr && img->isHardwareCanvas()) && parms.TranslationId != -1)
|
||||
if (!(img != nullptr && img->isHardwareCanvas()) && parms.TranslationId != INVALID_TRANSLATION)
|
||||
dg.mTranslationId = parms.TranslationId;
|
||||
|
||||
auto osave = offset;
|
||||
|
@ -796,7 +796,7 @@ void F2DDrawer::AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, const IntRect* clip)
|
||||
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, FTranslationID translation, PalEntry color, FRenderStyle style, const IntRect* clip)
|
||||
{
|
||||
RenderCommand dg;
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ public:
|
|||
int mIndexCount;
|
||||
|
||||
FGameTexture *mTexture;
|
||||
int mTranslationId;
|
||||
FTranslationID mTranslationId;
|
||||
PalEntry mSpecialColormap[2];
|
||||
int mScissor[4];
|
||||
int mDesaturate;
|
||||
|
@ -216,7 +216,7 @@ public:
|
|||
void AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
|
||||
double originx, double originy, double scalex, double scaley,
|
||||
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double lightlevel, uint32_t *indices, size_t indexcount);
|
||||
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, const IntRect* clip);
|
||||
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, FTranslationID translation, PalEntry color, FRenderStyle style, const IntRect* clip);
|
||||
void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int pic, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex,
|
||||
int clipx1, int clipy1, int clipx2, int clipy2);
|
||||
void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin = false, double flatscale = 1.0, PalEntry color = 0xffffffff, ERenderStyle rs = STYLE_Normal);
|
||||
|
|
|
@ -866,7 +866,7 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
|
|||
parms->destheight = INT_MAX;
|
||||
parms->Alpha = type == DrawTexture_Fill ? (float)fillalpha : 1.f;
|
||||
parms->fillcolor = type == DrawTexture_Fill ? fill : PalEntry(~0u);
|
||||
parms->TranslationId = -1;
|
||||
parms->TranslationId = INVALID_TRANSLATION;
|
||||
parms->colorOverlay = 0;
|
||||
parms->alphaChannel = false;
|
||||
parms->flipX = false;
|
||||
|
@ -1090,7 +1090,7 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
|
|||
break;
|
||||
|
||||
case DTA_TranslationIndex:
|
||||
parms->TranslationId = ListGetInt(tags);
|
||||
parms->TranslationId = FTranslationID::fromInt(ListGetInt(tags));
|
||||
break;
|
||||
|
||||
case DTA_ColorOverlay:
|
||||
|
|
|
@ -176,7 +176,7 @@ struct DrawParms
|
|||
double left;
|
||||
float Alpha;
|
||||
PalEntry fillcolor;
|
||||
int TranslationId;
|
||||
FTranslationID TranslationId;
|
||||
PalEntry colorOverlay;
|
||||
PalEntry color;
|
||||
int alphaChannel;
|
||||
|
|
|
@ -185,7 +185,7 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
|
|||
{
|
||||
return;
|
||||
}
|
||||
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
|
||||
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != NO_TRANSLATION);
|
||||
PalEntry color = 0xffffffff;
|
||||
if (!palettetrans) parms.TranslationId = 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);
|
||||
|
@ -210,7 +210,7 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double
|
|||
uint32_t tag = ListGetInt(args);
|
||||
bool res = ParseDrawTextureTags(drawer, pic, x, y, tag, args, &parms, DrawTexture_Normal);
|
||||
if (!res) return;
|
||||
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
|
||||
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != NO_TRANSLATION);
|
||||
PalEntry color = 0xffffffff;
|
||||
if (!palettetrans) parms.TranslationId = 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);
|
||||
|
@ -272,7 +272,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d
|
|||
double cx;
|
||||
double cy;
|
||||
int boldcolor;
|
||||
int trans = -1;
|
||||
FTranslationID trans = INVALID_TRANSLATION;
|
||||
int kerning;
|
||||
FGameTexture *pic;
|
||||
|
||||
|
@ -282,7 +282,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d
|
|||
if (parms.celly == 0) parms.celly = font->GetHeight() + 1;
|
||||
parms.celly = int (parms.celly * scaley);
|
||||
|
||||
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
|
||||
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != NO_TRANSLATION);
|
||||
|
||||
if (normalcolor >= NumTextColors)
|
||||
normalcolor = CR_UNTRANSLATED;
|
||||
|
@ -290,7 +290,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d
|
|||
|
||||
PalEntry colorparm = parms.color;
|
||||
PalEntry color = 0xffffffff;
|
||||
trans = palettetrans? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color);
|
||||
trans = palettetrans? INVALID_TRANSLATION : 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();
|
||||
|
|
|
@ -114,10 +114,10 @@ inline constexpr FTranslationID TRANSLATION(uint8_t a, uint32_t b)
|
|||
{
|
||||
return FTranslationID::fromInt((a << TRANSLATION_SHIFT) | b);
|
||||
}
|
||||
inline constexpr int MakeLuminosityTranslation(int range, uint8_t min, uint8_t max)
|
||||
inline constexpr FTranslationID MakeLuminosityTranslation(int range, uint8_t min, uint8_t max)
|
||||
{
|
||||
// ensure that the value remains positive.
|
||||
return ( (1 << 30) | ((range&0x3fff) << 16) | (min << 8) | max );
|
||||
return FTranslationID::fromInt( (1 << 30) | ((range&0x3fff) << 16) | (min << 8) | max );
|
||||
}
|
||||
|
||||
inline constexpr bool IsLuminosityTranslation(FTranslationID trans)
|
||||
|
@ -187,6 +187,11 @@ public:
|
|||
void CopyTranslation(FTranslationID dest, FTranslationID src);
|
||||
FTranslationID StoreTranslation(int slot, FRemapTable* remap);
|
||||
FRemapTable* TranslationToTable(int translation) const;
|
||||
FRemapTable* TranslationToTable(FTranslationID translation) const
|
||||
{
|
||||
return TranslationToTable(translation.index());
|
||||
}
|
||||
|
||||
void GenerateGlobalBrightmapFromColormap(const uint8_t* cmapdata, int numlevels);
|
||||
|
||||
void PushIdentityTable(int slot)
|
||||
|
|
|
@ -711,10 +711,10 @@ int FFont::GetLuminosity (uint32_t *colorsused, TArray<double> &Luminosity, int*
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
|
||||
FTranslationID FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
|
||||
{
|
||||
// Single pic fonts do not set up their translation table and must always return 0.
|
||||
if (Translations.Size() == 0) return 0;
|
||||
if (Translations.Size() == 0) return NO_TRANSLATION;
|
||||
assert(Translations.Size() == (unsigned)NumTextColors);
|
||||
|
||||
if (noTranslate)
|
||||
|
@ -728,7 +728,7 @@ int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
|
|||
if (color != nullptr) *color = retcolor;
|
||||
}
|
||||
if (range == CR_UNDEFINED)
|
||||
return -1;
|
||||
return INVALID_TRANSLATION;
|
||||
else if (range >= NumTextColors)
|
||||
range = CR_UNTRANSLATED;
|
||||
return Translations[range];
|
||||
|
@ -1059,7 +1059,7 @@ void FFont::LoadTranslations()
|
|||
Translations.Resize(NumTextColors);
|
||||
for (int i = 0; i < NumTextColors; i++)
|
||||
{
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = 0;
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = NO_TRANSLATION;
|
||||
else Translations[i] = MakeLuminosityTranslation(i*2 + TranslationType, minlum, maxlum);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ public:
|
|||
Translations.Resize(NumTextColors);
|
||||
for (int i = 0; i < NumTextColors; i++)
|
||||
{
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = 0;
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = NO_TRANSLATION;
|
||||
else Translations[i] = MakeLuminosityTranslation(i * 2 + 1, minlum, maxlum);
|
||||
}
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ public:
|
|||
Translations.Resize(NumTextColors);
|
||||
for (int i = 0; i < NumTextColors; i++)
|
||||
{
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = 0;
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = NO_TRANSLATION;
|
||||
else Translations[i] = MakeLuminosityTranslation(i * 2, minlum, maxlum);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ void FSingleLumpFont::LoadTranslations()
|
|||
Translations.Resize(NumTextColors);
|
||||
for (int i = 0; i < NumTextColors; i++)
|
||||
{
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = 0;
|
||||
if (i == CR_UNTRANSLATED) Translations[i] = NO_TRANSLATION;
|
||||
else Translations[i] = MakeLuminosityTranslation(i * 2 + (FontType == FONT1 ? 1 : 0), minlum, maxlum);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ void FSpecialFont::LoadTranslations()
|
|||
workpal[i * 4 + 2] = GPalette.BaseColors[i].r;
|
||||
workpal[i * 4 + 3] = GPalette.BaseColors[i].a;
|
||||
}
|
||||
V_ApplyLuminosityTranslation(trans, workpal, 256);
|
||||
V_ApplyLuminosityTranslation(LuminosityTranslationDesc::fromID(trans), workpal, 256);
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
if (!notranslate[i])
|
||||
|
@ -196,7 +196,7 @@ void FSpecialFont::LoadTranslations()
|
|||
remap.Remap[i] = i;
|
||||
}
|
||||
}
|
||||
trans = GPalette.StoreTranslation(TRANSLATION_Internal, &remap).index();
|
||||
trans = GPalette.StoreTranslation(TRANSLATION_Internal, &remap);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -667,12 +667,12 @@ static void CreateLuminosityTranslationRanges()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void V_ApplyLuminosityTranslation(int translation, uint8_t* pixel, int size)
|
||||
void V_ApplyLuminosityTranslation(const LuminosityTranslationDesc& lum, uint8_t* pixel, int size)
|
||||
{
|
||||
int colorrange = (translation >> 16) & 0x3fff;
|
||||
int colorrange = lum.colorrange;
|
||||
if (colorrange >= NumTextColors * 2) return;
|
||||
int lum_min = (translation >> 8) & 0xff;
|
||||
int lum_max = translation & 0xff;
|
||||
int lum_min = lum.lum_min;
|
||||
int lum_max = lum.lum_max;
|
||||
int lum_range = (lum_max - lum_min + 1);
|
||||
PalEntry* remap = paletteptr + colorrange * 256;
|
||||
|
||||
|
@ -892,10 +892,11 @@ void V_LoadTranslations()
|
|||
CalcDefaultTranslation(BigFont, CR_UNTRANSLATED * 2 + 1);
|
||||
if (OriginalBigFont != nullptr && OriginalBigFont != BigFont)
|
||||
{
|
||||
int sometrans = OriginalBigFont->Translations[0];
|
||||
assert(IsLuminosityTranslation(OriginalBigFont->Translations[0]));
|
||||
int sometrans = OriginalBigFont->Translations[0].index();
|
||||
sometrans &= ~(0x3fff << 16);
|
||||
sometrans |= (CR_UNTRANSLATED * 2 + 1) << 16;
|
||||
OriginalBigFont->Translations[CR_UNTRANSLATED] = sometrans;
|
||||
OriginalBigFont->Translations[CR_UNTRANSLATED] = FTranslationID::fromInt(sometrans);
|
||||
OriginalBigFont->forceremap = true;
|
||||
}
|
||||
}
|
||||
|
@ -904,18 +905,20 @@ void V_LoadTranslations()
|
|||
CalcDefaultTranslation(SmallFont, CR_UNTRANSLATED * 2);
|
||||
if (OriginalSmallFont != nullptr && OriginalSmallFont != SmallFont)
|
||||
{
|
||||
int sometrans = OriginalSmallFont->Translations[0];
|
||||
assert(IsLuminosityTranslation(OriginalSmallFont->Translations[0]));
|
||||
int sometrans = OriginalSmallFont->Translations[0].index();
|
||||
sometrans &= ~(0x3fff << 16);
|
||||
sometrans |= (CR_UNTRANSLATED * 2) << 16;
|
||||
OriginalSmallFont->Translations[CR_UNTRANSLATED] = sometrans;
|
||||
OriginalSmallFont->Translations[CR_UNTRANSLATED] = FTranslationID::fromInt(sometrans);
|
||||
OriginalSmallFont->forceremap = true;
|
||||
}
|
||||
if (NewSmallFont != nullptr)
|
||||
{
|
||||
int sometrans = NewSmallFont->Translations[0];
|
||||
assert(IsLuminosityTranslation(NewSmallFont->Translations[0]));
|
||||
int sometrans = NewSmallFont->Translations[0].index();
|
||||
sometrans &= ~(0x3fff << 16);
|
||||
sometrans |= (CR_UNTRANSLATED * 2) << 16;
|
||||
NewSmallFont->Translations[CR_UNTRANSLATED] = sometrans;
|
||||
NewSmallFont->Translations[CR_UNTRANSLATED] = FTranslationID::fromInt(sometrans);
|
||||
NewSmallFont->forceremap = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "vectors.h"
|
||||
#include "palentry.h"
|
||||
#include "name.h"
|
||||
#include "palettecontainer.h"
|
||||
|
||||
class FGameTexture;
|
||||
struct FRemapTable;
|
||||
|
@ -104,7 +105,7 @@ public:
|
|||
|
||||
virtual FGameTexture *GetChar (int code, int translation, int *const width) const;
|
||||
virtual int GetCharWidth (int code) const;
|
||||
int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
|
||||
FTranslationID GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
|
||||
int GetLump() const { return Lump; }
|
||||
int GetSpaceWidth () const { return SpaceWidth; }
|
||||
int GetHeight () const { return FontHeight; }
|
||||
|
@ -197,7 +198,7 @@ protected:
|
|||
int XMove = INT_MIN;
|
||||
};
|
||||
TArray<CharData> Chars;
|
||||
TArray<int> Translations;
|
||||
TArray<FTranslationID> Translations;
|
||||
|
||||
int Lump;
|
||||
FName FontName = NAME_None;
|
||||
|
@ -219,7 +220,7 @@ PalEntry V_LogColorFromColorRange (EColorRange range);
|
|||
EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int boldcolor);
|
||||
void V_InitFontColors();
|
||||
char* CleanseString(char* str);
|
||||
void V_ApplyLuminosityTranslation(int translation, uint8_t* pixel, int size);
|
||||
void V_ApplyLuminosityTranslation(const LuminosityTranslationDesc& lum, uint8_t* pixel, int size);
|
||||
void V_LoadTranslations();
|
||||
class FBitmap;
|
||||
|
||||
|
|
|
@ -635,6 +635,12 @@ public:
|
|||
SetMaterial(mat, clampmode, translation, overrideshader);
|
||||
}
|
||||
|
||||
void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, FTranslationID translation, int overrideshader)
|
||||
{
|
||||
SetMaterial(tex, upscalemask, scaleflags, clampmode, translation.index(), overrideshader);
|
||||
}
|
||||
|
||||
|
||||
void SetClipSplit(float bottom, float top)
|
||||
{
|
||||
mClipSplit[0] = bottom;
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "c_cvars.h"
|
||||
#include "imagehelpers.h"
|
||||
#include "v_video.h"
|
||||
#include "v_font.h"
|
||||
|
||||
// Wrappers to keep the definitions of these classes out of here.
|
||||
IHardwareTexture* CreateHardwareTexture(int numchannels);
|
||||
|
@ -321,7 +322,6 @@ bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch)
|
|||
// Initializes the buffer for the texture data
|
||||
//
|
||||
//===========================================================================
|
||||
void V_ApplyLuminosityTranslation(int translation, uint8_t *buffer, int size);
|
||||
|
||||
FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
|
||||
{
|
||||
|
@ -367,7 +367,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
|
|||
bmp.Blit(exx, exx, Pixels);
|
||||
if (IsLuminosityTranslation(translation))
|
||||
{
|
||||
V_ApplyLuminosityTranslation(translation, buffer, W * H);
|
||||
V_ApplyLuminosityTranslation(LuminosityTranslationDesc::fromInt(translation), buffer, W * H);
|
||||
}
|
||||
|
||||
if (remap == nullptr)
|
||||
|
|
|
@ -527,7 +527,7 @@ static void renderDrawMapView(const DVector2& cpos, const DVector2& cangvect, co
|
|||
auto flortex = sect->floortexture;
|
||||
if (!flortex.isValid()) continue;
|
||||
|
||||
int translation = TRANSLATION(Translation_Remap + curbasepal, sector[i].floorpal).index();
|
||||
auto translation = TRANSLATION(Translation_Remap + curbasepal, sector[i].floorpal);
|
||||
PalEntry light = shadeToLight(sector[i].floorshade);
|
||||
|
||||
for (auto section : sectionsPerSector[i])
|
||||
|
@ -580,7 +580,7 @@ static void renderDrawMapView(const DVector2& cpos, const DVector2& cangvect, co
|
|||
color.a = uint8_t(alpha * 255);
|
||||
}
|
||||
|
||||
int translation = TRANSLATION(Translation_Remap + curbasepal, actor->spr.pal).index();
|
||||
auto translation = TRANSLATION(Translation_Remap + curbasepal, actor->spr.pal);
|
||||
const static unsigned indices[] = { 0, 1, 2, 0, 2, 3 };
|
||||
twod->AddPoly(TexMan.GetGameTexture(actor->spr.spritetexture(), true), vertices.Data(), vertices.Size(), indices, 6, translation, color, rs, &viewport3d);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue