diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6ca5e7e13..78735bc91 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1022,7 +1022,6 @@ set (FASTMATH_SOURCES ${FASTMATH_SOURCES}) set (PCH_SOURCES glbackend/glbackend.cpp - glbackend/gl_palmanager.cpp glbackend/gl_texture.cpp thirdparty/src/md4.cpp @@ -1081,6 +1080,7 @@ set (PCH_SOURCES core/rendering/hw_entrypoint.cpp core/rendering/hw_models.cpp core/rendering/hw_voxels.cpp + core/rendering/hw_palmanager.cpp core/rendering/scene/hw_clipper.cpp core/rendering/scene/hw_walls.cpp core/rendering/scene/hw_flats.cpp diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 6bf494e9f..e395ece8a 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -75,6 +75,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gi.h" #include "gamefuncs.h" #include "hw_voxels.h" +#include "hw_palmanager.h" CVAR(Bool, autoloadlights, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Bool, autoloadbrightmaps, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -576,9 +577,9 @@ int GameMain() C_DeinitConsole(); V_ClearFonts(); voxClear(); + ClearPalManager(); TexMan.DeleteAll(); TileFiles.CloseAll(); // delete the texture data before shutting down graphics. - GLInterface.Deinit(); I_ShutdownGraphics(); freeallmodels(); if (gi) @@ -943,6 +944,8 @@ int RunGame() lookups.postLoadTables(); PostLoadSetup(); lookups.postLoadLookups(); + FMaterial::SetLayerCallback(setpalettelayer); + V_Init2(); twod->Begin(screen->GetWidth(), screen->GetHeight()); twod->End(); diff --git a/source/glbackend/gl_palmanager.cpp b/source/core/rendering/hw_palmanager.cpp similarity index 87% rename from source/glbackend/gl_palmanager.cpp rename to source/core/rendering/hw_palmanager.cpp index aee5dade4..0298aa657 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/core/rendering/hw_palmanager.cpp @@ -35,7 +35,7 @@ #include #include "m_crc32.h" -#include "glbackend.h" +#include "hw_palmanager.h" #include "resourcefile.h" #include "imagehelpers.h" @@ -44,6 +44,8 @@ #include "build.h" #include "v_video.h" +static PaletteManager* palmanager; + //=========================================================================== // // This class manages the hardware data for the indexed render mode. @@ -138,4 +140,24 @@ IHardwareTexture* PaletteManager::GetLookup(int index) return nullptr; } +//=========================================================================== +// +// +// +//=========================================================================== +IHardwareTexture *setpalettelayer(int layer, int translation) +{ + if (!palmanager) palmanager = new PaletteManager; + if (layer == 1) + return palmanager->GetPalette(GetTranslationType(translation) - Translation_Remap); + else if (layer == 2) + return palmanager->GetLookup(GetTranslationIndex(translation)); + else return nullptr; +} + +void ClearPalManager() +{ + if (palmanager) delete palmanager; + palmanager = nullptr; +} \ No newline at end of file diff --git a/source/core/rendering/hw_palmanager.h b/source/core/rendering/hw_palmanager.h new file mode 100644 index 000000000..e308f79ab --- /dev/null +++ b/source/core/rendering/hw_palmanager.h @@ -0,0 +1,24 @@ +#pragma once + +#include "gl_hwtexture.h" + +struct palette_t; + +class PaletteManager +{ + IHardwareTexture* palettetextures[256] = {}; + IHardwareTexture* lookuptextures[256] = {}; + + unsigned FindPalswap(const uint8_t* paldata, palette_t& fadecolor); + +public: + ~PaletteManager(); + void DeleteAll(); + IHardwareTexture *GetPalette(int index); + IHardwareTexture* GetLookup(int index); +}; + + +IHardwareTexture* setpalettelayer(int layer, int translation); +void ClearPalManager(); + diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index dc44c5e37..a31f8aa70 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -70,33 +70,16 @@ void Draw2D(F2DDrawer* drawer, FRenderState& state); GLInstance GLInterface; GLInstance::GLInstance() - :palmanager(this) { VSMatrix mat(0); matrixArray.Push(mat); } -IHardwareTexture *setpalettelayer(int layer, int translation) -{ - if (layer == 1) - return GLInterface.palmanager.GetPalette(GetTranslationType(translation) - Translation_Remap); - else if (layer == 2) - return GLInterface.palmanager.GetLookup(GetTranslationIndex(translation)); - else return nullptr; -} - void GLInstance::Init(int ydim) { - FMaterial::SetLayerCallback(setpalettelayer); new(&renderState) PolymostRenderState; // reset to defaults. } -void GLInstance::Deinit() -{ - palmanager.DeleteAll(); - lastPalswapIndex = -1; -} - void GLInstance::Draw(EDrawType type, size_t start, size_t count) { assert (BufferLock > 0); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index a21ccb2a3..90512258d 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -21,25 +21,6 @@ class F2DDrawer; struct palette_t; extern int xdim, ydim; -class PaletteManager -{ - IHardwareTexture* palettetextures[256] = {}; - IHardwareTexture* lookuptextures[256] = {}; - - GLInstance* const inst; - - unsigned FindPalswap(const uint8_t* paldata, palette_t& fadecolor); - -public: - PaletteManager(GLInstance *inst_) : inst(inst_) - {} - ~PaletteManager(); - void DeleteAll(); - IHardwareTexture *GetPalette(int index); - IHardwareTexture* GetLookup(int index); -}; - - struct glinfo_t { float maxanisotropy; }; @@ -75,9 +56,7 @@ class GLInstance friend IHardwareTexture* setpalettelayer(int layer, int translation); public: - TArray rendercommands; - PaletteManager palmanager; - int lastPalswapIndex = -1; + TArray rendercommands; FGameTexture* currentTexture = nullptr; int MatrixChange = 0; @@ -90,8 +69,6 @@ public: void Init(int y); - void Deinit(); - static int GetTexDimension(int value) { //if (value > gl.max_texturesize) return gl.max_texturesize;