mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-01-31 13:00:59 +00:00
- reworked how the software renderer manages its textures.
* it's no longer the main texture objects managing the pixel buffer but FSoftwareTexture. * create proper spans for true color textures. The paletted spans only match if the image does not have any translucent pixels. * create proper warp textures instead of working off the paletted variants. As a side effect, caching of pixel buffers for texture composition is temporarily disabled, as it management of texture redirections. These things will be reimplemented once things progress further. The existing methods here had their share of serious issues that should be fixed.
This commit is contained in:
parent
69cc1f831c
commit
82bd742ea3
31 changed files with 322 additions and 506 deletions
|
@ -91,14 +91,18 @@ void PolyRenderThread::PrepareTexture(FSoftwareTexture *texture, FRenderStyle st
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(loadmutex);
|
std::unique_lock<std::mutex> lock(loadmutex);
|
||||||
|
|
||||||
texture->GetPixels(style);
|
|
||||||
const FSoftwareTextureSpan *spans;
|
const FSoftwareTextureSpan *spans;
|
||||||
texture->GetColumn(style, 0, &spans);
|
|
||||||
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||||
{
|
{
|
||||||
texture->GetPixelsBgra();
|
texture->GetPixelsBgra();
|
||||||
texture->GetColumnBgra(0, &spans);
|
texture->GetColumnBgra(0, &spans);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
|
||||||
|
texture->GetPixels(alpha);
|
||||||
|
texture->GetColumn(alpha, 0, &spans);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolyRenderThread::PreparePolyObject(subsector_t *sub)
|
void PolyRenderThread::PreparePolyObject(subsector_t *sub)
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
||||||
bool UseBasePalette() override { return false; }
|
bool UseBasePalette() override { return false; }
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FVoxel *SourceVox;
|
FVoxel *SourceVox;
|
||||||
|
@ -79,10 +79,10 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox)
|
||||||
//
|
//
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
uint8_t *FVoxelTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FVoxelTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
// GetPixels gets called when a translated palette is used so we still need to implement it here.
|
// GetPixels gets called when a translated palette is used so we still need to implement it here.
|
||||||
auto Pixels = new uint8_t[256];
|
TArray<uint8_t> Pixels(256, true);
|
||||||
uint8_t *pp = SourceVox->Palette;
|
uint8_t *pp = SourceVox->Palette;
|
||||||
|
|
||||||
if(pp != NULL)
|
if(pp != NULL)
|
||||||
|
@ -94,7 +94,7 @@ uint8_t *FVoxelTexture::MakeTexture (FRenderStyle style)
|
||||||
pe.g = (pp[1] << 2) | (pp[1] >> 4);
|
pe.g = (pp[1] << 2) | (pp[1] >> 4);
|
||||||
pe.b = (pp[2] << 2) | (pp[2] >> 4);
|
pe.b = (pp[2] << 2) | (pp[2] >> 4);
|
||||||
// Alphatexture handling is just for completeness, but rather unlikely to be used ever.
|
// Alphatexture handling is just for completeness, but rather unlikely to be used ever.
|
||||||
Pixels[i] = (style.Flags & STYLEF_RedIsAlpha)? pe.r : ColorMatcher.Pick(pe);
|
Pixels[i] = alphatex? pe.r : ColorMatcher.Pick(pe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1163,7 +1163,7 @@ void FCanvasTextureInfo::EmptyList ()
|
||||||
for (probe = List; probe != NULL; probe = next)
|
for (probe = List; probe != NULL; probe = next)
|
||||||
{
|
{
|
||||||
next = probe->Next;
|
next = probe->Next;
|
||||||
probe->Texture->Unload();
|
//probe->Texture->Unload();
|
||||||
delete probe;
|
delete probe;
|
||||||
}
|
}
|
||||||
List = NULL;
|
List = NULL;
|
||||||
|
|
|
@ -106,14 +106,18 @@ namespace swrenderer
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(loadmutex);
|
std::unique_lock<std::mutex> lock(loadmutex);
|
||||||
|
|
||||||
texture->GetPixels(style);
|
|
||||||
const FSoftwareTextureSpan *spans;
|
const FSoftwareTextureSpan *spans;
|
||||||
texture->GetColumn(style, 0, &spans);
|
|
||||||
if (Viewport->RenderTarget->IsBgra())
|
if (Viewport->RenderTarget->IsBgra())
|
||||||
{
|
{
|
||||||
texture->GetPixelsBgra();
|
texture->GetPixelsBgra();
|
||||||
texture->GetColumnBgra(0, &spans);
|
texture->GetColumnBgra(0, &spans);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
|
||||||
|
texture->GetPixels(alpha);
|
||||||
|
texture->GetColumn(alpha, 0, &spans);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderThread::PreparePolyObject(subsector_t *sub)
|
void RenderThread::PreparePolyObject(subsector_t *sub)
|
||||||
|
|
|
@ -39,7 +39,16 @@
|
||||||
#include "m_alloc.h"
|
#include "m_alloc.h"
|
||||||
|
|
||||||
|
|
||||||
|
FSoftwareTexture *FTexture::GetSoftwareTexture()
|
||||||
|
{
|
||||||
|
if (!SoftwareTexture)
|
||||||
|
{
|
||||||
|
if (bWarped) SoftwareTexture = new FWarpTexture(this, bWarped);
|
||||||
|
// else if (GetRedirect() != this) ... must be decided later. The current data structures make it hard to do this without creating a mess.
|
||||||
|
else SoftwareTexture = new FSoftwareTexture(this);
|
||||||
|
}
|
||||||
|
return SoftwareTexture;
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -74,32 +83,31 @@ void FSoftwareTexture::CalcBitSize ()
|
||||||
HeightBits = i;
|
HeightBits = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
const uint32_t *FSoftwareTexture::GetColumnBgra(unsigned int column, const FSoftwareTextureSpan **spans_out)
|
const uint8_t *FSoftwareTexture::GetPixels(int style)
|
||||||
{
|
{
|
||||||
const uint32_t *pixels = GetPixelsBgra();
|
if (Pixels.Size() == 0 || CheckModified(style))
|
||||||
if (pixels == nullptr) return nullptr;
|
{
|
||||||
|
Pixels = mSource->Get8BitPixels(style);
|
||||||
column %= GetWidth();
|
|
||||||
|
|
||||||
if (spans_out != nullptr)
|
|
||||||
GetColumn(DefaultRenderStyle(), column, spans_out); // This isn't the right way to create the spans.
|
|
||||||
return pixels + column * GetHeight();
|
|
||||||
}
|
}
|
||||||
|
return Pixels.Data();
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
const uint32_t *FSoftwareTexture::GetPixelsBgra()
|
const uint32_t *FSoftwareTexture::GetPixelsBgra()
|
||||||
{
|
{
|
||||||
if (PixelsBgra.Size() == 0 || CheckModified(DefaultRenderStyle()))
|
if (PixelsBgra.Size() == 0 || CheckModified(2))
|
||||||
{
|
{
|
||||||
if (!GetColumn(DefaultRenderStyle(), 0, nullptr))
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
FBitmap bitmap;
|
FBitmap bitmap;
|
||||||
bitmap.Create(GetWidth(), GetHeight());
|
bitmap.Create(GetWidth(), GetHeight());
|
||||||
mTexture->CopyTrueColorPixels(&bitmap, 0, 0);
|
mTexture->CopyTrueColorPixels(&bitmap, 0, 0);
|
||||||
|
@ -114,7 +122,80 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const uint8_t *pixels)
|
const uint8_t *FSoftwareTexture::GetColumn(int index, unsigned int column, const FSoftwareTextureSpan **spans_out)
|
||||||
|
{
|
||||||
|
auto Pixeldata = GetPixels(index);
|
||||||
|
if ((unsigned)column >= (unsigned)GetWidth())
|
||||||
|
{
|
||||||
|
if (WidthMask + 1 == GetWidth())
|
||||||
|
{
|
||||||
|
column &= WidthMask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
column %= GetWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (spans_out != nullptr)
|
||||||
|
{
|
||||||
|
if (Spandata[index] == nullptr)
|
||||||
|
{
|
||||||
|
Spandata[index] = CreateSpans(Pixeldata);
|
||||||
|
}
|
||||||
|
*spans_out = Spandata[index][column];
|
||||||
|
}
|
||||||
|
return Pixeldata + column * GetHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
const uint32_t *FSoftwareTexture::GetColumnBgra(unsigned int column, const FSoftwareTextureSpan **spans_out)
|
||||||
|
{
|
||||||
|
auto Pixeldata = GetPixelsBgra();
|
||||||
|
if ((unsigned)column >= (unsigned)GetWidth())
|
||||||
|
{
|
||||||
|
if (WidthMask + 1 == GetWidth())
|
||||||
|
{
|
||||||
|
column &= WidthMask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
column %= GetWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (spans_out != nullptr)
|
||||||
|
{
|
||||||
|
if (Spandata[2] == nullptr)
|
||||||
|
{
|
||||||
|
Spandata[2] = CreateSpans(Pixeldata);
|
||||||
|
}
|
||||||
|
*spans_out = Spandata[2][column];
|
||||||
|
}
|
||||||
|
return Pixeldata + column * GetHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
static bool isTranslucent(uint8_t val)
|
||||||
|
{
|
||||||
|
return val == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isTranslucent(uint32_t val)
|
||||||
|
{
|
||||||
|
return (val & 0xff000000) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const T *pixels)
|
||||||
{
|
{
|
||||||
FSoftwareTextureSpan **spans, *span;
|
FSoftwareTextureSpan **spans, *span;
|
||||||
|
|
||||||
|
@ -136,7 +217,7 @@ FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const uint8_t *pixels)
|
||||||
int numcols = GetWidth();
|
int numcols = GetWidth();
|
||||||
int numrows = GetHeight();
|
int numrows = GetHeight();
|
||||||
int numspans = numcols; // One span to terminate each column
|
int numspans = numcols; // One span to terminate each column
|
||||||
const uint8_t *data_p;
|
const T *data_p;
|
||||||
bool newspan;
|
bool newspan;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
|
@ -149,7 +230,7 @@ FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const uint8_t *pixels)
|
||||||
for (y = numrows; y > 0; --y)
|
for (y = numrows; y > 0; --y)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (*data_p++ == 0)
|
if (isTranslucent(*data_p++))
|
||||||
{
|
{
|
||||||
if (!newspan)
|
if (!newspan)
|
||||||
{
|
{
|
||||||
|
@ -174,7 +255,7 @@ FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const uint8_t *pixels)
|
||||||
spans[x] = span;
|
spans[x] = span;
|
||||||
for (y = 0; y < numrows; ++y)
|
for (y = 0; y < numrows; ++y)
|
||||||
{
|
{
|
||||||
if (*data_p++ == 0)
|
if (isTranslucent(*data_p++))
|
||||||
{
|
{
|
||||||
if (!newspan)
|
if (!newspan)
|
||||||
{
|
{
|
||||||
|
@ -441,41 +522,9 @@ void FSoftwareTexture::GenerateBgraMipmapsFast()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
const uint8_t *FSoftwareTexture::GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out)
|
|
||||||
{
|
|
||||||
int index = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
auto Pixeldata = GetPixels(style);
|
|
||||||
if ((unsigned)column >= (unsigned)GetWidth())
|
|
||||||
{
|
|
||||||
if (WidthMask + 1 == GetWidth())
|
|
||||||
{
|
|
||||||
column &= WidthMask;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
column %= GetWidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (spans_out != nullptr)
|
|
||||||
{
|
|
||||||
if (Spandata[index] == nullptr)
|
|
||||||
{
|
|
||||||
Spandata[index] = CreateSpans (Pixeldata);
|
|
||||||
}
|
|
||||||
*spans_out = Spandata[index][column];
|
|
||||||
}
|
|
||||||
return Pixeldata + column*GetHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FSoftwareTexture::FreeAllSpans()
|
void FSoftwareTexture::FreeAllSpans()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 2; i++)
|
for(int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
if (Spandata[i] != nullptr)
|
if (Spandata[i] != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,12 +15,16 @@ class FSoftwareTexture
|
||||||
protected:
|
protected:
|
||||||
FTexture *mTexture;
|
FTexture *mTexture;
|
||||||
FTexture *mSource;
|
FTexture *mSource;
|
||||||
|
TArray<uint8_t> Pixels;
|
||||||
TArray<uint32_t> PixelsBgra;
|
TArray<uint32_t> PixelsBgra;
|
||||||
FSoftwareTextureSpan **Spandata[2] = { nullptr, nullptr };
|
FSoftwareTextureSpan **Spandata[3] = { };
|
||||||
uint8_t WidthBits = 0, HeightBits = 0;
|
uint8_t WidthBits = 0, HeightBits = 0;
|
||||||
uint16_t WidthMask = 0;
|
uint16_t WidthMask = 0;
|
||||||
|
|
||||||
|
void FreeAllSpans();
|
||||||
|
template<class T> FSoftwareTextureSpan **CreateSpans(const T *pixels);
|
||||||
|
void FreeSpans(FSoftwareTextureSpan **spans);
|
||||||
|
void CalcBitSize();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FSoftwareTexture(FTexture *tex)
|
FSoftwareTexture(FTexture *tex)
|
||||||
|
@ -51,7 +55,6 @@ public:
|
||||||
return mTexture->bMasked;
|
return mTexture->bMasked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcBitSize();
|
|
||||||
bool UseBasePalette() const { return mTexture->UseBasePalette(); }
|
bool UseBasePalette() const { return mTexture->UseBasePalette(); }
|
||||||
int GetSkyOffset() const { return mTexture->GetSkyOffset(); }
|
int GetSkyOffset() const { return mTexture->GetSkyOffset(); }
|
||||||
PalEntry GetSkyCapColor(bool bottom) const { return mTexture->GetSkyCapColor(bottom); }
|
PalEntry GetSkyCapColor(bool bottom) const { return mTexture->GetSkyCapColor(bottom); }
|
||||||
|
@ -93,35 +96,25 @@ public:
|
||||||
|
|
||||||
DVector2 GetScale() const { return mTexture->Scale; }
|
DVector2 GetScale() const { return mTexture->Scale; }
|
||||||
|
|
||||||
// Returns the whole texture, stored in column-major order
|
|
||||||
virtual const uint8_t *GetPixels(FRenderStyle style)
|
|
||||||
{
|
|
||||||
return mTexture->Get8BitPixels(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Unload()
|
void Unload()
|
||||||
{
|
{
|
||||||
mTexture->Unload();
|
Pixels.Reset();
|
||||||
PixelsBgra.Reset();
|
PixelsBgra.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the next call to GetPixels() will return an image different from the
|
// Returns true if the next call to GetPixels() will return an image different from the
|
||||||
// last call to GetPixels(). This should be considered valid only if a call to CheckModified()
|
// last call to GetPixels(). This should be considered valid only if a call to CheckModified()
|
||||||
// is immediately followed by a call to GetPixels().
|
// is immediately followed by a call to GetPixels().
|
||||||
virtual bool CheckModified (FRenderStyle style) { return false; }
|
virtual bool CheckModified (int which) { return false; }
|
||||||
|
|
||||||
void GenerateBgraFromBitmap(const FBitmap &bitmap);
|
void GenerateBgraFromBitmap(const FBitmap &bitmap);
|
||||||
void CreatePixelsBgraWithMipmaps();
|
void CreatePixelsBgraWithMipmaps();
|
||||||
void GenerateBgraMipmaps();
|
void GenerateBgraMipmaps();
|
||||||
void GenerateBgraMipmapsFast();
|
void GenerateBgraMipmapsFast();
|
||||||
int MipmapLevels();
|
int MipmapLevels();
|
||||||
void FreeAllSpans();
|
|
||||||
|
|
||||||
FSoftwareTextureSpan **CreateSpans (const uint8_t *pixels);
|
|
||||||
void FreeSpans (FSoftwareTextureSpan **spans);
|
|
||||||
|
|
||||||
// Returns a single column of the texture
|
// Returns a single column of the texture
|
||||||
virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out);
|
virtual const uint8_t *GetColumn(int style, unsigned int column, const FSoftwareTextureSpan **spans_out);
|
||||||
|
|
||||||
// Returns a single column of the texture, in BGRA8 format
|
// Returns a single column of the texture, in BGRA8 format
|
||||||
virtual const uint32_t *GetColumnBgra(unsigned int column, const FSoftwareTextureSpan **spans_out);
|
virtual const uint32_t *GetColumnBgra(unsigned int column, const FSoftwareTextureSpan **spans_out);
|
||||||
|
@ -129,6 +122,20 @@ public:
|
||||||
// Returns the whole texture, stored in column-major order, in BGRA8 format
|
// Returns the whole texture, stored in column-major order, in BGRA8 format
|
||||||
virtual const uint32_t *GetPixelsBgra();
|
virtual const uint32_t *GetPixelsBgra();
|
||||||
|
|
||||||
|
// Returns the whole texture, stored in column-major order
|
||||||
|
virtual const uint8_t *GetPixels(int style);
|
||||||
|
|
||||||
|
const uint8_t *GetPixels(FRenderStyle style)
|
||||||
|
{
|
||||||
|
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
|
||||||
|
return GetPixels(alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out)
|
||||||
|
{
|
||||||
|
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
|
||||||
|
return GetColumn(alpha, column, spans_out);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,32 +143,21 @@ public:
|
||||||
class FWarpTexture : public FSoftwareTexture
|
class FWarpTexture : public FSoftwareTexture
|
||||||
{
|
{
|
||||||
TArray<uint8_t> WarpedPixels[2];
|
TArray<uint8_t> WarpedPixels[2];
|
||||||
|
TArray<uint32_t> WarpedPixelsRgba;
|
||||||
|
|
||||||
int bWarped = 0;
|
int bWarped = 0;
|
||||||
|
uint64_t GenTime[3] = { 0, 0, 0 };
|
||||||
|
int WidthOffsetMultiplier, HeightOffsetMultiplier; // [mxd]
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FWarpTexture (FTexture *source, int warptype);
|
FWarpTexture (FTexture *source, int warptype);
|
||||||
|
|
||||||
const uint32_t *GetPixelsBgra() override;
|
const uint32_t *GetPixelsBgra() override;
|
||||||
bool CheckModified (FRenderStyle) override;
|
const uint8_t *GetPixels(int style) override;
|
||||||
|
bool CheckModified (int which) override;
|
||||||
|
|
||||||
float GetSpeed() const { return mTexture->shaderspeed; }
|
private:
|
||||||
|
|
||||||
uint64_t GenTime[2] = { 0, 0 };
|
|
||||||
uint64_t GenTimeBgra = 0;
|
|
||||||
int WidthOffsetMultiplier, HeightOffsetMultiplier; // [mxd]
|
|
||||||
protected:
|
|
||||||
|
|
||||||
const uint8_t *GetPixels(FRenderStyle style);
|
|
||||||
int NextPo2 (int v); // [mxd]
|
int NextPo2 (int v); // [mxd]
|
||||||
void SetupMultipliers (int width, int height); // [mxd]
|
void SetupMultipliers (int width, int height); // [mxd]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline FSoftwareTexture *FTexture::GetSoftwareTexture()
|
|
||||||
{
|
|
||||||
if (!SoftwareTexture)
|
|
||||||
{
|
|
||||||
if (bWarped) SoftwareTexture = new FWarpTexture(this, bWarped);
|
|
||||||
else SoftwareTexture = new FSoftwareTexture(this);
|
|
||||||
}
|
|
||||||
return SoftwareTexture;
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,38 +49,32 @@ FWarpTexture::FWarpTexture (FTexture *source, int warptype)
|
||||||
bWarped = warptype;
|
bWarped = warptype;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FWarpTexture::CheckModified (FRenderStyle style)
|
bool FWarpTexture::CheckModified (int style)
|
||||||
{
|
{
|
||||||
return screen->FrameTime != GenTime[!!(style.Flags & STYLEF_RedIsAlpha)];
|
return screen->FrameTime != GenTime[style];
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t *FWarpTexture::GetPixelsBgra()
|
const uint32_t *FWarpTexture::GetPixelsBgra()
|
||||||
{
|
{
|
||||||
auto Pixels = GetPixels(DefaultRenderStyle());
|
uint64_t time = screen->FrameTime;
|
||||||
if (PixelsBgra.Size() == 0 || GenTime[0] != GenTimeBgra)
|
if (time != GenTime[2])
|
||||||
{
|
{
|
||||||
CreatePixelsBgraWithMipmaps();
|
auto otherpix = FSoftwareTexture::GetPixelsBgra();
|
||||||
for (int i = 0; i < GetWidth() * GetHeight(); i++)
|
WarpedPixelsRgba.Resize(GetWidth() * GetHeight());
|
||||||
{
|
WarpBuffer(WarpedPixelsRgba.Data(), otherpix, GetWidth(), GetHeight(), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped);
|
||||||
if (Pixels[i] != 0)
|
FreeAllSpans();
|
||||||
PixelsBgra[i] = 0xff000000 | GPalette.BaseColors[Pixels[i]].d;
|
GenTime[2] = time;
|
||||||
else
|
|
||||||
PixelsBgra[i] = 0;
|
|
||||||
}
|
}
|
||||||
GenerateBgraMipmapsFast();
|
return WarpedPixelsRgba.Data();
|
||||||
GenTimeBgra = GenTime[0];
|
|
||||||
}
|
|
||||||
return PixelsBgra.Data();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const uint8_t *FWarpTexture::GetPixels(FRenderStyle style)
|
const uint8_t *FWarpTexture::GetPixels(int index)
|
||||||
{
|
{
|
||||||
int index = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
uint64_t time = screen->FrameTime;
|
uint64_t time = screen->FrameTime;
|
||||||
if (time != GenTime[index])
|
if (time != GenTime[index])
|
||||||
{
|
{
|
||||||
const uint8_t *otherpix = FSoftwareTexture::GetPixels(style);
|
const uint8_t *otherpix = FSoftwareTexture::GetPixels(index);
|
||||||
WarpedPixels[index].Resize(GetWidth() * GetHeight());
|
WarpedPixels[index].Resize(GetWidth() * GetHeight());
|
||||||
WarpBuffer(WarpedPixels[index].Data(), otherpix, GetWidth(), GetHeight(), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped);
|
WarpBuffer(WarpedPixels[index].Data(), otherpix, GetWidth(), GetHeight(), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped);
|
||||||
FreeAllSpans();
|
FreeAllSpans();
|
||||||
|
|
|
@ -50,7 +50,7 @@ class FAutomapTexture : public FWorldTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FAutomapTexture(int lumpnum);
|
FAutomapTexture(int lumpnum);
|
||||||
uint8_t *MakeTexture (FRenderStyle style);
|
TArray<uint8_t> Get8BitPixels(bool alphatex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,15 +88,15 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FAutomapTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FAutomapTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
FMemLump data = Wads.ReadLump (SourceLump);
|
FMemLump data = Wads.ReadLump (SourceLump);
|
||||||
const uint8_t *indata = (const uint8_t *)data.GetMem();
|
const uint8_t *indata = (const uint8_t *)data.GetMem();
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width * Height];
|
TArray<uint8_t> Pixels(Width * Height, true);
|
||||||
|
|
||||||
const uint8_t *remap = GetRemap(style);
|
const uint8_t *remap = GetRemap(alphatex);
|
||||||
for (x = 0; x < Width; ++x)
|
for (x = 0; x < Width; ++x)
|
||||||
{
|
{
|
||||||
for (y = 0; y < Height; ++y)
|
for (y = 0; y < Height; ++y)
|
||||||
|
|
|
@ -45,7 +45,6 @@ class FBrightmapTexture : public FWorldTexture
|
||||||
public:
|
public:
|
||||||
FBrightmapTexture (FTexture *source);
|
FBrightmapTexture (FTexture *source);
|
||||||
|
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override;
|
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
||||||
bool UseBasePalette() override { return false; }
|
bool UseBasePalette() override { return false; }
|
||||||
|
|
||||||
|
@ -74,13 +73,6 @@ FBrightmapTexture::FBrightmapTexture (FTexture *source)
|
||||||
SourceLump = -1;
|
SourceLump = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *FBrightmapTexture::MakeTexture(FRenderStyle style)
|
|
||||||
{
|
|
||||||
// This function is only necessary to satisfy the parent class's interface.
|
|
||||||
// This will never be called.
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FBrightmapTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
int FBrightmapTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
||||||
{
|
{
|
||||||
SourcePic->CopyTrueColorTranslated(bmp, x, y, rotate, TexMan.GlobalBrightmap.Palette);
|
SourcePic->CopyTrueColorTranslated(bmp, x, y, rotate, TexMan.GlobalBrightmap.Palette);
|
||||||
|
|
|
@ -56,7 +56,7 @@ class FBuildTexture : public FWorldTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FBuildTexture (const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top);
|
FBuildTexture (const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top);
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
|
||||||
bool UseBasePalette() override { return false; }
|
bool UseBasePalette() override { return false; }
|
||||||
FTextureFormat GetFormat() override { return TEX_RGB; }
|
FTextureFormat GetFormat() override { return TEX_RGB; }
|
||||||
|
@ -76,7 +76,6 @@ protected:
|
||||||
FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top)
|
FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top)
|
||||||
: RawPixels (pixels), Translation(translation)
|
: RawPixels (pixels), Translation(translation)
|
||||||
{
|
{
|
||||||
PixelsAreStatic = 3;
|
|
||||||
Width = width;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
_LeftOffset[1] = _LeftOffset[0] = left;
|
_LeftOffset[1] = _LeftOffset[0] = left;
|
||||||
|
@ -85,16 +84,16 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8
|
||||||
UseType = ETextureType::Override;
|
UseType = ETextureType::Override;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *FBuildTexture::MakeTexture(FRenderStyle style)
|
TArray<uint8_t> FBuildTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
auto Pixels = new uint8_t[Width * Height];
|
TArray<uint8_t> Pixels(Width * Height, true);
|
||||||
FRemapTable *Remap = translationtables[TRANSLATION_Standard][Translation];
|
FRemapTable *Remap = translationtables[TRANSLATION_Standard][Translation];
|
||||||
for (int i = 0; i < Width*Height; i++)
|
for (int i = 0; i < Width*Height; i++)
|
||||||
{
|
{
|
||||||
auto c = RawPixels[i];
|
auto c = RawPixels[i];
|
||||||
Pixels[i] = (style.Flags & STYLEF_RedIsAlpha) ? Remap->Palette[c].Luminance() : Remap->Remap[c];
|
Pixels[i] = alphatex ? Remap->Palette[c].Luminance() : Remap->Remap[c];
|
||||||
}
|
}
|
||||||
return (uint8_t*)Pixels;
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FBuildTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
int FBuildTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
||||||
|
|
|
@ -51,12 +51,9 @@ FCanvasTexture::FCanvasTexture (const char *name, int width, int height)
|
||||||
bPixelsAllocated = false;
|
bPixelsAllocated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FCanvasTexture::~FCanvasTexture ()
|
|
||||||
{
|
|
||||||
Unload ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint8_t *FCanvasTexture::Get8BitPixels (FRenderStyle style)
|
#if 0
|
||||||
|
const uint8_t *FCanvasTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
bNeedsUpdate = true;
|
bNeedsUpdate = true;
|
||||||
if (Canvas == NULL)
|
if (Canvas == NULL)
|
||||||
|
@ -66,7 +63,6 @@ const uint8_t *FCanvasTexture::Get8BitPixels (FRenderStyle style)
|
||||||
return Pixels;
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
const uint32_t *FCanvasTexture::GetPixelsBgra()
|
const uint32_t *FCanvasTexture::GetPixelsBgra()
|
||||||
{
|
{
|
||||||
bNeedsUpdate = true;
|
bNeedsUpdate = true;
|
||||||
|
@ -76,7 +72,6 @@ const uint32_t *FCanvasTexture::GetPixelsBgra()
|
||||||
}
|
}
|
||||||
return PixelsBgra;
|
return PixelsBgra;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style because making it work as alpha texture is impractical.
|
void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style because making it work as alpha texture is impractical.
|
||||||
{
|
{
|
||||||
|
@ -97,6 +92,7 @@ void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style
|
||||||
memset (Pixels, 0, Width*Height/2);
|
memset (Pixels, 0, Width*Height/2);
|
||||||
memset (Pixels+Width*Height/2, 255, Width*Height/2);
|
memset (Pixels+Width*Height/2, 255, Width*Height/2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void FCanvasTexture::MakeTextureBgra()
|
void FCanvasTexture::MakeTextureBgra()
|
||||||
{
|
{
|
||||||
|
@ -118,6 +114,7 @@ void FCanvasTexture::MakeTextureBgra()
|
||||||
memset(PixelsBgra + Width*Height / 2, 255, Width*Height / 2 * 4);
|
memset(PixelsBgra + Width*Height / 2, 255, Width*Height / 2 * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void FCanvasTexture::Unload ()
|
void FCanvasTexture::Unload ()
|
||||||
{
|
{
|
||||||
if (bPixelsAllocated)
|
if (bPixelsAllocated)
|
||||||
|
@ -148,6 +145,7 @@ void FCanvasTexture::Unload ()
|
||||||
|
|
||||||
FTexture::Unload();
|
FTexture::Unload();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool FCanvasTexture::CheckModified (FRenderStyle)
|
bool FCanvasTexture::CheckModified (FRenderStyle)
|
||||||
{
|
{
|
||||||
|
|
|
@ -163,7 +163,7 @@ public:
|
||||||
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);
|
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);
|
||||||
|
|
||||||
FTextureFormat GetFormat () override;
|
FTextureFormat GetFormat () override;
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t Format;
|
uint32_t Format;
|
||||||
|
@ -398,30 +398,30 @@ FTextureFormat FDDSTexture::GetFormat()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FDDSTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FDDSTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
auto lump = Wads.OpenLumpReader (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
|
|
||||||
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet);
|
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet);
|
||||||
|
|
||||||
int pmode = (style.Flags & STYLEF_RedIsAlpha) ? PIX_Alphatex : PIX_Palette;
|
int pmode = alphatex ? PIX_Alphatex : PIX_Palette;
|
||||||
if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel
|
if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel
|
||||||
{
|
{
|
||||||
ReadRGB (lump, Pixels, pmode);
|
ReadRGB (lump, Pixels.Data(), pmode);
|
||||||
}
|
}
|
||||||
else if (Format == ID_DXT1)
|
else if (Format == ID_DXT1)
|
||||||
{
|
{
|
||||||
DecompressDXT1 (lump, Pixels, pmode);
|
DecompressDXT1 (lump, Pixels.Data(), pmode);
|
||||||
}
|
}
|
||||||
else if (Format == ID_DXT3 || Format == ID_DXT2)
|
else if (Format == ID_DXT3 || Format == ID_DXT2)
|
||||||
{
|
{
|
||||||
DecompressDXT3 (lump, Format == ID_DXT2, Pixels, pmode);
|
DecompressDXT3 (lump, Format == ID_DXT2, Pixels.Data(), pmode);
|
||||||
}
|
}
|
||||||
else if (Format == ID_DXT5 || Format == ID_DXT4)
|
else if (Format == ID_DXT5 || Format == ID_DXT4)
|
||||||
{
|
{
|
||||||
DecompressDXT5 (lump, Format == ID_DXT4, Pixels, pmode);
|
DecompressDXT5 (lump, Format == ID_DXT4, Pixels.Data(), pmode);
|
||||||
}
|
}
|
||||||
return Pixels;
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,9 @@
|
||||||
|
|
||||||
class FEmptyTexture : public FWorldTexture
|
class FEmptyTexture : public FWorldTexture
|
||||||
{
|
{
|
||||||
uint8_t Pixel = 0;
|
|
||||||
public:
|
public:
|
||||||
FEmptyTexture (int lumpnum);
|
FEmptyTexture (int lumpnum);
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -82,7 +81,6 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
|
||||||
{
|
{
|
||||||
bMasked = true;
|
bMasked = true;
|
||||||
Width = Height = 1;
|
Width = Height = 1;
|
||||||
PixelsAreStatic = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -91,8 +89,10 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FEmptyTexture::MakeTexture(FRenderStyle style)
|
TArray<uint8_t> FEmptyTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
return &Pixel;
|
TArray<uint8_t> Pixel(1, true);
|
||||||
|
Pixel[0] = 0;
|
||||||
|
return Pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class FFlatTexture : public FWorldTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FFlatTexture (int lumpnum);
|
FFlatTexture (int lumpnum);
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,16 +101,16 @@ FFlatTexture::FFlatTexture (int lumpnum)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FFlatTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FFlatTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
auto lump = Wads.OpenLumpReader (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
auto numread = lump.Read (Pixels, Width*Height);
|
auto numread = lump.Read (Pixels.Data(), Width*Height);
|
||||||
if (numread < Width*Height)
|
if (numread < Width*Height)
|
||||||
{
|
{
|
||||||
memset (Pixels + numread, 0xBB, Width*Height - numread);
|
memset (Pixels.Data() + numread, 0xBB, Width*Height - numread);
|
||||||
}
|
}
|
||||||
FTexture::FlipSquareBlockRemap(Pixels, Width, Height, GetRemap(style));
|
FTexture::FlipSquareBlockRemap(Pixels.Data(), Width, Height, GetRemap(alphatex));
|
||||||
return Pixels;
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class FIMGZTexture : public FWorldTexture
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha);
|
FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha);
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
||||||
|
|
||||||
bool UseBasePalette() override { return !isalpha; }
|
bool UseBasePalette() override { return !isalpha; }
|
||||||
|
@ -121,7 +121,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FIMGZTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FIMGZTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
FMemLump lump = Wads.ReadLump (SourceLump);
|
FMemLump lump = Wads.ReadLump (SourceLump);
|
||||||
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
|
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
|
||||||
|
@ -131,10 +131,10 @@ uint8_t *FIMGZTexture::MakeTexture (FRenderStyle style)
|
||||||
int dest_adv = Height;
|
int dest_adv = Height;
|
||||||
int dest_rew = Width * Height - 1;
|
int dest_rew = Width * Height - 1;
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
dest_p = Pixels;
|
dest_p = Pixels.Data();
|
||||||
|
|
||||||
const uint8_t *remap = GetRemap(style, isalpha);
|
const uint8_t *remap = GetRemap(alphatex, isalpha);
|
||||||
|
|
||||||
// Convert the source image from row-major to column-major format and remap it
|
// Convert the source image from row-major to column-major format and remap it
|
||||||
if (!imgz->Compression)
|
if (!imgz->Compression)
|
||||||
|
|
|
@ -186,7 +186,7 @@ public:
|
||||||
FTextureFormat GetFormat () override;
|
FTextureFormat GetFormat () override;
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
|
||||||
bool UseBasePalette() override;
|
bool UseBasePalette() override;
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -272,17 +272,16 @@ FTextureFormat FJPEGTexture::GetFormat()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FJPEGTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
|
||||||
{
|
{
|
||||||
auto lump = Wads.OpenLumpReader (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
JSAMPLE *buff = NULL;
|
JSAMPLE *buff = NULL;
|
||||||
bool doalpha = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
|
|
||||||
jpeg_decompress_struct cinfo;
|
jpeg_decompress_struct cinfo;
|
||||||
jpeg_error_mgr jerr;
|
jpeg_error_mgr jerr;
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width * Height];
|
TArray<uint8_t> Pixels(Width * Height, true);
|
||||||
memset (Pixels, 0xBA, Width * Height);
|
memset (Pixels.Data(), 0xBA, Width * Height);
|
||||||
|
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
cinfo.err = jpeg_std_error(&jerr);
|
||||||
cinfo.err->output_message = JPEG_OutputMessage;
|
cinfo.err->output_message = JPEG_OutputMessage;
|
||||||
|
@ -311,7 +310,7 @@ uint8_t *FJPEGTexture::MakeTexture (FRenderStyle style)
|
||||||
{
|
{
|
||||||
int num_scanlines = jpeg_read_scanlines(&cinfo, &buff, 1);
|
int num_scanlines = jpeg_read_scanlines(&cinfo, &buff, 1);
|
||||||
uint8_t *in = buff;
|
uint8_t *in = buff;
|
||||||
uint8_t *out = Pixels + y;
|
uint8_t *out = Pixels.Data() + y;
|
||||||
switch (cinfo.out_color_space)
|
switch (cinfo.out_color_space)
|
||||||
{
|
{
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
|
@ -325,7 +324,7 @@ uint8_t *FJPEGTexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
{
|
{
|
||||||
auto remap = GetRemap(style, true);
|
auto remap = GetRemap(doalpha, true);
|
||||||
for (int x = Width; x > 0; --x)
|
for (int x = Width; x > 0; --x)
|
||||||
{
|
{
|
||||||
*out = remap[in[0]];
|
*out = remap[in[0]];
|
||||||
|
|
|
@ -195,10 +195,10 @@ protected:
|
||||||
bool bRedirect;
|
bool bRedirect;
|
||||||
bool bTranslucentPatches;
|
bool bTranslucentPatches;
|
||||||
|
|
||||||
uint8_t *MakeTexture (FRenderStyle style);
|
TArray<uint8_t> MakeTexture (bool alphatex);
|
||||||
|
|
||||||
// The getters must optionally redirect if it's a simple one-patch texture.
|
// The getters must optionally redirect if it's a simple one-patch texture.
|
||||||
const uint8_t *Get8BitPixels(FRenderStyle style) override { return bRedirect ? Parts->Texture->Get8BitPixels(style) : FWorldTexture::Get8BitPixels(style); }
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override { return bRedirect ? Parts->Texture->Get8BitPixels(alphatex) : MakeTexture(alphatex); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -305,7 +305,6 @@ FMultiPatchTexture::FMultiPatchTexture (const void *texdef, FPatchLookup *patchl
|
||||||
|
|
||||||
FMultiPatchTexture::~FMultiPatchTexture ()
|
FMultiPatchTexture::~FMultiPatchTexture ()
|
||||||
{
|
{
|
||||||
Unload ();
|
|
||||||
if (Parts != NULL)
|
if (Parts != NULL)
|
||||||
{
|
{
|
||||||
for(int i=0; i<NumParts;i++)
|
for(int i=0; i<NumParts;i++)
|
||||||
|
@ -397,16 +396,16 @@ uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FMultiPatchTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FMultiPatchTexture::MakeTexture (bool alphatex)
|
||||||
{
|
{
|
||||||
int numpix = Width * Height;
|
int numpix = Width * Height;
|
||||||
uint8_t blendwork[256];
|
uint8_t blendwork[256];
|
||||||
bool buildrgb = bComplex;
|
bool buildrgb = bComplex;
|
||||||
|
|
||||||
auto Pixels = new uint8_t[numpix];
|
TArray<uint8_t> Pixels(numpix, true);
|
||||||
memset (Pixels, 0, numpix);
|
memset (Pixels.Data(), 0, numpix);
|
||||||
|
|
||||||
if (style.Flags & STYLEF_RedIsAlpha)
|
if (alphatex)
|
||||||
{
|
{
|
||||||
buildrgb = !UseBasePalette();
|
buildrgb = !UseBasePalette();
|
||||||
}
|
}
|
||||||
|
@ -434,7 +433,7 @@ uint8_t *FMultiPatchTexture::MakeTexture (FRenderStyle style)
|
||||||
{
|
{
|
||||||
trans = GetBlendMap(Parts[i].Blend, blendwork);
|
trans = GetBlendMap(Parts[i].Blend, blendwork);
|
||||||
}
|
}
|
||||||
Parts[i].Texture->CopyToBlock (Pixels, Width, Height, Parts[i].OriginX, Parts[i].OriginY, Parts[i].Rotate, trans, style);
|
Parts[i].Texture->CopyToBlock (Pixels.Data(), Width, Height, Parts[i].OriginX, Parts[i].OriginY, Parts[i].Rotate, trans, alphatex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -448,12 +447,12 @@ uint8_t *FMultiPatchTexture::MakeTexture (FRenderStyle style)
|
||||||
for(int y = 0; y < Height; y++)
|
for(int y = 0; y < Height; y++)
|
||||||
{
|
{
|
||||||
uint8_t *in = buffer + Width * y * 4;
|
uint8_t *in = buffer + Width * y * 4;
|
||||||
uint8_t *out = Pixels + y;
|
uint8_t *out = Pixels.Data() + y;
|
||||||
for (int x = 0; x < Width; x++)
|
for (int x = 0; x < Width; x++)
|
||||||
{
|
{
|
||||||
if (*out == 0 && in[3] != 0)
|
if (*out == 0 && in[3] != 0)
|
||||||
{
|
{
|
||||||
*out = RGBToPalette(style, in[2], in[1], in[0]);
|
*out = RGBToPalette(alphatex, in[2], in[1], in[0]);
|
||||||
}
|
}
|
||||||
out += Height;
|
out += Height;
|
||||||
in += 4;
|
in += 4;
|
||||||
|
|
|
@ -62,7 +62,7 @@ class FPatchTexture : public FWorldTexture
|
||||||
bool isalpha = false;
|
bool isalpha = false;
|
||||||
public:
|
public:
|
||||||
FPatchTexture (int lumpnum, patch_t *header, bool isalphatex);
|
FPatchTexture (int lumpnum, patch_t *header, bool isalphatex);
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
||||||
void DetectBadPatches();
|
void DetectBadPatches();
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FPatchTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FPatchTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
uint8_t *remap, remaptable[256];
|
uint8_t *remap, remaptable[256];
|
||||||
int numspans;
|
int numspans;
|
||||||
|
@ -179,7 +179,7 @@ uint8_t *FPatchTexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3);
|
maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3);
|
||||||
|
|
||||||
remap = GetRemap(style, isalpha);
|
remap = GetRemap(alphatex, isalpha);
|
||||||
// Special case for skies
|
// Special case for skies
|
||||||
if (bNoRemap0 && remap == GPalette.Remap)
|
if (bNoRemap0 && remap == GPalette.Remap)
|
||||||
{
|
{
|
||||||
|
@ -190,11 +190,11 @@ uint8_t *FPatchTexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
if (badflag)
|
if (badflag)
|
||||||
{
|
{
|
||||||
auto Pixels = new uint8_t[Width * Height];
|
TArray<uint8_t> Pixels(Width * Height, true);
|
||||||
uint8_t *out;
|
uint8_t *out;
|
||||||
|
|
||||||
// Draw the image to the buffer
|
// Draw the image to the buffer
|
||||||
for (x = 0, out = Pixels; x < Width; ++x)
|
for (x = 0, out = Pixels.Data(); x < Width; ++x)
|
||||||
{
|
{
|
||||||
const uint8_t *in = (const uint8_t *)patch + LittleLong(patch->columnofs[x]) + 3;
|
const uint8_t *in = (const uint8_t *)patch + LittleLong(patch->columnofs[x]) + 3;
|
||||||
|
|
||||||
|
@ -211,13 +211,13 @@ uint8_t *FPatchTexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
numspans = Width;
|
numspans = Width;
|
||||||
|
|
||||||
auto Pixels = new uint8_t[numpix];
|
TArray<uint8_t> Pixels(numpix, true);
|
||||||
memset (Pixels, 0, numpix);
|
memset (Pixels.Data(), 0, numpix);
|
||||||
|
|
||||||
// Draw the image to the buffer
|
// Draw the image to the buffer
|
||||||
for (x = 0; x < Width; ++x)
|
for (x = 0; x < Width; ++x)
|
||||||
{
|
{
|
||||||
uint8_t *outtop = Pixels + x*Height;
|
uint8_t *outtop = Pixels.Data() + x*Height;
|
||||||
const column_t *column = (const column_t *)((const uint8_t *)patch + LittleLong(patch->columnofs[x]));
|
const column_t *column = (const column_t *)((const uint8_t *)patch + LittleLong(patch->columnofs[x]));
|
||||||
int top = -1;
|
int top = -1;
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ protected:
|
||||||
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
|
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
|
||||||
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
|
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
|
||||||
|
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,19 +370,18 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FPCXTexture::MakeTexture(FRenderStyle style)
|
TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
uint8_t PaletteMap[256];
|
uint8_t PaletteMap[256];
|
||||||
PCXHeader header;
|
PCXHeader header;
|
||||||
int bitcount;
|
int bitcount;
|
||||||
bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
|
|
||||||
auto lump = Wads.OpenLumpReader(SourceLump);
|
auto lump = Wads.OpenLumpReader(SourceLump);
|
||||||
|
|
||||||
lump.Read(&header, sizeof(header));
|
lump.Read(&header, sizeof(header));
|
||||||
|
|
||||||
bitcount = header.bitsPerPixel * header.numColorPlanes;
|
bitcount = header.bitsPerPixel * header.numColorPlanes;
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
|
|
||||||
if (bitcount < 24)
|
if (bitcount < 24)
|
||||||
{
|
{
|
||||||
|
@ -394,7 +393,7 @@ uint8_t *FPCXTexture::MakeTexture(FRenderStyle style)
|
||||||
case 1:
|
case 1:
|
||||||
PaletteMap[0] = alphatex? 0 : GrayMap[0];
|
PaletteMap[0] = alphatex? 0 : GrayMap[0];
|
||||||
PaletteMap[1] = alphatex? 255 : GrayMap[255];
|
PaletteMap[1] = alphatex? 255 : GrayMap[255];
|
||||||
ReadPCX1bit (Pixels, lump, &header);
|
ReadPCX1bit (Pixels.Data(), lump, &header);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
|
@ -402,7 +401,7 @@ uint8_t *FPCXTexture::MakeTexture(FRenderStyle style)
|
||||||
{
|
{
|
||||||
PaletteMap[i] = RGBToPalettePrecise(alphatex, header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
|
PaletteMap[i] = RGBToPalettePrecise(alphatex, header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
|
||||||
}
|
}
|
||||||
ReadPCX4bits (Pixels, lump, &header);
|
ReadPCX4bits (Pixels.Data(), lump, &header);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,19 +419,17 @@ uint8_t *FPCXTexture::MakeTexture(FRenderStyle style)
|
||||||
PaletteMap[i] = RGBToPalettePrecise(alphatex, r, g, b);
|
PaletteMap[i] = RGBToPalettePrecise(alphatex, r, g, b);
|
||||||
}
|
}
|
||||||
lump.Seek(sizeof(header), FileReader::SeekSet);
|
lump.Seek(sizeof(header), FileReader::SeekSet);
|
||||||
ReadPCX8bits (Pixels, lump, &header);
|
ReadPCX8bits (Pixels.Data(), lump, &header);
|
||||||
}
|
}
|
||||||
if (Width == Height)
|
if (Width == Height)
|
||||||
{
|
{
|
||||||
FlipSquareBlockRemap(Pixels, Width, Height, PaletteMap);
|
FlipSquareBlockRemap(Pixels.Data(), Width, Height, PaletteMap);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t *newpix = new uint8_t[Width*Height];
|
TArray<uint8_t> newpix(Width*Height, true);
|
||||||
FlipNonSquareBlockRemap (newpix, Pixels, Width, Height, Width, PaletteMap);
|
FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
||||||
uint8_t *oldpix = Pixels;
|
return newpix;
|
||||||
Pixels = newpix;
|
|
||||||
delete[] oldpix;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
FTextureFormat GetFormat () override;
|
FTextureFormat GetFormat () override;
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
|
||||||
bool UseBasePalette() override;
|
bool UseBasePalette() override;
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
|
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
|
||||||
|
@ -389,11 +389,10 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FPNGTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FPNGTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
FileReader *lump;
|
FileReader *lump;
|
||||||
FileReader lfr;
|
FileReader lfr;
|
||||||
bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
|
|
||||||
if (SourceLump >= 0)
|
if (SourceLump >= 0)
|
||||||
{
|
{
|
||||||
|
@ -405,10 +404,10 @@ uint8_t *FPNGTexture::MakeTexture (FRenderStyle style)
|
||||||
lump = &fr;
|
lump = &fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
if (StartOfIDAT == 0)
|
if (StartOfIDAT == 0)
|
||||||
{
|
{
|
||||||
memset (Pixels, 0x99, Width*Height);
|
memset (Pixels.Data(), 0x99, Width*Height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -419,45 +418,43 @@ uint8_t *FPNGTexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
if (ColorType == 0 || ColorType == 3) /* Grayscale and paletted */
|
if (ColorType == 0 || ColorType == 3) /* Grayscale and paletted */
|
||||||
{
|
{
|
||||||
M_ReadIDAT (*lump, Pixels, Width, Height, Width, BitDepth, ColorType, Interlace, BigLong((unsigned int)len));
|
M_ReadIDAT (*lump, Pixels.Data(), Width, Height, Width, BitDepth, ColorType, Interlace, BigLong((unsigned int)len));
|
||||||
|
|
||||||
if (Width == Height)
|
if (Width == Height)
|
||||||
{
|
{
|
||||||
if (!alphatex)
|
if (!alphatex)
|
||||||
{
|
{
|
||||||
FTexture::FlipSquareBlockRemap (Pixels, Width, Height, PaletteMap);
|
FTexture::FlipSquareBlockRemap (Pixels.Data(), Width, Height, PaletteMap);
|
||||||
}
|
}
|
||||||
else if (ColorType == 0)
|
else if (ColorType == 0)
|
||||||
{
|
{
|
||||||
FTexture::FlipSquareBlock (Pixels, Width, Height);
|
FTexture::FlipSquareBlock (Pixels.Data(), Width, Height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t alpharemap[256];
|
uint8_t alpharemap[256];
|
||||||
ReadAlphaRemap(lump, alpharemap);
|
ReadAlphaRemap(lump, alpharemap);
|
||||||
FTexture::FlipSquareBlockRemap(Pixels, Width, Height, alpharemap);
|
FTexture::FlipSquareBlockRemap(Pixels.Data(), Width, Height, alpharemap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t *newpix = new uint8_t[Width*Height];
|
TArray<uint8_t> newpix(Width*Height, true);
|
||||||
if (!alphatex)
|
if (!alphatex)
|
||||||
{
|
{
|
||||||
FTexture::FlipNonSquareBlockRemap (newpix, Pixels, Width, Height, Width, PaletteMap);
|
FTexture::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
||||||
}
|
}
|
||||||
else if (ColorType == 0)
|
else if (ColorType == 0)
|
||||||
{
|
{
|
||||||
FTexture::FlipNonSquareBlock (newpix, Pixels, Width, Height, Width);
|
FTexture::FlipNonSquareBlock (newpix.Data(), Pixels.Data(), Width, Height, Width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t alpharemap[256];
|
uint8_t alpharemap[256];
|
||||||
ReadAlphaRemap(lump, alpharemap);
|
ReadAlphaRemap(lump, alpharemap);
|
||||||
FTexture::FlipNonSquareBlockRemap(newpix, Pixels, Width, Height, Width, alpharemap);
|
FTexture::FlipNonSquareBlockRemap(newpix.Data(), Pixels.Data(), Width, Height, Width, alpharemap);
|
||||||
}
|
}
|
||||||
uint8_t *oldpix = Pixels;
|
return newpix;
|
||||||
Pixels = newpix;
|
|
||||||
delete[] oldpix;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* RGB and/or Alpha present */
|
else /* RGB and/or Alpha present */
|
||||||
|
@ -469,7 +466,7 @@ uint8_t *FPNGTexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
M_ReadIDAT (*lump, tempix, Width, Height, Width*bytesPerPixel, BitDepth, ColorType, Interlace, BigLong((unsigned int)len));
|
M_ReadIDAT (*lump, tempix, Width, Height, Width*bytesPerPixel, BitDepth, ColorType, Interlace, BigLong((unsigned int)len));
|
||||||
in = tempix;
|
in = tempix;
|
||||||
out = Pixels;
|
out = Pixels.Data();
|
||||||
|
|
||||||
// Convert from source format to paletted, column-major.
|
// Convert from source format to paletted, column-major.
|
||||||
// Formats with alpha maps are reduced to only 1 bit of alpha.
|
// Formats with alpha maps are reduced to only 1 bit of alpha.
|
||||||
|
|
|
@ -52,7 +52,7 @@ class FRawPageTexture : public FWorldTexture
|
||||||
int mPaletteLump = -1;
|
int mPaletteLump = -1;
|
||||||
public:
|
public:
|
||||||
FRawPageTexture (int lumpnum);
|
FRawPageTexture (int lumpnum);
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -174,17 +174,17 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FRawPageTexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FRawPageTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
FMemLump lump = Wads.ReadLump (SourceLump);
|
FMemLump lump = Wads.ReadLump (SourceLump);
|
||||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||||
const uint8_t *source_p = source;
|
const uint8_t *source_p = source;
|
||||||
uint8_t *dest_p;
|
uint8_t *dest_p;
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
dest_p = Pixels;
|
dest_p = Pixels.Data();
|
||||||
|
|
||||||
const uint8_t *remap = GetRemap(style);
|
const uint8_t *remap = GetRemap(alphatex);
|
||||||
|
|
||||||
// This does not handle the custom palette.
|
// This does not handle the custom palette.
|
||||||
// User maps are encouraged to use a real image format when replacing E2END and the original could never be used anywhere else.
|
// User maps are encouraged to use a real image format when replacing E2END and the original could never be used anywhere else.
|
||||||
|
|
|
@ -53,7 +53,6 @@ public:
|
||||||
Height = vertical ? 256 : 2;
|
Height = vertical ? 256 : 2;
|
||||||
bMasked = false;
|
bMasked = false;
|
||||||
bTranslucent = false;
|
bTranslucent = false;
|
||||||
PixelsAreStatic = 2; // The alpha buffer is static, but if this gets used as a regular texture, a separate buffer needs to be made.
|
|
||||||
|
|
||||||
// Fill the column/row with shading values.
|
// Fill the column/row with shading values.
|
||||||
// Vertical shaders have have minimum alpha at the top
|
// Vertical shaders have have minimum alpha at the top
|
||||||
|
@ -100,24 +99,24 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *MakeTexture(FRenderStyle style) override
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override
|
||||||
{
|
{
|
||||||
if (style.Flags & STYLEF_RedIsAlpha)
|
TArray<uint8_t> Pix(512, true);
|
||||||
|
if (alphatex)
|
||||||
{
|
{
|
||||||
return Pixels;
|
memcpy(Pix.Data(), Pixels, 512);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Since this presents itself to the game as a regular named texture
|
// Since this presents itself to the game as a regular named texture
|
||||||
// it can easily be used on walls and flats and should work as such,
|
// it can easily be used on walls and flats and should work as such,
|
||||||
// even if it makes little sense.
|
// even if it makes little sense.
|
||||||
auto Pix = new uint8_t[512];
|
|
||||||
for (int i = 0; i < 512; i++)
|
for (int i = 0; i < 512; i++)
|
||||||
{
|
{
|
||||||
Pix[i] = GrayMap[Pixels[i]];
|
Pix[i] = GrayMap[Pixels[i]];
|
||||||
}
|
}
|
||||||
return Pix;
|
|
||||||
}
|
}
|
||||||
|
return Pix;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel);
|
void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel);
|
||||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -191,7 +191,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
uint8_t *FTGATexture::MakeTexture (FRenderStyle style)
|
TArray<uint8_t> FTGATexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
uint8_t PaletteMap[256];
|
uint8_t PaletteMap[256];
|
||||||
auto lump = Wads.OpenLumpReader (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
|
@ -199,9 +199,8 @@ uint8_t *FTGATexture::MakeTexture (FRenderStyle style)
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
uint8_t r,g,b,a;
|
uint8_t r,g,b,a;
|
||||||
uint8_t * buffer;
|
uint8_t * buffer;
|
||||||
bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
|
|
||||||
auto Pixels = new uint8_t[Width*Height];
|
TArray<uint8_t> Pixels(Width*Height, true);
|
||||||
lump.Read(&hdr, sizeof(hdr));
|
lump.Read(&hdr, sizeof(hdr));
|
||||||
lump.Seek(hdr.id_len, FileReader::SeekCur);
|
lump.Seek(hdr.id_len, FileReader::SeekCur);
|
||||||
|
|
||||||
|
@ -356,7 +355,7 @@ uint8_t *FTGATexture::MakeTexture (FRenderStyle style)
|
||||||
|
|
||||||
case 3: // Grayscale
|
case 3: // Grayscale
|
||||||
{
|
{
|
||||||
auto remap = GetRemap(style, true);
|
auto remap = GetRemap(alphatex, true);
|
||||||
switch (hdr.bpp)
|
switch (hdr.bpp)
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
|
|
|
@ -47,49 +47,3 @@ FWorldTexture::FWorldTexture(const char *name, int lumpnum)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
FWorldTexture::~FWorldTexture()
|
|
||||||
{
|
|
||||||
Unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FWorldTexture::Unload ()
|
|
||||||
{
|
|
||||||
for(int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
if (!(PixelsAreStatic & (1 << i)))
|
|
||||||
{
|
|
||||||
delete[] Pixeldata[i];
|
|
||||||
}
|
|
||||||
Pixeldata[i] = nullptr;
|
|
||||||
}
|
|
||||||
FTexture::Unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
const uint8_t *FWorldTexture::Get8BitPixels (FRenderStyle style)
|
|
||||||
{
|
|
||||||
int index = !!(style.Flags & STYLEF_RedIsAlpha);
|
|
||||||
if (Pixeldata[index] == nullptr)
|
|
||||||
{
|
|
||||||
Pixeldata[index] = MakeTexture (style);
|
|
||||||
}
|
|
||||||
return Pixeldata[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -48,21 +48,10 @@ FSkyBox::FSkyBox(const char *name)
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
FSkyBox::~FSkyBox()
|
TArray<uint8_t> FSkyBox::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
// The faces are only referenced but not owned so don't delete them.
|
if (faces[0]) return faces[0]->Get8BitPixels(alphatex);
|
||||||
}
|
return FTexture::Get8BitPixels(alphatex);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const uint8_t *FSkyBox::Get8BitPixels (FRenderStyle style)
|
|
||||||
{
|
|
||||||
if (faces[0]) return faces[0]->Get8BitPixels(style);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -88,13 +77,3 @@ bool FSkyBox::UseBasePalette()
|
||||||
return false; // not really but here it's not important.
|
return false; // not really but here it's not important.
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void FSkyBox::Unload ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,7 @@ public:
|
||||||
bool fliptop;
|
bool fliptop;
|
||||||
|
|
||||||
FSkyBox(const char *name = nullptr);
|
FSkyBox(const char *name = nullptr);
|
||||||
~FSkyBox();
|
TArray<uint8_t> Get8BitPixels(bool alphatex);
|
||||||
//const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out);
|
|
||||||
const uint8_t *Get8BitPixels (FRenderStyle style);
|
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf);
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf);
|
||||||
bool UseBasePalette();
|
bool UseBasePalette();
|
||||||
void Unload ();
|
void Unload ();
|
||||||
|
|
|
@ -225,11 +225,11 @@ FTexture::~FTexture ()
|
||||||
if (SystemTexture[i] != nullptr) delete SystemTexture[i];
|
if (SystemTexture[i] != nullptr) delete SystemTexture[i];
|
||||||
SystemTexture[i] = nullptr;
|
SystemTexture[i] = nullptr;
|
||||||
}
|
}
|
||||||
|
if (SoftwareTexture != nullptr)
|
||||||
}
|
|
||||||
|
|
||||||
void FTexture::Unload()
|
|
||||||
{
|
{
|
||||||
|
delete SoftwareTexture;
|
||||||
|
SoftwareTexture = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -254,15 +254,16 @@ void FTexture::SetFrontSkyLayer ()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, FRenderStyle style)
|
void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, bool style)
|
||||||
{
|
{
|
||||||
const uint8_t *pixels = Get8BitPixels(style);
|
auto image = Get8BitPixels(style); // should use composition cache
|
||||||
|
const uint8_t *pixels = image.Data();
|
||||||
int srcwidth = Width;
|
int srcwidth = Width;
|
||||||
int srcheight = Height;
|
int srcheight = Height;
|
||||||
int step_x = Height;
|
int step_x = Height;
|
||||||
int step_y = 1;
|
int step_y = 1;
|
||||||
FClipRect cr = {0, 0, dwidth, dheight};
|
FClipRect cr = {0, 0, dwidth, dheight};
|
||||||
if (style.Flags & STYLEF_RedIsAlpha) translation = nullptr; // do not apply translations to alpha textures.
|
if (style) translation = nullptr; // do not apply translations to alpha textures.
|
||||||
|
|
||||||
if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate))
|
if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate))
|
||||||
{
|
{
|
||||||
|
@ -425,7 +426,6 @@ void FTexture::FlipNonSquareBlockRemap (uint8_t *dst, const uint8_t *src, int x,
|
||||||
|
|
||||||
void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat fmt)
|
void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat fmt)
|
||||||
{
|
{
|
||||||
const uint8_t *pix;
|
|
||||||
int x, y, w, h, stride;
|
int x, y, w, h, stride;
|
||||||
|
|
||||||
w = GetWidth();
|
w = GetWidth();
|
||||||
|
@ -435,7 +435,9 @@ void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat f
|
||||||
{
|
{
|
||||||
case TEX_Pal:
|
case TEX_Pal:
|
||||||
case TEX_Gray:
|
case TEX_Gray:
|
||||||
pix = Get8BitPixels(fmt == TEX_Pal? DefaultRenderStyle() : LegacyRenderStyles[STYLE_Shaded]);
|
{
|
||||||
|
auto ppix = Get8BitPixels(fmt == TEX_Gray); // should use composition cache
|
||||||
|
auto pix = ppix.Data();
|
||||||
stride = pitch - w;
|
stride = pitch - w;
|
||||||
for (y = 0; y < h; ++y)
|
for (y = 0; y < h; ++y)
|
||||||
{
|
{
|
||||||
|
@ -449,6 +451,7 @@ void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat f
|
||||||
buff += stride;
|
buff += stride;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TEX_RGB:
|
case TEX_RGB:
|
||||||
{
|
{
|
||||||
|
@ -479,14 +482,16 @@ int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyI
|
||||||
{
|
{
|
||||||
PalEntry *palette = screen->GetPalette();
|
PalEntry *palette = screen->GetPalette();
|
||||||
for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values
|
for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values
|
||||||
bmp->CopyPixelData(x, y, Get8BitPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, palette, inf);
|
auto ppix = Get8BitPixels(false); // should use composition cache
|
||||||
|
bmp->CopyPixelData(x, y, ppix.Data(), Width, Height, Height, 1, rotate, palette, inf);
|
||||||
for(int i=1;i<256;i++) palette[i].a = 0;
|
for(int i=1;i<256;i++) palette[i].a = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf)
|
int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf)
|
||||||
{
|
{
|
||||||
bmp->CopyPixelData(x, y, Get8BitPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, remap, inf);
|
auto ppix = Get8BitPixels(false); // should use composition cache
|
||||||
|
bmp->CopyPixelData(x, y, ppix.Data(), Width, Height, Height, 1, rotate, remap, inf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,7 +601,7 @@ PalEntry FTexture::GetSkyCapColor(bool bottom)
|
||||||
|
|
||||||
int FTexture::CheckRealHeight()
|
int FTexture::CheckRealHeight()
|
||||||
{
|
{
|
||||||
auto pixels = Get8BitPixels(DefaultRenderStyle());
|
auto pixels = Get8BitPixels(false);
|
||||||
|
|
||||||
for(int h = GetHeight()-1; h>= 0; h--)
|
for(int h = GetHeight()-1; h>= 0; h--)
|
||||||
{
|
{
|
||||||
|
@ -682,12 +687,10 @@ void FTexture::CreateDefaultBrightmap()
|
||||||
// Check for brightmaps
|
// Check for brightmaps
|
||||||
if (UseBasePalette() && TexMan.HasGlobalBrightmap &&
|
if (UseBasePalette() && TexMan.HasGlobalBrightmap &&
|
||||||
UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar &&
|
UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar &&
|
||||||
Brightmap == NULL && bWarped == 0 &&
|
Brightmap == NULL && bWarped == 0)
|
||||||
Get8BitPixels(DefaultRenderStyle())
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// May have one - let's check when we use this texture
|
// May have one - let's check when we use this texture
|
||||||
const uint8_t *texbuf = Get8BitPixels(DefaultRenderStyle());
|
auto texbuf = Get8BitPixels(false);
|
||||||
const int white = ColorMatcher.Pick(255, 255, 255);
|
const int white = ColorMatcher.Pick(255, 255, 255);
|
||||||
|
|
||||||
int size = GetWidth() * GetHeight();
|
int size = GetWidth() * GetHeight();
|
||||||
|
@ -1050,13 +1053,15 @@ void FTexture::SetSpriteAdjust()
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// empty stubs to be overloaded by child classes.
|
// the default just returns an empty texture.
|
||||||
//
|
//
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
const uint8_t *FTexture::Get8BitPixels(FRenderStyle style)
|
TArray<uint8_t> FTexture::Get8BitPixels(bool alphatex)
|
||||||
{
|
{
|
||||||
return nullptr;
|
TArray<uint8_t> Pixels(Width * Height, true);
|
||||||
|
memset(Pixels.Data(), 0, Width * Height);
|
||||||
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
@ -1212,26 +1217,4 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y)
|
||||||
mWidth = tex->GetWidth();
|
mWidth = tex->GetWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////
|
|
||||||
|
|
||||||
|
|
||||||
class TextureCache
|
|
||||||
{
|
|
||||||
struct ItemCacheInfo
|
|
||||||
{
|
|
||||||
int palettedCount; // counts use of final paletted textures
|
|
||||||
int palettedCountCompose; // counts use of images needed for composition (can be freed after precaching)
|
|
||||||
int rgbaCount; // counts use of final true color software textures
|
|
||||||
int rawCount; // counts use of raw images needed for composition (can be freed after precaching)
|
|
||||||
int textureCount; // counts use of hardware textures
|
|
||||||
};
|
|
||||||
TMap<uint64_t, TArray<uint8_t>> pixelCachePaletted; // 8 bit column major for composition and software rendering
|
|
||||||
TMap<uint64_t, TArray<uint8_t>> pixelCacheRgba; // 32 bit column major for software true color rendering
|
|
||||||
TMap<uint64_t, TArray<uint8_t>> pixelCacheRaw; // 32 bit row major for composition
|
|
||||||
TMap<uint64_t, IHardwareTexture *> hwTextureCache; // native system textures.
|
|
||||||
|
|
||||||
TMap<uint64_t, ItemCacheInfo> cacheMarker;
|
|
||||||
|
|
||||||
void PrecacheLevel();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
|
@ -363,20 +363,6 @@ FTexture *FTextureManager::FindTexture(const char *texname, ETextureType usetype
|
||||||
return !texnum.isValid()? NULL : Textures[texnum.GetIndex()].Texture;
|
return !texnum.isValid()? NULL : Textures[texnum.GetIndex()].Texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FTextureManager :: UnloadAll
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FTextureManager::UnloadAll ()
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < Textures.Size(); ++i)
|
|
||||||
{
|
|
||||||
Textures[i].Texture->Unload ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// FTextureManager :: AddTexture
|
// FTextureManager :: AddTexture
|
||||||
|
|
|
@ -298,11 +298,9 @@ public:
|
||||||
bool isFullbright() const { return bFullbright; }
|
bool isFullbright() const { return bFullbright; }
|
||||||
void CreateDefaultBrightmap();
|
void CreateDefaultBrightmap();
|
||||||
bool FindHoles(const unsigned char * buffer, int w, int h);
|
bool FindHoles(const unsigned char * buffer, int w, int h);
|
||||||
uint64_t CacheID()
|
|
||||||
{
|
// Returns the whole texture, stored in column-major order
|
||||||
// Just a temporary placeholder. This needs to be done differently as things progress.
|
virtual TArray<uint8_t> Get8BitPixels(bool alphatex);
|
||||||
return (uint64_t)(intptr_t)GetRedirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void FlipSquareBlock (uint8_t *block, int x, int y);
|
static void FlipSquareBlock (uint8_t *block, int x, int y);
|
||||||
|
@ -386,9 +384,6 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Returns the whole texture, stored in column-major order
|
|
||||||
virtual const uint8_t *Get8BitPixels(FRenderStyle style);
|
|
||||||
|
|
||||||
// Returns true if GetPixelsBgra includes mipmaps
|
// Returns true if GetPixelsBgra includes mipmaps
|
||||||
virtual bool Mipmapped() { return true; }
|
virtual bool Mipmapped() { return true; }
|
||||||
|
|
||||||
|
@ -397,8 +392,6 @@ protected:
|
||||||
virtual bool UseBasePalette();
|
virtual bool UseBasePalette();
|
||||||
virtual FTexture *GetRedirect();
|
virtual FTexture *GetRedirect();
|
||||||
|
|
||||||
virtual void Unload ();
|
|
||||||
|
|
||||||
// Returns the native pixel format for this image
|
// Returns the native pixel format for this image
|
||||||
virtual FTextureFormat GetFormat();
|
virtual FTextureFormat GetFormat();
|
||||||
|
|
||||||
|
@ -446,7 +439,7 @@ protected:
|
||||||
|
|
||||||
virtual void SetFrontSkyLayer();
|
virtual void SetFrontSkyLayer();
|
||||||
|
|
||||||
void CopyToBlock (uint8_t *dest, int dwidth, int dheight, int x, int y, int rotate, const uint8_t *translation, FRenderStyle style);
|
void CopyToBlock (uint8_t *dest, int dwidth, int dheight, int x, int y, int rotate, const uint8_t *translation, bool style);
|
||||||
|
|
||||||
static void InitGrayMap();
|
static void InitGrayMap();
|
||||||
|
|
||||||
|
@ -467,9 +460,9 @@ protected:
|
||||||
uint16_t Width, Height;
|
uint16_t Width, Height;
|
||||||
int16_t _LeftOffset[2], _TopOffset[2];
|
int16_t _LeftOffset[2], _TopOffset[2];
|
||||||
static uint8_t GrayMap[256];
|
static uint8_t GrayMap[256];
|
||||||
uint8_t *GetRemap(FRenderStyle style, bool srcisgrayscale = false)
|
uint8_t *GetRemap(bool wantluminance, bool srcisgrayscale = false)
|
||||||
{
|
{
|
||||||
if (style.Flags & STYLEF_RedIsAlpha)
|
if (wantluminance)
|
||||||
{
|
{
|
||||||
return translationtables[TRANSLATION_Standard][srcisgrayscale ? STD_Gray : STD_Grayscale]->Remap;
|
return translationtables[TRANSLATION_Standard][srcisgrayscale ? STD_Gray : STD_Grayscale]->Remap;
|
||||||
}
|
}
|
||||||
|
@ -651,8 +644,6 @@ public:
|
||||||
// This function can be used for such things as warping textures.
|
// This function can be used for such things as warping textures.
|
||||||
void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free);
|
void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free);
|
||||||
|
|
||||||
void UnloadAll ();
|
|
||||||
|
|
||||||
int NumTextures () const { return (int)Textures.Size(); }
|
int NumTextures () const { return (int)Textures.Size(); }
|
||||||
|
|
||||||
void UpdateAnimations (uint64_t mstime);
|
void UpdateAnimations (uint64_t mstime);
|
||||||
|
@ -739,15 +730,7 @@ public:
|
||||||
class FWorldTexture : public FTexture
|
class FWorldTexture : public FTexture
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
uint8_t *Pixeldata[2] = { nullptr, nullptr };
|
|
||||||
uint8_t PixelsAreStatic = 0; // can be set by subclasses which provide static pixel buffers.
|
|
||||||
|
|
||||||
FWorldTexture(const char *name = nullptr, int lumpnum = -1);
|
FWorldTexture(const char *name = nullptr, int lumpnum = -1);
|
||||||
~FWorldTexture();
|
|
||||||
|
|
||||||
void Unload() override;
|
|
||||||
const uint8_t *Get8BitPixels(FRenderStyle style) override;
|
|
||||||
virtual uint8_t *MakeTexture(FRenderStyle style) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// A texture that doesn't really exist
|
// A texture that doesn't really exist
|
||||||
|
@ -767,20 +750,17 @@ class FCanvasTexture : public FTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FCanvasTexture (const char *name, int width, int height);
|
FCanvasTexture (const char *name, int width, int height);
|
||||||
~FCanvasTexture ();
|
|
||||||
|
|
||||||
//const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out);
|
//const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out);
|
||||||
//const uint32_t *GetPixelsBgra() override;
|
//const uint32_t *GetPixelsBgra() override;
|
||||||
|
|
||||||
const uint8_t *Get8BitPixels (FRenderStyle style);
|
//const uint8_t *Get8BitPixels(bool alphatex);
|
||||||
void Unload ();
|
|
||||||
bool CheckModified (FRenderStyle) /*override*/;
|
bool CheckModified (FRenderStyle) /*override*/;
|
||||||
void NeedUpdate() { bNeedsUpdate=true; }
|
void NeedUpdate() { bNeedsUpdate=true; }
|
||||||
void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; }
|
void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; }
|
||||||
DCanvas *GetCanvas() { return Canvas; }
|
DCanvas *GetCanvas() { return Canvas; }
|
||||||
DCanvas *GetCanvasBgra() { return CanvasBgra; }
|
DCanvas *GetCanvasBgra() { return CanvasBgra; }
|
||||||
bool Mipmapped() override { return false; }
|
bool Mipmapped() override { return false; }
|
||||||
void MakeTexture (FRenderStyle style);
|
|
||||||
void MakeTextureBgra ();
|
void MakeTextureBgra ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -838,6 +818,7 @@ struct FTexCoordInfo
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
136
src/v_font.cpp
136
src/v_font.cpp
|
@ -171,16 +171,12 @@ class FFontChar1 : public FTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FFontChar1 (FTexture *sourcelump);
|
FFontChar1 (FTexture *sourcelump);
|
||||||
const uint8_t *Get8BitPixels (FRenderStyle style);
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
void SetSourceRemap(const uint8_t *sourceremap);
|
void SetSourceRemap(const uint8_t *sourceremap);
|
||||||
void Unload ();
|
|
||||||
~FFontChar1 ();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void MakeTexture ();
|
|
||||||
|
|
||||||
FTexture *BaseTexture;
|
FTexture *BaseTexture;
|
||||||
uint8_t *Pixels;
|
|
||||||
const uint8_t *SourceRemap;
|
const uint8_t *SourceRemap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,16 +185,13 @@ class FFontChar2 : public FTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0);
|
FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0);
|
||||||
~FFontChar2 ();
|
|
||||||
|
|
||||||
const uint8_t *Get8BitPixels (FRenderStyle style);
|
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
|
||||||
void SetSourceRemap(const uint8_t *sourceremap);
|
void SetSourceRemap(const uint8_t *sourceremap);
|
||||||
void Unload ();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int SourceLump;
|
int SourceLump;
|
||||||
int SourcePos;
|
int SourcePos;
|
||||||
uint8_t *Pixels;
|
|
||||||
const uint8_t *SourceRemap;
|
const uint8_t *SourceRemap;
|
||||||
|
|
||||||
void MakeTexture ();
|
void MakeTexture ();
|
||||||
|
@ -365,6 +358,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
|
||||||
FirstFont = this;
|
FirstFont = this;
|
||||||
Cursor = '_';
|
Cursor = '_';
|
||||||
ActiveColors = 0;
|
ActiveColors = 0;
|
||||||
|
translateUntranslated = false;
|
||||||
|
|
||||||
maxyoffs = 0;
|
maxyoffs = 0;
|
||||||
|
|
||||||
|
@ -530,14 +524,13 @@ void RecordTextureColors (FTexture *pic, uint8_t *usedcolors)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
auto pixels = pic->Get8BitPixels(DefaultRenderStyle());
|
auto pixels = pic->Get8BitPixels(false);
|
||||||
auto size = pic->GetWidth() * pic->GetHeight();
|
auto size = pic->GetWidth() * pic->GetHeight();
|
||||||
|
|
||||||
for(x = 0;x < size; x++)
|
for(x = 0;x < size; x++)
|
||||||
{
|
{
|
||||||
usedcolors[pixels[x]]++;
|
usedcolors[pixels[x]]++;
|
||||||
}
|
}
|
||||||
pic->Unload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -738,6 +731,7 @@ FRemapTable *FFont::GetColorTranslation (EColorRange range, PalEntry *color) con
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (range >= NumTextColors)
|
else if (range >= NumTextColors)
|
||||||
range = CR_UNTRANSLATED;
|
range = CR_UNTRANSLATED;
|
||||||
|
//if (range == CR_UNTRANSLATED && !translateUntranslated) return nullptr;
|
||||||
return &Ranges[range];
|
return &Ranges[range];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,6 +907,8 @@ void FFont::LoadTranslations()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fixme: This needs to build a translation based on the source palette, not some intermediate 'ordered' table.
|
||||||
|
|
||||||
ActiveColors = SimpleTranslation (usedcolors, PatchRemap, identity, &luminosity);
|
ActiveColors = SimpleTranslation (usedcolors, PatchRemap, identity, &luminosity);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
@ -1078,6 +1074,7 @@ void FSingleLumpFont::LoadFON1 (int lump, const uint8_t *data)
|
||||||
FirstChar = 0;
|
FirstChar = 0;
|
||||||
LastChar = 255;
|
LastChar = 255;
|
||||||
GlobalKerning = 0;
|
GlobalKerning = 0;
|
||||||
|
translateUntranslated = true;
|
||||||
PatchRemap = new uint8_t[256];
|
PatchRemap = new uint8_t[256];
|
||||||
|
|
||||||
for(unsigned int i = 0;i < 256;++i)
|
for(unsigned int i = 0;i < 256;++i)
|
||||||
|
@ -1558,7 +1555,6 @@ FFontChar1::FFontChar1 (FTexture *sourcelump)
|
||||||
// now copy all the properties from the base texture
|
// now copy all the properties from the base texture
|
||||||
assert(BaseTexture != NULL);
|
assert(BaseTexture != NULL);
|
||||||
CopySize(BaseTexture);
|
CopySize(BaseTexture);
|
||||||
Pixels = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -1569,39 +1565,21 @@ FFontChar1::FFontChar1 (FTexture *sourcelump)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
const uint8_t *FFontChar1::Get8BitPixels (FRenderStyle)
|
TArray<uint8_t> FFontChar1::Get8BitPixels (bool)
|
||||||
{
|
|
||||||
if (Pixels == NULL)
|
|
||||||
{
|
|
||||||
MakeTexture ();
|
|
||||||
}
|
|
||||||
return Pixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FFontChar1 :: MakeTexture
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FFontChar1::MakeTexture ()
|
|
||||||
{
|
{
|
||||||
// Make the texture as normal, then remap it so that all the colors
|
// Make the texture as normal, then remap it so that all the colors
|
||||||
// are at the low end of the palette
|
// are at the low end of the palette
|
||||||
Pixels = new uint8_t[Width*Height];
|
// Why? It only creates unnecessary work!
|
||||||
const uint8_t *pix = BaseTexture->Get8BitPixels(DefaultRenderStyle());
|
auto Pixels = BaseTexture->Get8BitPixels(false);
|
||||||
|
|
||||||
if (!SourceRemap)
|
if (SourceRemap)
|
||||||
{
|
|
||||||
memcpy(Pixels, pix, Width*Height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
for (int x = 0; x < Width*Height; ++x)
|
for (int x = 0; x < Width*Height; ++x)
|
||||||
{
|
{
|
||||||
Pixels[x] = SourceRemap[pix[x]];
|
Pixels[x] = SourceRemap[Pixels[x]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -1612,37 +1590,9 @@ void FFontChar1::MakeTexture ()
|
||||||
|
|
||||||
void FFontChar1::SetSourceRemap(const uint8_t *sourceremap)
|
void FFontChar1::SetSourceRemap(const uint8_t *sourceremap)
|
||||||
{
|
{
|
||||||
Unload();
|
|
||||||
SourceRemap = sourceremap;
|
SourceRemap = sourceremap;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FFontChar1 :: Unload
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FFontChar1::Unload ()
|
|
||||||
{
|
|
||||||
if (Pixels != NULL)
|
|
||||||
{
|
|
||||||
delete[] Pixels;
|
|
||||||
Pixels = NULL;
|
|
||||||
}
|
|
||||||
FTexture::Unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FFontChar1 :: ~FFontChar1
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
FFontChar1::~FFontChar1 ()
|
|
||||||
{
|
|
||||||
Unload ();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// FFontChar2 :: FFontChar2
|
// FFontChar2 :: FFontChar2
|
||||||
|
@ -1652,7 +1602,7 @@ FFontChar1::~FFontChar1 ()
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FFontChar2::FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs, int topofs)
|
FFontChar2::FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs, int topofs)
|
||||||
: SourceLump (sourcelump), SourcePos (sourcepos), Pixels (0), SourceRemap(NULL)
|
: SourceLump (sourcelump), SourcePos (sourcepos), SourceRemap(NULL)
|
||||||
{
|
{
|
||||||
UseType = ETextureType::FontChar;
|
UseType = ETextureType::FontChar;
|
||||||
Width = width;
|
Width = width;
|
||||||
|
@ -1663,29 +1613,13 @@ FFontChar2::FFontChar2 (int sourcelump, int sourcepos, int width, int height, in
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// FFontChar2 :: ~FFontChar2
|
// FFontChar2 :: SetSourceRemap
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FFontChar2::~FFontChar2 ()
|
void FFontChar2::SetSourceRemap(const uint8_t *sourceremap)
|
||||||
{
|
{
|
||||||
Unload ();
|
SourceRemap = sourceremap;
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FFontChar2 :: Unload
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FFontChar2::Unload ()
|
|
||||||
{
|
|
||||||
if (Pixels != NULL)
|
|
||||||
{
|
|
||||||
delete[] Pixels;
|
|
||||||
Pixels = NULL;
|
|
||||||
}
|
|
||||||
FTexture::Unload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -1696,34 +1630,7 @@ void FFontChar2::Unload ()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
const uint8_t *FFontChar2::Get8BitPixels (FRenderStyle)
|
TArray<uint8_t> FFontChar2::Get8BitPixels(bool)
|
||||||
{
|
|
||||||
if (Pixels == NULL)
|
|
||||||
{
|
|
||||||
MakeTexture ();
|
|
||||||
}
|
|
||||||
return Pixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FFontChar2 :: SetSourceRemap
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FFontChar2::SetSourceRemap(const uint8_t *sourceremap)
|
|
||||||
{
|
|
||||||
Unload();
|
|
||||||
SourceRemap = sourceremap;
|
|
||||||
}
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// FFontChar2 :: MakeTexture
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
void FFontChar2::MakeTexture ()
|
|
||||||
{
|
{
|
||||||
auto lump = Wads.OpenLumpReader (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
int destSize = Width * Height;
|
int destSize = Width * Height;
|
||||||
|
@ -1753,11 +1660,11 @@ void FFontChar2::MakeTexture ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixels = new uint8_t[destSize];
|
TArray<uint8_t> Pixels(destSize, true);
|
||||||
|
|
||||||
int runlen = 0, setlen = 0;
|
int runlen = 0, setlen = 0;
|
||||||
uint8_t setval = 0; // Shut up, GCC!
|
uint8_t setval = 0; // Shut up, GCC!
|
||||||
uint8_t *dest_p = Pixels;
|
uint8_t *dest_p = Pixels.Data();
|
||||||
int dest_adv = Height;
|
int dest_adv = Height;
|
||||||
int dest_rew = destSize - 1;
|
int dest_rew = destSize - 1;
|
||||||
|
|
||||||
|
@ -1838,6 +1745,7 @@ void FFontChar2::MakeTexture ()
|
||||||
name[8] = 0;
|
name[8] = 0;
|
||||||
I_FatalError ("The font %s is corrupt", name);
|
I_FatalError ("The font %s is corrupt", name);
|
||||||
}
|
}
|
||||||
|
return Pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -120,6 +120,7 @@ protected:
|
||||||
int GlobalKerning;
|
int GlobalKerning;
|
||||||
char Cursor;
|
char Cursor;
|
||||||
bool noTranslate;
|
bool noTranslate;
|
||||||
|
bool translateUntranslated;
|
||||||
struct CharData
|
struct CharData
|
||||||
{
|
{
|
||||||
FTexture *Pic;
|
FTexture *Pic;
|
||||||
|
|
Loading…
Reference in a new issue