raster fixes

This commit is contained in:
aap 2017-09-16 23:19:54 +02:00
parent 239a4eb4bc
commit 017e86053a
5 changed files with 50 additions and 24 deletions

View File

@ -383,7 +383,7 @@ rasterCreate(Raster *raster)
natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER); natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
}else }else
format = formatMap[(raster->format >> 8) & 0xF]; format = formatMap[(raster->format >> 8) & 0xF];
natras->format = 0; natras->format = format;
natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF]; natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
int32 levels = Raster::calculateNumLevels(raster->width, raster->height); int32 levels = Raster::calculateNumLevels(raster->width, raster->height);
natras->texture = createTexture(raster->width, raster->height, natras->texture = createTexture(raster->width, raster->height,
@ -510,7 +510,7 @@ rasterToImage(Raster *raster)
int32 depth; int32 depth;
Image *image; Image *image;
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
if(natras->format){ if(natras->customFormat){
image = Image::create(raster->width, raster->height, 32); image = Image::create(raster->width, raster->height, 32);
image->allocate(); image->allocate();
uint8 *pix = raster->lock(0); uint8 *pix = raster->lock(0);

View File

@ -619,34 +619,43 @@ readNativeTexture(Stream *stream)
int32 depth = stream->readU8(); int32 depth = stream->readU8();
int32 numLevels = stream->readU8(); int32 numLevels = stream->readU8();
int32 type = stream->readU8(); int32 type = stream->readU8();
/*
#define HAS_ALPHA (1<<0)
#define IS_CUBE (1<<1)
#define USE_AUTOMIPMAPGEN (1<<2)
#define IS_COMPRESSED (1<<3)
*/
int32 flags = stream->readU8(); int32 flags = stream->readU8();
Raster *raster; Raster *raster;
D3dRaster *ras; D3dRaster *ext;
assert((flags & 2) == 0);
if(flags & 8){ if(flags & 8){
raster = Raster::create(width, height, depth, format | type | 0x80, PLATFORM_D3D9); // is compressed
ras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); assert((flags & 2) == 0 && "Can't have cube maps yet");
ras->format = d3dformat; raster = Raster::create(width, height, depth, format | type | Raster::DONTALLOCATE, PLATFORM_D3D9);
ras->hasAlpha = flags & 1; ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
ras->texture = createTexture(raster->width, raster->height, ext->format = d3dformat;
ext->hasAlpha = flags & 1;
ext->texture = createTexture(raster->width, raster->height,
raster->format & Raster::MIPMAP ? numLevels : 1, raster->format & Raster::MIPMAP ? numLevels : 1,
ras->format); ext->format);
raster->flags &= ~0x80; raster->flags &= ~Raster::DONTALLOCATE;
ras->customFormat = 1; ext->customFormat = 1;
}else if(flags & 2){
assert(0 && "Can't have cube maps yet");
}else{ }else{
raster = Raster::create(width, height, depth, format | type, PLATFORM_D3D9); raster = Raster::create(width, height, depth, format | type, PLATFORM_D3D9);
ras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
} }
tex->raster = raster; tex->raster = raster;
// TODO: check if format supported and convert if necessary // TODO: check if format supported and convert if necessary
if(raster->format & Raster::PAL4) if(raster->format & Raster::PAL4)
stream->read(ras->palette, 4*32); stream->read(ext->palette, 4*32);
else if(raster->format & Raster::PAL8) else if(raster->format & Raster::PAL8)
stream->read(ras->palette, 4*256); stream->read(ext->palette, 4*256);
uint32 size; uint32 size;
uint8 *data; uint8 *data;
@ -676,28 +685,27 @@ writeNativeTexture(Texture *tex, Stream *stream)
// Raster // Raster
Raster *raster = tex->raster; Raster *raster = tex->raster;
D3dRaster *ras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); D3dRaster *ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
int32 numLevels = raster->getNumLevels(); int32 numLevels = raster->getNumLevels();
stream->writeI32(raster->format); stream->writeI32(raster->format);
stream->writeU32(ras->format); stream->writeU32(ext->format);
stream->writeU16(raster->width); stream->writeU16(raster->width);
stream->writeU16(raster->height); stream->writeU16(raster->height);
stream->writeU8(raster->depth); stream->writeU8(raster->depth);
stream->writeU8(numLevels); stream->writeU8(numLevels);
stream->writeU8(raster->type); stream->writeU8(raster->type);
uint8 flags = 0; uint8 flags = 0;
if(ras->hasAlpha) if(ext->hasAlpha)
flags |= 1; flags |= 1;
// 2 - cube map // no automipmapgen and cube supported yet
// 4 - something about mipmaps... if(ext->customFormat)
if(ras->customFormat)
flags |= 8; flags |= 8;
stream->writeU8(flags); stream->writeU8(flags);
if(raster->format & Raster::PAL4) if(raster->format & Raster::PAL4)
stream->write(ras->palette, 4*32); stream->write(ext->palette, 4*32);
else if(raster->format & Raster::PAL8) else if(raster->format & Raster::PAL8)
stream->write(ras->palette, 4*256); stream->write(ext->palette, 4*256);
uint32 size; uint32 size;
uint8 *data; uint8 *data;

View File

@ -89,6 +89,21 @@ PluginList::streamGetSize(void *object)
return size; return size;
} }
void
PluginList::streamSkip(Stream *stream)
{
int32 length;
ChunkHeaderInfo header;
if(!findChunk(stream, ID_EXTENSION, (uint32*)&length, nil))
return;
while(length > 0){
if(!readChunkHeaderInfo(stream, &header))
return;
stream->seek(header.length);
length -= 12 + header.length;
}
}
void void
PluginList::assertRights(void *object, uint32 pluginID, uint32 data) PluginList::assertRights(void *object, uint32 pluginID, uint32 data)
{ {

View File

@ -40,6 +40,7 @@ struct PluginList
bool streamRead(Stream *stream, void *); bool streamRead(Stream *stream, void *);
void streamWrite(Stream *stream, void *); void streamWrite(Stream *stream, void *);
int streamGetSize(void *); int streamGetSize(void *);
void streamSkip(Stream *stream);
void assertRights(void *, uint32 pluginID, uint32 data); void assertRights(void *, uint32 pluginID, uint32 data);
int32 registerPlugin(int32 size, uint32 id, int32 registerPlugin(int32 size, uint32 id,

View File

@ -334,8 +334,10 @@ Texture::streamRead(Stream *stream)
stream->read(mask, length); stream->read(mask, length);
Texture *tex = Texture::read(name, mask); Texture *tex = Texture::read(name, mask);
if(tex == nil) if(tex == nil){
s_plglist.streamSkip(stream);
return nil; return nil;
}
if(tex->refCount == 1) if(tex->refCount == 1)
tex->filterAddressing = filterAddressing; tex->filterAddressing = filterAddressing;