From e92be97f33eb6d2916b428fa7c412cd6ee4120d2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Apr 2020 14:23:57 +0200 Subject: [PATCH] - let FSkybox inherit from FImageTexture to simplify the redirection of the base image for the software renderer. --- src/common/textures/imagetexture.cpp | 23 +++++++----- src/common/textures/skyboxtexture.cpp | 36 +++++-------------- src/common/textures/skyboxtexture.h | 16 ++------- src/common/textures/textures.h | 9 ++--- .../swrenderer/textures/r_swtexture.h | 2 -- 5 files changed, 30 insertions(+), 56 deletions(-) diff --git a/src/common/textures/imagetexture.cpp b/src/common/textures/imagetexture.cpp index 3e5d3aabb..fa70f3b55 100644 --- a/src/common/textures/imagetexture.cpp +++ b/src/common/textures/imagetexture.cpp @@ -54,18 +54,23 @@ FImageTexture::FImageTexture(FImageSource *img, const char *name) noexcept if (img != nullptr) { if (name == nullptr) fileSystem.GetFileShortName(Name, img->LumpNum()); - Width = img->GetWidth(); - Height = img->GetHeight(); - - auto offsets = img->GetOffsets(); - _LeftOffset[1] = _LeftOffset[0] = offsets.first; - _TopOffset[1] = _TopOffset[0] = offsets.second; - - bMasked = img->bMasked; - bTranslucent = img->bTranslucent; + SetFromImage(); } } +void FImageTexture::SetFromImage() +{ + auto img = mImage; + Width = img->GetWidth(); + Height = img->GetHeight(); + + auto offsets = img->GetOffsets(); + _LeftOffset[1] = _LeftOffset[0] = offsets.first; + _TopOffset[1] = _TopOffset[0] = offsets.second; + + bMasked = img->bMasked; + bTranslucent = img->bTranslucent; +} //=========================================================================== // // diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index 2c212643f..64eb11e6f 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -35,15 +35,14 @@ //----------------------------------------------------------------------------- FSkyBox::FSkyBox(const char *name) -: FTexture(name) + : FImageTexture(name) { FTextureID texid = TexMan.CheckForTexture(name, ETextureType::Wall); - previous = nullptr; if (texid.isValid()) { previous = TexMan.GetTexture(texid); - CopySize(previous); } + else previous = nullptr; faces[0]=faces[1]=faces[2]=faces[3]=faces[4]=faces[5] = nullptr; UseType = ETextureType::Override; bSkybox = true; @@ -56,29 +55,12 @@ FSkyBox::FSkyBox(const char *name) // //----------------------------------------------------------------------------- -TArray FSkyBox::Get8BitPixels(bool alphatex) +void FSkyBox::SetSize() { - return previous->Get8BitPixels(alphatex); -} - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - -FBitmap FSkyBox::GetBgraBitmap(const PalEntry *p, int *trans) -{ - return previous->GetBgraBitmap(p, trans); -} - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - -FImageSource *FSkyBox::GetImage() const -{ - return previous->GetImage(); + if (!previous && faces[0]) previous = faces[0]; + if (previous && previous->GetImage()) + { + SetImage(previous->GetImage()); + SetFromImage(); + } } diff --git a/src/common/textures/skyboxtexture.h b/src/common/textures/skyboxtexture.h index 07a75f1e8..1c7a6ad2b 100644 --- a/src/common/textures/skyboxtexture.h +++ b/src/common/textures/skyboxtexture.h @@ -8,7 +8,7 @@ // //----------------------------------------------------------------------------- -class FSkyBox : public FTexture +class FSkyBox : public FImageTexture { public: @@ -17,19 +17,7 @@ public: bool fliptop; FSkyBox(const char *name); - TArray Get8BitPixels(bool alphatex); - FBitmap GetBgraBitmap(const PalEntry *, int *trans) override; - FImageSource *GetImage() const override; - - - void SetSize() - { - if (!previous && faces[0]) previous = faces[0]; - if (previous) - { - CopySize(previous); - } - } + void SetSize(); bool Is3Face() const { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index c8e25a5ea..e1fa263fd 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -241,8 +241,8 @@ public: double GetDisplayHeightDouble() { return Height / Scale.Y; } int GetDisplayLeftOffset() { return GetScaledLeftOffset(0); } int GetDisplayTopOffset() { return GetScaledTopOffset(0); } - double GetDisplayLeftOffsetDouble() { return GetScaledLeftOffsetDouble(0); } - double GetDisplayTopOffsetDouble() { return GetScaledTopOffsetDouble(0); } + double GetDisplayLeftOffsetDouble(int adjusted = 0) { return _LeftOffset[adjusted] / Scale.X; } + double GetDisplayTopOffsetDouble(int adjusted = 0) { return _TopOffset[adjusted] / Scale.Y; } int GetTexelWidth() { return Width; } int GetTexelHeight() { return Height; } @@ -398,8 +398,6 @@ protected: int GetTopOffset(int adjusted) { return _TopOffset[adjusted]; } int GetScaledLeftOffset (int adjusted) { int foo = int((_LeftOffset[adjusted] * 2) / Scale.X); return (foo >> 1) + (foo & 1); } int GetScaledTopOffset (int adjusted) { int foo = int((_TopOffset[adjusted] * 2) / Scale.Y); return (foo >> 1) + (foo & 1); } - double GetScaledLeftOffsetDouble(int adjusted) { return _LeftOffset[adjusted] / Scale.X; } - double GetScaledTopOffsetDouble(int adjusted) { return _TopOffset[adjusted] / Scale.Y; } // Interfaces for the different renderers. Everything that needs to check renderer-dependent offsets // should use these, so that if changes are needed, this is the only place to edit. @@ -508,6 +506,9 @@ public: class FImageTexture : public FTexture { FImageSource* mImage; +protected: + FImageTexture(const char *name) : FTexture(name) {} + void SetFromImage(); public: FImageTexture(FImageSource* image, const char* name = nullptr) noexcept; virtual TArray Get8BitPixels(bool alphatex); diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index bbf679af2..ce6438aaf 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -73,8 +73,6 @@ public: int GetTopOffset(int adjusted) { return mTexture->GetTopOffset(adjusted); } int GetScaledLeftOffset (int adjusted) { return mTexture->GetScaledLeftOffset(adjusted); } int GetScaledTopOffset (int adjusted) { return mTexture->GetScaledTopOffset(adjusted); } - double GetScaledLeftOffsetDouble(int adjusted) { return mTexture->GetScaledLeftOffsetDouble(adjusted); } - double GetScaledTopOffsetDouble(int adjusted) { return mTexture->GetScaledTopOffsetDouble(adjusted); } // Interfaces for the different renderers. Everything that needs to check renderer-dependent offsets // should use these, so that if changes are needed, this is the only place to edit.