1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef S3O_TEXTURE_HANDLER_H
#define S3O_TEXTURE_HANDLER_H
#include <string>
#include <vector>
#include "Bitmap.h"
#include "System/Threading/SpringThreading.h"
#include "System/UnorderedMap.hpp"
struct S3DModel;
class CBitmap;
class CS3OTextureHandler
{
public:
struct S3OTexMat {
int num;
unsigned int tex1;
unsigned int tex2;
unsigned int tex1SizeX;
unsigned int tex1SizeY;
unsigned int tex2SizeX;
unsigned int tex2SizeY;
};
struct CachedS3OTex {
unsigned int texID;
unsigned int xsize;
unsigned int ysize;
};
void Init();
void Kill();
void LoadTexture(S3DModel* model);
void PreloadTexture(S3DModel* model, bool invertAxis = false, bool invertAlpha = false);
public:
const S3OTexMat* GetTexture(unsigned int num) {
if (num < textures.size())
return &textures[num];
return nullptr;
}
private:
unsigned int LoadAndCacheTexture(
const S3DModel* model,
unsigned int texNum,
bool invertAxis,
bool invertAlpha,
bool preloadCall
);
unsigned int InsertTextureMat(const S3DModel* model);
private:
typedef spring::unsynced_map<std::string, CachedS3OTex> TextureCache;
typedef spring::unsynced_map<std::string, CBitmap> BitmapCache;
typedef spring::unsynced_map<std::uint64_t, unsigned int> TextureTable;
TextureCache textureCache; // stores individual primary- and secondary-textures by name
TextureTable textureTable; // stores (primary, secondary) texture-pairs by unique ident
BitmapCache bitmapCache;
spring::mutex cacheMutex;
std::vector<S3OTexMat> textures;
};
extern CS3OTextureHandler textureHandlerS3O;
#endif /* S3O_TEXTURE_HANDLER_H */
|