mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
Polymost: Clean up and rearrange some texcache code. No functional changes.
git-svn-id: https://svn.eduke32.com/eduke32@5710 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
d1266434f1
commit
84a2695cdc
6 changed files with 111 additions and 113 deletions
|
@ -1,2 +1,11 @@
|
|||
|
||||
#ifndef DXTFILTER_H_
|
||||
#define DXTFILTER_H_
|
||||
|
||||
void dxt_handle_io(int32_t fil, int32_t len, void *midbuf, char *packbuf);
|
||||
int32_t dedxt_handle_io(int32_t fil, int32_t, void *midbuf, int32_t mbufsiz, char *packbuf, int32_t ispacked);
|
||||
|
||||
int32_t dxtfilter(int32_t fil, const texcachepicture *pict, const char *pic, void *midbuf, char *packbuf, uint32_t miplen);
|
||||
int32_t dedxtfilter(int32_t fil, const texcachepicture *pict, char *pic, void *midbuf, char *packbuf, int32_t ispacked);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,6 +52,7 @@ extern globaltexcache texcache;
|
|||
|
||||
extern char TEXCACHEFILE[BMAX_PATH];
|
||||
|
||||
extern int32_t texcache_enabled(void);
|
||||
extern void texcache_freeptrs(void);
|
||||
extern void texcache_syncmemcache(void);
|
||||
extern void texcache_init(void);
|
||||
|
@ -61,7 +62,9 @@ extern pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashad
|
|||
extern int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, vec2_t *siz);
|
||||
extern int32_t texcache_loadtile(const texcacheheader *head, int32_t *doalloc, pthtyp *pth);
|
||||
extern char const * texcache_calcid(char *cachefn, const char *fn, const int32_t len, const int32_t dameth, const char effect);
|
||||
extern void texcache_writetex(char const * cachefn, texcacheheader *head);
|
||||
extern void texcache_prewritetex(texcacheheader *head);
|
||||
extern void texcache_postwritetex(char const * const cachefn, int32_t const offset);
|
||||
extern void texcache_writetex_fromdriver(char const * cachefn, texcacheheader *head);
|
||||
extern int32_t texcache_readtexheader(char const * cachefn, texcacheheader *head, int32_t modelp);
|
||||
extern void texcache_openfiles(void);
|
||||
extern void texcache_setupmemcache(void);
|
||||
|
|
|
@ -43,6 +43,7 @@ Description of Ken's filter to improve LZW compression of DXT1 format by ~15%: (
|
|||
#include "texcache.h"
|
||||
#include "lz4.h"
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
static uint16_t dxt_hicosub(uint16_t c)
|
||||
{
|
||||
int32_t r, g, b;
|
||||
|
@ -60,8 +61,9 @@ static uint16_t dedxt_hicoadd(uint16_t c)
|
|||
b = ((c>> 0)+(g>>1))&31;
|
||||
return((r<<11)+(g<<5)+b);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void dxt_handle_io(int32_t fil, int32_t len, void *midbuf, char *packbuf)
|
||||
void dxt_handle_io(int32_t fil, int32_t len, void *midbuf, char *packbuf)
|
||||
{
|
||||
void *writebuf;
|
||||
int32_t j, cleng;
|
||||
|
@ -89,7 +91,7 @@ static void dxt_handle_io(int32_t fil, int32_t len, void *midbuf, char *packbuf)
|
|||
Bwrite(fil, writebuf, cleng);
|
||||
}
|
||||
|
||||
static int32_t dedxt_handle_io(int32_t fil, int32_t j /* TODO: better name */,
|
||||
int32_t dedxt_handle_io(int32_t fil, int32_t j /* TODO: better name */,
|
||||
void *midbuf, int32_t mbufsiz, char *packbuf, int32_t ispacked)
|
||||
{
|
||||
void *inbuf;
|
||||
|
@ -133,19 +135,18 @@ static int32_t dedxt_handle_io(int32_t fil, int32_t j /* TODO: better name */,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
// NOTE: <pict> members are in external (little) endianness.
|
||||
int32_t dxtfilter(int32_t fil, const texcachepicture *pict, const char *pic, void *midbuf, char *packbuf, uint32_t miplen)
|
||||
{
|
||||
uint32_t j, k, offs, stride;
|
||||
char *cptr;
|
||||
|
||||
#if !defined EDUKE32_GLES
|
||||
if ((pict->format == (signed) B_LITTLE32(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)) ||
|
||||
(pict->format == (signed) B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT))) { offs = 0; stride = 8; }
|
||||
else if ((pict->format == (signed) B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)) ||
|
||||
(pict->format == (signed) B_LITTLE32(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT))) { offs = 8; stride = 16; }
|
||||
else
|
||||
#endif
|
||||
{ offs = 0; stride = 8; }
|
||||
|
||||
if (stride == 16) //If DXT3...
|
||||
|
@ -181,10 +182,6 @@ int32_t dxtfilter(int32_t fil, const texcachepicture *pict, const char *pic, voi
|
|||
|
||||
dxt_handle_io(fil, tabledivide32(miplen, stride)<<2, midbuf, packbuf);
|
||||
|
||||
#if defined EDUKE32_GLES
|
||||
UNREFERENCED_PARAMETER(pict);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -194,13 +191,11 @@ int32_t dedxtfilter(int32_t fil, const texcachepicture *pict, char *pic, void *m
|
|||
int32_t j, k, offs, stride;
|
||||
char *cptr;
|
||||
|
||||
#if !defined EDUKE32_GLES
|
||||
if ((pict->format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) ||
|
||||
(pict->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)) { offs = 0; stride = 8; }
|
||||
else if ((pict->format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) ||
|
||||
(pict->format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) { offs = 8; stride = 16; }
|
||||
else
|
||||
#endif
|
||||
{ offs = 0; stride = 8; }
|
||||
|
||||
if (stride == 16) //If DXT3...
|
||||
|
@ -246,3 +241,5 @@ int32_t dedxtfilter(int32_t fil, const texcachepicture *pict, char *pic, void *m
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -963,6 +963,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
|
|||
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
|
||||
#if defined USE_GLEXT && !defined EDUKE32_GLES
|
||||
if (!gotcache && glinfo.texcompr && glusetexcache && !(sk->flags & HICR_NOTEXCOMPRESS) &&
|
||||
(glusetexcompr == 2 || (glusetexcompr && !(sk->flags & HICR_ARTIMMUNITY))))
|
||||
{
|
||||
|
@ -977,7 +978,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
|
|||
(sk->flags & (HICR_NODOWNSIZE|HICR_ARTIMMUNITY) ? CACHEAD_NODOWNSIZE : 0);
|
||||
|
||||
/// OSD_Printf("Caching \"%s\"\n",fn);
|
||||
texcache_writetex(texcacheid, &cachead);
|
||||
texcache_writetex_fromdriver(texcacheid, &cachead);
|
||||
|
||||
if (willprint)
|
||||
{
|
||||
|
@ -989,6 +990,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
|
|||
else
|
||||
OSD_Printf("Cached skin \"%s\"\n", fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (willprint)
|
||||
{
|
||||
|
|
|
@ -1518,6 +1518,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
|
|||
pth->skyface = facen;
|
||||
pth->hicr = hicr;
|
||||
|
||||
#if defined USE_GLEXT && !defined EDUKE32_GLES
|
||||
if (!gotcache && glinfo.texcompr && glusetexcache && !(hicr->flags & HICR_NOTEXCOMPRESS) &&
|
||||
(glusetexcompr == 2 || (glusetexcompr && !(hicr->flags & HICR_ARTIMMUNITY))))
|
||||
{
|
||||
|
@ -1533,7 +1534,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
|
|||
(hicr->flags & (HICR_NODOWNSIZE|HICR_ARTIMMUNITY) ? CACHEAD_NODOWNSIZE : 0);
|
||||
|
||||
/// OSD_Printf("Caching \"%s\"\n", fn);
|
||||
texcache_writetex(texcacheid, &cachead);
|
||||
texcache_writetex_fromdriver(texcacheid, &cachead);
|
||||
|
||||
if (willprint)
|
||||
{
|
||||
|
@ -1546,6 +1547,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
|
|||
else
|
||||
OSD_Printf("Cached \"%s\"\n", fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (willprint)
|
||||
{
|
||||
|
|
|
@ -282,7 +282,7 @@ static void texcache_deletefiles(void)
|
|||
unlink(ptempbuf);
|
||||
}
|
||||
|
||||
static int32_t texcache_enabled(void)
|
||||
int32_t texcache_enabled(void)
|
||||
{
|
||||
#if defined EDUKE32_GLES || !defined USE_GLEXT
|
||||
return 0;
|
||||
|
@ -525,42 +525,11 @@ failure:
|
|||
}
|
||||
|
||||
#undef READTEXHEADER_FAILURE
|
||||
#define WRITEX_FAIL_ON_ERROR() if (bglGetError() != GL_NO_ERROR) goto failure
|
||||
|
||||
void texcache_writetex(char const * const cachefn, texcacheheader *head)
|
||||
#if defined USE_GLEXT && !defined EDUKE32_GLES
|
||||
|
||||
void texcache_prewritetex(texcacheheader *head)
|
||||
{
|
||||
char *pic = NULL, *packbuf = NULL;
|
||||
void *midbuf = NULL;
|
||||
uint32_t alloclen=0;
|
||||
#ifndef EDUKE32_GLES
|
||||
static GLint glGetTexLevelParameterivOK = GL_TRUE;
|
||||
uint32_t level=0;
|
||||
uint32_t padx=0, pady=0;
|
||||
GLint gi;
|
||||
#endif
|
||||
int32_t offset = 0;
|
||||
|
||||
if (!texcache_enabled()) return;
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
gi = GL_FALSE;
|
||||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi);
|
||||
if (gi != GL_TRUE)
|
||||
{
|
||||
if (glGetTexLevelParameterivOK == GL_TRUE)
|
||||
{
|
||||
OSD_Printf("Error: glGetTexLevelParameteriv returned GL_FALSE!\n");
|
||||
glGetTexLevelParameterivOK = GL_FALSE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Blseek(texcache.filehandle, 0, BSEEK_END);
|
||||
|
||||
offset = Blseek(texcache.filehandle, 0, BSEEK_CUR);
|
||||
// OSD_Printf("Caching %s, offset 0x%x\n", cachefn, offset);
|
||||
|
||||
Bmemcpy(head->magic, TEXCACHEMAGIC, 4); // sizes are set by caller
|
||||
|
||||
if (glusetexcache == 2)
|
||||
|
@ -571,19 +540,43 @@ void texcache_writetex(char const * const cachefn, texcacheheader *head)
|
|||
head->ydim = B_LITTLE32(head->ydim);
|
||||
head->flags = B_LITTLE32(head->flags);
|
||||
head->quality = B_LITTLE32(head->quality);
|
||||
}
|
||||
|
||||
#define WRITEX_FAIL_ON_ERROR() if (bglGetError() != GL_NO_ERROR) goto failure
|
||||
|
||||
void texcache_writetex_fromdriver(char const * const cachefn, texcacheheader *head)
|
||||
{
|
||||
texcachepicture pict;
|
||||
char *pic = NULL, *packbuf = NULL;
|
||||
void *midbuf = NULL;
|
||||
uint32_t alloclen=0;
|
||||
|
||||
if (!texcache_enabled()) return;
|
||||
|
||||
GLint gi = GL_FALSE;
|
||||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi);
|
||||
if (gi != GL_TRUE)
|
||||
{
|
||||
static GLint glGetTexLevelParameterivOK = GL_TRUE;
|
||||
if (glGetTexLevelParameterivOK == GL_TRUE)
|
||||
{
|
||||
OSD_Printf("Error: glGetTexLevelParameteriv returned GL_FALSE!\n");
|
||||
glGetTexLevelParameterivOK = GL_FALSE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
texcache_prewritetex(head);
|
||||
|
||||
Blseek(texcache.filehandle, 0, BSEEK_END);
|
||||
int32_t offset = Blseek(texcache.filehandle, 0, BSEEK_CUR);
|
||||
// OSD_Printf("Caching %s, offset 0x%x\n", cachefn, offset);
|
||||
if (Bwrite(texcache.filehandle, head, sizeof(texcacheheader)) != sizeof(texcacheheader)) goto failure;
|
||||
|
||||
CLEAR_GL_ERRORS();
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
for (level = 0; level==0 || (padx > 1 || pady > 1); level++)
|
||||
#endif
|
||||
for (uint32_t level = 0, padx = 0, pady = 0; level == 0 || (padx > 1 || pady > 1); ++level)
|
||||
{
|
||||
uint32_t miplen;
|
||||
texcachepicture pict;
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_ARB, &gi); WRITEX_FAIL_ON_ERROR();
|
||||
if (gi != GL_TRUE) goto failure; // an uncompressed mipmap
|
||||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &gi); WRITEX_FAIL_ON_ERROR();
|
||||
|
@ -602,15 +595,8 @@ void texcache_writetex(char const * const cachefn, texcacheheader *head)
|
|||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_DEPTH, &gi); WRITEX_FAIL_ON_ERROR();
|
||||
pict.depth = B_LITTLE32(gi);
|
||||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &gi); WRITEX_FAIL_ON_ERROR();
|
||||
miplen = gi; pict.size = B_LITTLE32(gi);
|
||||
#else // TODO: actually code this ;)
|
||||
// pict.format = GL_ETC1_RGB8_OES;
|
||||
pict.xdim = head->xdim;
|
||||
pict.ydim = head->ydim;
|
||||
pict.border = 0;
|
||||
pict.depth = 16;
|
||||
miplen = 0;
|
||||
#endif
|
||||
uint32_t miplen = gi; pict.size = B_LITTLE32(gi);
|
||||
|
||||
if (alloclen < miplen)
|
||||
{
|
||||
pic = (char *)Xrealloc(pic, miplen);
|
||||
|
@ -619,14 +605,28 @@ void texcache_writetex(char const * const cachefn, texcacheheader *head)
|
|||
midbuf = (void *)Xrealloc(midbuf, miplen);
|
||||
}
|
||||
|
||||
#ifdef USE_GLEXT
|
||||
bglGetCompressedTexImageARB(GL_TEXTURE_2D, level, pic); WRITEX_FAIL_ON_ERROR();
|
||||
#endif
|
||||
|
||||
if (Bwrite(texcache.filehandle, &pict, sizeof(texcachepicture)) != sizeof(texcachepicture)) goto failure;
|
||||
if (dxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf, miplen)) goto failure;
|
||||
}
|
||||
|
||||
texcache_postwritetex(cachefn, offset);
|
||||
|
||||
goto success;
|
||||
|
||||
failure:
|
||||
initprintf("ERROR: cache failure!\n");
|
||||
texcache.currentindex->offset = 0;
|
||||
Bmemset(texcache.currentindex->name,0,sizeof(texcache.currentindex->name));
|
||||
|
||||
success:
|
||||
TEXCACHE_FREEBUFS();
|
||||
}
|
||||
|
||||
#undef WRITEX_FAIL_ON_ERROR
|
||||
|
||||
void texcache_postwritetex(char const * const cachefn, int32_t const offset)
|
||||
{
|
||||
texcacheindex *t;
|
||||
int32_t i = hash_find(&texcache.hashes, cachefn);
|
||||
|
@ -665,18 +665,7 @@ void texcache_writetex(char const * const cachefn, texcacheheader *head)
|
|||
OSD_Printf("wtf?\n");
|
||||
}
|
||||
|
||||
goto success;
|
||||
|
||||
failure:
|
||||
initprintf("ERROR: cache failure!\n");
|
||||
texcache.currentindex->offset = 0;
|
||||
Bmemset(texcache.currentindex->name,0,sizeof(texcache.currentindex->name));
|
||||
|
||||
success:
|
||||
TEXCACHE_FREEBUFS();
|
||||
}
|
||||
|
||||
#undef WRITEX_FAIL_ON_ERROR
|
||||
#endif
|
||||
|
||||
static void texcache_setuptexture(int32_t *doalloc, GLuint *glpic)
|
||||
{
|
||||
|
@ -695,10 +684,12 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr)
|
|||
void *midbuf = NULL;
|
||||
int32_t alloclen=0;
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
int32_t level = 0;
|
||||
for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++)
|
||||
#if !defined USE_GLEXT && defined EDUKE32_GLES
|
||||
UNREFERENCED_PARAMETER(glerr);
|
||||
UNREFERENCED_PARAMETER(head);
|
||||
#endif
|
||||
|
||||
for (int32_t level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++)
|
||||
{
|
||||
if (texcache_readdata(&pict, sizeof(texcachepicture)))
|
||||
{
|
||||
|
@ -722,6 +713,7 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr)
|
|||
midbuf = (void *)Xrealloc(midbuf, pict.size);
|
||||
}
|
||||
|
||||
#if defined USE_GLEXT && !defined EDUKE32_GLES
|
||||
if (dedxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf,
|
||||
(head->flags & CACHEAD_COMPRESSED)!=0))
|
||||
{
|
||||
|
@ -729,16 +721,13 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr)
|
|||
return TEXCACHERR_DEDXT;
|
||||
}
|
||||
|
||||
#ifdef USE_GLEXT
|
||||
bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border,pict.size,pic);
|
||||
if ((*glerr=bglGetError()) != GL_NO_ERROR)
|
||||
{
|
||||
TEXCACHE_FREEBUFS();
|
||||
return TEXCACHERR_COMPTEX;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef EDUKE32_GLES
|
||||
GLint format;
|
||||
bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &format);
|
||||
if ((*glerr = bglGetError()) != GL_NO_ERROR)
|
||||
|
@ -756,10 +745,6 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr)
|
|||
#endif
|
||||
}
|
||||
|
||||
#if !defined USE_GLEXT && defined EDUKE32_GLES
|
||||
UNREFERENCED_PARAMETER(glerr);
|
||||
#endif
|
||||
|
||||
TEXCACHE_FREEBUFS();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue