leocad/common/lc_texture.h

88 lines
1.6 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();
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);
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
2017-12-30 21:49:50 +01:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) || QT_VERSION < QT_VERSION_CHECK(5, 0, 0) )
2013-08-09 06:57:18 +02:00
if (mRefCount == 1)
2017-12-30 21:49:50 +01:00
#else
if (mRefCount.load() == 1)
#endif
2013-08-09 06:57:18 +02:00
Load();
}
bool Release()
2013-08-09 06:57:18 +02:00
{
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;
}
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();
bool Load(int Flags);
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;