2019-10-06 19:15:53 +00:00
|
|
|
/*
|
|
|
|
** gl_palmanager.cpp
|
|
|
|
** Palette management
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 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 <memory>
|
|
|
|
#include "m_crc32.h"
|
|
|
|
#include "glbackend.h"
|
|
|
|
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "resourcefile.h"
|
2019-10-17 22:20:27 +00:00
|
|
|
#include "imagehelpers.h"
|
2019-11-05 22:35:38 +00:00
|
|
|
#include "v_font.h"
|
2019-11-10 20:11:17 +00:00
|
|
|
#include "palette.h"
|
2020-05-24 22:31:05 +00:00
|
|
|
#include "build.h"
|
2019-10-06 19:15:53 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
2020-05-24 22:31:05 +00:00
|
|
|
// This class manages the hardware data for the indexed render mode.
|
2019-10-06 19:15:53 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
PaletteManager::~PaletteManager()
|
|
|
|
{
|
|
|
|
DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2020-05-24 22:31:05 +00:00
|
|
|
void PaletteManager::DeleteAll()
|
2019-10-06 19:15:53 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
for (auto& pal : palettetextures)
|
2019-10-06 19:15:53 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
if (pal) delete pal;
|
|
|
|
pal = nullptr;
|
2019-10-06 19:15:53 +00:00
|
|
|
}
|
2020-05-24 22:31:05 +00:00
|
|
|
for (auto& pal : palswaptextures)
|
2019-10-07 23:08:08 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
if (pal) delete pal;
|
|
|
|
pal = nullptr;
|
2019-10-07 23:08:08 +00:00
|
|
|
}
|
|
|
|
lastindex = ~0u;
|
|
|
|
lastsindex = ~0u;
|
2019-10-06 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
2020-05-24 22:31:05 +00:00
|
|
|
//
|
2019-10-06 19:15:53 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2020-05-24 22:31:05 +00:00
|
|
|
void PaletteManager::BindPalette(int index)
|
2019-10-06 19:15:53 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
auto palettedata = GPalette.GetTranslation(Translation_BasePalettes, index);
|
|
|
|
if (palettedata == nullptr)
|
2019-10-06 19:15:53 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
index = 0;
|
|
|
|
palettedata = GPalette.GetTranslation(Translation_BasePalettes, index);
|
|
|
|
};
|
2019-10-06 19:15:53 +00:00
|
|
|
|
2020-05-24 22:31:05 +00:00
|
|
|
if (palettedata)
|
2019-10-06 22:07:45 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
if (index != lastindex)
|
2019-10-06 22:07:45 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
lastindex = index;
|
2019-10-06 19:15:53 +00:00
|
|
|
|
2020-05-24 22:31:05 +00:00
|
|
|
if (palettetextures[index] == nullptr)
|
2019-10-06 19:15:53 +00:00
|
|
|
{
|
|
|
|
auto p = GLInterface.NewTexture();
|
2019-10-19 21:14:36 +00:00
|
|
|
p->CreateTexture(256, 1, FHardwareTexture::TrueColor, false);
|
2020-05-24 22:31:05 +00:00
|
|
|
p->LoadTexture((uint8_t*)palettedata->Palette);
|
2019-10-19 17:10:09 +00:00
|
|
|
p->SetSampler(SamplerNoFilterClampXY);
|
2020-05-24 22:31:05 +00:00
|
|
|
palettetextures[index] = p;
|
2019-10-06 19:15:53 +00:00
|
|
|
}
|
2020-05-24 22:31:05 +00:00
|
|
|
inst->BindTexture(2, palettetextures[index]);
|
2019-10-06 19:15:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:07:45 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2019-10-07 23:08:08 +00:00
|
|
|
void PaletteManager::BindPalswap(int index)
|
2019-10-06 19:15:53 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
if (LookupTables[index].Len() == 0) index = 0;
|
|
|
|
if (LookupTables[index].Len() > 0)
|
2019-10-06 22:07:45 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
if (index != lastsindex)
|
2019-10-07 23:08:08 +00:00
|
|
|
{
|
2020-05-24 22:31:05 +00:00
|
|
|
lastsindex = index;
|
|
|
|
if (palswaptextures[index] == nullptr)
|
2019-10-07 23:08:08 +00:00
|
|
|
{
|
|
|
|
auto p = GLInterface.NewTexture();
|
2019-10-19 21:14:36 +00:00
|
|
|
p->CreateTexture(256, numshades, FHardwareTexture::Indexed, false);
|
2020-05-24 22:31:05 +00:00
|
|
|
p->LoadTexture((uint8_t*)LookupTables[index].GetChars());
|
2019-10-19 17:10:09 +00:00
|
|
|
p->SetSampler(SamplerNoFilterClampXY);
|
2020-05-24 22:31:05 +00:00
|
|
|
palswaptextures[index] = p;
|
2019-10-07 23:08:08 +00:00
|
|
|
}
|
2020-05-24 22:31:05 +00:00
|
|
|
inst->BindTexture(1, palswaptextures[index]);
|
|
|
|
inst->SetFadeColor(PalEntry(palookupfog[index].r, palookupfog[index].g, palookupfog[index].b));
|
2019-10-07 23:08:08 +00:00
|
|
|
}
|
2019-10-06 22:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-10-07 23:08:08 +00:00
|
|
|
|
2019-10-17 22:20:27 +00:00
|
|
|
|