From c892fb1ddb50521b18d1e6cdb1a0cdfdf5f71129 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 May 2020 22:59:50 +0200 Subject: [PATCH] - backend sync with Raze Mostly code reformatting plus license and copyright adjustments --- src/common/2d/v_2ddrawer.cpp | 2 +- src/common/scripting/jit/jit_move.cpp | 1 + src/common/scripting/vm/vmexec.cpp | 1 + src/common/textures/animtexture.cpp | 38 +++++------ src/common/textures/animtexture.h | 12 ++-- src/common/textures/formats/ddstexture.cpp | 5 +- src/common/textures/formats/jpegtexture.cpp | 3 +- src/common/textures/formats/pcxtexture.cpp | 2 +- src/common/textures/formats/pngtexture.cpp | 9 +-- src/common/textures/formats/tgatexture.cpp | 2 +- src/common/textures/gametexture.h | 9 +++ src/common/textures/hw_texcontainer.h | 10 ++- src/common/textures/imagehelpers.h | 1 - .../textures/multipatchtexturebuilder.cpp | 1 - src/common/textures/skyboxtexture.cpp | 53 +++++++++------ src/common/textures/texture.cpp | 68 +++++++++---------- src/common/textures/texturemanager.cpp | 1 - src/common/textures/textures.h | 6 +- 18 files changed, 126 insertions(+), 98 deletions(-) diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 98c0ba7117..b397cc88d7 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -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) diff --git a/src/common/scripting/jit/jit_move.cpp b/src/common/scripting/jit/jit_move.cpp index a02898ac06..53644568c3 100644 --- a/src/common/scripting/jit/jit_move.cpp +++ b/src/common/scripting/jit/jit_move.cpp @@ -3,6 +3,7 @@ #include "v_video.h" #include "s_soundinternal.h" #include "texturemanager.h" +#include "palutil.h" void JitCompiler::EmitMOVE() { diff --git a/src/common/scripting/vm/vmexec.cpp b/src/common/scripting/vm/vmexec.cpp index 6921d3dac9..7180cb1034 100644 --- a/src/common/scripting/vm/vmexec.cpp +++ b/src/common/scripting/vm/vmexec.cpp @@ -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]; diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index 387464fd0d..2d06eccab5 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -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(tex[0]->GetTexture())->SetFrameSize(width, height); + static_cast(tex[0]->GetTexture())->SetFrameSize(width, height); static_cast(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(tex[active]->GetTexture())->SetFrame(palette, data); } -FGameTexture * AnimTextures::GetFrame() +FGameTexture* AnimTextures::GetFrame() { - return tex[active]; + return tex[active]; } diff --git a/src/common/textures/animtexture.h b/src/common/textures/animtexture.h index 74414fee47..2515253a77 100644 --- a/src/common/textures/animtexture.h +++ b/src/common/textures/animtexture.h @@ -8,21 +8,21 @@ class AnimTexture : public FTexture uint8_t Palette[768]; TArray 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(); }; diff --git a/src/common/textures/formats/ddstexture.cpp b/src/common/textures/formats/ddstexture.cpp index 64b1b8604c..3a88fcdd14 100644 --- a/src/common/textures/formats/ddstexture.cpp +++ b/src/common/textures/formats/ddstexture.cpp @@ -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 diff --git a/src/common/textures/formats/jpegtexture.cpp b/src/common/textures/formats/jpegtexture.cpp index 1d98ea85a4..e07f4425de 100644 --- a/src/common/textures/formats/jpegtexture.cpp +++ b/src/common/textures/formats/jpegtexture.cpp @@ -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 diff --git a/src/common/textures/formats/pcxtexture.cpp b/src/common/textures/formats/pcxtexture.cpp index a995ec672a..89d05e4271 100644 --- a/src/common/textures/formats/pcxtexture.cpp +++ b/src/common/textures/formats/pcxtexture.cpp @@ -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 diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index f8ba8648f9..48eb2437c6 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -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 (len / 3, 256); + PaletteSize = std::min (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; -} +} \ No newline at end of file diff --git a/src/common/textures/formats/tgatexture.cpp b/src/common/textures/formats/tgatexture.cpp index 0cc0d210a9..80c7b04a89 100644 --- a/src/common/textures/formats/tgatexture.cpp +++ b/src/common/textures/formats/tgatexture.cpp @@ -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 diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 7b4c461746..38c0908c62 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -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; diff --git a/src/common/textures/hw_texcontainer.h b/src/common/textures/hw_texcontainer.h index cc350d635a..c75d42278d 100644 --- a/src/common/textures/hw_texcontainer.h +++ b/src/common/textures/hw_texcontainer.h @@ -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)) { diff --git a/src/common/textures/imagehelpers.h b/src/common/textures/imagehelpers.h index feb5bfcac7..8923f92dba 100644 --- a/src/common/textures/imagehelpers.h +++ b/src/common/textures/imagehelpers.h @@ -147,5 +147,4 @@ namespace ImageHelpers } } } - } diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 46447f86d7..7def5cb7aa 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -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++) diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index d8c645e8b9..2ca476a20e 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -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" diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 432026bc9d..016ac4fecc 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -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> 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; xPalette : 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); } - diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index eac5f30081..c7cffd07cd 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -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); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 9ca6be736b..b3e900ef6a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -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();