diff --git a/src/clump.cpp b/src/clump.cpp index 7be31bf..4bc4917 100644 --- a/src/clump.cpp +++ b/src/clump.cpp @@ -763,6 +763,7 @@ Light::create(int32 type) light->minusCosAngle = 1.0f; light->object.privateFlags = 1; light->object.flags = LIGHTATOMICS | LIGHTWORLD; + light->clump = NULL; light->inClump.init(); light->constructPlugins(); return light; @@ -772,6 +773,8 @@ void Light::destroy(void) { this->destructPlugins(); + if(this->clump) + this->inClump.remove(); free(this); } @@ -869,6 +872,8 @@ Camera::create(void) cam->farPlane = 10.0f; cam->fogPlane = 5.0f; cam->projection = Camera::PERSPECTIVE; + cam->clump = NULL; + cam->inClump.init(); cam->constructPlugins(); return cam; } @@ -893,6 +898,8 @@ void Camera::destroy(void) { this->destructPlugins(); + if(this->clump) + this->inClump.remove(); free(this); } diff --git a/src/d3d.cpp b/src/d3d.cpp index c4a0da2..157c8c7 100644 --- a/src/d3d.cpp +++ b/src/d3d.cpp @@ -16,6 +16,8 @@ using namespace std; namespace rw { namespace d3d { +bool32 isP8supported = 1; + #ifdef RW_D3D9 IDirect3DDevice9 *device = NULL; #else diff --git a/src/d3d8.cpp b/src/d3d8.cpp index a8c1a01..9508d45 100644 --- a/src/d3d8.cpp +++ b/src/d3d8.cpp @@ -405,6 +405,54 @@ makeMatFXPipeline(void) // Native Texture and Raster +// only handles 4 and 8 bit textures right now +Raster* +readAsImage(Stream *stream, int32 width, int32 height, int32 depth, int32 format, int32 numLevels) +{ + uint8 palette[256*4]; + uint8 *data; + + Image *img = Image::create(width, height, 32); + img->allocate(); + + if(format & Raster::PAL4) + stream->read(palette, 4*32); + else if(format & Raster::PAL8) + stream->read(palette, 4*256); + + // Only read one mipmap + for(int32 i = 0; i < numLevels; i++){ + uint32 size = stream->readU32(); + if(i == 0){ + data = new uint8[size]; + stream->read(data, size); + }else + stream->seek(size); + } + + if(format & (Raster::PAL4 | Raster::PAL8)){ + uint8 *idx = data; + uint8 *pixels = img->pixels; + for(int y = 0; y < img->height; y++){ + uint8 *line = pixels; + for(int x = 0; x < img->width; x++){ + line[0] = palette[*idx*4+0]; + line[1] = palette[*idx*4+1]; + line[2] = palette[*idx*4+2]; + line[3] = palette[*idx*4+3]; + line += 4; + idx++; + } + pixels += img->stride; + } + } + + delete[] data; + Raster *ras = Raster::createFromImage(img); + img->destroy(); + return ras; +} + Texture* readNativeTexture(Stream *stream) { @@ -427,6 +475,16 @@ readNativeTexture(Stream *stream) int32 type = stream->readU8(); int32 compression = stream->readU8(); + int32 pallength = 0; + if(format & Raster::PAL4 || format & Raster::PAL8){ + pallength = format & Raster::PAL4 ? 32 : 256; + if(!d3d::isP8supported){ + tex->raster = readAsImage(stream, width, height, depth, format|type, numLevels); + tex->streamReadPlugins(stream); + return tex; + } + } + Raster *raster; D3dRaster *ras; if(compression){ @@ -442,10 +500,8 @@ readNativeTexture(Stream *stream) // TODO: check if format supported and convert if necessary - if(raster->format & Raster::PAL4) - stream->read(ras->palette, 4*32); - else if(raster->format & Raster::PAL8) - stream->read(ras->palette, 4*256); + if(pallength != 0) + stream->read(ras->palette, 4*pallength); uint32 size; uint8 *data; diff --git a/src/rwd3d.h b/src/rwd3d.h index e441b59..ad18b3b 100644 --- a/src/rwd3d.h +++ b/src/rwd3d.h @@ -5,6 +5,8 @@ namespace rw { namespace d3d { +extern bool32 isP8supported; + #ifdef RW_D3D9 extern IDirect3DDevice9 *device; #else