mipmap hints in Texture. not used anywhere yet

This commit is contained in:
aap 2020-07-26 10:53:37 +02:00
parent fa6277be34
commit b63c3ea3b4
2 changed files with 38 additions and 3 deletions

View File

@ -378,6 +378,10 @@ struct Texture
static Texture *(*readCB)(const char *name, const char *mask); static Texture *(*readCB)(const char *name, const char *mask);
static void setLoadTextures(bool32); // default: true static void setLoadTextures(bool32); // default: true
static void setCreateDummies(bool32); // default: false static void setCreateDummies(bool32); // default: false
static void setMipmapping(bool32); // default: false
static void setAutoMipmapping(bool32); // default: false
static bool32 getMipmapping(void);
static bool32 getAutoMipmapping(void);
#ifndef RWPUBLIC #ifndef RWPUBLIC
static void registerModule(void); static void registerModule(void);

View File

@ -35,6 +35,8 @@ struct TextureGlobals
bool32 loadTextures; bool32 loadTextures;
// create dummy textures to store just names // create dummy textures to store just names
bool32 makeDummies; bool32 makeDummies;
bool32 mipmapping;
bool32 autoMipmapping;
LinkList texDicts; LinkList texDicts;
LinkList textures; LinkList textures;
@ -55,6 +57,8 @@ textureOpen(void *object, int32 offset, int32 size)
TexDictionary::setCurrent(texdict); TexDictionary::setCurrent(texdict);
TEXTUREGLOBAL(loadTextures) = 1; TEXTUREGLOBAL(loadTextures) = 1;
TEXTUREGLOBAL(makeDummies) = 0; TEXTUREGLOBAL(makeDummies) = 0;
TEXTUREGLOBAL(mipmapping) = 0;
TEXTUREGLOBAL(autoMipmapping) = 0;
return object; return object;
} }
static void* static void*
@ -92,6 +96,11 @@ Texture::setCreateDummies(bool32 b)
TEXTUREGLOBAL(makeDummies) = b; TEXTUREGLOBAL(makeDummies) = b;
} }
void Texture::setMipmapping(bool32 b) { TEXTUREGLOBAL(mipmapping) = b; }
void Texture::setAutoMipmapping(bool32 b) { TEXTUREGLOBAL(autoMipmapping) = b; }
bool32 Texture::getMipmapping(void) { return TEXTUREGLOBAL(mipmapping); }
bool32 Texture::getAutoMipmapping(void) { return TEXTUREGLOBAL(autoMipmapping); }
// //
// TexDictionary // TexDictionary
// //
@ -361,7 +370,10 @@ Texture::streamRead(Stream *stream)
return nil; return nil;
} }
uint32 filterAddressing = stream->readU32(); uint32 filterAddressing = stream->readU32();
// TODO: if V addressing is 0, copy U // if V addressing is 0, copy U
if((filterAddressing & 0xF000) == 0)
filterAddressing |= (filterAddressing&0xF00) << 4;
// if using mipmap filter mode, set automipmapping, // if using mipmap filter mode, set automipmapping,
// if 0x10000 is set, set mipmapping // if 0x10000 is set, set mipmapping
@ -377,13 +389,29 @@ Texture::streamRead(Stream *stream)
} }
stream->read8(mask, length); stream->read8(mask, length);
bool32 mipState = getMipmapping();
bool32 autoMipState = getAutoMipmapping();
int32 filter = filterAddressing&0xFF;
if(filter == MIPNEAREST || filter == MIPLINEAR ||
filter == LINEARMIPNEAREST || filter == LINEARMIPLINEAR){
setMipmapping(1);
setAutoMipmapping((filterAddressing&0x10000) == 0);
}else{
setMipmapping(0);
setAutoMipmapping(0);
}
Texture *tex = Texture::read(name, mask); Texture *tex = Texture::read(name, mask);
setMipmapping(mipState);
setAutoMipmapping(autoMipState);
if(tex == nil){ if(tex == nil){
s_plglist.streamSkip(stream); s_plglist.streamSkip(stream);
return nil; return nil;
} }
if(tex->refCount == 1) if(tex->refCount == 1)
tex->filterAddressing = filterAddressing; tex->filterAddressing = filterAddressing&0xFFFF;
if(s_plglist.streamRead(stream, tex)) if(s_plglist.streamRead(stream, tex))
return tex; return tex;
@ -399,7 +427,10 @@ Texture::streamWrite(Stream *stream)
char buf[36]; char buf[36];
writeChunkHeader(stream, ID_TEXTURE, this->streamGetSize()); writeChunkHeader(stream, ID_TEXTURE, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, 4); writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeU32(this->filterAddressing); uint32 filterAddressing = this->filterAddressing;
if(this->raster && (raster->format & Raster::AUTOMIPMAP) == 0)
filterAddressing |= 0x10000;
stream->writeU32(filterAddressing);
memset(buf, 0, 36); memset(buf, 0, 36);
strncpy(buf, this->name, 32); strncpy(buf, this->name, 32);