diff --git a/rts/Rendering/Textures/3DOTextureHandler.cpp b/rts/Rendering/Textures/3DOTextureHandler.cpp index c5a3ee59013..a87093f66dc 100644 --- a/rts/Rendering/Textures/3DOTextureHandler.cpp +++ b/rts/Rendering/Textures/3DOTextureHandler.cpp @@ -186,13 +186,13 @@ std::vector C3DOTextureHandler::LoadTexFiles() std::vector texFiles; - const std::vector& filesBMP = CFileHandler::FindFiles("unittextures/tatex/", "*.bmp"); - std::vector files = CFileHandler::FindFiles("unittextures/tatex/", "*.tga"); + const std::vector& bmpFiles = CFileHandler::FindFiles("unittextures/tatex/", "*.bmp"); + std::vector tgaFiles = CFileHandler::FindFiles("unittextures/tatex/", "*.tga"); - files.insert(files.end(), filesBMP.begin(), filesBMP.end()); - texFiles.reserve(files.size() + CTAPalette::NUM_PALETTE_ENTRIES); + tgaFiles.insert(tgaFiles.end(), bmpFiles.begin(), bmpFiles.end()); + texFiles.reserve(tgaFiles.size() + CTAPalette::NUM_PALETTE_ENTRIES); - for (const std::string& s: files) { + for (const std::string& s: tgaFiles) { const std::string s2 = StringToLower(FileSystem::GetBasename(s)); // avoid duplicate names and give tga images priority @@ -208,8 +208,7 @@ std::vector C3DOTextureHandler::LoadTexFiles() } } - if (paletteFile.FileExists()) - palette.Init(paletteFile); + palette.Init(paletteFile); for (unsigned a = 0; a < CTAPalette::NUM_PALETTE_ENTRIES; ++a) { TexFile texFile; diff --git a/rts/Rendering/Textures/3DOTextureHandler.h b/rts/Rendering/Textures/3DOTextureHandler.h index 2f8e5dc72bb..004b3323b98 100644 --- a/rts/Rendering/Textures/3DOTextureHandler.h +++ b/rts/Rendering/Textures/3DOTextureHandler.h @@ -7,6 +7,7 @@ #include #include "Rendering/GL/myGL.h" +#include "Rendering/Textures/TAPalette.h" #include "System/float4.h" #include "System/UnorderedMap.hpp" @@ -38,6 +39,8 @@ class C3DOTextureHandler private: spring::unordered_map textures; + CTAPalette palette; + GLuint atlas3do1 = 0; GLuint atlas3do2 = 0; int bigTexX = 0; diff --git a/rts/Rendering/Textures/TAPalette.cpp b/rts/Rendering/Textures/TAPalette.cpp index 73197c1b9a7..eb71b5868cf 100644 --- a/rts/Rendering/Textures/TAPalette.cpp +++ b/rts/Rendering/Textures/TAPalette.cpp @@ -1,27 +1,17 @@ /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ - #include "TAPalette.h" #include "System/FileSystem/FileHandler.h" -CTAPalette palette; - -CTAPalette::CTAPalette() -{ - for (auto& color: p) { - color[0] = 0; - color[1] = 0; - color[2] = 0; - color[3] = 255; - } -} - void CTAPalette::Init(CFileHandler& paletteFile) { - for (auto& color: p) { - for (auto& channel: color) { - paletteFile.Read(&color, 1); - } - color[3] = 255; + if (!paletteFile.FileExists()) + return; + + for (SColor& color: colors) { + paletteFile.Read(&color.i, 4); + // ignore alpha + color.a = 255; } } + diff --git a/rts/Rendering/Textures/TAPalette.h b/rts/Rendering/Textures/TAPalette.h index d3b8c86cb71..6f4c5e86f18 100644 --- a/rts/Rendering/Textures/TAPalette.h +++ b/rts/Rendering/Textures/TAPalette.h @@ -3,21 +3,29 @@ #ifndef TA_PALETTE_H #define TA_PALETTE_H +#include +#include "System/Color.h" + class CFileHandler; class CTAPalette { public: - enum { NUM_PALETTE_ENTRIES = 256 }; + CTAPalette() { + for (SColor& color: colors) { + color.r = 0; + color.g = 0; + color.b = 0; + } + } - CTAPalette(); + void Init(CFileHandler&); - inline const unsigned char* operator[] (int a) const { return p[a]; } + const uint8_t* operator[] (unsigned int a) const { return colors[a]; } - void Init(CFileHandler&); +public: + static constexpr unsigned int NUM_PALETTE_ENTRIES = 256; private: - unsigned char p[NUM_PALETTE_ENTRIES][4]; + SColor colors[NUM_PALETTE_ENTRIES]; }; -extern CTAPalette palette; - #endif /* TA_PALETTE_H */