[Glide64] Clean up OGLtextures.cpp

This commit is contained in:
zilmar 2016-02-04 17:08:24 +11:00
parent eab47fdd82
commit 009dfa94f3
1 changed files with 721 additions and 722 deletions

View File

@ -21,7 +21,7 @@
#define GR_TEXFMT_ARGB_CMP_DXT5 0x1A
#define GR_TEXTFMT_RGB_888 0xFF
int TMU_SIZE = 8*2048*2048;
int TMU_SIZE = 8 * 2048 * 2048;
static unsigned char* texture = NULL;
int packed_pixels_support = -1;
@ -65,7 +65,7 @@ void remove_tex(unsigned int idmin, unsigned int idmax)
while (aux && aux->id >= idmin && aux->id < idmax)
{
if (n >= sz)
t = (unsigned int *) realloc(t, ++sz*sizeof(int));
t = (unsigned int *)realloc(t, ++sz*sizeof(int));
t[n++] = aux->id;
aux = aux->next;
free(list);
@ -78,7 +78,7 @@ void remove_tex(unsigned int idmin, unsigned int idmax)
{
texlist *aux2 = aux->next->next;
if (n >= sz)
t = (unsigned int *) realloc(t, ++sz*sizeof(int));
t = (unsigned int *)realloc(t, ++sz*sizeof(int));
t[n++] = aux->next->id;
free(aux->next);
aux->next = aux2;
@ -91,7 +91,6 @@ void remove_tex(unsigned int idmin, unsigned int idmax)
//printf("RMVTEX nbtex is now %d (%06x - %06x)\n", nbTex, idmin, idmax);
}
void add_tex(unsigned int id)
{
texlist *aux = list;
@ -123,7 +122,7 @@ void init_textures()
// list = NULL;
// nbTex = 0;
if (!texture) texture = (unsigned char*)malloc(2048*2048*4);
if (!texture) texture = (unsigned char*)malloc(2048 * 2048 * 4);
}
void free_textures()
@ -139,7 +138,7 @@ void free_textures()
}
FX_ENTRY FxU32 FX_CALL
grTexMinAddress( GrChipID_t tmu )
grTexMinAddress(GrChipID_t tmu)
{
LOG("grTexMinAddress(%d)\r\n", tmu);
if (UMAmode)
@ -149,18 +148,18 @@ grTexMinAddress( GrChipID_t tmu )
}
FX_ENTRY FxU32 FX_CALL
grTexMaxAddress( GrChipID_t tmu )
grTexMaxAddress(GrChipID_t tmu)
{
LOG("grTexMaxAddress(%d)\r\n", tmu);
if (UMAmode)
return TMU_SIZE*2 - 1;
return TMU_SIZE * 2 - 1;
else
return tmu*TMU_SIZE + TMU_SIZE - 1;
}
FX_ENTRY FxU32 FX_CALL
grTexTextureMemRequired( FxU32 evenOdd,
GrTexInfo *info )
grTexTextureMemRequired(FxU32 evenOdd,
GrTexInfo *info)
{
int width, height;
LOG("grTextureMemRequired(%d)\r\n", evenOdd);
@ -177,7 +176,7 @@ grTexTextureMemRequired( FxU32 evenOdd,
height = width >> info->aspectRatioLog2;
}
switch(info->format)
switch (info->format)
{
case GR_TEXFMT_ALPHA_8:
case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
@ -188,19 +187,19 @@ grTexTextureMemRequired( FxU32 evenOdd,
case GR_TEXFMT_ARGB_4444:
case GR_TEXFMT_ALPHA_INTENSITY_88:
case GR_TEXFMT_RGB_565:
return (width*height)<<1;
return (width*height) << 1;
break;
case GR_TEXFMT_ARGB_8888:
return (width*height)<<2;
return (width*height) << 2;
break;
case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
return ((((width+0x3)&~0x3)*((height+0x3)&~0x3))>>1);
return ((((width + 0x3)&~0x3)*((height + 0x3)&~0x3)) >> 1);
case GR_TEXFMT_ARGB_CMP_DXT3:
return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3);
case GR_TEXFMT_ARGB_CMP_DXT5:
return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3);
case GR_TEXFMT_ARGB_CMP_FXT1:
return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1);
return ((((width + 0x7)&~0x7)*((height + 0x3)&~0x3)) >> 1);
default:
display_warning("grTexTextureMemRequired : unknown texture format: %x", info->format);
}
@ -209,8 +208,8 @@ grTexTextureMemRequired( FxU32 evenOdd,
FX_ENTRY FxU32 FX_CALL
grTexCalcMemRequired(
GrLOD_t lodmin, GrLOD_t lodmax,
GrAspectRatio_t aspect, GrTextureFormat_t fmt)
GrLOD_t lodmin, GrLOD_t lodmax,
GrAspectRatio_t aspect, GrTextureFormat_t fmt)
{
int width, height;
LOG("grTexCalcMemRequired(%d, %d, %d, %d)\r\n", lodmin, lodmax, aspect, fmt);
@ -227,7 +226,7 @@ grTexCalcMemRequired(
height = width >> aspect;
}
switch(fmt)
switch (fmt)
{
case GR_TEXFMT_ALPHA_8:
case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
@ -238,19 +237,19 @@ grTexCalcMemRequired(
case GR_TEXFMT_ARGB_4444:
case GR_TEXFMT_ALPHA_INTENSITY_88:
case GR_TEXFMT_RGB_565:
return (width*height)<<1;
return (width*height) << 1;
break;
case GR_TEXFMT_ARGB_8888:
return (width*height)<<2;
return (width*height) << 2;
break;
case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
return ((((width+0x3)&~0x3)*((height+0x3)&~0x3))>>1);
return ((((width + 0x3)&~0x3)*((height + 0x3)&~0x3)) >> 1);
case GR_TEXFMT_ARGB_CMP_DXT3:
return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3);
case GR_TEXFMT_ARGB_CMP_DXT5:
return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3);
case GR_TEXFMT_ARGB_CMP_FXT1:
return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1);
return ((((width + 0x7)&~0x7)*((height + 0x3)&~0x3)) >> 1);
default:
display_warning("grTexTextureMemRequired : unknown texture format: %x", fmt);
}
@ -260,7 +259,7 @@ grTexCalcMemRequired(
int grTexFormatSize(int fmt)
{
int factor = -1;
switch(fmt) {
switch (fmt) {
case GR_TEXFMT_ALPHA_8:
case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
factor = 1;
@ -304,7 +303,7 @@ int grTexFormatSize(int fmt)
int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpackfmt)
{
int factor = -1;
switch(fmt) {
switch (fmt) {
case GR_TEXFMT_ALPHA_8:
factor = 1;
*gltexfmt = GL_INTENSITY8;
@ -383,10 +382,10 @@ int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpac
}
FX_ENTRY void FX_CALL
grTexDownloadMipMap( GrChipID_t tmu,
FxU32 startAddress,
FxU32 evenOdd,
GrTexInfo *info )
grTexDownloadMipMap(GrChipID_t tmu,
FxU32 startAddress,
FxU32 evenOdd,
GrTexInfo *info)
{
int width, height, i, j;
int factor;
@ -412,16 +411,15 @@ grTexDownloadMipMap( GrChipID_t tmu,
factor = grTexFormat2GLPackedFmt(info->format, &gltexfmt, &glpixfmt, &glpackfmt);
if (factor < 0) {
// VP fixed the texture conversions to be more accurate, also swapped
// the for i/j loops so that is is less likely to break the memory cache
register int n = 0, m = 0;
switch(info->format)
switch (info->format)
{
case GR_TEXFMT_ALPHA_8:
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = (unsigned int)((unsigned char*)info->data)[m];
texel |= (texel << 8);
@ -435,9 +433,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
glformat = GL_INTENSITY8;
break;
case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = (unsigned int)((unsigned char*)info->data)[m];
texel |= (0xFF000000 | (texel << 16) | (texel << 8));
@ -451,9 +449,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
break;
case GR_TEXFMT_ALPHA_INTENSITY_44:
#if 1
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = (unsigned int)((unsigned char*)info->data)[m];
#if 1
@ -477,9 +475,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
#endif
break;
case GR_TEXFMT_RGB_565:
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = (unsigned int)((unsigned short*)info->data)[m];
unsigned int B = texel & 0x0000F800;
@ -499,9 +497,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
glformat = GL_RGB;
break;
case GR_TEXFMT_ARGB_1555:
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = (unsigned int)((unsigned short*)info->data)[m];
unsigned int A = texel & 0x00008000 ? 0xFF000000 : 0;
@ -522,9 +520,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
glformat = GL_RGB5_A1;
break;
case GR_TEXFMT_ALPHA_INTENSITY_88:
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int AI = (unsigned int)((unsigned short*)info->data)[m];
unsigned int I = (unsigned int)(AI & 0x000000FF);
@ -538,9 +536,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
break;
case GR_TEXFMT_ARGB_4444:
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = (unsigned int)((unsigned short*)info->data)[m];
unsigned int A = texel & 0x0000F000;
@ -561,9 +559,9 @@ grTexDownloadMipMap( GrChipID_t tmu,
glformat = GL_RGBA4;
break;
case GR_TEXFMT_ARGB_8888:
for (i=0; i<height; i++)
for (i = 0; i < height; i++)
{
for (j=0; j<width; j++)
for (j = 0; j < width; j++)
{
unsigned int texel = ((unsigned int*)info->data)[m];
unsigned int A = texel & 0xFF000000;
@ -605,36 +603,37 @@ grTexDownloadMipMap( GrChipID_t tmu,
else
glActiveTextureARB(GL_TEXTURE2_ARB);
switch(info->format)
switch (info->format)
{
case GR_TEXFMT_ARGB_CMP_DXT1:
case GR_TEXFMT_ARGB_CMP_DXT3:
case GR_TEXFMT_ARGB_CMP_DXT5:
case GR_TEXFMT_ARGB_CMP_FXT1:
remove_tex(startAddress+1, startAddress+1+((width*height*factor)>>4));
remove_tex(startAddress + 1, startAddress + 1 + ((width*height*factor) >> 4));
break;
default:
remove_tex(startAddress+1, startAddress+1+(width*height*factor));
remove_tex(startAddress + 1, startAddress + 1 + (width*height*factor));
}
add_tex(startAddress+1);
glBindTexture(GL_TEXTURE_2D, startAddress+1);
add_tex(startAddress + 1);
glBindTexture(GL_TEXTURE_2D, startAddress + 1);
if (largest_supported_anisotropy > 1.0f)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy);
switch(info->format)
switch (info->format)
{
case GR_TEXFMT_ARGB_CMP_DXT1:
case GR_TEXFMT_ARGB_CMP_DXT3:
case GR_TEXFMT_ARGB_CMP_DXT5:
case GR_TEXFMT_ARGB_CMP_FXT1:
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, (glformat ? glformat : gltexfmt), width, height, 0, (width*height*factor)>>4, info->data);
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, (glformat ? glformat : gltexfmt), width, height, 0, (width*height*factor) >> 4, info->data);
break;
default:
if (glformat) {
glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
} else
}
else
glTexImage2D(GL_TEXTURE_2D, 0, gltexfmt, width, height, 0, glpixfmt, glpackfmt, info->data);
}
@ -642,13 +641,13 @@ grTexDownloadMipMap( GrChipID_t tmu,
grDisplayGLError("grTexDownloadMipMap");
}
int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info );
int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info);
FX_ENTRY void FX_CALL
grTexSource( GrChipID_t tmu,
FxU32 startAddress,
FxU32 evenOdd,
GrTexInfo *info )
grTexSource(GrChipID_t tmu,
FxU32 startAddress,
FxU32 evenOdd,
GrTexInfo *info)
{
LOG("grTexSource(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
@ -668,7 +667,7 @@ grTexSource( GrChipID_t tmu,
tex0_height = tex0_width >> info->aspectRatioLog2;
}
glBindTexture(GL_TEXTURE_2D, startAddress+1);
glBindTexture(GL_TEXTURE_2D, startAddress + 1);
#ifdef VPDEBUG
dump_tex(startAddress+1);
#endif
@ -692,7 +691,7 @@ grTexSource( GrChipID_t tmu,
tex1_height = tex1_width >> info->aspectRatioLog2;
}
glBindTexture(GL_TEXTURE_2D, startAddress+1);
glBindTexture(GL_TEXTURE_2D, startAddress + 1);
#ifdef VPDEBUG
dump_tex(startAddress+1);
#endif
@ -701,14 +700,14 @@ grTexSource( GrChipID_t tmu,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1);
}
if(!CheckTextureBufferFormat(tmu, startAddress+1, info))
if (!CheckTextureBufferFormat(tmu, startAddress + 1, info))
{
if(tmu == 0 && blackandwhite1 != 0)
if (tmu == 0 && blackandwhite1 != 0)
{
blackandwhite1 = 0;
need_to_compile = 1;
}
if(tmu == 1 && blackandwhite0 != 0)
if (tmu == 1 && blackandwhite0 != 0)
{
blackandwhite0 = 0;
need_to_compile = 1;
@ -728,11 +727,11 @@ grTexSource( GrChipID_t tmu,
FX_ENTRY void FX_CALL
grTexDetailControl(
GrChipID_t tmu,
int lod_bias,
FxU8 detail_scale,
float detail_max
)
GrChipID_t tmu,
int lod_bias,
FxU8 detail_scale,
float detail_max
)
{
LOG("grTexDetailControl(%d,%d,%d,%d)\r\n", tmu, lod_bias, detail_scale, detail_max);
if (lod_bias != 31 && detail_scale != 7)
@ -742,27 +741,27 @@ grTexDetailControl(
display_warning("grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max);
}
lambda = detail_max;
if(lambda > 1.0f)
if (lambda > 1.0f)
{
lambda = 1.0f - (255.0f - lambda);
}
if(lambda > 1.0f) display_warning("lambda:%f", lambda);
if (lambda > 1.0f) display_warning("lambda:%f", lambda);
set_lambda();
}
FX_ENTRY void FX_CALL
grTexLodBiasValue(GrChipID_t tmu, float bias )
grTexLodBiasValue(GrChipID_t tmu, float bias)
{
LOG("grTexLodBiasValue(%d,%f)\r\n", tmu, bias);
}
FX_ENTRY void FX_CALL
grTexFilterMode(
GrChipID_t tmu,
GrTextureFilterMode_t minfilter_mode,
GrTextureFilterMode_t magfilter_mode
)
GrChipID_t tmu,
GrTextureFilterMode_t minfilter_mode,
GrTextureFilterMode_t magfilter_mode
)
{
LOG("grTexFilterMode(%d,%d,%d)\r\n", tmu, minfilter_mode, magfilter_mode);
if (tmu == GR_TMU1 || nbTextureUnits <= 2)
@ -795,16 +794,16 @@ grTexFilterMode(
FX_ENTRY void FX_CALL
grTexClampMode(
GrChipID_t tmu,
GrTextureClampMode_t s_clampmode,
GrTextureClampMode_t t_clampmode
)
GrChipID_t tmu,
GrTextureClampMode_t s_clampmode,
GrTextureClampMode_t t_clampmode
)
{
LOG("grTexClampMode(%d, %d, %d)\r\n", tmu, s_clampmode, t_clampmode);
if (tmu == GR_TMU1 || nbTextureUnits <= 2)
{
if (tmu == GR_TMU1 && nbTextureUnits <= 2) return;
switch(s_clampmode)
switch (s_clampmode)
{
case GR_TEXTURECLAMP_WRAP:
wrap_s0 = GL_REPEAT;
@ -818,7 +817,7 @@ grTexClampMode(
default:
display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode);
}
switch(t_clampmode)
switch (t_clampmode)
{
case GR_TEXTURECLAMP_WRAP:
wrap_t0 = GL_REPEAT;
@ -838,7 +837,7 @@ grTexClampMode(
}
else
{
switch(s_clampmode)
switch (s_clampmode)
{
case GR_TEXTURECLAMP_WRAP:
wrap_s1 = GL_REPEAT;
@ -852,7 +851,7 @@ grTexClampMode(
default:
display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode);
}
switch(t_clampmode)
switch (t_clampmode)
{
case GR_TEXTURECLAMP_WRAP:
wrap_t1 = GL_REPEAT;