2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2013-08-31 23:58:47 +02:00
|
|
|
#define LC_TEXTURE_WRAPU 0x01
|
|
|
|
#define LC_TEXTURE_WRAPV 0x02
|
|
|
|
#define LC_TEXTURE_MIPMAPS 0x04
|
2018-10-29 01:59:01 +01:00
|
|
|
#define LC_TEXTURE_CUBEMAP 0x08
|
2013-08-31 23:58:47 +02:00
|
|
|
|
|
|
|
#define LC_TEXTURE_POINT 0x00
|
|
|
|
#define LC_TEXTURE_LINEAR 0x10
|
|
|
|
#define LC_TEXTURE_BILINEAR 0x20
|
|
|
|
#define LC_TEXTURE_TRILINEAR 0x30
|
|
|
|
#define LC_TEXTURE_ANISOTROPIC 0x40
|
|
|
|
#define LC_TEXTURE_FILTER_MASK 0xf0
|
|
|
|
#define LC_TEXTURE_FILTER_SHIFT 4
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
#define LC_TEXTURE_NAME_LEN 256
|
|
|
|
|
2017-12-22 14:42:28 +01:00
|
|
|
#include "image.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
class lcTexture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcTexture();
|
|
|
|
~lcTexture();
|
|
|
|
|
2020-05-04 00:39:39 +02:00
|
|
|
lcTexture(const lcTexture&) = delete;
|
|
|
|
lcTexture(lcTexture&&) = delete;
|
|
|
|
lcTexture& operator=(const lcTexture&) = delete;
|
|
|
|
lcTexture& operator=(lcTexture&&) = delete;
|
|
|
|
|
2014-08-24 00:56:59 +02:00
|
|
|
void CreateGridTexture();
|
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
bool Load(const QString& FileName, int Flags = 0);
|
2013-08-09 06:57:18 +02:00
|
|
|
bool Load(lcMemFile& File, int Flags = 0);
|
2021-11-21 21:16:19 +01:00
|
|
|
void SetImage(Image&& Image, int Flags = 0);
|
2018-10-29 01:59:01 +01:00
|
|
|
void SetImage(std::vector<Image>&& Images, int Flags = 0);
|
2018-09-30 04:45:21 +02:00
|
|
|
void Upload(lcContext* Context);
|
2013-08-09 06:57:18 +02:00
|
|
|
void Unload();
|
|
|
|
|
2017-12-22 14:42:28 +01:00
|
|
|
void AddRef()
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2017-12-22 14:42:28 +01:00
|
|
|
mRefCount.ref();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
if (mRefCount == 1)
|
|
|
|
Load();
|
|
|
|
}
|
|
|
|
|
2017-12-22 14:42:28 +01:00
|
|
|
bool Release()
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const bool InUse = mRefCount.deref();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-12-22 14:42:28 +01:00
|
|
|
if (!InUse)
|
2013-08-09 06:57:18 +02:00
|
|
|
Unload();
|
|
|
|
|
2017-12-22 14:42:28 +01:00
|
|
|
return InUse;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2017-07-02 02:12:09 +02:00
|
|
|
void SetTemporary(bool Temporary)
|
|
|
|
{
|
|
|
|
mTemporary = Temporary;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsTemporary() const
|
|
|
|
{
|
|
|
|
return mTemporary;
|
|
|
|
}
|
|
|
|
|
2021-03-13 23:09:08 +01:00
|
|
|
bool NeedsUpload() const
|
|
|
|
{
|
|
|
|
return mTexture == 0 && !mImages.empty();
|
|
|
|
}
|
|
|
|
|
2021-11-22 03:25:17 +01:00
|
|
|
int GetFlags() const
|
|
|
|
{
|
|
|
|
return mFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Image& GetImage(int Index) const
|
|
|
|
{
|
|
|
|
return mImages[Index];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetImageCount() const
|
|
|
|
{
|
|
|
|
return mImages.size();
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
int mWidth;
|
|
|
|
int mHeight;
|
|
|
|
char mName[LC_TEXTURE_NAME_LEN];
|
2019-10-26 20:41:49 +02:00
|
|
|
QString mFileName;
|
2013-08-09 06:57:18 +02:00
|
|
|
GLuint mTexture;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool Load();
|
2021-11-22 03:25:17 +01:00
|
|
|
bool LoadImages();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-07-02 02:12:09 +02:00
|
|
|
bool mTemporary;
|
2017-12-22 14:42:28 +01:00
|
|
|
QAtomicInt mRefCount;
|
|
|
|
std::vector<Image> mImages;
|
|
|
|
int mFlags;
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
2014-10-05 07:21:51 +02:00
|
|
|
lcTexture* lcLoadTexture(const QString& FileName, int Flags);
|
|
|
|
void lcReleaseTexture(lcTexture* Texture);
|
|
|
|
|
2014-08-24 00:56:59 +02:00
|
|
|
extern lcTexture* gGridTexture;
|
|
|
|
|