Merge branch 'texture_rework' of https://github.com/coelckers/gzdoom into fix_friendly_spawn

This commit is contained in:
Rachael Alexanderson 2020-05-05 04:29:44 -04:00
commit 18f822bed7
20 changed files with 288 additions and 141 deletions

View file

@ -931,7 +931,6 @@ set (PCH_SOURCES
rendering/hwrenderer/hw_models.cpp rendering/hwrenderer/hw_models.cpp
rendering/hwrenderer/hw_postprocessshader.cpp rendering/hwrenderer/hw_postprocessshader.cpp
rendering/hwrenderer/hw_precache.cpp rendering/hwrenderer/hw_precache.cpp
rendering/hwrenderer/hw_draw2d.cpp
rendering/hwrenderer/scene/hw_lighting.cpp rendering/hwrenderer/scene/hw_lighting.cpp
rendering/hwrenderer/scene/hw_drawlistadd.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp
rendering/hwrenderer/scene/hw_setcolor.cpp rendering/hwrenderer/scene/hw_setcolor.cpp
@ -1114,6 +1113,7 @@ set (PCH_SOURCES
common/rendering/v_video.cpp common/rendering/v_video.cpp
common/rendering/r_thread.cpp common/rendering/r_thread.cpp
common/rendering/r_videoscale.cpp common/rendering/r_videoscale.cpp
common/rendering/hwrenderer/hw_draw2d.cpp
common/rendering/hwrenderer/data/hw_clock.cpp common/rendering/hwrenderer/data/hw_clock.cpp
common/rendering/hwrenderer/data/hw_skydome.cpp common/rendering/hwrenderer/data/hw_skydome.cpp
common/rendering/hwrenderer/data/flatvertices.cpp common/rendering/hwrenderer/data/flatvertices.cpp

View file

@ -677,7 +677,7 @@ void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigne
// //
//========================================================================== //==========================================================================
void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, bool local_origin) void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin, double flatscale)
{ {
float fU1, fU2, fV1, fV2; float fU1, fU2, fV1, fV2;
@ -690,27 +690,83 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu
dg.mTexture = src; dg.mTexture = src;
dg.mFlags = DTF_Wrap; dg.mFlags = DTF_Wrap;
// scaling is not used here. float fs = 1.f / float(flatscale);
if (!local_origin) bool flipc = false;
{ switch (local_origin)
fU1 = float(left) / (float)src->GetDisplayWidth();
fV1 = float(top) / (float)src->GetDisplayHeight();
fU2 = float(right) / (float)src->GetDisplayWidth();
fV2 = float(bottom) / (float)src->GetDisplayHeight();
}
else
{ {
case 0:
fU1 = float(left) / (float)src->GetDisplayWidth() * fs;
fV1 = float(top) / (float)src->GetDisplayHeight() * fs;
fU2 = float(right) / (float)src->GetDisplayWidth() * fs;
fV2 = float(bottom) / (float)src->GetDisplayHeight() * fs;
break;
case 1:
fU1 = 0; fU1 = 0;
fV1 = 0; fV1 = 0;
fU2 = float(right - left) / (float)src->GetDisplayWidth(); fU2 = float(right - left) / (float)src->GetDisplayWidth() * fs;
fV2 = float(bottom - top) / (float)src->GetDisplayHeight(); fV2 = float(bottom - top) / (float)src->GetDisplayHeight() * fs;
break;
// The following are for drawing frames with elements of pnly one orientation
case 2: // flip vertically
fU1 = 0;
fV2 = 0;
fU2 = float(right - left) / (float)src->GetDisplayWidth() * fs;
fV1 = float(bottom - top) / (float)src->GetDisplayHeight() * fs;
break;
case 3: // flip horizontally
fU2 = 0;
fV1 = 0;
fU1 = float(right - left) / (float)src->GetDisplayWidth() * fs;
fV2 = float(bottom - top) / (float)src->GetDisplayHeight() * fs;
break;
case 4: // flip vertically and horizontally
fU2 = 0;
fV2 = 0;
fU1 = float(right - left) / (float)src->GetDisplayWidth() * fs;
fV1 = float(bottom - top) / (float)src->GetDisplayHeight() * fs;
break;
case 5: // flip coordinates
fU1 = 0;
fV1 = 0;
fU2 = float(bottom - top) / (float)src->GetDisplayWidth() * fs;
fV2 = float(right - left) / (float)src->GetDisplayHeight() * fs;
break;
case 6: // flip coordinates and vertically
fU2 = 0;
fV1 = 0;
fU1 = float(bottom - top) / (float)src->GetDisplayWidth() * fs;
fV2 = float(right - left) / (float)src->GetDisplayHeight() * fs;
break;
case 7: // flip coordinates and horizontally
fU1 = 0;
fV2 = 0;
fU2 = float(bottom - top) / (float)src->GetDisplayWidth() * fs;
fV1 = float(right - left) / (float)src->GetDisplayHeight() * fs;
break;
} }
dg.mVertIndex = (int)mVertices.Reserve(4); dg.mVertIndex = (int)mVertices.Reserve(4);
auto ptr = &mVertices[dg.mVertIndex]; auto ptr = &mVertices[dg.mVertIndex];
ptr->Set(left, top, 0, fU1, fV1, 0xffffffff); ptr++; ptr->Set(left, top, 0, fU1, fV1, 0xffffffff); ptr++;
ptr->Set(left, bottom, 0, fU1, fV2, 0xffffffff); ptr++; if (local_origin < 4)
ptr->Set(right, top, 0, fU2, fV1, 0xffffffff); ptr++; {
ptr->Set(left, bottom, 0, fU1, fV2, 0xffffffff); ptr++;
ptr->Set(right, top, 0, fU2, fV1, 0xffffffff); ptr++;
}
else
{
ptr->Set(left, bottom, 0, fU2, fV1, 0xffffffff); ptr++;
ptr->Set(right, top, 0, fU1, fV2, 0xffffffff); ptr++;
}
ptr->Set(right, bottom, 0, fU2, fV2, 0xffffffff); ptr++; ptr->Set(right, bottom, 0, fU2, fV2, 0xffffffff); ptr++;
dg.mIndexIndex = mIndices.Size(); dg.mIndexIndex = mIndices.Size();
dg.mIndexCount += 6; dg.mIndexCount += 6;
@ -721,11 +777,11 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu
//=========================================================================== //===========================================================================
// //
// //
// //
//=========================================================================== //===========================================================================
void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, FRenderStyle *style) void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, FRenderStyle *style, bool prepend)
{ {
RenderCommand dg; RenderCommand dg;
@ -741,7 +797,13 @@ void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, F
dg.mIndexIndex = mIndices.Size(); dg.mIndexIndex = mIndices.Size();
dg.mIndexCount += 6; dg.mIndexCount += 6;
AddIndices(dg.mVertIndex, 6, 0, 1, 2, 1, 3, 2); AddIndices(dg.mVertIndex, 6, 0, 1, 2, 1, 3, 2);
AddCommand(&dg); if (!prepend) AddCommand(&dg);
else
{
// Only needed by Raze's fullscreen blends because they are being calculated late when half of the 2D content has already been submitted,
// This ensures they are below the HUD, not above it.
mData.Insert(0, dg);
}
} }
void F2DDrawer::ClearScreen(PalEntry color) void F2DDrawer::ClearScreen(PalEntry color)

View file

@ -182,9 +182,9 @@ public:
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2); void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2);
void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex, void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex,
int clipx1, int clipy1, int clipx2, int clipy2); int clipx1, int clipy1, int clipx2, int clipy2);
void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, bool local_origin = false); void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin = false, double flatscale = 1.0);
void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr); void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr, bool prepend = false);
void ClearScreen(PalEntry color = 0xff000000); void ClearScreen(PalEntry color = 0xff000000);
void AddDim(PalEntry color, float damount, int x1, int y1, int w, int h); void AddDim(PalEntry color, float damount, int x1, int y1, int w, int h);
void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color); void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color);

View file

@ -34,6 +34,7 @@ struct FRemapTable
int Index; int Index;
int NumEntries; // # of elements in this table (usually 256) int NumEntries; // # of elements in this table (usually 256)
bool Inactive = false; // This table is inactive and should be treated as if it was passed as NULL bool Inactive = false; // This table is inactive and should be treated as if it was passed as NULL
bool TwodOnly = false; // Only used for 2D rendering
bool ForFont = false; // Mark font translations because they may require different handling than the ones for sprites- bool ForFont = false; // Mark font translations because they may require different handling than the ones for sprites-
private: private:

View file

@ -372,10 +372,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
FixXMoves(); FixXMoves();
} }
if (!noTranslate) LoadTranslations();
} }
void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale) void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
@ -443,16 +439,13 @@ void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height
if (lump != nullptr) if (lump != nullptr)
{ {
auto pic = (*lump)->GetTexture(); auto pic = (*lump)->GetTexture();
Chars[i].OriginalPic = (*lump)->GetUseType() == ETextureType::FontChar? (*lump) : MakeGameTexture(pic, nullptr, ETextureType::FontChar);
auto b = pic->Get8BitPixels(false);
Chars[i].OriginalPic = MakeGameTexture(pic, nullptr, ETextureType::FontChar);
Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar);
Chars[i].OriginalPic->CopySize(*lump); Chars[i].OriginalPic->CopySize(*lump);
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage())), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage())), nullptr, ETextureType::FontChar);
Chars[i].TranslatedPic->CopySize(*lump); Chars[i].TranslatedPic->CopySize(*lump);
Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar);
TexMan.AddGameTexture(Chars[i].OriginalPic); if (Chars[i].OriginalPic != *lump) TexMan.AddGameTexture(Chars[i].OriginalPic);
TexMan.AddGameTexture(Chars[i].TranslatedPic); TexMan.AddGameTexture(Chars[i].TranslatedPic);
} }
Chars[i].XMove = width; Chars[i].XMove = width;

View file

@ -245,6 +245,7 @@ public:
FHexFont (const char *fontname, int lump) FHexFont (const char *fontname, int lump)
: FFont(lump) : FFont(lump)
{ {
const int spacing = 9;
assert(lump >= 0); assert(lump >= 0);
FontName = fontname; FontName = fontname;
@ -258,8 +259,22 @@ public:
SpaceWidth = 9; SpaceWidth = 9;
GlobalKerning = 0; GlobalKerning = 0;
translateUntranslated = true; translateUntranslated = true;
LoadTranslations(); Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
if (hexdata.glyphmap[i] > 0)
{
auto offset = hexdata.glyphmap[i];
int size = hexdata.glyphdata[offset] / 16;
Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar(&hexdata.glyphdata[offset + 1], size, size * 9, 16)), nullptr, ETextureType::FontChar);
Chars[i - FirstChar].OriginalPic = Chars[i - FirstChar].TranslatedPic;
Chars[i - FirstChar].XMove = size * spacing;
TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic);
}
else Chars[i - FirstChar].XMove = spacing;
}
} }
//========================================================================== //==========================================================================
@ -270,7 +285,6 @@ public:
void LoadTranslations() void LoadTranslations()
{ {
const int spacing = 9;
double luminosity[256]; double luminosity[256];
memset (PatchRemap, 0, 256); memset (PatchRemap, 0, 256);
@ -282,20 +296,6 @@ public:
} }
ActiveColors = 18; ActiveColors = 18;
Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
if (hexdata.glyphmap[i] > 0)
{
auto offset = hexdata.glyphmap[i];
int size = hexdata.glyphdata[offset] / 16;
Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16)), nullptr, ETextureType::FontChar);
Chars[i - FirstChar].XMove = size * spacing;
TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic);
}
else Chars[i - FirstChar].XMove = spacing;
}
BuildTranslations (luminosity, nullptr, &TranslationParms[1][0], ActiveColors, nullptr); BuildTranslations (luminosity, nullptr, &TranslationParms[1][0], ActiveColors, nullptr);
} }
@ -317,6 +317,7 @@ public:
FHexFont2(const char *fontname, int lump) FHexFont2(const char *fontname, int lump)
: FFont(lump) : FFont(lump)
{ {
const int spacing = 9;
assert(lump >= 0); assert(lump >= 0);
FontName = fontname; FontName = fontname;
@ -330,8 +331,21 @@ public:
SpaceWidth = 9; SpaceWidth = 9;
GlobalKerning = -1; GlobalKerning = -1;
translateUntranslated = true; translateUntranslated = true;
Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
if (hexdata.glyphmap[i] > 0)
{
auto offset = hexdata.glyphmap[i];
int size = hexdata.glyphdata[offset] / 16;
Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar);
Chars[i - FirstChar].OriginalPic = Chars[i - FirstChar].TranslatedPic;
Chars[i - FirstChar].XMove = size * spacing;
TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic);
}
else Chars[i - FirstChar].XMove = spacing;
LoadTranslations(); }
} }
//========================================================================== //==========================================================================
@ -342,7 +356,6 @@ public:
void LoadTranslations() override void LoadTranslations() override
{ {
const int spacing = 9;
double luminosity[256]; double luminosity[256];
memset(PatchRemap, 0, 256); memset(PatchRemap, 0, 256);
@ -354,20 +367,6 @@ public:
} }
ActiveColors = 18; ActiveColors = 18;
Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
if (hexdata.glyphmap[i] > 0)
{
auto offset = hexdata.glyphmap[i];
int size = hexdata.glyphdata[offset] / 16;
Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar);
Chars[i - FirstChar].XMove = size * spacing;
TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic);
}
else Chars[i - FirstChar].XMove = spacing;
}
BuildTranslations(luminosity, nullptr, &TranslationParms[0][0], ActiveColors, nullptr); BuildTranslations(luminosity, nullptr, &TranslationParms[0][0], ActiveColors, nullptr);
} }

View file

@ -176,6 +176,7 @@ void FSingleLumpFont::CreateFontFromPic (FTextureID picnum)
FirstChar = LastChar = 'A'; FirstChar = LastChar = 'A';
Chars.Resize(1); Chars.Resize(1);
Chars[0].TranslatedPic = pic; Chars[0].TranslatedPic = pic;
Chars[0].OriginalPic = pic;
// Only one color range. Don't bother with the others. // Only one color range. Don't bother with the others.
ActiveColors = 0; ActiveColors = 0;
@ -255,7 +256,6 @@ void FSingleLumpFont::LoadFON1 (int lump, const uint8_t *data)
LastChar = 255; // This is to allow LoadTranslations to function. The way this is all set up really needs to be changed. LastChar = 255; // This is to allow LoadTranslations to function. The way this is all set up really needs to be changed.
GlobalKerning = 0; GlobalKerning = 0;
translateUntranslated = true; translateUntranslated = true;
LoadTranslations();
LastChar = 0x2122; LastChar = 0x2122;
// Move the Windows-1252 characters to their proper place. // Move the Windows-1252 characters to their proper place.
@ -350,10 +350,12 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data)
if (destSize <= 0) if (destSize <= 0)
{ {
Chars[i].TranslatedPic = nullptr; Chars[i].TranslatedPic = nullptr;
Chars[i].OriginalPic = nullptr;
} }
else else
{ {
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar);
Chars[i].OriginalPic = Chars[i].TranslatedPic;
TexMan.AddGameTexture(Chars[i].TranslatedPic); TexMan.AddGameTexture(Chars[i].TranslatedPic);
do do
{ {
@ -376,8 +378,6 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data)
I_Error ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars()); I_Error ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars());
} }
} }
LoadTranslations();
} }
//========================================================================== //==========================================================================
@ -489,6 +489,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data)
-(int8_t)chardata[chari+4] // y offset -(int8_t)chardata[chari+4] // y offset
)), nullptr, ETextureType::FontChar); )), nullptr, ETextureType::FontChar);
Chars[chardata[chari] - FirstChar].TranslatedPic = tex; Chars[chardata[chari] - FirstChar].TranslatedPic = tex;
Chars[chardata[chari] - FirstChar].OriginalPic = tex;
TexMan.AddGameTexture(tex); TexMan.AddGameTexture(tex);
} }
@ -506,7 +507,6 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data)
} }
FixXMoves(); FixXMoves();
LoadTranslations();
} }
//========================================================================== //==========================================================================
@ -555,6 +555,7 @@ void FSingleLumpFont::CheckFON1Chars (double *luminosity)
if(!Chars[i].TranslatedPic) if(!Chars[i].TranslatedPic)
{ {
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar);
Chars[i].OriginalPic = Chars[i].TranslatedPic;
Chars[i].XMove = SpaceWidth; Chars[i].XMove = SpaceWidth;
TexMan.AddGameTexture(Chars[i].TranslatedPic); TexMan.AddGameTexture(Chars[i].TranslatedPic);
} }

View file

@ -140,10 +140,6 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture
{ {
ActiveColors = 0; ActiveColors = 0;
} }
else
{
LoadTranslations();
}
} }
//========================================================================== //==========================================================================

View file

@ -728,13 +728,6 @@ void V_InitFonts()
OriginalSmallFont = new FFont("OriginalSmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, true); OriginalSmallFont = new FFont("OriginalSmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, true);
} }
if (SmallFont)
{
uint32_t colors[256] = {};
SmallFont->RecordAllTextureColors(colors);
if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors);
NewSmallFont->SetDefaultTranslation(colors);
}
if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife
{ {
@ -770,13 +763,6 @@ void V_InitFonts()
OriginalBigFont = new FFont("OriginalBigFont", nullptr, "bigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true); OriginalBigFont = new FFont("OriginalBigFont", nullptr, "bigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
} }
if (BigFont)
{
uint32_t colors[256] = {};
BigFont->RecordAllTextureColors(colors);
if (OriginalBigFont != nullptr) OriginalBigFont->SetDefaultTranslation(colors);
}
// let PWAD BIGFONTs override the stock BIGUPPER font. (This check needs to be made smarter.) // let PWAD BIGFONTs override the stock BIGUPPER font. (This check needs to be made smarter.)
if (BigUpper && BigFont->Type != FFont::Folder && BigUpper->Type == FFont::Folder) if (BigUpper && BigFont->Type != FFont::Folder && BigUpper->Type == FFont::Folder)
{ {
@ -828,6 +814,28 @@ void V_InitFonts()
AlternativeSmallFont = OriginalSmallFont; AlternativeSmallFont = OriginalSmallFont;
} }
void V_LoadTranslations()
{
for (auto font = FFont::FirstFont; font; font = font->Next)
{
if (!font->noTranslate) font->LoadTranslations();
else font->ActiveColors = 0;
}
if (BigFont)
{
uint32_t colors[256] = {};
BigFont->RecordAllTextureColors(colors);
if (OriginalBigFont != nullptr) OriginalBigFont->SetDefaultTranslation(colors);
}
if (SmallFont)
{
uint32_t colors[256] = {};
SmallFont->RecordAllTextureColors(colors);
if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors);
NewSmallFont->SetDefaultTranslation(colors);
}
}
void V_ClearFonts() void V_ClearFonts()
{ {
while (FFont::FirstFont != nullptr) while (FFont::FirstFont != nullptr)

View file

@ -80,6 +80,7 @@ using GlyphSet = TMap<int, FGameTexture*>;
class FFont class FFont
{ {
friend void V_LoadTranslations();
public: public:
enum EFontType enum EFontType
@ -154,7 +155,7 @@ protected:
int TranslationType = 0; int TranslationType = 0;
int Displacement = 0; int Displacement = 0;
char Cursor; char Cursor;
bool noTranslate; bool noTranslate = false;
bool translateUntranslated; bool translateUntranslated;
bool MixedCase = false; bool MixedCase = false;
bool forceremap = false; bool forceremap = false;
@ -165,7 +166,7 @@ protected:
int XMove = INT_MIN; int XMove = INT_MIN;
}; };
TArray<CharData> Chars; TArray<CharData> Chars;
int ActiveColors; int ActiveColors = -1;
TArray<int> Translations; TArray<int> Translations;
uint8_t PatchRemap[256]; uint8_t PatchRemap[256];
@ -191,5 +192,6 @@ EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int
FFont *V_GetFont(const char *fontname, const char *fontlumpname = nullptr); FFont *V_GetFont(const char *fontname, const char *fontlumpname = nullptr);
void V_InitFontColors(); void V_InitFontColors();
char* CleanseString(char* str); char* CleanseString(char* str);
void V_LoadTranslations();

View file

@ -305,8 +305,8 @@ public:
FShader *BindEffect(int effect, EPassType passType); FShader *BindEffect(int effect, EPassType passType);
FShader *Get(unsigned int eff, bool alphateston, EPassType passType); FShader *Get(unsigned int eff, bool alphateston, EPassType passType);
private:
void SetActiveShader(FShader *sh); void SetActiveShader(FShader *sh);
private:
FShader *mActiveShader = nullptr; FShader *mActiveShader = nullptr;
TArray<FShaderCollection*> mPassShaders; TArray<FShaderCollection*> mPassShaders;

View file

@ -1,34 +1,39 @@
//
//---------------------------------------------------------------------------
//
// Copyright(C) 2018 Christoph Oelckers
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
//--------------------------------------------------------------------------
//
/* /*
** 2d drawer ** hw_draw2d.cpp
** Renderer interface ** 2d drawer Renderer interface
**
**---------------------------------------------------------------------------
** Copyright 2018-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
** **
*/ */
#include "doomstat.h"
#include "v_video.h" #include "v_video.h"
#include "cmdlib.h" #include "cmdlib.h"
#include "r_defs.h"
#include "hwrenderer/data/buffers.h" #include "hwrenderer/data/buffers.h"
#include "flatvertices.h" #include "flatvertices.h"
#include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/hw_viewpointbuffer.h"

View file

@ -289,6 +289,9 @@ void V_UpdateModeSize (int width, int height)
void V_OutputResized (int width, int height) void V_OutputResized (int width, int height)
{ {
V_UpdateModeSize(width, height); V_UpdateModeSize(width, height);
// set new resolution in 2D drawer
twod->Begin(screen->GetWidth(), screen->GetHeight());
twod->End();
setsizeneeded = true; setsizeneeded = true;
C_NewModeAdjust(); C_NewModeAdjust();
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)

View file

@ -102,6 +102,8 @@ void AnimTextures::SetSize(int width, int height)
{ {
static_cast<AnimTexture*>(tex[0]->GetTexture())->SetFrameSize(width, height); static_cast<AnimTexture*>(tex[0]->GetTexture())->SetFrameSize(width, height);
static_cast<AnimTexture*>(tex[1]->GetTexture())->SetFrameSize(width, height); static_cast<AnimTexture*>(tex[1]->GetTexture())->SetFrameSize(width, height);
tex[0]->SetSize(width, height);
tex[1]->SetSize(width, height);
} }
void AnimTextures::SetFrame(const uint8_t *palette, const void* data) void AnimTextures::SetFrame(const uint8_t *palette, const void* data)

View file

@ -59,6 +59,7 @@ public:
protected: protected:
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap); void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
void SetupPalette(FileReader &lump);
uint8_t BitDepth; uint8_t BitDepth;
uint8_t ColorType; uint8_t ColorType;
@ -152,11 +153,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
: FImageSource(lumpnum), : FImageSource(lumpnum),
BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false) BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false)
{ {
union
{
uint32_t palette[256];
uint8_t pngpal[256][3];
} p;
uint8_t trans[256]; uint8_t trans[256];
uint32_t len, id; uint32_t len, id;
int i; int i;
@ -210,15 +206,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
case MAKE_ID('P','L','T','E'): case MAKE_ID('P','L','T','E'):
PaletteSize = MIN<int> (len / 3, 256); PaletteSize = MIN<int> (len / 3, 256);
StartOfPalette = (uint32_t)lump.Tell(); StartOfPalette = (uint32_t)lump.Tell();
lump.Read (p.pngpal, PaletteSize * 3); lump.Seek(len, FileReader::SeekCur);
if (PaletteSize * 3 != (int)len)
{
lump.Seek (len - PaletteSize * 3, FileReader::SeekCur);
}
for (i = PaletteSize - 1; i >= 0; --i)
{
p.palette[i] = MAKERGB(p.pngpal[i][0], p.pngpal[i][1], p.pngpal[i][2]);
}
break; break;
case MAKE_ID('t','R','N','S'): case MAKE_ID('t','R','N','S'):
@ -248,9 +236,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
{ {
bMasked = true; bMasked = true;
PaletteSize = 256; PaletteSize = 256;
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
memcpy (PaletteMap, GPalette.GrayMap, 256);
PaletteMap[NonPaletteTrans[0]] = 0;
} }
else else
{ {
@ -259,14 +244,11 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
break; break;
case 3: // Paletted case 3: // Paletted
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
MakeRemap ((uint32_t*)GPalette.BaseColors, p.palette, PaletteMap, trans, PaletteSize);
for (i = 0; i < PaletteSize; ++i) for (i = 0; i < PaletteSize; ++i)
{ {
if (trans[i] == 0) if (trans[i] == 0)
{ {
bMasked = true; bMasked = true;
PaletteMap[i] = 0;
} }
} }
break; break;
@ -281,6 +263,87 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
} }
} }
void FPNGTexture::SetupPalette(FileReader &lump)
{
union
{
uint32_t palette[256];
uint8_t pngpal[256][3];
} p;
uint8_t trans[256];
uint32_t len, id;
int i;
auto pos = lump.Tell();
memset(trans, 255, 256);
// Parse pre-IDAT chunks. I skip the CRCs. Is that bad?
lump.Seek(33, FileReader::SeekSet);
lump.Read(&len, 4);
lump.Read(&id, 4);
while (id != MAKE_ID('I', 'D', 'A', 'T') && id != MAKE_ID('I', 'E', 'N', 'D'))
{
len = BigLong((unsigned int)len);
switch (id)
{
default:
lump.Seek(len, FileReader::SeekCur);
break;
case MAKE_ID('P', 'L', 'T', 'E'):
lump.Read(p.pngpal, PaletteSize * 3);
if (PaletteSize * 3 != (int)len)
{
lump.Seek(len - PaletteSize * 3, FileReader::SeekCur);
}
for (i = PaletteSize - 1; i >= 0; --i)
{
p.palette[i] = MAKERGB(p.pngpal[i][0], p.pngpal[i][1], p.pngpal[i][2]);
}
break;
case MAKE_ID('t', 'R', 'N', 'S'):
lump.Read(trans, len);
break;
}
lump.Seek(4, FileReader::SeekCur); // Skip CRC
lump.Read(&len, 4);
id = MAKE_ID('I', 'E', 'N', 'D');
lump.Read(&id, 4);
}
StartOfIDAT = (uint32_t)lump.Tell() - 8;
switch (ColorType)
{
case 0: // Grayscale
if (HaveTrans && NonPaletteTrans[0] < 256)
{
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
memcpy(PaletteMap, GPalette.GrayMap, 256);
PaletteMap[NonPaletteTrans[0]] = 0;
}
break;
case 3: // Paletted
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
MakeRemap((uint32_t*)GPalette.BaseColors, p.palette, PaletteMap, trans, PaletteSize);
for (i = 0; i < PaletteSize; ++i)
{
if (trans[i] == 0)
{
PaletteMap[i] = 0;
}
}
break;
default:
break;
}
lump.Seek(pos, FileReader::SeekSet);
}
//========================================================================== //==========================================================================
// //
// //
@ -336,6 +399,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
{ {
if (conversion != luminance) if (conversion != luminance)
{ {
if (!PaletteMap) SetupPalette(lfr);
ImageHelpers::FlipSquareBlockRemap (Pixels.Data(), Width, PaletteMap); ImageHelpers::FlipSquareBlockRemap (Pixels.Data(), Width, PaletteMap);
} }
else if (ColorType == 0) else if (ColorType == 0)
@ -354,6 +418,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
TArray<uint8_t> newpix(Width*Height, true); TArray<uint8_t> newpix(Width*Height, true);
if (conversion != luminance) if (conversion != luminance)
{ {
if (!PaletteMap) SetupPalette(lfr);
ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap); ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
} }
else if (ColorType == 0) else if (ColorType == 0)
@ -408,6 +473,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
case 4: // Grayscale + Alpha case 4: // Grayscale + Alpha
pitch = Width * 2; pitch = Width * 2;
backstep = Height * pitch - 2; backstep = Height * pitch - 2;
if (!PaletteMap) SetupPalette(lfr);
for (x = Width; x > 0; --x) for (x = Width; x > 0; --x)
{ {
for (y = Height; y > 0; --y) for (y = Height; y > 0; --y)

View file

@ -240,6 +240,10 @@ public:
if (int(ScaleY * h) != TexelHeight) ScaleY += (1 / 65536.); if (int(ScaleY * h) != TexelHeight) ScaleY += (1 / 65536.);
} }
void SetBase(FTexture* Tex)
{
Base = Tex;
}
void SetOffsets(int which, int x, int y) void SetOffsets(int which, int x, int y)
{ {
LeftOffset[which] = x; LeftOffset[which] = x;

View file

@ -138,19 +138,18 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u
{ {
buildinfo.texture = new FGameTexture(nullptr, buildinfo.Name); buildinfo.texture = new FGameTexture(nullptr, buildinfo.Name);
buildinfo.texture->SetUseType(usetype); buildinfo.texture->SetUseType(usetype);
buildinfo.texture->SetSize(buildinfo.Width, buildinfo.Height);
buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); // These are needed for construction of other multipatch textures. buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); // These are needed for construction of other multipatch textures.
buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]);
buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X);
buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning);
buildinfo.texture->SetNoDecals(buildinfo.bNoDecals);
TexMan.AddGameTexture(buildinfo.texture); TexMan.AddGameTexture(buildinfo.texture);
} }
void FMultipatchTextureBuilder::AddImageToTexture(FImageTexture *tex, BuildInfo& buildinfo) void FMultipatchTextureBuilder::AddImageToTexture(FImageTexture *tex, BuildInfo& buildinfo)
{ {
buildinfo.texture->Setup(tex); buildinfo.texture->SetBase(tex);
buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]);
buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]);
buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X);
buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning);
buildinfo.texture->SetNoDecals(buildinfo.bNoDecals);
calcShouldUpscale(buildinfo.texture); // calculate this once at insertion calcShouldUpscale(buildinfo.texture); // calculate this once at insertion
} }
@ -874,6 +873,7 @@ void FMultipatchTextureBuilder::ResolveAllPatches()
for (int i = BuiltTextures.Size()-1; i>= 0; i--) for (int i = BuiltTextures.Size()-1; i>= 0; i--)
{ {
auto &buildinfo = BuiltTextures[i]; auto &buildinfo = BuiltTextures[i];
bool hasEmpty = false; bool hasEmpty = false;
for (unsigned j = 0; j < buildinfo.Inits.Size(); j++) for (unsigned j = 0; j < buildinfo.Inits.Size(); j++)

View file

@ -625,8 +625,9 @@ void FTextureManager::AddHiresTextures (int wadnum)
auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override);
gtex->SetWorldPanning(true); gtex->SetWorldPanning(true);
gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight());
gtex->SetOffsets(0, oldtex->GetTexelLeftOffset(0), oldtex->GetTexelTopOffset(0));
gtex->SetOffsets(1, oldtex->GetTexelLeftOffset(1), oldtex->GetTexelTopOffset(1)); gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY()));
gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY()));
ReplaceTexture(tlist[i], gtex, true); ReplaceTexture(tlist[i], gtex, true);
} }
} }

View file

@ -3389,6 +3389,7 @@ static int D_DoomMain_Internal (void)
StartScreen->Progress(); StartScreen->Progress();
V_InitFonts(); V_InitFonts();
V_LoadTranslations();
UpdateGenericUI(false); UpdateGenericUI(false);
// [CW] Parse any TEAMINFO lumps. // [CW] Parse any TEAMINFO lumps.
@ -3549,6 +3550,9 @@ static int D_DoomMain_Internal (void)
V_Init2(); V_Init2();
twod->fullscreenautoaspect = gameinfo.fullscreenautoaspect; twod->fullscreenautoaspect = gameinfo.fullscreenautoaspect;
// Initialize the size of the 2D drawer so that an attempt to access it outside the draw code won't crash.
twod->Begin(screen->GetWidth(), screen->GetHeight());
twod->End();
UpdateJoystickMenu(NULL); UpdateJoystickMenu(NULL);
UpdateVRModes(); UpdateVRModes();

View file

@ -111,10 +111,10 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou
if (mainview && toscreen) if (mainview && toscreen)
{ {
screen->SetAABBTree(camera->Level->aabbTree); screen->SetAABBTree(camera->Level->aabbTree);
screen->UpdateShadowMap();
screen->mShadowMap.SetCollectLights([=] { screen->mShadowMap.SetCollectLights([=] {
CollectLights(camera->Level); CollectLights(camera->Level);
}); });
screen->UpdateShadowMap();
} }
// Update the attenuation flag of all light defaults for each viewpoint. // Update the attenuation flag of all light defaults for each viewpoint.