diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b13fabe9d..35e529a08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1089,7 +1089,6 @@ set (PCH_SOURCES gl/textures/gl_material.cpp gl/textures/gl_hirestex.cpp gl/textures/gl_samplers.cpp - gl/textures/gl_translate.cpp gl/textures/gl_hqresize.cpp menu/joystickmenu.cpp menu/loadsavemenu.cpp diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 1c6a3e65c..c9a615c0c 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -50,7 +50,6 @@ #include "gl/scene/gl_drawinfo.h" #include "gl/scene/gl_scenedrawer.h" #include "gl/data/gl_vertexbuffer.h" -#include "gl/textures/gl_translate.h" CVAR(Bool, gl_lights_additive, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -954,7 +953,7 @@ int LegacyDesaturation(F2DDrawer::RenderCommand &cmd) // The easy case: It was already done. auto find = DesaturatedTranslationTable.CheckKey(cmd.mTranslation); - if (find != nullptr && find->tables[desat] != nullptr) return GLTranslationPalette::GetInternalTranslation(find->tables[desat]); + if (find != nullptr && find->tables[desat] != nullptr) return find->tables[desat]->GetUniqueIndex(); // To handle this case for the legacy renderer a desaturated variant of the translation needs to be built. auto newremap = new FRemapTable(*cmd.mTranslation); @@ -971,5 +970,5 @@ int LegacyDesaturation(F2DDrawer::RenderCommand &cmd) } auto &tbl = DesaturatedTranslationTable[cmd.mTranslation]; tbl.tables[desat] = newremap; - return GLTranslationPalette::GetInternalTranslation(newremap); + return newremap->GetUniqueIndex(); } \ No newline at end of file diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index d399bc066..f5a48842d 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -64,7 +64,6 @@ #include "gl/shaders/gl_postprocessshader.h" #include "gl/stereo3d/gl_stereo3d.h" #include "gl/textures/gl_texture.h" -#include "gl/textures/gl_translate.h" #include "gl/textures/gl_material.h" #include "gl/textures/gl_samplers.h" #include "gl/utility/gl_clock.h" @@ -576,7 +575,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) auto mat = FMaterial::ValidateTexture(cmd.mTexture, false); if (mat == nullptr) continue; - if (gltrans == -1) gltrans = GLTranslationPalette::GetInternalTranslation(cmd.mTranslation); + if (gltrans == -1 && cmd.mTranslation != nullptr) gltrans = cmd.mTranslation->GetUniqueIndex(); gl_RenderState.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, -gltrans, -1, cmd.mDrawMode == F2DDrawer::DTM_AlphaTexture); gl_RenderState.EnableTexture(true); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 8a3000fe1..bd7d4be61 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -45,7 +45,6 @@ #include "gl/data/gl_data.h" #include "gl/textures/gl_hwtexture.h" #include "gl/textures/gl_texture.h" -#include "gl/textures/gl_translate.h" #include "gl/utility/gl_clock.h" #include "gl/utility/gl_templates.h" #include "gl/gl_functions.h" @@ -340,19 +339,6 @@ int OpenGLFrameBuffer::GetPageCount() } -//========================================================================== -// -// DFrameBuffer :: CreatePalette -// -// Creates a native palette from a remap table, if supported. -// -//========================================================================== - -FNativePalette *OpenGLFrameBuffer::CreatePalette(FRemapTable *remap) -{ - return GLTranslationPalette::CreatePalette(remap); -} - //========================================================================== // // diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 73c3c8d5f..4f3724b86 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -56,8 +56,6 @@ public: // Releases the screenshot buffer. virtual void ReleaseScreenshotBuffer(); - FNativePalette *CreatePalette(FRemapTable *remap); - bool WipeStartScreen(int type); void WipeEndScreen(); bool WipeDo(int ticks); diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index 9c3f4c960..25811cb91 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -39,7 +39,6 @@ #include "gl/system/gl_framebuffer.h" #include "gl/system/gl_cvars.h" #include "gl/shaders/gl_shader.h" -#include "gl/textures/gl_translate.h" #include "gl/textures/gl_material.h" #include "gl/textures/gl_samplers.h" #include "gl/utility/gl_templates.h" diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 1ab90ef03..6975f4d76 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -44,7 +44,6 @@ #include "gl/renderer/gl_renderer.h" #include "gl/data/gl_data.h" #include "gl/textures/gl_texture.h" -#include "gl/textures/gl_translate.h" #include "gl/textures/gl_material.h" #include "gl/textures/gl_samplers.h" #include "gl/shaders/gl_shader.h" @@ -250,7 +249,7 @@ unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, F { // When using translations everything must be mapped to the base palette. // so use CopyTrueColorTranslated - tex->CopyTrueColorTranslated(&bmp, exx, exx, 0, GLTranslationPalette::GetPalette(translation)); + tex->CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation)); isTransparent = 0; // This is not conclusive for setting the texture's transparency info. } @@ -299,7 +298,8 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla } else { - translation = GLTranslationPalette::GetInternalTranslation(translation); + auto remap = TranslationToTable(translation); + translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); } } diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index a74173325..17e9464bf 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -46,7 +46,6 @@ #include "gl/textures/gl_texture.h" #include "gl/textures/gl_material.h" #include "gl/textures/gl_samplers.h" -#include "gl/textures/gl_translate.h" #include "gl/models/gl_models.h" //========================================================================== @@ -513,7 +512,8 @@ void gl_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl while (it.NextPair(pair)) { PClassActor *cls = pair->Key; - int gltrans = GLTranslationPalette::GetInternalTranslation(GetDefaultByType(cls)->Translation); + auto remap = TranslationToTable(GetDefaultByType(cls)->Translation); + int gltrans = remap == nullptr ? 0 : remap->GetUniqueIndex(); for (unsigned i = 0; i < cls->GetStateCount(); i++) { diff --git a/src/gl/textures/gl_translate.cpp b/src/gl/textures/gl_translate.cpp deleted file mode 100644 index c775c50a6..000000000 --- a/src/gl/textures/gl_translate.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2007-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/ -// -//-------------------------------------------------------------------------- -// -/* -** gl_translate.cpp -** GL-related translation stuff -** -*/ - -#include "doomtype.h" -#include "r_data/r_translate.h" -#include "gl/textures/gl_translate.h" -#include "m_crc32.h" - -TArray GLTranslationPalette::AllPalettes; - - -GLTranslationPalette *GLTranslationPalette::CreatePalette(FRemapTable *remap) -{ - GLTranslationPalette *p = new GLTranslationPalette(remap); - p->Update(); - return p; -} - -bool GLTranslationPalette::Update() -{ - PalData pd; - - memset(pd.pe, 0, sizeof(pd.pe)); - memcpy(pd.pe, remap->Palette, remap->NumEntries * sizeof(*remap->Palette)); - pd.crc32 = CalcCRC32((uint8_t*)pd.pe, sizeof(pd.pe)); - for(unsigned int i=0;i< AllPalettes.Size(); i++) - { - if (pd.crc32 == AllPalettes[i].crc32) - { - if (!memcmp(pd.pe, AllPalettes[i].pe, sizeof(pd.pe))) - { - Index = 1+i; - return true; - } - } - } - Index = 1+AllPalettes.Push(pd); - return true; -} - -int GLTranslationPalette::GetInternalTranslation(FRemapTable *remap) -{ - if (remap == nullptr || remap->Inactive) return 0; - - GLTranslationPalette *tpal = static_cast(remap->GetNative()); - if (tpal == nullptr) return 0; - return tpal->GetIndex(); -} - -int GLTranslationPalette::GetInternalTranslation(int trans) -{ - if (trans <= 0) return 0; - return GetInternalTranslation(TranslationToTable(trans)); -} diff --git a/src/gl/textures/gl_translate.h b/src/gl/textures/gl_translate.h deleted file mode 100644 index 092f4d73e..000000000 --- a/src/gl/textures/gl_translate.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __GL_TRANSLATE__ -#define __GL_TRANSLATE__ - -#include "doomtype.h" -#include "v_video.h" - -enum -{ - TRANSLATION_ICE = -1, - TRANSLATION_INTENSITY = -2, - TRANSLATION_SHADE = -3, -}; - - -class GLTranslationPalette : public FNativePalette -{ - struct PalData - { - int crc32; - PalEntry pe[256]; - }; - static TArray AllPalettes; - - int Index; - FRemapTable *remap; - - GLTranslationPalette(FRemapTable *r) { remap=r; Index=-1; } - -public: - - static GLTranslationPalette *CreatePalette(FRemapTable *remap); - static int GetInternalTranslation(int trans); - static int GetInternalTranslation(FRemapTable *trans); - static PalEntry *GetPalette(unsigned int index) - { - return index > 0 && index <= AllPalettes.Size()? AllPalettes[index-1].pe : NULL; - } - bool Update(); - int GetIndex() const { return Index; } -}; - - -#endif diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index 5f17c9002..28a480b3d 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -52,6 +52,7 @@ #include "r_state.h" #include "vm.h" #include "v_text.h" +#include "m_crc32.h" #include "gi.h" #include "stats.h" @@ -103,6 +104,38 @@ static bool IndexOutOfRange(const int start1, const int end1, const int start2, return IndexOutOfRange(start2, end2) || outOfRange; } + + +TArray FUniquePalette::AllPalettes; + +//---------------------------------------------------------------------------- +// +// Helper class to deal with frequently changing translations from ACS +// +//---------------------------------------------------------------------------- + +bool FUniquePalette::Update() +{ + PalData pd; + + memset(pd.pe, 0, sizeof(pd.pe)); + memcpy(pd.pe, remap->Palette, remap->NumEntries * sizeof(*remap->Palette)); + pd.crc32 = CalcCRC32((uint8_t*)pd.pe, sizeof(pd.pe)); + for (unsigned int i = 0; i< AllPalettes.Size(); i++) + { + if (pd.crc32 == AllPalettes[i].crc32) + { + if (!memcmp(pd.pe, AllPalettes[i].pe, sizeof(pd.pe))) + { + Index = 1 + i; + return true; + } + } + } + Index = 1 + AllPalettes.Push(pd); + return true; +} + /****************************************************/ /****************************************************/ @@ -133,6 +166,23 @@ FRemapTable::~FRemapTable() // //---------------------------------------------------------------------------- +int FRemapTable::GetUniqueIndex() +{ + if (Inactive) return 0; + if (Native == nullptr) + { + Native = new FUniquePalette(this); + Native->Update(); + } + return Native->GetIndex(); +} + +//---------------------------------------------------------------------------- +// +// +// +//---------------------------------------------------------------------------- + void FRemapTable::Alloc(int count) { Remap = (uint8_t *)M_Malloc(count*sizeof(*Remap) + count*sizeof(*Palette)); @@ -356,21 +406,6 @@ void FRemapTable::UpdateNative() // //---------------------------------------------------------------------------- -FNativePalette *FRemapTable::GetNative() -{ - if (Native == NULL) - { - Native = screen->CreatePalette(this); - } - return Native; -} - -//---------------------------------------------------------------------------- -// -// -// -//---------------------------------------------------------------------------- - bool FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) { if (IndexOutOfRange(start, end, pal1, pal2)) diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index da69745a4..8e704a5d3 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -4,7 +4,6 @@ #include "doomtype.h" #include "tarray.h" -class FNativePalette; class FSerializer; enum @@ -31,6 +30,34 @@ enum EStandardTranslations STD_Grayscale = 9, // desaturated version of the palette. }; +struct FRemapTable; + +class FUniquePalette +{ + friend struct FRemapTable; + struct PalData + { + int crc32; + PalEntry pe[256]; + }; + static TArray AllPalettes; + + int Index; + FRemapTable *remap; + + FUniquePalette(FRemapTable *r) { remap = r; Index = -1; } + +public: + + static PalEntry *GetPalette(unsigned int index) + { + return index > 0 && index <= AllPalettes.Size() ? AllPalettes[index - 1].pe : NULL; + } + bool Update(); + int GetIndex() const { return Index; } +}; + + struct FRemapTable { FRemapTable(int count=256); @@ -42,7 +69,6 @@ struct FRemapTable void MakeIdentity(); void KillNative(); void UpdateNative(); - FNativePalette *GetNative(); bool IsIdentity() const; void Serialize(FSerializer &arc); static void StaticSerializeTranslations(FSerializer &arc); @@ -53,10 +79,11 @@ struct FRemapTable bool AddTint(int start, int end, int r, int g, int b, int amount); bool AddToTranslation(const char * range); int StoreTranslation(int slot); + int GetUniqueIndex(); uint8_t *Remap; // For the software renderer PalEntry *Palette; // The ideal palette this maps to - FNativePalette *Native; // The Palette stored in a HW texture + FUniquePalette *Native; // The index into the list of unique palettes (this is to avoid frequent texture recreation with changing ACS translations) int NumEntries; // # of elements in this table (usually 256) bool Inactive; // This table is inactive and should be treated as if it was passed as NULL diff --git a/src/v_video.cpp b/src/v_video.cpp index 1e806b1f2..9247807d0 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -882,19 +882,6 @@ void DFrameBuffer::DrawBlendingRect() { } -//========================================================================== -// -// DFrameBuffer :: CreatePalette -// -// Creates a native palette from a remap table, if supported. -// -//========================================================================== - -FNativePalette *DFrameBuffer::CreatePalette(FRemapTable *remap) -{ - return NULL; -} - //========================================================================== // // DFrameBuffer :: WipeStartScreen @@ -958,17 +945,6 @@ void DFrameBuffer::GameRestart() { } -//=========================================================================== -// -// -// -//=========================================================================== - -FNativePalette::~FNativePalette() -{ -} - - CCMD(clean) { Printf ("CleanXfac: %d\nCleanYfac: %d\n", CleanXfac, CleanYfac); diff --git a/src/v_video.h b/src/v_video.h index dc2db39cf..56f078b3d 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -260,13 +260,7 @@ public: }; -// This class represents a texture lookup palette. -class FNativePalette -{ -public: - virtual ~FNativePalette(); - virtual bool Update() = 0; -}; +class FUniquePalette; // A canvas that represents the actual display. The video code is responsible // for actually implementing this. Built on top of SimpleCanvas, because it @@ -369,9 +363,6 @@ public: // accelerated 2D mode. virtual void DrawBlendingRect(); - // Create a palette texture from a remap/palette table. - virtual FNativePalette *CreatePalette(FRemapTable *remap); - // Precaches or unloads a texture // Report a game restart