2019-09-17 17:03:42 +00:00
|
|
|
|
|
|
|
#ifndef __GLTEXTURE_H
|
|
|
|
#define __GLTEXTURE_H
|
|
|
|
|
2019-10-05 19:59:03 +00:00
|
|
|
class FBitmap;
|
2019-10-06 07:31:36 +00:00
|
|
|
class FTexture;
|
2019-09-17 17:03:42 +00:00
|
|
|
|
2019-10-06 08:19:51 +00:00
|
|
|
#include "tarray.h"
|
|
|
|
|
2019-09-17 17:03:42 +00:00
|
|
|
class FHardwareTexture //: public IHardwareTexture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-09-18 18:44:21 +00:00
|
|
|
int mSampler = 0;
|
2019-09-17 17:03:42 +00:00
|
|
|
unsigned int glTexID = 0;
|
|
|
|
int glTextureBytes = 4;
|
|
|
|
bool mipmapped = true;
|
|
|
|
int mWidth = 0, mHeight = 0;
|
2019-10-06 07:31:36 +00:00
|
|
|
int colorId = 0;
|
2019-09-17 17:03:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
~FHardwareTexture();
|
|
|
|
|
|
|
|
//bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);
|
|
|
|
|
|
|
|
unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped);
|
|
|
|
unsigned int LoadTexture(unsigned char * buffer);
|
2019-10-05 19:59:03 +00:00
|
|
|
unsigned int LoadTexture(FBitmap &bmp);
|
2019-09-17 17:03:42 +00:00
|
|
|
unsigned int GetTextureHandle();
|
2019-09-18 18:44:21 +00:00
|
|
|
int GetSampler() { return mSampler; }
|
|
|
|
void SetSampler(int sampler) { mSampler = sampler; }
|
2019-10-06 07:31:36 +00:00
|
|
|
|
|
|
|
friend class FGameTexture;
|
|
|
|
};
|
|
|
|
|
2019-10-06 08:19:51 +00:00
|
|
|
// This class identifies a single source image to the game.
|
|
|
|
// Since hightile palette variations are identified by file name, they will create separate game textures.
|
2019-10-06 07:31:36 +00:00
|
|
|
class FGameTexture
|
|
|
|
{
|
|
|
|
int Width, Height;
|
|
|
|
bool isHightile;
|
|
|
|
|
2019-10-06 08:19:51 +00:00
|
|
|
// Source image for this texture.
|
2019-10-06 07:31:36 +00:00
|
|
|
FTexture* sourceData = nullptr;
|
2019-10-06 08:19:51 +00:00
|
|
|
// indexed or the sole image for hightiles.
|
2019-10-06 07:31:36 +00:00
|
|
|
FHardwareTexture* hwBase = nullptr;
|
|
|
|
// If the number was large a TMap would be better -
|
|
|
|
// but in most cases the maximum number of palettes for a single tile is less than 10 where a linear search is much faster than a TMap.
|
|
|
|
TArray<FHardwareTexture*> hwTextures;
|
|
|
|
public:
|
|
|
|
FGameTexture(bool hightile, int width, int height);
|
|
|
|
virtual ~FGameTexture();
|
|
|
|
|
|
|
|
// For dynamic subtypes.
|
|
|
|
virtual void SizeChanged(int width, int height);
|
|
|
|
static constexpr int MakeId(int palette, int palswap)
|
|
|
|
{
|
|
|
|
return palette + 256 * palswap;
|
|
|
|
}
|
|
|
|
|
|
|
|
FHardwareTexture* GetBaseTexture();
|
|
|
|
FHardwareTexture* CreateHardwareTexture(int palette, int palswap);
|
|
|
|
|
|
|
|
FHardwareTexture* GetHardwareTexture(int palette, int palswap)
|
|
|
|
{
|
|
|
|
if (isHightile) return GetBaseTexture();
|
|
|
|
auto id = MakeId(palette, palswap);
|
|
|
|
auto found = hwTextures.FindEx([=](FHardwareTexture* tex)
|
|
|
|
{
|
|
|
|
return tex->colorId == id;
|
|
|
|
});
|
|
|
|
if (!found) return CreateHardwareTexture(palette, palswap);
|
|
|
|
}
|
2019-09-17 17:03:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|