2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
#ifndef __TEXTURE_HPP
|
|
|
|
#define __TEXTURE_HPP
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
|
2012-11-11 19:28:03 +01:00
|
|
|
enum TexErr
|
|
|
|
{
|
|
|
|
TE_OK = 0,
|
|
|
|
TE_ERROR,
|
|
|
|
TE_NOMEM
|
|
|
|
};
|
|
|
|
|
2012-12-28 15:19:40 +01:00
|
|
|
struct TexData
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-12-28 15:19:40 +01:00
|
|
|
TexData() : data(NULL), dataSize(0), width(0), height(0), format(-1), maxLOD(0), thread(false) { }
|
2012-11-03 20:16:03 +01:00
|
|
|
u8 *data;
|
2012-11-04 20:22:02 +01:00
|
|
|
u32 dataSize;
|
2012-01-21 21:57:41 +01:00
|
|
|
u32 width;
|
|
|
|
u32 height;
|
|
|
|
u8 format;
|
|
|
|
u8 maxLOD;
|
2012-11-11 19:28:03 +01:00
|
|
|
bool thread;
|
2012-12-28 15:19:40 +01:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
class STexture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Cleanup(TexData &tex);
|
|
|
|
bool CopyTexture(const TexData &src, TexData &dest);
|
2012-07-23 00:10:17 +02:00
|
|
|
// Get from PNG, if not found from JPG
|
2012-12-28 15:19:40 +01:00
|
|
|
TexErr fromImageFile(TexData &dest, const char *filename, u8 f = -1, u32 minMipSize = 0, u32 maxMipSize = 0);
|
2012-01-21 21:57:41 +01:00
|
|
|
// This function doesn't use MEM2 if the PNG is loaded from memory and there's no mip mapping
|
2012-12-28 15:19:40 +01:00
|
|
|
TexErr fromPNG(TexData &dest, const u8 *buffer, u8 f = -1, u32 minMipSize = 0, u32 maxMipSize = 0);
|
|
|
|
TexErr fromJPG(TexData &dest, const u8 *buffer, const u32 buffer_size, u8 f = -1, u32 minMipSize = 0, u32 maxMipSize = 0);
|
2012-11-03 20:16:03 +01:00
|
|
|
/* Just for THP */
|
2012-12-28 15:19:40 +01:00
|
|
|
TexErr fromTHP(TexData &dest, const u8 *buffer, u32 w, u32 h);
|
2012-01-21 21:57:41 +01:00
|
|
|
private:
|
2012-11-03 20:16:03 +01:00
|
|
|
void _resize(u8 *dst, u32 dstWidth, u32 dstHeight, const u8 *src, u32 srcWidth, u32 srcHeight);
|
|
|
|
void _resizeD2x2(u8 *dst, const u8 *src, u32 srcWidth, u32 srcHeight);
|
|
|
|
u8 *_genMipMaps(u8 *src, u32 width, u32 height, u8 maxLOD, u32 lod0Width, u32 lod0Height);
|
|
|
|
void _calcMipMaps(u8 &maxLOD, u8 &minLOD, u32 &lod0Width, u32 &lod0Height, u32 width, u32 height, u32 minSize, u32 maxSize);
|
2012-01-21 21:57:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
u32 fixGX_GetTexBufferSize(u16 wd, u16 ht, u32 fmt, u8 mipmap, u8 maxlod);
|
|
|
|
|
2012-12-28 15:19:40 +01:00
|
|
|
extern STexture TexHandle;
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#endif //!defined(__TEXTURE_HPP)
|