leocad/common/lc_texture.h

109 lines
1.9 KiB
C
Raw Normal View History

#pragma once
2013-08-09 06:57:18 +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
#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
#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;
void CreateGridTexture();
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);
void Upload(lcContext* Context);
2013-08-09 06:57:18 +02:00
void Unload();
void AddRef()
2013-08-09 06:57:18 +02:00
{
mRefCount.ref();
2013-08-09 06:57:18 +02:00
if (mRefCount == 1)
Load();
}
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
if (!InUse)
2013-08-09 06:57:18 +02:00
Unload();
return InUse;
2013-08-09 06:57:18 +02:00
}
void SetTemporary(bool Temporary)
{
mTemporary = Temporary;
}
bool IsTemporary() const
{
return mTemporary;
}
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];
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
bool mTemporary;
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);
extern lcTexture* gGridTexture;