- integrated GL parts of translation handling into the main module.

Now that this doesn't have to share assets with HW2D it could be simplified a lot.
This commit is contained in:
Christoph Oelckers 2018-04-01 00:59:49 +02:00
parent bc485a7f2c
commit a9d5533603
14 changed files with 89 additions and 201 deletions

View file

@ -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

View file

@ -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();
}

View file

@ -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);

View file

@ -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);
}
//==========================================================================
//
//

View file

@ -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);

View file

@ -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"

View file

@ -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();
}
}

View file

@ -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<PClassActor*, bool> &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++)
{

View file

@ -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::PalData> 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<GLTranslationPalette*>(remap->GetNative());
if (tpal == nullptr) return 0;
return tpal->GetIndex();
}
int GLTranslationPalette::GetInternalTranslation(int trans)
{
if (trans <= 0) return 0;
return GetInternalTranslation(TranslationToTable(trans));
}

View file

@ -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<PalData> 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

View file

@ -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::PalData> 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))

View file

@ -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<PalData> 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

View file

@ -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);

View file

@ -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