mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-27 09:20:51 +00:00
- draft class for in-game textures.
These will abstract away all the gory details so that the using code only sees a single entity to use.
This commit is contained in:
parent
4a866b0320
commit
126f670239
2 changed files with 43 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
#define __GLTEXTURE_H
|
#define __GLTEXTURE_H
|
||||||
|
|
||||||
class FBitmap;
|
class FBitmap;
|
||||||
|
class FTexture;
|
||||||
|
|
||||||
class FHardwareTexture //: public IHardwareTexture
|
class FHardwareTexture //: public IHardwareTexture
|
||||||
{
|
{
|
||||||
|
@ -15,6 +16,7 @@ private:
|
||||||
int glTextureBytes = 4;
|
int glTextureBytes = 4;
|
||||||
bool mipmapped = true;
|
bool mipmapped = true;
|
||||||
int mWidth = 0, mHeight = 0;
|
int mWidth = 0, mHeight = 0;
|
||||||
|
int colorId = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -28,6 +30,45 @@ public:
|
||||||
unsigned int GetTextureHandle();
|
unsigned int GetTextureHandle();
|
||||||
int GetSampler() { return mSampler; }
|
int GetSampler() { return mSampler; }
|
||||||
void SetSampler(int sampler) { mSampler = sampler; }
|
void SetSampler(int sampler) { mSampler = sampler; }
|
||||||
|
|
||||||
|
friend class FGameTexture;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FGameTexture
|
||||||
|
{
|
||||||
|
int Width, Height;
|
||||||
|
bool isHightile;
|
||||||
|
|
||||||
|
FTexture* sourceData = nullptr;
|
||||||
|
// either indexed or the sole image for hightiles.
|
||||||
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -159,7 +159,9 @@ public:
|
||||||
|
|
||||||
int GetTextureID();
|
int GetTextureID();
|
||||||
FHardwareTexture* NewTexture();
|
FHardwareTexture* NewTexture();
|
||||||
|
FGameTexture* NewTexture(const char *name, bool hightile);
|
||||||
void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler);
|
void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler);
|
||||||
|
void BindTexture(int texunit, FGameTexture* texid, int sampler = NoSampler);
|
||||||
void UnbindTexture(int texunit);
|
void UnbindTexture(int texunit);
|
||||||
void UnbindAllTextures();
|
void UnbindAllTextures();
|
||||||
void EnableBlend(bool on);
|
void EnableBlend(bool on);
|
||||||
|
|
Loading…
Reference in a new issue