mirror of
https://github.com/aap/librw.git
synced 2026-01-25 12:32:57 +00:00
anisotropy plugin
This commit is contained in:
@@ -471,6 +471,19 @@ readAsImage(Stream *stream, int32 width, int32 height, int32 depth, int32 format
|
||||
Raster *ras = nil;
|
||||
|
||||
for(int i = 0; i < numLevels; i++){
|
||||
uint32 size = stream->readU32();
|
||||
|
||||
// don't read levels that don't exist
|
||||
if(ras && i >= ras->getNumLevels()){
|
||||
stream->seek(size);
|
||||
continue;
|
||||
}
|
||||
|
||||
// one allocation is enough, first level is largest
|
||||
if(data == nil)
|
||||
data = rwNewT(uint8, size, MEMDUR_FUNCTION | ID_IMAGE);
|
||||
stream->read8(data, size);
|
||||
|
||||
if(ras){
|
||||
ras->lock(i, Raster::LOCKWRITE|Raster::LOCKNOFETCH);
|
||||
img->width = ras->width;
|
||||
@@ -478,13 +491,6 @@ readAsImage(Stream *stream, int32 width, int32 height, int32 depth, int32 format
|
||||
img->stride = img->width*img->bpp;
|
||||
}
|
||||
|
||||
uint32 size = stream->readU32();
|
||||
// one allocation is enough, first level is largest
|
||||
if(data == nil)
|
||||
data = rwNewT(uint8, size, MEMDUR_FUNCTION | ID_IMAGE);
|
||||
stream->read8(data, size);
|
||||
|
||||
|
||||
if(format & (Raster::PAL4 | Raster::PAL8)){
|
||||
uint8 *idx = data;
|
||||
uint8 *pixels = img->pixels;
|
||||
|
||||
@@ -63,6 +63,7 @@ struct RwRasterStateCache {
|
||||
Texture::Addressing addressingU;
|
||||
Texture::Addressing addressingV;
|
||||
Texture::FilterMode filter;
|
||||
int32 maxAniso;
|
||||
};
|
||||
|
||||
#define MAXNUMSTAGES 8
|
||||
@@ -342,7 +343,10 @@ restoreD3d9Device(void)
|
||||
setSamplerState(i, D3DSAMP_ADDRESSU, addressConvMap[rwStateCache.texstage[i].addressingU]);
|
||||
setSamplerState(i, D3DSAMP_ADDRESSV, addressConvMap[rwStateCache.texstage[i].addressingV]);
|
||||
setSamplerState(i, D3DSAMP_MAGFILTER, filterConvMap[rwStateCache.texstage[i].filter]);
|
||||
setSamplerState(i, D3DSAMP_MINFILTER, filterConvMap[rwStateCache.texstage[i].filter]);
|
||||
if(rwStateCache.texstage[i].maxAniso == 1)
|
||||
setSamplerState(i, D3DSAMP_MINFILTER, filterConvMap[rwStateCache.texstage[i].filter]);
|
||||
else
|
||||
setSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
|
||||
setSamplerState(i, D3DSAMP_MIPFILTER, filterConvMap_MIP[rwStateCache.texstage[i].filter]);
|
||||
}
|
||||
for(s = 0; s < MAXNUMSTATES; s++)
|
||||
@@ -474,14 +478,25 @@ setRasterStage(uint32 stage, Raster *raster)
|
||||
}
|
||||
|
||||
static void
|
||||
setFilterMode(uint32 stage, int32 filter)
|
||||
setFilterMode(uint32 stage, int32 filter, int32 maxAniso = 1)
|
||||
{
|
||||
if(rwStateCache.texstage[stage].filter != (Texture::FilterMode)filter){
|
||||
rwStateCache.texstage[stage].filter = (Texture::FilterMode)filter;
|
||||
setSamplerState(stage, D3DSAMP_MAGFILTER, filterConvMap[filter]);
|
||||
setSamplerState(stage, D3DSAMP_MINFILTER, filterConvMap[filter]);
|
||||
if(maxAniso == 1)
|
||||
setSamplerState(stage, D3DSAMP_MINFILTER, filterConvMap[filter]);
|
||||
else
|
||||
setSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
|
||||
setSamplerState(stage, D3DSAMP_MIPFILTER, filterConvMap_MIP[filter]);
|
||||
}
|
||||
if(rwStateCache.texstage[stage].maxAniso != maxAniso){
|
||||
rwStateCache.texstage[stage].maxAniso = maxAniso;
|
||||
if(maxAniso == 1)
|
||||
setSamplerState(stage, D3DSAMP_MINFILTER, filterConvMap[filter]);
|
||||
else
|
||||
setSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
|
||||
setSamplerState(stage, D3DSAMP_MAXANISOTROPY, maxAniso);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -510,7 +525,7 @@ setTexture(uint32 stage, Texture *tex)
|
||||
return;
|
||||
}
|
||||
if(tex->raster){
|
||||
setFilterMode(stage, tex->getFilter());
|
||||
setFilterMode(stage, tex->getFilter(), tex->getMaxAnisotropy());
|
||||
setAddressU(stage, tex->getAddressU());
|
||||
setAddressV(stage, tex->getAddressV());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user