mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Texture filter: switch to GL textures format.
This commit is contained in:
parent
c984298b7b
commit
4b92cd9444
|
@ -99,7 +99,7 @@ boolean ext_ghq_init(int maxwidth, int maxheight, int maxbpp, int options, int c
|
|||
if (!txfilter.shutdown)
|
||||
txfilter.shutdown = (txfilter_shutdown)DLSYM(txfilter.lib, "txfilter_shutdown");
|
||||
if (!txfilter.filter)
|
||||
txfilter.filter = (txfilter_filter)DLSYM(txfilter.lib, "txfilter");
|
||||
txfilter.filter = (txfilter_filter)DLSYM(txfilter.lib, "txfilter_filter");
|
||||
if (!txfilter.hirestex)
|
||||
txfilter.hirestex = (txfilter_hirestex)DLSYM(txfilter.lib, "txfilter_hirestex");
|
||||
if (!txfilter.checksum)
|
||||
|
|
|
@ -102,37 +102,19 @@ typedef unsigned char boolean;
|
|||
#define LET_TEXARTISTS_FLY 0x40000000 /* a little freedom for texture artists */
|
||||
#define DUMP_TEX 0x80000000
|
||||
|
||||
#ifndef __GLIDE_H__ /* GLIDE3 */
|
||||
/* from 3Dfx Interactive Inc. glide.h */
|
||||
#define GR_TEXFMT_ALPHA_8 0x2
|
||||
#define GR_TEXFMT_INTENSITY_8 0x3
|
||||
|
||||
#define GR_TEXFMT_ALPHA_INTENSITY_44 0x4
|
||||
#define GR_TEXFMT_P_8 0x5
|
||||
|
||||
#define GR_TEXFMT_RGB_565 0xa
|
||||
#define GR_TEXFMT_ARGB_1555 0xb
|
||||
#define GR_TEXFMT_ARGB_4444 0xc
|
||||
#define GR_TEXFMT_ALPHA_INTENSITY_88 0xd
|
||||
|
||||
#define GR_TEXFMT_ARGB_8888 0x12
|
||||
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT1 0x16
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT3 0x18
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT5 0x1A
|
||||
#endif /* GLIDE3 */
|
||||
|
||||
struct GHQTexInfo {
|
||||
unsigned char *data;
|
||||
int width;
|
||||
int height;
|
||||
unsigned short format;
|
||||
|
||||
int smallLodLog2;
|
||||
int largeLodLog2;
|
||||
int aspectRatioLog2;
|
||||
|
||||
unsigned int format;
|
||||
unsigned short texture_format;
|
||||
unsigned short pixel_type;
|
||||
unsigned char is_hires_tex;
|
||||
|
||||
GHQTexInfo() :
|
||||
data(NULL), width(0), height(0), format(0),
|
||||
texture_format(0), pixel_type(0), is_hires_tex(0)
|
||||
{}
|
||||
};
|
||||
|
||||
/* Callback to display hires texture info.
|
||||
|
@ -228,7 +210,7 @@ TAPI void TAPIENTRY
|
|||
txfilter_shutdown(void);
|
||||
|
||||
TAPI boolean TAPIENTRY
|
||||
txfilter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat,
|
||||
txfilter_filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat,
|
||||
uint64 g64crc, GHQTexInfo *info);
|
||||
|
||||
TAPI boolean TAPIENTRY
|
||||
|
|
|
@ -97,7 +97,7 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
|
|||
} else {
|
||||
DBG_INFO(80, L"zlib compressed: %.02fkb->%.02fkb\n", (float)dataSize/1000, (float)destLen/1000);
|
||||
dataSize = destLen;
|
||||
format |= GR_TEXFMT_GZ;
|
||||
format |= GL_TEXFMT_GZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,9 +161,6 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
|
|||
_cache.size(), (uint32)(checksum >> 32), (uint32)(checksum & 0xffffffff),
|
||||
info->width, info->height, info->format, (float)_totalSize/1000000);
|
||||
|
||||
DBG_INFO(80, L"smalllodlog2:%d largelodlog2:%d aspectratiolog2:%d\n",
|
||||
txCache->info.smallLodLog2, txCache->info.largeLodLog2, txCache->info.aspectRatioLog2);
|
||||
|
||||
if (_cacheSize > 0) {
|
||||
DBG_INFO(80, L"cache max config:%.02fmb\n", (float)_cacheSize/1000000);
|
||||
|
||||
|
@ -203,7 +200,7 @@ TxCache::get(uint64 checksum, GHQTexInfo *info)
|
|||
}
|
||||
|
||||
/* zlib decompress it */
|
||||
if (info->format & GR_TEXFMT_GZ) {
|
||||
if (info->format & GL_TEXFMT_GZ) {
|
||||
uint32 destLen = _gzdestLen;
|
||||
uint8 *dest = (_gzdest0 == info->data) ? _gzdest1 : _gzdest0;
|
||||
if (uncompress(dest, &destLen, info->data, ((*itMap).second)->size) != Z_OK) {
|
||||
|
@ -211,7 +208,7 @@ TxCache::get(uint64 checksum, GHQTexInfo *info)
|
|||
return 0;
|
||||
}
|
||||
info->data = dest;
|
||||
info->format &= ~GR_TEXFMT_GZ;
|
||||
info->format &= ~GL_TEXFMT_GZ;
|
||||
DBG_INFO(80, L"zlib decompressed: %.02fkb->%.02fkb\n", (float)(((*itMap).second)->size)/1000, (float)destLen/1000);
|
||||
}
|
||||
|
||||
|
@ -262,7 +259,7 @@ TxCache::save(const wchar_t *path, const wchar_t *filename, int config)
|
|||
* texture data in a zlib compressed state. if the GZ_TEXCACHE or GZ_HIRESTEXCACHE
|
||||
* option is toggled, the cache will need to be rebuilt.
|
||||
*/
|
||||
/*if (format & GR_TEXFMT_GZ) {
|
||||
/*if (format & GL_TEXFMT_GZ) {
|
||||
dest = _gzdest0;
|
||||
destLen = _gzdestLen;
|
||||
if (dest && destLen) {
|
||||
|
@ -270,7 +267,7 @@ TxCache::save(const wchar_t *path, const wchar_t *filename, int config)
|
|||
dest = NULL;
|
||||
destLen = 0;
|
||||
}
|
||||
format &= ~GR_TEXFMT_GZ;
|
||||
format &= ~GL_TEXFMT_GZ;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
@ -281,12 +278,9 @@ TxCache::save(const wchar_t *path, const wchar_t *filename, int config)
|
|||
/* other texture info */
|
||||
gzwrite(gzfp, &((*itMap).second->info.width), 4);
|
||||
gzwrite(gzfp, &((*itMap).second->info.height), 4);
|
||||
gzwrite(gzfp, &format, 2);
|
||||
|
||||
gzwrite(gzfp, &((*itMap).second->info.smallLodLog2), 4);
|
||||
gzwrite(gzfp, &((*itMap).second->info.largeLodLog2), 4);
|
||||
gzwrite(gzfp, &((*itMap).second->info.aspectRatioLog2), 4);
|
||||
|
||||
gzwrite(gzfp, &format, 4);
|
||||
gzwrite(gzfp, &((*itMap).second->info.texture_format), 2);
|
||||
gzwrite(gzfp, &((*itMap).second->info.pixel_type), 2);
|
||||
gzwrite(gzfp, &((*itMap).second->info.is_hires_tex), 1);
|
||||
|
||||
gzwrite(gzfp, &destLen, 4);
|
||||
|
@ -335,25 +329,21 @@ TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
|
|||
/* yep, we have it. load it into memory cache. */
|
||||
int dataSize;
|
||||
uint64 checksum;
|
||||
GHQTexInfo tmpInfo;
|
||||
int tmpconfig;
|
||||
/* read header to determine config match */
|
||||
gzread(gzfp, &tmpconfig, 4);
|
||||
|
||||
if (tmpconfig == config) {
|
||||
do {
|
||||
memset(&tmpInfo, 0, sizeof(GHQTexInfo));
|
||||
GHQTexInfo tmpInfo;
|
||||
|
||||
gzread(gzfp, &checksum, 8);
|
||||
|
||||
gzread(gzfp, &tmpInfo.width, 4);
|
||||
gzread(gzfp, &tmpInfo.height, 4);
|
||||
gzread(gzfp, &tmpInfo.format, 2);
|
||||
|
||||
gzread(gzfp, &tmpInfo.smallLodLog2, 4);
|
||||
gzread(gzfp, &tmpInfo.largeLodLog2, 4);
|
||||
gzread(gzfp, &tmpInfo.aspectRatioLog2, 4);
|
||||
|
||||
gzread(gzfp, &tmpInfo.format, 4);
|
||||
gzread(gzfp, &tmpInfo.texture_format, 2);
|
||||
gzread(gzfp, &tmpInfo.pixel_type, 2);
|
||||
gzread(gzfp, &tmpInfo.is_hires_tex, 1);
|
||||
|
||||
gzread(gzfp, &dataSize, 4);
|
||||
|
@ -363,7 +353,7 @@ TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
|
|||
gzread(gzfp, tmpInfo.data, dataSize);
|
||||
|
||||
/* add to memory cache */
|
||||
add(checksum, &tmpInfo, (tmpInfo.format & GR_TEXFMT_GZ) ? dataSize : 0);
|
||||
add(checksum, &tmpInfo, (tmpInfo.format & GL_TEXFMT_GZ) ? dataSize : 0);
|
||||
|
||||
free(tmpInfo.data);
|
||||
} else {
|
||||
|
|
|
@ -163,6 +163,8 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
{
|
||||
uint8 *texture = src;
|
||||
uint8 *tmptex = _tex1;
|
||||
if (srcformat == GL_RGBA)
|
||||
srcformat = GL_RGBA8;
|
||||
uint16 destformat = srcformat;
|
||||
|
||||
/* We need to be initialized first! */
|
||||
|
@ -194,26 +196,26 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
*/
|
||||
if ((srcwidth >= 4 && srcheight >= 4) &&
|
||||
((_options & (FILTER_MASK|ENHANCEMENT_MASK|COMPRESSION_MASK)) ||
|
||||
(srcformat == GR_TEXFMT_ARGB_8888 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)))) {
|
||||
(srcformat == GL_RGBA8 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)))) {
|
||||
|
||||
#if !_16BPP_HACK
|
||||
/* convert textures to a format that the compressor accepts (ARGB8888) */
|
||||
if (_options & COMPRESSION_MASK) {
|
||||
#endif
|
||||
if (srcformat != GR_TEXFMT_ARGB_8888) {
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, srcformat, GR_TEXFMT_ARGB_8888)) {
|
||||
if (srcformat != GL_RGBA8) {
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, srcformat, GL_RGBA8)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat);
|
||||
return 0;
|
||||
}
|
||||
texture = tmptex;
|
||||
destformat = GR_TEXFMT_ARGB_8888;
|
||||
destformat = GL_RGBA8;
|
||||
}
|
||||
#if !_16BPP_HACK
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
case GL_RGBA8:
|
||||
|
||||
/*
|
||||
* prepare texture enhancements (x2, x4 scalers)
|
||||
|
@ -322,9 +324,9 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
int compressionType = _options & COMPRESSION_MASK;
|
||||
int tmpwidth, tmpheight;
|
||||
uint16 tmpformat;
|
||||
if ((destformat == GR_TEXFMT_ALPHA_INTENSITY_88) ||
|
||||
(destformat == GR_TEXFMT_ARGB_8888) ||
|
||||
(destformat == GR_TEXFMT_ALPHA_8)) {
|
||||
if ((destformat == GL_LUMINANCE8_ALPHA8) ||
|
||||
(destformat == GL_RGBA8) ||
|
||||
(destformat == GL_ALPHA8)) {
|
||||
compressionType = S3TC_COMPRESSION;
|
||||
}
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
|
@ -343,11 +345,11 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
/*
|
||||
* texture (re)conversions
|
||||
*/
|
||||
if (destformat == GR_TEXFMT_ARGB_8888) {
|
||||
if (srcformat == GR_TEXFMT_ARGB_8888 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)) srcformat = GR_TEXFMT_ARGB_4444;
|
||||
if (srcformat != GR_TEXFMT_ARGB_8888) {
|
||||
if (destformat == GL_RGBA8) {
|
||||
if (srcformat == GL_RGBA8 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)) srcformat = GL_RGBA4;
|
||||
if (srcformat != GL_RGBA8) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, GR_TEXFMT_ARGB_8888, srcformat)) {
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, GL_RGBA8, srcformat)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat);
|
||||
return 0;
|
||||
}
|
||||
|
@ -358,7 +360,7 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
|
||||
break;
|
||||
#if !_16BPP_HACK
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
case GL_RGBA4:
|
||||
|
||||
int scale_shift = 0;
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
|
@ -426,11 +428,11 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
}
|
||||
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GL_RGB5_A1:
|
||||
break;
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GL_RGB:
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
case GL_ALPHA8:
|
||||
break;
|
||||
#endif /* _16BPP_HACK */
|
||||
}
|
||||
|
@ -440,11 +442,8 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
info->data = texture;
|
||||
info->width = srcwidth;
|
||||
info->height = srcheight;
|
||||
info->format = destformat;
|
||||
info->smallLodLog2 = _txUtil->grLodLog2(srcwidth, srcheight);
|
||||
info->largeLodLog2 = info->smallLodLog2;
|
||||
info->aspectRatioLog2 = _txUtil->grAspectRatioLog2(srcwidth, srcheight);
|
||||
info->is_hires_tex = 0;
|
||||
setTextureFormat(destformat, info);
|
||||
|
||||
/* cache the texture. */
|
||||
if (_cacheSize) _txTexCache->add(g64crc, info);
|
||||
|
@ -513,8 +512,9 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
|
|||
* NOTE: the pre-converted palette from Glide64 is in RGBA5551 format.
|
||||
* A comp comes before RGB comp.
|
||||
*/
|
||||
if (palette && info->format == GR_TEXFMT_P_8) {
|
||||
DBG_INFO(80, L"found GR_TEXFMT_P_8 format. Need conversion!!\n");
|
||||
// TODO: deal with palette textures
|
||||
if (palette && info->format == GL_COLOR_INDEX8_EXT) {
|
||||
DBG_INFO(80, L"found GL_COLOR_INDEX8_EXT format. Need conversion!!\n");
|
||||
|
||||
int width = info->width;
|
||||
int height = info->height;
|
||||
|
@ -526,30 +526,30 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
|
|||
/* use palette and convert to 16bit format */
|
||||
_txQuantize->P8_16BPP((uint32*)texture, (uint32*)tmptex, info->width, info->height, (uint32*)palette);
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_1555;
|
||||
format = GL_RGB5_A1;
|
||||
|
||||
#if 1
|
||||
/* XXX: compressed if memory cache compression is ON */
|
||||
if (_options & COMPRESSION_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->quantize(texture, tmptex, info->width, info->height, format, GR_TEXFMT_ARGB_8888)) {
|
||||
if (_txQuantize->quantize(texture, tmptex, info->width, info->height, format, GL_RGBA8)) {
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_8888;
|
||||
format = GL_RGBA8;
|
||||
}
|
||||
if (format == GR_TEXFMT_ARGB_8888) {
|
||||
if (format == GL_RGBA8) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->compress(texture, tmptex,
|
||||
info->width, info->height, GR_TEXFMT_ARGB_1555,
|
||||
info->width, info->height, GL_RGB5_A1,
|
||||
&width, &height, &format,
|
||||
_options & COMPRESSION_MASK)) {
|
||||
texture = tmptex;
|
||||
} else {
|
||||
/*if (!_txQuantize->quantize(texture, tmptex, info->width, info->height, GR_TEXFMT_ARGB_8888, GR_TEXFMT_ARGB_1555)) {
|
||||
/*if (!_txQuantize->quantize(texture, tmptex, info->width, info->height, GL_RGBA8, GL_RGB5_A1)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", format);
|
||||
return 0;
|
||||
}*/
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_1555;
|
||||
format = GL_RGB5_A1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -559,16 +559,13 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
|
|||
info->data = texture;
|
||||
info->width = width;
|
||||
info->height = height;
|
||||
info->format = format;
|
||||
info->smallLodLog2 = _txUtil->grLodLog2(width, height);
|
||||
info->largeLodLog2 = info->smallLodLog2;
|
||||
info->aspectRatioLog2 = _txUtil->grAspectRatioLog2(width, height);
|
||||
info->is_hires_tex = 1;
|
||||
setTextureFormat(format, info);
|
||||
|
||||
/* XXX: add to hires texture cache!!! */
|
||||
_txHiResCache->add(r_crc64, info);
|
||||
|
||||
DBG_INFO(80, L"GR_TEXFMT_P_8 loaded as gfmt:%x!\n", format);
|
||||
DBG_INFO(80, L"GL_COLOR_INDEX8_EXT loaded as gfmt:%x!\n", format);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -611,7 +608,7 @@ TxFilter::dmptx(uint8 *src, int width, int height, int rowStridePixel, uint16 gf
|
|||
DBG_INFO(80, L"hirestex: r_crc64:%08X %08X\n",
|
||||
(uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff));
|
||||
|
||||
if (!_txQuantize->quantize(src, _tex1, rowStridePixel, height, (gfmt & 0x00ff), GR_TEXFMT_ARGB_8888))
|
||||
if (!_txQuantize->quantize(src, _tex1, rowStridePixel, height, (gfmt & 0x00ff), GL_RGBA8))
|
||||
return 0;
|
||||
|
||||
src = _tex1;
|
||||
|
|
|
@ -55,7 +55,7 @@ txfilter_shutdown(void)
|
|||
}
|
||||
|
||||
TAPI boolean TAPIENTRY
|
||||
txfilter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat,
|
||||
txfilter_filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat,
|
||||
uint64 g64crc, GHQTexInfo *info)
|
||||
{
|
||||
if (txFilter)
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
/* use power of 2 texture size
|
||||
* (0:disable, 1:enable, 2:3dfx) */
|
||||
#define POW2_TEXTURES 2
|
||||
#define POW2_TEXTURES 0
|
||||
|
||||
/* hack to reduce texture footprint to achieve
|
||||
* better performace on midrange gfx cards.
|
||||
|
@ -220,7 +220,6 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
int tmpwidth = 0, tmpheight = 0;
|
||||
uint16 tmpformat = 0;
|
||||
uint8 *tmptex= NULL;
|
||||
int untiled_width = 0, untiled_height = 0;
|
||||
uint16 destformat = 0;
|
||||
|
||||
/* Rice hi-res textures: begin
|
||||
|
@ -378,7 +377,7 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
if (tmptex) {
|
||||
/* check if _rgb.* and _a.* have matching size and format. */
|
||||
if (!tex || width != tmpwidth || height != tmpheight ||
|
||||
format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) {
|
||||
format != GL_RGBA8 || tmpformat != GL_RGBA8) {
|
||||
#if !DEBUG
|
||||
INFO(80, L"-----\n");
|
||||
INFO(80, L"path: %ls\n", dir_path.string().c_str());
|
||||
|
@ -388,7 +387,7 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
INFO(80, L"Error: missing _rgb.*!\n");
|
||||
} else if (width != tmpwidth || height != tmpheight) {
|
||||
INFO(80, L"Error: _rgb.* and _a.* have mismatched width or height!\n");
|
||||
} else if (format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) {
|
||||
} else if (format != GL_RGBA8 || tmpformat != GL_RGBA8) {
|
||||
INFO(80, L"Error: _rgb.* or _a.* not in 32bit color!\n");
|
||||
}
|
||||
if (tex) free(tex);
|
||||
|
@ -408,7 +407,7 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
#if 1
|
||||
/* use R comp for alpha. this is what Rice uses. sigh... */
|
||||
((uint32*)tex)[i] &= 0x00ffffff;
|
||||
((uint32*)tex)[i] |= ((((uint32*)tmptex)[i] & 0x00ff0000) << 8);
|
||||
((uint32*)tex)[i] |= ((((uint32*)tmptex)[i] & 0xff) << 24);
|
||||
#endif
|
||||
#if 0
|
||||
/* use libpng style grayscale conversion */
|
||||
|
@ -514,11 +513,11 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
DBG_INFO(80, L"read in as %d x %d gfmt:%x\n", tmpwidth, tmpheight, tmpformat);
|
||||
|
||||
/* check if size and format are OK */
|
||||
if (!(format == GR_TEXFMT_ARGB_8888 ||
|
||||
format == GR_TEXFMT_P_8 ||
|
||||
format == GR_TEXFMT_ARGB_CMP_DXT1 ||
|
||||
format == GR_TEXFMT_ARGB_CMP_DXT3 ||
|
||||
format == GR_TEXFMT_ARGB_CMP_DXT5) ||
|
||||
if (!(format == GL_RGBA8 ||
|
||||
format == GL_COLOR_INDEX8_EXT ||
|
||||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
|
||||
format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
|
||||
format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) ||
|
||||
(width * height) < 4) { /* TxQuantize requirement: width * height must be 4 or larger. */
|
||||
free(tex);
|
||||
tex = NULL;
|
||||
|
@ -532,7 +531,7 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
}
|
||||
|
||||
/* analyze and determine best format to quantize */
|
||||
if (format == GR_TEXFMT_ARGB_8888) {
|
||||
if (format == GL_RGBA8) {
|
||||
int i;
|
||||
int alphabits = 0;
|
||||
int fullalpha = 0;
|
||||
|
@ -580,16 +579,16 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
if (j < width - 1) tmptexel[7] = ((uint32*)tex)[i * width + j + 1]; /* east */
|
||||
for (k = 0; k < 8; k++) {
|
||||
if ((tmptexel[k] & 0xff000000) == 0xff000000) {
|
||||
r += ((tmptexel[k] & 0x00ff0000) >> 16);
|
||||
b += ((tmptexel[k] & 0x00ff0000) >> 16);
|
||||
g += ((tmptexel[k] & 0x0000ff00) >> 8);
|
||||
b += ((tmptexel[k] & 0x000000ff) );
|
||||
r += ((tmptexel[k] & 0x000000ff) );
|
||||
numtexel++;
|
||||
}
|
||||
}
|
||||
if (numtexel) {
|
||||
((uint32*)tex)[i * width + j] = ((r / numtexel) << 16) |
|
||||
((uint32*)tex)[i * width + j] = ((b / numtexel) << 16) |
|
||||
((g / numtexel) << 8) |
|
||||
((b / numtexel) );
|
||||
((r / numtexel) );
|
||||
} else {
|
||||
((uint32*)tex)[i * width + j] = texel & 0x00ffffff;
|
||||
}
|
||||
|
@ -637,16 +636,16 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||
if (_maxbpp < 32 || _options & (FORCE16BPP_HIRESTEX|COMPRESSION_MASK)) {
|
||||
#endif
|
||||
if (alphabits == 0) destformat = GR_TEXFMT_RGB_565;
|
||||
else if (alphabits == 1) destformat = GR_TEXFMT_ARGB_1555;
|
||||
else destformat = GR_TEXFMT_ARGB_8888;
|
||||
if (alphabits == 0) destformat = GL_RGB;
|
||||
else if (alphabits == 1) destformat = GL_RGB5_A1;
|
||||
else destformat = GL_RGBA8;
|
||||
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||
} else {
|
||||
destformat = GR_TEXFMT_ARGB_8888;
|
||||
destformat = GL_RGBA8;
|
||||
}
|
||||
#endif
|
||||
if (fmt == 4 && alphabits == 0) {
|
||||
destformat = GR_TEXFMT_ARGB_8888;
|
||||
destformat = GL_RGBA8;
|
||||
/* Rice I format; I = (R + G + B) / 3 */
|
||||
for (i = 0; i < height * width; i++) {
|
||||
uint32 texel = ((uint32*)tex)[i];
|
||||
|
@ -658,10 +657,10 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
}
|
||||
if (intensity) {
|
||||
if (alphabits == 0) {
|
||||
if (fmt == 4) destformat = GR_TEXFMT_ALPHA_8;
|
||||
else destformat = GR_TEXFMT_INTENSITY_8;
|
||||
if (fmt == 4) destformat = GL_ALPHA8;
|
||||
else destformat = GL_LUMINANCE8;
|
||||
} else {
|
||||
destformat = GR_TEXFMT_ALPHA_INTENSITY_88;
|
||||
destformat = GL_LUMINANCE8_ALPHA8;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -671,8 +670,8 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
* Rice hi-res textures: end */
|
||||
|
||||
|
||||
/* XXX: only ARGB8888 for now. comeback to this later... */
|
||||
if (format == GR_TEXFMT_ARGB_8888) {
|
||||
/* XXX: only RGBA8888 for now. comeback to this later... */
|
||||
if (format == GL_RGBA8) {
|
||||
|
||||
/* minification */
|
||||
if (width > _maxwidth || height > _maxheight) {
|
||||
|
@ -703,7 +702,6 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
* NOTE: texture size must be checked before expanding to pow2 size.
|
||||
*/
|
||||
) {
|
||||
uint32 alpha = 0;
|
||||
int dataSize = 0;
|
||||
int compressionType = _options & COMPRESSION_MASK;
|
||||
|
||||
|
@ -725,21 +723,21 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
switch (_options & COMPRESSION_MASK) {
|
||||
case S3TC_COMPRESSION:
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
case GL_RGBA8:
|
||||
#if GLIDE64_DXTN
|
||||
case GR_TEXFMT_ARGB_1555: /* for ARGB1555 use DXT5 instead of DXT1 */
|
||||
case GL_RGB5_A1: /* for GL_RGB5_A1 use DXT5 instead of DXT1 */
|
||||
#endif
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_88:
|
||||
case GL_LUMINANCE8_ALPHA8:
|
||||
dataSize = width * height;
|
||||
break;
|
||||
#if !GLIDE64_DXTN
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GL_RGB5_A1:
|
||||
#endif
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GR_TEXFMT_INTENSITY_8:
|
||||
case GL_RGB:
|
||||
case GL_LUMINANCE8:
|
||||
dataSize = (width * height) >> 1;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8: /* no size benefit with dxtn */
|
||||
case GL_ALPHA8: /* no size benefit with dxtn */
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
@ -749,8 +747,8 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
#if 0 /* TEST: dither before compression for better results with gradients */
|
||||
tmptex = (uint8 *)malloc(_txUtil->sizeofTx(width, height, destformat));
|
||||
if (tmptex) {
|
||||
if (_txQuantize->quantize(tex, tmptex, width, height, GR_TEXFMT_ARGB_8888, destformat, 0))
|
||||
_txQuantize->quantize(tmptex, tex, width, height, destformat, GR_TEXFMT_ARGB_8888, 0);
|
||||
if (_txQuantize->quantize(tex, tmptex, width, height, GL_RGBA8, destformat, 0))
|
||||
_txQuantize->quantize(tmptex, tex, width, height, destformat, GL_RGBA8, 0);
|
||||
free(tmptex);
|
||||
}
|
||||
#endif
|
||||
|
@ -794,40 +792,35 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
tmptex = (uint8 *)malloc(_txUtil->sizeofTx(width, height, destformat));
|
||||
if (tmptex) {
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
case GL_RGBA8:
|
||||
case GL_RGBA4:
|
||||
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||
if (_maxbpp < 32 || _options & FORCE16BPP_HIRESTEX)
|
||||
#endif
|
||||
destformat = GR_TEXFMT_ARGB_4444;
|
||||
destformat = GL_RGBA4;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GL_RGB5_A1:
|
||||
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||
if (_maxbpp < 32 || _options & FORCE16BPP_HIRESTEX)
|
||||
#endif
|
||||
destformat = GR_TEXFMT_ARGB_1555;
|
||||
destformat = GL_RGB5_A1;
|
||||
break;
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GL_RGB:
|
||||
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||
if (_maxbpp < 32 || _options & FORCE16BPP_HIRESTEX)
|
||||
#endif
|
||||
destformat = GR_TEXFMT_RGB_565;
|
||||
destformat = GL_RGB;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_88:
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_44:
|
||||
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||
destformat = GR_TEXFMT_ALPHA_INTENSITY_88;
|
||||
#else
|
||||
destformat = GR_TEXFMT_ALPHA_INTENSITY_44;
|
||||
#endif
|
||||
case GL_LUMINANCE8_ALPHA8:
|
||||
destformat = GL_LUMINANCE8_ALPHA8;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
destformat = GR_TEXFMT_ALPHA_8; /* yes, this is correct. ALPHA_8 instead of INTENSITY_8 */
|
||||
case GL_ALPHA8:
|
||||
destformat = GL_ALPHA8; /* yes, this is correct. ALPHA_8 instead of INTENSITY_8 */
|
||||
break;
|
||||
case GR_TEXFMT_INTENSITY_8:
|
||||
destformat = GR_TEXFMT_INTENSITY_8;
|
||||
case GL_LUMINANCE8:
|
||||
destformat = GL_LUMINANCE8;
|
||||
}
|
||||
if (_txQuantize->quantize(tex, tmptex, width, height, GR_TEXFMT_ARGB_8888, destformat, 0)) {
|
||||
if (_txQuantize->quantize(tex, tmptex, width, height, GL_RGBA8, destformat, 0)) {
|
||||
format = destformat;
|
||||
free(tex);
|
||||
tex = tmptex;
|
||||
|
@ -862,16 +855,11 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
chksum64 |= (uint64)chksum;
|
||||
|
||||
GHQTexInfo tmpInfo;
|
||||
memset(&tmpInfo, 0, sizeof(GHQTexInfo));
|
||||
|
||||
tmpInfo.data = tex;
|
||||
tmpInfo.width = width;
|
||||
tmpInfo.height = height;
|
||||
tmpInfo.format = format;
|
||||
tmpInfo.largeLodLog2 = _txUtil->grLodLog2(width, height);
|
||||
tmpInfo.smallLodLog2 = tmpInfo.largeLodLog2;
|
||||
tmpInfo.aspectRatioLog2 = _txUtil->grAspectRatioLog2(width, height);
|
||||
tmpInfo.is_hires_tex = 1;
|
||||
setTextureFormat(format, &tmpInfo);
|
||||
|
||||
/* remove redundant in cache */
|
||||
if (replace && TxCache::del(chksum64)) {
|
||||
|
|
|
@ -167,7 +167,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
png_set_shift(png_ptr, sig_bit);*/
|
||||
|
||||
/* convert rgba to bgra */
|
||||
png_set_bgr(png_ptr);
|
||||
//png_set_bgr(png_ptr); // OpenGL does not need it
|
||||
|
||||
/* turn on interlace handling to cope with the weirdness
|
||||
* of texture authors using interlaced format */
|
||||
|
@ -176,7 +176,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
/* update info structure */
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
/* we only get here if ARGB8888 */
|
||||
/* we only get here if RGBA8888 */
|
||||
row_bytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
/* allocate memory to read in image */
|
||||
|
@ -202,7 +202,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
*width = (row_bytes >> 2);
|
||||
*height = o_height;
|
||||
*format = GR_TEXFMT_ARGB_8888;
|
||||
*format = GL_RGBA8;
|
||||
|
||||
#if POW2_TEXTURES
|
||||
/* next power of 2 size conversions */
|
||||
|
@ -489,8 +489,8 @@ uint8*
|
|||
TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
|
||||
{
|
||||
/* NOTE: returned image format;
|
||||
* 4, 8bit palette bmp -> GR_TEXFMT_P_8
|
||||
* 24, 32bit bmp -> GR_TEXFMT_ARGB_8888
|
||||
* 4, 8bit palette bmp -> GL_COLOR_INDEX8_EXT
|
||||
* 24, 32bit bmp -> GL_RGBA8
|
||||
*/
|
||||
|
||||
uint8 *image = NULL;
|
||||
|
@ -610,11 +610,11 @@ TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
|
|||
switch (bmp_ihdr.biBitCount) {
|
||||
case 8:
|
||||
case 4:
|
||||
*format = GR_TEXFMT_P_8;
|
||||
*format = GL_COLOR_INDEX8_EXT;
|
||||
break;
|
||||
case 32:
|
||||
case 24:
|
||||
*format = GR_TEXFMT_ARGB_8888;
|
||||
*format = GL_RGBA8;
|
||||
}
|
||||
|
||||
#if POW2_TEXTURES
|
||||
|
@ -770,15 +770,15 @@ TxImage::readDDS(FILE* fp, int* width, int* height, uint16* format)
|
|||
DBG_INFO(80, L"DXT1 format\n");
|
||||
/* compensate for missing LinearSize */
|
||||
dds_fhdr.dwLinearSize = (dds_fhdr.dwWidth * dds_fhdr.dwHeight) >> 1;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT1;
|
||||
tmpformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
} else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT3", 4) == 0) {
|
||||
DBG_INFO(80, L"DXT3 format\n");
|
||||
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT3;
|
||||
tmpformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
} else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT5", 4) == 0) {
|
||||
DBG_INFO(80, L"DXT5 format\n");
|
||||
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT5;
|
||||
tmpformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
} else {
|
||||
DBG_INFO(80, L"Error: not DXT1 or DXT3 or DXT5 format!\n");
|
||||
return NULL;
|
||||
|
|
|
@ -32,51 +32,25 @@
|
|||
#define KBHIT(key) (0)
|
||||
#endif
|
||||
|
||||
/* from OpenGL glext.h */
|
||||
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
#ifdef OS_WINDOWS
|
||||
#include <GL/gl.h>
|
||||
#include "glext.h"
|
||||
#else
|
||||
#ifdef GLES2
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#else
|
||||
#if defined(OS_MAC_OS_X)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glext.h>
|
||||
#elif defined(OS_LINUX)
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#endif // OS_MAC_OS_X
|
||||
#endif // GLES2
|
||||
#endif // OS_WINDOWS
|
||||
|
||||
/* in-memory zlib texture compression */
|
||||
#define GR_TEXFMT_GZ 0x8000
|
||||
|
||||
#if 0 /* this is here to remind me of other formats */
|
||||
/* from 3Dfx Interactive Inc. glide.h */
|
||||
#define GR_TEXFMT_8BIT 0x0
|
||||
#define GR_TEXFMT_RGB_332 GR_TEXFMT_8BIT
|
||||
#define GR_TEXFMT_YIQ_422 0x1
|
||||
#define GR_TEXFMT_ALPHA_8 0x2 /* (0..0xFF) alpha */
|
||||
#define GR_TEXFMT_INTENSITY_8 0x3 /* (0..0xFF) intensity */
|
||||
#define GR_TEXFMT_ALPHA_INTENSITY_44 0x4
|
||||
#define GR_TEXFMT_P_8 0x5 /* 8-bit palette */
|
||||
#define GR_TEXFMT_RSVD0 0x6 /* GR_TEXFMT_P_8_RGBA */
|
||||
#define GR_TEXFMT_P_8_6666 GR_TEXFMT_RSVD0
|
||||
#define GR_TEXFMT_P_8_6666_EXT GR_TEXFMT_RSVD0
|
||||
#define GR_TEXFMT_RSVD1 0x7
|
||||
#define GR_TEXFMT_16BIT 0x8
|
||||
#define GR_TEXFMT_ARGB_8332 GR_TEXFMT_16BIT
|
||||
#define GR_TEXFMT_AYIQ_8422 0x9
|
||||
#define GR_TEXFMT_RGB_565 0xa
|
||||
#define GR_TEXFMT_ARGB_1555 0xb
|
||||
#define GR_TEXFMT_ARGB_4444 0xc
|
||||
#define GR_TEXFMT_ALPHA_INTENSITY_88 0xd
|
||||
#define GR_TEXFMT_AP_88 0xe /* 8-bit alpha 8-bit palette */
|
||||
#define GR_TEXFMT_RSVD2 0xf
|
||||
#define GR_TEXFMT_RSVD4 GR_TEXFMT_RSVD2
|
||||
|
||||
/* from 3Dfx Interactive Inc. g3ext.h */
|
||||
#define GR_TEXFMT_ARGB_CMP_FXT1 0x11
|
||||
#define GR_TEXFMT_ARGB_8888 0x12
|
||||
#define GR_TEXFMT_YUYV_422 0x13
|
||||
#define GR_TEXFMT_UYVY_422 0x14
|
||||
#define GR_TEXFMT_AYUV_444 0x15
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT1 0x16
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT2 0x17
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT3 0x18
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT4 0x19
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT5 0x1A
|
||||
#define GR_TEXTFMT_RGB_888 0xFF
|
||||
#endif
|
||||
#define GL_TEXFMT_GZ 0x80000000
|
||||
|
||||
#endif /* __INTERNAL_H__ */
|
||||
|
|
|
@ -814,29 +814,25 @@ TxQuantize::quantize(uint8* src, uint8* dest, int width, int height, uint16 srcf
|
|||
quantizerFunc quantizer;
|
||||
int bpp_shift = 0;
|
||||
|
||||
if (destformat == GR_TEXFMT_ARGB_8888) {
|
||||
if (destformat == GL_RGBA8 || destformat == GL_RGBA) {
|
||||
switch (srcformat) {
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GL_RGB5_A1:
|
||||
quantizer = &TxQuantize::ARGB1555_ARGB8888;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
case GL_RGBA4:
|
||||
quantizer = &TxQuantize::ARGB4444_ARGB8888;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GL_RGB:
|
||||
quantizer = &TxQuantize::RGB565_ARGB8888;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
case GL_ALPHA8:
|
||||
quantizer = &TxQuantize::A8_ARGB8888;
|
||||
bpp_shift = 2;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_44:
|
||||
quantizer = &TxQuantize::AI44_ARGB8888;
|
||||
bpp_shift = 2;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_88:
|
||||
case GL_LUMINANCE8_ALPHA8:
|
||||
quantizer = &TxQuantize::AI88_ARGB8888;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
|
@ -880,30 +876,26 @@ TxQuantize::quantize(uint8* src, uint8* dest, int width, int height, uint16 srcf
|
|||
(*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
|
||||
}
|
||||
|
||||
} else if (srcformat == GR_TEXFMT_ARGB_8888) {
|
||||
} else if (srcformat == GL_RGBA8 || srcformat == GL_RGBA) {
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GL_RGB5_A1:
|
||||
quantizer = fastQuantizer ? &TxQuantize::ARGB8888_ARGB1555 : &TxQuantize::ARGB8888_ARGB1555_ErrD;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
case GL_RGBA4:
|
||||
quantizer = fastQuantizer ? &TxQuantize::ARGB8888_ARGB4444 : &TxQuantize::ARGB8888_ARGB4444_ErrD;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GL_RGB:
|
||||
quantizer = fastQuantizer ? &TxQuantize::ARGB8888_RGB565 : &TxQuantize::ARGB8888_RGB565_ErrD;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
case GR_TEXFMT_INTENSITY_8:
|
||||
case GL_ALPHA8:
|
||||
case GL_LUMINANCE8:
|
||||
quantizer = fastQuantizer ? &TxQuantize::ARGB8888_A8 : &TxQuantize::ARGB8888_I8_Slow;
|
||||
bpp_shift = 2;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_44:
|
||||
quantizer = fastQuantizer ? &TxQuantize::ARGB8888_AI44 : &TxQuantize::ARGB8888_AI44_ErrD;
|
||||
bpp_shift = 2;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_88:
|
||||
case GL_LUMINANCE8_ALPHA8:
|
||||
quantizer = fastQuantizer ? &TxQuantize::ARGB8888_AI88 : &TxQuantize::ARGB8888_AI88_Slow;
|
||||
bpp_shift = 1;
|
||||
break;
|
||||
|
@ -976,31 +968,30 @@ TxQuantize::DXTn(uint8 *src, uint8 *dest,
|
|||
*/
|
||||
|
||||
/* skip formats that DXTn won't help in size. */
|
||||
if (srcformat == GR_TEXFMT_ALPHA_8 ||
|
||||
srcformat == GR_TEXFMT_ALPHA_INTENSITY_44) {
|
||||
if (srcformat == GL_ALPHA8) {
|
||||
; /* shutup compiler */
|
||||
} else {
|
||||
int dstRowStride = ((srcwidth + 3) & ~3) << 2;
|
||||
int compression = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
|
||||
*destformat = GR_TEXFMT_ARGB_CMP_DXT5;
|
||||
*destformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
|
||||
#if !GLIDE64_DXTN
|
||||
/* okay... we are going to disable DXT1 with 1bit alpha
|
||||
* for Glide64. some textures have all 0 alpha values.
|
||||
* see "N64 Kobe Bryant in NBA Courtside"
|
||||
*/
|
||||
if (srcformat == GR_TEXFMT_ARGB_1555) {
|
||||
if (srcformat == GL_RGB5_A1) {
|
||||
dstRowStride >>= 1;
|
||||
compression = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
*destformat = GR_TEXFMT_ARGB_CMP_DXT1;
|
||||
*destformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
} else
|
||||
#endif
|
||||
if (srcformat == GR_TEXFMT_RGB_565 ||
|
||||
srcformat == GR_TEXFMT_INTENSITY_8) {
|
||||
if (srcformat == GL_RGB ||
|
||||
srcformat == GL_LUMINANCE8) {
|
||||
dstRowStride >>= 1;
|
||||
compression = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
*destformat = GR_TEXFMT_ARGB_CMP_DXT1;
|
||||
*destformat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
}
|
||||
|
||||
unsigned int numcore = _numcore;
|
||||
|
|
|
@ -75,26 +75,25 @@ TxUtil::sizeofTx(int width, int height, uint16 format)
|
|||
|
||||
/* a lookup table for the shifts would be better */
|
||||
switch (format) {
|
||||
case GR_TEXFMT_ARGB_CMP_DXT1:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
||||
dataSize = (((width + 0x3) & ~0x3) * ((height + 0x3) & ~0x3)) >> 1;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_CMP_DXT3:
|
||||
case GR_TEXFMT_ARGB_CMP_DXT5:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
||||
dataSize = ((width + 0x3) & ~0x3) * ((height + 0x3) & ~0x3);
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_44:
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
case GR_TEXFMT_INTENSITY_8:
|
||||
case GR_TEXFMT_P_8:
|
||||
case GL_ALPHA8:
|
||||
case GL_LUMINANCE8:
|
||||
case GL_COLOR_INDEX8_EXT:
|
||||
dataSize = width * height;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_88:
|
||||
case GL_RGBA4:
|
||||
case GL_RGB5_A1:
|
||||
case GL_RGB:
|
||||
case GL_LUMINANCE8_ALPHA8:
|
||||
dataSize = (width * height) << 1;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
case GL_RGBA8:
|
||||
dataSize = (width * height) << 2;
|
||||
break;
|
||||
default:
|
||||
|
@ -936,3 +935,42 @@ TxMemBuf::size_of(unsigned int num)
|
|||
{
|
||||
return ((num < 2) ? _size[num] : 0);
|
||||
}
|
||||
|
||||
void setTextureFormat(uint16 internalFormat, GHQTexInfo * info)
|
||||
{
|
||||
info->format = internalFormat;
|
||||
switch (internalFormat) {
|
||||
case GL_RGBA8:
|
||||
info->texture_format = GL_RGBA;
|
||||
info->pixel_type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case GL_RGB:
|
||||
info->texture_format = GL_RGB;
|
||||
info->pixel_type = GL_UNSIGNED_SHORT_5_6_5;
|
||||
break;
|
||||
case GL_RGBA4:
|
||||
info->texture_format = GL_RGBA;
|
||||
info->pixel_type = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
break;
|
||||
case GL_RGB5_A1:
|
||||
info->texture_format = GL_RGBA;
|
||||
info->pixel_type = GL_UNSIGNED_SHORT_5_5_5_1;
|
||||
break;
|
||||
case GL_ALPHA8:
|
||||
info->texture_format = GL_ALPHA;
|
||||
info->pixel_type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case GL_LUMINANCE8:
|
||||
info->texture_format = GL_LUMINANCE;
|
||||
info->pixel_type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case GL_LUMINANCE8_ALPHA8:
|
||||
info->texture_format = GL_LUMINANCE_ALPHA;
|
||||
info->pixel_type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
default:
|
||||
info->texture_format = GL_RGBA;
|
||||
info->pixel_type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,4 +109,6 @@ public:
|
|||
uint32 size_of(unsigned int num);
|
||||
};
|
||||
|
||||
void setTextureFormat(uint16 internalFormat, GHQTexInfo * info);
|
||||
|
||||
#endif /* __TXUTIL_H__ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user