- backend sync with Raze

Mostly code reformatting plus license and copyright adjustments
This commit is contained in:
Christoph Oelckers 2020-05-26 22:59:50 +02:00
parent 4881ec257a
commit c892fb1ddb
18 changed files with 126 additions and 98 deletions

View file

@ -45,7 +45,7 @@ F2DDrawer* twod = &drawer;
EXTERN_CVAR(Float, transsouls)
CVAR(Float, classic_scaling_factor, 1.0, CVAR_ARCHIVE)
CVAR(Float, classic_scaling_pixelaspect, 1.2, CVAR_ARCHIVE)
CVAR(Float, classic_scaling_pixelaspect, 1.2f, CVAR_ARCHIVE)
IMPLEMENT_CLASS(DShape2DTransform, false, false)

View file

@ -3,6 +3,7 @@
#include "v_video.h"
#include "s_soundinternal.h"
#include "texturemanager.h"
#include "palutil.h"
void JitCompiler::EmitMOVE()
{

View file

@ -42,6 +42,7 @@
#include "types.h"
#include "basics.h"
#include "texturemanager.h"
#include "palutil.h"
extern cycle_t VMCycles[10];
extern int VMCalls[10];

View file

@ -43,13 +43,13 @@
void AnimTexture::SetFrameSize(int width, int height)
{
FTexture::SetSize(width, height);
Image.Resize(width*height);
Image.Resize(width * height);
}
void AnimTexture::SetFrame(const uint8_t *palette, const void *data_)
void AnimTexture::SetFrame(const uint8_t* palette, const void* data_)
{
memcpy(Palette, palette, 768);
memcpy(Image.Data(), data_, Width * Height);
memcpy(Palette, palette, 768);
memcpy(Image.Data(), data_, Width * Height);
CleanHardwareTextures();
}
@ -70,10 +70,10 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans)
for (int i = 0; i < Width * Height; i++)
{
int p = i * 4;
int index = spix[i];
dpix[p + 0] = Palette[index*3+2];
dpix[p + 1] = Palette[index*3+1];
dpix[p + 2] = Palette[index*3];
int index = spix[i];
dpix[p + 0] = Palette[index * 3 + 2];
dpix[p + 1] = Palette[index * 3 + 1];
dpix[p + 2] = Palette[index * 3];
dpix[p + 3] = 255;
}
return bmp;
@ -87,32 +87,32 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans)
AnimTextures::AnimTextures()
{
active = 1;
tex[0] = MakeGameTexture(new AnimTexture, "", ETextureType::Special);
tex[1] = MakeGameTexture(new AnimTexture, "", ETextureType::Special);
active = 1;
tex[0] = MakeGameTexture(new AnimTexture, "", ETextureType::Special);
tex[1] = MakeGameTexture(new AnimTexture, "", ETextureType::Special);
}
AnimTextures::~AnimTextures()
{
delete tex[0];
delete tex[1];
delete tex[0];
delete tex[1];
}
void AnimTextures::SetSize(int width, int height)
{
static_cast<AnimTexture*>(tex[0]->GetTexture())->SetFrameSize(width, height);
static_cast<AnimTexture*>(tex[0]->GetTexture())->SetFrameSize(width, height);
static_cast<AnimTexture*>(tex[1]->GetTexture())->SetFrameSize(width, height);
tex[0]->SetSize(width, height);
tex[1]->SetSize(width, height);
}
void AnimTextures::SetFrame(const uint8_t *palette, const void* data)
void AnimTextures::SetFrame(const uint8_t* palette, const void* data)
{
active ^= 1;
active ^= 1;
static_cast<AnimTexture*>(tex[active]->GetTexture())->SetFrame(palette, data);
}
FGameTexture * AnimTextures::GetFrame()
FGameTexture* AnimTextures::GetFrame()
{
return tex[active];
return tex[active];
}

View file

@ -8,21 +8,21 @@ class AnimTexture : public FTexture
uint8_t Palette[768];
TArray<uint8_t> Image;
public:
AnimTexture() = default;
AnimTexture() = default;
void SetFrameSize(int width, int height);
void SetFrame(const uint8_t *palette, const void* data);
virtual FBitmap GetBgraBitmap(const PalEntry* remap, int* trans) override;
void SetFrame(const uint8_t* palette, const void* data);
virtual FBitmap GetBgraBitmap(const PalEntry* remap, int* trans) override;
};
class AnimTextures
{
int active;
FGameTexture *tex[2];
FGameTexture* tex[2];
public:
AnimTextures();
~AnimTextures();
void SetSize(int width, int height);
void SetFrame(const uint8_t *palette, const void* data);
FGameTexture *GetFrame();
void SetFrame(const uint8_t* palette, const void* data);
FGameTexture* GetFrame();
};

View file

@ -1,9 +1,10 @@
/*
** pngtexture.cpp
** ddstexture.cpp
** Texture class for DDS images
**
**---------------------------------------------------------------------------
** Copyright 2006-2007 Randy Heit
** Copyright 2006-2016 Randy Heit
** Copyright 2006-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without

View file

@ -3,7 +3,8 @@
** Texture class for JPEG images
**
**---------------------------------------------------------------------------
** Copyright 2006-2007 Randy Heit
** Copyright 2005-2016 Randy Heit
** Copyright 2005-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without

View file

@ -4,7 +4,7 @@
**
**---------------------------------------------------------------------------
** Copyright 2005 David HENRY
** Copyright 2006 Christoph Oelckers
** Copyright 2006-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without

View file

@ -4,6 +4,7 @@
**
**---------------------------------------------------------------------------
** Copyright 2004-2007 Randy Heit
** Copyright 2005-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
@ -34,7 +35,6 @@
*/
#include "files.h"
#include "filesystem.h"
#include "templates.h"
#include "m_png.h"
#include "bitmap.h"
@ -42,6 +42,7 @@
#include "image.h"
#include "printf.h"
#include "texturemanager.h"
#include "filesystem.h"
//==========================================================================
//
@ -640,7 +641,7 @@ class FPNGFileTexture : public FTexture
{
public:
FPNGFileTexture (FileReader &lump, int width, int height, uint8_t colortype);
virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans);
virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans) override;
protected:
@ -721,7 +722,7 @@ FBitmap FPNGFileTexture::GetBgraBitmap(const PalEntry *remap, int *trans)
lump->Seek (len, FileReader::SeekCur);
else
{
PaletteSize = MIN<int> (len / 3, 256);
PaletteSize = std::min<int> (len / 3, 256);
for(int i = 0; i < PaletteSize; i++)
{
pe[i].r = lump->ReadUInt8();
@ -753,4 +754,4 @@ FBitmap FPNGFileTexture::GetBgraBitmap(const PalEntry *remap, int *trans)
bmp.CopyPixelDataRGB(0, 0, Pixels.Data(), Width, Height, 3, pixwidth, 0, CF_RGB);
}
return bmp;
}
}

View file

@ -3,7 +3,7 @@
** Texture class for TGA images
**
**---------------------------------------------------------------------------
** Copyright 2006 Christoph Oelckers
** Copyright 2006-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without

View file

@ -108,6 +108,8 @@ class FGameTexture
public:
float alphaThreshold = 0.5f;
FGameTexture(FTexture* wrap, const char *name);
~FGameTexture();
void Setup(FTexture* wrap);
@ -253,6 +255,13 @@ public:
LeftOffset[which] = x;
TopOffset[which] = y;
}
void SetOffsets(int x, int y)
{
LeftOffset[0] = x;
TopOffset[0] = y;
LeftOffset[1] = x;
TopOffset[1] = y;
}
void SetScale(float x, float y)
{
ScaleX = x;

View file

@ -60,8 +60,14 @@ private:
TranslatedTexture * GetTexID(int translation, int scaleflags)
{
auto remap = GPalette.TranslationToTable(translation);
translation = remap == nullptr ? 0 : remap->Index;
// Allow negative indices to pass through unchanged.
// This is needed for allowing the client to allocate slots that aren't matched to a palette, e.g. Build's indexed variants.
if (translation >= 0)
{
auto remap = GPalette.TranslationToTable(translation);
translation = remap == nullptr ? 0 : remap->Index;
}
else translation &= ~0x7fffffff;
if (translation == 0 && !(scaleflags & CTF_Upscale))
{

View file

@ -147,5 +147,4 @@ namespace ImageHelpers
}
}
}
}

View file

@ -873,7 +873,6 @@ void FMultipatchTextureBuilder::ResolveAllPatches()
for (int i = BuiltTextures.Size()-1; i>= 0; i--)
{
auto &buildinfo = BuiltTextures[i];
bool hasEmpty = false;
for (unsigned j = 0; j < buildinfo.Inits.Size(); j++)

View file

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

View file

@ -76,7 +76,7 @@ FTexture::FTexture (int lumpnum)
//
//===========================================================================
FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans)
FBitmap FTexture::GetBgraBitmap(const PalEntry* remap, int* ptrans)
{
FBitmap bmp;
bmp.Create(Width, Height);
@ -116,9 +116,9 @@ int FTexture::CheckRealHeight()
//
//===========================================================================
bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
bool FTexture::FindHoles(const unsigned char* buffer, int w, int h)
{
const unsigned char * li;
const unsigned char* li;
int y, x;
int startdraw, lendraw;
int gaps[5][2];
@ -134,11 +134,11 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
startdraw = -1;
lendraw = 0;
for (y = 0; y<h; y++)
for (y = 0; y < h; y++)
{
li = buffer + w * y * 4 + 3;
for (x = 0; x<w; x++, li += 4)
for (x = 0; x < w; x++, li += 4)
{
if (*li != 0) break;
}
@ -204,15 +204,15 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
//
//----------------------------------------------------------------------------
void FTexture::CheckTrans(unsigned char * buffer, int size, int trans)
void FTexture::CheckTrans(unsigned char* buffer, int size, int trans)
{
if (bTranslucent == -1)
{
bTranslucent = trans;
if (trans == -1)
{
uint32_t * dwbuf = (uint32_t*)buffer;
for (int i = 0; i<size; i++)
uint32_t* dwbuf = (uint32_t*)buffer;
for (int i = 0; i < size; i++)
{
uint32_t alpha = dwbuf[i] >> 24;
@ -244,13 +244,13 @@ void FTexture::CheckTrans(unsigned char * buffer, int size, int trans)
#define CHKPIX(ofs) (l1[(ofs)*4+MSB]==255 ? (( ((uint32_t*)l1)[0] = ((uint32_t*)l1)[ofs]&SOME_MASK), trans=true ) : false)
bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
bool FTexture::SmoothEdges(unsigned char* buffer, int w, int h)
{
int x, y;
bool trans = buffer[MSB] == 0; // If I set this to false here the code won't detect textures
// that only contain transparent pixels.
bool semitrans = false;
unsigned char * l1;
unsigned char* l1;
if (h <= 1 || w <= 1) return false; // makes (a) no sense and (b) doesn't work with this code!
@ -258,42 +258,42 @@ bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
if (l1[MSB] == 0 && !CHKPIX(1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (x = 1; x<w - 1; x++, l1 += 4)
for (x = 1; x < w - 1; x++, l1 += 4)
{
if (l1[MSB] == 0 && !CHKPIX(-1) && !CHKPIX(1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
}
if (l1[MSB] == 0 && !CHKPIX(-1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (y = 1; y<h - 1; y++)
for (y = 1; y < h - 1; y++)
{
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (x = 1; x<w - 1; x++, l1 += 4)
for (x = 1; x < w - 1; x++, l1 += 4)
{
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(-1) && !CHKPIX(1) && !CHKPIX(-w - 1) && !CHKPIX(-w + 1) && !CHKPIX(w - 1) && !CHKPIX(w + 1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
}
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(-1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
}
if (l1[MSB] == 0 && !CHKPIX(-w)) CHKPIX(1);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (x = 1; x<w - 1; x++, l1 += 4)
for (x = 1; x < w - 1; x++, l1 += 4)
{
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(-1)) CHKPIX(1);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
}
if (l1[MSB] == 0 && !CHKPIX(-w)) CHKPIX(-1);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
return trans || semitrans;
}
@ -304,7 +304,7 @@ bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
//
//===========================================================================
bool FTexture::ProcessData(unsigned char * buffer, int w, int h, bool ispatch)
bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch)
{
if (Masked)
{
@ -324,7 +324,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
{
FTextureBuffer result;
unsigned char * buffer = nullptr;
unsigned char* buffer = nullptr;
int W, H;
int isTransparent = -1;
bool checkonly = !!(flags & CTF_CheckOnly);
@ -336,7 +336,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
if (!checkonly)
{
buffer = new unsigned char[W*(H + 1) * 4];
buffer = new unsigned char[W * (H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);
auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation);
@ -344,12 +344,12 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
FBitmap bmp(buffer, W * 4, W, H);
int trans;
auto Pixels = GetBgraBitmap(remap? remap->Palette : nullptr, &trans);
auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans);
bmp.Blit(exx, exx, Pixels);
if (remap == nullptr)
{
CheckTrans(buffer, W*H, trans);
CheckTrans(buffer, W * H, trans);
isTransparent = bTranslucent;
}
else
@ -375,9 +375,10 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
result.mHeight = H;
// Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.)
if (GetImage() && flags & CTF_ProcessData)
if (GetImage() && flags & CTF_ProcessData)
{
if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly);
if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
}
@ -392,8 +393,8 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
bool FTexture::DetermineTranslucency()
{
// This will calculate all we need, so just discard the result.
CreateTexBuffer(0);
// This will calculate all we need, so just discard the result.
CreateTexBuffer(0);
return !!bTranslucent;
}
@ -512,10 +513,10 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
{
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
if (hwtex == nullptr)
{
{
hwtex = CreateHardwareTexture();
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
}
}
return hwtex;
}
return nullptr;
@ -539,4 +540,3 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
SystemTextures.AddHardwareTexture(0, false, hwtex);
}

View file

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

View file

@ -3,7 +3,7 @@
**
**---------------------------------------------------------------------------
** Copyright 2005-2016 Randy Heit
** Copyright 2005-2016 Christoph Oelckers
** Copyright 2005-2019 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
@ -203,8 +203,9 @@ class FTexture : public RefCountedBase
{
friend class FGameTexture; // only for the porting work
protected:
public:
FHardwareTextureContainer SystemTextures;
protected:
FloatRect* areas = nullptr;
int SourceLump;
uint16_t Width = 0, Height = 0;
@ -250,7 +251,6 @@ public:
int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method.
bool FindHoles(const unsigned char * buffer, int w, int h);
void CopySize(FTexture* BaseTexture)
{
Width = BaseTexture->GetWidth();