- some cleanup of the texture code

* removed unneeded includes
* moved global brightmap to GPalette
* took Build tile init code out of the FTextureManager class, because this code is not compatible with how real Build games need to go about it, making the texture manager not shareable.
* removed dependency on higher level info from the Image class.
This commit is contained in:
Christoph Oelckers 2020-04-11 18:53:56 +02:00
parent a13c7bd053
commit 7d192decc7
29 changed files with 262 additions and 316 deletions

View file

@ -53,6 +53,7 @@ FColorMatcher ColorMatcher;
void PaletteContainer::Init(int numslots) // This cannot be a constructor!!!
{
Clear();
HasGlobalBrightmap = false;
// Make sure that index 0 is always the identity translation.
FRemapTable remap;
remap.MakeIdentity();
@ -64,16 +65,17 @@ void PaletteContainer::Init(int numslots) // This cannot be a constructor!!!
void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index)
{
// Initialize all tables to the original palette.
// At this point we do not care about the transparent index yet.
for (int i = 0; i < 256; i++, colors += 3)
{
BaseColors[i] = PalEntry(255, colors[0], colors[1], colors[2]);
uniqueRemaps[0]->Palette[i] = BaseColors[i] = RawColors[i] = PalEntry(255, colors[0], colors[1], colors[2]);
Remap[i] = i;
}
uniqueRemaps[0]->MakeIdentity(); // update the identity remap.
// If the palette already has a transparent index, clear that color now
if (transparent_index >= 0 && transparent_index <= 255)
{
BaseColors[transparent_index] = 0;
@ -86,8 +88,8 @@ void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index)
// Find white and black from the original palette so that they can be
// used to make an educated guess of the translucency % for a
// translucency map.
WhiteIndex = BestColor((uint32_t*)BaseColors, 255, 255, 255, 0, 255);
BlackIndex = BestColor((uint32_t*)BaseColors, 0, 0, 0, 0, 255);
WhiteIndex = BestColor((uint32_t*)RawColors, 255, 255, 255, 0, 255);
BlackIndex = BestColor((uint32_t*)RawColors, 0, 0, 0, 0, 255);
}
@ -241,6 +243,41 @@ int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap)
return AddTranslation(slot, remap);
}
//===========================================================================
//
// Examines the colormap to see if some of the colors have to be
// considered fullbright all the time.
//
//===========================================================================
void PaletteContainer::GenerateGlobalBrightmapFromColormap(const uint8_t *cmapdata, int numlevels)
{
GlobalBrightmap.MakeIdentity();
memset(GlobalBrightmap.Remap, WhiteIndex, 256);
for (int i = 0; i < 256; i++) GlobalBrightmap.Palette[i] = PalEntry(255, 255, 255, 255);
for (int j = 0; j < numlevels; j++)
{
for (int i = 0; i < 256; i++)
{
// the palette comparison should be for ==0 but that gives false positives with Heretic
// and Hexen.
uint8_t mappedcolor = cmapdata[i]; // consider colormaps which already remap the base level.
if (cmapdata[i + j * 256] != mappedcolor || (RawColors[mappedcolor].r < 10 && RawColors[mappedcolor].g < 10 && RawColors[mappedcolor].b < 10))
{
GlobalBrightmap.Remap[i] = BlackIndex;
GlobalBrightmap.Palette[i] = PalEntry(255, 0, 0, 0);
}
}
}
for (int i = 0; i < 256; i++)
{
HasGlobalBrightmap |= GlobalBrightmap.Remap[i] == WhiteIndex;
if (GlobalBrightmap.Remap[i] == WhiteIndex) DPrintf(DMSG_NOTIFY, "Marked color %d as fullbright\n", i);
}
}
//----------------------------------------------------------------------------
//
//

View file

@ -71,10 +71,15 @@ class PaletteContainer
{
public:
PalEntry BaseColors[256]; // non-gamma corrected palette
PalEntry RawColors[256]; // colors as read from the game data without the transparancy remap applied
uint8_t Remap[256]; // remap original palette indices to in-game indices
uint8_t WhiteIndex; // white in original palette index
uint8_t BlackIndex; // black in original palette index
bool HasGlobalBrightmap;
FRemapTable GlobalBrightmap;
private:
FMemArena remapArena;
TArray<FRemapTable*> uniqueRemaps;
@ -90,6 +95,7 @@ public:
void CopyTranslation(int dest, int src);
int StoreTranslation(int slot, FRemapTable* remap);
FRemapTable* TranslationToTable(int translation);
void GenerateGlobalBrightmapFromColormap(const uint8_t* cmapdata, int numlevels);
void PushIdentityTable(int slot)
{

View file

@ -75,6 +75,7 @@ public:
bool operator !=(const FTextureID &other) const { return texnum != other.texnum; }
FTextureID operator +(int offset) throw();
int GetIndex() const { return texnum; } // Use this only if you absolutely need the index!
void SetIndex(int index) { texnum = index; } // Use this only if you absolutely need the index!
// The switch list needs these to sort the switches by texture index
int operator -(FTextureID other) const { return texnum - other.texnum; }

View file

@ -35,7 +35,6 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "textures/textures.h"

View file

@ -33,12 +33,9 @@
**
*/
#include "doomtype.h"
#include "filesystem.h"
#include "r_data/r_translate.h"
#include "palettecontainer.h"
#include "bitmap.h"
#include "v_video.h"
#include "image.h"
class FBrightmapTexture : public FImageSource
@ -70,11 +67,11 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source)
int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion)
{
SourcePic->CopyTranslatedPixels(bmp, TexMan.GlobalBrightmap.Palette);
SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette);
return 0;
}
FTexture *CreateBrightmapTexture(FImageSource *tex)
{
return new FImageTexture(new FBrightmapTexture(tex));
return CreateImageTexture(new FBrightmapTexture(tex));
}

View file

@ -34,7 +34,6 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "templates.h"
@ -42,7 +41,6 @@
#include "colormatcher.h"
#include "bitmap.h"
#include "textures/textures.h"
#include "r_data/sprites.h"
#include "resourcefile.h"
#include "image.h"
@ -101,113 +99,6 @@ int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion)
}
//===========================================================================
//
// AddTiles
//
// Adds all the tiles in an artfile to the texture manager.
//
//===========================================================================
void FTextureManager::AddTiles (const FString &pathprefix, const void *tiles, int translation)
{
// int numtiles = LittleLong(((uint32_t *)tiles)[1]); // This value is not reliable
int tilestart = LittleLong(((uint32_t *)tiles)[2]);
int tileend = LittleLong(((uint32_t *)tiles)[3]);
const uint16_t *tilesizx = &((const uint16_t *)tiles)[8];
const uint16_t *tilesizy = &tilesizx[tileend - tilestart + 1];
const uint32_t *picanm = (const uint32_t *)&tilesizy[tileend - tilestart + 1];
const uint8_t *tiledata = (const uint8_t *)&picanm[tileend - tilestart + 1];
for (int i = tilestart; i <= tileend; ++i)
{
int pic = i - tilestart;
int width = LittleShort(tilesizx[pic]);
int height = LittleShort(tilesizy[pic]);
uint32_t anm = LittleLong(picanm[pic]);
int xoffs = (int8_t)((anm >> 8) & 255) + width/2;
int yoffs = (int8_t)((anm >> 16) & 255) + height/2;
int size = width*height;
FTextureID texnum;
FTexture *tex;
if (width <= 0 || height <= 0) continue;
tex = new FImageTexture(new FBuildTexture (pathprefix, i, tiledata, translation, width, height, xoffs, yoffs));
texnum = AddTexture (tex);
tiledata += size;
tex->Name.Format("%sBTIL%04d", pathprefix.GetChars(), i);
tex->UseType = ETextureType::Override;
// reactivate only if the texture counter works here.
//StartScreen->Progress();
if ((picanm[pic] & 63) && (picanm[pic] & 192))
{
int type, speed;
switch (picanm[pic] & 192)
{
case 64: type = 2; break;
case 128: type = 0; break;
case 192: type = 1; break;
default: type = 0; break; // Won't happen, but GCC bugs me if I don't put this here.
}
speed = (anm >> 24) & 15;
speed = MAX (1, (1 << speed) * 1000 / 120); // Convert from 120 Hz to 1000 Hz.
AddSimpleAnim (texnum, picanm[pic] & 63, type, speed);
}
// Blood's rotation types:
// 0 - Single
// 1 - 5 Full
// 2 - 8 Full
// 3 - Bounce (looks no different from Single; seems to signal bouncy sprites)
// 4 - 5 Half (not used in game)
// 5 - 3 Flat (not used in game)
// 6 - Voxel
// 7 - Spin Voxel
int rotType = (anm >> 28) & 7;
if (rotType == 1)
{
spriteframe_t rot;
rot.Texture[0] =
rot.Texture[1] = texnum;
for (int j = 1; j < 4; ++j)
{
rot.Texture[j*2] =
rot.Texture[j*2+1] =
rot.Texture[16-j*2] =
rot.Texture[17-j*2] = texnum.GetIndex() + j;
}
rot.Texture[8] =
rot.Texture[9] = texnum.GetIndex() + 4;
rot.Flip = 0x00FC;
rot.Voxel = NULL;
tex->Rotations = SpriteFrames.Push (rot);
}
else if (rotType == 2)
{
spriteframe_t rot;
rot.Texture[0] =
rot.Texture[1] = texnum;
for (int j = 1; j < 8; ++j)
{
rot.Texture[16-j*2] =
rot.Texture[17-j*2] = texnum.GetIndex() + j;
}
rot.Flip = 0;
rot.Voxel = NULL;
tex->Rotations = SpriteFrames.Push (rot);
}
}
}
//===========================================================================
//
// CountTiles
@ -284,6 +175,114 @@ static int BuildPaletteTranslation(int lump)
}
#include "r_data/sprites.h"
//===========================================================================
//
// AddTiles
//
// Adds all the tiles in an artfile to the texture manager.
//
//===========================================================================
void AddTiles(const FString& pathprefix, const void* tiles, int translation)
{
// int numtiles = LittleLong(((uint32_t *)tiles)[1]); // This value is not reliable
int tilestart = LittleLong(((uint32_t*)tiles)[2]);
int tileend = LittleLong(((uint32_t*)tiles)[3]);
const uint16_t* tilesizx = &((const uint16_t*)tiles)[8];
const uint16_t* tilesizy = &tilesizx[tileend - tilestart + 1];
const uint32_t* picanm = (const uint32_t*)&tilesizy[tileend - tilestart + 1];
const uint8_t* tiledata = (const uint8_t*)&picanm[tileend - tilestart + 1];
for (int i = tilestart; i <= tileend; ++i)
{
int pic = i - tilestart;
int width = LittleShort(tilesizx[pic]);
int height = LittleShort(tilesizy[pic]);
uint32_t anm = LittleLong(picanm[pic]);
int xoffs = (int8_t)((anm >> 8) & 255) + width / 2;
int yoffs = (int8_t)((anm >> 16) & 255) + height / 2;
int size = width * height;
FTextureID texnum;
FTexture* tex;
if (width <= 0 || height <= 0) continue;
FStringf name("%sBTIL%04d", pathprefix.GetChars(), i);
tex = new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, translation, width, height, xoffs, yoffs), name);
texnum = TexMan.AddTexture(tex);
tiledata += size;
tex->SetUseType(ETextureType::Override);
// reactivate only if the texture counter works here.
//StartScreen->Progress();
if ((picanm[pic] & 63) && (picanm[pic] & 192))
{
int type, speed;
switch (picanm[pic] & 192)
{
case 64: type = 2; break;
case 128: type = 0; break;
case 192: type = 1; break;
default: type = 0; break; // Won't happen, but GCC bugs me if I don't put this here.
}
speed = (anm >> 24) & 15;
speed = MAX(1, (1 << speed) * 1000 / 120); // Convert from 120 Hz to 1000 Hz.
TexMan.AddSimpleAnim(texnum, picanm[pic] & 63, type, speed);
}
// Blood's rotation types:
// 0 - Single
// 1 - 5 Full
// 2 - 8 Full
// 3 - Bounce (looks no different from Single; seems to signal bouncy sprites)
// 4 - 5 Half (not used in game)
// 5 - 3 Flat (not used in game)
// 6 - Voxel
// 7 - Spin Voxel
int rotType = (anm >> 28) & 7;
if (rotType == 1)
{
spriteframe_t rot;
rot.Texture[0] =
rot.Texture[1] = texnum;
for (int j = 1; j < 4; ++j)
{
rot.Texture[j * 2].SetIndex(texnum.GetIndex() + j);
rot.Texture[j * 2 + 1].SetIndex(texnum.GetIndex() + j);
rot.Texture[16 - j * 2].SetIndex(texnum.GetIndex() + j);
rot.Texture[17 - j * 2].SetIndex(texnum.GetIndex() + j);
}
rot.Texture[8].SetIndex(texnum.GetIndex());
rot.Texture[9].SetIndex(texnum.GetIndex());
rot.Flip = 0x00FC;
rot.Voxel = NULL;
tex->SetRotations(SpriteFrames.Push(rot));
}
else if (rotType == 2)
{
spriteframe_t rot;
rot.Texture[0] =
rot.Texture[1] = texnum;
for (int j = 1; j < 8; ++j)
{
rot.Texture[16 - j * 2].SetIndex(texnum.GetIndex() + j);
rot.Texture[17 - j * 2].SetIndex(texnum.GetIndex() + j);
}
rot.Flip = 0;
rot.Voxel = NULL;
tex->SetRotations(SpriteFrames.Push(rot));
}
}
}
//===========================================================================
//
// R_CountBuildTiles
@ -293,7 +292,7 @@ static int BuildPaletteTranslation(int lump)
//
//===========================================================================
void FTextureManager::InitBuildTiles()
void InitBuildTiles()
{
int lumpnum;
int numtiles;
@ -312,7 +311,7 @@ void FTextureManager::InitBuildTiles()
int numlumps = fileSystem.GetNumEntries();
for (int i = 0; i < numlumps; i++)
{
const char *name = fileSystem.GetFileFullName(i);
const char* name = fileSystem.GetFileFullName(i);
if (fileSystem.CheckNumForFullName(name) != i) continue; // This palette is hidden by a later one. Do not process
FString base = ExtractFileBase(name, true);
base.ToLower();
@ -328,14 +327,13 @@ void FTextureManager::InitBuildTiles()
// only read from the same source as the palette.
// The entire format here is just too volatile to allow liberal mixing.
// An .ART set must be treated as one unit.
lumpnum = fileSystem.CheckNumForFullName(artpath, fileSystem.GetFileContainer(i));
lumpnum = fileSystem.CheckNumForFullName(artpath, fileSystem.GetFileContainer(i));
if (lumpnum < 0)
{
break;
}
BuildTileData.Reserve(1);
auto &artdata = BuildTileData.Last();
auto& artdata = TexMan.GetNewBuildTileData();
artdata.Resize(fileSystem.FileLength(lumpnum));
fileSystem.ReadFile(lumpnum, &artdata[0]);

View file

@ -48,11 +48,9 @@
** the pixel data, it is fairly inefficient to process.
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "bitmap.h"
#include "v_video.h"
#include "imagehelpers.h"
#include "image.h"

View file

@ -35,7 +35,6 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "textures/textures.h"

View file

@ -33,7 +33,6 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "textures/textures.h"

View file

@ -34,10 +34,7 @@
**
*/
#include "doomtype.h"
#include "filesystem.h"
#include "v_palette.h"
#include "v_video.h"
#include "bitmap.h"
#include "image.h"
#include "imagehelpers.h"

View file

@ -33,10 +33,8 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "v_video.h"
#include "bitmap.h"
#include "imagehelpers.h"
#include "image.h"

View file

@ -39,12 +39,10 @@ extern "C"
#include <jpeglib.h>
}
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "v_text.h"
#include "printf.h"
#include "bitmap.h"
#include "v_video.h"
#include "imagehelpers.h"
#include "image.h"

View file

@ -37,7 +37,7 @@
#include <stdint.h>
#include "files.h"
#include "md5.h"
#include "doomtype.h"
#include "printf.h"
struct MD5Check
{

View file

@ -34,25 +34,11 @@
*/
#include <ctype.h>
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "gi.h"
#include "st_start.h"
#include "sc_man.h"
#include "templates.h"
#include "r_data/r_translate.h"
#include "bitmap.h"
#include "colormatcher.h"
#include "v_palette.h"
#include "v_video.h"
#include "v_text.h"
#include "cmdlib.h"
#include "imagehelpers.h"
#include "image.h"
#include "multipatchtexture.h"
#include "imagehelpers.h"
//==========================================================================
//

View file

@ -1,5 +1,7 @@
#pragma once
#include "sc_man.h"
#include "palettecontainer.h"
#include "textures.h"
//==========================================================================
//

View file

@ -33,11 +33,8 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "v_palette.h"
#include "v_video.h"
#include "bitmap.h"
#include "image.h"
#include "imagehelpers.h"
@ -63,7 +60,7 @@ class FPatchTexture : public FImageSource
bool badflag = false;
bool isalpha = false;
public:
FPatchTexture (int lumpnum, patch_t *header, bool isalphatex);
FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
void DetectBadPatches();
@ -127,16 +124,15 @@ static bool CheckIfPatch(FileReader & file, bool &isalpha)
FImageSource *PatchImage_TryCreate(FileReader & file, int lumpnum)
{
patch_t header;
bool isalpha;
if (!CheckIfPatch(file, isalpha)) return NULL;
file.Seek(0, FileReader::SeekSet);
header.width = file.ReadUInt16();
header.height = file.ReadUInt16();
header.leftoffset = file.ReadInt16();
header.topoffset = file.ReadInt16();
return new FPatchTexture(lumpnum, &header, isalpha);
int width = file.ReadUInt16();
int height = file.ReadUInt16();
int leftoffset = file.ReadInt16();
int topoffset = file.ReadInt16();
return new FPatchTexture(lumpnum, width, height, leftoffset, topoffset, isalpha);
}
//==========================================================================
@ -145,15 +141,15 @@ FImageSource *PatchImage_TryCreate(FileReader & file, int lumpnum)
//
//==========================================================================
FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex)
FPatchTexture::FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex)
: FImageSource(lumpnum)
{
bUseGamePalette = !isalphatex;
isalpha = isalphatex;
Width = header->width;
Height = header->height;
LeftOffset = header->leftoffset;
TopOffset = header->topoffset;
Width = w;
Height = h;
LeftOffset = lo;
TopOffset = to;
DetectBadPatches();
}

View file

@ -34,11 +34,9 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "bitmap.h"
#include "v_video.h"
#include "imagehelpers.h"
#include "image.h"

View file

@ -33,7 +33,6 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "templates.h"

View file

@ -33,10 +33,8 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "gi.h"
#include "bitmap.h"
#include "textures/textures.h"
#include "imagehelpers.h"
@ -159,7 +157,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
// Special case hack for Heretic's E2 end pic. This is not going to be exposed as an editing feature because the implications would be horrible.
FString Name;
fileSystem.GetFileShortName(Name, lumpnum);
if (Name.CompareNoCase("E2END") == 0 && gameinfo.gametype == GAME_Heretic)
if (Name.CompareNoCase("E2END") == 0)
{
mPaletteLump = fileSystem.CheckNumForName("E2PAL");
if (fileSystem.FileLength(mPaletteLump) < 768) mPaletteLump = -1;

View file

@ -34,8 +34,6 @@
**
*/
#include "doomtype.h"
#include "d_player.h"
#include "menu/menu.h"
#include "filesystem.h"
#include "bitmap.h"

View file

@ -45,10 +45,8 @@
#include "stb_image.h"
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "v_video.h"
#include "bitmap.h"
#include "imagehelpers.h"
#include "image.h"

View file

@ -33,12 +33,10 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "templates.h"
#include "bitmap.h"
#include "v_video.h"
#include "imagehelpers.h"
#include "image.h"

View file

@ -323,7 +323,7 @@ typedef FImageSource * (*CreateFunc)(FileReader & file, int lumpnum);
struct TexCreateInfo
{
CreateFunc TryCreate;
ETextureType usetype;
bool checkflat;
};
FImageSource *IMGZImage_TryCreate(FileReader &, int lumpnum);
@ -342,21 +342,21 @@ FImageSource *AutomapImage_TryCreate(FileReader &, int lumpnum);
// Examines the lump contents to decide what type of texture to create,
// and creates the texture.
FImageSource * FImageSource::GetImage(int lumpnum, ETextureType usetype)
FImageSource * FImageSource::GetImage(int lumpnum, bool isflat)
{
static TexCreateInfo CreateInfo[] = {
{ IMGZImage_TryCreate, ETextureType::Any },
{ PNGImage_TryCreate, ETextureType::Any },
{ JPEGImage_TryCreate, ETextureType::Any },
{ DDSImage_TryCreate, ETextureType::Any },
{ PCXImage_TryCreate, ETextureType::Any },
{ StbImage_TryCreate, ETextureType::Any },
{ TGAImage_TryCreate, ETextureType::Any },
{ RawPageImage_TryCreate, ETextureType::MiscPatch },
{ FlatImage_TryCreate, ETextureType::Flat },
{ PatchImage_TryCreate, ETextureType::Any },
{ EmptyImage_TryCreate, ETextureType::Any },
{ AutomapImage_TryCreate, ETextureType::MiscPatch },
{ IMGZImage_TryCreate, false },
{ PNGImage_TryCreate, false },
{ JPEGImage_TryCreate, false },
{ DDSImage_TryCreate, false },
{ PCXImage_TryCreate, false },
{ StbImage_TryCreate, false },
{ TGAImage_TryCreate, false },
{ RawPageImage_TryCreate, false },
{ FlatImage_TryCreate, true }, // flat detection is not reliable, so only consider this for real flats.
{ PatchImage_TryCreate, false },
{ EmptyImage_TryCreate, false },
{ AutomapImage_TryCreate, false },
};
if (lumpnum == -1) return nullptr;
@ -377,7 +377,7 @@ FImageSource * FImageSource::GetImage(int lumpnum, ETextureType usetype)
for (size_t i = 0; i < countof(CreateInfo); i++)
{
if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == ETextureType::Any))
if (!CreateInfo[i].checkflat || isflat)
{
auto image = CreateInfo[i].TryCreate(data, lumpnum);
if (image != nullptr)

View file

@ -2,13 +2,22 @@
#include <stdint.h>
#include "tarray.h"
#include "textures.h"
#include "textures/bitmap.h"
#include "memarena.h"
class FImageSource;
using PrecacheInfo = TMap<int, std::pair<int, int>>;
// Doom patch format header
struct patch_t
{
int16_t width; // bounding box size
int16_t height;
int16_t leftoffset; // pixels to the left of origin
int16_t topoffset; // pixels below the origin
uint32_t columnofs[1]; // only [width] used
};
struct PalettedPixels
{
friend class FImageSource;
@ -80,7 +89,7 @@ public:
FBitmap GetCachedBitmap(PalEntry *remap, int conversion, int *trans = nullptr);
static void ClearImages() { ImageArena.FreeAll(); ImageForLump.Clear(); NextID = 0; }
static FImageSource * GetImage(int lumpnum, ETextureType usetype);
static FImageSource * GetImage(int lumpnum, bool checkflat);
@ -137,26 +146,6 @@ public:
static void RegisterForPrecache(FImageSource *img);
};
//==========================================================================
//
// a TGA texture
//
//==========================================================================
class FImageTexture : public FTexture
{
FImageSource *mImage;
public:
FImageTexture (FImageSource *image, const char *name = nullptr);
virtual TArray<uint8_t> Get8BitPixels(bool alphatex);
void SetImage(FImageSource *img) // This is only for the multipatch texture builder!
{
mImage = img;
}
FImageSource *GetImage() const override { return mImage; }
FBitmap GetBgraBitmap(PalEntry *p, int *trans) override;
};
class FTexture;
FTexture* CreateImageTexture(FImageSource* img) noexcept;

View file

@ -40,6 +40,7 @@
#include "bitmap.h"
#include "v_video.h"
#include "image.h"
#include "textures.h"
//==========================================================================
@ -48,7 +49,7 @@
//
//==========================================================================
FImageTexture::FImageTexture(FImageSource *img, const char *name)
FImageTexture::FImageTexture(FImageSource *img, const char *name) noexcept
: FTexture(name, img? img->LumpNum() : 0)
{
mImage = img;
@ -89,24 +90,9 @@ TArray<uint8_t> FImageTexture::Get8BitPixels(bool alpha)
return mImage->GetPalettedPixels(alpha? alpha : bNoRemap0 ? FImageSource::noremap0 : FImageSource::normal);
}
//==========================================================================
//
// FMultiPatchTexture :: GetRawTexture
//
// Doom ignored all compositing of mid-sided textures on two-sided lines.
// Since these textures had to be single-patch in Doom, that essentially
// means it ignores their Y offsets.
//
// If this texture is composed of only one patch, return that patch.
// Otherwise, return this texture, since Doom wouldn't have been able to
// draw it anyway.
//
//==========================================================================
/* todo: this needs to be reimplemented without assuming that the underlying patch will be usable as-is.
FTexture *FMultiPatchTexture::GetRawTexture()
FTexture* CreateImageTexture(FImageSource* img) noexcept
{
return NumParts == 1 && UseType == ETextureType::Wall && bMultiPatch == 1 && Scale == Parts->Texture->Scale ? Parts->Texture : this;
return new FImageTexture(img);
}
*/

View file

@ -94,7 +94,7 @@ FTexture * FTexture::CreateTexture(const char *name, int lumpnum, ETextureType u
{
if (lumpnum == -1) return nullptr;
auto image = FImageSource::GetImage(lumpnum, usetype);
auto image = FImageSource::GetImage(lumpnum, usetype == ETextureType::Flat);
if (image != nullptr)
{
FTexture *tex = new FImageTexture(image);
@ -415,7 +415,7 @@ void FTexture::CreateDefaultBrightmap()
if (!bBrightmapChecked)
{
// Check for brightmaps
if (GetImage() && GetImage()->UseGamePalette() && TexMan.HasGlobalBrightmap &&
if (GetImage() && GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap &&
UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar &&
Brightmap == NULL && bWarped == 0)
{
@ -426,7 +426,7 @@ void FTexture::CreateDefaultBrightmap()
int size = GetTexelWidth() * GetTexelHeight();
for (int i = 0; i<size; i++)
{
if (TexMan.GlobalBrightmap.Remap[texbuf[i]] == white)
if (GPalette.GlobalBrightmap.Remap[texbuf[i]] == white)
{
// Create a brightmap
DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", Name.GetChars());
@ -438,12 +438,12 @@ void FTexture::CreateDefaultBrightmap()
}
// No bright pixels found
DPrintf(DMSG_SPAMMY, "No bright pixels found in texture '%s'\n", Name.GetChars());
bBrightmapChecked = 1;
bBrightmapChecked = true;
}
else
{
// does not have one so set the flag to 'done'
bBrightmapChecked = 1;
bBrightmapChecked = true;
}
}
}

View file

@ -1176,11 +1176,11 @@ void FTextureManager::AddLocalizedVariants()
//
//==========================================================================
FTexture *CreateShaderTexture(bool, bool);
void InitBuildTiles();
void FTextureManager::Init()
{
DeleteAll();
GenerateGlobalBrightmapFromColormap();
SpriteFrames.Clear();
//if (BuildTileFiles.Size() == 0) CountBuildTiles ();
FTexture::InitGrayMap();
@ -1533,55 +1533,6 @@ void FTextureManager::SpriteAdjustChanged()
}
}
//===========================================================================
//
// Examines the colormap to see if some of the colors have to be
// considered fullbright all the time.
//
//===========================================================================
void FTextureManager::GenerateGlobalBrightmapFromColormap()
{
fileSystem.CheckNumForFullName("textures/tgapal", false, 0, true);
HasGlobalBrightmap = false;
int lump = fileSystem.CheckNumForName("COLORMAP");
if (lump == -1) lump = fileSystem.CheckNumForName("COLORMAP", ns_colormaps);
if (lump == -1) return;
FileData cmap = fileSystem.ReadFile(lump);
uint8_t palbuffer[768];
ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer);
const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem();
const uint8_t *paldata = palbuffer;
const int black = 0;
const int white = ColorMatcher.Pick(255, 255, 255);
GlobalBrightmap.MakeIdentity();
memset(GlobalBrightmap.Remap, white, 256);
for (int i = 0; i<256; i++) GlobalBrightmap.Palette[i] = PalEntry(255, 255, 255, 255);
for (int j = 0; j<32; j++)
{
for (int i = 0; i<256; i++)
{
// the palette comparison should be for ==0 but that gives false positives with Heretic
// and Hexen.
if (cmapdata[i + j * 256] != i || (paldata[3 * i]<10 && paldata[3 * i + 1]<10 && paldata[3 * i + 2]<10))
{
GlobalBrightmap.Remap[i] = black;
GlobalBrightmap.Palette[i] = PalEntry(255, 0, 0, 0);
}
}
}
for (int i = 0; i<256; i++)
{
HasGlobalBrightmap |= GlobalBrightmap.Remap[i] == white;
if (GlobalBrightmap.Remap[i] == white) DPrintf(DMSG_NOTIFY, "Marked color %d as fullbright\n", i);
}
}
//==========================================================================
//
//

View file

@ -190,20 +190,6 @@ struct FDoorAnimation
FName CloseSound;
};
// Patches.
// A patch holds one or more columns.
// Patches are used for sprites and all masked pictures, and we compose
// textures from the TEXTURE1/2 lists of patches.
struct patch_t
{
int16_t width; // bounding box size
int16_t height;
int16_t leftoffset; // pixels to the left of origin
int16_t topoffset; // pixels below the origin
uint32_t columnofs[]; // only [width] used
// the [0] is &columnofs[width]
};
// All FTextures present their data to the world in 8-bit format, but if
// the source data is something else, this is it.
enum FTextureFormat : uint32_t
@ -309,10 +295,10 @@ public:
void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly);
// These are mainly meant for 2D code which only needs logical information about the texture to position it properly.
int GetDisplayWidth() { return GetScaledWidth(); }
int GetDisplayHeight() { return GetScaledHeight(); }
double GetDisplayWidthDouble() { return GetScaledWidthDouble(); }
double GetDisplayHeightDouble() { return GetScaledHeightDouble(); }
int GetDisplayWidth() { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); }
int GetDisplayHeight() { int foo = int((Height * 2) / Scale.Y); return (foo >> 1) + (foo & 1); }
double GetDisplayWidthDouble() { return Width / Scale.X; }
double GetDisplayHeightDouble() { return Height / Scale.Y; }
int GetDisplayLeftOffset() { return GetScaledLeftOffset(0); }
int GetDisplayTopOffset() { return GetScaledTopOffset(0); }
double GetDisplayLeftOffsetDouble() { return GetScaledLeftOffsetDouble(0); }
@ -641,17 +627,24 @@ private:
void AdjustSpriteOffsets();
// Build tiles
void AddTiles (const FString &pathprefix, const void *, int translation);
//int CountBuildTiles ();
void InitBuildTiles ();
// Animation stuff
FAnimDef *AddAnim (FAnimDef *anim);
void FixAnimations ();
void InitAnimated ();
void InitAnimDefs ();
public:
FAnimDef *AddSimpleAnim (FTextureID picnum, int animcount, uint32_t speedmin, uint32_t speedrange=0);
FAnimDef *AddComplexAnim (FTextureID picnum, const TArray<FAnimDef::FAnimFrame> &frames);
TArray<uint8_t>& GetNewBuildTileData()
{
BuildTileData.Reserve(1);
return BuildTileData.Last();
}
private:
void ParseAnim (FScanner &sc, ETextureType usetype);
FAnimDef *ParseRangeAnim (FScanner &sc, FTextureID picnum, ETextureType usetype, bool missing);
void ParsePicAnim (FScanner &sc, FTextureID picnum, ETextureType usetype, bool missing, TArray<FAnimDef::FAnimFrame> &frames);
@ -664,8 +657,7 @@ private:
void ParseAnimatedDoor(FScanner &sc);
void InitPalettedVersions();
void GenerateGlobalBrightmapFromColormap();
// Switches
void InitSwitchList ();
@ -695,8 +687,6 @@ private:
public:
TArray<FAnimDef *> mAnimations;
bool HasGlobalBrightmap;
FRemapTable GlobalBrightmap;
short sintable[2048]; // for texture warping
enum
{
@ -761,6 +751,24 @@ public:
}
};
class FImageTexture : public FTexture
{
FImageSource* mImage;
public:
FImageTexture(FImageSource* image, const char* name = nullptr) noexcept;
virtual TArray<uint8_t> Get8BitPixels(bool alphatex);
void SetImage(FImageSource* img) // This is only for the multipatch texture builder!
{
mImage = img;
}
FImageSource* GetImage() const override { return mImage; }
FBitmap GetBgraBitmap(PalEntry* p, int* trans) override;
};
extern FTextureManager TexMan;
struct FTexCoordInfo

View file

@ -158,6 +158,18 @@ void InitPalette ()
GPalette.Init(NUM_TRANSLATION_TABLES);
GPalette.SetPalette (pal, 0);
int lump = fileSystem.CheckNumForName("COLORMAP");
if (lump == -1) lump = fileSystem.CheckNumForName("COLORMAP", ns_colormaps);
if (lump != -1)
{
FileData cmap = fileSystem.ReadFile(lump);
uint8_t palbuffer[768];
ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer);
const unsigned char* cmapdata = (const unsigned char*)cmap.GetMem();
GPalette.GenerateGlobalBrightmapFromColormap(cmapdata, 32);
}
MakeGoodRemap ((uint32_t*)GPalette.BaseColors, GPalette.Remap);
ColorMatcher.SetPalette ((uint32_t *)GPalette.BaseColors);